Committed new auto-module registering system
require_module is now DEPRECATED
This commit is contained in:
parent
70396a2fc1
commit
3cba7811bd
|
@ -57,6 +57,7 @@ struct amxx_module_info_s
|
|||
const char *author;
|
||||
const char *version;
|
||||
int reload; // reload on mapchange when nonzero
|
||||
const char *logtag; //added in version 2
|
||||
};
|
||||
|
||||
|
||||
|
@ -65,7 +66,7 @@ struct amxx_module_info_s
|
|||
#define AMXX_PARAM 2 /* Invalid parameter */
|
||||
#define AMXX_FUNC_NOT_PRESENT 3 /* Function not present */
|
||||
|
||||
#define AMXX_INTERFACE_VERSION 1
|
||||
#define AMXX_INTERFACE_VERSION 2
|
||||
|
||||
class CModule
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -4139,3 +4140,26 @@ int AMXAPI amx_UTF8Check(const char *string)
|
|||
return err;
|
||||
}
|
||||
#endif /* AMX_UTF8XXX */
|
||||
|
||||
int AMXAPI amx_GetLibraries(AMX *amx)
|
||||
{
|
||||
AMX_HEADER *hdr = (AMX_HEADER *)amx->base;
|
||||
int numLibraries = NUMENTRIES(hdr, libraries, pubvars);
|
||||
|
||||
return numLibraries;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
#define _snprintf snprintf
|
||||
#endif
|
||||
|
||||
const char *AMXAPI amx_GetLibrary(AMX *amx, int index, char *buffer, int len)
|
||||
{
|
||||
AMX_HEADER *hdr = (AMX_HEADER *)amx->base;
|
||||
AMX_FUNCSTUB *lib;
|
||||
|
||||
lib = GETENTRY(hdr, libraries, index);
|
||||
_snprintf(buffer, len, "%s", GETENTRYNAME(hdr,lib));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
|
|
@ -403,7 +403,10 @@ int AMXAPI amx_StrLen(cell *cstring, int *length);
|
|||
int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value);
|
||||
int AMXAPI amx_UTF8Put(char *string, char **endptr, int maxchars, cell value);
|
||||
int AMXAPI amx_UTF8Check(const char *string);
|
||||
void amx_NullNativeTable(AMX *amx);
|
||||
int AMXAPI amx_GetLibraries(AMX *amx);
|
||||
const char *AMXAPI amx_GetLibrary(AMX *amx, int index, char *buffer, int len);
|
||||
|
||||
//no longer used! void amx_NullNativeTable(AMX *amx);
|
||||
|
||||
#if !defined AMX_NO_ALIGN
|
||||
#if defined __linux__
|
||||
|
|
|
@ -2849,14 +2849,6 @@ static cell AMX_NATIVE_CALL lang_exists(AMX *amx, cell *params)
|
|||
|
||||
cell AMX_NATIVE_CALL require_module(AMX *amx, cell *params)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
String s;
|
||||
|
||||
s.assign(get_amxstring(amx, params[1], 0, len));
|
||||
|
||||
CurModuleList.push(s);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -278,7 +278,6 @@ enum ModuleCallReason
|
|||
extern ModuleCallReason g_ModuleCallReason; // modules.cpp
|
||||
extern CModule *g_CurrentlyCalledModule; // modules.cpp
|
||||
extern const char *g_LastRequestedFunc; // modules.cpp
|
||||
extern CQueue<String> CurModuleList;
|
||||
void Module_CacheFunctions();
|
||||
|
||||
void *Module_ReqFnptr(const char *funcName); // modules.cpp
|
||||
|
|
|
@ -58,7 +58,6 @@ void (*function)(void*);
|
|||
void (*endfunction)(void*);
|
||||
|
||||
CLog g_log;
|
||||
CQueue<String> CurModuleList;
|
||||
CForwardMngr g_forwards;
|
||||
CList<CPlayer*> g_auth;
|
||||
CList<CCVar> g_cvars;
|
||||
|
@ -465,11 +464,6 @@ void C_ServerDeactivate_Post() {
|
|||
g_langMngr.Save(build_pathname_r(file, sizeof(file)-1, "%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
|
||||
g_langMngr.SaveCache(build_pathname_r(file, sizeof(file)-1, "%s/dictionary.cache", get_localinfo("amxx_datadir", "addons/amxmodx/data")));
|
||||
g_langMngr.Clear();
|
||||
//clear module name cache
|
||||
while (!CurModuleList.empty())
|
||||
{
|
||||
CurModuleList.pop();
|
||||
}
|
||||
|
||||
// last memreport
|
||||
#ifdef MEMORY_TEST
|
||||
|
|
|
@ -253,64 +253,64 @@ const char *StrCaseStr(const char *as, const char *bs)
|
|||
return strstr(a,b);
|
||||
}
|
||||
|
||||
//BAILOPAN
|
||||
int CheckModules(AMX *amx, char error[64])
|
||||
//returns 0 for module not found, 1 for "everything's okay"
|
||||
int CheckModules(AMX *amx, char error[128])
|
||||
{
|
||||
int idx = 0, flag = -1;
|
||||
if (amx_FindPublic(amx, "plugin_modules", &idx) == AMX_ERR_NONE)
|
||||
int numLibraries = amx_GetLibraries(amx);
|
||||
char buffer[32];
|
||||
bool found = false;
|
||||
bool isdbi = false;
|
||||
CList<CModule,const char *>::iterator a;
|
||||
const amxx_module_info_s *info;
|
||||
|
||||
for (int i=0; i<numLibraries; i++)
|
||||
{
|
||||
cell retVal = 0;
|
||||
int err = 0;
|
||||
if ( (err = amx_Exec(amx, &retVal, idx, 0)) == AMX_ERR_NONE )
|
||||
amx_GetLibrary(amx, i, buffer, sizeof(buffer)-1);
|
||||
found = false;
|
||||
if (strcmpi(buffer, "float")==0)
|
||||
continue;
|
||||
isdbi = false;
|
||||
if (strcmpi(buffer, "dbi")==0)
|
||||
isdbi = true;
|
||||
for (a=g_modules.begin(); a; ++a)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
while (!CurModuleList.empty())
|
||||
if ( (*a).getStatusValue() == MODULE_LOADED )
|
||||
{
|
||||
if (!flag)
|
||||
info = (*a).getInfoNew();
|
||||
if (info)
|
||||
{
|
||||
CurModuleList.pop();
|
||||
continue;
|
||||
}
|
||||
//assume module is not found
|
||||
flag = 0;
|
||||
for (CList<CModule,const char *>::iterator pMod = g_modules.begin(); pMod; ++pMod)
|
||||
{
|
||||
if (strcmpi(CurModuleList.front().c_str(), "dbi") == 0)
|
||||
if (isdbi)
|
||||
{
|
||||
if (StrCaseStr( (*pMod).getName(), "sql") || strstr( (*pMod).getName(), "dbi" ))
|
||||
if (info->logtag
|
||||
&& (StrCaseStr(info->logtag, "sql")
|
||||
||
|
||||
StrCaseStr(info->logtag, "dbi"))
|
||||
)
|
||||
{
|
||||
// the module checks in
|
||||
flag = 1;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (strcmpi( (*pMod).getName(), CurModuleList.front().c_str() ) == 0)
|
||||
if (info->logtag && (strcmpi(info->logtag, buffer) == 0))
|
||||
{
|
||||
flag = 1;
|
||||
found = true;
|
||||
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;
|
||||
if (!found)
|
||||
{
|
||||
sprintf(error, "Module \"%s\" required for plugin. Check modules.ini.", buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int set_amxnatives(AMX* amx,char error[64])
|
||||
int set_amxnatives(AMX* amx,char error[128])
|
||||
{
|
||||
for ( CList<CModule,const char *>::iterator a = g_modules.begin(); a ; ++a )
|
||||
{
|
||||
|
@ -327,29 +327,17 @@ int set_amxnatives(AMX* amx,char error[64])
|
|||
amx_Register(amx, time_Natives, -1);
|
||||
amx_Register(amx, vault_Natives, -1);
|
||||
|
||||
if ( amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE )
|
||||
if (CheckModules(amx, error))
|
||||
{
|
||||
//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 || *error == 0)
|
||||
if ( amx_Register(amx, core_Natives, -1) != AMX_ERR_NONE )
|
||||
{
|
||||
sprintf(error,"Plugin uses an unknown function (name \"%s\") - check your modules.ini.",save.c_str());
|
||||
sprintf(error, "Plugin uses an unknown function (name \"%s\") - check your modules.ini.", no_function);
|
||||
}
|
||||
return (amx->error = AMX_ERR_NATIVE);
|
||||
|
||||
return AMX_ERR_NONE;
|
||||
}
|
||||
|
||||
CheckModules(amx, error);
|
||||
|
||||
return AMX_ERR_NONE;
|
||||
return (amx->error = AMX_ERR_NATIVE);
|
||||
}
|
||||
|
||||
int unload_amxscript(AMX* amx, void** program)
|
||||
|
|
Loading…
Reference in New Issue
Block a user