Beispiel #1
0
Datei: parser.py Projekt: JDD/DLR
    def parse_N(self, scan_id, scan, page):
        #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):
            fleetscan = FleetScan()

            newstick = m.group(1)
            fleetname = m.group(2)
            originx = m.group(3)
            originy = m.group(4)
            originz = m.group(5)
            arrivaltick = int(m.group(6))
            numships = m.group(7)

            fleetscan.mission = "Unknown"
            fleetscan.fleet_name = fleetname
            fleetscan.launch_tick = newstick
            fleetscan.landing_tick = arrivaltick
            fleetscan.fleet_size = numships

            owner=Planet.load(originx,originy,originz)
            if owner is None:
                continue
            fleetscan.owner = owner
            fleetscan.target = scan.planet
            try:
                scan.fleets.append(fleetscan)
                session.commit()
            except Exception, e:
                session.rollback()
                scanlog("Exception in news: %s"%(str(e),), traceback=True)
                continue

            scanlog('Incoming: ' + newstick + ':' + fleetname + '-' + originx + ':' + originy + ':' + originz + '-' + arrivaltick + '|' + numships)
Beispiel #2
0
    def parse_D(self, scan_id, scan, page):
        devscan = scan.devscan = DevScan()

        m=re.search("""
            <tr><td[^>]*>Light\s+Factory</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Medium\s+Factory</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Heavy\s+Factory</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Wave\s+Amplifier</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Wave\s+Distorter</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Metal\s+Refinery</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Crystal\s+Refinery</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Eonium\s+Refinery</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Research\s+Laboratory</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Finance\s+Centre</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Security\s+Centre</td><td[^>]*>(\d*)</td></tr>
        """, page,re.VERBOSE)

        devscan.light_factory = m.group(1)
        devscan.medium_factory = m.group(2)
        devscan.heavy_factory = m.group(3)
        devscan.wave_amplifier = m.group(4)
        devscan.wave_distorter = m.group(5)
        devscan.metal_refinery = m.group(6)
        devscan.crystal_refinery = m.group(7)
        devscan.eonium_refinery = m.group(8)
        devscan.research_lab = m.group(9)
        devscan.finance_centre = m.group(10)
        devscan.security_centre = m.group(11)

        m = re.search("""
            <tr><td[^>]*>Space\s+Travel</td><td[^>]*>(\d+)</td></tr>\s*
            <tr><td[^>]*>Infrastructure</td><td[^>]*>(\d+)</td></tr>\s*
            <tr><td[^>]*>Hulls</td><td[^>]*>(\d+)</td></tr>\s*
            <tr><td[^>]*>Waves</td><td[^>]*>(\d+)</td></tr>\s*
            <tr><td[^>]*>Core\s+Extraction</td><td[^>]*>(\d+)</td></tr>\s*
            <tr><td[^>]*>Covert\s+Ops</td><td[^>]*>(\d+)</td></tr>\s*
            <tr><td[^>]*>Asteroid\s+Mining</td><td[^>]*>(\d+)</td></tr>
        """, page,re.VERBOSE)

        devscan.travel = m.group(1)
        devscan.infrastructure = m.group(2)
        devscan.hulls = m.group(3)
        devscan.waves = m.group(4)
        devscan.core = m.group(5)
        devscan.covert_op = m.group(6)
        devscan.mining = m.group(7)

        session.commit()

        if scan.planet.intel is None:
            scan.planet.intel = Intel()
        if (scan.planet.intel.dists < devscan.wave_distorter) or (scan.tick == Updates.current_tick()):
            scan.planet.intel.dists = devscan.wave_distorter
            session.commit()
            scanlog("Updating planet-intel-dists")
        if (scan.planet.intel.amps < devscan.wave_amplifier) or (scan.tick == Updates.current_tick()):
            scan.planet.intel.amps = devscan.wave_amplifier
            session.commit()
            scanlog("Updating planet-intel-amps")
Beispiel #3
0
Datei: parser.py Projekt: JDD/DLR
 def group(self, uid, gid):
     scanlog("Group scan: %s" %(gid,))
     page = urlopen(Config.get("URL","viewgroup")%(gid,)).read()
     for m in re.finditer('scan_id=([0-9a-zA-Z]+)',page):
         try:
             self.scan(uid, m.group(1), gid)
         except Exception, e:
             scanlog("Exception in scan: %s"%(str(e),), traceback=True)
