Rewrite. Note: untested

This commit is contained in:
David Anderson 2004-05-28 06:28:49 +00:00
parent 997a79a692
commit 8afd62a7c9
12 changed files with 5799 additions and 595 deletions

View File

@ -1,274 +0,0 @@
/* AMX Mod X
* Admin Base for PgSQL Plugin
*
* by the David "BAILOPAN" Anderson
*
* This file for AMX Mod X.
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* In addition, as a special exception, the author gives permission to
* link the code of this program with the Half-Life Game Engine ("HL
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
* L.L.C ("Valve"). You must obey the GNU General Public License in all
* respects for all of the code used other than the HL Engine and MODs
* from Valve. If you modify this file, you may extend this exception
* to your version of the file, but you are not obligated to do so. If
* you do not wish to do so, delete this exception statement from your
* version.
*/
#include <amxmodx>
#include <amxmisc>
#include <pgsql>
#define MAX_ADMINS 64
new g_aPassword[MAX_ADMINS][32]
new g_aName[MAX_ADMINS][32]
new g_aFlags[MAX_ADMINS]
new g_aAccess[MAX_ADMINS]
new g_aNum = 0
#if !defined NO_STEAM
new g_cmdLoopback[16]
#endif
public plugin_init()
{
register_plugin("Admin Base for PgSQL","0.16","BAILOPAN")
register_cvar("amx_mode","2.0")
register_cvar("amx_password_field","_pw")
register_cvar("amx_default_access","")
register_srvcmd("amx_sqladmins","adminSql")
register_cvar("amx_pgsql_host","127.0.0.1")
register_cvar("amx_pgsql_user","root")
register_cvar("amx_pgsql_pass","")
register_cvar("amx_pgsql_db","amx")
register_cvar("amx_vote_ratio","0.02")
register_cvar("amx_votekick_ratio","0.40")
register_cvar("amx_voteban_ratio","0.40")
register_cvar("amx_votemap_ratio","0.40")
register_cvar("amx_vote_time","10")
register_cvar("amx_vote_answers","1")
register_cvar("amx_vote_delay","60")
register_cvar("amx_last_voting","0")
register_cvar("amx_show_activity","2")
set_cvar_float("amx_last_voting",0.0)
register_concmd("amx_reloadadmins","cmdReload",ADMIN_ADMIN)
#if !defined NO_STEAM
format( g_cmdLoopback, 15, "amxauth%c%c%c%c" ,
random_num('A','Z') , random_num('A','Z') ,random_num('A','Z'),random_num('A','Z') )
register_clcmd( g_cmdLoopback, "ackSignal" )
#endif
remove_user_flags(0,read_flags("z")) // remove 'user' flag from server rights
new configsDir[128]
get_configsdir(configsDir, 127)
server_cmd("exec %s/amxx.cfg", configsDir) // Execute main configuration file
server_cmd("exec %s/pgsql.cfg;amx_sqladmins", configsDir)
}
public adminSql() {
new host[64],user[32],pass[32],db[32],error[128]
get_cvar_string("amx_pgsql_host",host,63)
get_cvar_string("amx_pgsql_user",user,31)
get_cvar_string("amx_pgsql_pass",pass,31)
get_cvar_string("amx_pgsql_db",db,31)
new pgsql = pgsql_connect(host,user,pass,db)
if(pgsql < 1){
pgsql_error(pgsql, error, 128)
server_print("[AMXX] PgSQL error: can't connect: '%s'",error)
return PLUGIN_HANDLED
}
pgsql_query(pgsql,"CREATE TABLE IF NOT EXISTS admins ( auth varchar(32) NOT NULL default '', password varchar(32) NOT NULL default '', access varchar(32) NOT NULL default '', flags varchar(32) NOT NULL default '' ) TYPE=MyISAM")
if(pgsql_query(pgsql,"SELECT auth,password,access,flags FROM admins") < 1) {
pgsql_error(pgsql,error,127)
server_print("[AMXX] PgSQL error: can't load admins: '%s'",error)
return PLUGIN_HANDLED
}
new szFlags[32],szAccess[32],iAccess
while( pgsql_nextrow(pgsql) > 0 )
{
pgsql_getfield(pgsql, 1, g_aName[ g_aNum ] ,31)
pgsql_getfield(pgsql, 2, g_aPassword[ g_aNum ] ,31)
pgsql_getfield(pgsql, 3, szAccess,31)
pgsql_getfield(pgsql, 4, szFlags,31)
iAccess = read_flags(szAccess)
if (!(iAccess & ADMIN_USER) && !(iAccess & ADMIN_ADMIN)) {
iAccess |= ADMIN_ADMIN
}
g_aAccess[ g_aNum ] = iAccess
g_aFlags[ g_aNum ] = read_flags( szFlags )
++g_aNum
}
server_print("[AMXX] Loaded %d admin%s from database",g_aNum, (g_aNum == 1) ? "" : "s" )
pgsql_close(pgsql)
return PLUGIN_HANDLED
}
public cmdReload(id,level,cid)
{
if (!cmd_access(id,level,cid,1))
return PLUGIN_HANDLED
g_aNum = 0
adminSql() // Re-Load admins accounts
return PLUGIN_HANDLED
}
getAccess(id,name[],authid[],ip[], password[]){
new index = -1
new result = 0
for(new i = 0; i < g_aNum; ++i) {
if (g_aFlags[i] & FLAG_AUTHID) {
if (equal(authid,g_aName[i])) {
index = i
break
}
}
else if (g_aFlags[i] & FLAG_IP) {
new c = strlen( g_aName[i] )
if ( g_aName[i][ c - 1 ] == '.' ) { /* check if this is not a xxx.xxx. format */
if ( equal( g_aName[i] , ip , c ) ) {
index = i
break
}
} /* in other case an IP must just match */
else if ( equal(ip,g_aName[i]) ){
index = i
break
}
}
else {
if (g_aFlags[i] & FLAG_TAG) {
if (contain(name,g_aName[i])!=-1){
index = i
break
}
}
else if (equal(name,g_aName[i])) {
index = i
break
}
}
}
if (index != -1) {
if (g_aFlags[index] & FLAG_NOPASS){
result |= 8
new sflags[32]
get_flags(g_aAccess[index],sflags,31)
set_user_flags(id,g_aAccess[index])
log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")",
name,get_user_userid(id),authid,g_aName[index] ,sflags,ip)
}
else if (equal(password,g_aPassword[index])) {
result |= 12
set_user_flags(id,g_aAccess[index])
new sflags[32]
get_flags(g_aAccess[index],sflags,31)
log_amx("Login: ^"%s<%d><%s><>^" became an admin (account ^"%s^") (access ^"%s^") (address ^"%s^")",
name,get_user_userid(id),authid,g_aName[index] ,sflags,ip)
}
else {
result |= 1
if (g_aFlags[index] & FLAG_KICK){
result |= 2
log_amx("Login: ^"%s<%d><%s><>^" kicked due to invalid password (account ^"%s^") (address ^"%s^")",
name,get_user_userid(id),authid,g_aName[index],ip)
}
}
}
else if (get_cvar_float("amx_mode")==2.0) {
result |= 2
}
else {
new defaccess[32]
get_cvar_string("amx_default_access",defaccess,31)
if (!defaccess[0])
defaccess[0] = 'z'
new idefaccess = read_flags(defaccess)
if (idefaccess){
result |= 8
set_user_flags(id,idefaccess)
}
}
return result
}
accessUser( id, name[]="" )
{
remove_user_flags(id)
new userip[32],userauthid[32],password[32],passfield[32],username[32]
get_user_ip(id,userip,31,1)
get_user_authid(id,userauthid,31)
if ( name[0] ) copy( username , 31, name)
else get_user_name(id,username,31 )
get_cvar_string("amx_password_field",passfield,31)
get_user_info(id,passfield,password,31)
new result = getAccess(id,username,userauthid,userip,password)
if (result & 1) client_cmd(id,"echo ^"* Invalid Password!^"")
if (result & 2) {
#if !defined NO_STEAM
client_cmd(id,g_cmdLoopback)
#else
client_cmd(id,"echo ^"* You have no entry to the server...^";disconnect")
#endif
return PLUGIN_HANDLED
}
if (result & 4) client_cmd(id,"echo ^"* Password accepted^"")
if (result & 8) client_cmd(id,"echo ^"* Privileges set^"")
return PLUGIN_CONTINUE
}
public client_infochanged(id)
{
if ( !is_user_connected(id) || !get_cvar_num("amx_mode") )
return PLUGIN_CONTINUE
new newname[32], oldname[32]
get_user_name(id,oldname,31)
get_user_info(id,"name",newname,31)
if ( !equal(newname,oldname) )
accessUser( id , newname )
return PLUGIN_CONTINUE
}
#if !defined NO_STEAM
public ackSignal(id)
server_cmd("kick #%d ^"You have no entry to the server...^"", get_user_userid(id) )
public client_authorized(id)
#else
public client_connect(id)
#endif
return get_cvar_num( "amx_mode" ) ? accessUser( id ) : PLUGIN_CONTINUE

