Exemple #1
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))
Exemple #2
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,))
Exemple #3
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],
        )
Exemple #4
0
 def execute(self, request, user, x, y, h=False, hs=False, ticks=None):
     galaxy = Galaxy.load(x,y)
     if galaxy is None:
         return HttpResponseRedirect(reverse("galaxy_ranks"))
     
     ticks = int(ticks or 0) if (h or hs) else 12
     
     if not (h or hs):
         Q = session.query(Planet, Intel.nick, Alliance.name)
         Q = Q.outerjoin(Planet.intel)
         Q = Q.outerjoin(Intel.alliance)
         Q = Q.filter(Planet.active == True)
         Q = Q.filter(Planet.galaxy == galaxy)
         Q = Q.order_by(asc(Planet.z))
         planets = Q.all()
         exiles = galaxy.exiles[:10]
     else:
         planets, exiles = None, None
     
     if not hs:
         sizediffvalue = GalaxyHistory.rdiff * PA.getint("numbers", "roid_value")
         valuediffwsizevalue = GalaxyHistory.vdiff - sizediffvalue
         resvalue = valuediffwsizevalue * PA.getint("numbers", "res_value")
         shipvalue = valuediffwsizevalue * PA.getint("numbers", "ship_value")
         xpvalue = GalaxyHistory.xdiff * PA.getint("numbers", "xp_value")
         Q = session.query(GalaxyHistory,
                             sizediffvalue,
                             valuediffwsizevalue,
                             resvalue, shipvalue,
                             xpvalue,
                             )
         Q = Q.filter(GalaxyHistory.current == galaxy)
         Q = Q.order_by(desc(GalaxyHistory.tick))
         history = Q[:ticks] if ticks else Q.all()
     else:
         history = None
     
     if not h:
         Q = session.query(GalaxyHistory)
         Q = Q.filter(or_(GalaxyHistory.hour == 23, GalaxyHistory.tick == Updates.current_tick()))
         Q = Q.filter(GalaxyHistory.current == galaxy)
         Q = Q.order_by(desc(GalaxyHistory.tick))
         hsummary = Q.all() if hs else Q[:14]
     else:
         hsummary = None
     
     return render(["galaxy.tpl",["hgalaxy.tpl","hsgalaxy.tpl"][hs]][h or hs],
                     request,
                     galaxy = galaxy,
                     planets = planets,
                     exiles = exiles,
                     history = history,
                     hsummary = hsummary,
                     ticks = ticks,
                   )
Exemple #5
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))
Exemple #6
0
class galaxy(graphs):
    load = staticmethod(lambda x, y, z, name: Galaxy.load(x, y))
    title = staticmethod(lambda o: "%s:%s" % (
        o.x,
        o.y,
    ))
    query = {
        'values':
        session.query(GalaxyHistory.tick, GalaxyHistory.size,
                      GalaxyHistory.score, GalaxyHistory.value),
        'ranks':
        session.query(GalaxyHistory.tick, GalaxyHistory.size_rank,
                      GalaxyHistory.score_rank, GalaxyHistory.value_rank),
    }
Exemple #7
0
 def execute(self, message, user, params):
     
     galaxy = Galaxy.load(*params.group(1,3))
     if galaxy is None:
         message.alert("No galaxy with coords %s:%s" % params.group(1,3))
         return
     
     penis = galaxy.galpenis
     if penis is None:
         message.alert("No galpenis stats matching %s:%s" % params.group(1,3))
         return
     
     message.reply("galpenis for '%s' is %s score long. This makes %s:%s rank: %s for galpenis in the universe!" % (
                     galaxy.name, penis.penis, galaxy.x, galaxy.y, penis.rank,))
Exemple #8
0
    def execute(self, message, user, params):

        # Planet or Galaxy
        if len(params.groups()) == 5:
            # 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

        # User or Alliance
        else:
            alliance = Alliance.load(params.group(1)) if params.group(1) is not None else None
            # Alliance
            if alliance is not None:
                message.reply(str(alliance))
                return

            # User
            if params.group(1) is None:
                message.reply(str(self.get_user_planet(user)))
                return
            elif not self.is_user(user):
                raise PNickParseError
            elif not user.is_member():
                message.reply("No alliance matching '%s' found" % (params.group(1),))
                return
            else:
                lookup = User.load(params.group(1), exact=False)
                if lookup is None:
                    message.reply("No alliance or user matching '%s' found" % (params.group(1),))
                    return
                elif lookup.planet is None:
                    message.reply("User %s has not entered their planet details" % (lookup.name,))
                    return
                else:
                    message.reply(str(lookup.planet))
                    return
Exemple #9
0
 def execute(self, request, user, x, y, through):
     galaxy = Galaxy.load(x,y)
     if galaxy is None:
         return HttpResponseRedirect(reverse("exiles"))
     
     if through:
         exiles = galaxy.exiles
     else:
         Q = session.query(PlanetExiles)
         Q = Q.join(PlanetExiles.planet)
         Q = Q.filter(and_(Planet.x == galaxy.x, Planet.y == galaxy.y))
         Q = Q.order_by(desc(PlanetExiles.tick))
         exiles = Q.all()
     
     return render("exiles.tpl", request, galaxy = galaxy, through = through, exiles = exiles)
