Example #1
0
    def parse_news(self, scan_id,page):
        m = re.search('on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
        x = m.group(1)
        y = m.group(2)
        z = m.group(3)
        tick = m.group(4)

        p=loadable.planet(x, y, z)
        if not p.load_most_recent(self.cursor): #really, this should never, ever fail.
            return
    #incoming fleets
    #<td class=left valign=top>Incoming</td><td valign=top>851</td><td class=left valign=top>We have detected an open jumpgate from Tertiary, located at 18:5:11. The fleet will approach our system in tick 855 and appears to have roughly 95 ships.</td>
        for m in re.finditer('<td class="left" valign="top">Incoming</td><td valign="top">(\d+)</td><td class="left" valign="top">We have detected an open jumpgate from ([^<]+), located at (\d+):(\d+):(\d+). The fleet will approach our system in tick (\d+) and appears to have roughly (\d+) ships.</td>', page):
            newstick = m.group(1)
            fleetname = m.group(2)
            originx = m.group(3)
            originy = m.group(4)
            originz = m.group(5)
            arrivaltick = m.group(6)
            numships = m.group(7)

            owner=loadable.planet(originx,originy,originz)
            if not owner.load_most_recent(self.cursor):
                continue
            query="INSERT INTO fleet (scan_id,owner_id,target,fleet_size,fleet_name,launch_tick,landing_tick,mission) VALUES (%s,%s,%s,%s,%s,%s,%s,'unknown')"
            try:
                self.cursor.execute(query,(scan_id,owner.id,p.id,numships,fleetname,newstick,arrivaltick))
            except Exception, e:
                print "Exception in news: "+e.__str__()
                traceback.print_exc()
                continue

            print 'Incoming: ' + newstick + ':' + fleetname + '-' + originx + ':' + originy + ':' + originz + '-' + arrivaltick + '|' + numships
Example #2
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

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

        victim = None
        attacker = None
        mcs = 0

        victim = loadable.planet(x=m.group(1),y=m.group(2),z=m.group(3))
        if not victim.load_most_recent(self.cursor):
            irc_msg.reply("%s:%s:%s is not a valid planet" % (victim.x,victim.y,victim.z))
            return 1

        if not victim:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 1

        if m.lastindex >= 6 and m.group(4) and m.group(5) and m.group(6):
            attacker = loadable.planet(x=m.group(4),y=m.group(5),z=m.group(6))
            if not attacker.load_most_recent(self.cursor):
                irc_msg.reply("%s:%s:%s is not a valid planet" % (attacker.x,attacker.y,attacker.z))
                return 1
        if not attacker:
            u=loadable.user(pnick=irc_msg.user)
            if not u.load_from_db(self.cursor):
                irc_msg.reply("You must be registered to use the automatic "+self.__class__.__name__+" command (log in with P and set mode +x, then make sure your planet is set with the pref command)")
                return 1
            if u.planet_id:
                attacker = u.planet
            else:
                irc_msg.reply("Usage: %s (make sure your planet is set with the pref command)" % (self.usage,))
                return 1

        if m.lastindex == 7:
            mcs = int(m.group(7))

        reply="Target %s:%s:%s (%s|%s) "%(victim.x,victim.y,victim.z,
                                          self.format_value(victim.value*100),self.format_value(victim.score*100))
        reply+="| Attacker %s:%s:%s (%s|%s) "%(attacker.x,attacker.y,attacker.z,
                                               self.format_value(attacker.value*100),self.format_value(attacker.score*100))

        bravery = attacker.bravery(victim)
        cap = int(attacker.cap_rate(victim)*victim.size)
        xp = int(attacker.calc_xp(victim, mcs))
        score = self.format_value(100 * 60 * xp)

        reply+="| Bravery: %.2f | Cap: %d | MCs: %d | XP: %d | Score: %s" % (bravery,cap,mcs,xp,score)
        irc_msg.reply(reply)

        return 1
Example #3
0
    def parse_jumpgate(self, scan_id,page):
        m = re.search('on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
        x = m.group(1)
        y = m.group(2)
        z = m.group(3)
        tick = m.group(4)
        # <td class=left>Origin</td><td class=left>Mission</td><td>Fleet</td><td>ETA</td><td>Fleetsize</td>
        # <td class=left>13:10:5</td><td class=left>Attack</td><td>Gamma</td><td>5</td><td>265</td>


        p=loadable.planet(x, y, z)
        if not p.load_most_recent(self.cursor): #really, this should never, ever fail, but exiles might bork it
            return

        #                     <td class="left">15:7:11            </td><td class="left">Defend </td><td>Ad infinitum</td><td>9</td><td>0</td>
        #<tr><td class="left">10:4:9</td><td class="left">Return</td><td>They look thirsty</td><td>5</td><td>3000</td></tr>
        #	<tr><td class="left">4:1:10</td><td class="left">Return</td><td>Or Is It?</td><td>9</td><td>3000</td></tr>

	#<tr><td class="left">10:1:10</td><td class="left">Defend</td><td class="left">Pesticide IV</td><td class="right">1</td><td class="right">0</td></tr>

        for m in re.finditer('<td[^>]*>(\d+)\:(\d+)\:(\d+)</td><td[^>]*>([^<]+)</td><td[^>]*>([^<]+)</td><td[^>]*>(\d+)</td><td[^>]*>(\d+(?:,\d{3})*)</td>', page):
            originx = m.group(1)
            originy = m.group(2)
            originz = m.group(3)
            mission = m.group(4)
            fleet = m.group(5)
            eta = m.group(6)
            fleetsize = m.group(7).replace(',', '')

            print "JGP fleet "

            attacker=loadable.planet(originx,originy,originz)
            if not attacker.load_most_recent(self.cursor):
                print "Can't find attacker in db: %s:%s:%s"%(originx,originy,originz)
                continue
            query="INSERT INTO fleet (scan_id,owner_id,target,fleet_size,fleet_name,landing_tick,mission) VALUES (%s,%s,%s,%s,%s,%s,%s)"

            try:
                self.cursor.execute(query,(scan_id,attacker.id,p.id,fleetsize,fleet,int(tick)+int(eta),mission.lower()))
            except psycopg.IntegrityError, e:
                print "Caught exception in jgp: "+e.__str__()
                traceback.print_exc()
                print "Trying to update instead"
                query="UPDATE fleet SET scan_id=%s WHERE owner_id=%s AND target=%s AND fleet_size=%s AND fleet_name=%s AND landing_tick=%s AND mission=%s"
                try:
                    self.cursor.execute(query,(scan_id,attacker.id,p.id,fleetsize,fleet,int(tick)+int(eta),mission.lower()))
                except:
                    print "Exception trying to update jgp: "+e.__str__()
                    traceback.print_exc()
                    continue
            except Exception, e:
                print "Exception in jgp: "+e.__str__()
                traceback.print_exc()
                continue
Example #4
0
    def execute(self,user,access,irc_msg):
        m=self.commandre.search(irc_msg.command)
        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("Usage: %s" % (self.usage,))
            return 0
        u=self.load_user_with_planet(user,irc_msg)
        if not u:
            return 0
        # assign param variables
        x=m.group(1)
        y=m.group(2)
        z=m.group(3)
        sum=m.group(5)

        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

        res=u.planet.resources_per_agent(p)
        reply="Your Seagals will ninja %s resources from %s:%s:%s - 13: %s, 35: %s."%(res,p.x,p.y,p.z,self.format_real_value(res*13),self.format_real_value(res*35))
        if sum:
            reply+=" You need %s Seagals to ninja %sk res."%(int(math.ceil((float(sum)*1000)/res)),sum)
        irc_msg.reply(reply)

        return 1
Example #5
0
    def execute(self,user,access,irc_msg):
        m=self.commandre.search(irc_msg.command)
        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("Usage: %s" % (self.usage,))
            return 0

        # assign param variables
        x=m.group(1)
        y=m.group(2)
        z=m.group(3)
        eta=m.group(4)

        skip_missing = False
        if m.lastindex == 5:
            skip_missing = True

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

        jgp=self.get_jgp(target)
        if not jgp:
            irc_msg.reply("I'd get right on that if I had a JGP from this tick. Really, I would. Right. On. That.")
            return 1

        planets=[row for row in jgp if row['eta']==int(eta)]
        aus=self.get_aus(target,planets)
        outdated=[au for au in aus if au['age'] > 12]
        up_to_date=[au for au in aus if au['age'] <= 12]
        fleet_count = len(up_to_date)
        if len(outdated) > 0:
            if skip_missing:
                if fleet_count == 0:
                    irc_msg.reply("I need at least one AU to make a calc, dummy")
                    return 0
                else:
                    reply = "Ignoring missing AU scans on "
                    reply += string.join(["%s:%s:%s" % (p['x'],p['y'],p['z']) for p in outdated], ", ")
                    if fleet_count > 10:
                        reply += ". This is going to take a moment, %s" % (irc_msg.nick,)
                    irc_msg.reply(reply)
            else:
                reply=string.join(["%s:%s:%s" % (p['x'],p['y'],p['z']) for p in outdated], ", ")
                irc_msg.reply("Get off your ass and give me fresh AUs on: %s" % (reply,))
                return 1
        elif fleet_count > 10:
            irc_msg.reply("This is going to take a moment, %s" % (irc_msg.nick,))

        calc_creator(target,up_to_date,jgp,fleet_count,irc_msg).start()
        return 1
Example #6
0
    def execute(self, user, access, irc_msg):
        m = irc_msg.match_command(self.commandre)
        if not m:
            return 0

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

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

        planet = None

        if m.lastindex == 3 and m.group(1) and m.group(2) and m.group(3):
            planet = loadable.planet(x=m.group(1), y=m.group(2), z=m.group(3))
            if not planet.load_most_recent(self.cursor, irc_msg.round):
                irc_msg.reply("%s:%s:%s is not a valid planet" % (planet.x, planet.y, planet.z))
                return 1
        else:
            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 automatic " +
                    self.__class__.__name__ +
                    " command (log in with P and set mode +x, then make sure your planet is set with the pref command)")
                return 1
            if u.planet_id:
                planet = u.planet
            else:
                irc_msg.reply("Usage: %s (make sure your planet is set with the pref command)" % (self.usage,))
                return 1

        if not planet:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        query = "SELECT score"
        query += " FROM planet_dump"
        query += " WHERE tick=(SELECT max_tick(%s::smallint)) AND round=%s"
        query += " ORDER BY score_rank ASC"
        query += " LIMIT 20"
        self.cursor.execute(query, (irc_msg.round, irc_msg.round,))
        if self.cursor.rowcount < 1:
            irc_msg.reply("Error retrieving score of top 20 planets from database")
        top20_average_score = reduce(lambda s, p: s + float(p['score']) / 20.0,
                                     self.cursor.dictfetchall(),
                                     0.0)

        score_modifier = 0.5 * (1.0 - float(planet.score) / top20_average_score)
        race_bonus = self.config.getfloat('Planetarion', planet.race + '_salvage_bonus')
        salvage_rate = 0.3 * (1.0 + race_bonus) * (1.0 + score_modifier)
        reply = "%s:%s:%s (%s|%s) gets a defense salvage rate of %2.1f%%" % (planet.x, planet.y, planet.z, self.format_value(
            planet.value * 100), self.format_value(planet.score * 100), 100 * salvage_rate)
        irc_msg.reply(reply)
        return 1
Example #7
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 or not m.group(1):
            u=loadable.user(pnick=irc_msg.user)
            if not u.load_from_db(self.cursor):
                irc_msg.reply("Usage: %s (you must be registered for automatic lookup)" % (self.usage,))
                return 1
            if u.planet:
                reply=self.surprise(x=u.planet.x,y=u.planet.y,z=u.planet.z)
                irc_msg.reply(reply)
            else:
                irc_msg.reply("Usage: %s (you must be registered for automatic lookup)" % (self.usage,))
            return 0

        # assign param variables
        param=m.group(1)
        m=self.coordre.search(param)
        if m:
            x=m.group(1)
            y=m.group(2)
            z=m.group(4)

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

                irc_msg.reply(reply)
                return 1
            else:
                g=loadable.galaxy(x=x,y=y)
                if not g.load_most_recent(self.cursor):
                    irc_msg.reply("No galaxy matching '%s' found"%(param,))
                    return 1
                reply=self.surprise(x=g.x,y=g.y)
                irc_msg.reply(reply)
                return 1

        a=loadable.alliance(name=param.strip())
        if not a.load_most_recent(self.cursor):
            irc_msg.reply("No alliance matching '%s' found" % (param,))
            return 1
        reply=self.surprise(alliance=a.name)
        irc_msg.reply(reply)

        return 1
Example #8
0
    def unsafe_method(self,message,nick,pnick,source):
        message=message.replace("\x02","")
        m=self.statusre.search(message)
        if not m:

            return
        print m.groups()

        target_x=m.group(1)
        target_y=m.group(2)
        target_z=m.group(3)

        owner_x=m.group(4)
        owner_y=m.group(5)
        owner_z=m.group(6)



        fleetname=m.group(7)
        race=m.group(9)
        fleetsize=m.group(10)
        mission=m.group(11)
        eta=m.group(12)

        print "%s:%s:%s %s:%s:%s '%s' %s m:%s e:%s"%(owner_x,owner_y,owner_z,target_x,target_y,target_z,fleetname,fleetsize,mission,eta)

        target=loadable.planet(target_x,target_y,target_z)
        if not target.load_most_recent(self.cursor):
            return

        owner=loadable.planet(owner_x,owner_y,owner_z)
        if not owner.load_most_recent(self.cursor):
            return

        self.cursor.execute("SELECT max_tick() AS max_tick")
        curtick=self.cursor.dictfetchone()['max_tick']
        landing_tick = int(eta) + int(curtick)

        query="INSERT INTO fleet(owner_id,target,fleet_size,fleet_name,landing_tick,mission) VALUES (%s,%s,%s,%s,%s,%s)"
        try:
            self.cursor.execute(query,(owner.id,target.id,fleetsize,fleetname,landing_tick,mission.lower()))
        except Exception,e:
            print "Exception in galstatus: "+e.__str__()
            traceback.print_exc()
Example #9
0
File: pref.py Project: munin/munin
    def save_planet(self, irc_msg, u, x, y, z, round):
        p = loadable.planet(x=x, y=y, z=z)
        if not p.load_most_recent(self.cursor, round):
            irc_msg.reply("%s:%s:%s is not a valid planet" % (x, y, z))
            return 0

        if u.pref:
            query = "INSERT INTO round_user_pref (user_id,round,planet_id) VALUES (%s,%s,%s)"
            query += " ON CONFLICT (user_id,round) DO"
            query += " UPDATE SET planet_id=EXCLUDED.planet_id"
            self.cursor.execute(query, (u.id, round, p.id,))
            irc_msg.reply("Your planet has been saved as %s:%s:%s" % (x, y, z))
            return p.id
Example #10
0
    def execute(self, page):
        m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
        if not m:
            print "Expired/non-matchinng scan (id: %s)" %(self.rand_id,)
            return

        scantype=self.name_to_type(m.group(1))
        x = m.group(2)
        y = m.group(3)
        z = m.group(4)
        tick = m.group(5)
        m = re.search('Scan time: ([^<]+)', page)
        scan_time=None
        if m:
            scan_time=dateutil.parser.parse(m.group(1))

        #check to see if we have already added this scan to the database
        p=loadable.planet(x, y, z)
        if p.load_most_recent(self.cursor): #really, this should never, ever fail.
            #quickly insert the scan incase someone else pastes it :o
            next_id=-1
            nxt_query= "SELECT nextval('scan_id_seq')"
            query = "INSERT INTO scan (id, tick, pid, nick, pnick, scantype, rand_id, group_id, scan_time) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"
            try:
                self.cursor.execute(nxt_query)
                next_id=self.cursor.dictfetchone()['nextval']
                self.cursor.execute(query, (next_id, tick, p.id, self.nick, self.pnick, scantype, self.rand_id, self.group_id, scan_time))
            except psycopg.IntegrityError, e:
                print "Scan %s may already exist" %(self.rand_id,)
                print e.__str__()
                return
            if next_id < 0:
                raise Exception("Scan id is %s"%(next_id,))
            if scantype=='planet':
                self.parse_planet(next_id,page)

            elif scantype=='development':
                self.parse_development(next_id,page)

            elif scantype=='unit':
                self.parse_unit(next_id,page,'unit')

            elif scantype=='news':
                self.parse_news(next_id,page)
            elif scantype=='jgp':
                self.parse_jumpgate(next_id,page)
            elif scantype=='au':
                self.parse_unit(next_id,page,'au')
Example #11
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
        planet = None
        param = m.group(1)
        m = self.paramre.search(param)

        if not m or not m.group(1):
            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 automatic " +
                    self.__class__.__name__ +
                    " command (log in with P and set mode +x, then make sure you've set your planet with the pref command)")
                #
                return 1
            if u.planet:
                planet = u.planet
            else:
                irc_msg.reply("Usage: %s" % (self.usage,))
                return 1
        else:
            m = self.coordre.search(param)
            if m:
                x = m.group(1)
                y = m.group(2)
                z = m.group(4)
                # assign param variables
                if z:
                    p = loadable.planet(x=x, y=y, z=z)
                    if not p.load_most_recent(self.cursor, irc_msg.round):
                        irc_msg.reply("No planet matching '%s' found" % (param,))
                        return 1
                    planet = p
            else:
                irc_msg.reply("Usage: %s (you must be registered for automatic lookup)" % (self.usage,))
                return 1
        if planet:
            reply = "%s:%s:%s can hit planets with value %d or above or score %d or above" % (
                planet.x, planet.y, planet.z, int(planet.value * .4), int(planet.score * .6))

        irc_msg.reply(reply)
        return 1