2990
dlls/pgsql/amxxmodule.cpp Executable file

File diff suppressed because it is too large Load Diff

2152
dlls/pgsql/amxxmodule.h Executable file

File diff suppressed because it is too large Load Diff

Binary file not shown.

462
dlls/pgsql/moduleconfig.h Executable file
View File

@ -0,0 +1,462 @@
// Configuration
#ifndef __MODULECONFIG_H__
#define __MODULECONFIG_H__
// Module info
#define MODULE_NAME "PgSQL"
#define MODULE_VERSION "1.1"
#define MODULE_AUTHOR "BAILOPAN"
#define MODULE_URL "http://www.bailopan.com/"
#define MODULE_LOGTAG "PGSQL"
// If you want the module not to be reloaded on mapchange, remove / comment out the next line
#define MODULE_RELOAD_ON_MAPCHANGE
#ifdef __DATE__
#define MODULE_DATE __DATE__
#else // __DATE__
#define MODULE_DATE "Unknown"
#endif // __DATE__
// metamod plugin?
// #define USE_METAMOD
// - AMXX Init functions
// Also consider using FN_META_*
// AMXX query
//#define FN_AMXX_QUERY OnAmxxQuery
// AMXX attach
// Do native functions init here (MF_AddNatives)
#define FN_AMXX_ATTACH OnAmxxAttach
// AMXX dettach
//#define FN_AMXX_DETTACH OnAmxxDetach
// All plugins loaded
// Do forward functions init here (MF_RegisterForward)
// #define FN_AMXX_PLUGINSLOADED OnPluginsLoaded
/**** METAMOD ****/
// If your module doesn't use metamod, you may close the file now :)
#ifdef USE_METAMOD
// ----
// Hook Functions
// Uncomment these to be called
// You can also change the function name
// - Metamod init functions
// Also consider using FN_AMXX_*
// Meta query
//#define FN_META_QUERY OnMetaQuery
// Meta attach
//#define FN_META_ATTACH OnMetaAttach
// Meta dettach
//#define FN_META_DETTACH OnMetaDettach
// (wd) are Will Day's notes
// - GetEntityAPI2 functions
// #define FN_GameDLLInit GameDLLInit /* pfnGameInit() */
// #define FN_DispatchSpawn DispatchSpawn /* pfnSpawn() */
// #define FN_DispatchThink DispatchThink /* pfnThink() */
// #define FN_DispatchUse DispatchUse /* pfnUse() */
// #define FN_DispatchTouch DispatchTouch /* pfnTouch() */
// #define FN_DispatchBlocked DispatchBlocked /* pfnBlocked() */
// #define FN_DispatchKeyValue DispatchKeyValue /* pfnKeyValue() */
// #define FN_DispatchSave DispatchSave /* pfnSave() */
// #define FN_DispatchRestore DispatchRestore /* pfnRestore() */
// #define FN_DispatchObjectCollsionBox DispatchObjectCollsionBox /* pfnSetAbsBox() */
// #define FN_SaveWriteFields SaveWriteFields /* pfnSaveWriteFields() */
// #define FN_SaveReadFields SaveReadFields /* pfnSaveReadFields() */
// #define FN_SaveGlobalState SaveGlobalState /* pfnSaveGlobalState() */
// #define FN_RestoreGlobalState RestoreGlobalState /* pfnRestoreGlobalState() */
// #define FN_ResetGlobalState ResetGlobalState /* pfnResetGlobalState() */
// #define FN_ClientConnect ClientConnect /* pfnClientConnect() (wd) Client has connected */
// #define FN_ClientDisconnect ClientDisconnect /* pfnClientDisconnect() (wd) Player has left the game */
// #define FN_ClientKill ClientKill /* pfnClientKill() (wd) Player has typed "kill" */
// #define FN_ClientPutInServer ClientPutInServer /* pfnClientPutInServer() (wd) Client is entering the game */
// #define FN_ClientCommand ClientCommand /* pfnClientCommand() (wd) Player has sent a command (typed or from a bind) */
// #define FN_ClientUserInfoChanged ClientUserInfoChanged /* pfnClientUserInfoChanged() (wd) Client has updated their setinfo structure */
// #define FN_ServerActivate ServerActivate /* pfnServerActivate() (wd) Server is starting a new map */
// #define FN_ServerDeactivate ServerDeactivate /* pfnServerDeactivate() (wd) Server is leaving the map (shutdown or changelevel); SDK2 */
// #define FN_PlayerPreThink PlayerPreThink /* pfnPlayerPreThink() */
// #define FN_PlayerPostThink PlayerPostThink /* pfnPlayerPostThink() */
// #define FN_StartFrame StartFrame /* pfnStartFrame() */
// #define FN_ParmsNewLevel ParmsNewLevel /* pfnParmsNewLevel() */
// #define FN_ParmsChangeLevel ParmsChangeLevel /* pfnParmsChangeLevel() */
// #define FN_GetGameDescription GetGameDescription /* pfnGetGameDescription() Returns string describing current .dll. E.g. "TeamFotrress 2" "Half-Life" */
// #define FN_PlayerCustomization PlayerCustomization /* pfnPlayerCustomization() Notifies .dll of new customization for player. */
// #define FN_SpectatorConnect SpectatorConnect /* pfnSpectatorConnect() Called when spectator joins server */
// #define FN_SpectatorDisconnect SpectatorDisconnect /* pfnSpectatorDisconnect() Called when spectator leaves the server */
// #define FN_SpectatorThink SpectatorThink /* pfnSpectatorThink() Called when spectator sends a command packet (usercmd_t) */
// #define FN_Sys_Error Sys_Error /* pfnSys_Error() Notify game .dll that engine is going to shut down. Allows mod authors to set a breakpoint. SDK2 */
// #define FN_PM_Move PM_Move /* pfnPM_Move() (wd) SDK2 */
// #define FN_PM_Init PM_Init /* pfnPM_Init() Server version of player movement initialization; (wd) SDK2 */
// #define FN_PM_FindTextureType PM_FindTextureType /* pfnPM_FindTextureType() (wd) SDK2 */
// #define FN_SetupVisibility SetupVisibility /* pfnSetupVisibility() Set up PVS and PAS for networking for this client; (wd) SDK2 */
// #define FN_UpdateClientData UpdateClientData /* pfnUpdateClientData() Set up data sent only to specific client; (wd) SDK2 */
// #define FN_AddToFullPack AddToFullPack /* pfnAddToFullPack() (wd) SDK2 */
// #define FN_CreateBaseline CreateBaseline /* pfnCreateBaseline() Tweak entity baseline for network encoding allows setup of player baselines too.; (wd) SDK2 */
// #define FN_RegisterEncoders RegisterEncoders /* pfnRegisterEncoders() Callbacks for network encoding; (wd) SDK2 */
// #define FN_GetWeaponData GetWeaponData /* pfnGetWeaponData() (wd) SDK2 */
// #define FN_CmdStart CmdStart /* pfnCmdStart() (wd) SDK2 */
// #define FN_CmdEnd CmdEnd /* pfnCmdEnd() (wd) SDK2 */
// #define FN_ConnectionlessPacket ConnectionlessPacket /* pfnConnectionlessPacket() (wd) SDK2 */
// #define FN_GetHullBounds GetHullBounds /* pfnGetHullBounds() (wd) SDK2 */
// #define FN_CreateInstancedBaselines CreateInstancedBaselines /* pfnCreateInstancedBaselines() (wd) SDK2 */
// #define FN_InconsistentFile InconsistentFile /* pfnInconsistentFile() (wd) SDK2 */
// #define FN_AllowLagCompensation AllowLagCompensation /* pfnAllowLagCompensation() (wd) SDK2 */
// - GetEntityAPI2_Post functions
// #define FN_GameDLLInit_Post GameDLLInit_Post
// #define FN_DispatchSpawn_Post DispatchSpawn_Post
// #define FN_DispatchThink_Post DispatchThink_Post
// #define FN_DispatchUse_Post DispatchUse_Post
// #define FN_DispatchTouch_Post DispatchTouch_Post
// #define FN_DispatchBlocked_Post DispatchBlocked_Post
// #define FN_DispatchKeyValue_Post DispatchKeyValue_Post
// #define FN_DispatchSave_Post DispatchSave_Post
// #define FN_DispatchRestore_Post DispatchRestore_Post
// #define FN_DispatchObjectCollsionBox_Post DispatchObjectCollsionBox_Post
// #define FN_SaveWriteFields_Post SaveWriteFields_Post
// #define FN_SaveReadFields_Post SaveReadFields_Post
// #define FN_SaveGlobalState_Post SaveGlobalState_Post
// #define FN_RestoreGlobalState_Post RestoreGlobalState_Post
// #define FN_ResetGlobalState_Post ResetGlobalState_Post
// #define FN_ClientConnect_Post ClientConnect_Post
// #define FN_ClientDisconnect_Post ClientDisconnect_Post
// #define FN_ClientKill_Post ClientKill_Post
// #define FN_ClientPutInServer_Post ClientPutInServer_Post
// #define FN_ClientCommand_Post ClientCommand_Post
// #define FN_ClientUserInfoChanged_Post ClientUserInfoChanged_Post
// #define FN_ServerActivate_Post ServerActivate_Post
// #define FN_ServerDeactivate_Post ServerDeactivate_Post
// #define FN_PlayerPreThink_Post PlayerPreThink_Post
// #define FN_PlayerPostThink_Post PlayerPostThink_Post
// #define FN_StartFrame_Post StartFrame_Post
// #define FN_ParmsNewLevel_Post ParmsNewLevel_Post
// #define FN_ParmsChangeLevel_Post ParmsChangeLevel_Post
// #define FN_GetGameDescription_Post GetGameDescription_Post
// #define FN_PlayerCustomization_Post PlayerCustomization_Post
// #define FN_SpectatorConnect_Post SpectatorConnect_Post
// #define FN_SpectatorDisconnect_Post SpectatorDisconnect_Post
// #define FN_SpectatorThink_Post SpectatorThink_Post
// #define FN_Sys_Error_Post Sys_Error_Post
// #define FN_PM_Move_Post PM_Move_Post
// #define FN_PM_Init_Post PM_Init_Post
// #define FN_PM_FindTextureType_Post PM_FindTextureType_Post
// #define FN_SetupVisibility_Post SetupVisibility_Post
// #define FN_UpdateClientData_Post UpdateClientData_Post
// #define FN_AddToFullPack_Post AddToFullPack_Post
// #define FN_CreateBaseline_Post CreateBaseline_Post
// #define FN_RegisterEncoders_Post RegisterEncoders_Post
// #define FN_GetWeaponData_Post GetWeaponData_Post
// #define FN_CmdStart_Post CmdStart_Post
// #define FN_CmdEnd_Post CmdEnd_Post
// #define FN_ConnectionlessPacket_Post ConnectionlessPacket_Post
// #define FN_GetHullBounds_Post GetHullBounds_Post
// #define FN_CreateInstancedBaselines_Post CreateInstancedBaselines_Post
// #define FN_InconsistentFile_Post InconsistentFile_Post
// #define FN_AllowLagCompensation_Post AllowLagCompensation_Post
// - GetEngineAPI functions
// #define FN_PrecacheModel PrecacheModel
// #define FN_PrecacheSound PrecacheSound
// #define FN_SetModel SetModel
// #define FN_ModelIndex ModelIndex
// #define FN_ModelFrames ModelFrames
// #define FN_SetSize SetSize
// #define FN_ChangeLevel ChangeLevel
// #define FN_GetSpawnParms GetSpawnParms
// #define FN_SaveSpawnParms SaveSpawnParms
// #define FN_VecToYaw VecToYaw
// #define FN_VecToAngles VecToAngles
// #define FN_MoveToOrigin MoveToOrigin
// #define FN_ChangeYaw ChangeYaw
// #define FN_ChangePitch ChangePitch
// #define FN_FindEntityByString FindEntityByString
// #define FN_GetEntityIllum GetEntityIllum
// #define FN_FindEntityInSphere FindEntityInSphere
// #define FN_FindClientInPVS FindClientInPVS
// #define FN_EntitiesInPVS EntitiesInPVS
// #define FN_MakeVectors MakeVectors
// #define FN_AngleVectors AngleVectors
// #define FN_CreateEntity CreateEntity
// #define FN_RemoveEntity RemoveEntity
// #define FN_CreateNamedEntity CreateNamedEntity
// #define FN_MakeStatic MakeStatic
// #define FN_EntIsOnFloor EntIsOnFloor
// #define FN_DropToFloor DropToFloor
// #define FN_WalkMove WalkMove
// #define FN_SetOrigin SetOrigin
// #define FN_EmitSound EmitSound
// #define FN_EmitAmbientSound EmitAmbientSound
// #define FN_TraceLine TraceLine
// #define FN_TraceToss TraceToss
// #define FN_TraceMonsterHull TraceMonsterHull
// #define FN_TraceHull TraceHull
// #define FN_TraceModel TraceModel
// #define FN_TraceTexture TraceTexture
// #define FN_TraceSphere TraceSphere
// #define FN_GetAimVector GetAimVector
// #define FN_ServerCommand ServerCommand
// #define FN_ServerExecute ServerExecute
// #define FN_engClientCommand engClientCommand
// #define FN_ParticleEffect ParticleEffect
// #define FN_LightStyle LightStyle
// #define FN_DecalIndex DecalIndex
// #define FN_PointContents PointContents
// #define FN_MessageBegin MessageBegin
// #define FN_MessageEnd MessageEnd
// #define FN_WriteByte WriteByte
// #define FN_WriteChar WriteChar
// #define FN_WriteShort WriteShort
// #define FN_WriteLong WriteLong
// #define FN_WriteAngle WriteAngle
// #define FN_WriteCoord WriteCoord
// #define FN_WriteString WriteString
// #define FN_WriteEntity WriteEntity
// #define FN_CVarRegister CVarRegister
// #define FN_CVarGetFloat CVarGetFloat
// #define FN_CVarGetString CVarGetString
// #define FN_CVarSetFloat CVarSetFloat
// #define FN_CVarSetString CVarSetString
// #define FN_AlertMessage AlertMessage
// #define FN_EngineFprintf EngineFprintf
// #define FN_PvAllocEntPrivateData PvAllocEntPrivateData
// #define FN_PvEntPrivateData PvEntPrivateData
// #define FN_FreeEntPrivateData FreeEntPrivateData
// #define FN_SzFromIndex SzFromIndex
// #define FN_AllocString AllocString
// #define FN_GetVarsOfEnt GetVarsOfEnt
// #define FN_PEntityOfEntOffset PEntityOfEntOffset
// #define FN_EntOffsetOfPEntity EntOffsetOfPEntity
// #define FN_IndexOfEdict IndexOfEdict
// #define FN_PEntityOfEntIndex PEntityOfEntIndex
// #define FN_FindEntityByVars FindEntityByVars
// #define FN_GetModelPtr GetModelPtr
// #define FN_RegUserMsg RegUserMsg
// #define FN_AnimationAutomove AnimationAutomove
// #define FN_GetBonePosition GetBonePosition
// #define FN_FunctionFromName FunctionFromName
// #define FN_NameForFunction NameForFunction
// #define FN_ClientPrintf ClientPrintf
// #define FN_ServerPrint ServerPrint
// #define FN_Cmd_Args Cmd_Args
// #define FN_Cmd_Argv Cmd_Argv
// #define FN_Cmd_Argc Cmd_Argc
// #define FN_GetAttachment GetAttachment
// #define FN_CRC32_Init CRC32_Init
// #define FN_CRC32_ProcessBuffer CRC32_ProcessBuffer
// #define FN_CRC32_ProcessByte CRC32_ProcessByte
// #define FN_CRC32_Final CRC32_Final
// #define FN_RandomLong RandomLong
// #define FN_RandomFloat RandomFloat
// #define FN_SetView SetView
// #define FN_Time Time
// #define FN_CrosshairAngle CrosshairAngle
// #define FN_LoadFileForMe LoadFileForMe
// #define FN_FreeFile FreeFile
// #define FN_EndSection EndSection
// #define FN_CompareFileTime CompareFileTime
// #define FN_GetGameDir GetGameDir
// #define FN_Cvar_RegisterVariable Cvar_RegisterVariable
// #define FN_FadeClientVolume FadeClientVolume
// #define FN_SetClientMaxspeed SetClientMaxspeed
// #define FN_CreateFakeClient CreateFakeClient
// #define FN_RunPlayerMove RunPlayerMove
// #define FN_NumberOfEntities NumberOfEntities
// #define FN_GetInfoKeyBuffer GetInfoKeyBuffer
// #define FN_InfoKeyValue InfoKeyValue
// #define FN_SetKeyValue SetKeyValue
// #define FN_SetClientKeyValue SetClientKeyValue
// #define FN_IsMapValid IsMapValid
// #define FN_StaticDecal StaticDecal
// #define FN_PrecacheGeneric PrecacheGeneric
// #define FN_GetPlayerUserId GetPlayerUserId
// #define FN_BuildSoundMsg BuildSoundMsg
// #define FN_IsDedicatedServer IsDedicatedServer
// #define FN_CVarGetPointer CVarGetPointer
// #define FN_GetPlayerWONId GetPlayerWONId
// #define FN_Info_RemoveKey Info_RemoveKey
// #define FN_GetPhysicsKeyValue GetPhysicsKeyValue
// #define FN_SetPhysicsKeyValue SetPhysicsKeyValue
// #define FN_GetPhysicsInfoString GetPhysicsInfoString
// #define FN_PrecacheEvent PrecacheEvent
// #define FN_PlaybackEvent PlaybackEvent
// #define FN_SetFatPVS SetFatPVS
// #define FN_SetFatPAS SetFatPAS
// #define FN_CheckVisibility CheckVisibility
// #define FN_DeltaSetField DeltaSetField
// #define FN_DeltaUnsetField DeltaUnsetField
// #define FN_DeltaAddEncoder DeltaAddEncoder
// #define FN_GetCurrentPlayer GetCurrentPlayer
// #define FN_CanSkipPlayer CanSkipPlayer
// #define FN_DeltaFindField DeltaFindField
// #define FN_DeltaSetFieldByIndex DeltaSetFieldByIndex
// #define FN_DeltaUnsetFieldByIndex DeltaUnsetFieldByIndex
// #define FN_SetGroupMask SetGroupMask
// #define FN_engCreateInstancedBaseline engCreateInstancedBaseline
// #define FN_Cvar_DirectSet Cvar_DirectSet
// #define FN_ForceUnmodified ForceUnmodified
// #define FN_GetPlayerStats GetPlayerStats
// #define FN_AddServerCommand AddServerCommand
// #define FN_Voice_GetClientListening Voice_GetClientListening
// #define FN_Voice_SetClientListening Voice_SetClientListening
// #define FN_GetPlayerAuthId GetPlayerAuthId
// - GetEngineAPI_Post functions
// #define FN_PrecacheModel_Post PrecacheModel_Post
// #define FN_PrecacheSound_Post PrecacheSound_Post
// #define FN_SetModel_Post SetModel_Post
// #define FN_ModelIndex_Post ModelIndex_Post
// #define FN_ModelFrames_Post ModelFrames_Post
// #define FN_SetSize_Post SetSize_Post
// #define FN_ChangeLevel_Post ChangeLevel_Post
// #define FN_GetSpawnParms_Post GetSpawnParms_Post
// #define FN_SaveSpawnParms_Post SaveSpawnParms_Post
// #define FN_VecToYaw_Post VecToYaw_Post
// #define FN_VecToAngles_Post VecToAngles_Post
// #define FN_MoveToOrigin_Post MoveToOrigin_Post
// #define FN_ChangeYaw_Post ChangeYaw_Post
// #define FN_ChangePitch_Post ChangePitch_Post
// #define FN_FindEntityByString_Post FindEntityByString_Post
// #define FN_GetEntityIllum_Post GetEntityIllum_Post
// #define FN_FindEntityInSphere_Post FindEntityInSphere_Post
// #define FN_FindClientInPVS_Post FindClientInPVS_Post
// #define FN_EntitiesInPVS_Post EntitiesInPVS_Post
// #define FN_MakeVectors_Post MakeVectors_Post
// #define FN_AngleVectors_Post AngleVectors_Post
// #define FN_CreateEntity_Post CreateEntity_Post
// #define FN_RemoveEntity_Post RemoveEntity_Post
// #define FN_CreateNamedEntity_Post CreateNamedEntity_Post
// #define FN_MakeStatic_Post MakeStatic_Post
// #define FN_EntIsOnFloor_Post EntIsOnFloor_Post
// #define FN_DropToFloor_Post DropToFloor_Post
// #define FN_WalkMove_Post WalkMove_Post
// #define FN_SetOrigin_Post SetOrigin_Post
// #define FN_EmitSound_Post EmitSound_Post
// #define FN_EmitAmbientSound_Post EmitAmbientSound_Post
// #define FN_TraceLine_Post TraceLine_Post
// #define FN_TraceToss_Post TraceToss_Post
// #define FN_TraceMonsterHull_Post TraceMonsterHull_Post
// #define FN_TraceHull_Post TraceHull_Post
// #define FN_TraceModel_Post TraceModel_Post
// #define FN_TraceTexture_Post TraceTexture_Post
// #define FN_TraceSphere_Post TraceSphere_Post
// #define FN_GetAimVector_Post GetAimVector_Post
// #define FN_ServerCommand_Post ServerCommand_Post
// #define FN_ServerExecute_Post ServerExecute_Post
// #define FN_engClientCommand_Post engClientCommand_Post
// #define FN_ParticleEffect_Post ParticleEffect_Post
// #define FN_LightStyle_Post LightStyle_Post
// #define FN_DecalIndex_Post DecalIndex_Post
// #define FN_PointContents_Post PointContents_Post
// #define FN_MessageBegin_Post MessageBegin_Post
// #define FN_MessageEnd_Post MessageEnd_Post
// #define FN_WriteByte_Post WriteByte_Post
// #define FN_WriteChar_Post WriteChar_Post
// #define FN_WriteShort_Post WriteShort_Post
// #define FN_WriteLong_Post WriteLong_Post
// #define FN_WriteAngle_Post WriteAngle_Post
// #define FN_WriteCoord_Post WriteCoord_Post
// #define FN_WriteString_Post WriteString_Post
// #define FN_WriteEntity_Post WriteEntity_Post
// #define FN_CVarRegister_Post CVarRegister_Post
// #define FN_CVarGetFloat_Post CVarGetFloat_Post
// #define FN_CVarGetString_Post CVarGetString_Post
// #define FN_CVarSetFloat_Post CVarSetFloat_Post
// #define FN_CVarSetString_Post CVarSetString_Post
// #define FN_AlertMessage_Post AlertMessage_Post
// #define FN_EngineFprintf_Post EngineFprintf_Post
// #define FN_PvAllocEntPrivateData_Post PvAllocEntPrivateData_Post
// #define FN_PvEntPrivateData_Post PvEntPrivateData_Post
// #define FN_FreeEntPrivateData_Post FreeEntPrivateData_Post
// #define FN_SzFromIndex_Post SzFromIndex_Post
// #define FN_AllocString_Post AllocString_Post
// #define FN_GetVarsOfEnt_Post GetVarsOfEnt_Post
// #define FN_PEntityOfEntOffset_Post PEntityOfEntOffset_Post
// #define FN_EntOffsetOfPEntity_Post EntOffsetOfPEntity_Post
// #define FN_IndexOfEdict_Post IndexOfEdict_Post
// #define FN_PEntityOfEntIndex_Post PEntityOfEntIndex_Post
// #define FN_FindEntityByVars_Post FindEntityByVars_Post
// #define FN_GetModelPtr_Post GetModelPtr_Post
// #define FN_RegUserMsg_Post RegUserMsg_Post
// #define FN_AnimationAutomove_Post AnimationAutomove_Post
// #define FN_GetBonePosition_Post GetBonePosition_Post
// #define FN_FunctionFromName_Post FunctionFromName_Post
// #define FN_NameForFunction_Post NameForFunction_Post
// #define FN_ClientPrintf_Post ClientPrintf_Post
// #define FN_ServerPrint_Post ServerPrint_Post
// #define FN_Cmd_Args_Post Cmd_Args_Post
// #define FN_Cmd_Argv_Post Cmd_Argv_Post
// #define FN_Cmd_Argc_Post Cmd_Argc_Post
// #define FN_GetAttachment_Post GetAttachment_Post
// #define FN_CRC32_Init_Post CRC32_Init_Post
// #define FN_CRC32_ProcessBuffer_Post CRC32_ProcessBuffer_Post
// #define FN_CRC32_ProcessByte_Post CRC32_ProcessByte_Post
// #define FN_CRC32_Final_Post CRC32_Final_Post
// #define FN_RandomLong_Post RandomLong_Post
// #define FN_RandomFloat_Post RandomFloat_Post
// #define FN_SetView_Post SetView_Post
// #define FN_Time_Post Time_Post
// #define FN_CrosshairAngle_Post CrosshairAngle_Post
// #define FN_LoadFileForMe_Post LoadFileForMe_Post
// #define FN_FreeFile_Post FreeFile_Post
// #define FN_EndSection_Post EndSection_Post
// #define FN_CompareFileTime_Post CompareFileTime_Post
// #define FN_GetGameDir_Post GetGameDir_Post
// #define FN_Cvar_RegisterVariable_Post Cvar_RegisterVariable_Post
// #define FN_FadeClientVolume_Post FadeClientVolume_Post
// #define FN_SetClientMaxspeed_Post SetClientMaxspeed_Post
// #define FN_CreateFakeClient_Post CreateFakeClient_Post
// #define FN_RunPlayerMove_Post RunPlayerMove_Post
// #define FN_NumberOfEntities_Post NumberOfEntities_Post
// #define FN_GetInfoKeyBuffer_Post GetInfoKeyBuffer_Post
// #define FN_InfoKeyValue_Post InfoKeyValue_Post
// #define FN_SetKeyValue_Post SetKeyValue_Post
// #define FN_SetClientKeyValue_Post SetClientKeyValue_Post
// #define FN_IsMapValid_Post IsMapValid_Post
// #define FN_StaticDecal_Post StaticDecal_Post
// #define FN_PrecacheGeneric_Post PrecacheGeneric_Post
// #define FN_GetPlayerUserId_Post GetPlayerUserId_Post
// #define FN_BuildSoundMsg_Post BuildSoundMsg_Post
// #define FN_IsDedicatedServer_Post IsDedicatedServer_Post
// #define FN_CVarGetPointer_Post CVarGetPointer_Post
// #define FN_GetPlayerWONId_Post GetPlayerWONId_Post
// #define FN_Info_RemoveKey_Post Info_RemoveKey_Post
// #define FN_GetPhysicsKeyValue_Post GetPhysicsKeyValue_Post
// #define FN_SetPhysicsKeyValue_Post SetPhysicsKeyValue_Post
// #define FN_GetPhysicsInfoString_Post GetPhysicsInfoString_Post
// #define FN_PrecacheEvent_Post PrecacheEvent_Post
// #define FN_PlaybackEvent_Post PlaybackEvent_Post
// #define FN_SetFatPVS_Post SetFatPVS_Post
// #define FN_SetFatPAS_Post SetFatPAS_Post
// #define FN_CheckVisibility_Post CheckVisibility_Post
// #define FN_DeltaSetField_Post DeltaSetField_Post
// #define FN_DeltaUnsetField_Post DeltaUnsetField_Post
// #define FN_DeltaAddEncoder_Post DeltaAddEncoder_Post
// #define FN_GetCurrentPlayer_Post GetCurrentPlayer_Post
// #define FN_CanSkipPlayer_Post CanSkipPlayer_Post
// #define FN_DeltaFindField_Post DeltaFindField_Post
// #define FN_DeltaSetFieldByIndex_Post DeltaSetFieldByIndex_Post
// #define FN_DeltaUnsetFieldByIndex_Post DeltaUnsetFieldByIndex_Post
// #define FN_SetGroupMask_Post SetGroupMask_Post
// #define FN_engCreateInstancedBaseline_Post engCreateInstancedBaseline_Post
// #define FN_Cvar_DirectSet_Post Cvar_DirectSet_Post
// #define FN_ForceUnmodified_Post ForceUnmodified_Post
// #define FN_GetPlayerStats_Post GetPlayerStats_Post
// #define FN_AddServerCommand_Post AddServerCommand_Post
// #define FN_Voice_GetClientListening_Post Voice_GetClientListening_Post
// #define FN_Voice_SetClientListening_Post Voice_SetClientListening_Post
// #define FN_GetPlayerAuthId_Post GetPlayerAuthId_Post
// #define FN_OnFreeEntPrivateData OnFreeEntPrivateData
// #define FN_GameShutdown GameShutdown
// #define FN_ShouldCollide ShouldCollide
// #define FN_OnFreeEntPrivateData_Post OnFreeEntPrivateData_Post
// #define FN_GameShutdown_Post GameShutdown_Post
// #define FN_ShouldCollide_Post ShouldCollide_Post
#endif // USE_METAMOD
#endif // __MODULECONFIG_H__

