def parseWormAuthorized(sig): global worms wormID = int(sig[1]) try: if not worms[wormID].isAdmin: worms[wormID].isAdmin = True io.messageLog(("Worm %i (%s) added to admins" % (wormID,worms[wormID].Name)),io.LOG_ADMIN) # TODO: Send the last part in a PM to the admin. (Needs new backend for private messaging. Add teamchat too!) io.authorizeWorm(wormID) io.privateMsg(wormID, "%s authenticated for admin! Type %shelp for command info" % (worms[wormID].Name,cfg.ADMIN_PREFIX)) except KeyError: io.messageLog("AdminAdd: Our local copy of wormses doesn't match the real list.",io.LOG_ERROR)
def parseWormAuthorized(sig): global worms wormID = int(sig[1]) try: if not worms[wormID].isAdmin: worms[wormID].isAdmin = True io.messageLog(("Worm %i (%s) added to admins" % (wormID, worms[wormID].Name)), io.LOG_ADMIN) # TODO: Send the last part in a PM to the admin. (Needs new backend for private messaging. Add teamchat too!) io.authorizeWorm(wormID) io.privateMsg( wormID, "%s authenticated for admin! Type %shelp for command info" % (worms[wormID].Name, cfg.ADMIN_PREFIX)) except KeyError: io.messageLog( "AdminAdd: Our local copy of wormses doesn't match the real list.", io.LOG_ERROR)
def parseAdminCommand(wormid, message): global kickedUsers try: # Do not check on msg size or anything, exception handling is further down if (not message.startswith(cfg.ADMIN_PREFIX)): return False # normal chat cmd = message.split(" ")[0] cmd = cmd.replace(cfg.ADMIN_PREFIX, "", 1).lower() #Remove the prefix if wormid >= 0: io.messageLog( "%i:%s issued %s" % (wormid, hnd.worms[wormid].Name, cmd.replace(cfg.ADMIN_PREFIX, "", 1)), io.LOG_ADMIN) else: io.messageLog("ded admin issued %s" % cmd, io.LOG_USRCMD) # Unnecesary to split multiple times, this saves CPU. params = message.split(" ")[1:] if cmd == "help": adminCommandHelp(wormid) elif cmd == "kick": kickTime = cfg.VOTING_KICK_TIME if len(params) > 1: # Time for kick kickTime = float(params[1]) wormIP = io.getWormIP(int(params[0])).split(":")[0] if wormIP != "127.0.0.1": kickedUsers[wormIP] = time.time() + kickTime * 60 if len(params) > 2: # Given some reason io.kickWorm(int(params[0]), " ".join(params[2:])) else: io.kickWorm(int(params[0])) elif cmd == "ban": if len(params) > 1: # Given some reason io.banWorm(int(params[0]), " ".join(params[1:])) else: io.banWorm(int(params[0])) elif cmd == "mute": io.muteWorm(int(params[0])) elif cmd == "preset": preset = -1 for p in range(len(hnd.availablePresets)): if hnd.availablePresets[p].lower().find( params[0].lower()) != -1: preset = p break if preset == -1: io.privateMsg( wormid, "Invalid preset, available presets: " + ", ".join(hnd.availablePresets)) else: hnd.selectPreset(Preset=hnd.availablePresets[preset]) elif cmd == "mod": mod = "" for m in io.listMods(): if m.lower().find(" ".join(params[0:]).lower()) != -1: mod = m break if mod == "": io.privateMsg( wormid, "Invalid mod, available mods: " + ", ".join(io.listMods())) else: hnd.selectPreset(Mod=mod) elif cmd == "map": level = "" for l in io.listMaps(): if l.lower().find(" ".join(params[0:]).lower()) != -1: level = l break if level == "": io.privateMsg( wormid, "Invalid map, available maps: " + ", ".join(io.listMaps())) else: hnd.selectPreset(Level=level) elif cmd == "lt": hnd.selectPreset(LT=int(params[0])) elif cmd == "start": io.startGame() elif cmd == "stop": io.gotoLobby() elif cmd == "pause": io.privateMsg(wormid, "Ded script paused") hnd.scriptPaused = True elif cmd == "unpause": io.privateMsg(wormid, "Ded script continues") hnd.scriptPaused = False elif cmd == "setvar": io.setvar(params[0], " ".join(params[1:])) # In case value contains spaces elif cmd == "authorize": try: wormID = int(params[0]) if not hnd.worms[wormID].isAdmin: hnd.worms[wormID].isAdmin = True io.authorizeWorm(wormID) io.messageLog( "Worm %i (%s) added to admins by %i (%s)" % (wormID, hnd.worms[wormID].Name, wormid, hnd.worms[wormid].Name), io.LOG_INFO) io.privateMsg( wormID, "%s made you admin! Type %shelp for commands" % (hnd.worms[wormid].Name, cfg.ADMIN_PREFIX)) io.privateMsg( wormid, "%s added to admins." % hnd.worms[wormID].Name) except KeyError: io.messageLog( "parseAdminCommand: Our local copy of wormses doesn't match the real list.", io.LOG_ERROR) elif parseAdminCommand_Preset and parseAdminCommand_Preset( wormid, cmd, params): pass else: raise Exception, "Invalid admin command" except: # All python classes derive from main "Exception", but confused me, this has the same effect. if wormid >= 0: io.privateMsg(wormid, "Invalid admin command") io.messageLog(formatExceptionInfo(), io.LOG_ERROR) #Helps to fix errors return False return True
def parseAdminCommand(wormid,message): global kickedUsers try: # Do not check on msg size or anything, exception handling is further down if (not message.startswith(cfg.ADMIN_PREFIX)): return False # normal chat cmd = message.split(" ")[0] cmd = cmd.replace(cfg.ADMIN_PREFIX,"",1).lower() #Remove the prefix if wormid >= 0: io.messageLog("%i:%s issued %s" % (wormid,hnd.worms[wormid].Name,cmd.replace(cfg.ADMIN_PREFIX,"",1)),io.LOG_ADMIN) else: io.messageLog("ded admin issued %s" % cmd, io.LOG_USRCMD) # Unnecesary to split multiple times, this saves CPU. params = message.split(" ")[1:] if cmd == "help": adminCommandHelp(wormid) elif cmd == "kick": kickTime = cfg.VOTING_KICK_TIME if len(params) > 1: # Time for kick kickTime = float(params[1]) wormIP = io.getWormIP(int( params[0] )).split(":")[0] if wormIP != "127.0.0.1": kickedUsers[ wormIP ] = time.time() + kickTime*60 if len(params) > 2: # Given some reason io.kickWorm( int( params[0] ), " ".join(params[2:]) ) else: io.kickWorm( int( params[0] ) ) elif cmd == "ban": if len(params) > 1: # Given some reason io.banWorm( int( params[0] ), " ".join(params[1:]) ) else: io.banWorm( int( params[0] ) ) elif cmd == "mute": io.muteWorm( int( params[0] ) ) elif cmd == "preset": preset = -1 for p in range(len(hnd.availablePresets)): if hnd.availablePresets[p].lower().find(params[0].lower()) != -1: preset = p break if preset == -1: io.privateMsg(wormid,"Invalid preset, available presets: " + ", ".join(hnd.availablePresets)) else: hnd.selectPreset( Preset = hnd.availablePresets[preset] ) elif cmd == "mod": mod = "" for m in io.listMods(): if m.lower().find(" ".join(params[0:]).lower()) != -1: mod = m break if mod == "": io.privateMsg(wormid,"Invalid mod, available mods: " + ", ".join(io.listMods())) else: hnd.selectPreset( Mod = mod ) elif cmd == "map": level = "" for l in io.listMaps(): if l.lower().find(" ".join(params[0:]).lower()) != -1: level = l break if level == "": io.privateMsg(wormid,"Invalid map, available maps: " + ", ".join(io.listMaps())) else: hnd.selectPreset( Level = level ) elif cmd == "lt": hnd.selectPreset( LT = int(params[0]) ) elif cmd == "start": io.startGame() elif cmd == "stop": io.gotoLobby() elif cmd == "pause": io.privateMsg(wormid,"Ded script paused") hnd.scriptPaused = True elif cmd == "unpause": io.privateMsg(wormid,"Ded script continues") hnd.scriptPaused = False elif cmd == "setvar": io.setvar(params[0], " ".join(params[1:])) # In case value contains spaces elif cmd == "authorize": try: wormID = int(params[0]) if not hnd.worms[wormID].isAdmin: hnd.worms[wormID].isAdmin = True io.authorizeWorm(wormID) io.messageLog( "Worm %i (%s) added to admins by %i (%s)" % (wormID,hnd.worms[wormID].Name,wormid,hnd.worms[wormid].Name),io.LOG_INFO) io.privateMsg(wormID, "%s made you admin! Type %shelp for commands" % (hnd.worms[wormid].Name,cfg.ADMIN_PREFIX)) io.privateMsg(wormid, "%s added to admins." % hnd.worms[wormID].Name) except KeyError: io.messageLog("parseAdminCommand: Our local copy of wormses doesn't match the real list.",io.LOG_ERROR) elif parseAdminCommand_Preset and parseAdminCommand_Preset(wormid, cmd, params): pass else: raise Exception, "Invalid admin command" except: # All python classes derive from main "Exception", but confused me, this has the same effect. if wormid >= 0: io.privateMsg(wormid, "Invalid admin command") io.messageLog(formatExceptionInfo(),io.LOG_ERROR) #Helps to fix errors return False return True