Example #12
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("Usage: %s" % (self.usage,))
            return 0
        # assign param variables
        params = m.group(1)
        m = self.planet_coordre.search(params)
        reply = ""
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        x = m.group(1)
        y = m.group(2)
        z = m.group(3)
        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

        query = "SELECT tick,nick,scantype,rand_id,tick"
        query += " FROM scan AS t1"
        query += " WHERE t1.pid=%s AND scantype='news' ORDER BY tick DESC LIMIT 10"
        self.cursor.execute(query, (p.id,))

        if self.cursor.rowcount > 0:
            s = self.cursor.dictfetchall()
            reply = "Latest news scans on %s:%s:%s - http://game.planetarion.com/showscan.pl?scan_id=%s" % (
                x,
                y,
                z,
                ", ".join(map(lambda x: "%s (pt %s)" % (x["rand_id"], x["tick"]), s)),
            )
        else:
            reply = "No news available on %s:%s:%s" % (x, y, z)
        irc_msg.reply(reply)

        return 1
Example #13
0
    def save_planet(self, irc_msg, u, x, y, z):
        p = loadable.planet(x=x, y=y, z=z)
        if not p.load_most_recent(self.cursor):
            irc_msg.reply("%s:%s:%s is not a valid planet" % (x, y, z))
            return 0

        if u.pref:
            query = "UPDATE user_list SET planet_id=%s WHERE id=%s"
            self.cursor.execute(query, (p.id, u.id))
            irc_msg.reply("Your planet has been saved as %s:%s:%s" % (x, y, z))
            return p.id
        else:
            raise Exception("This code /should/ be defunct now that prefs are in the user_list table")
            query = "INSERT INTO user_pref (id,planet_id) VALUES (%s,%s)"
            self.cursor.execute(query, (u.id, p.id))
            irc_msg.reply("Your planet has been saved as %s:%s:%s" % (x, y, z))