Beispiel #4
0
 def group(self, uid, gid):
     scanlog("Group scan: %s" %(gid,))
     page = urlopen(Config.get("URL","viewgroup")%(gid,)+"&inc=1").read()
     for scan in page.split("<hr>"):
         m = re.search('scan_id=([0-9a-zA-Z]+)',scan)
         if m:
             try:
                 self.execute(scan, uid, m.group(1), gid)
             except Exception, e:
                 scanlog("Exception in scan: %s"%(str(e),), traceback=True)
Beispiel #5
0
    def parse_U(self, scan_id, scan, page):
        for m in re.finditer('(\w+\s?\w*\s?\w*)</td><td[^>]*>(\d+(?:,\d{3})*)</td>', page):
            scanlog("%s: %s"%m.groups())

            ship = Ship.load(name=m.group(1))
            if ship is None:
                scanlog("No such unit %s" % (m.group(1),))
                continue
            scan.units.append(UnitScan(ship=ship, amount=m.group(2).replace(',', '')))

        session.commit()
Beispiel #6
0
 def group(self, uid, gid):
     scanlog("Group scan: %s" % (gid, ))
     page = urlopen(Config.get("URL", "viewgroup") % (gid, ) +
                    "&inc=1").read()
     for scan in page.split("<hr>"):
         m = re.search('scan_id=([0-9a-zA-Z]+)', scan)
         if m:
             try:
                 self.execute(scan, uid, m.group(1), gid)
             except Exception, e:
                 scanlog("Exception in scan: %s" % (str(e), ),
                         traceback=True)
Beispiel #7
0
 def group(self, uid, gid):
     scanlog("Group scan: %s" %(gid,))
     req = urllib2.Request(Config.get("URL","viewgroup")%(gid,)+"&inc=1")
     req.add_header("User-Agent", self.useragent)
     page = urllib2.urlopen(req).read()
     for scan in page.split("<hr>"):
         m = re.search('scan_id=([0-9a-zA-Z]+)',scan)
         if m:
             try:
                 self.execute(scan, uid, m.group(1), gid)
             except Exception, e:
                 scanlog("Exception in scan: %s"%(str(e),), traceback=True)
Beispiel #8
0
    def parse_J(self, scan_id, scan, page):
        # <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>

        #                     <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[^>]*>(?:<a[^>]+>)?(\d+)\:(\d+)\:(\d+)(?:</a>)?[^/]*/[^/]*/td><td[^>]*>([^<]+)</td><td[^>]*>([^<]+)</td><td[^>]*>(\d+)</td><td[^>]*>(\d+(?:,\d{3})*)</td>', page):
            scanlog("%s:%s:%s %s %s %s %s" %m.groups())
            
            fleetscan = FleetScan()

            originx = m.group(1)
            originy = m.group(2)
            originz = m.group(3)
            mission = m.group(4)
            fleet = m.group(5)
            eta = int(m.group(6))
            fleetsize = m.group(7).replace(',', '')

            fleetscan.mission = mission
            fleetscan.fleet_name = fleet
            fleetscan.landing_tick = eta + scan.tick
            fleetscan.fleet_size = fleetsize

            attacker=PlanetHistory.load_planet(originx,originy,originz,scan.tick)
            if attacker is None:
                scanlog("Can't find attacker in db: %s:%s:%s tick: %s"%(originx,originy,originz, scan.tick))
                continue
            fleetscan.owner = attacker
            fleetscan.target = scan.planet
            fleetscan.in_cluster = fleetscan.owner.x == fleetscan.target.x
            fleetscan.in_galaxy = fleetscan.in_cluster and fleetscan.owner.y == fleetscan.target.y

            try:
                scan.fleets.append(fleetscan)
                session.commit()
            except IntegrityError, e:
                session.rollback()
                scanlog("Caught integrity exception in jgp: %s"%(str(e),))
                scanlog("Trying to update instead")
                query = session.query(FleetScan).filter_by(owner=attacker, target=scan.planet, fleet_size=fleetsize, fleet_name=fleet, landing_tick=eta+scan.tick, mission=mission)
                try:
                    query.update({"scan_id": scan_id})
                    session.commit()
                except Exception, e:
                    session.rollback()
                    scanlog("Exception trying to update jgp: %s"%(str(e),), traceback=True)
                    continue
