Esempio n. 1
0
    def execute(self, message, user, params):
        
        if params.group(4) is None:
            target = Planet.load(*params.group(1,3,5))
            if target is None:
                message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
                return
            attacker = self.get_user_planet(user)
        else:
            target = Planet.load(*params.group(1,3,5))
            if target is None:
                message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
                return
            attacker = Planet.load(*params.group(6,8,10))
            if attacker is None:
                message.alert("No planet with coords %s:%s:%s" % params.group(6,8,10))
                return
        
        reply="Target "
        target_val = target.value
        attacker_val = attacker.value
        target_score = target.score
        attacker_score = attacker.score

        reply+="%s:%s:%s (%s|%s) "%(target.x,target.y,target.z,
                                 self.num2short(target.value),self.num2short(target.score))
        reply+="| Attacker %s:%s:%s (%s|%s) "%(attacker.x,attacker.y,attacker.z,
                                            self.num2short(attacker.value),self.num2short(attacker.score))

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

        cap=target.maxcap(attacker)
        xp=attacker.calc_xp(target)
        reply+="| Roids: %s | XP: %s | Score: %s" % (cap,xp,xp*60)
        message.reply(reply)
Esempio n. 2
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()
Esempio n. 3
0
File: xp.py Progetto: munin/merlin
 def planet(self, message, user, params):
     target = Planet.load(*params.group(1,3,5))
     if target is None:
         message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
         return
     attacker = Planet.load(*params.group(6,8,10))
     if attacker is None:
         message.alert("No planet with coords %s:%s:%s" % params.group(6,8,10))
         return
     
     self.execute(message, target, attacker)
Esempio n. 4
0
 def planet(self, message, user, params):
     target = Planet.load(*params.group(1,3,5))
     if target is None:
         message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
         return
     attacker = Planet.load(*params.group(6,8,10))
     if attacker is None:
         message.alert("No planet with coords %s:%s:%s" % params.group(6,8,10))
         return
     
     self.execute(message, target, attacker)
Esempio n. 5
0
    def __init__(self, message, m):

        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 = 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)

        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__()
            traceback.print_exc()
Esempio n. 6
0
    def execute(self, message, alliance=None, race=None, sortby="score"):
        planet = aliased(Planet)
        planet_intel = aliased(Intel)
        

        Q = session.query(planet.x, planet.y, planet.z, planet_intel.nick)
        Q = Q.outerjoin((planet.intel, planet_intel))
        if alliance:
            Q = Q.filter(planet_intel.alliance == alliance)
        if race:
            Q = Q.filter(planet.race == race)
        if sortby == "xp":
            Q = Q.order_by(desc(planet.xp))
        elif sortby == "size":
            Q = Q.order_by(desc(planet.size))
        elif sortby == "value":
            Q = Q.order_by(desc(planet.value))
        else:
            Q = Q.order_by(desc(planet.score))
        result = Q.all()
        
        reply = "Top%s planets" % (" "+race if race is not None else "")
        if alliance:
            reply+=" in %s"%(alliance.name,)
        reply+=" by %s:\n"%(sortby)
        prev = []
        i=0
        for x, y, z, nick in result[:10]:
            i+=1
            line = "#%2s %12s%s"%(i, "["+nick+"] " if nick else "", Planet.load(x,y,z))
            prev.append(line)
        message.reply(reply+"\n".join(prev))
Esempio n. 7
0
 def execute(self, request, user):
     
     planet, galaxy = (user.planet, user.planet.galaxy,) if user.planet else (Planet(), Galaxy(),)
     
     planets = session.query(Planet).filter(Planet.active == True)
     galaxies = session.query(Galaxy).filter(Galaxy.active == True)
     alliances = session.query(Alliance).filter(Alliance.active == True)
     
     dup = lambda l,o,c=True: l+[o] if o in session and c and o not in l else l
     
     return render("index.tpl", request,
                  topplanets = dup(planets.order_by(asc(Planet.score_rank))[:20], 
                                   planet),
              roidingplanets = dup(planets.filter(Planet.size_growth > 0).order_by(desc(Planet.size_growth))[:5],
                                   planet, planet.size_growth > 0),
               roidedplanets = dup(planets.filter(Planet.size_growth < 0).order_by(asc(Planet.size_growth))[:5],
                                   planet, planet.size_growth < 0),
                   xpplanets = dup(planets.filter(Planet.xp_growth > 0).order_by(desc(Planet.xp_growth))[:5],
                                   planet, planet.xp_growth > 0),
               bashedplanets = dup(planets.filter(Planet.value_growth < 0).order_by(asc(Planet.value_growth))[:5],
                                   planet, planet.value_growth < 0),
             
                 topgalaxies = dup(galaxies.order_by(asc(Galaxy.score_rank))[:10],
                                   galaxy),
             roidinggalaxies = dup(galaxies.filter(Galaxy.size_growth > 0).order_by(desc(Galaxy.size_growth))[:5],
                                   galaxy, galaxy.size_growth > 0),
              roidedgalaxies = dup(galaxies.filter(Galaxy.size_growth < 0).order_by(asc(Galaxy.size_growth))[:5],
                                   galaxy, galaxy.size_growth < 0),
                  xpgalaxies = dup(galaxies.filter(Galaxy.xp_growth > 0).order_by(desc(Galaxy.xp_growth))[:5],
                                   galaxy, galaxy.xp_growth > 0),
              bashedgalaxies = dup(galaxies.filter(Galaxy.value_growth < 0).order_by(asc(Galaxy.value_growth))[:5],
                                   galaxy, galaxy.value_growth < 0),
             
                topalliances =     alliances.order_by(asc(Alliance.score_rank))[:8],
                         )
Esempio n. 8
0
    def execute(self, request, user, x, y, z, through):
        planet = Planet.load(x, y, z)
        if planet is None:
            return HttpResponseRedirect(reverse("exiles"))

        if through:
            Q = session.query(PlanetExiles)
            Q = Q.filter(
                or_(
                    and_(PlanetExiles.oldx == planet.x,
                         PlanetExiles.oldy == planet.y,
                         PlanetExiles.oldz == planet.z),
                    and_(PlanetExiles.newx == planet.x,
                         PlanetExiles.newy == planet.y,
                         PlanetExiles.newz == planet.z)))
            Q = Q.order_by(desc(PlanetExiles.tick))
            exiles = Q.all()
        else:
            exiles = planet.exiles

        return render("exiles.tpl",
                      request,
                      planet=planet,
                      through=through,
                      exiles=exiles)
