def reload(self): from Core.string import errorlog # If the reload succeeds, this Loader instance will be # replaced, so this .success is only tested if it fails. self.success = False try: # Reload this module, which will instantiate a new # Loader, which in turn will do all the main loading. self.load_module("Core.loader") # Check the new loader has a successful status if sys.modules["Core.loader"].Loader.success is not True: raise ImportError except Exception, e: # If the new Loader fails, catch the error and restore everything print "%s Reload failed, reverting to previous." % (time.strftime("%Y%m%d %H:%M:%S | "),) errorlog(" - Loader Reload Error: %s\n" % (str(e),)) self.restore(sys)
def robocop(self, message): # Call back a hooked robocop module command = message.get_command() # Check we have a callback stored for this command, if self.robocops.has_key(command): callback = self.robocops[command] # and call it, passing in the message try: callback.robocop(message) except (MerlinSystemCall, socket.error): raise except Exception, e: # Error while executing a callback/mod/hook message.alert(False) errorlog(" - RoboCop Callback Error: %s\n%s\n" % (str(e),message,)) finally:
def reload(self): from Core.string import errorlog # If the reload succeeds, this Loader instance will be # replaced, so this .success is only tested if it fails. self.success = False try: # Reload this module, which will instantiate a new # Loader, which in turn will do all the main loading. self.load_module("Core.loader") # Check the new loader has a successful status if sys.modules["Core.loader"].Loader.success is not True: raise ImportError except Exception, e: # If the new Loader fails, catch the error and restore everything print "%s Reload failed, reverting to previous." % (time.asctime(),) errorlog("%s - Loader Reload Error: %s\n" % (time.asctime(),str(e),)) self.restore(sys)
def robocop(self, message): # Call back a hooked robocop module command = message.get_command() # Check we have a callback stored for this command, if self.robocops.has_key(command): callback = self.robocops[command] # and call it, passing in the message try: callback.robocop(message) except (MerlinSystemCall, socket.error): raise except Exception, e: # Error while executing a callback/mod/hook message.alert(False) errorlog("%s - RoboCop Callback Error: %s\n%s\n" % (time.asctime(),str(e),message,)) finally:
def callback(self, message): # Call back a hooked module event = message.get_command() # Check we have some callbacks stored for this event, if self.callbacks.has_key(event): # cycle through them for callback in self.callbacks[event]: # and call each one, passing in the message try: callback(message) except (MerlinSystemCall, socket.error): raise except Exception, e: # Error while executing a callback/mod/hook message.alert("Error in module '%s'. Please report the command you used to the bot owner as soon as possible." % (callback.name,)) errorlog(" - IRC Callback Error: %s\n%s\n" % (str(e),message,)) finally: # Remove any uncommitted or unrolled-back state session.remove()
def callback(self, message): # Call back a hooked module event = message.get_command() # Check we have some callbacks stored for this event, if self.callbacks.has_key(event): # cycle through them for callback in self.callbacks[event]: # and call each one, passing in the message try: callback(message) except (MerlinSystemCall, socket.error): raise except Exception, e: # Error while executing a callback/mod/hook message.alert("Error in module '%s'. Please report the command you used to the bot owner as soon as possible." % (callback.name,)) errorlog("%s - IRC Callback Error: %s\n%s\n" % (time.asctime(),str(e),message,)) finally: # Remove any uncommitted or unrolled-back state session.remove()
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 = "" if name[:3] == "!#!": name = " ".join(name[3:].split("!#!")) 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 has recalled." % (name, x, y, z) +\ "\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 Config.getboolean("Misc", "globaldef"): push("broadcast", notice="!#!"+notice.replace(" ","!#!")) else: 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")
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")