Beispiel #9
0
    def parse_U(self, scan_id, scan, page):
        for m in re.finditer(
                '(\w+\s?\w*\s?\w*)</td><td[^>]*>(\d+(?:,\d{3})*)</td>', page):
            scanlog("%s: %s" % m.groups())

            ship = Ship.load(name=m.group(1))
            if ship is None:
                scanlog("No such unit %s" % (m.group(1), ))
                continue
            scan.units.append(
                UnitScan(ship=ship, amount=m.group(2).replace(',', '')))

        session.commit()
Beispiel #10
0
 def run(self):
     scanlog(asctime())
     t_start=time()
     
     uid = self.uid
     type = self.type
     id = self.id
     try:
         if type == "scan":
             self.scan(uid, id)
         elif type == "group":
             self.group(uid, id)
     except Exception, e:
         scanlog("Exception in scan: %s"%(str(e),), traceback=True)
Beispiel #11
0
    def run(self):
        scanlog(asctime())
        t_start = time()

        uid = self.uid
        type = self.type
        id = self.id
        try:
            if type == "scan":
                self.scan(uid, id)
            elif type == "group":
                self.group(uid, id)
        except Exception, e:
            scanlog("Exception in scan: %s" % (str(e), ), traceback=True)
Beispiel #12
0
 def group(self, uid, gid):
     # Skip duplicate groups, only from the "share" channel. This allowed partially processed groups to be repeated if required.
     if not self.share and session.query(Scan).filter(Scan.group_id == gid).count() > 0:
         return
     scanlog("Group scan: %s" %(gid,))
     req = urllib2.Request(Config.get("URL","viewgroup")%(gid,)+"&inc=1")
     req.add_header("User-Agent", self.useragent)
     page = urllib2.urlopen(req).read()
     for scan in page.split("<hr>"):
         m = re.search('scan_id=([0-9a-zA-Z]+)',scan)
         if m:
             try:
                 self.execute(scan, uid, m.group(1), gid)
             except Exception, e:
                 scanlog("Exception in scan: %s"%(str(e),), traceback=True)
Beispiel #13
0
class parse(Thread):
    def __init__(self, uid, type, id):
        self.uid = uid
        self.type = type
        self.id = id
        Thread.__init__(self)

    def run(self):
        scanlog(asctime())
        t_start = time()

        uid = self.uid
        type = self.type
        id = self.id
        try:
            if type == "scan":
                self.scan(uid, id)
            elif type == "group":
                self.group(uid, id)
        except Exception, e:
            scanlog("Exception in scan: %s" % (str(e), ), traceback=True)

        t1 = time() - t_start
        scanlog("Total time taken: %.3f seconds" % (t1, ), spacing=True)
        session.remove()
Beispiel #14
0
class parse(Thread):
    useragent = "Merlin (Python-urllib/%s); Alliance/%s; BotNick/%s; Admin/%s" % (
        urllib2.__version__, Config.get("Alliance", "name"),
        Config.get("Connection", "nick"), Config.items("Admins")[0][0])

    def __init__(self, uid, type, id, share=True):
        self.uid = uid
        self.type = type
        self.id = id
        self.share = share
        Thread.__init__(self)

    def run(self):
        scanlog(asctime())
        t_start = time()

        uid = self.uid
        type = self.type
        id = self.id
        try:
            if type == "scan":
                self.scan(uid, id)
            elif type == "group":
                self.group(uid, id)
        except Exception, e:
            scanlog("Exception in scan: %s" % (str(e), ), traceback=True)

        t1 = time() - t_start
        scanlog("Total time taken: %.3f seconds" % (t1, ), spacing=True)
        session.remove()
Beispiel #15
0
    def __init__(self, message, m):

        scanlog(asctime())
        try:
            pnick = "(%s)" % message.get_pnick()
        except:
            pnick = ""
        scanlog("Galaxy status from %s%s" % (message.get_nick(), pnick))

        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)



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

        if mission == "A":
            mission = "Attack"
        elif mission == "D":
            mission = "Defend"
        elif mission == "R":
            mission = "Return"

        target=Planet.load(target_x,target_y,target_z)
        if target is None:
            return

        owner=Planet.load(owner_x,owner_y,owner_z)
        if owner is None:
            return

        curtick=Updates.current_tick()
        landing_tick = int(eta) + int(curtick)

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

        fleet = FleetScan(owner=owner, target=target, fleet_size=fleetsize, fleet_name=fleetname, landing_tick=landing_tick, mission=mission)
        fleet.in_cluster = owner_x == target_x
        fleet.in_galaxy = fleet.in_cluster and owner_y == target_y
        try:
            session.add(fleet)
            session.commit()
        except IntegrityError,e:
            session.rollback()
            print "Exception in galstatus: "+e.__str__()
            scanlog("Exception in galstatus: "+e.__str__())
            traceback.print_exc()
