Example #1
0
    def exec_gal(self,irc_msg,x,y):
        query="SELECT t2.id AS id, t1.id AS pid, t1.x AS x, t1.y AS y, t1.z AS z, t2.nick AS nick, t2.fakenick AS fakenick, t2.defwhore AS defwhore, t2.gov AS gov, t2.bg AS bg, t2.covop AS covop, t2.alliance_id AS alliance_id, t2.relay AS relay, t2.reportchan AS reportchan, t2.scanner AS scanner, t2.distwhore AS distwhore, t2.comment AS comment, t3.name AS alliance FROM planet_dump as t1, intel as t2 LEFT JOIN alliance_canon AS t3 ON t2.alliance_id=t3.id WHERE tick=(SELECT max_tick()) AND t1.id=t2.pid AND x=%s AND y=%s ORDER BY y,z,x"
        self.cursor.execute(query,(x,y))

        replied_to_request = False

        repls=[]
        for d in self.cursor.dictfetchall():
            x=d['x']
            y=d['y']
            z=d['z']
            i=loadable.intel(pid=d['pid'],nick=d['nick'],fakenick=d['fakenick'],defwhore=d['defwhore'],gov=d['gov'],bg=d['bg'],
                             covop=d['covop'],alliance=d['alliance'],relay=d['relay'],reportchan=d['reportchan'],
                             scanner=d['scanner'],distwhore=d['distwhore'],comment=d['comment'])
            if i.nick or i.alliance:
                replied_to_request = True
                r="#%d "%(z,)
                if i.nick and i.alliance:
                    r+="%s [%s]"%(i.nick,i.alliance[:3])
                elif i.nick:
                    r+=i.nick
                elif i.alliance:
                    r+="["+i.alliance[:3]+"]"
                repls.append(r)

        if not replied_to_request:
            irc_msg.reply("No information stored for galaxy %s:%s" % (x,y))
        else:
            reply="Intel %d:%d - "%(x,y)
            reply+=self.gal_info(x,y)
            reply+=" - "
            reply+=" - ".join(repls)
            irc_msg.reply(reply)
        return 1
Example #2
0
    def report_incoming(self,target,owner,message,reporter,source,landing_tick):
        i=loadable.intel(pid=target.id)
        if not i.load_from_db(self.cursor):
            print "planet %s:%s:%s not in intel"%(target.x,target.y,target.z)
            return
        reply="%s reports: " % (reporter,)
        if i.nick:
            reply+=i.nick + " -> "
        reply+=" (xp: %s" % (owner.calc_xp(target),)

#        if i.alliance and i.alliance.lower() == self.config.get("Auth", "alliance").lower() and source != "#"+self.config.get("Auth", "home") and not (i.relay and i.reportchan != "#"+self.config.get("Auth", "home")):
#            d = self.get_defcall(target.id, landing_tick)
#            if d:
#                reply+=", d: %s) " % (d['id'],)
#            else:
#                reply+=") "
#            reply+=message
#            self.client.privmsg("#"+self.config.get("Auth", "home"),reply)
#            return



        if i.relay and i.reportchan and source != i.reportchan:
            reply+=") "
            reply+=message
            self.client.privmsg(i.reportchan,reply)
        else:
            print "planet not set to relay (%s) or report (%s) or report is source (%s)"%(i.relay,i.reportchan,source)