Example #14
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.planet_coordre.search(m.group(1))
        if  m:

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

            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

            query="SELECT scantype,max(tick) AS latest,count(*) AS count FROM scan WHERE pid=%s GROUP BY scantype"
            self.cursor.execute(query,(p.id,))

            reply=""
            if self.cursor.rowcount < 1:
                reply+="No scans available on %s:%s:%s" % (p.x,p.y,p.z)

            else:
                reply+="scans for %s:%s:%s -" % (p.x,p.y,p.z)
                prev=[]
                for p in self.cursor.dictfetchall():
                    prev.append("(%d %s, latest pt%s)" % (p['count'],p['scantype'],p['latest']))

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


            irc_msg.reply(reply)

        else:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0
        return 1
Example #15
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0
        victim=None
        params=m.group(1)
        m=self.planet_coordre.search(params)
        if m:
            victim=loadable.planet(x=m.group(1),y=m.group(2),z=m.group(3))
            if not victim.load_most_recent(self.cursor):
                irc_msg.reply("%s:%s:%s is not a valid planet" % (victim.x,victim.y,victim.z))
                return 1
            total_roids=victim.size
        else:
            m=self.paramre.search(params)
            if not m:
                irc_msg.reply("Usage: %s" % (self.usage,))
                return 0

            total_roids=int(m.group(1))

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

        reply=""
        cap=0
        cap_rate=.25
        u=self.load_user_from_pnick(user)
        if u and u.planet and victim:
            cap_rate=u.planet.cap_rate(victim)
        for i in range(1,5):
            cap+=int(total_roids*cap_rate)
            reply+="Wave %d: %d (%d), " % (i,int(total_roids*cap_rate),cap)
            total_roids = total_roids - int(total_roids*cap_rate)
        irc_msg.reply("Caprate: %s%% %s"%(int(cap_rate*100),reply.strip(', ')))

        return 1
Example #16
0
    def get_au(self,x,y,z,mission):
        p=loadable.planet(x=x,y=y,z=z)
        base={"x": x, "y": y, "z": z}
        if not p.load_most_recent(self.cursor):
            z=base.copy()
            val=z.update({"age": 1000})
            return val
        query="SELECT max_tick() - t1.tick AS age,t1.rand_id"
        query+=" FROM scan AS t1"
        query+=" WHERE t1.pid=%s"
        query+=" AND scantype='au'"
        query+=" ORDER BY tick DESC LIMIT 1"

        self.cursor.execute(query,(p.id,))
        if self.cursor.rowcount < 1:
            val={"age": 1000}
        else:
            val=self.cursor.dictfetchone()
        val['x']=x
        val['y']=y
        val['z']=z
        val['mission']=mission
        return val
Example #17
0
    def surprise(self, round, x=None, y=None, z=None, alliance=None):
        args = (round, round,)
        query = "SELECT t1.id AS attacker,count(t1.id) AS attacks "
        query += " FROM planet_canon AS t1"
        query += " INNER JOIN fleet AS t3 ON t1.id=t3.owner_id"
        query += " INNER JOIN planet_dump AS t4 ON t4.id=t3.target"
        query += " INNER JOIN intel AS t5 ON t3.target=t5.pid"
        query += " INNER JOIN alliance_canon AS t6 ON t5.alliance_id=t6.id"
        query += " WHERE mission = 'attack'"
        query += " AND t4.tick=(SELECT max_tick(%s::smallint)) AND t4.round=%s"

        if x and y:
            query += " AND t4.x=%s AND t4.y=%s"
            args += (x, y)
        if z:
            query += " AND t4.z=%s"
            args += (z,)

        if alliance:
            query += " AND t6.name ilike %s"
            args += ('%' + alliance + '%',)

        query += " GROUP BY t1.id"
        query += " ORDER BY count(t1.id) DESC"

        self.cursor.execute(query, args)
        attackers = self.cursor.dictfetchall()
        if not len(attackers):
            reply = "No fleets found targeting"
            if x and y:
                reply += " coords %s:%s" % (x, y)
            if z:
                reply += ":%s" % (z,)
            if alliance:
                reply += " alliance %s" % (alliance,)
        else:
            reply = "Top attackers on"
            if x and y:
                reply += " coords %s:%s" % (x, y)
            if z:
                reply += ":%s" % (z,)
            if alliance:
                reply += " alliance %s" % (alliance,)
            reply += " are "
            i = 0
            prev = []
            for a in attackers:
                if i > 4:
                    break
                else:
                    i += 1

                p = loadable.planet(id=a['attacker'])
                if not p.load_most_recent(self.cursor, round):
                    i -= 1
                    pass
                prev.append("%s:%s:%s - %s" % (p.x, p.y, p.z, a['attacks']))

            reply += ' | '.join(prev)

        return reply