Beispiel #16
0
    def parse_N(self, scan_id, scan, page):
        #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 <a[^>]+>(\d+):(\d+):(\d+)</a>. The fleet will approach our system in tick (\d+) and appears to have (\d+) visible ships.</td>',
                page):
            fleetscan = FleetScan()

            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)

            fleetscan.mission = "Unknown"
            fleetscan.fleet_name = fleetname
            fleetscan.launch_tick = newstick
            fleetscan.landing_tick = int(arrivaltick)
            fleetscan.fleet_size = numships

            owner = PlanetHistory.load_planet(
                originx,
                originy,
                originz,
                newstick,
                closest=not Config.getboolean("Misc", "catchup"))
            if owner is None:
                continue
            fleetscan.owner = owner
            fleetscan.target = scan.planet
            fleetscan.in_cluster = fleetscan.owner.x == fleetscan.target.x
            fleetscan.in_galaxy = fleetscan.in_cluster and fleetscan.owner.y == fleetscan.target.y

            try:
                scan.fleets.append(fleetscan)
                session.commit()
            except Exception, e:
                session.rollback()
                scanlog("Exception in news: %s" % (str(e), ), traceback=True)
                continue

            scanlog('Incoming: ' + newstick + ':' + fleetname + '-' + originx +
                    ':' + originy + ':' + originz + '-' + arrivaltick + '|' +
                    numships)
Beispiel #17
0
    def report_incoming(self, message, target, owner, fleet):
        i=target.intel
        if i is None:
            scanlog("planet %s:%s:%s not in intel" % (target.x,target.y,target.z))
            return
        reply="%s reports: " % (message.get_nick(),)
        if i.nick:
            reply+=i.nick + " -> "
        reply+=" (xp: %s" % (owner.calc_xp(target),)

        # munin has some commented code here for associating with a defcall

        if i.relay and i.reportchan and message.get_chan() != i.reportchan:
            reply+=") "
            reply+=message.get_msg().replace("\x02","")
            message.privmsg(reply,i.reportchan)
        else:
            scanlog("planet not set to relay (%s) or report (%s) or report is source (%s)" % (i.relay,i.reportchan,message.get_chan()))
Beispiel #18
0
 def group(self, uid, gid):
     # Skip duplicate groups, only from the "share" channel. This allowed partially processed groups to be repeated if required.
     if not self.share and session.query(Scan).filter(
             Scan.group_id == gid).count() > 0:
         return
     scanlog("Group scan: %s" % (gid, ))
     req = urllib2.Request(
         Config.get("URL", "viewgroup") % (gid, ) + "&inc=1")
     req.add_header("User-Agent", self.useragent)
     page = urllib2.urlopen(req).read()
     for scan in page.split("<hr>"):
         m = re.search('scan_id=([0-9a-zA-Z]+)', scan)
         if m:
             try:
                 self.execute(scan, uid, m.group(1), gid)
             except Exception, e:
                 scanlog("Exception in scan: %s" % (str(e), ),
                         traceback=True)
Beispiel #19
0
 def execute(self, page, uid, pa_id, gid=None):
     scanlog("Scan: %s (group: %s)" %(pa_id,gid,))
     page = decode(page)
     
     m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
     if not m:
         scanlog("Expired/non-matchinng scan (id: %s)" %(pa_id,))
         return
     
     scantype = m.group(1)[0].upper()
     x = int(m.group(2))
     y = int(m.group(3))
     z = int(m.group(4))
     tick = int(m.group(5))
     
     planet = Planet.load(x,y,z)
     if planet is None:
         return
     try:
         scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, group_id=gid, scanner_id=uid)
         planet.scans.append(scan)
         session.commit()
         scan_id = scan.id
     except IntegrityError, e:
         session.rollback()
         scanlog("Scan %s may already exist: %s" %(pa_id,str(e),))
         return
