def myRank(wormName, wormid): global rank try: rankPos = rank[wormName][3] rankNames = [ False, False, False, False ] for k in rank: if rank[k][3] >= rankPos - 2 and rank[k][3] <= rankPos + 1: rankNames[ rank[k][3] - rankPos + 2 ] = k for k in rankNames: if k: io.privateMsg(wormid, str(rank[k][3]) + ") " + k + " (" + str(rank[k][0]) + " kills, " + str(rank[k][1]) + " deaths, " + str(rank[k][2]) + " suicides)") except KeyError: io.privateMsg(wormid, wormName + " has not played yet")
def myRank(wormName, wormid): global rank try: rankPos = rank[wormName][3] rankNames = [False, False, False, False] for k in rank: if rank[k][3] >= rankPos - 2 and rank[k][3] <= rankPos + 1: rankNames[rank[k][3] - rankPos + 2] = k for k in rankNames: if k: rankSingle(k, wormid) except KeyError: io.privateMsg(wormid, wormName + " has not played yet")
def myRank(wormName, wormid): global rank try: rankPos = rank[wormName][3] rankNames = [ False, False, False, False ] for k in rank: if rank[k][3] >= rankPos - 2 and rank[k][3] <= rankPos + 1: rankNames[ rank[k][3] - rankPos + 2 ] = k for k in rankNames: if k: rankSingle(k, wormid) except KeyError: io.privateMsg(wormid, wormName + " has not played yet")
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 addVote( command, poster, description ): global voteCommand, voteTime, votePoster, voteDescription if time.time() - voteTime < cfg.VOTING_TIME: io.privateMsg(poster, "Previous vote still running, " + str(int( cfg.VOTING_TIME + voteTime - time.time() )) + " seconds left") return if time.time() - hnd.worms[poster].FailedVoteTime < cfg.VOTING_TIME * 2: io.privateMsg(poster, "You cannot add vote for " + str(int( cfg.VOTING_TIME * 2 + hnd.worms[poster].FailedVoteTime - time.time() )) + " seconds") return voteCommand = command for w in hnd.worms.keys(): hnd.worms[w].Voted = 0 votePoster = poster hnd.worms[poster].Voted = 1 voteTime = time.time() voteDescription = description recheckVote()
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 addVote(command, poster, description): global voteCommand, voteTime, votePoster, voteDescription if time.time() - voteTime < cfg.VOTING_TIME: io.privateMsg( poster, "Previous vote still running, " + str(int(cfg.VOTING_TIME + voteTime - time.time())) + " seconds left") return if time.time() - hnd.worms[poster].FailedVoteTime < cfg.VOTING_TIME * 2: io.privateMsg( poster, "You cannot add vote for " + str( int(cfg.VOTING_TIME * 2 + hnd.worms[poster].FailedVoteTime - time.time())) + " seconds") return voteCommand = command for w in hnd.worms.keys(): hnd.worms[w].Voted = 0 votePoster = poster hnd.worms[poster].Voted = 1 voteTime = time.time() voteDescription = description recheckVote()
def mapHelp(wormid): helpMsg = "" tmp = "" io.privateMsg(wormid, "Map voting shortcuts to use with %sm:" % cfg.USER_PREFIX) if len(presetcfg.MAP_SHORTCUTS) == 0: io.privateMsg(wormid, "<not available>") else: for k in presetcfg.MAP_SHORTCUTS.keys(): tmp = k + " - " + presetcfg.MAP_SHORTCUTS[k].replace(".lxl", "") + " // " helpMsg = helpMsg + tmp io.privateMsg(wormid, helpMsg)
def userCommandHelp(wormid): if cfg.RANKING: io.privateMsg(wormid, "%stoprank - display the best players" % cfg.USER_PREFIX) io.privateMsg( wormid, "%srank [name] - display your or other player rank" % cfg.USER_PREFIX) io.privateMsg( wormid, "%sranktotal - display the number of players in the ranking" % cfg.USER_PREFIX) if cfg.VOTING: io.privateMsg( wormid, "%smod presetName - vote for a mod preset" % cfg.USER_PREFIX) io.privateMsg( wormid, "%smap mapName - vote for a map, old style" % cfg.USER_PREFIX) io.privateMsg( wormid, "%sm mapCode - quick map voting, try %smaphelp for a list of options" % (cfg.USER_PREFIX, cfg.USER_PREFIX)) if cfg.KICK_VOTING: io.privateMsg( wormid, "%skick playerID - vote to kick player" % cfg.USER_PREFIX) if cfg.TEAMGAMES_VOTING: io.privateMsg( wormid, "%steams/%snoteams - vote for team game" % (cfg.USER_PREFIX, cfg.USER_PREFIX)) if cfg.TEAM_SHUFFLE: io.privateMsg(wormid, "%sshuffle - randomize teams" % cfg.USER_PREFIX) if cfg.ALLOW_TEAM_CHANGE: t_msg = "%steam [b/r" % (cfg.USER_PREFIX) if cfg.MAX_TEAMS >= 3: t_msg += "/g" if cfg.MAX_TEAMS >= 4: t_msg += "/y" t_msg += "] - set your team" io.privateMsg(wormid, t_msg)
def adminCommandHelp(wormid): io.privateMsg(wormid, "Admin help:") io.privateMsg(wormid, "%skick wormID [time] [reason]" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sban wormID [reason]" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smute wormID" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smod presetName" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smap mapName" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%steam wormID teamID (0123 or brgy)" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%spause - pause ded script" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sunpause - resume ded script" % cfg.ADMIN_PREFIX)
def parseUserCommand(wormid, message): global kickedUsers try: # Do not check on msg size or anything, exception handling is further down if message in [ "y", "n", "start", "stop", "rank", "toprank", "ranktotal" ]: # Single-word usercommands for faster typing cmd = message else: if (not message.startswith(cfg.USER_PREFIX)): return False # normal chat cmd = message.split(" ")[0] cmd = cmd.replace(cfg.USER_PREFIX, "", 1).lower() #Remove the prefix if wormid >= 0: io.messageLog( "%i:%s issued %s" % (wormid, hnd.worms[wormid].Name, cmd.replace(cfg.USER_PREFIX, "", 1)), io.LOG_USRCMD) 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": userCommandHelp(wormid) if cfg.ALLOW_TEAM_CHANGE and cmd == "team": if not params: io.privateMsg(wormid, "You need to specify a team") raise Exception, "You need to specify a team" else: if params[0].lower() == "blue" or params[0].lower() == "b": io.setWormTeam(wormid, 0) elif params[0].lower() == "red" or params[0].lower() == "r": io.setWormTeam(wormid, 1) elif (params[0].lower() == "green" or params[0].lower() == "g") and cfg.MAX_TEAMS >= 3: io.setWormTeam(wormid, 2) elif (params[0].lower() == "yellow" or params[0].lower() == "y") and cfg.MAX_TEAMS >= 4: io.setWormTeam(wormid, 3) if cfg.RANKING: if cmd == "toprank": ranking.firstRank(wormid) if cmd == "rank": if wormid in hnd.worms: wormName = hnd.worms[wormid].Name if params: wormName = " ".join(params) ranking.myRank(wormName, wormid) if cmd == "ranktotal": io.privateMsg( wormid, "There are " + str(len(ranking.rank)) + " players in the ranking.") if cfg.VOTING: if cmd == "kick": kicked = int(params[0]) if not kicked in hnd.worms.keys(): raise Exception, "Invalid worm ID" addVote( "io.kickWorm(" + str(kicked) + ", 'You are kicked for " + str(cfg.VOTING_KICK_TIME) + " minutes')", wormid, "Kick %i: %s" % (kicked, hnd.worms[kicked].Name)) hnd.worms[kicked].Voted = -1 if cmd == "mute": if not kicked in hnd.worms.keys(): raise Exception, "Invalid worm ID" kicked = int(params[0]) addVote("io.muteWorm(" + str(kicked) + ")", wormid, "Mute %i: %s" % (kicked, hnd.worms[kicked].Name)) hnd.worms[kicked].Voted = -1 if cmd == "mod": # Users are proven to be stupid and can't tell the difference between mod and preset # so here we're first looking for a preset, and then looking for a mod with the same name if preset not found # (well, let's call that UI simplification) 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: addVote( 'hnd.selectPreset( Preset = "%s" )' % hnd.availablePresets[preset], wormid, "Preset %s" % hnd.availablePresets[preset]) else: 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(hnd.availablePresets) + ", ".join(io.listMods())) else: addVote('hnd.selectPreset( Mod = "%s" )' % mod, wormid, "Mod %s" % mod) if 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: addVote('hnd.selectPreset( Level = "%s" )' % level, wormid, "Map %s" % level) if cmd == "lt": addVote('hnd.selectPreset( LT = %i )' % int(params[0]), wormid, "Loading time %i" % int(params[0])) if cmd == "start": addVote( 'hnd.lobbyWaitAfterGame = time.time(); hnd.lobbyWaitBeforeGame = time.time()', wormid, "Start game now") if cmd == "stop": addVote('io.gotoLobby()', wormid, "Go to lobby") if (cmd == "y" or cmd == "yes"): if hnd.worms[wormid].Voted != 1: hnd.worms[wormid].Voted = 1 recheckVote() if (cmd == "n" or cmd == "no"): if hnd.worms[wormid].Voted != -1: hnd.worms[wormid].Voted = -1 recheckVote() elif parseUserCommand_Preset and parseUserCommand_Preset( wormid, cmd, params): pass else: raise Exception, "Invalid user command" except: # All python classes derive from main "Exception", but confused me, this has the same effect. if wormid >= 0: io.privateMsg( wormid, "Invalid user command - type !help for list of commands") 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
def userCommandHelp(wormid): if cfg.ALLOW_TEAM_CHANGE: msg = "%steam [b/r" % (cfg.USER_PREFIX) if cfg.MAX_TEAMS >= 3: msg += "/g" if cfg.MAX_TEAMS >= 4: msg += "/y" msg += "] - set your team" io.privateMsg(wormid, msg + " - set your team") if cfg.RANKING: io.privateMsg(wormid, "%stoprank - display the best players" % cfg.USER_PREFIX ) io.privateMsg(wormid, "%srank [name] - display your or other player rank" % cfg.USER_PREFIX ) io.privateMsg(wormid, "%sranktotal - display the number of players in the ranking" % cfg.USER_PREFIX ) if cfg.VOTING: io.privateMsg(wormid, "%skick wormID - add vote to kick player etc" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smute wormID - add vote" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smod modName (or part of name) - add vote" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smap mapName - add vote" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%slt loadingTime - add vote" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sstart - start game now" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sstop - go to lobby" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sy / %sn - vote yes / no" % (cfg.ADMIN_PREFIX, cfg.ADMIN_PREFIX) ) if userCommandHelp_Preset: userCommandHelp_Preset(wormid)
def adminCommandHelp(wormid): io.privateMsg(wormid, "Admin help:") io.privateMsg(wormid, "%skick wormID [time] [reason]" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sban wormID [reason]" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smute wormID" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%spreset presetName" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smod modName (or part of name)" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smap mapName" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%slt loadingTime" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%steam wormID teamID (0123 or brgy)" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sstart - start game now" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sstop - go to lobby" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%spause - pause ded script" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sunpause - resume ded script" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%ssetvar varname value" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sauthorize wormID" % cfg.ADMIN_PREFIX) if adminCommandHelp_Preset: adminCommandHelp_Preset(wormid)
def parseChatMessage(sig): global worms wormID = int(sig[1]) message = sig[2] #Length-based anti-spam - see dedicated_config for details if cfg.ANTISPAM != 0: if len(message) > cfg.ANTISPAM_KICKLIMIT: if cfg.ANTISPAM > 1 and len(message) > cfg.ANTISPAM_BANLIMIT: if cfg.ANTISPAM == 2: kickWithTime(wormID, "excessive spamming") return elif cfg.ANTISPAM == 3: io.banWorm(wormID, "excessive spamming") io.messageLog( "Player " + worms[wormID].Name + " from IP " + worms[wormID].Ip + " was banned for spamming", io.LOG_INFO) return else: io.kickWorm(wormID, "spamming") return #NEW: Impersonation protection - check if the player tries to impersonate another player using the newline tags. #NOTE: The "GOGO" spamfest taunt is whitelisted here! if cfg.ANTI_IMPERSONATION: if message not in cfg.ANTI_IMPERSONATION_WHITELIST and detectFormattingTags( message): #Warn the player and count the attempt io.privateMsg(wormID, cfg.ANTI_IMPERSONATION_CLIENT_WARNING) worms[wormID].tags_detected += 1 #TODO HACK EXPERIMENTAL TEST: Check whether the message contains other players' nicknames - if yes, warn the other players for w in worms.keys(): if w != wormID and (worms[w].real_name.strip() in message or worms[w].getCleanName().strip() in message): if cfg.ANTI_IMPERSONATION_SERVER_WARNING: #Do not broadcast warning if it doesn't exist io.chatMsg( cfg.ANTI_IMPERSONATION_SERVER_WARNING.replace( "<player>", worms[wormID].getCleanName()).replace( "<another>", worms[w].getCleanName())) #Apply sanctions if worms[wormID].tags_detected > cfg.ANTI_IMPERSONATION_LIMIT: if cfg.ANTI_IMPERSONATION_ACTION == 1: io.kickWorm(wormID, "used non-allowed formatting tags in chat") return elif cfg.ANTI_IMPERSONATION_ACTION == 2: kickWithTime(wormID, "used non-allowed formatting tags in chat") return #Taunt antispam - see dedicated_config for details if cfg.TAUNT_ANTISPAM: for kw in cfg.TAUNT_KEYWORDS: if kw in message.lower(): worms[wormID].spammed += 1 io.privateMsg(wormID, cfg.TAUNT_ANTISPAM_WARNING) if worms[wormID].spammed > cfg.TAUNT_ANTISPAM_LIMIT: if cfg.TAUNT_ANTISPAM == 1: io.kickWorm(wormID, "spamming") elif cfg.TAUNT_ANTISPAM == 2: kickWithTime(wormID, "spamming") return #Commands ret = None aret = None if worms[wormID].isAdmin and message.startswith(cfg.ADMIN_PREFIX): aret = cmds.parseAdminCommand(wormID, message) if message.startswith(cfg.USER_PREFIX): ret = cmds.parseUserCommand(wormID, message) if ret == "map": updateVotes(send_msg=("map", )) elif ret == "mod": updateVotes(send_msg=("mod", )) elif ret == "teams": updateVotes(send_msg=("teams", )) elif ret == "kick": #Don't broadcast voting status if voted for kick updateVotes(send_msg=())
def firstRank(wormid): global rank # TODO: too lazy to do cycle try: for k in rank: if rank[k][3] == 1: w1 = k elif rank[k][3] == 2: w2 = k elif rank[k][3] == 3: w3 = k elif rank[k][3] == 4: w4 = k elif rank[k][3] == 5: w5 = k io.privateMsg(wormid, "The best players are :") io.privateMsg(wormid, "1) " + w1 + " (" + str(rank[w1][0]) + " kills, " + str(rank[w1][1]) + " deaths, " + str(rank[w1][2]) + " suicides)") io.privateMsg(wormid, "2) " + w2 + " (" + str(rank[w2][0]) + " kills, " + str(rank[w2][1]) + " deaths, " + str(rank[w2][2]) + " suicides)") io.privateMsg(wormid, "3) " + w3 + " (" + str(rank[w3][0]) + " kills, " + str(rank[w3][1]) + " deaths, " + str(rank[w3][2]) + " suicides)") io.privateMsg(wormid, "4) " + w4 + " (" + str(rank[w4][0]) + " kills, " + str(rank[w4][1]) + " deaths, " + str(rank[w4][2]) + " suicides)") io.privateMsg(wormid, "5) " + w5 + " (" + str(rank[w5][0]) + " kills, " + str(rank[w5][1]) + " deaths, " + str(rank[w5][2]) + " suicides)") except Exception: pass
def parseUserCommand(wormid,message): global kickedUsers try: # Do not check on msg size or anything, exception handling is further down if message in [ "y", "n", "start", "stop", "rank", "toprank", "ranktotal" ]: # Single-word usercommands for faster typing cmd = message else: if (not message.startswith(cfg.USER_PREFIX)): return False # normal chat cmd = message.split(" ")[0] cmd = cmd.replace(cfg.USER_PREFIX,"",1).lower() #Remove the prefix if wormid >= 0: io.messageLog("%i:%s issued %s" % (wormid,hnd.worms[wormid].Name,cmd.replace(cfg.USER_PREFIX,"",1)),io.LOG_USRCMD) 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": userCommandHelp(wormid) if cfg.ALLOW_TEAM_CHANGE and cmd == "team": if not params: io.privateMsg(wormid, "You need to specify a team" ) raise Exception, "You need to specify a team" else: if params[0].lower() == "blue" or params[0].lower() == "b": io.setWormTeam(wormid, 0) elif params[0].lower() == "red" or params[0].lower() == "r": io.setWormTeam(wormid, 1) elif ( params[0].lower() == "green" or params[0].lower() == "g" ) and cfg.MAX_TEAMS >= 3: io.setWormTeam(wormid, 2) elif ( params[0].lower() == "yellow" or params[0].lower() == "y" ) and cfg.MAX_TEAMS >= 4: io.setWormTeam(wormid, 3) if cfg.RANKING: if cmd == "toprank": ranking.firstRank(wormid) if cmd == "rank": if wormid in hnd.worms: wormName = hnd.worms[wormid].Name if params: wormName = " ".join(params) ranking.myRank(wormName, wormid) if cmd == "ranktotal": io.privateMsg(wormid, "There are " + str(len(ranking.rank)) + " players in the ranking.") if cfg.VOTING: if cmd == "kick": kicked = int( params[0] ) if not kicked in hnd.worms.keys(): raise Exception, "Invalid worm ID" addVote( "io.kickWorm(" + str(kicked) + ", 'You are kicked for " + str(cfg.VOTING_KICK_TIME) + " minutes')", wormid, "Kick %i: %s" % ( kicked, hnd.worms[kicked].Name ) ) hnd.worms[kicked].Voted = -1 if cmd == "mute": if not kicked in hnd.worms.keys(): raise Exception, "Invalid worm ID" kicked = int( params[0] ) addVote( "io.muteWorm(" + str(kicked) +")", wormid, "Mute %i: %s" % ( kicked, hnd.worms[kicked].Name ) ) hnd.worms[kicked].Voted = -1 if cmd == "mod": # Users are proven to be stupid and can't tell the difference between mod and preset # so here we're first looking for a preset, and then looking for a mod with the same name if preset not found # (well, let's call that UI simplification) 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: addVote( 'hnd.selectPreset( Preset = "%s" )' % hnd.availablePresets[preset], wormid, "Preset %s" % hnd.availablePresets[preset] ) else: 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(hnd.availablePresets) + ", ".join(io.listMods())) else: addVote( 'hnd.selectPreset( Mod = "%s" )' % mod, wormid, "Mod %s" % mod ) if 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: addVote( 'hnd.selectPreset( Level = "%s" )' % level, wormid, "Map %s" % level ) if cmd == "lt": addVote( 'hnd.selectPreset( LT = %i )' % int(params[0]), wormid, "Loading time %i" % int(params[0]) ) if cmd == "start": addVote( 'hnd.lobbyWaitAfterGame = time.time(); hnd.lobbyWaitBeforeGame = time.time()', wormid, "Start game now" ) if cmd == "stop": addVote( 'io.gotoLobby()', wormid, "Go to lobby" ) if ( cmd == "y" or cmd == "yes" ): if hnd.worms[wormid].Voted != 1: hnd.worms[wormid].Voted = 1 recheckVote() if ( cmd == "n" or cmd == "no" ): if hnd.worms[wormid].Voted != -1: hnd.worms[wormid].Voted = -1 recheckVote() elif parseUserCommand_Preset and parseUserCommand_Preset(wormid, cmd, params): pass else: raise Exception, "Invalid user command" except: # All python classes derive from main "Exception", but confused me, this has the same effect. if wormid >= 0: io.privateMsg(wormid, "Invalid user command - type !help for list of commands") io.messageLog(formatExceptionInfo(),io.LOG_ERROR) #Helps to fix errors return False return True
def controlUpdatesList(wormid): if cfg.CONTROL_UPDATES == 1: for updateEntry in cfg.CONTROL_UPDATES_LIST: io.privateMsg(wormid, updateEntry) else: io.privateMsg(wormid, "No recent news")
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 rankSingle(wormName, wormid): k = wormName io.privateMsg( wormid, str(rank[k][3]) + ") " + k + " (" + str(rank[k][0]) + " kills, " + str(rank[k][1]) + " deaths, " + str(rank[k][2]) + " suicides)")
def parseAdminCommand(wormid, message): try: # Do not check on msg size or anything, exception handling is further down 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": wormid = int(params[0]) wormIP = io.getWormIP(wormid).split(":")[0] if wormIP != "127.0.0.1": if len(params) > 1: # Given some reason hnd.kickWithTime(wormid, " ".join(params[2:])) else: hnd.kickWithTime(wormid) 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 == "mod": 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.loadPreset(availablePresets[p]) 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.loadMap(l) elif cmd == "pause": io.privateMsg(wormid, "Ded script paused") hnd.scriptPaused = True elif cmd == "unpause": io.privateMsg(wormid, "Ded script continues") hnd.scriptPaused = False 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(io.formatExceptionInfo(), io.LOG_ERROR) #Helps to fix errors return False return True
def userCommandHelp(wormid): if cfg.ALLOW_TEAM_CHANGE: msg = "%steam [b/r" % (cfg.USER_PREFIX) if cfg.MAX_TEAMS >= 3: msg += "/g" if cfg.MAX_TEAMS >= 4: msg += "/y" msg += "] - set your team" io.privateMsg(wormid, msg + " - set your team") if cfg.RANKING: io.privateMsg(wormid, "%stoprank - display the best players" % cfg.USER_PREFIX) io.privateMsg( wormid, "%srank [name] - display your or other player rank" % cfg.USER_PREFIX) io.privateMsg( wormid, "%sranktotal - display the number of players in the ranking" % cfg.USER_PREFIX) if cfg.VOTING: io.privateMsg( wormid, "%skick wormID - add vote to kick player etc" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smute wormID - add vote" % cfg.ADMIN_PREFIX) io.privateMsg( wormid, "%smod modName (or part of name) - add vote" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%smap mapName - add vote" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%slt loadingTime - add vote" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sstart - start game now" % cfg.ADMIN_PREFIX) io.privateMsg(wormid, "%sstop - go to lobby" % cfg.ADMIN_PREFIX) io.privateMsg( wormid, "%sy / %sn - vote yes / no" % (cfg.ADMIN_PREFIX, cfg.ADMIN_PREFIX)) if userCommandHelp_Preset: userCommandHelp_Preset(wormid)
def firstRank(wormid): global rank # TODO: too lazy to do cycle try: for k in rank: if rank[k][3] == 1: w1 = k elif rank[k][3] == 2: w2 = k elif rank[k][3] == 3: w3 = k elif rank[k][3] == 4: w4 = k elif rank[k][3] == 5: w5 = k io.privateMsg(wormid, "The best players are :") io.privateMsg( wormid, "1) " + w1 + " (" + str(rank[w1][0]) + " kills, " + str(rank[w1][1]) + " deaths, " + str(rank[w1][2]) + " suicides)") io.privateMsg( wormid, "2) " + w2 + " (" + str(rank[w2][0]) + " kills, " + str(rank[w2][1]) + " deaths, " + str(rank[w2][2]) + " suicides)") io.privateMsg( wormid, "3) " + w3 + " (" + str(rank[w3][0]) + " kills, " + str(rank[w3][1]) + " deaths, " + str(rank[w3][2]) + " suicides)") io.privateMsg( wormid, "4) " + w4 + " (" + str(rank[w4][0]) + " kills, " + str(rank[w4][1]) + " deaths, " + str(rank[w4][2]) + " suicides)") io.privateMsg( wormid, "5) " + w5 + " (" + str(rank[w5][0]) + " kills, " + str(rank[w5][1]) + " deaths, " + str(rank[w5][2]) + " suicides)") except Exception: pass
def rankSingle(wormName, wormid): k = wormName io.privateMsg(wormid, str(rank[k][3]) + ") " + k + " (" + str(rank[k][0]) + " kills, " + str(rank[k][1]) + " deaths, " + str(rank[k][2]) + " suicides)")
def parseUserCommand(wormid, message): try: # Do not check on msg size or anything, exception handling is further down cmd = message.split(" ")[0] cmd = cmd.replace(cfg.USER_PREFIX, "", 1).lower() #Remove the prefix if cfg.USERCOMMAND_LOGGING: if wormid >= 0: io.messageLog( "%i:%s issued %s" % (wormid, hnd.worms[wormid].Name, cmd.replace(cfg.USER_PREFIX, "", 1)), io.LOG_USRCMD) 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": userCommandHelp(wormid) return "none" elif cmd == "maphelp": mapHelp(wormid) return "none" #News feed (previously called updates, hence the command name...) elif cmd == "news": controlUpdatesList(wormid) return "none" #Teamchanges... elif cfg.ALLOW_TEAM_CHANGE and cmd == "team": #Not team deathmatch if io.getGameType() != 1: io.privateMsg(wormid, "Game type is not team deathmatch") #Not in lobby elif hnd.gameState != hnd.GAME_LOBBY: io.privateMsg(wormid, "You can only change team in lobby") #No team specified elif not params: io.privateMsg(wormid, "You need to specify a team") #Everything OK else: if params[0].lower() == "blue" or params[0].lower() == "b": hnd.setTeam(wormid, 0) elif params[0].lower() == "red" or params[0].lower() == "r": hnd.setTeam(wormid, 1) elif (params[0].lower() == "green" or params[0].lower() == "g") and cfg.MAX_TEAMS >= 3: hnd.setTeam(wormid, 2) elif (params[0].lower() == "yellow" or params[0].lower() == "y") and cfg.MAX_TEAMS >= 4: hnd.setTeam(wormid, 3) else: io.privateMsg(wormid, "Invalid team") elif cfg.RANKING and cmd in ("rank", "toprank", "ranktotal"): if cmd == "toprank": ranking.firstRank(wormid) if cmd == "rank": if wormid in hnd.worms: wormName = hnd.worms[wormid].Name if params: wormName = " ".join(params).replace( "\"", "\'\'" ) #Convert double quotes to prevent annoyance ranking.myRank(wormName, wormid) if cmd == "ranktotal": if cfg.NAME_CHECK_ACTION == 1 and cfg.HANDLE_RANDOMS_IN_RANKTOTAL: tmp_rankplayers = sortRankPlayers( randoms=0, random_max=cfg.NAME_CHECK_RANDOM) tmp_rankrandoms = sortRankPlayers( randoms=1, random_max=cfg.NAME_CHECK_RANDOM) io.privateMsg( wormid, "There are " + str(len(tmp_rankplayers)) + " players and " + str(len(tmp_rankrandoms)) + " unnamed players in the ranking.") else: io.privateMsg( wormid, "There are " + str(len(ranking.rank)) + " players in the ranking.") return "none" elif cfg.KICK_VOTING and cmd == "kick": try: kicked = int(params[0]) except ValueError: io.privateMsg(wormid, "Invalid player ID") if not kicked in hnd.worms.keys(): io.privateMsg(wormid, "Invalid player ID") else: hnd.worms[wormid].votedKick = kicked io.chatMsg( hnd.worms[wormid].getCleanName() + " votes to kick " + hnd.worms[kicked].getCleanName() ) #NOTE: We are using the real name here - so it should be cleaned return "kick" elif cfg.VOTING and cmd in ("mod", "map", "m"): if cmd == "mod": #NEW: only presets 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: hnd.worms[wormid].votedPreset = hnd.availablePresets[ preset] io.privateMsg(wormid, "You voted for %s" % hnd.worms[wormid].votedPreset ) #Send these as private msgs to reduce spam return "mod" else: io.privateMsg( wormid, "Invalid preset, available presets: " + ", ".join(hnd.availablePresets)) if cmd == "map": level = "" for l in io.listMaps(): if l.lower().find(" ".join(params[0:]).lower()) != -1: level = l break if level != "": hnd.worms[wormid].votedMap = level io.privateMsg( wormid, "You voted for %s" % hnd.worms[wormid].votedMap) return "map" else: io.privateMsg( wormid, "Invalid map, available maps: " + ", ".join(io.listMaps()) ) #NOTE: This generates a very spammy message... #Quick map voting if cmd == "m": if not params: io.privateMsg( wormid, "No map specified, try %smaphelp for a list of options" % cfg.USER_PREFIX) elif params[0].lower() in presetcfg.MAP_SHORTCUTS.keys(): hnd.worms[wormid].votedMap = presetcfg.MAP_SHORTCUTS[ params[0].lower()] io.privateMsg( wormid, "You voted for %s" % hnd.worms[wormid].votedMap) return "map" else: io.privateMsg( wormid, "Invalid map option, try %smaphelp for a list of available options" % cfg.USER_PREFIX) elif cfg.TEAMGAMES_VOTING and (cmd == "teams" or cmd == "noteams"): if cmd == "teams": hnd.worms[wormid].votedTeams = 1 io.privateMsg(wormid, "You voted for team game!") elif cmd == "noteams": hnd.worms[wormid].votedTeams = 0 io.privateMsg(wormid, "You voted for deathmatch!") return "teams" #Team shuffling elif cmd == "shuffle" and cfg.TEAM_SHUFFLE: #Not TDM if io.getGameType() != 1: io.privateMsg(wormid, "Not TDM - cannot shuffle") #Not in lobby elif hnd.gameState != hnd.GAME_LOBBY: io.privateMsg(wormid, "Cannot shuffle when not in lobby") #Too many shuffles elif hnd.shuffle_counter >= cfg.TEAM_SHUFFLE: io.privateMsg(wormid, "Shuffle limit already reached") else: hnd.shuffleTeams() #Not in lobby #TEST: Use this to check team status... #elif cfg.TEAMCHANGE_LOGGING and cmd == "teamtest": # io.messageLog("TEAMTEST: teamtest called by player " + str(wormid), io.LOG_INFO) # teamtestresult = str(hnd.getNumberWormsInAllTeams()).replace("[","").replace("]","").replace(","," ") # io.privateMsg(wormid, "Team status is "+teamtestresult+" - is this reasonable?") # return "none" else: raise Exception, "Invalid user command" except: # All python classes derive from main "Exception", but confused me, this has the same effect. if wormid >= 0: io.privateMsg( wormid, "Invalid user command - type !help for list of commands") if cfg.USERCOMMAND_ERROR_LOGGING: io.messageLog(io.formatExceptionInfo(), io.LOG_ERROR) #Helps to fix errors return None return "none"
def parseNewWorm(wormID, name): global worms exists = False try: worm = worms[wormID] exists = True except KeyError: #Worm doesn't exist. worm = Worm() worm.real_name = name #NOTE: This is the name used by the server #Now prepare the name used by the script - used for ranking, for example name = name.replace("\t", " ").strip( ) # Do not allow tab in names, it will screw up our ranking tab-separated text-file database #Check if the player has quotation marks in his/her name quotemarks_in_nick = 0 if "\"" in name: name = name.replace( "\"", "\'\'" ) #Double quotes (") cause problems with chat/private messages - convert to single quotes (') quotemarks_in_nick = 1 worm.Name = name worm.iID = wormID worm.Ping = [] wormIP = io.getWormIP(wormID).split(":")[ 0] #Get worm IP address now - it will be needed later worm.Ip = wormIP worms[wormID] = worm #Set team for handler ##NOTE: OLX sets a team when the player joins - and it may not always be 0 (blue)!!! So get the team number now! #TEST: Log these initial teams if cfg.TEAMCHANGE_LOGGING: io.messageLog( "TEAMJOIN: Game reports team " + str(io.getWormTeam(wormID)) + " for joining worm " + str(name), io.LOG_INFO) worm.Team = io.getWormTeam(wormID) # io.messageLog("Curtime " + str(time.time()) + " IP " + str(wormIP) + " Kicked worms: " + str(kickedUsers), io.LOG_INFO) if wormIP in kickedUsers and kickedUsers[wormIP] > time.time(): io.kickWorm( wormID, "You can join in " + str(int(kickedUsers[wormIP] - time.time()) / 60 + 1) + " minutes") return #Original ranking authentication based on skin color... #NOTE: This is a weak way of authentication if cfg.RANKING_AUTHENTICATION: if not name in ranking.auth: ranking.auth[name] = getWormSkin(wormID) try: rank_auth_file_path = io.getWriteFullFileName( cfg.RANKING_AUTH_FILE) f = open(rank_auth_file_path, "a") try: portalocker.lock(f, portalocker.LOCK_EX) except: pass f.write(name + "\t" + str(ranking.auth[name][0]) + " " + ranking.auth[name][1] + "\n") f.close() except IOError: io.messageLog( "parseNewWorm: Unable to open ranking authentication file: " + cfg.RANKING_AUTH_FILE + " from path: " + rank_auth_file_path, io.LOG_ERROR) else: if ranking.auth[name] != getWormSkin(wormID): io.kickWorm(wormID, "Player with name %s already registered" % name) return #Notify or kick players that have forbidden nicks if name in cfg.FORBIDDEN_NAMES: if cfg.NAME_CHECK_ACTION == 1: worm.Name = "random" + str(random.randint( 0, cfg.NAME_CHECK_RANDOM)) #Assign random name io.privateMsg(wormID, cfg.NAME_CHECK_WARNMSG) elif cfg.NAME_CHECK_ACTION == 2: io.kickWorm(wormID, cfg.NAME_CHECK_KICKMSG) return #NEW: Kick players who have newline tags in their nicks - those can cause annoyance #NOTE: This may give false positives if there are nested tags, but it's an unlikely case if detectFormattingTags(name): io.kickWorm( wormID, "Please remove formatting tags ( <...> ) from your nickname - they cause problems" ) return #Kick players with excessively long nicks. #NOTE: In 0.59, oversized name are truncated automatically so this becomes obsolete if len(name) > cfg.MAX_NAME_LENGTH: io.kickWorm(wormID, "name too long") return #Kick players with quotation marks in their name (only if configured!) #NOTE: This should not be needed anymore if quotemarks_in_nick == 1 and cfg.KICK_QUOTEMARKS == 1: io.kickWorm( wormID, "please remove quotation marks from your nickname - they screw up ranking." ) return #If only one player per IP allowed, check if there is already a player from the IP #NOTE: This is a weak check and may cause more harm than good as it prevents people behind a shared IP from joining while not really preventing rank manipulation if cfg.ONE_PLAYER_PER_IP: for w in worms.keys(): if worms[w].Ip == wormIP and w != wormID: io.kickWorm(wormID, "only one player per IP address allowed") return #Nag players to download the latest version. 0.58 rc3 may still be in use, and this is less harsh than kicking. #TODO: Do this in a better way? if cfg.VERSION_CHECK: ver = io.getWormVersion(wormID) newest_ver = io.getVar("GameOptions.State.NewestVersion") #Newest version, everything OK if distutils.version.LooseVersion( ver.lower()) == distutils.version.LooseVersion( newest_ver.lower()): pass #Outdated 0.58 versions and older elif distutils.version.LooseVersion( ver.lower()) < distutils.version.LooseVersion( newest_ver.lower()): io.privateMsg( wormID, "You're using an outdated version! Please download " + newest_ver.replace("/", " ").replace("_", " ") + " from http://openlierox.net/") #0.59 b10 and later are buggy elif distutils.version.LooseVersion( ver.lower()) >= distutils.version.LooseVersion( "OpenLieroX/0.59_beta10".lower()): io.privateMsg( wormID, "You're using a buggy version of the game! You may want to download " + newest_ver.replace("/", " ").replace("_", " ") + " from http://openlierox.net/") #Other 0.59 versions are not as buggy but they lack the nice updates of 0.58 rc5 else: io.privateMsg( wormID, "You seem to be using an experimental version of the game! You may want to download " + newest_ver.replace("/", " ").replace("_", " ") + " from http://openlierox.net/") #Assign team if io.getGameType() == 1: worms[ wormID].votedTeams = 1 #Set vote status to 1 so that it will be TDM if it was TDM before this player joined io.privateMsg( wormID, "Game type is team deathmatch - say !noteams if you do not want teams for the next game" ) #NOTE: The player is already assigned to a team by the game! - so assigning him to the smallest team here would lead to unbalancement # if the team status were, for example, [4, 4]. So check whether 1) teams are balanced (difference <=1) or not, and 2) the player is not in the smallest team #NOTE: Calling balanceTeams might look more elegant, but it might move other players as well, and it should not be called when we are not in lobby #NOTE: Be careful with RandomTeamForNewWorm option! It may cause an exception! team_status = getNumberWormsInAllTeams() #Get team member counts team_status = team_status[ 0:cfg.MAX_TEAMS] #Remove teams that are not used wormteam = io.getWormTeam( wormID) #Could use worm.Team too, but this might be safer... if (max(team_status) - min(team_status) ) > 1 and wormteam != team_status.index(min(team_status)): setTeam(wormID, team_status.index(min(team_status))) #Update votes - this is needed if there are, let's say, 3 players who all vote for TDM but TDM requires 4 - now there are 4 and 3 of them vote so TDM should be selected! #No need to broadcast anything - TDM is broadcasted if the status changes. updateVotes()