def HandleAdminCommand(player, ip, acl, *command): global data if Global.state!="modeeditor": LadderLogHandlers.unregister_handler("ADMIN_COMMAND", HandleAdminCommand) if(Armagetronad.IsSetting(command[0]) and len(command)>1): data["mode"].settings[command[0]]=" ".join(command[1:]) Armagetronad.PrintMessage("0xff0000"+command[0]+" changed to "+" ".join(command[1:])) setSettings()
def unloadExtension(name): name=[x for x in getExtensions() if x.lower()==name.lower()] if not len(name): return True name=name[0] global loadedExtensions module=[i for i in loadedExtensions if i.__name__==name] if len(module)!=1: return False module=module[0] loadedExtensions.remove(module) tools.delete_modules_from_dir(os.path.join("extensions", name)) LadderLogHandlers.unregister_package(module.__name__) Commands.unregister_package(module.__name__) sys.stderr.write("[EXTENSION] Unloaded extension "+module.__name__+"\n")
def main(debug=False, disabledCommands=[], reloaded=False): if not reloaded: h=logging.StreamHandler() h.setLevel(logging.DEBUG) f=logging.Formatter("[%(name)s] (%(asctime)s) %(levelname)s: %(message)s") h.setFormatter(f) log.addHandler(h) log.setLevel(logging.INFO) #We need some special settings. Set it Global.set_script_settings() for x in dir(LadderLogHandlers): if not x[0].isupper(): continue if inspect.isfunction(getattr(LadderLogHandlers,x)): x="".join([i.upper() if i.islower() else "_"+i for i in x]) Armagetronad.SendCommand("LADDERLOG_WRITE"+x+" 1") # X has already a underscore at beginning. if not reloaded: if Global.debug: log.info("Starting in debug mode.") Player.enableLogging(logging.DEBUG) Team.enableLogging(logging.DEBUG) LadderLogHandlers.enableLogging(logging.DEBUG) Poll.enableLogging(logging.DEBUG) else: Player.enableLogging(logging.WARNING) Team.enableLogging(logging.WARNING) LadderLogHandlers.enableLogging(logging.INFO) Poll.enableLogging(logging.WARNING) Commands.disabled=Commands.disabled+disabledCommands #Init AccessLevel.load() if not reloaded: log.info("Script started") Armagetronad.PrintMessage("0xff0000Script started") else: log.info("Script reloaded") #We need to refresh player list Global.reloadPlayerList() while(True): line="" if Global.handleLadderLog==False: time.sleep(1) continue try: line=input() except KeyboardInterrupt: log.info("Exiting") break line=line.strip() keywords=line.split(" ") command=keywords[0] args=keywords[1:] del keywords #make command name CamelCase real_commandname=command.upper() command=command.lower() command=command.replace("_"," ") command=command.title() command=command.replace(" ","") #call handler if(hasattr(LadderLogHandlers,command) ): getattr(LadderLogHandlers,command)(*args) if real_commandname in LadderLogHandlers.extraHandlers: for extraHandler in LadderLogHandlers.extraHandlers[real_commandname]: try: extraHandler(*args) except TypeError as e: log.error("Extension "+extraHandler.__package__+" registered a wrong ladderlog handler. This is a bug.") if debug: raise e
def modeEditor(acl, player): if Global.state=="modeEditor": Armagetronad.PrintPlayerMessage(player, "0xff0000Already in mode editor state!") Armagetronad.SendCommand("INCLUDE settings.cfg") Armagetronad.SendCommand("SINCLUDE settings_custom.cfg") Armagetronad.SendCommand("DEFAULT_KICK_REASON Server\ under\ maintenance.") def setSettings(): Armagetronad.SendCommand("ALLOW_TEAM_NAME_PLAYER 1") Armagetronad.SendCommand("FORTRESS_CONQUEST_TIMEOUT -1") Armagetronad.SendCommand("MAX_CLIENTS 1") Armagetronad.SendCommand("SP_TEAMS_MAX 1") Armagetronad.SendCommand("TEAMS_MAX 1") Armagetronad.SendCommand("SP_AUTO_AIS 0") Armagetronad.SendCommand("AUTO_AIS 0") Armagetronad.SendCommand("SP_NUM_AIS 0") Armagetronad.SendCommand("NUM_AIS 0") Armagetronad.SendCommand("CYCLE_SPEED_MIN 0") Armagetronad.SendCommand("CYCLE_RUBBER 10000000") Armagetronad.SendCommand("SP_WALLS_LENGTH 0.000001") Armagetronad.SendCommand("CYCLE_SPEED 5") Armagetronad.SendCommand("CYCLE_BRAKE -100") Armagetronad.SendCommand("CYCLE_BRAKE_DEPLETE 0") Armagetronad.SendCommand("CYCLE_SPEED_DECAY_ABOVE 1.5") Armagetronad.SendCommand("CYCLE_ACCEL 0") Armagetronad.SendCommand("SP_MIN_PLAYERS 0") Armagetronad.SendCommand("CYCLE_TURN_SPEED_FACTOR 1") Armagetronad.SendCommand("CYCLE_SPEED_DECAY_BELOW 2") Armagetronad.SendCommand("FORTRESS_SURVIVE_WIN 0") setSettings() Poll.Cancel() Mode.current_mode=None Armagetronad.SendCommand("NETWORK_AUTOBAN_FACTOR 0") Armagetronad.PrintPlayerMessage(player, "0xff0000Kicking other players ...") Armagetronad.PrintPlayerMessage(player, "\n"*4) for playero in Player.players.values(): if playero.ip!=Player.players[player].ip: Armagetronad.SendCommand("KICK "+playero.getLadderName() ) else: playero.kill() Armagetronad.SendCommand("NETWORK_AUTOBAN_FACTOR 10") Armagetronad.SendCommand("LADDERLOG_WRITE_ADMIN_COMMAND 1") def HandleAdminCommand(player, ip, acl, *command): global data if Global.state!="modeeditor": LadderLogHandlers.unregister_handler("ADMIN_COMMAND", HandleAdminCommand) if(Armagetronad.IsSetting(command[0]) and len(command)>1): data["mode"].settings[command[0]]=" ".join(command[1:]) Armagetronad.PrintMessage("0xff0000"+command[0]+" changed to "+" ".join(command[1:])) setSettings() LadderLogHandlers.register_handler("ADMIN_COMMAND", HandleAdminCommand) Global.state="modeeditor" global data data=dict() data["speed"]=5 data["mode"]=Mode.Mode("Unsaved") data["stopped"]=False def PrintMessage(): message="""0x00ffffWelcome to ModeEditor! 0xffffff ModeEditor was made to help you creating new modes. Use the /stop, /go, /lessSpeed, /moreSpeed and brake commands to controll the speed of the cycle. To add a zone or a respawn point at the current position of your cycle use /makeZone and /makeRes. If you want to go to a specific position, use /stop and then use /tele. You can use /modeSetting to change settings like name and lives. To change game settings like rubber you can use /admin (i.e. /admin CYCLE_RUBBER 5). Your changes will get recorded. To save the mode use /saveMode to save the mode. If you want to go back to normal mode, use /normal.""" for msg in message.split("\n"): Armagetronad.PrintMessage(msg) time.sleep(3) LadderLogHandlers.atRoundend.append(PrintMessage)
message=Messages.PlayerRespawned.format(player=Player.players[player].name, msg=res_msg) if not SimpleMode.current_lives==0: Armagetronad.PrintMessage(message) def HandleCycleCreated(player_name, x, y, xdir, ydir): if SimpleMode.current_mode: if "respoint" not in Player.players[player_name].data: if SimpleMode.current_lives==None: Player.players[player_name].setLives(SimpleMode.current_mode.lives+1) #@UndefinedVariable else: Player.players[player_name].setLives(SimpleMode.current_lives+1) Player.players[player_name].data["respoint"]=tuple( map( float,(x,y,xdir,ydir) ) ) def DoInit(*args): if SimpleMode.current_mode: SimpleMode.current_mode.activate(kill=False) #@UndefinedVariable for player_name in Player.players: if "respoint" in Player.players[player_name].data: del Player.players[player_name].data["respoint"] def CheckForNewMatch(cur_num, max_num): if cur_num=="1": if SimpleMode.current_mode: Armagetronad.SendCommand("CENTER_MESSAGE "+Messages.ModeMessage.format(mode=SimpleMode.current_mode.name)) #@UndefinedVariable for respawn_event in RESPAWN_EVENTS: LadderLogHandlers.register_handler(respawn_event, HandlePlayerDied) LadderLogHandlers.register_handler("CYCLE_CREATED", HandleCycleCreated) LadderLogHandlers.register_handler("ROUND_COMMENCING", DoInit, CheckForNewMatch)