Example #3
0
File: intel.py Project: munin/munin
    def exec_gal(self, irc_msg, x, y):
        query = "SELECT i.id AS id, p.id AS pid, p.x AS x, p.y AS y, p.z AS z, i.nick AS nick, i.fakenick AS fakenick, i.defwhore AS defwhore, i.gov AS gov, i.bg AS bg, i.covop AS covop, i.alliance_id AS alliance_id, i.relay AS relay, i.reportchan AS reportchan, i.scanner AS scanner, i.distwhore AS distwhore, i.comment AS comment, a.name AS alliance"
        query += " FROM planet_dump AS p, intel AS i"
        query += " LEFT JOIN alliance_canon AS a ON i.alliance_id=a.id"
        query += " WHERE tick=(SELECT max_tick(%s::smallint)) AND p.round=%s AND p.id=i.pid AND x=%s AND y=%s"
        query += " ORDER BY z ASC"
        self.cursor.execute(query, (irc_msg.round, irc_msg.round, x, y,))

        replied_to_request = False

        repls = []
        for d in self.cursor.dictfetchall():
            x = d['x']
            y = d['y']
            z = d['z']
            i = loadable.intel(
                pid=d['pid'],
                nick=d['nick'],
                fakenick=d['fakenick'],
                defwhore=d['defwhore'],
                gov=d['gov'],
                bg=d['bg'],
                covop=d['covop'],
                alliance=d['alliance'],
                relay=d['relay'],
                reportchan=d['reportchan'],
                scanner=d['scanner'],
                distwhore=d['distwhore'],
                comment=d['comment'])
            if i.nick or i.alliance:
                replied_to_request = True
                r = "#%d " % (z,)
                if i.nick and i.alliance:
                    r += "%s [%s]" % (i.nick, i.alliance[:3])
                elif i.nick:
                    r += i.nick
                elif i.alliance:
                    r += "[" + i.alliance[:3] + "]"
                repls.append(r)

        if not replied_to_request:
            irc_msg.reply("No information stored for galaxy %s:%s" % (x, y))
        else:
            reply = "Intel %d:%d - " % (x, y)
            reply += self.gal_info(x, y, irc_msg.round)
            reply += " - "
            reply += " - ".join(repls)
            irc_msg.reply(reply)
        return 1
Example #4
0
    def exec_gal(self,irc_msg,x,y):
        query="SELECT t2.id AS id, t1.id AS pid, t1.x AS x, t1.y AS y, t1.z AS z, t2.nick AS nick, t2.fakenick AS fakenick, t2.defwhore AS defwhore, t2.gov AS gov, t2.bg AS bg, t2.covop AS covop, t2.alliance_id AS alliance_id, t2.relay AS relay, t2.reportchan AS reportchan, t2.scanner AS scanner, t2.distwhore AS distwhore, t2.comment AS comment, t3.name AS alliance FROM planet_dump as t1, intel as t2 LEFT JOIN alliance_canon AS t3 ON t2.alliance_id=t3.id WHERE tick=(SELECT MAX(tick) FROM updates) AND t1.id=t2.pid AND x=%s AND y=%s ORDER BY y,z,x"
        self.cursor.execute(query,(x,y))

        replied_to_request = False
        for d in self.cursor.dictfetchall():
            x=d['x']
            y=d['y']
            z=d['z']
            i=loadable.intel(pid=d['pid'],nick=d['nick'],fakenick=d['fakenick'],defwhore=d['defwhore'],gov=d['gov'],bg=d['bg'],
                             covop=d['covop'],alliance=d['alliance'],relay=d['relay'],reportchan=d['reportchan'],
                             scanner=d['scanner'],distwhore=d['distwhore'],comment=d['comment'])
            if not i.is_empty():
                replied_to_request = True
                reply="Information stored for %s:%s:%s - "% (x,y,z)
                reply+=i.__str__()
                irc_msg.reply(reply)

        if not replied_to_request:
            irc_msg.reply("No information stored for galaxy %s:%s" % (x,y))
        return 1