Esempio n. 9
0
 def execute(self, request, user, x, y, z, fleets=False):
     week = Updates.week_tick()
     
     planet = Planet.load(x,y,z)
     if planet is None:
         return HttpResponseRedirect(reverse("planet_ranks"))
     
     Q = session.query(FleetScan, Planet, Alliance)
     Q = Q.join(FleetScan.target)
     Q = Q.outerjoin(Planet.intel).outerjoin(Intel.alliance)
     Q = Q.filter(FleetScan.owner == planet)
     Q = Q.order_by(desc(FleetScan.landing_tick))
     if not fleets:
         Q = Q.filter(FleetScan.landing_tick >= week)
     outgoing = Q.all()
     
     Q = session.query(FleetScan, Planet, Alliance)
     Q = Q.join(FleetScan.owner)
     Q = Q.outerjoin(Planet.intel).outerjoin(Intel.alliance)
     Q = Q.filter(FleetScan.target == planet)
     Q = Q.order_by(desc(FleetScan.landing_tick))
     if not fleets:
         Q = Q.filter(FleetScan.landing_tick >= week)
     incoming = Q.all()
     
     scan = planet.scan("A") or planet.scan("U")
     
     return render("iplanet.tpl", request, planet=planet, scan=scan, outgoing=outgoing, incoming=incoming)
Esempio n. 10
0
File: scan.py Progetto: JDD/merlin
 def planet(self, message, user, params):
     planet = Planet.load(*params.group(1,3,5))
     if planet is None:
         message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
         return
     
     # List of last 10 scans
     if params.group(6) == "o":
         scans = planet.scans.filter_by(scantype=self.type).order_by(desc(Scan.id))[:10]
         if len(scans) < 1:
             message.reply("No %s Scans of %s:%s:%s found"%(PA.get(self.type,"name"),planet.x,planet.y,planet.z))
             return
         prev = []
         for scan in scans:
             prev.append("(pt%s %s)" % (scan.tick, scan.pa_id,))
         reply = "Last 10 %s Scans on %s:%s:%s "%(PA.get(self.type,"name"),planet.x,planet.y,planet.z) + " ".join(prev)
         message.reply(reply)
         return
     
     # Latest scan
     scan = planet.scan(self.type)
     if scan is None:
         message.reply("No %s Scans of %s:%s:%s found"%(PA.get(self.type,"name"),planet.x,planet.y,planet.z))
         return
     
     # Link to scan
     if params.group(7) == "l":
         reply = "%s on %s:%s:%s " % (scan.type,planet.x,planet.y,planet.z,)
         reply+= self.url(scan.link, user)
         message.reply(reply)
         return
     
     # Display the scan
     message.reply(self.url(str(scan), user))
Esempio n. 11
0
 def remove(self, message, user, params):
     id = int(params.group(1))
     attack = Attack.load(id)
     if attack is None:
         message.alert("No attack exists with id %d" %(id))
         return
     
     for coord in re.findall(loadable.coord, params.group(2)):
         if not coord[4]:
             galaxy = Galaxy.load(coord[0],coord[2], active=False)
             if galaxy:
                 attack.removeGalaxy(galaxy)
         
         else:
             planet = Planet.load(coord[0],coord[2],coord[4], active=False)
             if planet:
                 attack.removePlanet(planet)
     
     if not len(attack.planets):
         session.delete(attack)
     
     session.commit()
     
     if attack in session:
         message.reply(str(attack))
     else:
         message.reply("Deleted Attack %d LT: %d | %s" %(attack.id,attack.landtick,attack.comment,))
Esempio n. 12
0
 def planet(self, message, user, params):
     planet = Planet.load(*params.group(1, 3, 5))
     if planet is None:
         message.alert("No planet with coords %s:%s:%s" %
                       params.group(1, 3, 5))
         return
     self.execute(message, planet)
Esempio n. 13
0
    def execute(self, message, user, params):

        planet = Planet.load(*params.group(1, 3, 5))
        if planet is None:
            message.reply("No planet with coords %s:%s:%s found" %
                          params.group(1, 3, 5))
            return

        Q = session.query(Scan.scantype, max(Scan.tick), count())
        Q = Q.filter(Scan.planet == planet)
        Q = Q.group_by(Scan.scantype)
        result = Q.all()

        if len(result) < 1:
            message.reply("No scans available on %s:%s:%s" % (
                planet.x,
                planet.y,
                planet.z,
            ))
            return

        prev = []
        for type, latest, number in result:
            prev.append("(%d %s, latest pt%s)" % (
                number,
                type,
                latest,
            ))

        reply = "scans for %s:%s:%s - " % (planet.x, planet.y,
                                           planet.z) + ", ".join(prev)
        message.reply(reply)
Esempio n. 14
0
 def execute(self, message, user, params):
     
     p = Planet.load(*params.group(1,3,5))
     if p is None:
         message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
         return
     ship = Ship.load(name=params.group(6))
     if ship is None:
         message.alert("No Ship called: %s" % (params.group(6),))
         return
     
     scan = p.scan("P")
     if scan is None:
         message.reply("No planet scans available on %s:%s:%s" % (p.x,p.y,p.z,))
         return
     
     planetscan = scan.planetscan
     tick=scan.tick
     res_m=planetscan.res_metal
     res_c=planetscan.res_crystal
     res_e=planetscan.res_eonium
     prod_res=planetscan.prod_res
     rand_id=scan.pa_id
     
     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.0, 'Low': 0.33, 'Medium': 0.66, 'High': 1.0}
     
     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)
     
     reply="Newest planet scan on %s:%s:%s (id: %s, pt: %s)" % (p.x,p.y,p.z,rand_id,tick)
     reply+=" can purchase %s: %s"%(ship.name,int(buildable))
     
     for gov in PA.options("govs"):
         bonus = PA.getfloat(gov, "prodcost")
         if bonus == 0:
             continue
         reply+=" | %s: %s"%(PA.get(gov, "name"),int(buildable/(1+bonus)))
     
     factory_usage=getattr(planetscan,class_factory_table[ship.class_])
     if prod_res > 0 and factory_usage != "None":
         max_prod_modifier=prod_modifier_table[factory_usage]
         buildable_from_prod = buildable + max_prod_modifier*prod_res/total_cost
         reply+=" Counting %s res in prod at %s usage:" % (self.num2short(prod_res),factory_usage)
         reply+=" %s"%(int(buildable_from_prod))
         
         for gov in PA.options("govs"):
             bonus = PA.getfloat(gov, "prodcost")
             if bonus == 0:
                 continue
             reply+=" | %s: %s"%(PA.get(gov, "name"),int(buildable_from_prod/(1+bonus)))
     
     message.reply(reply)