Exemple #10
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))
Exemple #11
0
 def execute(self, request, user, x, y):
     tick = Updates.midnight_tick()
     
     galaxy = Galaxy.load(x,y)
     if galaxy is None:
         return HttpResponseRedirect(reverse("galaxy_ranks"))
     gh = galaxy.history(tick)
     
     Q = session.query(Planet, PlanetHistory, Intel.nick, Alliance.name)
     Q = Q.outerjoin(Planet.intel)
     Q = Q.outerjoin(Intel.alliance)
     Q = Q.outerjoin((PlanetHistory, and_(Planet.id == PlanetHistory.id, PlanetHistory.tick == tick)))
     Q = Q.filter(Planet.active == True)
     Q = Q.filter(Planet.galaxy == galaxy)
     Q = Q.order_by(asc(Planet.z))
     return render("galaxy.tpl", request, galaxy=galaxy, gh=gh, planets=Q.all())
Exemple #12
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)
Exemple #13
0
 def galaxy(self, message, user, params):
     galaxy = Galaxy.load(*params.group(1,3))
     if galaxy is None:
         message.alert("No galaxy with coords %s:%s" % params.group(1,3))
         return
     
     Q = session.query(sum(Planet.value), sum(Planet.score),
                       sum(Planet.size), sum(Planet.xp),
                       count(), Planet.race)
     Q = Q.filter(Planet.galaxy == galaxy)
     Q = Q.filter(Planet.active == True)
     Q = Q.group_by(Planet.race)
     Q = Q.order_by(asc(Planet.race))
     result = Q.all()
     
     self.execute(message, "%s:%s" % (galaxy.x, galaxy.y,), result)
Exemple #14
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)
Exemple #15
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
Exemple #16
0
    def execute(self, request, user, x, y, through):
        galaxy = Galaxy.load(x, y)
        if galaxy is None:
            return HttpResponseRedirect(reverse("exiles"))

        if through:
            exiles = galaxy.exiles
        else:
            Q = session.query(PlanetExiles)
            Q = Q.join(PlanetExiles.planet)
            Q = Q.filter(and_(Planet.x == galaxy.x, Planet.y == galaxy.y))
            Q = Q.order_by(desc(PlanetExiles.tick))
            exiles = Q.all()

        return render("exiles.tpl",
                      request,
                      galaxy=galaxy,
                      through=through,
                      exiles=exiles)
Exemple #17
0
Fichier : intel.py Projet : JDD/DLR
    def view_intel(self, message, user, params):

        if params.group(5) is None:
            galaxy = Galaxy.load(*params.group(1, 3))
            if galaxy is None:
                message.alert("No galaxy with coords %s:%s" % params.group(1, 3))
                return

            Q = session.query(Planet)
            Q = Q.filter(Planet.active == True)
            Q = Q.filter(Planet.galaxy == galaxy)
            Q = Q.order_by(asc(Planet.z))
            prev = []
            for planet in Q:
                if planet.intel is not None and (planet.intel.nick or planet.alliance):
                    reply = "#%s" % (planet.z,)
                    if planet.intel.nick:
                        reply += " %s" % (planet.intel.nick,)
                    if planet.alliance and planet.alliance.alias:
                        reply += " [%s]" % (planet.alliance.alias[:3],)
                    elif planet.alliance:
                        reply += " [%s]" % (planet.alliance.name[:3],)
                    prev.append(reply)
            if len(prev):
                reply = "Intel %d:%d - " % (galaxy.x, galaxy.y)
                reply += "Score (%d) Value (%d) Size (%d)" % (galaxy.score_rank, galaxy.value_rank, galaxy.size_rank)
                reply += " - "
                reply += " - ".join(prev)
                message.reply(reply)
            else:
                message.reply("No information stored for %s:%s" % (galaxy.x, galaxy.y))
            return

        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 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))
Exemple #18
0
 def execute(self, request, user, x, y, types):
     types = types.upper()
     
     galaxy = Galaxy.load(x,y)
     if galaxy is None:
         return HttpResponseRedirect(reverse("galaxy_ranks"))
     
     group = []
     scans = []
     for planet in galaxy.planets:
         if not planet.active:
             continue
         group.append((planet, [],))
         
         for type in Scan._scan_types:
             if type in types:
                 group[-1][1].append(planet.scan(type))
                 scans.append(planet.scan(type))
     
     return render("scans/galaxy.tpl", request, galaxy=galaxy, group=group, scans=scans)
Exemple #19
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))
Exemple #20
0
 def execute(self, request, user, x, y, types):
     types = types.upper()
     
     galaxy = Galaxy.load(x,y)
     if galaxy is None:
         return HttpResponseRedirect(reverse("galaxy_ranks"))
     
     group = []
     scans = []
     for planet in galaxy.planets:
         if not planet.active:
             continue
         group.append((planet, [],))
         
         for type in Scan._scan_types:
             if type in types:
                 group[-1][1].append(planet.scan(type))
                 scans.append(planet.scan(type))
     
     return render("scans/galaxy.tpl", request, galaxy=galaxy, group=group, scans=scans)
Exemple #21
0
    def execute(self, message, user, params):

        galaxy = Galaxy.load(*params.group(1, 3))
        if galaxy is None:
            message.alert("No galaxy with coords %s:%s" % params.group(1, 3))
            return

        penis = galaxy.galpenis
        if penis is None:
            message.alert("No galaxy growth stats matching %s:%s" %
                          params.group(1, 3))
            return

        message.reply(
            "galaxy growth for '%s' is %s score long. This makes %s:%s rank: %s for growth in the universe!"
            % (
                galaxy.name,
                penis.penis,
                galaxy.x,
                galaxy.y,
                penis.rank,
            ))