Beispiel #20
0
    def execute(self, page, uid, pa_id, gid=None):
        scanlog("Scan: %s (group: %s)" %(pa_id,gid,))
        page = decode(page)
        
        m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
        if not m:
            scanlog("Expired/non-matchinng scan (id: %s)" %(pa_id,))
            return
        
        scantype = m.group(1)[0].upper()
        x = int(m.group(2))
        y = int(m.group(3))
        z = int(m.group(4))
        tick = int(m.group(5))

        m = re.search("<p class=\"right scan_time\">Scan time: ([^<]*)</p>", page)
        scantime = m.group(1)
        
        planet = Planet.load(x,y,z,)

        try:
            Q = session.query(Scan).filter(Scan.pa_id == pa_id).filter(Scan.planet_id == None)
            if Q.count() > 0:
                scan = Q.first()
            else:
                scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, time=scantime, group_id=gid, scanner_id=uid)
                session.add(scan)
            if planet:
                planet.scans.append(scan)
            session.commit()
            scan_id = scan.id
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" %(pa_id,str(e),))
            return
Beispiel #21
0
    def parse_N(self, scan_id, scan, page):
        #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 <a[^>]+>(\d+):(\d+):(\d+)</a>. The fleet will approach our system in tick (\d+) and appears to have (\d+) visible ships.</td>', page):
            fleetscan = FleetScan()

            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)

            fleetscan.mission = "Unknown"
            fleetscan.fleet_name = fleetname
            fleetscan.launch_tick = newstick
            fleetscan.landing_tick = int(arrivaltick)
            fleetscan.fleet_size = numships

            owner = PlanetHistory.load_planet(originx,originy,originz,newstick,closest=not Config.getboolean("Misc", "catchup"))
            if owner is None:
                continue
            fleetscan.owner = owner
            fleetscan.target = scan.planet
            fleetscan.in_cluster = fleetscan.owner.x == fleetscan.target.x
            fleetscan.in_galaxy = fleetscan.in_cluster and fleetscan.owner.y == fleetscan.target.y

            try:
                scan.fleets.append(fleetscan)
                session.commit()
            except Exception, e:
                session.rollback()
                scanlog("Exception in news: %s"%(str(e),), traceback=True)
                continue

            scanlog('Incoming: ' + newstick + ':' + fleetname + '-' + originx + ':' + originy + ':' + originz + '-' + arrivaltick + '|' + numships)
Beispiel #22
0
    def execute(self, page, uid, pa_id, gid=None):
        scanlog("Scan: %s (group: %s)" % (
            pa_id,
            gid,
        ))
        page = decode(page)

        m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
        if not m:
            scanlog("Expired/non-matchinng scan (id: %s)" % (pa_id, ))
            return

        scantype = m.group(1)[0].upper()
        x = int(m.group(2))
        y = int(m.group(3))
        z = int(m.group(4))
        tick = int(m.group(5))

        m = re.search("<p class=\"right scan_time\">Scan time: ([^<]*)</p>",
                      page)
        scantime = m.group(1)

        planet = Planet.load(
            x,
            y,
            z,
        )

        try:
            Q = session.query(Scan).filter(Scan.pa_id == pa_id).filter(
                Scan.planet_id == None)
            if Q.count() > 0:
                scan = Q.first()
            else:
                scan = Scan(pa_id=pa_id,
                            scantype=scantype,
                            tick=tick,
                            time=scantime,
                            group_id=gid,
                            scanner_id=uid)
                session.add(scan)
            if planet:
                planet.scans.append(scan)
            session.commit()
            scan_id = scan.id
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" % (
                pa_id,
                str(e),
            ))
            return
Beispiel #23
0
    def execute(self, page, uid, pa_id, gid=None):
        scanlog("Scan: %s (group: %s)" % (
            pa_id,
            gid,
        ))
        page = decode(page)

        m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
        if not m:
            scanlog("Expired/non-matchinng scan (id: %s)" % (pa_id, ))
            return

        scantype = m.group(1)[0].upper()
        x = int(m.group(2))
        y = int(m.group(3))
        z = int(m.group(4))
        tick = int(m.group(5))

        planet = Planet.load(x, y, z)
        if planet is None:
            return
        try:
            scan = Scan(pa_id=pa_id,
                        scantype=scantype,
                        tick=tick,
                        group_id=gid,
                        scanner_id=uid)
            planet.scans.append(scan)
            session.commit()
            scan_id = scan.id
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" % (
                pa_id,
                str(e),
            ))
            return
