-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSourceModInterface.cpp
179 lines (148 loc) · 5.43 KB
/
SourceModInterface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* ======== Basic Admin tool ========
* Copyright (C) 2004-2007 Erling K. Sæterdal
* No warranties of any kind
*
* License: zlib/libpng
*
* Author(s): Erling K. Sæterdal ( EKS )
* Credits:
* Menu code based on code from CSDM ( http://www.tcwonline.org/~dvander/cssdm ) Created by BAILOPAN
* Helping on misc errors/functions: BAILOPAN,karma,LDuke,sslice,devicenull,PMOnoTo,cybermind ( most who idle in #sourcemod on GameSurge realy )
* ============================ */
#include "SourceModInterface.h"
SourceModInterface g_SMExt;
SourceModInterfaceCallbacks *g_SMCallbacks;
IExtensionManager *smexts;
IShareSys *g_pShareSys;
IExtension *myself;
IAdminSystem *g_pAdmins;
IPlayerManager *g_pPlayers;
SourceModInterface::SourceModInterface()
{
g_pShareSys = NULL;
myself = NULL;
g_pAdmins = NULL;
g_pPlayers = NULL;
g_InterfaceConnected = false;
}
void SourceModInterface::Disconnect()
{
if(g_pPlayers)
g_pPlayers->RemoveClientListener(g_SMCallbacks);
if(myself)
smexts->UnloadExtension(myself);
g_pAdmins = NULL;
g_pShareSys = NULL;
myself = NULL;
g_pAdmins = NULL;
g_pPlayers = NULL;
g_InterfaceConnected = false;
}
bool SourceModInterface::Connect()
{
char error[256];
char path[256];
int maxlength = sizeof(error);
g_SMCallbacks = new SourceModInterfaceCallbacks;
if ((smexts = (IExtensionManager *)g_SMAPI->MetaFactory(SOURCEMOD_INTERFACE_EXTENSIONS, NULL, NULL)) == NULL)
{
g_BATCore.AddLogEntry("ERROR! Failed to get %s interface, this means any integration with sourcemod will not happen",SOURCEMOD_INTERFACE_EXTENSIONS);
if (error)
g_BATCore.AddLogEntry("ERROR! Sourcemod returned the error: %s",error);
Disconnect();
return false;
}
/* This could be more dynamic */
#if defined __linux__
g_SMAPI->PathFormat(path,sizeof(path),"addons/addons/bin/bat_mm_i486.so");
#else
g_SMAPI->PathFormat(path,sizeof(path),"addons/addons/bin/bat_mm.dll");
#endif
if ((myself = smexts->LoadExternal(&g_SMExt,path,"bat_mm.ext",error,maxlength)) == NULL)
{
g_BATCore.AddLogEntry("ERROR! Failed to load as sourcemod external, sourcemod integration is impossible");
Disconnect();
return false;
}
bool GotInterface = g_pShareSys->RequestInterface(SMINTERFACE_ADMINSYS_NAME,SMINTERFACE_ADMINSYS_VERSION, myself, (SMInterface **)&g_pAdmins);
if(!GotInterface)
{
g_BATCore.AddLogEntry("ERROR! Failed to get the sourcemod admin interface ( %s Version: %d )",SMINTERFACE_ADMINSYS_NAME,SMINTERFACE_ADMINSYS_VERSION);
Disconnect();
return false;
}
GotInterface = g_pShareSys->RequestInterface(SMINTERFACE_PLAYERMANAGER_NAME,SMINTERFACE_PLAYERMANAGER_VERSION, myself, (SMInterface **)&g_pPlayers);
if(!GotInterface)
{
g_BATCore.AddLogEntry("ERROR! Failed to get the sourcemod admin interface ( %s Version: %d )",SMINTERFACE_PLAYERMANAGER_NAME,SMINTERFACE_PLAYERMANAGER_VERSION);
Disconnect();
return false;
}
g_InterfaceConnected = true;
g_pPlayers->AddClientListener(g_SMCallbacks);
return true;
}
bool SourceModInterface::OnExtensionLoad(IExtension *me, IShareSys *sys, char *error, size_t maxlength, bool late)
{
g_pShareSys = sys;
myself = me;
return true;
}
void SourceModInterface::OnExtensionUnload()
{
/* Clean up any resources here, and more importantly, make sure
* any listeners/hooks into SourceMod are totally removed, as well
* as data structures like handle types and forwards.
*/
//...
}
void SourceModInterface::OnExtensionsAllLoaded()
{
/* Called once all extensions are marked as loaded.
* This always called, and always called only once.
*/
}
void SourceModInterface::OnExtensionPauseChange(bool pause)
{
}
bool SourceModInterface::QueryRunning(char *error, size_t maxlength)
{
/* if something is required that can't be determined during the initial
* load process, print a message here will show a helpful message to
* users when they view the extension's info.
*/
return true;
}
void SourceModInterface::SetAdminRights(int id,int iBATFlags,const char *AdminName)
{
IGamePlayer *pPlayer = g_pPlayers->GetGamePlayer(g_UserInfo[id].PlayerEdict);
int iFlags = g_BATCore.GetAdminLoader()->ConvertToSoureModAdminRights(iBATFlags);
AdminId AdminID = pPlayer->GetAdminId();
if (AdminID == INVALID_ADMIN_ID)
{
AdminID = g_pAdmins->CreateAdmin(AdminName);
pPlayer->SetAdminId(AdminID,true);
}
g_pAdmins->SetAdminFlags(AdminID,Access_Effective,iFlags);
}
void SourceModInterfaceCallbacks::OnClientPostAdminCheck(int client)
{
IGamePlayer *pPlayer = g_pPlayers->GetGamePlayer(g_UserInfo[client].PlayerEdict);
AdminId admin = pPlayer->GetAdminId();
const char * AuthID = pPlayer->GetAuthString();
if(g_BATVars.GetSMInterface() == 1)
{
if (admin == INVALID_ADMIN_ID)
return;
uint bits = g_pAdmins->GetAdminFlags(admin, Access_Effective);
const char *SMAdminString = g_BATCore.GetAdminLoader()->GetAdminAccountFlagsString(bits);
int NewAdminRights = g_BATCore.GetAdminLoader()->ConvertFromSourceModAdminRights(SMAdminString);
const char *BATAdminString = g_BATCore.GetAdminLoader()->GetAdminAccountFlagsString(bits);
g_UserInfo[client].AdminAccess = NewAdminRights;
_snprintf(g_UserInfo[client].AdminFlags,39,"%s",g_BATCore.GetAdminLoader()->GetAdminAccountFlagsString(NewAdminRights));
}
else if(g_BATVars.GetSMInterface() == 2)
{
g_SMExt.SetAdminRights(client,g_UserInfo[client].AdminAccess,g_UserInfo[client].AdminName);
}
}