Exemple #22
0
 def execute(self, request, user, x, y):
     galaxy = Galaxy.load(x,y)
     if galaxy is None:
         return HttpResponseRedirect(reverse("galaxy_ranks"))
     
     group = []
     scans = []
     for planet in galaxy.planets:
         if not planet.active:
             continue
         group.append((planet, [],))
         if planet.scan("P"):
             group[-1][1].append(planet.scan("P"))
             scans.append(planet.scan("P"))
         
         if planet.scan("D"):
             group[-1][1].append(planet.scan("D"))
             scans.append(planet.scan("D"))
         
         if planet.scan("A") or planet.scan("U"):
             group[-1][1].append(planet.scan("A") or planet.scan("U"))
             scans.append(planet.scan("A") or planet.scan("U"))
     
     return render("scans/galaxy.tpl", request, galaxy=galaxy, group=group, scans=scans)
Exemple #23
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))
Exemple #24
0
 def execute(self, request, user, x, y):
     galaxy = Galaxy.load(x,y)
     if galaxy is None:
         return HttpResponseRedirect(reverse("galaxy_ranks"))
     
     group = []
     scans = []
     for planet in galaxy.planets:
         if not planet.active:
             continue
         group.append((planet, [],))
         if planet.scan("P"):
             group[-1][1].append(planet.scan("P"))
             scans.append(planet.scan("P"))
         
         if planet.scan("D"):
             group[-1][1].append(planet.scan("D"))
             scans.append(planet.scan("D"))
         
         if planet.scan("A") or planet.scan("U"):
             group[-1][1].append(planet.scan("A") or planet.scan("U"))
             scans.append(planet.scan("A") or planet.scan("U"))
     
     return render("scans/galaxy.tpl", request, galaxy=galaxy, group=group, scans=scans)
Exemple #25
0
    def execute(self, message, user, params):
        tick = Updates.current_tick()
        # Galaxy Scan
        if params.group(5) is None:

            #            Access Control:
            #            Uncomment this and change "group" to the lowest group that can request galscans.
            #            if not user.is_group():
            #                message.alert("Insufficient access for galaxy scans.")
            #                return

            galaxy = Galaxy.load(*params.group(1, 3))
            if galaxy is None:
                message.alert("No galaxy with coords %s:%s" % params.group(1, 3))
                return
            planets = galaxy.planets
            galscan = Config.has_option("Misc", "galscans") and Config.getboolean("Misc", "galscans")
        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
            planets = [planet]
            galscan = False

        # Scan Quota
        if Config.has_section("ScanQuota"):
            opts = Config.options("ScanQuota")
            q = []
            for o in opts:
                if int(o) >= user.access:
                    q.append(int(o))
            if q:
                ScanQuota = Config.getint("ScanQuota", str(min(q)))
                reqs = (
                    session.query(Request.id)
                    .filter(Request.requester_id == user.id)
                    .filter(Request.tick == tick)
                    .count()
                )
                if (reqs + len(planets) * len(params.group(6).upper())) > ScanQuota:
                    message.reply(
                        "This request will exceed your scan quota for this tick (%d scans remaining). "
                        % (ScanQuota - reqs)
                        + "Try searching with !planet, !dev, !unit, !news, !jgp, !au."
                    )
                    return

        dists = int(params.group(7) or 0)
        galdists = []

        mergescans = (not galscan) and (
            Config.has_option("Misc", "maxscans")
            and len(planets) * len(params.group(6)) > Config.getint("Misc", "maxscans")
        )

        for planet in planets:
            if galscan or mergescans:
                galdists.append(planet.intel.dists if planet.intel else 0)
                if len(galdists) < len(planets):
                    continue
            types = 0
            for scantype in params.group(6).upper():
                # Reject requests for incoming scans
                if not PA.getboolean(scantype, "request"):
                    message.alert("%s scans cannot be requested." % (PA.get(scantype, "name")))
                    continue
                types += 1
                if galscan or mergescans:
                    # Request the scans
                    for i in range(len(planets)):
                        request = self.request(message, user, planets[i], scantype, galdists[i], galscan or mergescans)
                    # Inform the requester
                    if galscan and (message.get_chan() != self.scanchan()):
                        message.reply(
                            "Requested a Galaxy %s Scan of %s:%s. !request cancel %s:%s to cancel the request."
                            % (request.type, planet.x, planet.y, request.id - len(planets) + 1, request.id)
                        )
                    # Check for existing scans
                    scan = planet.scan(scantype)
                    if scan and request.tick - scan.tick < PA.getint(scantype, "expire"):
                        message.reply(
                            "%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable."
                            % (scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id)
                        )
                        # Cancel requests with a 0-tick old scan, if required
                        if request.tick == scan.tick:
                            req0age = (
                                Config.getint("Misc", "req0agej")
                                if request.scantype == "J"
                                else Config.getint("Misc", "req0age")
                            )
                            if req0age == 1:
                                Q = (
                                    session.query(Request)
                                    .filter(Request.tick == request.tick)
                                    .filter(Request.planet_id == request.planet_id)
                                )
                                Q = Q.filter(Request.scantype == request.scantype).filter(
                                    Request.requester_id == request.requester_id
                                )
                                if Q.count() == 1:
                                    request.active = False
                                    message.reply(
                                        "Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request."
                                        % (request.id)
                                    )
                                    message.privmsg(
                                        "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()
                                    )
                            elif req0age == 0:
                                request.active = False
                                message.reply("Request %s cancelled due to an existing scan." % (request.id))
                                message.privmsg(
                                    "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()
                                )

                    # Tell the scanners
                    requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon"
                    if galscan:
                        message.privmsg(
                            "[%s:%s] %s requested a Galaxy %s Scan of %s:%s Max Dists(i:%s%s) "
                            % (
                                request.id - len(planets) + 1,
                                request.id,
                                requester,
                                request.type,
                                planet.x,
                                planet.y,
                                max(galdists),
                                "/r:%s" % dists if dists > 0 else "",
                            )
                            + Config.get("URL", "reqgscan") % (planet.x, planet.y),
                            self.scanchan(),
                        )
                else:
                    request = self.request(message, user, planet, scantype, 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)
                        )

                    # Check for existing scans
                    scan = planet.scan(scantype)
                    if scan and request.tick - scan.tick < PA.getint(scan.scantype, "expire"):
                        message.reply(
                            "%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable."
                            % (scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id)
                        )
                        # Cancel requests with a 0-tick old scan, if required
                        if request.tick == scan.tick:
                            req0age = (
                                Config.getint("Misc", "req0agej")
                                if request.scantype == "J"
                                else Config.getint("Misc", "req0age")
                            )
                            if req0age == 1:
                                Q = (
                                    session.query(Request)
                                    .filter(Request.tick == request.tick)
                                    .filter(Request.planet_id == request.planet_id)
                                )
                                Q = Q.filter(Request.scantype == request.scantype).filter(
                                    Request.requester_id == request.requester_id
                                )
                                if Q.count() == 1:
                                    request.active = False
                                    message.reply(
                                        "Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request."
                                        % (request.id)
                                    )
                                    message.privmsg(
                                        "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()
                                    )
                            elif req0age == 0:
                                request.active = False
                                message.reply("Request %s cancelled due to an existing scan." % (request.id))
                                message.privmsg(
                                    "Cancelled scan request %s due to existing scan" % (request.id), self.scanchan()
                                )

            if mergescans:
                message.reply(
                    "Requested %d scans. !request cancel %s:%s to cancel the request."
                    % (len(planets) * types, request.id - len(planets) * types + 1, request.id)
                )
                message.privmsg(
                    "[%s:%s] %s requested %d scans (%s) Max Dists(i:%s%s). !request links for details "
                    % (
                        request.id - len(planets) * types + 1,
                        request.id,
                        requester,
                        len(planets) * types,
                        params.group(6).upper(),
                        max(galdists),
                        "/r:%s" % dists if dists > 0 else "",
                    ),
                    self.scanchan(),
                )
        session.commit()