Beispiel #24
0
 tick = int(m.group(5))
 
 planet = Planet.load(x,y,z)
 if planet is None:
     return
 try:
     scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, group_id=gid, scanner_id=uid)
     planet.scans.append(scan)
     session.commit()
     scan_id = scan.id
 except IntegrityError, e:
     session.rollback()
     scanlog("Scan %s may already exist: %s" %(pa_id,str(e),))
     return
 
 scanlog("%s %s:%s:%s" %(PA.get(scantype,"name"), x,y,z,))
 
 parser = {
           "P": self.parse_P,
           "D": self.parse_D,
           "U": self.parse_U,
           "A": self.parse_U,
           "J": self.parse_J,
           "N": self.parse_N,
          }.get(scantype)
 if parser is not None:
     parser(scan_id, scan, page)
 
 Q = session.query(Request)
 Q = Q.filter(Request.scantype==scantype)
 Q = Q.filter(Request.target==planet)
Beispiel #25
0
            if Q.count() > 0:
                scan = Q.first()
            else:
                scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, time=scantime, group_id=gid, scanner_id=uid)
                session.add(scan)
            if planet:
                planet.scans.append(scan)
            session.commit()
            scan_id = scan.id
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" %(pa_id,str(e),))
            return

        if planet is None:
            scanlog("No planet found. Check the bot is ticking. Scan will be tried again at next tick.")
            return
        
        scanlog("%s %s:%s:%s" %(PA.get(scantype,"name"), x,y,z,))
        
        parser = {
                  "P": self.parse_P,
                  "D": self.parse_D,
                  "U": self.parse_U,
                  "A": self.parse_U,
                  "J": self.parse_J,
                  "N": self.parse_N,
                 }.get(scantype)
        if parser is not None:
            parser(scan_id, scan, page)
        
Beispiel #26
0
    def parse_J(self, scan_id, scan, page):
        # <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>

        #                     <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[^>]*>(?:<a[^>]+>)?(\d+)\:(\d+)\:(\d+)(?:</a>)?[^/]*/[^/]*/td><td[^>]*>([^<]+)</td><td[^>]*>([^<]+)</td><td[^>]*>(\d+)</td><td[^>]*>(\d+(?:,\d{3})*)</td>',
                page):
            scanlog("%s:%s:%s %s %s %s %s" % m.groups())

            fleetscan = FleetScan()

            originx = m.group(1)
            originy = m.group(2)
            originz = m.group(3)
            mission = m.group(4)
            fleet = m.group(5)
            eta = int(m.group(6))
            fleetsize = m.group(7).replace(',', '')

            fleetscan.mission = mission
            fleetscan.fleet_name = fleet
            fleetscan.landing_tick = eta + scan.tick
            fleetscan.fleet_size = fleetsize

            attacker = PlanetHistory.load_planet(originx, originy, originz,
                                                 scan.tick)
            if attacker is None:
                scanlog("Can't find attacker in db: %s:%s:%s tick: %s" %
                        (originx, originy, originz, scan.tick))
                continue
            fleetscan.owner = attacker
            fleetscan.target = scan.planet
            fleetscan.in_cluster = fleetscan.owner.x == fleetscan.target.x
            fleetscan.in_galaxy = fleetscan.in_cluster and fleetscan.owner.y == fleetscan.target.y

            try:
                scan.fleets.append(fleetscan)
                session.commit()
            except IntegrityError, e:
                session.rollback()
                scanlog("Caught integrity exception in jgp: %s" % (str(e), ))
                scanlog("Trying to update instead")
                query = session.query(FleetScan).filter_by(
                    owner=attacker,
                    target=scan.planet,
                    fleet_size=fleetsize,
                    fleet_name=fleet,
                    landing_tick=eta + scan.tick,
                    mission=mission)
                try:
                    query.update({"scan_id": scan_id})
                    session.commit()
                except Exception, e:
                    session.rollback()
                    scanlog("Exception trying to update jgp: %s" % (str(e), ),
                            traceback=True)
                    continue
Beispiel #27
0
                        group_id=gid,
                        scanner_id=uid)
            planet.scans.append(scan)
            session.commit()
            scan_id = scan.id
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" % (
                pa_id,
                str(e),
            ))
            return

        scanlog("%s %s:%s:%s" % (
            PA.get(scantype, "name"),
            x,
            y,
            z,
        ))

        parser = {
            "P": self.parse_P,
            "D": self.parse_D,
            "U": self.parse_U,
            "A": self.parse_U,
            "J": self.parse_J,
            "N": self.parse_N,
        }.get(scantype)
        if parser is not None:
            parser(scan_id, scan, page)

        Q = session.query(Request)
