Exemple #1
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)
Exemple #2
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 #3
0
 def request(self, message, user, planet, scan, dists, gal=False):
     request = Request(target=planet, scantype=scan, dists=dists)
     user.requests.append(request)
     session.commit()
     
     if not gal:
         requester = user.name if not Config.getboolean("Misc", "anonscans") else "Anon"
         dists_intel = planet.intel.dists if planet.intel else 0
         message.privmsg("[%s] %s requested a %s Scan of %s:%s:%s Dists(i:%s%s) " % (request.id, requester, request.type, planet.x,planet.y,planet.z, 
                                                         dists_intel, "/r:%s" % request.dists if request.dists > 0 else "") + request.link, self.scanchan())
     
     return request
Exemple #4
0
    def robocop(self, message, etype, uname="Unknown", tick=0, x=0, y=0, z=0, name="", eta=0, size=0, res=0, cons=0):
        notice = ""
        email = ""

        user = User.load(uname)
        if user is None:
            errorlog("Defcall: Invalid user in email. Idiot.")
            uname = "%s (whoever that is??)" % (uname)
            ucoords = "x:x:x"
            addr = Config.get("imap", "bounce")
            email = "Bad username in notifications: %s\n\nOriginal notification:\n\n\n" % (uname)
        else:
            uname = "%s%s" % (user.name, ("(%s)" % (user.alias)) if user.alias else "")
            if user.planet:
                ucoords = "%d:%d:%d" % (user.planet.x, user.planet.y, user.planet.z)
            else:
                ucoords = "idiot"
            addr = user.email

        if etype != "fin":
            p = Planet.load(x,y,z)
            if p is None:
                errorlog("Defcall: Invalid planet in email. Probably an exile.")

        if etype == "new":
            # Message to DC channel / main channel. Request scans.
            if p is None:
                arace = "??"
                aally = "Unknown"
            else:
                arace = p.race
                i = p.intel
                if i and i.alliance:
                    aally = i.alliance.name
                else:
                    aally = "Unknown"
            
            notice = "DEFCALL: %s (%s) has incoming eta %s(%s) from %s:%s:%s (%s, %s) - Fleet: %s Visible Ships: %s" % (uname, ucoords, eta, int(eta)-int(tick),
                                                                                                                        x, y, z, arace, aally, name, size)
            email += "Notification from Planetarion in tick %s\n\n" % (tick) +\
                     "Incoming Fleet %s from %s:%s:%s with %s visible ships expected to land in tick %s." % (name, x, y, z, size, eta) +\
                    "\n\nThis has been reported to the %s DCs." % (Config.get("Alliance", "name"))
        elif etype == "rec":
            # Message to DC channel *and* main channel
            notice = "RECALL: %s (%s) has had a recall: Fleet: %s from %s:%s:%s" % (uname, ucoords, name, x, y, z)
            email += "Notification from Planetarion in tick %s\n\n" % (tick) +\
                     "Incoming Fleet %s from %s:%s:%s with eta %s(%s) has recalled." % (name, x, y, z, eta, int(eta)-int(tick)) +\
                    "\n\nThis has been reported to %s." % (Config.get("Alliance", "name"))
        elif etype == "fin":
            # Nothing to see here. Move along.
            notice = ""
            what = ""
            if int(res):
                what = "research"
                if int(cons):
                    what += " and construction"
            else:
                what = "construction"
            email += "Notification from Planetarion in tick %s\n\nAll %s has finished and none is queued." % (tick, what)
        else:
            return
        # Send email - pref?
        if notice:
            if etype == "new" and Config.has_option("Channels", "def"):
                message.notice(notice, Config.get("Channels", "def"))
            else:
                message.notice(notice, Config.get("Channels", "home"))
        
        if email and addr:
            self.send_email("Relayed PA Notifications from tick %s" % (tick), email, addr)
        
        # Check for scans
	if etype == "new" and p and user:
           if Config.has_option("Misc", "autoscans"):
               scantypes = Config.get("Misc", "autoscans")
           else:
               scantypes = "A"
           scanage = (Config.getint("Misc", "scanage") or 2)

           for stype in scantypes:
               scan = p.scan(stype)
               if scan and (int(tick) - scan.tick <= scanage):
                   return
               else:
                   req = Request(target=p, scantype=stype, dists=0)
                   user.requests.append(req)
                   session.commit()
                   push("request", request_id=req.id, mode="request")