Exemple #26
0
    def view_intel(self, message, user, params):

        if params.group(5) is None:
            galaxy = Galaxy.load(*params.group(1, 3))
            if galaxy is None:
                message.alert("No galaxy with coords %s:%s" %
                              params.group(1, 3))
                return

            Q = session.query(Planet)
            Q = Q.filter(Planet.active == True)
            Q = Q.filter(Planet.galaxy == galaxy)
            Q = Q.order_by(asc(Planet.z))
            prev = []
            for planet in Q:
                if planet.intel is not None and (planet.intel.nick
                                                 or planet.alliance):
                    reply = "#%s" % (planet.z, )
                    if planet.intel.nick:
                        reply += " %s" % (planet.intel.nick, )
                    if planet.alliance and planet.alliance.alias:
                        reply += " [%s]" % (planet.alliance.alias[:3], )
                    elif planet.alliance:
                        reply += " [%s]" % (planet.alliance.name[:3], )
                    prev.append(reply)
            if len(prev):
                reply = "Intel %d:%d - " % (
                    galaxy.x,
                    galaxy.y,
                )
                reply += "Score (%d) Value (%d) Size (%d)" % (
                    galaxy.score_rank, galaxy.value_rank, galaxy.size_rank)
                reply += " - "
                reply += " - ".join(prev)
                message.reply(reply)
            else:
                message.reply("No information stored for %s:%s" % (
                    galaxy.x,
                    galaxy.y,
                ))
            return

        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 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,
            ))