Esempio n. 15
0
 def scan(self, uid, pa_id, gid=None):
     page = urlopen(Config.get("URL","viewscan")%(pa_id,)).read()
     page = decode(page)
     
     m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
     if not m:
         print "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()
         print "Scan %s may already exist" %(pa_id,)
         print e.__str__()
         return
Esempio n. 16
0
File: guess.py Progetto: JDD/merlin
    def list_fleets(self, message, user, params):
        # Check the planet exists
        planet = Planet.load(*params.group(1,3,5))
        if planet is None:
            message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
            return

        # Find all fleets with a known alliance who have defended this planet
        OQ = session.query(coalesce(FleetScan.launch_tick, FleetScan.landing_tick), literal_column("'From'").label("dir"), Planet.x, Planet.y, Planet.z, Alliance.name).select_from(FleetScan)
        OQ = OQ.filter(FleetScan.target_id == planet.id, FleetScan.in_galaxy==False, FleetScan.mission=="Defend")
        OQ = OQ.join(Intel, FleetScan.owner_id == Intel.planet_id).filter(Intel.alliance_id != None)
        OQ = OQ.join(Alliance, Intel.alliance_id == Alliance.id).join(Planet, FleetScan.owner_id == Planet.id)

        # Find all fleets with a known alliance who have been defended by this planet
        TQ = session.query(coalesce(FleetScan.launch_tick, FleetScan.landing_tick), literal_column("'To  '").label("dir"), Planet.x, Planet.y, Planet.z, Alliance.name).select_from(FleetScan)
        TQ = TQ.filter(FleetScan.owner_id == planet.id, FleetScan.in_galaxy==False, FleetScan.mission=="Defend")
        TQ = TQ.join(Intel, FleetScan.target_id == Intel.planet_id).filter(Intel.alliance_id != None)
        TQ = TQ.join(Alliance, Intel.alliance_id == Alliance.id).join(Planet, FleetScan.target_id == Planet.id)

        # Combine the results into one sorted list
        results = sorted(OQ.all()+TQ.all(), reverse=True)

        # Quit now if there are no results
        if len(results) == 0:
            message.reply("No suggestions found")
            return

        # Reply to the user
        message.reply("Tick  Dir   Planet     Alliance")
        limit = int(params.group(6) or 5)
        for r in results[:limit]:
            message.reply("%4s  %s  %-9s  %s" % (r[0], r[1], "%s:%s:%s" % (r[2], r[3], r[4]), r[5]))
        if len(results) > limit:
            message.reply("%s results not shown (%s total)" % (len(results)-limit, len(results)))