Example #18
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.match(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        # assign param variables
        params = m.group(1)
        m = self.planet_coordre.search(params)

        current_tick = self.current_tick()

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

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

            reply = "%s:%s:%s" % (x, y, z)

            query = "SELECT start_tick, end_tick"
            query += " FROM anarchy"
            query += " INNER JOIN planet_dump ON anarchy.pid = planet_dump.id"
            query += " WHERE planet_dump.tick = %s"
            query += " AND planet_dump.x = %s"
            query += " AND planet_dump.y = %s"
            query += " AND planet_dump.z = %s"
            query += " ORDER BY end_tick ASC"
            self.cursor.execute(query, (current_tick, x, y, z))
            current_end_tick = None
            anarchy_list = []
            for period in self.cursor.dictfetchall():
                end = period['end_tick']
                if end > current_tick:
                    current_end_tick = end
                else:
                    anarchy_list.append("%d-%d" % (period['start_tick'], period['end_tick']))
            if len(anarchy_list) == 0:
                reply += " has had no previous periods of anarchy"
            else:
                reply += " was previously in anarchy between ticks: %s" % (", ".join(anarchy_list))

            if current_end_tick:
                reply += " and is currently in anarchy until tick %d" % (current_end_tick)
                needed_scans = []

                # Get guards from planet scan.
                query = "SELECT scan.tick, guards"
                query += " FROM scan INNER JOIN planet ON scan.id = planet.scan_id"
                query += " WHERE scan.pid = %s "
                query += " ORDER BY scan.scan_time DESC"
                query += " LIMIT 1"
                self.cursor.execute(query,(planet.id,))
                if self.cursor.rowcount < 1:
                    needed_scans.append('planet')
                else:
                    planet_scan = self.cursor.dictfetchone()
                    guards = planet_scan['guards']
                    planet_tick = planet_scan['tick']

                # Get SCs and total number of constructions from development
                # scan.
                query = "SELECT scan.tick, light_factory, medium_factory, heavy_factory, wave_amplifier, wave_distorter, metal_refinery,"
                query += " crystal_refinery, eonium_refinery, research_lab, finance_centre, military_centre, security_centre, structure_defense"
                query += " FROM scan INNER JOIN development ON scan.id = development.scan_id"
                query += " WHERE scan.pid = %s"
                query += " ORDER BY scan.scan_time DESC"
                query += " LIMIT 1"
                self.cursor.execute(query,(planet.id,))
                if self.cursor.rowcount < 1:
                    needed_scans.append('development')

                if len(needed_scans) == 0:
                    dev_scan = self.cursor.dictfetchone()
                    sc = dev_scan['security_centre']
                    total = (dev_scan['light_factory']+dev_scan['medium_factory']+dev_scan['heavy_factory']+
                             dev_scan['wave_amplifier']+dev_scan['wave_distorter']+
                             dev_scan['metal_refinery']+dev_scan['crystal_refinery']+dev_scan['eonium_refinery']+
                             dev_scan['research_lab']+dev_scan['structure_defense']+
                             dev_scan['finance_centre']+dev_scan['military_centre']+dev_scan['security_centre']
                    )
                    development_tick = dev_scan['tick']

                    min_alert = (1 - 0.15 +       float(sc) / total) * (50 + 5*float(guards) / float(planet.size + 1))
                    max_alert = (1 - 0.15 + 0.4 + float(sc) / total) * (50 + 5*float(guards) / float(planet.size + 1))
                    reply += ", with a minimum alert of %d and a maximum of %d (planet scan from pt%d, dev scan from pt%d)" % (
                        int(min_alert),
                        int(max_alert),
                        planet_tick,
                        development_tick
                    )
                else:
                    reply += ", need a %s scan to calculate alert" % (" and ".join(needed_scans))
            else:
                reply += " and is not currently in anarchy"
        else:
            query = "SELECT x, y, z"
            query += " FROM anarchy"
            query += " INNER JOIN planet_dump ON anarchy.pid = planet_dump.id"
            query += " WHERE end_tick > %s"
            query += " AND tick = %s"
            query += " ORDER BY x ASC, y ASC, z ASC"
            self.cursor.execute(query, (current_tick, current_tick))
            if self.cursor.rowcount < 1:
                reply = "There are currently no planets in anarchy. Get to it!"
            else:
                anarchy_list = map(lambda p: "%d:%d:%d" % (p['x'], p['y'], p['z']),
                                   self.cursor.dictfetchall())
                reply = "Planets currently in anarchy: %s" % (", ".join(anarchy_list))

        irc_msg.reply(reply)
        return 1
Example #19
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
        # assign param variables
        param = m.group(2)
        if not param:
            param = ""

        if access < self.level:
            if access >= 50:
                self.hacky_stupid_half_member_status(irc_msg)
                return 1
            irc_msg.reply("You do not have enough access to use this command")
            return 0
        curtick = self.current_tick(irc_msg.round)
        m = self.coordre.search(param)
        if m:
            x = m.group(1)
            y = m.group(2)
            z = m.group(4)
            when = m.group(6)
            if when:
                when = int(when)
            if when and when < 32:
                tick = curtick + when
            elif when and when < curtick:
                irc_msg.reply(
                    "Can not check status on the past. You wanted tick %s, but current tick is %s. (If you really need to know, poke %s.)" %
                    (when,
                     curtick,
                     self.config.get(
                         'Auth',
                         'owner_nick')))
                return 1
            elif when:
                tick = when

            args = ()
            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"

            if when:
                query += " t1.tick = %s AND t1.round = %s"
                args += (tick, irc_msg.round)
            else:
                query += " t1.tick > (SELECT max_tick(%s::smallint)) AND t1.round = %s"
                args += (irc_msg.round, irc_msg.round,)
            query += " AND t3.tick = (SELECT max_tick(%s::smallint)) AND t3.round = %s AND t3.x=%s AND t3.y=%s"
            args += (irc_msg.round, irc_msg.round,)

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

                query += " ORDER BY t1.tick ASC"

                self.cursor.execute(query, args + (x, y, z))
                if self.cursor.rowcount < 1:
                    reply = "No bookings matching planet %s:%s:%s" % (x, y, z)
                    if when:
                        reply += " for tick %s" % (tick,)
                    irc_msg.reply(reply)
                    return 1
                reply = "Status for %s:%s:%s -" % (x, y, z)
                if when:
                    res = self.cursor.dictfetchall()
                    type = "nick"
                    owner = res[0]['nick']
                    if res[0]['pnick']:
                        owner = res[0]['pnick']
                        type = "user"
                    reply += " booked for landing pt %s (eta %s) by %s %s" % (
                        res[0]['tick'], res[0]['tick'] - curtick, type, owner)

                else:
                    prev = []
                    for r in self.cursor.dictfetchall():
                        owner = "nick:" + r['nick']
                        if r['pnick']:
                            owner = "user:"******"(%s %s)" % (r['tick'], owner))

                    reply += " " + ', '.join(prev)
                irc_msg.reply(reply)
            else:
                query += " ORDER BY y, z, x, tick"

                self.cursor.execute(query, args + (x, y))

                if self.cursor.rowcount < 1:
                    reply = "No bookings matching galaxy %s:%s" % (x, y)
                    if when:
                        reply += " for tick %s" % (tick,)
                    irc_msg.reply(reply)
                    return 1
                ticks = {}
                for r in self.cursor.dictfetchall():
                    if r['tick'] not in ticks:
                        ticks[r['tick']] = []
                    ticks[r['tick']].append(r)

                reply = "Target information for %s:%s (by landing tick) -" % (x, y)
                sorted_keys = sorted(ticks.keys())
                for k in sorted_keys:
                    reply = ' '.join([reply, "Tick %s (eta %s)" % (k, k - curtick)])
                    booked_list = ticks[k]
                    prev = []
                    for p in booked_list:
                        owner = "nick:" + p['nick']
                        if p['pnick']:
                            owner = "user:"******"(%s %s)" % (p['z'], owner))

                    reply += " " + ', '.join(prev)
                    irc_msg.reply(reply.strip())
                    reply = ""
            return 1

        m = self.nickre.search(param)
        if m:
            subject = m.group(1)
            when = m.group(3)
            if when:
                when = int(when)
            if subject:
                subject = subject.strip()

            if when and when < 80:
                tick = curtick + when
            elif when and when < curtick:
                irc_msg.reply(
                    "Can not check status on the past. You wanted tick %s, but current tick is %s. (If you really need to know, poke %s.)" %
                    (when,
                     curtick,
                     self.config.get(
                         'Auth',
                         'owner_nick')))
                return 1
            elif when:
                tick = when

            if not subject:
                subject = irc_msg.user_or_nick()

            args = ()
            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"

            if when:
                query += " t1.tick = %s AND t1.round = %s"
                args += (tick, irc_msg.round,)
            else:
                query += " t1.tick > (SELECT max_tick(%s::smallint)) AND t1.round = %s"
                args += (irc_msg.round, irc_msg.round,)
            query += " AND t3.tick = (SELECT max_tick(%s::smallint)) AND t3.round = %s AND (t1.nick ILIKE %s OR t2.pnick ILIKE %s)"
            args += (irc_msg.round, irc_msg.round,)
            self.cursor.execute(query, args + ('%' + subject + '%', '%' + subject + '%'))
            if self.cursor.rowcount < 1:
                reply = "No active bookings matching nick/user %s" % (subject)
                irc_msg.reply(reply)
                return 1
            reply = "Bookings matching nick/user %s" % (subject)
            if when:
                reply += " for landing on tick %s (eta %s):" % (tick, tick - curtick)
                prev = []
                for b in self.cursor.dictfetchall():
                    tmp = "(%s:%s:%s as " % (b['x'], b['y'], b['z'])
                    if b['pnick']:
                        tmp += "user: %s" % (b['pnick'])
                    else:
                        tmp += "nick: %s" % (b['nick'])
                    tmp += ")"
                    prev.append(tmp)

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

            else:
                prev = []
                for b in self.cursor.dictfetchall():
                    tmp = "(%s:%s:%s landing pt%s/eta %s" % (b['x'], b['y'], b['z'], b['tick'], b['tick'] - curtick)
                    if b['pnick']:
                        tmp += " user:%s" % (b['pnick'])
                    else:
                        tmp += " nick:%s" % (b['nick'])
                    tmp += ")"
                    prev.append(tmp)
                reply += " " + ', '.join(prev)
            irc_msg.reply(reply)

        return 1