Example #5
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0

        m=self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 1

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 1

        #assign param variables
        par=m.group(1)
        m=self.planet_coordre.search(par)
        if not m:
            m=self.gal_coordre.search(par)
            if m:
                return self.exec_gal(irc_msg,m.group(1),m.group(2))
            else:
                irc_msg.reply("Usage: %s" % (self.usage,))
                return 1

        p=loadable.planet(x=m.group(1),y=m.group(2),z=m.group(3))

        params=m.group(4)

        if not p.load_most_recent(self.cursor):
            irc_msg.reply("No planet matching '%s:%s:%s' found"%(p.x,p.y,p.z,))
            return 1

        i=loadable.intel(pid=p.id)
        if not i.load_from_db(self.cursor):
            pass

        opts=self.split_opts(params)
        opts['pid']=p.id
        a=loadable.alliance(name=i.alliance)
        if i.alliance:
            a.load_most_recent(self.cursor)
        for opt, val in opts.items():
            if opt == "alliance":
                if val in self.nulls:
                    a=loadable.alliance(id=None)
                    continue
                a=loadable.alliance(name=val)
                if not a.load_most_recent(self.cursor):
                    irc_msg.reply("'%s' is not a valid alliance, your information was not added."%(val,))
                    return 1
                else:
                    opts['alliance'] = a.name
            if (opt in self.options) and (val in self.nulls):
                opts[opt] = None
                continue
            if opt in ("nick","fakenick","bg","gov","reportchan"):
                opts[opt] = val
            if opt in ("defwhore","covop","scanner","distwhore","relay"):
                if val in self.true:
                    opts[opt] = True
                if val in self.false:
                    opts[opt] = False
            if opt == "comment":
                opts[opt] = self.commentre.split(irc_msg.command)[1]

        for k in self.options:
            if not opts.has_key(k):
                opts[k]=getattr(i,k)

        if i.id:
            query="UPDATE intel SET "
            query+="pid=%s,nick=%s,fakenick=%s,defwhore=%s,gov=%s,bg=%s,covop=%s,alliance_id=%s,relay=%s,reportchan=%s,"
            query+="scanner=%s,distwhore=%s,comment=%s"
            query+=" WHERE id=%s"
            self.cursor.execute(query,(opts['pid'],opts['nick'],
                                       opts['fakenick'],opts['defwhore'],opts['gov'],opts['bg'],
                                       opts['covop'],a.id,opts['relay'],opts['reportchan'],
                                       opts['scanner'],opts['distwhore'],opts['comment'],i.id))
        elif params:
            query="INSERT INTO intel (pid,nick,fakenick,defwhore,gov,bg,covop,relay,reportchan,scanner,distwhore,comment,alliance_id) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
            self.cursor.execute(query,(opts['pid'],opts['nick'],
                                       opts['fakenick'],opts['defwhore'],opts['gov'],opts['bg'],
                                       opts['covop'],opts['relay'],opts['reportchan'],
                                       opts['scanner'],opts['distwhore'],
                                       opts['comment'],a.id))
        i=loadable.intel(pid=opts['pid'],nick=opts['nick'],fakenick=opts['fakenick'],defwhore=opts['defwhore'],gov=opts['gov'],bg=opts['bg'],
                         covop=opts['covop'],alliance=opts['alliance'],relay=opts['relay'],reportchan=opts['reportchan'],
                         scanner=opts['scanner'],distwhore=opts['distwhore'],comment=opts['comment'])

        reply="Information stored for %s:%s:%s - "% (p.x,p.y,p.z)
        reply+=i.__str__()
        irc_msg.reply(reply)

        return 1