Esempio n. 17
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 (\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()
                print "Exception in news: "+e.__str__()
                traceback.print_exc()
                continue

            print 'Incoming: ' + newstick + ':' + fleetname + '-' + originx + ':' + originy + ':' + originz + '-' + arrivaltick + '|' + numships
Esempio n. 18
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
Esempio n. 19
0
    def execute(self, request, user, x, y, z, type, dists):
        from Arthur.views.scans.list import scans
        tick = Updates.current_tick()
        type = type.upper()

        planet = Planet.load(x, y, z)
        if planet is None:
            return scans.execute(request,
                                 user,
                                 message="No planet with coords %s:%s:%s" % (
                                     x,
                                     y,
                                     z,
                                 ))

        dists = int(dists or 0)
        req = Request(target=planet, scantype=type, dists=dists)
        user.requests.append(req)
        session.commit()

        push("request", request_id=req.id, mode="request")

        return scans.execute(request,
                             user,
                             message="Requested a %s Scan of %s:%s:%s" % (
                                 req.type,
                                 x,
                                 y,
                                 z,
                             ),
                             planet=planet)
Esempio n. 20
0
 def execute(self, request, user, id, x, y, z, when):
     planet = Planet.load(x,y,z)
     if planet is None:
         return self.attack(request, user, id, "No planet with coords %s:%s:%s" %(x,y,z,))
     
     tick = Updates.current_tick()
     when = int(when)
     if when < PA.getint("numbers", "protection"):
         eta = when
         when += tick
     elif when <= tick:
         return self.attack(request, user, id, "Can not book targets in the past. You wanted tick %s, but current tick is %s." % (when, tick,))
     else:
         eta = when - tick
     if when > 32767:
         when = 32767        
     
     if planet.intel and planet.alliance and planet.alliance.name == Config.get("Alliance","name"):
         return self.attack(request, user, id, "%s:%s:%s is %s in %s. Quick, launch before they notice!" % (x,y,z, planet.intel.nick or 'someone', Config.get("Alliance","name"),))
     
     try:
         planet.bookings.append(Target(user=user, tick=when))
         session.commit()
     except IntegrityError:
         session.rollback()
         target = planet.bookings.filter(Target.tick == when).first()
         if target is not None:
             return self.attack(request, user, id, "Target %s:%s:%s is already booked for landing tick %s by user %s" % (x,y,z, when, target.user.name,))
     else:
         return self.attack(request, user, id, "Booked landing on %s:%s:%s tick %s (eta %s) for user %s" % (x,y,z, when, (when-tick), user.name,))
     
     return self.attack(request, user, id)
Esempio n. 21
0
    def new(self, message, user, params):
        tick = Updates.current_tick()
        comment = params.group(3) or ""
        when = int(params.group(1))
        if when < PA.getint("numbers", "protection"):
            eta = when
            when += tick
        elif when <= tick:
            message.alert(
                "Can not create attacks in the past. You wanted tick %s, but current tick is %s." % (when, tick)
            )
            return
        else:
            eta = when - tick
        if when > 32767:
            when = 32767

        attack = Attack(landtick=when, comment=comment)
        session.add(attack)

        for coord in re.findall(loadable.coord, params.group(2)):
            if not coord[4]:
                galaxy = Galaxy.load(coord[0], coord[2])
                if galaxy:
                    attack.addGalaxy(galaxy)

            else:
                planet = Planet.load(coord[0], coord[2], coord[4])
                if planet:
                    attack.addPlanet(planet)

        session.commit()
        message.reply(str(attack))
Esempio n. 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
Esempio n. 23
0
    def execute(self, message, user, params):

        target = Planet.load(*params.group(1, 3, 5))
        if target is None:
            message.reply("No planet matching '%s:%s:%s' found" %
                          params.group(1, 3, 5))
            return
        replies = [str(target)]

        if self.user_has_planet(user):
            attacker = user.planet
            reply = "Target "

            reply += "%s:%s:%s (%s|%s) " % (target.x, target.y, target.z,
                                            self.num2short(target.value),
                                            self.num2short(target.score))
            reply += "| Attacker %s:%s:%s (%s|%s) " % (
                attacker.x, attacker.y, attacker.z,
                self.num2short(attacker.value), self.num2short(attacker.score))

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

            cap = target.maxcap(attacker)
            xp = attacker.calc_xp(target)
            reply += "| Roids: %s | XP: %s | Score: %s" % (
                cap, xp, xp * PA.getint("numbers", "xp_value"))
            replies.append(reply)

        if target.intel is not None:
            replies.append(
                ("Information stored for %s:%s:%s -" + str(target.intel) if
                 str(target.intel) else "No information stored for %s:%s:%s") %
                (
                    target.x,
                    target.y,
                    target.z,
                ))

        bookings = target.bookings.filter(
            Target.tick > Updates.current_tick()).all()
        if len(bookings) < 1:
            replies.append("No bookings matching planet %s:%s:%s" % (
                target.x,
                target.y,
                target.z,
            ))
        else:
            prev = []
            for booking in bookings:
                prev.append("(%s user:%s)" % (booking.tick, booking.user.name))
            replies.append("Status for %s:%s:%s - " % (
                target.x,
                target.y,
                target.z,
            ) + ", ".join(prev))

        message.reply("\n".join(replies))
Esempio n. 24
0
 def execute(self, request, user, x, y, z, h=False, hs=False, ticks=None):
     planet = Planet.load(x,y,z)
     if planet is None:
         return HttpResponseRedirect(reverse("planet_ranks"))
     
     ticks = int(ticks or 0) if (h or hs) else 12
     
     if not hs:
         sizediffvalue = PlanetHistory.rdiff * PA.getint("numbers", "roid_value")
         valuediffwsizevalue = PlanetHistory.vdiff - sizediffvalue
         resvalue = valuediffwsizevalue * PA.getint("numbers", "res_value")
         shipvalue = valuediffwsizevalue * PA.getint("numbers", "ship_value")
         xpvalue = PlanetHistory.xdiff * PA.getint("numbers", "xp_value")
         Q = session.query(PlanetHistory,
                             sizediffvalue,
                             valuediffwsizevalue,
                             resvalue, shipvalue,
                             xpvalue,
                             )
         Q = Q.filter(PlanetHistory.current == planet)
         Q = Q.order_by(desc(PlanetHistory.tick))
         history = Q[:ticks] if ticks else Q.all()
     else:
         history = None
     
     if not (h or hs):
         landings = session.query(PlanetLandings.hour, count()).filter(PlanetLandings.planet==planet).group_by(PlanetLandings.hour).all()
         landed = session.query(PlanetLandedOn.hour, count()).filter(PlanetLandedOn.planet==planet).group_by(PlanetLandedOn.hour).all()
         vdrops = session.query(PlanetValueDrops.hour, count()).filter(PlanetValueDrops.planet==planet).group_by(PlanetValueDrops.hour).all()
         idles = session.query(PlanetIdles.hour, count()).filter(PlanetIdles.planet==planet).group_by(PlanetIdles.hour).all()
         hourstats = {
                         'landings' : dict(landings), 'landingsT' : sum([c for hour,c in landings]),
                         'landed'   : dict(landed),   'landedT'   : sum([c for hour,c in landed]),
                         'vdrops'   : dict(vdrops),   'vdropsT'   : sum([c for hour,c in vdrops]),
                         'idles'    : dict(idles),    'idlesT'    : sum([c for hour,c in idles]),
                         }
     else:
         hourstats = None
     
     if not h:
         Q = session.query(PlanetHistory)
         Q = Q.filter(or_(PlanetHistory.hour == 23, PlanetHistory.tick == Updates.current_tick()))
         Q = Q.filter(PlanetHistory.current == planet)
         Q = Q.order_by(desc(PlanetHistory.tick))
         hsummary = Q.all() if hs else Q[:14]
     else:
         hsummary = None
     
     return render(["planet.tpl",["hplanet.tpl","hsplanet.tpl"][hs]][h or hs],
                     request,
                     planet = planet,
                     history = history,
                     hour = datetime.utcnow().hour, hourstats = hourstats,
                     hsummary = hsummary,
                     ticks = ticks,
                   )
Esempio n. 25
0
 def execute(self, request, user, x, y, z, type):
     planet = Planet.load(x,y,z)
     if planet is None:
         return HttpResponseRedirect(reverse("planet_ranks"))
     
     scan = planet.scan(type)
     if scan is None:
         return HttpResponseRedirect(reverse("planet_scans", kwargs={"x":planet.x, "y":planet.y, "z":planet.z}))
     
     return render("scans/base.tpl", request, scan=scan)
Esempio n. 26
0
    def __init__(self, message, m):

        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=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)

        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__()
            traceback.print_exc()
Esempio n. 27
0
 def execute(self, message, user, params):
     
     planet = Planet.load(*params.group(1,3,5))
     if planet is None:
         message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
         return
     
     notice = "DEFCALL: %s wants %s to %s:%s:%s eta %s" % (user.name, params.group(7), params.group(1), params.group(3), 
                                                           params.group(5), params.group(6))
     message.notice(notice, Config.get("Channels", "home"))