Example #20
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

        # assign param variables
        when=None
        x=m.group(1)
        y=m.group(2)
        z=m.group(3)
        when=m.group(5)
        if when: when=int(when)
        override=m.group(7)

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

        curtick=self.current_tick()
        tick=-1

        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

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


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

        if not override: # trying to unbook own target
            query="DELETE FROM target WHERE pid = %s "
            args=(p.id,)
            if when:
                query+=" AND tick = %s "
                args+=(tick,)
            else:
                query+=" AND tick > %s "
                args+=(curtick,)
            if u:
                #query+=" AND (uid ILIKE %s OR uid IS NULL)"
                query+=" AND uid = %s"
                args+=(u.id,)
            else:
                query+=" AND nick ILIKE %s"
                args+=(irc_msg.nick,)

            self.cursor.execute(query,args)
            if self.cursor.rowcount == 0:
                reply="You have no bookings matching %s:%s:%s" %(p.x,p.y,p.z)
                if when:
                    reply+=" for landing on tick %s"%(tick,)
                reply+=". If you are trying to unbook someone else's target, you must confirm with 'yes'."
            else:
                reply="You have unbooked %s:%s:%s"%(p.x,p.y,p.z)
                if when:
                    reply+=" for landing pt %s"%(tick,)
                else:
                    reply+=" for %d booking(s)"%(self.cursor.rowcount)
                reply+="."

        else:
            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 "
            args=(p.id,)
            if when:
                query+=" AND tick=%s"
                args+=(tick,)
            else:
                query+=" AND tick > %s"
                args+=(curtick,)
            self.cursor.execute(query,args)
            if self.cursor.rowcount < 1:
                reply="No bookings matching %s:%s:%s" %(p.x,p.y,p.z)
                if when:
                    reply+=" for landing on tick %s"%(tick,)
                irc_msg.reply(reply)
                return 1

            res=self.cursor.dictfetchall()

            query="DELETE FROM target WHERE pid = %s "
            args=(p.id,)
            if when:
                query+=" AND tick = %s "
                args+=(tick,)
            else:
                query+=" AND tick > %s "
                args+=(curtick,)

            self.cursor.execute(query,args)

            reply="You have unbooked %s:%s:%s"%(p.x,p.y,p.z)
            if when:
                owner=res[0]['nick']
                type="nick"
                if res[0]['pnick']:
                    owner=res[0]['pnick']
                    type="user"
                reply+=" for landing pt %s (previously held by %s %s)"%(res[0]['tick'],type,owner)
            else:
                reply+=" for %d booking(s): "%(self.cursor.rowcount)
                prev=[]
                for r in res:
                    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 #21
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("Usage: %s" % (self.usage,))
            return 0

        # assign param variables
        params=m.group(1)
        m=self.planet_coordre.search(params)

        reply=""
        if m:
            x=m.group(1)
            y=m.group(2)
            z=m.group(3)

            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

            query="SELECT t1.tick,t1.nick,t1.scantype,t1.rand_id,t3.name,t2.amount"
            query+=" FROM scan AS t1"
            query+=" INNER JOIN unit AS t2 ON t1.id=t2.scan_id"
            query+=" INNER JOIN ship AS t3 ON t2.ship_id=t3.id"
            query+=" WHERE t1.pid=%s AND t1.id=(SELECT id FROM scan WHERE pid=t1.pid AND scantype='unit' ORDER BY tick DESC LIMIT 1)"
            self.cursor.execute(query,(p.id,))

            if self.cursor.rowcount < 1:
                reply+="No unit scans available on %s:%s:%s" % (p.x,p.y,p.z)
            else:

                reply+="Newest unit scan on %s:%s:%s" % (p.x,p.y,p.z)

                prev=[]
                for s in self.cursor.dictfetchall():
                    prev.append("%s %s" % (s['name'],s['amount']))
                    tick=s['tick']
                    rand_id=s['rand_id']

                reply+=" (id: %s, pt: %s) " % (rand_id,tick)
                reply+=string.join(prev,' | ')
        else:
            m=self.idre.search(params)
            if not m:
                irc_msg.reply("Usage: %s" % (self.usage,))
                return 0

            rand_id=m.group(1)

            query="SELECT x,y,z,t1.tick,t1.nick,t1.scantype,t1.rand_id,t3.name,t2.amount"
            query+=" FROM scan AS t1"
            query+=" INNER JOIN unit AS t2 ON t1.id=t2.scan_id"
            query+=" INNER JOIN ship AS t3 ON t2.ship_id=t3.id"
            query+=" INNER JOIN planet_dump AS t4 ON t1.pid=t4.id"
            query+=" WHERE t4.tick=(SELECT max_tick()) AND t1.rand_id=%s"
            self.cursor.execute(query,(rand_id,))

            if self.cursor.rowcount < 1:
                reply+="No planet scans matching ID %s" % (rand_id,)
            else:
                reply+="Newest unit scan on "

                prev=[]
                for s in self.cursor.dictfetchall():
                    prev.append("%s %s" % (s['name'],s['amount']))
                    tick=s['tick']
                    x=s['x']
                    y=s['y']
                    z=s['z']

                reply+="%s:%s:%s (id: %s, pt: %s) " % (x,y,z,rand_id,tick)
                reply+=string.join(prev,' | ')
        irc_msg.reply(reply)
        return 1
