New module registering ability

This commit is contained in:
David Anderson 2004-09-09 05:16:53 +00:00
parent 4232d68c92
commit 6c73a7d8d1
5 changed files with 88 additions and 5 deletions

View File

@ -78,7 +78,7 @@ int CPluginMngr::loadPluginsFromFile( const char* filename )
debugFlag = 1; debugFlag = 1;
} }
#endif #endif
CPlugin* plugin = loadPlugin( pluginsDir , pluginName , error, debugFlag); CPlugin* plugin = loadPlugin( pluginsDir , pluginName , error, debugFlag);
if (!plugin) if (!plugin)

View File

@ -2653,6 +2653,19 @@ static cell lang_exists(AMX *amx, cell *params)
return g_langMngr.LangExists(get_amxstring(amx, params[1], 1, len)) ? 1 : 0; return g_langMngr.LangExists(get_amxstring(amx, params[1], 1, len)) ? 1 : 0;
} }
static cell register_module(AMX *amx, cell *params)
{
int len = 0;
String s;
s.assign(get_amxstring(amx, params[1], 0, len));
CurModuleList.push(s);
return 1;
}
AMX_NATIVE_INFO amxmod_Natives[] = { AMX_NATIVE_INFO amxmod_Natives[] = {
{ "client_cmd", client_cmd }, { "client_cmd", client_cmd },
{ "client_print", client_print }, { "client_print", client_print },
@ -2752,6 +2765,7 @@ AMX_NATIVE_INFO amxmod_Natives[] = {
{ "register_logevent",register_logevent}, { "register_logevent",register_logevent},
{ "register_menucmd", register_menucmd }, { "register_menucmd", register_menucmd },
{ "register_menuid", register_menuid }, { "register_menuid", register_menuid },
{ "register_module", register_module },
{ "register_plugin", register_plugin }, { "register_plugin", register_plugin },
{ "register_srvcmd", register_srvcmd }, { "register_srvcmd", register_srvcmd },
{ "remove_cvar_flags", remove_cvar_flags }, { "remove_cvar_flags", remove_cvar_flags },

View File

@ -266,6 +266,7 @@ enum ModuleCallReason
extern ModuleCallReason g_ModuleCallReason; // modules.cpp extern ModuleCallReason g_ModuleCallReason; // modules.cpp
extern CModule *g_CurrentlyCalledModule; // modules.cpp extern CModule *g_CurrentlyCalledModule; // modules.cpp
extern const char *g_LastRequestedFunc; // modules.cpp extern const char *g_LastRequestedFunc; // modules.cpp
extern CQueue<String> CurModuleList;
void *Module_ReqFnptr(const char *funcName); // modules.cpp void *Module_ReqFnptr(const char *funcName); // modules.cpp

View File

@ -57,6 +57,7 @@ void (*function)(void*);
void (*endfunction)(void*); void (*endfunction)(void*);
CLog g_log; CLog g_log;
CQueue<String> CurModuleList;
CForwardMngr g_forwards; CForwardMngr g_forwards;
CList<CPlayer*> g_auth; CList<CPlayer*> g_auth;
CList<CCVar> g_cvars; CList<CCVar> g_cvars;
@ -199,7 +200,6 @@ const char* get_localinfo( const char* name , const char* def )
// Initialize AMX stuff and load it's plugins from plugins.ini list // Initialize AMX stuff and load it's plugins from plugins.ini list
// Call precache forward function from plugins // Call precache forward function from plugins
int C_Spawn( edict_t *pent ) { int C_Spawn( edict_t *pent ) {
g_forcedmodules = false; g_forcedmodules = false;
g_forcedsounds = false; g_forcedsounds = false;
@ -447,7 +447,6 @@ void C_ServerDeactivate_Post() {
g_FakeMeta.m_Plugins.begin()->GetDllFuncTable().pfnSpawn = C_Spawn; g_FakeMeta.m_Plugins.begin()->GetDllFuncTable().pfnSpawn = C_Spawn;
detachReloadModules(); detachReloadModules();
g_auth.clear(); g_auth.clear();
g_forwards.clear(); g_forwards.clear();
g_commands.clear(); g_commands.clear();
@ -465,6 +464,13 @@ void C_ServerDeactivate_Post() {
g_langMngr.Save(build_pathname("%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxmodx/data"))); g_langMngr.Save(build_pathname("%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.SaveCache(build_pathname("%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data"))); g_langMngr.SaveCache(build_pathname("%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
g_langMngr.Clear(); g_langMngr.Clear();
//clear module name cache
while (!CurModuleList.empty())
{
CurModuleList.pop();
}
// last memreport // last memreport
#ifdef MEMORY_TEST #ifdef MEMORY_TEST
if (g_memreport_enabled) if (g_memreport_enabled)

View File

@ -214,6 +214,63 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64
return set_amxnatives(amx,error); return set_amxnatives(amx,error);
} }
//BAILOPAN
int CheckModules(AMX *amx, char error[64])
{
int idx = 0, flag = 1;
if (amx_FindPublic(amx, "plugin_modules", &idx) == AMX_ERR_NONE)
{
cell retVal = 0;
int err = 0;
if ( (err = amx_Exec(amx, &retVal, idx, 0)) == AMX_ERR_NONE )
{
unsigned int i = 0;
while (!CurModuleList.empty())
{
if (!flag)
{
CurModuleList.pop();
continue;
}
//assume module is not found
flag = 0;
for (CList<CModule>::iterator pMod = g_modules.begin(); pMod; ++pMod)
{
if (strcmpi(CurModuleList.front().c_str(), "dbi") == 0)
{
if (strstr( (*pMod).getName(), "sql") || strstr( (*pMod).getName(), "dbi" ))
{
// the module checks in
flag = 1;
break;
}
} else {
if (strcmpi( (*pMod).getName(), CurModuleList.front().c_str() ) == 0)
{
flag = 1;
break;
}
}
}
//module was not found
if (!flag)
{
sprintf(error, "Module \"%s\" required for plugin. Check modules.ini.", CurModuleList.front().c_str());
}
CurModuleList.pop();
}
} else {
AMXXLOG_Log("[AMXX] Run time error %d on line %ld during module check.", err, amx->curline);
//could not execute
return -1; //bad! very bad!
}
} else {
return -1;
}
return flag;
}
int set_amxnatives(AMX* amx,char error[64]) int set_amxnatives(AMX* amx,char error[64])
{ {
for ( CList<CModule>::iterator a = g_modules.begin(); a ; ++a ) for ( CList<CModule>::iterator a = g_modules.begin(); a ; ++a )
@ -233,14 +290,19 @@ int set_amxnatives(AMX* amx,char error[64])
if ( amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE ) if ( amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE )
{ {
sprintf(error,"Function not found (name \"%s\")",no_function); if (CheckModules(amx, error) == -1)
{
//HACKHACK
sprintf(error,"Plugin uses an unknown function (name \"%s\") - check your modules.ini.",no_function);
}
return (amx->error = AMX_ERR_NATIVE); return (amx->error = AMX_ERR_NATIVE);
} }
CheckModules(amx, error);
return AMX_ERR_NONE; return AMX_ERR_NONE;
} }
int unload_amxscript(AMX* amx, void** program) int unload_amxscript(AMX* amx, void** program)
{ {
CList<CScript,AMX*>::iterator a = g_loadedscripts.find( amx ); CList<CScript,AMX*>::iterator a = g_loadedscripts.find( amx );