Esempio n. 28
0
 def execute(self, message, user, params):
     planet = Planet.load(*params.group(1,3,5))
     if planet is None:
         message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
         return
     
     tick = Updates.current_tick()
     when = int(params.group(6) or 0)
     if 0 < when < 32:
         eta = when
         when += tick
     elif 0 < when <= tick:
         message.alert("Can not unbook targets in the past. You wanted tick %s, but current tick is %s." % (when, tick,))
         return
     else:
         eta = when - tick
     if when > 32767:
         when = 32767 
     
     override = params.group(7)
     
     Q = session.query(Target)
     Q = Q.join(Target.user)
     Q = Q.filter(Target.planet == planet)
     Q = Q.filter(Target.user == user) if override is None else Q
     Q = Q.filter(Target.tick == when) if when else Q.filter(Target.tick >= tick)
     Q = Q.order_by(asc(Target.tick))
     result = Q.all()
     for target in result:
         session.delete(target)
     count = len(result)
     session.commit()
     
     if count < 1:
         reply=("You have no " if override is None else "No ") +"bookings matching %s:%s:%s"%(planet.x,planet.y,planet.z,)
         if when:
             reply+=" for landing on tick %s"%(when,)
         reply+=". If you are trying to unbook someone else's target, you must confirm with 'yes'." if override is None else ""
     else:
         reply="You have unbooked %s:%s:%s"%(planet.x,planet.y,planet.z,)
         if when:
             reply+=" for landing pt %s"%(when,)
             if override:
                 reply+=" (previously held by user %s)"%(result[0].user.name)
         else:
             reply+=" for %d booking(s)"%(count,)
             if override:
                 prev=[]
                 for target in result:
                     prev.append("(%s user:%s)" % (target.tick,target.user.name))
                 reply+=": "+", ".join(prev)
                     
         reply+="."
     message.reply(reply)
     return
Esempio n. 29
0
 def execute(self, message, user, params):
     
     if len(params.groups()) < 3:
         planet = self.get_user_planet(user)
     else:
         planet = Planet.load(*params.group(1,3,5))
         if planet is None:
             message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
             return
     
     message.reply("%s:%s:%s can be hit by planets with value %d or below or score %d or below"%(planet.x,planet.y,planet.z,int(planet.value/PA.getfloat("bash","value")),int(planet.score/PA.getfloat("bash","score"))))
Esempio n. 30
0
 def check_planet(self, request, user):
     coords = request.POST.get(PLANET) or ""
     
     if coords == "Clear":
         if self.user_has_planet(user):
             user.planet = None
             session.commit()
         return False
     
     m = self.coord.match(coords)
     if m:
         planet = Planet.load(*m.group(1,3,5))
     else:
         planet = None
     
     if planet is not None:
         if self.is_user(user):
             user.planet = planet
             if user.is_member():
                 alliance = Alliance.load(Config.get("Alliance","name"))
                 if planet.intel is None:
                     planet.intel = Intel(nick=user.name, alliance=alliance)
                 else:
                     planet.intel.nick = user.name
                     planet.intel.alliance = alliance
             session.commit()
         else:
             user.planet = planet
             session.expunge(user)
         return user.planet.id
     
     pa_id = request.COOKIES.get(PLANET_KEY)
     if self.user_has_planet(user):
         if pa_id == user.planet.id:
             return True
         else:
             return user.planet.id
     elif self.is_user(user):
         if pa_id:
             return False
         else:
             return True
     else:
         if pa_id:
             planet = session.query(Planet).filter_by(id=pa_id).first()
             if planet is None:
                 return False
             else:
                 user.planet = planet
                 session.expunge(user)
                 return True
         else:
             return True
Esempio n. 31
0
    def new(self, message, user, params):
        tick = Updates.current_tick()
        comment = params.group(4) or ""
        when = int(params.group(1))
        waves = params.group(2) or Config.get("Misc", "attwaves")
        if when < PA.getint("numbers", "protection"):
            when += tick
        elif when <= tick:
            message.alert(
                "Can not create attacks in the past. You wanted tick %s, but current tick is %s."
                % (
                    when,
                    tick,
                ))
            return
        if when > 32767:
            when = 32767

        attack = Attack(landtick=when, comment=comment, waves=int(waves))
        session.add(attack)

        for coord in re.findall(loadable.coord, params.group(3)):
            if not coord[4]:
                galaxy = Galaxy.load(coord[0], coord[2])
                if galaxy:
                    attack.addGalaxy(galaxy)

            else:
                planet = Planet.load(coord[0], coord[2], coord[4])
                if planet:
                    attack.addPlanet(planet)

        session.commit()
        message.reply(str(attack))

        # Request scans
        if Config.has_option("Misc", "attscans"):
            scantypes = Config.get("Misc", "attscans")
        else:
            scantypes = ""

        for stype in scantypes:
            for p in attack.planets:
                scan = p.scan(stype)
                if scan and (int(tick) == scan.tick):
                    return
                else:
                    req = Request(target=p, scantype=stype, dists=0)
                    user.requests.append(req)
                    session.commit()
                    push("request", request_id=req.id, mode="request")
        if scantypes:
            message.reply("Scans requested: %s" % (scantypes))
Esempio n. 32
0
    def check_planet(self, request, user):
        coords = request.REQUEST.get(PLANET) or ""

        if coords == "Clear":
            if self.user_has_planet(user):
                user.planet = None
                session.commit()
            return False

        m = self.coord.match(coords)
        if m:
            planet = Planet.load(*m.group(1, 3, 5))
        else:
            planet = None

        if planet is not None:
            if self.is_user(user):
                user.planet = planet
                if user.is_member():
                    alliance = Alliance.load(Config.get("Alliance", "name"))
                    if planet.intel is None:
                        planet.intel = Intel(nick=user.name, alliance=alliance)
                    else:
                        planet.intel.nick = user.name
                        planet.intel.alliance = alliance
                session.commit()
            else:
                user.planet = planet
                session.expunge(user)
            return user.planet.id

        pa_id = request.COOKIES.get(PLANET_KEY)
        if self.user_has_planet(user):
            if pa_id == user.planet.id:
                return True
            else:
                return user.planet.id
        elif self.is_user(user):
            if pa_id:
                return False
            else:
                return True
        else:
            if pa_id:
                planet = session.query(Planet).filter_by(id=pa_id).first()
                if planet is None:
                    return False
                else:
                    user.planet = planet
                    session.expunge(user)
                    return True
            else:
                return True
