/*----------------------------------------------------------------------------*-YAdmin system - Modules CoreChangelog:23/03/07:First version, loads and closes FS modules and recieves registration data.-*----------------------------------------------------------------------------*/#define MAX_MODULE_PATH 16#define MAX_MODULE_NAME 16#define MAX_MODULE_TAG 64#define MAX_MODULE_FILENAME (MAX_MODULE_PATH + MAX_MODULE_NAME + 4)#define MODULE_LOAD_FILE "YSS/modules.txt"#define MODULE_LOAD_PATH "YSS/modules/"#define MODULE_START Module:1forward Modules_Close(name[]);forward Module:Modules_Register(name[], tag[], hidden);enum e_MOD_FLAG (<<= 1){ e_MOD_FLAG_NONE, e_MOD_FLAG_PRIVATE = 1, e_MOD_FLAG_ACTIVE} // e - weak tagenum E_MODULES{ E_MODULES_NAME[MAX_MODULE_NAME], E_MODULES_TAG[MAX_MODULE_TAG], e_MOD_FLAG:E_MODULES_FLAGS} // E - strong tagstatic g_sModuleData[MAX_MODULES][E_MODULES], g_sModuleCount = 0, g_sHiddenCount = 0, g_sVisibleCount = 0;/*----------------------------------------------------------------------------*-Function: Modules_ModulesParams: -Return: Modules_LoadAll().Notes: The "constructor" for all this, although it just forwards (inline).-*----------------------------------------------------------------------------*/#define Modules_Modules() \ Modules_LoadAll()/*----------------------------------------------------------------------------*-Function: Modules_IsActiveParams: Module:moduleID - The module index you want to check the state of.Return: e_MOD_FLAG_ACTIVE state.Notes: Tries to be an inline function.-*----------------------------------------------------------------------------*/#define Modules_IsActive(%1) \ (g_sModuleData[%1][E_MODULES_FLAGS] & e_MOD_FLAG_ACTIVE)/*----------------------------------------------------------------------------*-Function: Modules_IsPrivateParams: Module:moduleID - The module index you want to check the state of.Return: e_MOD_FLAG_PRIVATE state.Notes: Tries to be an inline function.-*----------------------------------------------------------------------------*/#define Modules_IsPrivate(%1) \ (g_sModuleData[%1][E_MODULES_FLAGS] & e_MOD_FLAG_PRIVATE)/*----------------------------------------------------------------------------*-Function: Modules_LoadAllParams: -Return: bool: module list load success.Notes: Reads the list of modules and calls the loader code.-*----------------------------------------------------------------------------*/stock bool:Modules_LoadAll(){ new File:f; if (!(f = fopen(MODULE_LOAD_FILE, io_read))) return false; new line[MAX_STRING]; while (fread(f, line)) { if (line[0] > ' ') Modules_Open(line); } fclose(f); return true;}/*----------------------------------------------------------------------------*-Function: Modules_CloseAllParams: -Return: -Notes: Goes through the modules array and closes all the EXTERNAL modules.-*----------------------------------------------------------------------------*/stock Modules_CloseAll(){ for (new Module:i = MODULE_START; i < MAX_MODULES; i++) { Modules_CloseID(i); } // Just in case the counting went wrong somewhere g_sModuleCount = 0; g_sHiddenCount = 0; g_sVisibleCount = 0;}/*----------------------------------------------------------------------------*-Function: Modules_OpenParams: name[] - The module name for the file to load.Return: -Notes: Formats and calls the RCON command to load a filterscript for a module.-*----------------------------------------------------------------------------*/stock Modules_Open(name[]){ new command[MAX_MODULE_FILENAME + 8]; format(command, sizeof (command), "loadfs %sYSS_%s", MODULE_LOAD_PATH, name); SendRconCommand(command);}/*----------------------------------------------------------------------------*-Function: Modules_CloseParams: name[] - The module name for the file to close.Return: -Notes: Formats and calls the RCON command to unload a module filterscript.-*----------------------------------------------------------------------------*/public Modules_Close(name[]){ new command[MAX_MODULE_FILENAME + 10]; format(command, sizeof (command), "unloadfs %sYSS_%s", MODULE_LOAD_PATH, name); SendRconCommand(command);}/*----------------------------------------------------------------------------*-Function: Modules_CloseIDParams: Module:id - The module id you want to get the name of to close.Return: -Notes: Resolves an id into a name and calls Modules_Close for that name. Also handles updates of loaded module information.-*----------------------------------------------------------------------------*/stock Modules_CloseID(Module:id){ if (!Modules_IsActive(id)) return; Modules_Close(g_sModuleData[id][E_MODULES_NAME]); if (Modules_IsPrivate(id)) { g_sHiddenCount--; } else { g_sVisibleCount--; } g_sModuleData[id][E_MODULES_FLAGS] = e_MOD_FLAG_NONE; g_sModuleCount--;}/*----------------------------------------------------------------------------*-Function: Modules_CloseDelayParams: name[] - The module name to pass to be closed.Return: -Notes: Sets a timer to call the unload code after the filterscript is loaded.-*----------------------------------------------------------------------------*/#define Modules_CloseDelay(%1) \ SetTimerEx("Modules_Close", 100, 0, "s", (%1)) // 1/10th of a second should more than do!/*----------------------------------------------------------------------------*-Function: Modules_RegisterParams: name[] - The module's name (same as the filename part). tag[] - The module's textual description for information display. hidden - Wether or not all players can see this module listed.Return: Module: Fail - 0, Success - index.Notes: The public function called by module filterscripts once they're loaded. Allows the script to know that everything is loaded and ready to go.-*----------------------------------------------------------------------------*/public Module:Modules_Register(name[], tag[], hidden){ new Module:i = MODULE_START; // Find a spare slot while (i < MAX_MODULES) { if (!Modules_IsActive(i)) break; i++; } // None found if (i == MAX_MODULES) { Modules_CloseDelay(name); // Close it after a delay so it's not shutting down while starting up return Module:0; } // Save the data g_sModuleData[i][E_MODULES_FLAGS] = e_MOD_FLAG_ACTIVE; Modules_SetVisibility(i, hidden); //if (strlen(name) >= MAX_MODULE_NAME) name[MAX_MODULE_NAME - 1] = '\0'; //if (strlen(tag) >= MAX_MODULE_NAME) tag[MAX_MODULE_TAG - 1] = '\0'; strcpy(g_sModuleData[i][E_MODULES_NAME], name); strcpy(g_sModuleData[i][E_MODULES_TAG], tag); g_sModuleCount++; return i;}/*----------------------------------------------------------------------------*-Function: Modules_SetVisibilityParams: Module:id - The module id you want to modify. hide - Wether or not it's to be displayed to all.Return: -Notes: Sets wether or not the module is listed to regular people module lists.-*----------------------------------------------------------------------------*/static stock Modules_SetVisibility(Module:id, hide){ g_sModuleData[id][E_MODULES_FLAGS] &= ~e_MOD_FLAG_PRIVATE; g_sModuleData[id][E_MODULES_FLAGS] |= hide ? e_MOD_FLAG_PRIVATE : e_MOD_FLAG_NONE; Modules_UpdateCounts();}/*----------------------------------------------------------------------------*-Function: Modules_UpdateCountsParams: -Return: -Notes: When a module is loaded/unloaded this ensures the counts of visible and hidden modules is accurate as running variable totals can be innacurate.-*----------------------------------------------------------------------------*/static stock Modules_UpdateCounts(){ g_sHiddenCount = 0; g_sVisibleCount = 0; for (new Module:i = MODULE_START; i < MAX_MODULES; i++) { if (Modules_IsActive(i)) { if (Modules_IsPrivate(i)) g_sHiddenCount++; else g_sVisibleCount++; } }}/*----------------------------------------------------------------------------*-Function: GetModuleCountParams: -Return: g_sModuleCount.Notes: Not inline as the varibale is static to this file. Returns the number of active modules excluding core.-*----------------------------------------------------------------------------*/stock Modules_GetModuleCount(){ return g_sModuleCount;}/*----------------------------------------------------------------------------*-Function: GetVisibleCountParams: -Return: g_sVisibleCount.Notes: Like GetModuleCount only only returns the number of visible modules.-*----------------------------------------------------------------------------*/stock Modules_GetVisibleCount(){ return g_sVisibleCount;}/*----------------------------------------------------------------------------*-Function: GetHiddenCountParams: -Return: g_sHiddenCount.Notes: Again like GetModuleCount only returns the number of hidden modules.-*----------------------------------------------------------------------------*/stock Modules_GetHiddenCount(){ return g_sHiddenCount;}