Example #22
0
File: jgp.py Project: munin/munin
    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("Usage: %s" % (self.usage,))
            return 0

        # assign param variables
        params = m.group(1)
        m = self.planet_coordre.search(params)

        reply = ""
        if m:
            x = m.group(1)
            y = m.group(2)
            z = m.group(3)

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

            query = "SELECT t3.x,t3.y,t3.z,t1.tick AS tick,t1.nick,t1.scantype,t1.rand_id,t2.mission,t2.fleet_size,t2.fleet_name,t2.landing_tick-t1.tick AS eta"
            query += " FROM scan AS t1"
            query += " INNER JOIN fleet AS t2 ON t1.id=t2.scan_id"
            query += " INNER JOIN planet_dump AS t3 ON t2.owner_id=t3.id"
            query += " WHERE t1.pid=%s AND t3.tick=(SELECT max_tick(%s::smallint)) AND t3.round=%s"
            query += " AND t1.id=(SELECT id FROM scan WHERE pid=t1.pid AND scantype='jgp'"
            query += " ORDER BY tick DESC, id DESC LIMIT 1) ORDER BY eta ASC"
            self.cursor.execute(query, (p.id, irc_msg.round, irc_msg.round,))

            if self.cursor.rowcount < 1:
                if self.fallback(irc_msg, p, None, irc_msg.round):
                    return 1
                else:
                    reply += "No JGP scans available on %s:%s:%s" % (p.x, p.y, p.z)

            else:
                reply += "Newest JGP scan on %s:%s:%s" % (p.x, p.y, p.z)

                prev = []
                for s in self.cursor.dictfetchall():
                    prev.append(
                        "(%s:%s:%s %s | %s %s %s)" %
                        (s['x'],
                         s['y'],
                            s['z'],
                            s['fleet_name'],
                            s['fleet_size'],
                            s['mission'],
                            s['eta']))
                    tick = s['tick']
                    rand_id = s['rand_id']

                reply += " (id: %s, pt: %s) " % (rand_id, tick)
                reply += ' | '.join(prev)
                if len(reply) > 450:
                    reply = " Newest JGP scan on %s:%s:%s (pt: %s) " % (x, y, z, tick)
                    reply += "http://game.planetarion.com/showscan.pl?scan_id=%s" % (rand_id,)
        else:
            m = self.idre.search(params)
            if not m:
                irc_msg.reply("Usage: %s" % (self.usage,))
                return 0

            rand_id = m.group(1)

            query = "SELECT t4.x AS targ_x,t4.y AS targ_y,t4.z AS targ_z,t1.tick,t1.nick,t1.scantype,t1.rand_id,t2.mission,t2.fleet_size,t2.fleet_name,t2.landing_tick-t1.tick AS eta"
            query += ",t5.x AS x,t5.y AS y,t5.z AS z"
            query += " FROM scan AS t1"
            query += " INNER JOIN fleet AS t2 ON t1.id=t2.scan_id"
            query += " INNER JOIN planet_dump AS t4 ON t1.pid=t4.id"
            query += " INNER JOIN planet_dump AS t5 ON t4.tick=t5.tick AND t2.owner_id=t5.id"
            query += " WHERE t4.tick=(SELECT max_tick(%s::smallint)) AND t4.round=%s AND t1.rand_id=%s"
            self.cursor.execute(query, (irc_msg.round, irc_msg.round, rand_id,))

            if self.cursor.rowcount < 1:
                if self.fallback(irc_msg, None, rand_id, irc_msg.round):
                    return 1
                else:
                    reply += "No JGP scans matching ID %s" % (rand_id,)
            else:
                reply += "Newest JGP scan on "

                prev = []
                for s in self.cursor.dictfetchall():
                    prev.append(
                        "(%s:%s:%s %s | %s %s %s)" %
                        (s['x'],
                         s['y'],
                            s['z'],
                            s['fleet_name'],
                            s['fleet_size'],
                            s['mission'],
                            s['eta']))
                    tick = s['tick']
                    x = s['targ_x']
                    y = s['targ_y']
                    z = s['targ_z']
                reply += "%s:%s:%s (id: %s, pt: %s) " % (x, y, z, rand_id, tick)
                reply += ' | '.join(prev)
        irc_msg.reply(reply)
        return 1
Example #23
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0
        print access, irc_msg.access, irc_msg.target
        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 or not m.group(1):
            u=loadable.user(pnick=irc_msg.user)
            if not u.load_from_db(self.cursor):
                irc_msg.reply("You must be registered to use the automatic "+self.__class__.__name__+" command (log in with P and set mode +x, then make sure you've set your planet with the pref command)")
                return 1
            if u.planet:
                irc_msg.reply(str(u.planet))
            else:
                irc_msg.reply("Usage: %s" % (self.usage,))
            return 1
        param=m.group(1)
        m=self.coordre.search(param)
        if m:
            x=m.group(1)
            y=m.group(2)
            z=m.group(4)
            # assign param variables

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

        #check if this is an alliance
        a=loadable.alliance(name=param.strip())
        if a.load_most_recent(self.cursor):
            irc_msg.reply(str(a))
            return
        u=self.load_user_from_pnick(param.strip())
        if u and irc_msg.access >= 100:
            if u.planet:
                irc_msg.reply(str(u.planet))
            else:
                irc_msg.reply("User %s has not entered their planet details" % (u.pnick,))
            return 
        irc_msg.reply("No alliance or user matching '%s' found" % (param,))
        return
        

        # do stuff here

        return
Example #24
0
                traceback.print_exc()
                continue

            print 'Incoming: ' + newstick + ':' + fleetname + '-' + originx + ':' + originy + ':' + originz + '-' + arrivaltick + '|' + numships

    #launched attacking fleets
    #<td class=left valign=top>Launch</td><td valign=top>848</td><td class=left valign=top>The Disposable Heroes fleet has been launched, heading for 15:9:8, on a mission to Attack. Arrival tick: 857</td>
        for m in re.finditer('<td class="left" valign="top">Launch</td><td valign="top">(\d+)</td><td class="left" valign="top">The ([^,]+) fleet has been launched, heading for (\d+):(\d+):(\d+), on a mission to Attack. Arrival tick: (\d+)</td>', page):
            newstick = m.group(1)
            fleetname = m.group(2)
            originx = m.group(3)
            originy = m.group(4)
            originz = m.group(5)
            arrivaltick = m.group(6)

            target=loadable.planet(originx,originy,originz)
            if not target.load_most_recent(self.cursor):
                continue
            query="INSERT INTO fleet (scan_id,owner_id,target,fleet_name,launch_tick,landing_tick,mission) VALUES (%s,%s,%s,%s,%s,%s,'attack')"

            try:
                self.cursor.execute(query,(scan_id,p.id,target.id,fleetname,newstick,arrivaltick))
            except Exception, e:
                print "Exception in news: "+e.__str__()
                traceback.print_exc()
                continue

            print 'Attack:' + newstick + ':' + fleetname + ':' + originx + ':' + originy + ':' + originz + ':' + arrivaltick

    #launched defending fleets
    #<td class=left valign=top>Launch</td><td valign=top>847</td><td class=left valign=top>The Ship Collection fleet has been launched, heading for 2:9:14, on a mission to Defend. Arrival tick: 853</td>
Example #25
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 #26
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("Usage: %s" % (self.usage,))
            return 0

        # assign param variables
        params = m.group(1)
        m = self.planet_coordre.search(params)

        reply = ""
        if m:
            x = m.group(1)
            y = m.group(2)
            z = m.group(3)

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

            query = "SELECT tick,nick,scantype,rand_id,timestamp,roid_metal,roid_crystal,roid_eonium,res_metal,res_crystal,res_eonium"
            query += ", prod_res,agents,guards"
            query += " FROM scan AS t1 INNER JOIN planet AS t2 ON t1.id=t2.scan_id"
            query += " WHERE t1.pid=%s AND t1.round=%s ORDER BY timestamp DESC"
            self.cursor.execute(query, (p.id, irc_msg.round,))

            if self.cursor.rowcount < 1:
                reply += "No planet scans available on %s:%s:%s" % (p.x, p.y, p.z)
            else:
                s = self.cursor.dictfetchone()
                reply += "Newest planet scan on %s:%s:%s (id: %s, pt: %s)" % (p.x, p.y, p.z, s['rand_id'], s['tick'])
                reply += " Roids: (m:%s, c:%s, e:%s) | Resources: (m:%s, c:%s, e:%s)" % (
                    s['roid_metal'], s['roid_crystal'], s['roid_eonium'], s['res_metal'], s['res_crystal'], s['res_eonium'])
                reply += " | Hidden: %s | Agents: %s | Guards: %s" % (s['prod_res'], s['agents'], s['guards'])
                i = 0
                reply += " | Older scans: "
                prev = []
                for s in self.cursor.dictfetchall():
                    i += 1
                    if i > 4:
                        break
                    prev.append("(%s,pt%s)" % (s['rand_id'], s['tick']))
                reply += ', '.join(prev)

        else:
            m = self.idre.search(params)
            if not m:
                irc_msg.reply("Usage: %s" % (self.usage,))
                return 0

            rand_id = m.group(1)

            query = "SELECT x,y,z,t1.tick AS tick,nick,scantype,rand_id,timestamp,roid_metal,roid_crystal,roid_eonium,res_metal,res_crystal,res_eonium"
            query += ", prod_res,agents,guards"
            query += " FROM scan AS t1 INNER JOIN planet AS t2 ON t1.id=t2.scan_id"
            query += " INNER JOIN planet_dump AS t3 ON t1.pid=t3.id"
            query += " WHERE t3.tick=(SELECT max_tick(%s::smallint)) AND t3.round=%s AND t1.rand_id=%s ORDER BY timestamp DESC"
            self.cursor.execute(query, (irc_msg.round, irc_msg.round, rand_id,))

            if self.cursor.rowcount < 1:
                reply += "No planet scans matching ID %s" % (rand_id,)
            else:
                s = self.cursor.dictfetchone()
                reply += "Newest planet scan on %s:%s:%s (id: %s, pt: %s)" % (
                    s['x'], s['y'], s['z'], s['rand_id'], s['tick'])
                reply += " Roids: (m:%s, c:%s, e:%s) | Resources: (m:%s, c:%s, e:%s)" % (
                    s['roid_metal'], s['roid_crystal'], s['roid_eonium'], s['res_metal'], s['res_crystal'], s['res_eonium'])
                reply += " | Hidden: %s | Agents: %s | Guards: %s" % (s['prod_res'], s['agents'], s['guards'])

        irc_msg.reply(reply)
        return 1