Beispiel #28
0
    def parse_D(self, scan_id, scan, page):
        devscan = scan.devscan = DevScan()

        m = re.search(
            """
            <tr><td[^>]*>Light\s+Factory</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Medium\s+Factory</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Heavy\s+Factory</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Wave\s+Amplifier</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Wave\s+Distorter</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Metal\s+Refinery</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Crystal\s+Refinery</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Eonium\s+Refinery</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Research\s+Laboratory</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Finance\s+Centre</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Military\s+Centre</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Security\s+Centre</td><td[^>]*>(\d*)</td></tr>\s*
            <tr><td[^>]*>Structure\s+Defence</td><td[^>]*>(\d*)</td></tr>
        """, page, re.VERBOSE)

        devscan.light_factory = m.group(1)
        devscan.medium_factory = m.group(2)
        devscan.heavy_factory = m.group(3)
        devscan.wave_amplifier = m.group(4)
        devscan.wave_distorter = m.group(5)
        devscan.metal_refinery = m.group(6)
        devscan.crystal_refinery = m.group(7)
        devscan.eonium_refinery = m.group(8)
        devscan.research_lab = m.group(9)
        devscan.finance_centre = m.group(10)
        devscan.military_centre = m.group(11)
        devscan.security_centre = m.group(12)
        devscan.structure_defence = m.group(13)

        m = re.search(
            """
            <tr><td[^>]*>Space\s+Travel</td><td[^>]*>(\d+)\s*<span[^<]*</span></td></tr>\s*
            <tr><td[^>]*>Infrastructure</td><td[^>]*>(\d+)\s*<span[^<]*</span></td></tr>\s*
            <tr><td[^>]*>Hulls</td><td[^>]*>(\d+)\s*<span[^<]*</span></td></tr>\s*
            <tr><td[^>]*>Waves</td><td[^>]*>(\d+)\s*<span[^<]*</span></td></tr>\s*
            <tr><td[^>]*>Core\s+Extraction</td><td[^>]*>(\d+)\s*<span[^<]*</span></td></tr>\s*
            <tr><td[^>]*>Covert\s+Ops</td><td[^>]*>(\d+)\s*<span[^<]*</span></td></tr>\s*
            <tr><td[^>]*>Asteroid\s+Mining</td><td[^>]*>(\d+)\s*<span[^<]*</span></td></tr>\s*
            <tr><td[^>]*>Population\s+Management</td><td[^>]*>(\d+)\s*<span[^<]*</span></td></tr>
        """, page, re.VERBOSE)

        devscan.travel = m.group(1)
        devscan.infrastructure = m.group(2)
        devscan.hulls = m.group(3)
        devscan.waves = m.group(4)
        devscan.core = m.group(5)
        devscan.covert_op = m.group(6)
        devscan.mining = m.group(7)
        devscan.pop = m.group(8)

        session.commit()

        if scan.planet.intel is None:
            scan.planet.intel = Intel()
        if (scan.planet.intel.dists < devscan.wave_distorter) or (
                scan.tick == Updates.current_tick()):
            scan.planet.intel.dists = devscan.wave_distorter
            session.commit()
            scanlog("Updating planet-intel-dists")
        if (scan.planet.intel.amps < devscan.wave_amplifier) or (
                scan.tick == Updates.current_tick()):
            scan.planet.intel.amps = devscan.wave_amplifier
            session.commit()
            scanlog("Updating planet-intel-amps")
Beispiel #29
0
                session.add(scan)
            if planet:
                planet.scans.append(scan)
            session.commit()
            scan_id = scan.id
        except IntegrityError, e:
            session.rollback()
            scanlog("Scan %s may already exist: %s" % (
                pa_id,
                str(e),
            ))
            return

        if planet is None:
            scanlog(
                "No planet found. Check the bot is ticking. Scan will be tried again at next tick."
            )
            return

        scanlog("%s %s:%s:%s" % (
            PA.get(scantype, "name"),
            x,
            y,
            z,
        ))

        parser = {
            "P": self.parse_P,
            "D": self.parse_D,
            "U": self.parse_U,
            "A": self.parse_U,