Exemple #27
0
 def execute(self, message, user, params):
     
     tick = Updates.current_tick()
     
     # Planet or Galaxy
     if len(params.groups()) == 6:
         when = int(params.group(6) or 0)
         if when and when < 32:
             when += tick
         elif when and when <= tick:
             message.alert("Can not check status on the past. You wanted tick %s, but current tick is %s." % (when, tick,))
             return
         
         # Planet
         if params.group(5) is not None:
             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
             
             Q = session.query(User.name, Target.tick)
             Q = Q.join(Target.user)
             Q = Q.filter(Target.planet == planet)
             Q = Q.filter(Target.tick == when) if when else Q.filter(Target.tick > tick)
             Q = Q.order_by(asc(Target.tick))
             result = Q.all()
             
             if len(result) < 1:
                 reply="No bookings matching planet %s:%s:%s" % (planet.x, planet.y, planet.z,)
                 if when:
                     reply+=" for tick %s"%(when,)
                 message.reply(reply)
                 return
             
             reply="Status for %s:%s:%s - " % (planet.x, planet.y, planet.z,)
             if when:
                 user, land = result[0]
                 reply+="booked for landing pt %s (eta %s) by %s"%(land,land-tick,user)
             else:
                 prev=[]
                 for user, land in result:
                     prev.append("(%s user:%s)" % (land,user))
                 reply+=", ".join(prev)
             message.reply(reply)
             return
         
         # Galaxy
         else:
             galaxy = Galaxy.load(*params.group(1,3))
             if galaxy is None:
                 message.alert("No galaxy with coords %s:%s" % params.group(1,3))
                 return
             
             Q = session.query(Planet.z, User.name, Target.tick)
             Q = Q.join(Target.planet)
             Q = Q.join(Target.user)
             Q = Q.filter(Planet.active == True)
             Q = Q.filter(Planet.galaxy == galaxy)
             Q = Q.filter(Target.tick == when) if when else Q.filter(Target.tick > tick)
             Q = Q.order_by(asc(Planet.z))
             result = Q.all()
             
             if len(result) < 1:
                 reply="No bookings matching galaxy %s:%s" % (galaxy.x, galaxy.y,)
                 if when:
                     reply+=" for tick %s"%(when,)
                 message.reply(reply)
                 return
             
             reply="Target information for %s:%s" % (galaxy.x, galaxy.y,)
             reply+=" landing on tick %s (eta %s): "%(when,when-tick) if when else ": "
             
             ticks={}
             for z, user, land in result:
                 if not ticks.has_key(land):
                     ticks[land]=[]
                 ticks[land].append((z, user,))
             sorted_keys=ticks.keys()
             sorted_keys.sort()
             
             replies = []
             for land in sorted_keys:
                 prev=[]
                 for z, user in ticks[land]:
                     prev.append("(%s user:%s)" % (z,user))
                 replies.append("Tick %s (eta %s) "%(land,land-tick) +", ".join(prev))
             replies[0] = reply + replies[0]
             
             message.reply("\n".join(replies))
             return
     
     # User or Alliance
     else:
         when = int(params.group(2) or 0)
         if when and when < 80:
             when += tick
         elif when and when <= tick:
             message.alert("Can not check status on the past. You wanted tick %s, but current tick is %s." % (when, tick,))
             return
         
         if params.group(1) is None and not self.is_user(user):
             raise PNickParseError
         booker = User.load(params.group(1), exact=False) if params.group(1) is not None else user
         alliance = (Alliance(name="Unknown") if params.group(1).lower() == "unknown" else Alliance.load(params.group(1))) if booker is None else None
         if (booker or alliance) is None:
             message.reply("No alliance or user matching '%s' found" % (params.group(1),))
             return
         
         # User
         if booker is not None:
             Q = session.query(Planet, Target.tick)
             Q = Q.join(Target.planet)
             Q = Q.join(Target.user)
             Q = Q.filter(Planet.active == True)
             Q = Q.filter(Target.user == booker)
             Q = Q.filter(Target.tick == when) if when else Q.filter(Target.tick > tick)
             Q = Q.order_by(asc(Target.tick))
             Q = Q.order_by(asc(Planet.x))
             Q = Q.order_by(asc(Planet.y))
             Q = Q.order_by(asc(Planet.z))
             result = Q.all()
             
             if len(result) < 1:
                 reply="No bookings matching user %s" % (booker.name,)
                 if when:
                     reply+=" for tick %s"%(when,)
                 message.reply(reply)
                 return
             
             reply="Bookings matching user %s" % (booker.name,)
             reply+=" landing on tick %s (eta %s): "%(when,when-tick) if when else ": "
             
             prev=[]
             for planet, land in result:
                 prev.append("(%s:%s:%s%s)" % (planet.x, planet.y, planet.z, "" if when else " landing pt%s/eta %s" % (land,land-tick,),))
             reply+=", ".join(prev)
             message.reply(reply)
             return
         
         # Alliance
         else:
             Q = session.query(Planet, User.name, Target.tick)
             Q = Q.join(Target.planet)
             Q = Q.join(Planet.intel) if alliance.id else Q.outerjoin(Planet.intel)
             Q = Q.join(Target.user)
             Q = Q.filter(Planet.active == True)
             Q = Q.filter(Intel.alliance == (alliance if alliance.id else None))
             Q = Q.filter(Target.tick == when) if when else Q.filter(Target.tick > tick)
             Q = Q.order_by(asc(Planet.x))
             Q = Q.order_by(asc(Planet.y))
             Q = Q.order_by(asc(Planet.z))
             result = Q.all()
             
             if len(result) < 1:
                 reply="No active bookings matching alliance %s" %(alliance.name)
                 if when:
                     reply+=" for tick %s."%(when,)
                 message.reply(reply)
                 return
             
             reply="Target information for %s"%(alliance.name)
             reply+=" landing on tick %s (eta %s): "%(when,when-tick) if when else ": "
             
             ticks={}
             for planet, user, land in result:
                 if not ticks.has_key(land):
                     ticks[land]=[]
                 ticks[land].append((planet, user,))
             sorted_keys=ticks.keys()
             sorted_keys.sort()
             
             replies = []
             for land in sorted_keys:
                 prev=[]
                 for planet, user in ticks[land]:
                     prev.append("(%s:%s:%s %s)" % (planet.x,planet.y,planet.z,user))
                 replies.append("Tick %s (eta %s) "%(land,land-tick) +", ".join(prev))
             replies[0] = reply + replies[0]
             
             message.reply("\n".join(replies))
             return