Example #27
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("Usage: %s" % (self.usage,))
            return 0

        # assign param variables
        reply = ""
        x = m.group(1)
        y = m.group(2)
        z = m.group(3)
        ship_name = m.group(4)

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

        query = "SELECT tick,nick,scantype,rand_id,timestamp,roid_metal,roid_crystal,roid_eonium,res_metal,res_crystal,res_eonium"
        query += ", factory_usage_light, factory_usage_medium, factory_usage_heavy, prod_res"
        query += " FROM scan AS t1 INNER JOIN planet AS t2 ON t1.id=t2.scan_id"
        query += " WHERE t1.pid=%s ORDER BY timestamp DESC"
        self.cursor.execute(query, (p.id,))

        if self.cursor.rowcount < 1:
            reply += "No planet scans available on %s:%s:%s" % (p.x, p.y, p.z)
        else:
            s = self.cursor.dictfetchone()
            tick = s['tick']
            res_m = int(s['res_metal'])
            res_c = int(s['res_crystal'])
            res_e = int(s['res_eonium'])
            prod_res = int(s['prod_res'])
            rand_id = s['rand_id']

            query = "SELECT name,class,metal,crystal,eonium,total_cost"
            query += " FROM ship WHERE name ilike %s AND round = %s LIMIT 1"
            self.cursor.execute(query, ('%' + ship_name + '%', irc_msg.round,))

            ship = self.get_ship_from_db(ship_name, irc_msg.round)
            if not ship:
                reply = "%s is not a ship" % (ship_name)
            else:
                cost_m = ship['metal']
                cost_c = ship['crystal']
                cost_e = ship['eonium']
                total_cost = ship['total_cost']
                class_factory_table = {
                    'Fighter': 'factory_usage_light',
                    'Corvette': 'factory_usage_light',
                    'Frigate': 'factory_usage_medium',
                    'Destroyer': 'factory_usage_medium',
                    'Cruiser': 'factory_usage_heavy',
                    'Battleship': 'factory_usage_heavy'}
                prod_modifier_table = {'None': 0, 'Low': 33, 'Medium': 66, 'High': 100}

                capped_number = min(res_m / cost_m, res_c / cost_c, res_e / cost_e)
                overflow = res_m + res_c + res_e - (capped_number * (cost_m + cost_c + cost_e))
                buildable = capped_number + ((overflow * .95) / total_cost)

                demo_modifier = 1 / (1 - float(self.config.get('Planetarion', 'democracy_cost_reduction')))
                tota_modifier = 1 / (1 - float(self.config.get('Planetarion', 'totalitarianism_cost_reduction')))
                reply = "Newest planet scan on %s:%s:%s (id: %s, pt: %s)" % (p.x, p.y, p.z, rand_id, tick)

                buildable_from_prod = 0

                if prod_res == 0:
                    reply += " has nothing in production. Can afford from stockpile:"
                else:
                    factory_usage = s[class_factory_table[ship['class']]]
                    max_prod_modifier = prod_modifier_table[factory_usage]
                    if max_prod_modifier == 0:
                        reply += " only has production in wrong factory type(s). Can afford from stockpile:"
                    else:
                        buildable_from_prod = max_prod_modifier * prod_res / 100 / total_cost

                        reply += " has %d res in production at %s usage: %s: %d | Democracy: %d | Totalitarianism: %d. Counting stockpile:" % (
                            prod_res,
                            factory_usage,
                            ship['name'],
                            int(buildable_from_prod),
                            int(buildable_from_prod * demo_modifier),
                            int(buildable_from_prod * tota_modifier)
                        )

                reply += " %s: %d | Democracy: %d | Totalitarianism: %d" % (
                    ship['name'],
                    int(buildable_from_prod + buildable),
                    int((buildable_from_prod + buildable) * demo_modifier),
                    int((buildable_from_prod + buildable) * demo_modifier),
                )

        irc_msg.reply(reply)
        return 1
Example #28
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

        params=m.group(1)

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

        roid_count = -1

        victim = None
        attacker = None

        m=self.planet_coordre.search(params)
        if m:
            victim = loadable.planet(x=m.group(1),y=m.group(2),z=m.group(3))
            if not victim.load_most_recent(self.cursor):
                irc_msg.reply("%s:%s:%s is not a valid planet" % (victim.x,victim.y,victim.z))
                return 1
            params=params[m.end():]

        m=self.planet_coordre.search(params)
        if m:
            attacker = loadable.planet(x=m.group(1),y=m.group(2),z=m.group(3))
            if not attacker.load_most_recent(self.cursor):
                irc_msg.reply("%s:%s:%s is not a valid planet" % (attacker.x,attacker.y,attacker.z))
                return 1
            params=params[m.end():]

        if not victim:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 1

        if victim and not attacker:
            u=loadable.user(pnick=irc_msg.user)
            if not u.load_from_db(self.cursor):
		irc_msg.reply("You must be registered to use the automatic "+self.__class__.__name__+" command (log in with P and set mode +x, then make sure your planet is set with the pref command)")
                return 1
            if u.planet_id:
                attacker = u.planet
            else:
                irc_msg.reply("Usage: %s (you must be registered for automatic lookup)" % (self.usage,))
                return 1

        if roid_count > -1:
            reply="Capturing %s roids " % (roid_count,)
            victim_val = victim.value
            victim_score = victim.score
            reply+="from %s:%s:%s (%s|%s) "%(victim.x,victim.y,victim.z,
                                          self.format_value(victim_val*100),self.format_value(victim_score*100))

            attacker_val = attacker.value
            attacker_score = attacker.score
            reply+="will earn %s:%s:%s (%s|%s) "%(attacker.x,attacker.y,attacker.z,
                                               self.format_value(attacker_val*100),self.format_value(attacker_score*100))

            bravery = max(0,(min(2,float(victim_val)/attacker_val)-0.1 ) * (min(2,float(victim_score)/attacker_score)-0.2))
            bravery *= 10
            xp=int(bravery*roid_count)

            reply+="XP: %s, Score: %s (Bravery: %.2f)" % (xp,xp*60,bravery)
            irc_msg.reply(reply)
        else:
            reply="Target "
            victim_val = victim.value
            attacker_val = attacker.value
            victim_score = victim.score
            attacker_score = attacker.score

            reply+="%s:%s:%s (%s|%s) "%(victim.x,victim.y,victim.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))

            bravery=attacker.bravery(victim)

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

            cap=int(attacker.cap_rate(victim)*victim.size)
            xp=attacker.calc_xp(victim)
            reply+="| Roids: %s | XP: %s | Score: %s" % (cap,xp,xp*60)
            irc_msg.reply(reply)

        return 1
