From 3ec4ccd9da6404c3dbbc122249fafdbdb8178fcd Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 10 Sep 2004 15:52:48 +0000 Subject: [PATCH] Added new "amxx plugins" plugin fail message --- amxmodx/CPlugin.cpp | 23 ++++++++++++++--------- amxmodx/CPlugin.h | 4 ++++ amxmodx/amx.cpp | 9 ++++----- amxmodx/amxmodx.cpp | 4 ++-- amxmodx/amxmodx.h | 3 +-- amxmodx/meta_api.cpp | 3 --- amxmodx/modules.cpp | 21 +++++++++++++-------- amxmodx/srvcmd.cpp | 12 ++++++++++++ 8 files changed, 50 insertions(+), 29 deletions(-) diff --git a/amxmodx/CPlugin.cpp b/amxmodx/CPlugin.cpp index c587be41..da1ba108 100755 --- a/amxmodx/CPlugin.cpp +++ b/amxmodx/CPlugin.cpp @@ -38,7 +38,7 @@ CPluginMngr::CPlugin* CPluginMngr::loadPlugin(const char* path, const char* name CPlugin** a = &head; while( *a ) a = &(*a)->next; *a = new CPlugin( pCounter++ ,path,name,error, debug); - return *error ? 0 : *a; + return (*a); } void CPluginMngr::unloadPlugin( CPlugin** a ) { @@ -81,8 +81,13 @@ int CPluginMngr::loadPluginsFromFile( const char* filename ) CPlugin* plugin = loadPlugin( pluginsDir , pluginName , error, debugFlag); - if (!plugin) - AMXXLOG_Log("[AMXX] %s (plugin \"%s\")", error, pluginName ); + if (plugin->getStatusCode() == ps_bad_load) + { + char errorMsg[255]; + sprintf(errorMsg, "%s (plugin \"%s\")", error, pluginName); + plugin->setError(errorMsg); + AMXXLOG_Log("[AMXX] %s", plugin->getError()); + } } return pCounter; @@ -97,10 +102,6 @@ void CPluginMngr::clear() { CPluginMngr::CPlugin* CPluginMngr::findPluginFast(AMX *amx) { return (CPlugin*)(amx->userdata[3]); - /*CPlugin*a = head; - while ( a && &a->amx != amx ) - a=a->next; - return a;*/ } CPluginMngr::CPlugin* CPluginMngr::findPlugin(AMX *amx) { @@ -146,8 +147,12 @@ CPluginMngr::CPlugin::CPlugin(int i, const char* p,const char* n, char* e, int d char* path = build_pathname("%s/%s",p,n); code = 0; int err = load_amxscript(&amx,&code,path,e, d); - if ( err == AMX_ERR_NONE ) status = ps_running; - else status = ps_bad_load; + if ( err == AMX_ERR_NONE ) + { + status = ps_running; + } else { + status = ps_bad_load; + } amx.userdata[3] = this; paused_fun = 0; next = 0; diff --git a/amxmodx/CPlugin.h b/amxmodx/CPlugin.h index f061475f..c1eacc4d 100755 --- a/amxmodx/CPlugin.h +++ b/amxmodx/CPlugin.h @@ -63,6 +63,7 @@ public: String version; String title; String author; + String errorMsg; int paused_fun; int status; CPlugin* next; @@ -76,11 +77,14 @@ public: inline const char* getVersion() { return version.c_str();} inline const char* getTitle() { return title.c_str();} inline const char* getAuthor() { return author.c_str();} + inline const char* getError() { return errorMsg.c_str();} + inline int getStatusCode() { return status; } inline int getId() const { return id; } inline AMX* getAMX() { return &amx; } inline void setTitle( const char* n ) { title.assign(n); } inline void setAuthor( const char* n ) { author.assign(n); } inline void setVersion( const char* n ) { version.assign(n); } + inline void setError( const char* n ) { errorMsg.assign(n); } inline bool isValid() const { return ((status != ps_bad_load) && (status != ps_locked)); } inline bool isPaused() const { return ( (status == ps_paused) || (status == ps_stopped)); } inline bool isFunctionPaused( int id ) const { return (paused_fun & (1<address == 0) + if (strcmp(GETENTRYNAME(hdr,func), "require_module")==0) { + func->address = NULL; + } else { func->address = (ucell)null_native; } func=(AMX_FUNCSTUB*)((unsigned char*)func+hdr->defsize); @@ -2833,9 +2834,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index, int numparams, ...) if (amx->callback==NULL) return AMX_ERR_CALLBACK; i=amx_Register(amx,NULL,0); /* verify that all natives are registered */ - //HACKHACK - still execute if doing a module test! - // this WILL cause a crash if bad natives are used.... - if (i!=AMX_ERR_NONE && !no_module_test) + if (i!=AMX_ERR_NONE) return i; if ((amx->flags & AMX_FLAG_RELOC)==0) diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index c86c8898..772d7525 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -2653,7 +2653,7 @@ static cell AMX_NATIVE_CALL lang_exists(AMX *amx, cell *params) return g_langMngr.LangExists(get_amxstring(amx, params[1], 1, len)) ? 1 : 0; } -static cell AMX_NATIVE_CALL register_module(AMX *amx, cell *params) +cell AMX_NATIVE_CALL require_module(AMX *amx, cell *params) { int len = 0; @@ -2765,7 +2765,7 @@ AMX_NATIVE_INFO amxmod_Natives[] = { { "register_logevent",register_logevent}, { "register_menucmd", register_menucmd }, { "register_menuid", register_menuid }, - { "require_module", register_module }, + { "require_module", require_module }, { "register_plugin", register_plugin }, { "register_srvcmd", register_srvcmd }, { "remove_cvar_flags", remove_cvar_flags }, diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index b222b2d3..8fab409e 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -254,7 +254,7 @@ void* alloc_amxmemory(void**, int size); void free_amxmemory(void **ptr); // get_localinfo const char* get_localinfo( const char* name , const char* def ); -static cell AMX_NATIVE_CALL null_native(AMX *amx, cell *params); +cell AMX_NATIVE_CALL require_module(AMX *amx, cell *params); enum ModuleCallReason { @@ -268,7 +268,6 @@ extern ModuleCallReason g_ModuleCallReason; // modules.cpp extern CModule *g_CurrentlyCalledModule; // modules.cpp extern const char *g_LastRequestedFunc; // modules.cpp extern CQueue CurModuleList; -extern int no_module_test; void *Module_ReqFnptr(const char *funcName); // modules.cpp diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 4f138e55..55b9a413 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -266,9 +266,7 @@ int C_Spawn( edict_t *pent ) { memset(g_players[0].flags,-1,sizeof(g_players[0].flags)); // ###### Load AMX scripts - no_module_test = 0; g_plugins.loadPluginsFromFile( get_localinfo("amxx_plugins", "addons/amxmodx/configs/plugins.ini") ); - no_module_test = 0; // Register forwards FF_PluginInit = registerForward("plugin_init", ET_IGNORE, FP_DONE); @@ -448,7 +446,6 @@ void C_ServerDeactivate_Post() { // pft that's not really a hack g_FakeMeta.m_Plugins.begin()->GetDllFuncTable().pfnSpawn = C_Spawn; - no_module_test = 0; detachReloadModules(); g_auth.clear(); g_forwards.clear(); diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index a77989dc..eb2d3b51 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -217,12 +217,11 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 //BAILOPAN int CheckModules(AMX *amx, char error[64]) { - int idx = 0, flag = 1; + int idx = 0, flag = -1; if (amx_FindPublic(amx, "plugin_modules", &idx) == AMX_ERR_NONE) { cell retVal = 0; int err = 0; - no_module_test = 1; if ( (err = amx_Exec(amx, &retVal, idx, 0)) == AMX_ERR_NONE ) { unsigned int i = 0; @@ -262,11 +261,9 @@ int CheckModules(AMX *amx, char error[64]) } } else { AMXXLOG_Log("[AMXX] Run time error %d on line %ld during module check.", err, amx->curline); - no_module_test = 0; //could not execute return -1; //bad! very bad! } - no_module_test = 0; } else { return -1; } @@ -293,12 +290,20 @@ int set_amxnatives(AMX* amx,char error[64]) if ( amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE ) { + //HACKHACK - if we get here, nullify the plugin's native table + //then reregister the one native we need + // - BAILOPAN + String save; + save.assign(no_function); + amx_NullNativeTable(amx); + AMX_NATIVE_INFO p[] = { + { "require_module", require_module }, + { NULL, NULL }, + }; + amx_Register(amx, p, -1); if (CheckModules(amx, error) == -1) { - //HACKHACK - if we get here, nullify the plugin's native table - // - BAILOPAN - amx_NullNativeTable(amx); - sprintf(error,"Plugin uses an unknown function (name \"%s\") - check your modules.ini.",no_function); + sprintf(error,"Plugin uses an unknown function (name \"%s\") - check your modules.ini.",save.c_str()); } return (amx->error = AMX_ERR_NATIVE); } diff --git a/amxmodx/srvcmd.cpp b/amxmodx/srvcmd.cpp index 28df23bc..28d9cdef 100755 --- a/amxmodx/srvcmd.cpp +++ b/amxmodx/srvcmd.cpp @@ -62,6 +62,18 @@ void amx_command(){ ++a; } + a = g_plugins.begin(); + + while (a) + { + if ( (*a).getStatusCode() == ps_bad_load ) + { + //error + print_srvconsole("Load fails: %s\n", (*a).getError()); + } + ++a; + } + print_srvconsole( "%d plugins, %d running\n",plugins,running ); }