Exemple #28
0
 def execute(self, message, user, params):
     
     if params.group(5) is None:
         galaxy = Galaxy.load(*params.group(1,3))
         if galaxy is None:
             message.alert("No galaxy with coords %s:%s" % params.group(1,3))
             return
         
         Q = session.query(Planet)
         Q = Q.filter(Planet.active == True)
         Q = Q.filter(Planet.galaxy == galaxy)
         Q = Q.order_by(asc(Planet.z))
         prev = []
         for planet in Q:
             if planet.intel is not None:
                 reply = "#%s"%(planet.z,)
                 if planet.intel.nick:
                     reply += " %s"%(planet.intel.nick,)
                 if planet.alliance:
                     reply += " [%s]"%(planet.alliance.name[:3],)
                 prev.append(reply)
         if len(prev):
             reply ="Intel %d:%d - "%(galaxy.x,galaxy.y,)
             reply+="Score (%d) Value (%d) Size (%d)"%(galaxy.score_rank,galaxy.value_rank,galaxy.size_rank)
             reply+=" - "
             reply+=" - ".join(prev)
             message.reply(reply)
         else:
             message.reply("No information stored for %s:%s" % (galaxy.x, galaxy.y,))
         return
     
     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","scanner","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 == "dists":
             try:
                 planet.intel.dists = int(val)
             except ValueError:
                 pass
         if opt == "comment":
             planet.intel.comment = message.get_msg().split("comment=")[1]
     session.commit()
     if 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,))
Exemple #29
0
 def planet_galaxy(self, message, user, params):
     tick = Updates.current_tick()
     when = int(params.group(6) or 0)
     if when and when < PA.getint("numbers", "protection"):
         when += tick
     elif when and when <= tick:
         message.alert("Can not check status on the past. You wanted tick %s, but current tick is %s." % (when, tick,))
         return
     
     # Planet
     if params.group(5) is not None:
         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
         
         Q = session.query(User.name, Target.tick)
         Q = Q.join(Target.user)
         Q = Q.filter(Target.planet == planet)
         Q = Q.filter(Target.tick == when) if when else Q.filter(Target.tick > tick)
         Q = Q.order_by(asc(Target.tick))
         result = Q.all()
         
         if len(result) < 1:
             reply="No bookings matching planet %s:%s:%s" % (planet.x, planet.y, planet.z,)
             if when:
                 reply+=" for tick %s"%(when,)
             message.reply(reply)
             return
         
         reply="Status for %s:%s:%s - " % (planet.x, planet.y, planet.z,)
         if when:
             user, land = result[0]
             reply+="booked for landing pt %s (eta %s) by %s"%(land,land-tick,user)
         else:
             prev=[]
             for user, land in result:
                 prev.append("(%s user:%s)" % (land,user))
             reply+=", ".join(prev)
         message.reply(reply)
         return
     
     # Galaxy
     else:
         galaxy = Galaxy.load(*params.group(1,3))
         if galaxy is None:
             message.alert("No galaxy with coords %s:%s" % params.group(1,3))
             return
         
         Q = session.query(Planet.z, User.name, Target.tick)
         Q = Q.join(Target.planet)
         Q = Q.join(Target.user)
         Q = Q.filter(Planet.active == True)
         Q = Q.filter(Planet.galaxy == galaxy)
         Q = Q.filter(Target.tick == when) if when else Q.filter(Target.tick > tick)
         Q = Q.order_by(asc(Planet.z))
         result = Q.all()
         
         if len(result) < 1:
             reply="No bookings matching galaxy %s:%s" % (galaxy.x, galaxy.y,)
             if when:
                 reply+=" for tick %s"%(when,)
             message.reply(reply)
             return
         
         reply="Target information for %s:%s" % (galaxy.x, galaxy.y,)
         reply+=" landing on tick %s (eta %s): "%(when,when-tick) if when else ": "
         
         ticks={}
         for z, user, land in result:
             if not ticks.has_key(land):
                 ticks[land]=[]
             ticks[land].append((z, user,))
         sorted_keys=ticks.keys()
         sorted_keys.sort()
         
         replies = []
         for land in sorted_keys:
             prev=[]
             for z, user in ticks[land]:
                 prev.append("(%s user:%s)" % (z,user))
             replies.append("Tick %s (eta %s) "%(land,land-tick) +", ".join(prev))
         replies[0] = reply + replies[0]
         
         message.reply("\n".join(replies))
         return
Exemple #30
0
    def execute(self, message, user, params):
        tick = Updates.current_tick()
        # Galaxy Scan
        if params.group(5) is None:

