Ejemplo n.º 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))
Ejemplo n.º 2
0
Archivo: attack.py Proyecto: JDD/merlin
    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))
Ejemplo n.º 3
0
 def execute(self, request, user, id, message=None):
     attack = Attack.load(id)
     if attack is None or not attack.active:
         return HttpResponseRedirect(reverse("attacks"))
     
     waves = xrange(attack.landtick, attack.landtick + Attack._waves)
     show_jgps = attack.landtick <= Updates.current_tick() + Attack._show_jgp_ticks
     
     group = []
     scans = []
     for planet in attack.planets:
         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"))
         
         if show_jgps and planet.scan("J"):
             group[-1][1].append(planet.scan("J"))
             scans.append(planet.scan("J"))
         
         bookings = dict([(target.tick, target,) for target in planet.bookings.filter(Target.tick.between(attack.landtick, attack.landtick+4))])
         for tick in waves:
             group[-1][2].append((tick, bookings.get(tick) or (False if show_jgps else None),))
     
     return render("attack.tpl", request, attack=attack, message=message, waves=waves, group=group, scans=scans)
Ejemplo n.º 4
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,))
Ejemplo n.º 5
0
 def land(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
     
     tick = Updates.current_tick()
     when = int(params.group(2))
     
     if when == 0:
         session.delete(attack)
         session.commit()
         message.reply("Deleted Attack %d LT: %d | %s" %(attack.id,attack.landtick,attack.comment,))
         return
     
     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
     
     old = attack.landtick
     attack.landtick = when
     
     session.commit()
     message.reply("Changed LT for attack %d from %d to %d"%(id,old,when))
Ejemplo n.º 6
0
 def attack(self, request, user, id, message=None):
     attack = Attack.load(id)
     if attack and attack.active:
         from Arthur.views.attack.attack import view
         return view.execute(request, user, id, message)
     else:
         from Arthur.views.attack.attack import attack
         return attack.execute(request, user, message)
Ejemplo n.º 7
0
 def attack(self, request, user, id, message=None):
     attack = Attack.load(id)
     if attack and attack.active:
         from Arthur.views.attack.attack import view
         return view.execute(request, user, id, message)
     else:
         from Arthur.views.attack.attack import attack
         return attack.execute(request, user, message)
Ejemplo n.º 8
0
    def show(self, message, user, params):
        id = params.group(1)
        attack = Attack.load(id)

        if attack is None:
            message.alert("No attack exists with id %s" % (id))
            return

        message.reply(str(attack))
Ejemplo n.º 9
0
    def show(self, message, user, params):
        id = params.group(1)
        attack = Attack.load(id)

        if attack is None:
            message.alert("No attack exists with id %s" % (id))
            return

        message.reply(str(attack))
Ejemplo n.º 10
0
 def waves(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
     
     attack.waves = params.group(2)
     
     session.commit()
     message.reply("Updated waves for attack %d: %d"%(id,attack.waves,))
Ejemplo n.º 11
0
Archivo: attack.py Proyecto: JDD/merlin
 def show(self, message, user, params):
     id = params.group(1)
     attack = Attack.load(id)
     
     if attack is None:
         message.alert("No attack exists with id %s" %(id))
         return
     if user.access < (Config.getint("Access",  "hc") if "hc" in Config.options("Access") else 1000) and attack.landtick > Updates.current_tick() + Config.getint("Misc", "attactive"):
         message.alert("Attack %s is not open yet" %(id))
         return
     
     message.reply(str(attack))
Ejemplo n.º 12
0
    def execute(self, request, user, id, message=None):
        attack = Attack.load(id)
        if attack is None or not attack.active:
            return HttpResponseRedirect(reverse("attacks"))

        waves = xrange(attack.landtick, attack.landtick + Attack._waves)
        show_jgps = attack.landtick <= Updates.current_tick(
        ) + Attack._show_jgp_ticks

        group = []
        scans = []
        for planet in attack.planets:
            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"))

            if show_jgps and planet.scan("J"):
                group[-1][1].append(planet.scan("J"))
                scans.append(planet.scan("J"))

            bookings = dict([(
                target.tick,
                target,
            ) for target in planet.bookings.filter(
                Target.tick.between(attack.landtick, attack.landtick + 4))])
            for tick in waves:
                group[-1][2].append((
                    tick,
                    bookings.get(tick) or (False if show_jgps else None),
                ))

        return render("attack.tpl",
                      request,
                      attack=attack,
                      message=message,
                      waves=waves,
                      group=group,
                      scans=scans)
Ejemplo n.º 13
0
 def comment(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
     
     if params.group(2) in self.nulls:
         attack.comment = ""
     else:
         attack.comment = params.group(2)
     
     session.commit()
     message.reply("Updated comment for attack %d: %s"%(id,attack.comment,))
Ejemplo n.º 14
0
    def waves(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

        attack.waves = params.group(2)

        session.commit()
        message.reply("Updated waves for attack %d: %d" % (
            id,
            attack.waves,
        ))
Ejemplo n.º 15
0
    def show(self, message, user, params):
        id = params.group(1)
        attack = Attack.load(id)

        if attack is None:
            message.alert("No attack exists with id %s" % (id))
            return
        if user.access < (Config.getint("Access", "hc")
                          if "hc" in Config.options("Access") else
                          1000) and attack.landtick > Updates.current_tick(
                          ) + Config.getint("Misc", "attactive"):
            message.alert("Attack %s is not open yet" % (id))
            return

        message.reply(str(attack))
Ejemplo n.º 16
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))
Ejemplo n.º 17
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))
Ejemplo n.º 18
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))