Esempio n. 33
0
 def planet(self, message, user, params):
     if params.group(6) is None:
         target = Planet.load(*params.group(1,3,5))
         if target is None:
             message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
             return
         if self.user_has_planet(user):
             attacker = user.planet
         else:
             attacker = None
     else:
         target = Planet.load(*params.group(1,3,5))
         if target is None:
             message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
             return
         attacker = Planet.load(*params.group(6,8,10))
         if attacker is None:
             message.alert("No planet with coords %s:%s:%s" % params.group(6,8,10))
             return
     
     self.execute(message, target, attacker)
Esempio n. 34
0
File: request.py Progetto: JDD/DLR
 def execute(self, message, user, params):
     planet = Planet.load(*params.group(1,3,5))
     if planet is None:
         message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
         return
     
     scan = params.group(6).upper()
     dists = int(params.group(7) or 0)
     
     request = self.request(message, user, planet, scan, dists)
     if message.get_chan() != self.scanchan():
         message.reply("Requested a %s Scan of %s:%s:%s. !request cancel %s to cancel the request." % (request.type, planet.x, planet.y, planet.z, request.id,))
Esempio n. 35
0
 def execute(self, message, user, params):
     
     if len(params.groups()) == 1:
         target = Planet(size=int(params.group(1)))
         attacker = None
     elif params.group(4) is None:
         target = Planet.load(*params.group(1,3,5))
         if target is None:
             message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
             return
         if self.user_has_planet(user):
             attacker = user.planet
         else:
             attacker = None
     else:
         target = Planet.load(*params.group(1,3,5))
         if target is None:
             message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
             return
         attacker = Planet.load(*params.group(6,8,10))
         if attacker is None:
             message.alert("No planet with coords %s:%s:%s" % params.group(6,8,10))
             return
     
     reply = ""
     total = 0
     for i in range(1,5):
         cap = target.maxcap(attacker)
         total += cap
         reply+="Wave %d: %d (%d), " % (i,cap,total,)
         target.size -= cap
     message.reply("Caprate: %s%% %s"%(int(target.caprate(attacker)*100),reply.strip(', ')))
Esempio n. 36
0
 def execute(self, message, user, params):
     
     params = self.split_opts(params.group(1))
     reply = ""
     for opt, val in params.items():
         if opt == "planet":
             m = self.planet_coordre.match(val)
             if m:
                 planet = Planet.load(*m.group(1,3,5))
                 if planet is None:
                     continue
                 user.planet = planet
                 reply += " planet=%s:%s:%s"%(planet.x,planet.y,planet.z)
                 if user.is_member():
                     alliance = Alliance.load(Config.get("Alliance","name"))
                     if planet.intel is None:
                         planet.intel = Intel(nick=user.name, alliance=alliance)
                     else:
                         planet.intel.nick = user.name
                         planet.intel.alliance = alliance
             elif val in self.nulls:
                 user.planet = None
                 reply += " planet=None"
         if opt == "password":
             user.passwd = val
             reply += " password=%s"%(val)
         if opt == "email":
             try:
                 user.email = val
             except AssertionError:
                 pass
             else:
                 reply += " email=%s"%(val)
         if opt == "phone":
             user.phone = val
             reply += " phone=%s"%(val)
         if opt == "pubphone":
             if val.lower() in self.true:
                 user.pubphone = True
                 reply += " pubphone=%s"%(True)
             elif val.lower() in self.false:
                 user.pubphone = False
                 reply += " pubphone=%s"%(False)
         if opt == "googlevoice":
             if val.lower() in self.true:
                 user.googlevoice = True
                 reply += " googlevoice=%s"%(True)
             elif val.lower() in self.false:
                 user.googlevoice = False
                 reply += " googlevoice=%s"%(False)
     session.commit()
     message.reply("Updated your preferences:"+reply)
Esempio n. 37
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
Esempio n. 38
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[^>]*>(\d+)\:(\d+)\:(\d+)</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=Planet.load(originx,originy,originz)
            if attacker is None:
                scanlog("Can't find attacker in db: %s:%s:%s"%(originx,originy,originz))
                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
Esempio n. 39
0
    def execute(self, message, user, params):

        p = Planet.load(*params.group(1, 3, 5))
        if p is None:
            message.alert("No planet with coords %s:%s:%s" %
                          params.group(1, 3, 5))
            return
        tick = params.group(6)

        p1 = aliased(PlanetHistory)
        p2 = aliased(PlanetHistory)
        Q = session.query(p1.tick, p1.value, p1.value - p2.value, p1.size,
                          p1.size - p2.size)
        Q = Q.filter(and_(p1.id == p2.id, p1.tick - 1 == p2.tick))
        Q = Q.filter(p1.current == p)

        if tick:
            Q = Q.filter(p1.tick == tick)
            result = Q.first()
            if result is None:
                message.reply("No data for %s:%s:%s on tick %s" %
                              (p.x, p.y, p.z, tick))
                return

            tick, value, vdiff, size, rdiff = result
            reply = "Value on pt%s for %s:%s:%s: " % (tick, p.x, p.y, p.z)
            reply += "value: %s (%s%s)" % (value, ["+", ""][vdiff < 0], vdiff)
            if rdiff != 0:
                reply += " roids: %s%s" % (["+", ""][rdiff < 0], rdiff)
            message.reply(reply)
        else:
            tick = Updates.current_tick()
            Q = Q.filter(p1.tick > (tick - 16)).order_by(asc(p1.tick))
            result = Q.all()
            if len(result) < 1:
                message.reply("No data for %s:%s:%s" % (p.x, p.y, p.z))
                return

            prev = []
            for tick, value, vdiff, size, rdiff in result:
                reply = "pt%s %s (%s%s)" % (
                    tick,
                    self.num2short(value),
                    ["+", ""][vdiff < 0],
                    self.num2short(vdiff),
                )
                if rdiff != 0:
                    reply += " roids: %s%s" % (["+", ""][rdiff < 0], rdiff)
                prev.append(reply)
            reply = "Value in the last 15 ticks on %s:%s:%s: " % (
                p.x, p.y, p.z) + ' | '.join(prev)
            message.reply(reply)