#            Access Control:
#            Uncomment this and change "group" to the lowest group that can request galscans.
#            if not user.is_group():
#                message.alert("Insufficient access for galaxy scans.")
#                return

            galaxy = Galaxy.load(*params.group(1,3))
            if galaxy is None:
                message.alert("No galaxy with coords %s:%s" % params.group(1,3))
                return
            planets = galaxy.planets
            galscan = Config.has_option("Misc", "galscans") and Config.getboolean("Misc", "galscans")
        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
            planets = [planet]
            galscan = False

        # Scan Quota
        if Config.has_section("ScanQuota"):
            opts = Config.options("ScanQuota") 
            q = []
            for o in opts:
                if int(o) >= user.access:
                    q.append(int(o))
            if q:
                ScanQuota = Config.getint("ScanQuota", str(min(q)))
                reqs = session.query(Request.id).filter(Request.requester_id == user.id).filter(Request.tick == tick).count()
                if (reqs + len(planets) * len(params.group(6).upper())) > ScanQuota:
                    message.reply("This request will exceed your scan quota for this tick (%d scans remaining). " % (ScanQuota - reqs) +\
                                  "Try searching with !planet, !dev, !unit, !news, !jgp, !au.")
                    return

        dists = int(params.group(7) or 0)
        galdists = []

        mergescans = (not galscan) and (Config.has_option("Misc", "maxscans") and len(planets)*len(params.group(6)) > Config.getint("Misc", "maxscans"))

        for planet in planets:
            if galscan or mergescans:
                galdists.append(planet.intel.dists if planet.intel else 0)
                if len(galdists) < len(planets):
                    continue
            types = 0
            for scantype in params.group(6).upper():
                # Reject requests for incoming scans
                if not PA.getboolean(scantype, "request"):
                    message.alert("%s scans cannot be requested." % (PA.get(scantype, "name")))
                    continue
                types += 1
                if galscan or mergescans:
                    # Request the scans
                    for i in range(len(planets)):
                        request = self.request(message, user, planets[i], scantype, galdists[i], galscan or mergescans)
                    # Inform the requester    
                    if galscan and (message.get_chan() != self.scanchan()):
                        message.reply("Requested a Galaxy %s Scan of %s:%s. !request cancel %s:%s to cancel the request." % (request.type, planet.x, planet.y, 
                                                                                                                             request.id-len(planets)+1, request.id))
                    # Check for existing scans
                    scan = planet.scan(scantype)
                    if scan and request.tick - scan.tick < PA.getint(scantype,"expire"):
                        message.reply("%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable." % (
                                                                        scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id,))
                        # Cancel requests with a 0-tick old scan, if required
                        if (request.tick == scan.tick):
                            req0age = Config.getint("Misc", "req0agej") if request.scantype == "J" else Config.getint("Misc", "req0age")
                            if req0age == 1:
                               Q = session.query(Request).filter(Request.tick == request.tick).filter(Request.planet_id == request.planet_id)
                               Q = Q.filter(Request.scantype == request.scantype).filter(Request.requester_id == request.requester_id)
                               if Q.count() == 1:
                                   request.active = False
                                   message.reply("Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request." % (request.id))
                                   message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan())
                            elif req0age == 0:
                                request.active = False
                                message.reply("Request %s cancelled due to an existing scan." % (request.id))
                                message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan())

                    # Tell the scanners
                    requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon"
                    if galscan:
                        message.privmsg("[%s:%s] %s requested a Galaxy %s Scan of %s:%s Max Dists(i:%s%s) " % (request.id-len(planets)+1, request.id, requester, 
                                        request.type, planet.x, planet.y, max(galdists), 
                                        "/r:%s" % dists if dists > 0 else "") + Config.get("URL", "reqgscan") % (planet.x, planet.y) , self.scanchan())
                else:
                    request = self.request(message, user, planet, scantype, 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,))

                    # Check for existing scans
                    scan = planet.scan(scantype)
                    if scan and request.tick - scan.tick < PA.getint(scan.scantype,"expire"):
                        message.reply("%s Scan of %s:%s:%s is already available from %s ticks ago: %s. !request cancel %s if this is suitable." % (
                                                                        scantype, planet.x, planet.y, planet.z, request.tick - scan.tick, scan.link, request.id,))
                        # Cancel requests with a 0-tick old scan, if required
                        if (request.tick == scan.tick):
                            req0age = Config.getint("Misc", "req0agej") if request.scantype == "J" else Config.getint("Misc", "req0age")
                            if req0age == 1:
                               Q = session.query(Request).filter(Request.tick == request.tick).filter(Request.planet_id == request.planet_id)
                               Q = Q.filter(Request.scantype == request.scantype).filter(Request.requester_id == request.requester_id)
                               if Q.count() == 1:
                                   request.active = False
                                   message.reply("Request %s cancelled due to an existing scan. If you really need a newer one, repeat your scan request." % (request.id))
                                   message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan())
                            elif req0age == 0:
                                request.active = False
                                message.reply("Request %s cancelled due to an existing scan." % (request.id))
                                message.privmsg("Cancelled scan request %s due to existing scan" % (request.id), self.scanchan())

            if mergescans:
                message.reply("Requested %d scans. !request cancel %s:%s to cancel the request." % (len(planets) * types, request.id-len(planets)*types+1, request.id))
                message.privmsg("[%s:%s] %s requested %d scans (%s) Max Dists(i:%s%s). !request links for details " % (request.id-len(planets)*types+1, request.id, 
                                requester, len(planets)*types, params.group(6).upper(), max(galdists), "/r:%s" % dists if dists > 0 else ""), self.scanchan())
        session.commit()