View File

@ -1,9 +0,0 @@
// pgSQL configuration file
// File location: $moddir/addons/amxx/configs/pgsql.cfg
// *NOTE* Linux users may encounter problems if they specify "localhost" instead of "127.0.0.1"
// We recommend using your server IP address instead of its name
amx_pgsql_host "127.0.0.1"
amx_pgsql_user "root"
amx_pgsql_pass ""
amx_pgsql_db "amx"

View File

@ -1,32 +0,0 @@
/* PostgreSQL functions
*
* by David "BAILOPAN" Anderson
* Under the GNU General Public License, version 2
*/
#if defined _pgsql_included
#endinput
#endif
#define _pgsql_included
/* Opens connection. If already such exists then that will be used.
* Function returns sql id to use with other sql natives.
* Host can be plain ip or hostname, ports are not yet allowed. */
native pgsql_connect(host[],user[],pass[],dbname[]);
/* Uses an existing connection (sql) to perform a new query (query) (might close previous query if any).
Will return the number of rows found.
*/
native pgsql_query(sql,query[], {Float,_}:...);
/* Advances to the next row in the query set. */
native pgsql_nextrow(sql);
/* Stores specified column (fieldnum) of current query (sql) in (dest) with (maxlength) characters maximum. */
native pgsql_getfield(sql,fieldnum,dest[],maxlength);
/* Clears query (sql) and closes connection (if any other plugin doesn't use it). */
native pgsql_close(sql);
/* Stores last error of current query/connection (sql) in (dest) with (maxlength) characters maximum. */
native pgsql_error(sql,dest[],maxlength);