Esempio n. 40
0
    def set_intel(self, message, user, params):
        planet = Planet.load(*params.group(1, 3, 5))
        if planet is None:
            message.alert("No planet with coords %s:%s:%s" %
                          params.group(1, 3, 5))
            return

        if planet.intel is None:
            planet.intel = Intel()

        params = self.split_opts(message.get_msg())
        for opt, val in params.items():
            if opt == "alliance":
                if val in self.nulls:
                    planet.intel.alliance = None
                    continue
                alliance = Alliance.load(val)
                if alliance is None:
                    message.alert("No alliances match %s" % (val, ))
                    continue
                planet.intel.alliance = alliance
            if (opt in options) and (val in self.nulls):
                setattr(planet.intel, opt, None)
                continue
            if opt in ("nick", "fakenick", "bg", "gov", "reportchan"):
                setattr(planet.intel, opt, val)
            if opt in ("defwhore", "covop", "relay"):
                if val.lower() in self.true:
                    setattr(planet.intel, opt, True)
                if val.lower() in self.false:
                    setattr(planet.intel, opt, False)
            if opt in ("amps", "dists"):
                if val.isdigit():
                    setattr(planet.intel, opt, int(val))
            if opt == "comment":
                planet.intel.comment = message.get_msg(
                )[message.get_msg().lower().index("comment=") +
                  len("comment="):]
        session.commit()
        if planet.intel and str(planet.intel):
            message.reply("Information stored for %s:%s:%s -%s" % (
                planet.x,
                planet.y,
                planet.z,
                str(planet.intel),
            ))
        else:
            message.reply("No information stored for %s:%s:%s" % (
                planet.x,
                planet.y,
                planet.z,
            ))
Esempio n. 41
0
 def execute(self, message, user, params):
     
     p = Planet.load(*params.group(1,3,5))
     if p is None:
         message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
         return
     
     sum=params.group(6)
     res=user.planet.resources_per_agent(p)
     reply="Your Seagals will ninja %s resources from %s:%s:%s - 5: %s, 10: %s, 20: %s."%(res,p.x,p.y,p.z,self.num2short(res*5),self.num2short(res*10),self.num2short(res*20))
     if sum:
         reply+=" You need %s Seagals to ninja %sk res."%(int(math.ceil((float(sum)*1000)/res)),sum)
     message.reply(reply)
Esempio n. 42
0
 def execute(self, message, user, params):
     
     planet = Planet.load(*params.group(1,3,5))
     if planet is None:
         message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
         return
     
     notice = "DEFCALL: %s wants %s to %s:%s:%s eta %s" % (user.name, params.group(7), params.group(1), params.group(3), 
                                                           params.group(5), params.group(6))
     if Config.getboolean("Misc", "globaldef"):
         push("broadcast", notice="!#!"+notice.replace(" ","!#!"))
     else:
         message.notice(notice, Config.get("Channels", "home"))
Esempio n. 43
0
 def execute(self, message, user, params):
     
     p = Planet.load(*params.group(1,3,5))
     if p is None:
         message.alert("No planet with coords %s:%s:%s" % params.group(1,3,5))
         return
     
     sum=params.group(6)
     res=user.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.num2short(res*13),self.num2short(res*35))
     if sum:
         reply+=" You need %s Seagals to ninja %sk res."%(int(math.ceil((float(sum)*1000)/res)),sum)
     message.reply(reply)
Esempio n. 44
0
    def list_fleets(self, message, user, params):
        # Check the planet exists
        planet = Planet.load(*params.group(1, 3, 5))
        if planet is None:
            message.alert("No planet with coords %s:%s:%s" %
                          params.group(1, 3, 5))
            return

        # Find all fleets with a known alliance who have defended this planet
        OQ = session.query(
            coalesce(FleetScan.launch_tick, FleetScan.landing_tick),
            literal_column("'From'").label("dir"), Planet.x, Planet.y,
            Planet.z, Alliance.name).select_from(FleetScan)
        OQ = OQ.filter(FleetScan.target_id == planet.id,
                       FleetScan.in_galaxy == False,
                       FleetScan.mission == "Defend")
        OQ = OQ.join(Intel, FleetScan.owner_id == Intel.planet_id).filter(
            Intel.alliance_id != None)
        OQ = OQ.join(Alliance, Intel.alliance_id == Alliance.id).join(
            Planet, FleetScan.owner_id == Planet.id)

        # Find all fleets with a known alliance who have been defended by this planet
        TQ = session.query(
            coalesce(FleetScan.launch_tick, FleetScan.landing_tick),
            literal_column("'To  '").label("dir"), Planet.x, Planet.y,
            Planet.z, Alliance.name).select_from(FleetScan)
        TQ = TQ.filter(FleetScan.owner_id == planet.id,
                       FleetScan.in_galaxy == False,
                       FleetScan.mission == "Defend")
        TQ = TQ.join(Intel, FleetScan.target_id == Intel.planet_id).filter(
            Intel.alliance_id != None)
        TQ = TQ.join(Alliance, Intel.alliance_id == Alliance.id).join(
            Planet, FleetScan.target_id == Planet.id)

        # Combine the results into one sorted list
        results = sorted(OQ.all() + TQ.all(), reverse=True)

        # Quit now if there are no results
        if len(results) == 0:
            message.reply("No suggestions found")
            return

        # Reply to the user
        message.reply("Tick  Dir   Planet     Alliance")
        limit = int(params.group(6) or 5)
        for r in results[:limit]:
            message.reply("%4s  %s  %-9s  %s" % (r[0], r[1], "%s:%s:%s" %
                                                 (r[2], r[3], r[4]), r[5]))
        if len(results) > limit:
            message.reply("%s results not shown (%s total)" %
                          (len(results) - limit, len(results)))
Esempio n. 45
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[^>]*>(\d+)\:(\d+)\:(\d+)</td><td[^>]*>([^<]+)</td><td[^>]*>([^<]+)</td><td[^>]*>(\d+)</td><td[^>]*>(\d+)</td>', page):
            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)

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

            print "JGP fleet "

            attacker=Planet.load(originx,originy,originz)
            if attacker is None:
                print "Can't find attacker in db: %s:%s:%s"%(originx,originy,originz)
                continue
            fleetscan.owner = attacker
            fleetscan.target = scan.planet

            try:
                scan.fleets.append(fleetscan)
                session.commit()
            except IntegrityError, e:
                session.rollback()
                print "Caught integrity exception in jgp: "+e.__str__()
                print "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()
                    print "Exception trying to update jgp: "+e.__str__()
                    traceback.print_exc()
                    continue
