From f9c9088303c28acd7823c9eefaf99d94de7c4790 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 19 May 2006 01:54:28 +0000 Subject: [PATCH] added affinity implementation --- dlls/mysqlx/basic_sql.cpp | 32 +++++++++++++++++++++++++++++++- dlls/mysqlx/module.cpp | 18 +++++++++++++++++- dlls/mysqlx/mysql2.vcproj | 3 +++ dlls/mysqlx/mysql2_header.h | 1 + dlls/mysqlx/sdk/amxxmodule.cpp | 6 ++++++ dlls/mysqlx/sdk/amxxmodule.h | 8 ++++++++ dlls/mysqlx/sqlheaders.h | 17 +++++++++++++++++ dlls/mysqlx/threading.cpp | 2 +- 8 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 dlls/mysqlx/sqlheaders.h diff --git a/dlls/mysqlx/basic_sql.cpp b/dlls/mysqlx/basic_sql.cpp index 75d3c483..0c40303d 100644 --- a/dlls/mysqlx/basic_sql.cpp +++ b/dlls/mysqlx/basic_sql.cpp @@ -1,6 +1,7 @@ #include #include "sh_list.h" #include "mysql2_header.h" +#include "sqlheaders.h" using namespace SourceMod; using namespace SourceHook; @@ -314,7 +315,6 @@ static cell AMX_NATIVE_CALL SQL_NumResults(AMX *amx, cell *params) if (!rs) { - MF_LogError(amx, AMX_ERR_NATIVE, "No result set in this query!"); return 0; } @@ -398,6 +398,34 @@ static cell AMX_NATIVE_CALL SQL_FieldNameToNum(AMX *amx, cell *params) return columnId; } +static cell AMX_NATIVE_CALL SQL_GetAffinity(AMX *amx, cell *params) +{ + return MF_SetAmxString(amx, params[1], g_Mysql.NameString(), params[2]); +} + +static cell AMX_NATIVE_CALL SQL_SetAffinity(AMX *amx, cell *params) +{ + int len; + char *str = MF_GetAmxString(amx, params[1], 0, &len); + + if (stricmp(str, g_Mysql.NameString()) == 0) + { + return 1; + } + + SqlFunctions *pFuncs = (SqlFunctions *)MF_RequestFunction(SQL_DRIVER_FUNC); + while (pFuncs) + { + if (pFuncs->driver->IsCompatDriver(str)) + { + return pFuncs->set_affinity(amx); + } + pFuncs = pFuncs->prev; + } + + return 0; +} + extern AMX_NATIVE_INFO g_BaseSqlNatives[] = { {"SQL_MakeDbTuple", SQL_MakeDbTuple}, @@ -415,6 +443,8 @@ extern AMX_NATIVE_INFO g_BaseSqlNatives[] = {"SQL_NumColumns", SQL_NumColumns}, {"SQL_FieldNumToName", SQL_FieldNumToName}, {"SQL_FieldNameToNum", SQL_FieldNameToNum}, + {"SQL_GetAffinity", SQL_GetAffinity}, + {"SQL_SetAffinity", SQL_SetAffinity}, {NULL, NULL}, }; diff --git a/dlls/mysqlx/module.cpp b/dlls/mysqlx/module.cpp index d3147653..d208ab9a 100644 --- a/dlls/mysqlx/module.cpp +++ b/dlls/mysqlx/module.cpp @@ -1,13 +1,29 @@ #include "amxxmodule.h" #include "mysql2_header.h" +#include "sqlheaders.h" static g_ident = 0; +SqlFunctions g_MysqlFuncs = +{ + &g_Mysql, + SetMysqlAffinity, + NULL +}; + +int SetMysqlAffinity(AMX *amx) +{ + MF_AmxReRegister(amx, g_BaseSqlNatives, -1); + MF_AmxReRegister(amx, g_ThreadSqlNatives, -1); + + return 0; +} + void OnAmxxAttach() { MF_AddNatives(g_BaseSqlNatives); MF_AddNatives(g_ThreadSqlNatives); - MF_RegisterFunction(&g_Mysql, "GetSqlDriver"); + g_MysqlFuncs.prev = (SqlFunctions *)MF_RegisterFunctionEx(&g_MysqlFuncs, SQL_DRIVER_FUNC); if (!MF_RequestFunction("GetDbDriver") && !MF_FindLibrary("SQLITE", LibType_Library)) { MF_AddNatives(g_OldCompatNatives); diff --git a/dlls/mysqlx/mysql2.vcproj b/dlls/mysqlx/mysql2.vcproj index fbc0e35d..bbb4a6e8 100644 --- a/dlls/mysqlx/mysql2.vcproj +++ b/dlls/mysqlx/mysql2.vcproj @@ -251,6 +251,9 @@ + + diff --git a/dlls/mysqlx/mysql2_header.h b/dlls/mysqlx/mysql2_header.h index ecc9b67a..f136a2f2 100644 --- a/dlls/mysqlx/mysql2_header.h +++ b/dlls/mysqlx/mysql2_header.h @@ -42,6 +42,7 @@ bool FreeHandle(unsigned int num); void FreeAllHandles(HandleType type); void FreeHandleTable(); void ShutdownThreading(); +int SetMysqlAffinity(AMX *amx); extern AMX_NATIVE_INFO g_BaseSqlNatives[]; extern AMX_NATIVE_INFO g_ThreadSqlNatives[]; diff --git a/dlls/mysqlx/sdk/amxxmodule.cpp b/dlls/mysqlx/sdk/amxxmodule.cpp index 30ef9c79..3492febb 100755 --- a/dlls/mysqlx/sdk/amxxmodule.cpp +++ b/dlls/mysqlx/sdk/amxxmodule.cpp @@ -2513,6 +2513,8 @@ PFN_ADDLIBRARIES g_fn_AddLibraries; PFN_REMOVELIBRARIES g_fn_RemoveLibraries; PFN_OVERRIDENATIVES g_fn_OverrideNatives; PFN_GETLOCALINFO g_fn_GetLocalInfo; +PFN_AMX_REREGISTER g_fn_AmxReRegister; +PFN_REGISTERFUNCTIONEX g_fn_RegisterFunctionEx; // *** Exports *** C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo) @@ -2563,6 +2565,7 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("MergeDefinitionFile", g_fn_MergeDefinition_File, PFN_MERGEDEFINITION_FILE); REQFUNC("Format", g_fn_Format, PFN_FORMAT); REQFUNC("RegisterFunction", g_fn_RegisterFunction, PFN_REGISTERFUNCTION); + REQFUNC("RegisterFunctionEx", g_fn_RegisterFunctionEx, PFN_REGISTERFUNCTIONEX); // Amx scripts REQFUNC("GetAmxScript", g_fn_GetAmxScript, PFN_GET_AMXSCRIPT); @@ -2627,11 +2630,13 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("RegAuthFunc", g_fn_RegAuthFunc, PFN_REG_AUTH_FUNC); REQFUNC("UnregAuthFunc", g_fn_UnregAuthFunc, PFN_UNREG_AUTH_FUNC); + //Added in 1.75 REQFUNC("FindLibrary", g_fn_FindLibrary, PFN_FINDLIBRARY); REQFUNC("AddLibraries", g_fn_AddLibraries, PFN_ADDLIBRARIES); REQFUNC("RemoveLibraries", g_fn_RemoveLibraries, PFN_REMOVELIBRARIES); REQFUNC("OverrideNatives", g_fn_OverrideNatives, PFN_OVERRIDENATIVES); REQFUNC("GetLocalInfo", g_fn_GetLocalInfo, PFN_GETLOCALINFO); + REQFUNC("AmxReregister", g_fn_AmxReRegister, PFN_AMX_REREGISTER); #ifdef MEMORY_TEST // Memory @@ -2766,6 +2771,7 @@ void ValidateMacros_DontCallThis_Smiley() MF_GetPlayerEdict(0); MF_Format("", 4, "str"); MF_RegisterFunction(NULL, ""); + MF_RegisterFunctionEx(NULL, ""); MF_SetPlayerTeamInfo(0, 0, ""); MF_PlayerPropAddr(0, 0); MF_RegAuthFunc(NULL); diff --git a/dlls/mysqlx/sdk/amxxmodule.h b/dlls/mysqlx/sdk/amxxmodule.h index 986e0eb4..e74febf4 100755 --- a/dlls/mysqlx/sdk/amxxmodule.h +++ b/dlls/mysqlx/sdk/amxxmodule.h @@ -2181,6 +2181,8 @@ typedef size_t (*PFN_ADDLIBRARIES) (const char * /*name*/, LibType /*type*/ typedef size_t (*PFN_REMOVELIBRARIES) (void * /*parent*/); typedef void (*PFN_OVERRIDENATIVES) (AMX_NATIVE_INFO * /*natives*/); typedef const char * (*PFN_GETLOCALINFO) (const char * /*name*/, const char * /*def*/); +typedef int (*PFN_AMX_REREGISTER) (AMX * /*amx*/, AMX_NATIVE_INFO * /*list*/, int /*list*/); +typedef void * (*PFN_REGISTERFUNCTIONEX) (void * /*pfn*/, const char * /*desc*/); extern PFN_ADD_NATIVES g_fn_AddNatives; extern PFN_BUILD_PATHNAME g_fn_BuildPathname; @@ -2253,6 +2255,8 @@ extern PFN_ADDLIBRARIES g_fn_AddLibraries; extern PFN_REMOVELIBRARIES g_fn_RemoveLibraries; extern PFN_OVERRIDENATIVES g_fn_OverrideNatives; extern PFN_GETLOCALINFO g_fn_GetLocalInfo; +extern PFN_AMX_REREGISTER g_fn_AmxReRegister; +extern PFN_REGISTERFUNCTIONEX g_fn_RegisterFunctionEx; #ifdef MAY_NEVER_BE_DEFINED // Function prototypes for intellisense and similar systems @@ -2322,6 +2326,8 @@ size_t MF_AddLibraries (const char *name, LibType type, void *parent) { } size_t MF_RemoveLibraries (void *parent) { } void MF_OverrideNatives (AMX_NATIVE_INFO *natives) { } const char * MF_GetLocalInfo (const char *name, const char *def) { } +int MF_AmxReRegister (AMX *amx, AMX_NATIVE_INFO *list, int number) { return 0; } +void * MF_RegisterFunctionEx (void *pfn, const char *description) { } #endif // MAY_NEVER_BE_DEFINED #define MF_AddNatives g_fn_AddNatives @@ -2396,6 +2402,8 @@ void MF_LogError(AMX *amx, int err, const char *fmt, ...); #define MF_RemoveLibraries g_fn_RemoveLibraries #define MF_OverrideNatives g_fn_OverrideNatives #define MF_GetLocalInfo g_fn_GetLocalInfo +#define MF_AmxReRegister g_fn_AmxReRegister +#define MF_RegisterFunctionEx g_fn_RegisterFunctionEx #ifdef MEMORY_TEST /*** Memory ***/ diff --git a/dlls/mysqlx/sqlheaders.h b/dlls/mysqlx/sqlheaders.h new file mode 100644 index 00000000..e756f703 --- /dev/null +++ b/dlls/mysqlx/sqlheaders.h @@ -0,0 +1,17 @@ +#ifndef _INCLUDE_SQLHEADERS_H +#define _INCLUDE_SQLHEADERS_H + +#include "ISQLDriver.h" + +#define SQL_DRIVER_FUNC "GetSqlFuncs" + +typedef int (*SQLAFFINITY)(AMX *amx); + +struct SqlFunctions +{ + SourceMod::ISQLDriver *driver; + SQLAFFINITY set_affinity; + SqlFunctions *prev; +}; + +#endif //_INCLUDE_SQLHEADERS_H diff --git a/dlls/mysqlx/threading.cpp b/dlls/mysqlx/threading.cpp index 2ef4b31a..5ee57d54 100644 --- a/dlls/mysqlx/threading.cpp +++ b/dlls/mysqlx/threading.cpp @@ -284,7 +284,7 @@ void OnPluginsLoaded() void StartFrame() { - if (g_lasttime < gpGlobals->time) + if (g_pWorker && (g_lasttime < gpGlobals->time)) { g_lasttime = gpGlobals->time + 0.3f; g_QueueLock->Lock();