def exec_all_registered(event_name): import es exec_cmd = execmd_cvar.get_string() script_dir = scriptdir_cvar.get_string() # Execute root scripts cfg_path = '{}/{}.cfg'.format(script_dir, event_name) if GAME_PATH.joinpath('cfg', cfg_path).exists(): es.dbgmsg(2, 'Sending {} command for {}.'.format(exec_cmd, event_name)) engine_server.server_command('{} {}'.format(exec_cmd, cfg_path)) # Execute cfg scripts es.dbgmsg(2, 'Script pack registration scanning...') for scriptpack, enabled in cfg_scripts.items(): if not enabled: continue cfg_path = '{}/{}/{}.cfg'.format(script_dir, scriptpack, event_name) if GAME_PATH.joinpath('cfg', cfg_path).exists(): es.dbgmsg(2, 'Sending {} command for {}.'.format(exec_cmd, cfg_path)) engine_server.server_command('{} {}'.format(exec_cmd, cfg_path)) else: es.dbgmsg(1, 'File doesn\'t exist: {}'.format(cfg_path)) # Execute Python addons es.dbgmsg(2, 'Checking all scripts...') es.addons.triggerEvent(event_name)
def load(): """Setups the database upon sp load. Makes sure there are heroes on the server, restarts the game and setups the database file. Raises: NotImplementedError: When there are no heroes """ heroes = Hero.get_subclasses() if not heroes: raise NotImplementedError('No heroes on the server.') if not cfg.starting_heroes: raise NotImplementedError('No starting heroes set.') for cid in cfg.starting_heroes: if not find_element(heroes, 'cid', cid): raise ValueError('Invalid starting hero cid: {0}'.format(cid)) # Setup database setup() # Restart the game engine_server.server_command('mp_restartgame 1\n') # Send a message to everyone other_messages['Plugin Loaded'].send()
def load(): """Setup the plugin.""" # Make sure there are proper heroes on the server wcgo.utilities.import_modules(wcgo.heroes) wcgo.utilities.import_modules(wcgo.items) heroes = wcgo.entities.Hero.get_subclass_dict() if not heroes: raise NotImplementedError( "There are no heroes on the server") starting_heroes = cfg.starting_heroes.get_string().split(',') if not starting_heroes: raise NotImplementedError( "There are no starting heroes defined") for clsid in starting_heroes: if clsid not in heroes: raise ValueError( "Invalid starting hero clsid: '{0}'".format(clsid)) # Initialize the database and restart the game global database database = wcgo.database.Database(_DATABASE_PATH) for player in wcgo.player.PlayerIter(): _init_player(player) # Listen to Hero.e_level_up event and restart the game wcgo.entities.Hero.e_level_up += _on_hero_level_up engine_server.server_command('mp_restartgame 1\n')
def restartround(self): ENDROUND_TEXT = 'endround' CVAR_ENDROUND = cvar.find_base(ENDROUND_TEXT) CVAR_ENDROUND.remove_flags(ConVarFlags.CHEAT) engine_server.server_command('{0};'.format(ENDROUND_TEXT)) engine_server.server_execute() CVAR_ENDROUND.add_flags(ConVarFlags.CHEAT)
def sp_unban(source, command): if command.get_arg_count() == 1: source.message("c=(white)[c=(purple)SPc=(white)] Usage: $c=(purple)sp_unban $c=(white)<steamid>") return CommandReturn.BLOCK steamid = command[1] engine_server.server_command("removeid {}\n".format(steamid)) return CommandReturn.BLOCK
def load(): """Setups the database upon Hero-Wars loading. Makes sure there are heroes on the server, restarts the game and setups the database file. Raises: NotImplementedError: When there are no heroes """ heroes = Hero.get_subclasses() if not heroes: raise NotImplementedError('No heroes on the server.') if not cfg.starting_heroes: raise NotImplementedError('No starting heroes set.') for cid in cfg.starting_heroes: if not find_element(heroes, 'cid', cid): raise ValueError('Invalid starting hero cid: {0}'.format(cid)) # Setup database hw.database.setup() # Load Hero-Wars events load_events() # Restart the game engine_server.server_command('mp_restartgame 1\n') # Send a message to everyone other_messages['Plugin Loaded'].send()
def echo_console(text): """Echo a message to the server's console.""" # Import engine_server # This is done here to fix an ImportError from engines.server import engine_server # Loop through each line in the text for line in text.split("\n"): # Echo the message engine_server.server_command('echo "{0}"\n'.format(line.replace('"', "'")))
def echo_console(text): """Echo a message to the server's console.""" # Import engine_server # This is done here to fix an ImportError from engines.server import engine_server # Loop through each line in the text for line in text.split('\n'): # Echo the message engine_server.server_command('echo "{0}"\n'.format( line.replace('"', "'")))
def ban(self, duration=0, kick=True, write_ban=True): """Ban a player from the server. :param int duration: Duration of the ban in minutes. Use 0 for permament. :param bool kick: If True, the player will be kicked as well. :param bool write_ban: If True, the ban will be written to ``cfg/banned_users.cfg``. """ engine_server.server_command("banid {} {} {}".format(duration, self.userid, "kick" if kick else "")) if write_ban: engine_server.server_command("writeid")
def execute(self): """Execute the config file.""" # Does the file exist? if not self.fullpath.isfile(): raise FileNotFoundError( 'Cannot execute file "{0}", file not found'.format( self.fullpath)) # Open/close the file with self.fullpath.open() as open_file: # Loop through all lines in the file for line in open_file.readlines(): # Strip the line line = line.strip() # Is the line a command or cvar? if line.startswith('//') or not line: continue # Get the command's or cvar's name name = line.split(' ', 1)[0] # Is the command/cvar valid if name not in self._commands | self._cvars: continue # Does the command/cvar have any value/arguments? if not line.count(' '): continue # Is this a command? if name in self._commands: # Execute the line engine_server.server_command(line + '\n') # Is this a cvar else: # Get the cvar's value value = line.split(' ', 1)[1] # Do quotes need removed? if value.startswith('"') and line.count('"') >= 2: # Remove the quotes value = value.split('"')[1] # Set the cvar's value ConVar(name).set_string(value)
def _player_management_select_callback(menu, player_index, choice): """Player Management menu's select_callback function.""" if choice.value[1] == 'kick': engine_server.server_command('kickid {} {}\n'.format( choice.value[0].userid, 'Kicked by Admin.')) elif choice.value[1] == 'ban': engine_server.server_command('banid 30 {} kick\n'.format( choice.value[0].userid, 'Banned by Admin for 30 minutes.')) elif choice.value[1] == 'perm': engine_server.server_command('banid 0 {} kick\n'.format( choice.value[0].userid, 'Banned by Admin permanently.')) engine_server.server_command('writeid\n') elif choice.value[1] == 'item': next_menu = menus['Give Item'] next_menu.obj = choice.value[0] next_menu.previous_menu = menu return next_menu elif choice.value[1] == 'change': next_menu = menus['Change Exp'] next_menu.multiplier = choice.value[0] next_menu.previous_menu = menu return next_menu else: next_menu = menus['Shift Attr'] next_menu.obj = choice.value[0] next_menu.attr_name = choice.value[1] next_menu.previous_menu = menu return next_menu
def on_changelevel(command): if mapcommands_cvar.get_int() <= 0: return new_map = nextmap_cvar.get_string() if new_map in ('', '0') or len(command) <= 1: return import es nextmap_cvar.set_string('') engine_server.server_command('changelevel {}'.format(new_map)) es.dbgmsg(0, '[EventScripts] Next map changed from {} to {}.'.format( command[1], new_map)) return CommandReturn.BLOCK
def sp_kick(source, command): if command.get_arg_count() == 1: source.message("c=(white)[c=(purple)SPc=(white)] Usage: " "$c=(purple)sp_kick $c=(white)<name|#userid|@filter> [reason: \"\"]") return CommandReturn.BLOCK targets = target_filter(command[1], source.index) if len(targets) == 0: source.message("c=(white)[c=(purple)SPc=(white)] No Targets found.") else: for target in targets: reason = " ".join([command[x] for x in range(2, command.get_arg_count())]) engine_server.server_command("kickid {} {}\n".format(userid_from_index(target), reason)) source.message("c=(white)[c=(purple)SPc=(white)] Kicked " + str(len(targets)) + " players.") return CommandReturn.BLOCK
def end_warmup(): """End warmup and start the match.""" # TODO: Call start match # Get the configuration to call on warmup end current = end_config.get_string() # Is a configuration file supposed to be called? if current: # Call the end configuration engine_server.server_command( 'exec {config};'.format( config=current, ) )
def _sp_help(command_info, command=None, *server_sub_commands): """Print all sp sub-commands or help for a specific command.""" if command is None: engine_server.server_command('sp') return commands = (command,) + server_sub_commands try: node = TypedServerCommand.parser.get_node(commands) except ValueError: core_command_logger.log_message( 'Command "{}" does not exist.'.format(' '.join(commands))) return core_command_logger.log_message(node.signature) if node.description is not None: core_command_logger.log_message(' ' + node.description)
def start_warmup(self): """Start warmup round.""" # Reset the extensions used self._extensions = 0 # Get the amount of time for warmup self._warmup_time = warmup_time.get_int() # Was an invalid value given? if self._warmup_time <= 0: warn( '"gg_warmup_time" is set to an invalid number.' ' Skipping warmup round.' ) self.end_warmup() return # Get the configuration to call on warmup start current = start_config.get_string() # Is a configuration file supposed to be called? if current: # Call the start configuration engine_server.server_command( 'exec {config};'.format( config=current, ) ) # Get the warmup weapon self._find_warmup_weapon() # Set the match status GunGameStatus.MATCH = GunGameMatchStatus.WARMUP # TODO: Give warmup weapon # Start the warmup repeat self.repeat.start(1, self._warmup_time)
def sp_ban(source, command): if command.get_arg_count() == 1: source.message("c=(white)[c=(purple)SPc=(white)] Usage: " "$c=(purple)sp_ban $c=(white)<name|#userid|@filter> [minutes: 0] [reason: \"\"]") return CommandReturn.BLOCK targets = target_filter(command[1], source.index) time = command[2] if command.get_arg_count() > 2 else 0 reason = " ".join([command[x] for x in range(3, command.get_arg_count())]) if len(targets) == 0: source.message("c=(white)[c=(purple)SPc=(white)] No Targets found.") else: for target in targets: engine_server.server_command("banid {} {}\n".format(time, userid_from_index(target))) engine_server.server_command("kickid {} {}\n".format(userid_from_index(target), reason)) engine_server.server_command("writeid") source.message("c=(white)[c=(purple)SPc=(white)] Banned " + str(len(targets)) + " players.") return CommandReturn.BLOCK
def execute(self): """Execute the config file.""" engine_server.server_command( 'exec source-python/{0}\n'.format(self.filepath))
def reset_cvars(): engine_server.server_command("mp_limitteams 0;") engine_server.server_command("mp_autoteambalance 0;")
def enter_warm_up_state(self): self.state = self.States.warm_up self.player_pool.unready_all() warm_up_map = random.choice(self.WARM_UP_MAPS) engine_server.server_command('changelevel %s;' % warm_up_map)
def kick(self, message=""): """Kick the player from the server. :param str message: A message the kicked player will receive. """ engine_server.server_command("kickid {} {}".format(self.userid, message).rstrip())
def start_match(): is_warmup_period = False engine_server.server_command('mp_warmup_end;') SayText2(CHAT_PREFIX + "!LIVE ON NEXT RESTART!").send() engine_server.server_command('mp_restartgame 10;')
def endless_warmup(): if is_warmup_period == True: engine_server.server_command('mp_warmup_pausetimer 1;')