Exemple #31
0
    def execute(self, message, user, params):

        planet = None
        galaxy = None
        alliance = None

        # Planet or Galaxy
        if len(params.groups()) == 5:
            # 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
            # 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
        # Alliance or User
        else:
            # Self
            if params.group(1) is None:
                planet = self.get_user_planet(user)
            # Alliance or User
            else:
                alliance = Alliance.load(params.group(1))
                # User
                if alliance is None:
                    u = User.load(params.group(1))
                    if u is None:
                        message.reply("No alliance or user matching '%s' found" % (params.group(1),))
                        return
                    elif u.planet is None:
                        message.reply("User %s has not entered their planet details" % (u.name,))
                        return
                    else:
                        planet = u.planet

        tick = Updates.current_tick()
        target = aliased(Planet)
        target_intel = aliased(Intel)
        owner = aliased(Planet)
        owner_intel = aliased(Intel)

        Q = session.query(owner.x, owner.y, owner.z, count())
        Q = Q.join((FleetScan.owner, owner))
        Q = Q.join((FleetScan.target, target))
        Q = Q.filter(FleetScan.mission == "Attack")
        if planet:
            Q = Q.filter(FleetScan.target == planet)
        if galaxy:
            Q = Q.filter(target.galaxy == galaxy)
        if alliance:
            Q = Q.join((target.intel, target_intel))
            Q = Q.filter(target_intel.alliance == alliance)
        Q = Q.group_by(owner.x, owner.y, owner.z)
        Q = Q.order_by(desc(count()))
        result = Q.all()

        if len(result) < 1:
            reply = "No fleets found targetting"
            if planet:
                reply += " coords %s:%s:%s" % (planet.x, planet.y, planet.z)
            if galaxy:
                reply += " coords %s:%s" % (galaxy.x, galaxy.y)
            if alliance:
                reply += " alliance %s" % (alliance.name,)
            message.reply(reply)
            return

        reply = "Top attackers on"
        if planet:
            reply += " coords %s:%s:%s" % (planet.x, planet.y, planet.z)
        if galaxy:
            reply += " coords %s:%s" % (galaxy.x, galaxy.y)
        if alliance:
            reply += " alliance %s" % (alliance.name,)
        reply += " are (total: %s) " % (sum([attacks for x, y, z, attacks in result]),)
        prev = []
        for x, y, z, attacks in result[:5]:
            prev.append("%s:%s:%s - %s" % (x, y, z, attacks))
        message.reply(reply + " | ".join(prev))
Exemple #32
0
    def planet_galaxy(self, message, user, params):
        tick = Updates.current_tick()
        when = int(params.group(6) or 0)
        if when and when < PA.getint("numbers", "protection"):
            when += tick
        elif when and when <= tick:
            message.alert(
                "Can not check status on the past. You wanted tick %s, but current tick is %s."
                % (
                    when,
                    tick,
                ))
            return

        # Planet
        if params.group(5) is not None:
            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

            Q = session.query(User.name, Target.tick)
            Q = Q.join(Target.user)
            Q = Q.filter(Target.planet == planet)
            Q = Q.filter(Target.tick == when) if when else Q.filter(
                Target.tick > tick)
            Q = Q.order_by(asc(Target.tick))
            result = Q.all()

            if len(result) < 1:
                reply = "No bookings matching planet %s:%s:%s" % (
                    planet.x,
                    planet.y,
                    planet.z,
                )
                if when:
                    reply += " for tick %s" % (when, )
                message.reply(reply)
                return

            reply = "Status for %s:%s:%s - " % (
                planet.x,
                planet.y,
                planet.z,
            )
            if when:
                user, land = result[0]
                reply += "booked for landing pt %s (eta %s) by %s" % (
                    land, land - tick, user)
            else:
                prev = []
                for user, land in result:
                    prev.append("(%s user:%s)" % (land, user))
                reply += ", ".join(prev)
            message.reply(reply)
            return

        # Galaxy
        else:
            galaxy = Galaxy.load(*params.group(1, 3))
            if galaxy is None:
                message.alert("No galaxy with coords %s:%s" %
                              params.group(1, 3))
                return

            Q = session.query(Planet.z, User.name, Target.tick)
            Q = Q.join(Target.planet)
            Q = Q.join(Target.user)
            Q = Q.filter(Planet.active == True)
            Q = Q.filter(Planet.galaxy == galaxy)
            Q = Q.filter(Target.tick == when) if when else Q.filter(
                Target.tick > tick)
            Q = Q.order_by(asc(Planet.z))
            result = Q.all()

            if len(result) < 1:
                reply = "No bookings matching galaxy %s:%s" % (
                    galaxy.x,
                    galaxy.y,
                )
                if when:
                    reply += " for tick %s" % (when, )
                message.reply(reply)
                return

            reply = "Target information for %s:%s" % (
                galaxy.x,
                galaxy.y,
            )
            reply += " landing on tick %s (eta %s): " % (
                when, when - tick) if when else ": "

            ticks = {}
            for z, user, land in result:
                if not ticks.has_key(land):
                    ticks[land] = []
                ticks[land].append((
                    z,
                    user,
                ))
            sorted_keys = ticks.keys()
            sorted_keys.sort()

            replies = []
            for land in sorted_keys:
                prev = []
                for z, user in ticks[land]:
                    prev.append("(%s user:%s)" % (z, user))
                replies.append("Tick %s (eta %s) " % (land, land - tick) +
                               ", ".join(prev))
            replies[0] = reply + replies[0]

            message.reply("\n".join(replies))
            return