Example #6
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0


        m=self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply(self.usage)
            return 0

        search=m.group(2)
        u=loadable.user(pnick=irc_msg.user)
        if search is not None:
            a=loadable.alliance(name=search)
            if not a.load_most_recent(self.cursor):
                reply="No alliances match %s" % (search,)
                irc_msg.reply(reply)
                return 1
        elif u.load_from_db(self.cursor) and u.userlevel >= 100:
            a=loadable.alliance(name=self.config.get('Auth', 'alliance'))
            if not a.load_most_recent(self.cursor):
                reply="No alliances match %s" % (search,)
                irc_msg.reply(reply)
                return 1
        elif u.id > -1 and u.planet is not None:
            i=loadable.intel(pid=u.planet.id)
            if (not i.load_from_db(self.cursor)) or i.alliance is None:
                reply="Make sure you've set your planet with !pref and alliance with !intel"
                irc_msg.reply(reply)
                return 1
            else:
                a=loadable.alliance(name=i.alliance)
        else:
            reply="Make sure you've set your planet with !pref and alliance with !intel"
            irc_msg.reply(reply)
            return 1

        query="DROP TABLE apenis;DROP SEQUENCE al_activity_rank;"
        try:
            self.cursor.execute(query)
        except:
            pass

        query="CREATE TEMP SEQUENCE al_activity_rank"
        self.cursor.execute(query)
        query="SELECT setval('al_activity_rank',1,false)"
        self.cursor.execute(query)


        query="CREATE TEMP TABLE apenis AS"
        query+=" (SELECT *,nextval('al_activity_rank') AS activity_rank"
        query+=" FROM (SELECT t1.name, t1.members, t1.score-t5.score AS activity"
        query+=" FROM alliance_dump AS t1"
        query+=" INNER JOIN alliance_dump AS t5"
        query+=" ON t1.id=t5.id AND t1.tick - 72 = t5.tick"
        query+=" WHERE t1.tick = (select max(tick) from updates)"
        query+=" ORDER BY activity DESC) AS t8)"

        self.cursor.execute(query)

        query="SELECT name,activity,activity_rank,members"
        query+=" FROM apenis"
        query+=" WHERE name ILIKE %s"

        self.cursor.execute(query,(a.name,))
        if self.cursor.rowcount < 1:
            query="SELECT name,activity,activity_rank"
            query+=" FROM apenis"
            query+=" WHERE name ILIKE %s"

            self.cursor.execute(query,(a.name,))

        res=self.cursor.dictfetchone()
        if not res:
            reply="No apenis stats matching %s"% (a.name,)
        else:
            person=res['name']
            reply ="apenis for %s is %s score long. This makes %s rank: %s apenis. The average peon is sporting a %s score epenis." % (person,res['activity'],person,res['activity_rank'],int(res['activity']/res['members']))

        irc_msg.reply(reply)

        return 1
Example #7
0
File: pref.py Project: munin/munin
    def execute(self, user, access, irc_msg):
        m = irc_msg.match_command(self.commandre)
        if not m:
            return 0

        m = self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        u = loadable.user(pnick=irc_msg.user)
        if not u.load_from_db(self.cursor, irc_msg.round):
            irc_msg.reply(
                "You must be registered to use the " +
                self.__class__.__name__ +
                " command (log in with P and set mode +x)")
            return 1

        param_dict = self.split_opts(m.group(1))
        if param_dict is None:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 1

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0

        for opt in param_dict:
            val = param_dict[opt]
            if opt == "planet":
                m = self.planet_coordre.search(val)
                if m:
                    x = m.group(1)
                    y = m.group(2)
                    z = m.group(3)
                else:
                    irc_msg.reply("You must provide coordinates (x:y:z) for the planet option")
                    continue
                pid = self.save_planet(irc_msg, u, x, y, z, irc_msg.round)
                if pid > 0 and u.userlevel >= 100:
                    a = loadable.alliance(name=self.config.get('Auth', 'alliance'))
                    if a.load_most_recent(self.cursor, irc_msg.round):
                        i = loadable.intel(pid=pid)
                        i.load_from_db(self.cursor, irc_msg.round)
                        if i.id:
                            query = "UPDATE intel SET "
                            query += "nick=%s,alliance_id=%s"
                            query += " WHERE id=%s"
                            self.cursor.execute(query, (user, a.id, i.id))
                        else:
                            query = "INSERT INTO intel (pid,nick,alliance_id,round) VALUES (%s,%s,%s,%s)"
                            self.cursor.execute(query, (pid, user, a.id, irc_msg.round,))
            if opt == "stay":
                self.save_stay(irc_msg, u, val, access, irc_msg.round)
            if opt == "pubphone":
                self.save_pubphone(irc_msg, u, val, access)
            if opt == "password":
                self.save_password(irc_msg, u, val)
            if opt == "phone":
                self.save_phone(irc_msg, u, val)

        return 1
