Added new "amxx plugins" plugin fail message
This commit is contained in:
parent
5867e3398f
commit
3ec4ccd9da
|
@ -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;
|
||||
|
|
|
@ -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<<id)) ? true : false; }
|
||||
|
|
|
@ -1576,7 +1576,6 @@ static AMX_NATIVE findfunction(const char *name, AMX_NATIVE_INFO *list, int numb
|
|||
}
|
||||
|
||||
const char *no_function; // PM: Nice hack ;)
|
||||
int no_module_test;
|
||||
int AMXAPI amx_Register(AMX *amx, AMX_NATIVE_INFO *list, int number)
|
||||
{
|
||||
AMX_FUNCSTUB *func;
|
||||
|
@ -1632,8 +1631,10 @@ void amx_NullNativeTable(AMX *amx)
|
|||
|
||||
for (i=0; i<numnatives; i++)
|
||||
{
|
||||
if (func->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)
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -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<String> CurModuleList;
|
||||
extern int no_module_test;
|
||||
|
||||
void *Module_ReqFnptr(const char *funcName); // modules.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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user