View File

@ -30,7 +30,24 @@
#include "pgsql_amx.h" #include "pgsql_amx.h"
pgs *cns = NULL; std::string error;
std::vector<pgdb*> dblist;
int sql_exists(const char* host,const char* user,const char* pass,const char* dbase) {
std::vector<pgdb*>::iterator i;
int id = 0;
for (i=dblist.begin(); i!=dblist.end(); i++) {
id++;
if (((*i)->host.compare(host) == 0) &&
((*i)->user.compare(user) == 0) &&
((*i)->pass.compare(pass) == 0) &&
((*i)->name.compare(dbase) == 0) &&
(!(*i)->free)) {
return id;
}
}
return -1;
}
bool is_ipaddr(const char *IP) bool is_ipaddr(const char *IP)
{ {
@ -43,180 +60,201 @@ bool is_ipaddr(const char *IP)
return true; return true;
} }
void pgdb::Kill()
char *make_connstring(const char *host, const char *user, const char *pass, const char *name)
{ {
int len = 46 + strlen(host) + strlen(user) + strlen(pass) + strlen(name) + 2; if (free)
char *c_info = new char[len]; return;
PQfinish(cn);
if (is_ipaddr(host)) { host.clear();
sprintf(c_info, "hostaddr = '%s' user = '%s' pass = '%s' name = '%s'", host, user, pass, name); user.clear();
} else { pass.clear();
sprintf(c_info, "host = '%s' user = '%s' pass = '%s' name = '%s'", host, user, pass, name); name.clear();
} row = 0;
free = true;
return c_info;
} }
PGconn* make_connection(const char *h, const char *u, const char *ps, const char *n) int pgdb::Connect(const char *hh, const char *uu, const char *pp, const char *dd)
{ {
pgs *p = cns; host.assign(hh);
int last = 0; user.assign(uu);
pass.assign(pp);
name.assign(dd);
if (is_ipaddr(host.c_str())) {
cstr.assign("hostaddr = '");
} else {
cstr.assign("host = '");
}
while (p) { cstr.append(host);
last = p->ii(); cstr.append("' user = '");
if (p->v.host==h && p->v.user==u && p->v.pass==ps && p->v.name==n) { cstr.append(user);
return p->v.cn; cstr.append("' pass = '");
} cstr.append(pass);
} cstr.append("' name = '");
char *c_info = make_connstring(h, u, ps, n); cstr.append(name);
/* now search for a free one */ cstr.append("'");
p = cns;
while (p) {
if (p->free) {
p->set(h, u, ps, n, p->ii());
return p->v.cn;
} else {
p = p->link();
}
}
if (cns == NULL) {
cns = new pgs;
PGconn *cn = PQconnectdb(c_info);
cns->set(h, u, ps, n, 1);
cns->scn(cn);
return cn;
} else {
p = new pgs(h, u, ps, n, last+1);
cns->sln(p);
PGconn *cn = PQconnectdb(c_info);
cns->scn(cn);
return cn;
}
}
pgs* get_conn_i(int n=1) cn = PQconnectdb(cstr.c_str());
{
pgs *p = cns; if (PQstatus(cn) != CONNECTION_OK) {
int i=0; err.assign(PQerrorMessage(cn));
while (p) { free = true;
if (++i==n) { lastError = PQstatus(cn);
return p; return 0;
} else {
p = p->link();
}
} }
return NULL; free = false;
return true;
} }
static cell AMX_NATIVE_CALL pgsql_connect(AMX *amx, cell *params) static cell AMX_NATIVE_CALL pgsql_connect(AMX *amx, cell *params)
{ {
int i; int len;
const char *host = GET_AMXSTRING(amx,params[1],0,i); unsigned int i;
const char *user = GET_AMXSTRING(amx,params[2],1,i); pgdb *c = NULL;
const char *pass = GET_AMXSTRING(amx,params[3],2,i);
const char *name = GET_AMXSTRING(amx,params[4],3,i);
PGconn *cn = make_connection(host, user, pass, name); const char *host = MF_GetAmxString(amx,params[1],0,&len);
const char *user = MF_GetAmxString(amx,params[2],1,&len);
const char *pass = MF_GetAmxString(amx,params[3],2,&len);
const char *name = MF_GetAmxString(amx,params[4],3,&len);
if (PQstatus(cn) != CONNECTION_OK) { int id = sql_exists(host, user, pass, name);
char *error = PQerrorMessage(cn);
SET_AMXSTRING(amx, params[5], (error?error:""), params[6]); if (id >= 0)
return id;
id = -1;
for (i=0; i<dblist.size(); i++) {
if (dblist[i]->free) {
id = i;
break;
}
}
if (id < 0) {
c = new pgdb;
dblist.push_back(c);
id = dblist.size() - 1;
} else {
c = dblist[id];
}
if (!c->Connect(host, user, pass, name)) {
MF_SetAmxString(amx, params[5], c->err.c_str(), params[6]);
return 0; return 0;
} }
return 1; return id+1;
} }
static cell AMX_NATIVE_CALL pgsql_error(AMX *amx, cell *params) static cell AMX_NATIVE_CALL pgsql_error(AMX *amx, cell *params)
{ {
int c = params[1]; unsigned int id = params[1] - 1;
pgs *p = get_conn_i(c);
char *error = PQerrorMessage(p->v.cn); if (id >= dblist.size() || dblist[id]->free) {
SET_AMXSTRING(amx, params[2], (error==NULL?"":error), params[3]); error.assign("Invalid handle.");
return 1; MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
}
dblist[id]->err.assign(PQerrorMessage(dblist[id]->cn));
MF_SetAmxString(amx, params[2], dblist[id]->err.c_str(), params[3]);
return dblist[id]->lastError;
} }
static cell AMX_NATIVE_CALL pgsql_query(AMX *amx, cell *params) static cell AMX_NATIVE_CALL pgsql_query(AMX *amx, cell *params)
{ {
pgs *p = get_conn_i(params[1]); unsigned int id = params[1] - 1;
if (p == NULL) {
if (id >= dblist.size() || dblist[id]->free) {
error.assign("Invalid handle.");
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0; return 0;
} }
if (p->v.res) { pgdb *c = dblist[id];
p->reset();
} if (c->res)
c->reset();
int i; int i;
const char *query = FORMAT_AMXSTRING(amx, params, 2, i); const char *query = MF_FormatAmxString(amx, params, 2, &i);
p->v.res = PQexec(p->v.cn, query); c->res = PQexec(c->cn, query);
c->row = 0;
if (PQresultStatus(p->v.res) != PGRES_COMMAND_OK) { if (PQresultStatus(c->res) != PGRES_COMMAND_OK) {
c->lastError = PQresultStatus(c->res);
return -1; return -1;
} }
return PQntuples(p->v.res); return PQntuples(c->res);
} }
static cell AMX_NATIVE_CALL pgsql_nextrow(AMX *amx, cell *params) static cell AMX_NATIVE_CALL pgsql_nextrow(AMX *amx, cell *params)
{ {
pgs *p = get_conn_i(params[1]); unsigned int id = params[1] - 1;
if (p == NULL) { if (id >= dblist.size() || dblist[id]->free) {
error.assign("Invalid handle.");
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0; return 0;
} }
if (p->v.cn == NULL) { pgdb *c = dblist[id];
return -1;
}
if (PQstatus(p->v.cn)!= CONNECTION_OK) {
return -1;
}
if (p->v.row > PQntuples(p->v.res)) { if (c->row > PQntuples(c->res))
return 0; return 0;
}
p->v.row++; c->row++;
return 1; return 1;
} }
static cell AMX_NATIVE_CALL pgsql_getfield(AMX *amx, cell *params) static cell AMX_NATIVE_CALL pgsql_getfield(AMX *amx, cell *params)
{ {
pgs *p = get_conn_i(params[1]); unsigned int id = params[1] - 1;
int col = params[2] + 1; int col = params[2];
if (p == NULL) {
if (id >= dblist.size() || dblist[id]->free) {
error.assign("Invalid handle.");
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0; return 0;
} }
if (p->v.cn == NULL) { pgdb *c = dblist[id];
return -1;
}
if (PQstatus(p->v.cn)!= CONNECTION_OK) {
return -1;
}
if (col-1 > PQnfields(p->v.res)) { if (col-1 > PQnfields(c->res))
return 0; return 0;
}
char *field = PQgetvalue(p->v.res, p->v.row, col); char *field = PQgetvalue(c->res, c->row, col);
return SET_AMXSTRING(amx, params[3], field?field:"", params[4]); return MF_SetAmxString(amx, params[3], field?field:"", params[4]);
} }
static cell AMX_NATIVE_CALL pgsql_close(AMX *amx, cell *params) static cell AMX_NATIVE_CALL pgsql_close(AMX *amx, cell *params)
{ {
pgs *p = get_conn_i(params[1]); unsigned int id = params[1] - 1;
p->close(); if (id >= dblist.size() || dblist[id]->free) {
error.assign("Invalid handle.");
MF_RaiseAmxError(amx, AMX_ERR_NATIVE);
return 0;
}
pgdb *c = dblist[id];
c->Kill();
return 1; return 1;
} }
void OnAmxxAttach()
{
MF_AddNatives(pgsql_exports);
}
AMX_NATIVE_INFO pgsql_exports[] = { AMX_NATIVE_INFO pgsql_exports[] = {
{"dbi_connect", pgsql_connect}, {"dbi_connect", pgsql_connect},
{"dbi_error", pgsql_error}, {"dbi_error", pgsql_error},
@ -224,25 +262,12 @@ AMX_NATIVE_INFO pgsql_exports[] = {
{"dbi_nextrow", pgsql_nextrow}, {"dbi_nextrow", pgsql_nextrow},
{"dbi_close", pgsql_close}, {"dbi_close", pgsql_close},
{"dbi_getfield", pgsql_getfield}, {"dbi_getfield", pgsql_getfield},
{"pgsql_connect", pgsql_connect},
{"pgsql_error", pgsql_error},
{"pgsql_query", pgsql_query},
{"pgsql_nextrow", pgsql_nextrow},
{"pgsql_close", pgsql_close},
{"pgsql_getfield", pgsql_getfield},
{NULL, NULL}, {NULL, NULL},
}; };
C_DLLEXPORT int AMX_Query(module_info_s** info) {
*info = &module_info;
return 1;
}
C_DLLEXPORT int AMX_Attach(pfnamx_engine_g* amxeng,pfnmodule_engine_g* meng) {
g_engAmxFunc = amxeng;
g_engModuleFunc = meng;
ADD_AMXNATIVES(&module_info, pgsql_exports);
return(1);
}
C_DLLEXPORT int AMX_Detach() {
delete cns;
return(1);
}

View File

@ -1,6 +0,0 @@
LIBRARY fun_amx
EXPORTS
AMX_Attach @1
AMX_Detach @3
SECTIONS
.data READ WRITE

View File

@ -31,109 +31,32 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <libpq-fe.h> #include <libpq-fe.h>
#include <modules.h> #include <string>
#include <vector>
#include "amxxmodule.h"
#define destroy(x) if(x){delete(x);x=0;} class pgdb
#define destarr(x) if(x){delete[]x;x=0;}
pfnamx_engine_g* g_engAmxFunc;
pfnmodule_engine_g* g_engModuleFunc;
#define NAME "PgSQL"
#define AUTHOR "BAILOPAN"
#define VERSION "1.00"
#define URL "http://www.bailopan.com/"
#define LOGTAG "PGSQL"
#define DATE __DATE__
module_info_s module_info = {
NAME,
AUTHOR,
VERSION,
AMX_INTERFACE_VERSION,
RELOAD_MODULE,
};
class pgs
{ {
public: public:
pgs() void reset() { PQclear(res); row = 0; }
{ pgdb() { free = true; }
} int Connect(const char *hh, const char *uu, const char *pp, const char *dd);
void Kill();
pgs(const char *h, const char *u, const char *p, const char *n, int i=1) ~pgdb() { Kill(); }
{
set(h, u, p, n, i);
}
void set(const char *h, const char *u, const char *p, const char *n, int i=1)
{
v.host = h;
v.user = u;
v.pass = p;
v.name = n;
v.cn = NULL;
v.row = 0;
next = NULL;
id = i;
free = false;
}
pgs* link()
{
return next;
}
int ii()
{
return id;
}
void scn(PGconn *cn)
{
v.cn = cn;
}
void sln(pgs *p)
{
next = p;
}
void reset()
{
PQclear(v.res);
v.row = 0;
}
void close()
{
PQfinish(v.cn);
destroy(v.host);
destroy(v.user);
destroy(v.pass);
destroy(v.name);
v.row = 0;
free = true;
}
struct pgsql {
const char *host;
const char *user;
const char *pass;
const char *name;
PGconn *cn;
PGresult *res;
int row;
} v;
~pgs()
{
close();
}
bool free; bool free;
PGconn *cn;
private: PGresult *res;
pgs *next; int row;
int id; std::string host;
std::string user;
std::string pass;
std::string name;
std::string cstr;
std::string err;
int lastError;
}; };
extern std::string error;
extern std::vector<pgdb*> dblist;
extern AMX_NATIVE_INFO pgsql_exports[];

View File

@ -39,11 +39,11 @@
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="libpq.lib wsock32.lib" AdditionalDependencies="wsock32.lib libpq.lib"
OutputFile=".\Release/pgsql_amx.dll" OutputFile=".\Release/pgsql_amxx.dll"
LinkIncremental="1" LinkIncremental="1"
SuppressStartupBanner="TRUE" SuppressStartupBanner="TRUE"
ModuleDefinitionFile=".\pgsql_amx.def" ModuleDefinitionFile=""
ProgramDatabaseFile=".\Release/pgsql.pdb" ProgramDatabaseFile=".\Release/pgsql.pdb"
ImportLibrary=".\Release/pgsql.lib" ImportLibrary=".\Release/pgsql.lib"
TargetMachine="1"/> TargetMachine="1"/>
@ -103,10 +103,11 @@
Name="VCCustomBuildTool"/> Name="VCCustomBuildTool"/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
OutputFile="Debug/pgsql_debug.dll" AdditionalDependencies="wsock32.lib libpq.lib"
OutputFile="Debug/pgsql_amxx.dll"
LinkIncremental="1" LinkIncremental="1"
SuppressStartupBanner="TRUE" SuppressStartupBanner="TRUE"
ModuleDefinitionFile=".\pgsql_amx.def" ModuleDefinitionFile=""
GenerateDebugInformation="TRUE" GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/pgsql_debug.pdb" ProgramDatabaseFile=".\Debug/pgsql_debug.pdb"
ImportLibrary=".\Debug/pgsql_debug.lib" ImportLibrary=".\Debug/pgsql_debug.lib"
@ -167,9 +168,19 @@
BrowseInformation="1"/> BrowseInformation="1"/>
</FileConfiguration> </FileConfiguration>
</File> </File>
<File <Filter
RelativePath="pgsql_amx.def"> Name="SDK"
</File> Filter="">
<File
RelativePath=".\amxxmodule.cpp">
</File>
<File
RelativePath=".\amxxmodule.h">
</File>
<File
RelativePath=".\moduleconfig.h">
</File>
</Filter>
</Filter> </Filter>
<Filter <Filter
Name="Header Files" Name="Header Files"
@ -182,9 +193,6 @@
Name="Resource Files" Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"> Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter> </Filter>
<File
RelativePath="pgsql.inc">
</File>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>

View File

@ -1,35 +0,0 @@
PgSQL Module for AMX Mod X
by David "BAILOPAN" Anderson
----------------------------
Installation
------------
1] Place the pgsql.cfg file in your addons/amxx/configs dir.
2] Place the module in the right place:
Linux:
Place geoip_amx_i386.so into addons/amxx/modules/
(If you want a glibc2.3 optimized binary, use geoip_amx_i686.so)
Add this line to addons/amxx/modules.ini :
geoip_amx_i386.so
Windows:
Place geoip_amx.dll into addons/ammx/modules/
Add this line to addons/amxx/modules.ini :
geoip_amx.dll
3] Scripters: Place "pgsql.inc" in addons/amxx/scripting/include
4] If you are using pgsql to store admins:
Place admin_pgsql.amx in addons/amxx/plugins/
And add this line to addons/amxx/plugins.ini:
admin_pgsql.amx
5] Put pgsql.cfg in addons/amxx/configs/
Open it and make sure the host, user, password, and database name are correct