Example #8
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0

        u=None
        if user:
            u=loadable.user(pnick=irc_msg.user)
            if not u.load_from_db(self.cursor):
                pass

        m=self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        # assign param variables

        x=m.group(1)
        y=m.group(2)
        z=m.group(3)

        # first, plain lookup

        p=loadable.planet(x=x,y=y,z=z)
        if not p.load_most_recent(self.cursor):
            irc_msg.reply("No planet matching '%s:%s:%s' found"%(p.x,p.y,p.z,))
            return 1

        irc_msg.reply(p.__str__())

        # next we do XP



        if u.planet_id:
            # this is a straight copy from xp. Dirty dirty.
            attacker = u.planet
            reply="Target "
            victim_val = p.value
            attacker_val = attacker.value
            victim_score = p.score
            attacker_score = attacker.score

            reply+="%s:%s:%s (%s|%s) "%(p.x,p.y,p.z,
                                        self.format_value(victim_val*100),self.format_value(victim_score*100))
            reply+="| Attacker %s:%s:%s (%s|%s) "%(attacker.x,attacker.y,attacker.z,
                                                   self.format_value(attacker_val*100),self.format_value(attacker_score*100))
            total_roids = p.size

            #bravery = min(20,10*(float(victim_val)/attacker_val))
            #bravery = min(20,5*(float(victim_val)/attacker_val)*(float(victim_score)/attacker_score))

            bravery = max(0,(min(2,float(victim_val)/attacker_val)-0.4 ) * (min(2,float(victim_score)/attacker_score)-0.6))
            #bravery = max(0,min(30,10*(min(2,float(victim_val)/attacker_val)  + min(2,float(victim_score)/attacker_score) - 1)))
            bravery *= 10

            reply+="| Bravery: %.2f " % (bravery,)

            cap=total_roids/4
            xp=int(cap*bravery)
            reply+="| Roids: %s | XP: %s | Score: %s" % (cap,xp,xp*60)
            irc_msg.reply(reply)

        i=loadable.intel(pid=p.id)
        reply="Information stored for %s:%s:%s - "% (p.x,p.y,p.z)
        if i.load_from_db(self.cursor) and i.id>0:
            reply+=i.__str__()
        irc_msg.reply(reply)


        query="SELECT t1.id AS id, t1.nick AS nick, t1.pid AS pid, t1.tick AS tick, t1.uid AS uid, t2.pnick AS pnick, t2.userlevel AS userlevel, t3.x AS x, t3.y AS y, t3.z AS z"
        query+=" FROM target AS t1"
        query+=" INNER JOIN planet_dump AS t3 ON t1.pid=t3.id"
        query+=" LEFT JOIN user_list AS t2 ON t1.uid=t2.id"
        query+=" WHERE t1.tick > (SELECT max_tick()) AND t3.tick = (SELECT max_tick()) AND t3.x=%s AND t3.y=%s AND t3.z=%s"

        self.cursor.execute(query,(p.x,p.y,p.z))
        if self.cursor.rowcount < 1:
            reply="No bookings matching planet %s:%s:%s"%(p.x,p.y,p.z)
        else:
            reply="Status for %s:%s:%s -" % (x,y,z)
            prev=[]
            for r in self.cursor.dictfetchall():
                owner="nick:"+r['nick']
                if r['pnick']:
                    owner="user:"******"(%s %s)" % (r['tick'],owner))

            reply+=" "+string.join(prev,', ')

        irc_msg.reply(reply)




        return 1