Esempio n. 46
0
    def planet(self, message, user, params):
        planet = Planet.load(*params.group(1, 3, 5))
        if planet is None:
            message.reply("No planet with coords %s:%s:%s found" %
                          params.group(1, 3, 5))
            return

        # List of last 10 scans
        if params.group(6) == "o":
            scans = planet.scans.filter_by(scantype=self.type).order_by(
                desc(Scan.id))[:10]
            if len(scans) < 1:
                message.reply(
                    "No %s Scans of %s:%s:%s found" %
                    (PA.get(self.type, "name"), planet.x, planet.y, planet.z))
                return
            prev = []
            for scan in scans:
                prev.append("(pt%s %s)" % (
                    scan.tick,
                    scan.pa_id,
                ))
            reply = "Last 10 %s Scans on %s:%s:%s " % (PA.get(
                self.type,
                "name"), planet.x, planet.y, planet.z) + " ".join(prev)
            message.reply(reply)
            return

        # Latest scan
        scan = planet.scan(self.type)
        if scan is None:
            message.reply(
                "No %s Scans of %s:%s:%s found" %
                (PA.get(self.type, "name"), planet.x, planet.y, planet.z))
            return

        # Link to scan
        if params.group(7) == "l":
            reply = "%s on %s:%s:%s " % (
                scan.type,
                planet.x,
                planet.y,
                planet.z,
            )
            reply += self.url(scan.link, user)
            message.reply(reply)
            return

        # Display the scan
        message.reply(self.url(str(scan), user))
Esempio n. 47
0
class planet(graphs):
    load = staticmethod(lambda x, y, z, name: Planet.load(x, y, z))
    title = staticmethod(lambda o: "%s:%s:%s" % (
        o.x,
        o.y,
        o.z,
    ))
    query = {
        'values':
        session.query(PlanetHistory.tick, PlanetHistory.size,
                      PlanetHistory.score, PlanetHistory.value),
        'ranks':
        session.query(PlanetHistory.tick, PlanetHistory.size_rank,
                      PlanetHistory.score_rank, PlanetHistory.value_rank),
    }
Esempio n. 48
0
    def execute(self, message, user, params):

        planet = Planet.load(*params.group(1, 3, 5))
        if planet is None:
            message.reply("No planet with coords %s:%s:%s found" %
                          params.group(1, 3, 5))
            return

        notice = "DEFCALL: %s wants %s to %s:%s:%s eta %s" % (
            user.name, params.group(7), params.group(1), params.group(3),
            params.group(5), params.group(6))
        if Config.getboolean("Misc", "globaldef"):
            push("broadcast", notice="!#!" + notice.replace(" ", "!#!"))
        else:
            message.notice(notice, Config.get("Channels", "home"))
Esempio n. 49
0
    def planet_galaxy(self, message, user, params):
        # Planet
        if params.group(5) is not None:
            planet = Planet.load(*params.group(1,3,5))
            if planet is None:
                message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
            else:
                self.execute(message, planet=planet)

        # Galaxy
        else:
            galaxy = Galaxy.load(*params.group(1,3))
            if galaxy is None:
                message.reply("No galaxy with coords %s:%s" % params.group(1,3))
            else:
                self.execute(message, galaxy=galaxy)
Esempio n. 50
0
    def execute(self, request, user, x, y, z, type):
        planet = Planet.load(x, y, z)
        if planet is None:
            return HttpResponseRedirect(reverse("planet_ranks"))

        scan = planet.scan(type)
        if scan is None:
            return HttpResponseRedirect(
                reverse("planet_scans",
                        kwargs={
                            "x": planet.x,
                            "y": planet.y,
                            "z": planet.z
                        }))

        return render("scans/base.tpl", request, scan=scan)
Esempio n. 51
0
 def planet_galaxy(self, message, user, params):
     # Planet
     if params.group(5) is not None:
         planet = Planet.load(*params.group(1,3,5))
         if planet is None:
             message.reply("No planet with coords %s:%s:%s found" % params.group(1,3,5))
             return
         message.reply(str(planet))
         return
     
     # Galaxy
     else:
         galaxy = Galaxy.load(*params.group(1,3))
         if galaxy is None:
             message.reply("No galaxy with coords %s:%s" % params.group(1,3))
             return
         message.reply(str(galaxy))
         return
Esempio n. 52
0
 def add(self, message, user, params):
     id = int(params.group(1))
     attack = Attack.load(id)
     if attack is None:
         message.alert("No attack exists with id %d" %(id))
         return
     
     for coord in re.findall(loadable.coord, params.group(2)):
         if not coord[4]:
             galaxy = Galaxy.load(coord[0],coord[2])
             if galaxy:
                 attack.addGalaxy(galaxy)
         
         else:
             planet = Planet.load(coord[0],coord[2],coord[4])
             if planet:
                 attack.addPlanet(planet)
     
     session.commit()
     message.reply(str(attack))
Esempio n. 53
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 (\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
            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)
Esempio n. 54
0
    def execute(self, message, user, params):
        alliance = Alliance.load(params.group(1))
        if (alliance is None) and (params.group(1).lower()
                                   not in ["None", "<>", "?"]):
            message.alert("No alliances match %s" % (params.group(1)))
            return

        reply = "Planets added to '%s':" % (alliance.name
                                            if alliance else "None")

        planets = self.planet_coordre.findall(params.group(2))
        for coord in planets:
            planet = Planet.load(coord[0], coord[2], coord[4])
            if planet:
                if planet.intel is None:
                    planet.intel = Intel()
                planet.intel.alliance = alliance
                reply += " %s:%s:%s" % (coord[0], coord[2], coord[4])

        session.commit()
        message.reply(reply)
Esempio n. 55
0
    def execute(self, message, user, params):
        tick = Updates.current_tick()
        url = Config.get("URL", "bcalc")
        i = 1
        coords, clazz = params.groups()
        for coord in re.findall(loadable.coord, coords):
            planet = Planet.load(coord[0], coord[2], coord[4])
            if planet:
                scan = planet.scan("A")

                if scan and (int(tick) <= scan.tick + 12):
                    url = scan.addPlanetToCalc(
                        url, False, i, self.class_translation[clazz]
                        if clazz in self.class_translation.keys() else None)
                else:
                    message.reply("Missing a scan for %d:%d:%d" %
                                  (planet.x, planet.y, planet.z))
                    return
            i = i + 1

        message.reply("Calc: %s" % (tinyurl.create_one("%s&att_fleets=%d" %
                                                       (url, i - 1))))