Example #29
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("Usage: %s" % (self.usage,))
            return 0

        # assign param variables
        params=m.group(1)
        m=self.planet_coordre.search(params)

        reply=""
        if m:
            x=m.group(1)
            y=m.group(2)
            z=m.group(3)

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

            query="SELECT t2.id AS id,t1.tick,nick,scantype,rand_id,travel,infrastructure,hulls,waves,core,covert_op,mining"
            query+=",light_factory,medium_factory,heavy_factory,wave_amplifier,wave_distorter"
            query+=",metal_refinery,crystal_refinery,eonium_refinery,research_lab,finance_centre,security_centre"
            query+=" FROM scan AS t1 INNER JOIN development AS t2 ON t1.id=t2.scan_id"
            query+=" WHERE t1.pid=%s ORDER BY t1.tick DESC"
            self.cursor.execute(query,(p.id,))

            if self.cursor.rowcount < 1:
                reply+="No dev scans available on %s:%s:%s" % (p.x,p.y,p.z)
            else:
                s=self.cursor.dictfetchone()

                total=self.get_total_cons_from_scan(self.cursor,s['id'])

                reply+="Newest development scan on %s:%s:%s (id: %s, pt: %s)" % (p.x,p.y,p.z,s['rand_id'],s['tick'])
                reply+=" Travel: %s, Infrajerome: %s, Hulls: %s, Waves: %s, Core: %s, Covop: %s, Mining: %s"%(s['travel'],self.infra(s['infrastructure']),self.hulls(s['hulls']),
                                                                                                              self.waves(s['waves']),s['core'],self.covop(s['covert_op']),
                                                                                                              self.mining(s['mining']))



                irc_msg.reply(reply)
                reply="Structures: LFac: %s, MFac: %s, HFac: %s, Amp: %s, Dist: %s, MRef: %s, CRef: %s, ERef: %s, ResLab: %s (%s%%), FC: %s, Sec: %s (%s%%) " % (s['light_factory'],s['medium_factory'],
                                                                                                                                                       s['heavy_factory'],s['wave_amplifier'],
                                                                                                                                                       s['wave_distorter'],s['metal_refinery'],
                                                                                                                                                       s['crystal_refinery'],s['eonium_refinery'],
                                                                                                                                                       s['research_lab'],
                                                                                                                                                       int(float(s['research_lab'])/total*100),
                                                                                                                                                       s['finance_centre'],
                                                                                                                                                       s['security_centre'],
                                                                                                                                                       int(float(s['security_centre'])/total*100))
                i=0
                reply+=" Older scans: "
                prev=[]
                for s in self.cursor.dictfetchall():
                    i+=1
                    if i > 4:
                        break
                    prev.append("(%s,pt%s)" % (s['rand_id'],s['tick']))
                reply+=string.join(prev,', ')

        else:
            m=self.idre.search(params)
            if not m:
                irc_msg.reply("Usage: %s" % (self.usage,))
                return 0

            rand_id=m.group(1)
            query="SELECT t2.id AS id,t1.tick,nick,scantype,rand_id,travel,infrastructure,hulls,waves,core,covert_op,mining"
            query+=",light_factory,medium_factory,heavy_factory,wave_amplifier,wave_distorter"
            query+="+metal_refinery+crystal_refinery+eonium_refinery+research_lab+finance_centre+security_centre"
            query+=" FROM scan AS t1 INNER JOIN development AS t2 ON t1.id=t2.scan_id"
            query+=" INNER JOIN planet_dump AS t3 ON t1.pid=t3.id"
            query+=" WHERE t3.tick=(SELECT max_tick()) AND t1.rand_id=%s ORDER BY t1.tick DESC"
            self.cursor.execute(query,(rand_id,))

            if self.cursor.rowcount < 1:
                reply+="No dev scans matching ID %s" % (rand_id,)
            else:
                s=self.cursor.dictfetchone()

                query="SELECT light_factory+medium_factory+heavy_factory+wave_amplifier+wave_distorter"
                query+="+metal_refinery+crystal_refinery+eonium_refinery+research_lab+finance_centre+security_centre"
                query+=" AS total FROM development WHERE id=%s"

                self.cursor.execute(query,(s['id'],))
                total=self.cursor.dictfetchone()['total']

                reply+="Development scan on %s:%s:%s (id: %s, pt: %s)" % (s['x'],s['y'],s['z'],s['rand_id'],s['tick'])
                reply+=" Travel: %s, Infrajerome: %s, Hulls: %s, Waves: %s, Core: %s, Covop: %s, Mining: %s"%(s['travel'],self.infra(s['infrastructure']),self.hulls(s['hulls']),
                                                                                                              self.waves(s['waves']),s['core'],self.covop(s['covert_op']),
                                                                                                              self.mining(s['mining']))
                irc_msg.reply(reply)
                reply="Surface: LFac: %s, MFac: %s, HFac: %s, Amp: %s, Dist: %s, MRef: %s, CRef: %s, ERef: %s, ResLab: %s (%s%%), FC: %s, Sec: %s (%s%%) " % (s['light_factory'],s['medium_factory'],
                                                                                                                                                       s['heavy_factory'],s['wave_amplifier'],
                                                                                                                                                       s['wave_distorter'],s['metal_refinery'],
                                                                                                                                                       s['crystal_refinery'],s['eonium_refinery'],
                                                                                                                                                       s['research_lab'],
                                                                                                                                                       int(float(s['research_lab'])/total*100),
                                                                                                                                                       s['finance_centre'],
                                                                                                                                                       s['security_centre'],
                                                                                                                                                       int(float(s['security_centre'])/total*100))

        irc_msg.reply(reply)

        return 1
Example #30
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
        params=m.group(1)
        m=self.paramre.search(params)
        if m:
            x=m.group(1)
            y=m.group(2)
            z=m.group(3)
            tick=m.group(4)

            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

            query="SELECT t1.value,t1.value-t2.value AS vdiff,t1.size-t2.size AS sdiff"
            query+=" FROM planet_dump AS t1"
            query+=" INNER JOIN planet_dump AS t2"
            query+=" ON t1.id=t2.id AND t1.tick-1=t2.tick"
            query+=" WHERE t1.tick=%s AND t1.id=%s"

            reply=""

            self.cursor.execute(query,(tick,p.id))
            if self.cursor.rowcount<1:
                reply+="No data for %s:%s:%s on tick %s" % (p.x,p.y,p.z,tick)
            else:
                x=self.cursor.dictfetchone()

                reply+="Value on pt%s for %s:%s:%s: " % (tick,p.x,p.y,p.z)
                reply+="value: %s (%s%s) " % (x['value'],["+","-"][x['vdiff']<0],abs(x['vdiff']))
                if x['sdiff']!=0:
                    reply+="roids: %s%s" % (["+","-"][x['sdiff']<0],abs(x['sdiff']))
            irc_msg.reply(reply)
            return 1


        m=self.planet_coordre.search(params)
        if  m:
            x=m.group(1)
            y=m.group(2)
            z=m.group(3)

            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

            #query="SELECT tick,t1.value,t1.value-t2.value AS diff FROM planet_dump AS t1 INNER JOIN planet_dump AS t2 ON
            query="SELECT t1.tick,t1.value,t1.value-t2.value AS vdiff,t1.size-t2.size AS sdiff"
            query+=" FROM planet_dump AS t1"
            query+=" INNER JOIN planet_dump AS t2"
            query+=" ON t1.id=t2.id AND t1.tick-1=t2.tick"
            query+=" WHERE t1.tick>(SELECT max_tick()-16) AND t1.id=%s"
            query+=" ORDER BY t1.tick ASC"

            self.cursor.execute(query,(p.id,))

            reply=""

            if self.cursor.rowcount<1:
                reply+="No data for %s:%s:%s" % (p.x,p.y,p.z)
            else:
                results=self.cursor.dictfetchall()

                reply+="Value in the last 15 ticks on %s:%s:%s: " % (p.x,p.y,p.z)

                info=map(lambda x: "pt%s %s (%s%s)" % (x['tick'],self.format_value(x['value']*100),["+","-"][x['vdiff']<0],
                                                         self.format_value(abs(x['vdiff']*100)))+
                         [" roids:"+["+","-"][x['sdiff']<0]+str(abs(x['sdiff'])),""][x['sdiff']==0],results)

                print info
                reply+=str.join(' | ',info)
            irc_msg.reply(reply)
        return 1