Example #9
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0

        m=self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        x=m.group(1)
        y=m.group(2)
        z=m.group(3)
        when=int(m.group(4))
        override=m.group(6)

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0

        if access < 100 and not irc_msg.user:
            irc_msg.reply("I don't trust you. You have to set mode +x to book a target.")
            return 0


        p=loadable.planet(x=x,y=y,z=z)
        if not p.load_most_recent(self.cursor):
            irc_msg.reply("No planet matching '%s:%s:%s' found"%(x,y,z))
            return 1
        else:
            i=loadable.intel(pid=p.id)
            if not i.load_from_db(self.cursor):
                pass
            else:
                if i and i.alliance and i.alliance.lower()== self.config.get("Auth", "alliance").lower():
                    irc_msg.reply("%s:%s:%s is %s in %s. Quick, launch before they notice the highlight."%(x,y,z,i.nick or 'someone',self.config.get('Auth', 'alliance')))
                    return 0
        curtick=self.current_tick()
        tick=-1
        eta=-1

        if when < 32:
            tick=curtick+when
            eta=when
        elif when < curtick:
            irc_msg.reply("Can not book targets in the past. You wanted tick %s, but current tick is %s."%(when,curtick))
            return 1
        else:
            tick=when
            eta=tick-curtick
        if tick > 32767:
            tick=32767


        query="SELECT t1.id AS id, t1.nick AS nick, t1.pid AS pid, t1.tick AS tick, t1.uid AS uid, t2.pnick AS pnick, t2.userlevel AS userlevel, t3.x AS x, t3.y AS y, t3.z AS z"
        query+=" FROM target AS t1"
        query+=" INNER JOIN planet_dump AS t3 ON t1.pid=t3.id"
        query+=" LEFT JOIN user_list AS t2 ON t1.uid=t2.id"
        query+=" WHERE"
        query+=" t1.tick > %s"
        query+=" AND t3.tick = (SELECT max_tick()) AND t3.x=%s AND t3.y=%s"
        query+=" AND t3.z=%s"

        self.cursor.execute(query,(tick,x,y,z))

        if self.cursor.rowcount > 0 and not override:
            reply="There are already bookings for that target after landing pt %s (eta %s). To see status on this target, do !status %s:%s:%s." % (tick,eta,x,y,z)
            reply+=" To force booking at your desired eta/landing tick, use !book %s:%s:%s %s yes (Bookers:" %(x,y,z,tick)
            prev=[]
            for r in self.cursor.dictfetchall():
                owner="nick:"+r['nick']
                if r['pnick']:
                    owner="user:"******"(%s %s)" % (r['tick'],owner))
            reply+=" "+string.join(prev,', ')
            reply+=" )"
            irc_msg.reply(reply)
            return 1

        uid=None
        if irc_msg.user:
            u=loadable.user(pnick=irc_msg.user)
            if u.load_from_db(self.cursor):
                uid=u.id

        query="INSERT INTO target (nick,pid,tick,uid) VALUES (%s,%s,%s,%s)"
        try:
            self.cursor.execute(query,(irc_msg.nick,p.id,tick,uid))
            if uid:
                reply="Booked landing on %s:%s:%s tick %s for user %s" % (p.x,p.y,p.z,tick,irc_msg.user)
            else:
                reply="Booked landing on %s:%s:%s tick %s for nick %s" % (p.x,p.y,p.z,tick,irc_msg.nick)
        except psycopg.IntegrityError:
            query="SELECT t1.id AS id, t1.nick AS nick, t1.pid AS pid, t1.tick AS tick, t1.uid AS uid, t2.pnick AS pnick, t2.userlevel AS userlevel "
            query+=" FROM target AS t1 LEFT JOIN user_list AS t2 ON t1.uid=t2.id "
            query+=" WHERE t1.pid=%s AND t1.tick=%s"

            self.cursor.execute(query,(p.id,tick))
            book=self.cursor.dictfetchone()
            if not book:
                raise Exception("Integrity error? Unable to booking for pid %s and tick %s"%(p.id,tick))
            if book['pnick']:
                reply="Target %s:%s:%s is already booked for landing tick %s by user %s" % (p.x,p.y,p.z,book['tick'],book['pnick'])
            else:
                reply="Target %s:%s:%s is already booked for landing tick %s by nick %s" % (p.x,p.y,p.z,book['tick'],book['nick'])
        except:
            raise

        irc_msg.reply(reply)

        return 1