Пример #1
0
def checkConfigLists():

    availableMapList = io.listMaps()

    for l in cfg.LEVELS:
        if l not in availableMapList:
            io.messageLog("Autocycle map not found: %s" % l, io.LOG_ERROR)

    for k in presetcfg.MAP_SHORTCUTS.values():
        if k not in availableMapList:
            io.messageLog("Shortcut map not found: %s" % k, io.LOG_ERROR)
Пример #2
0
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"
Пример #3
0
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 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 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 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