added affinity implementation

This commit is contained in:
David Anderson 2006-05-19 01:54:28 +00:00
parent 9bbb0df492
commit f9c9088303
8 changed files with 84 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#include <stdio.h>
#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},
};

View File

@ -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);

View File

@ -251,6 +251,9 @@
<File
RelativePath=".\sdk\sh_stack.h">
</File>
<File
RelativePath=".\sqlheaders.h">
</File>
</Filter>
</Files>
<Globals>

View File

@ -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[];

View File

@ -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);

View File

@ -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 ***/

17
dlls/mysqlx/sqlheaders.h Normal file
View File

@ -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

View File

@ -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();