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)) queue_server_command(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)) queue_server_command(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 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 add_directory(self, directory): """Add all files in the given directory to the downloadables. :param str directory: The directory to add to the downloadables. """ # Loop through all files in the directory for file in GAME_PATH.joinpath(directory).walkfiles(): # Add the current file to the downloadables self.add(file.replace(GAME_PATH, '').replace('\\', '/'))
def add_directory(self, directory): """Add all files in the given directory to the downloadables. :param str directory: The directory to add to the downloadables. :return: Return the number of files that have been added. :rtype: int """ index = 0 for index, file in enumerate(GAME_PATH.joinpath(directory).walkfiles(), 1): self.add(file.replace(GAME_PATH, '').replace('\\', '/').lstrip('/')) return index
def add_directory(self, directory): """Add all files in the given directory to the downloadables. :param str directory: The directory to add to the downloadables. :return: Return the number of files that have been added. :rtype: int """ index = 0 for index, file in enumerate(GAME_PATH.joinpath(directory).walkfiles(), 1): self.add(file.replace(GAME_PATH, '').replace('\\', '/')) return index
def load_plugin(self, plugin_name): """Load a plugin by name. :param str plugin_name: Name of the plugin to load. :return: Return the loaded plugin. Return ``None`` on failure. :rtype: Plugin """ plugin = None self.log_message( self.translations['Loading'].get_string(plugin=plugin_name)) try: plugin = self.manager.load(plugin_name) except InvalidPluginName: self.log_message(self.translations['Invalid Name'].get_string( plugin=plugin_name)) except PluginAlreadyLoaded: self.log_message(self.translations['Already Loaded'].get_string( plugin=plugin_name)) except PluginFileNotFoundError: self.log_message(self.translations['No Module'].get_string( plugin=plugin_name, file=GAME_PATH.relpathto( self.manager.get_plugin_file_path(plugin_name)).replace( '\\', '/'))) except PluginHasBuiltInName: self.log_message( self.translations['Built-in'].get_string(plugin=plugin_name)) except: except_hooks.print_exception() self.log_message(self.translations['Unable to Load'].get_string( plugin=plugin_name)) else: self.log_message(self.translations['Successful Load'].get_string( plugin=plugin_name)) return plugin
def load_plugin(self, plugin_name): """Load a plugin by name. :param str plugin_name: Name of the plugin to load. :return: Return the loaded plugin. Return ``None`` on failure. :rtype: Plugin """ plugin = None self.log_message(self.translations[ 'Loading'].get_string(plugin=plugin_name)) try: plugin = self.manager.load(plugin_name) except InvalidPluginName: self.log_message(self.translations[ 'Invalid Name'].get_string(plugin=plugin_name)) except PluginAlreadyLoaded: self.log_message(self.translations[ 'Already Loaded'].get_string(plugin=plugin_name)) except PluginFileNotFoundError: self.log_message(self.translations[ 'No Module'].get_string( plugin=plugin_name, file=GAME_PATH.relpathto( self.manager.get_plugin_file_path( plugin_name)).replace('\\', '/'))) except PluginHasBuiltInName: self.log_message(self.translations[ 'Built-in'].get_string(plugin=plugin_name)) except: except_hooks.print_exception() self.log_message(self.translations[ 'Unable to Load'].get_string(plugin=plugin_name)) else: self.log_message(self.translations[ 'Successful Load'].get_string(plugin=plugin_name)) return plugin
from paths import GAME_PATH from public import public # ============================================================================= # >> ALL DECLARATION # ============================================================================= # Add all the global variables to __all__ __all__ = ['GAME_NAME', 'GameEngine'] # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the specific game for the server GAME_NAME = GAME_PATH.rsplit(sep, 2)[1] # Get the Engine's instance GameEngine = get_engine_interface() # ============================================================================= # >> CLASSES # ============================================================================= @public class AutoUnload(object): ''' Class used to auto unload specific instances. Each class which inherits this one should have a _unload_instance method.
# >> ALL DECLARATION # ============================================================================= __all__ = ( 'AutoUnload', 'GAME_NAME', 'PLATFORM', 'SOURCE_ENGINE', 'SOURCE_ENGINE_BRANCH', 'echo_console', ) # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= # Get the specific game for the server GAME_NAME = GAME_PATH.rsplit(sep, 2)[1] # Get the platform the server is on PLATFORM = system().lower() # Get the sp.core logger core_logger = _sp_logger.core # Create a dictionary to store AutoUnload object in _module_instances = defaultdict(list) # ============================================================================= # >> CLASSES # ============================================================================= class AutoUnload(object):