-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBATCore.h
305 lines (256 loc) · 9.94 KB
/
BATCore.h
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/* ======== 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 )
* ============================ */
#ifndef _INCLUDE_SAMPLEPLUGIN_H
#define _INCLUDE_SAMPLEPLUGIN_H
class StrUtil
{
public:
int StrReplace(char *str, const char *from, const char *to, int maxlen); // Replaces part of a string with something else
char* StrRemoveQuotes(char *text); // Removes Quotes from the string
int GetFirstIndexOfChar(char *Text,int MaxLen,unsigned char t); // Gets index of the instance of t in a char array
void StrTrimLeft(char *buffer); // Trim from the left ( Removes white spaces )
void StrTrimRight(char *buffer); // Trim from the right ( Removes white spaces )
void StrTrim(char *buffer); // Trims the string ( Removes white spaces )
bool StrIsSpace(unsigned char b); // If the char is a space or whitespace
unsigned long StrHash(register const char *str, register int len); // Hashes the string ( Uses dbm hash ( Duff's device version )
};
struct StrAlphaSortStuct
{
char *TheStr; // Pointer to the actual text.
int Index; // What order this string has after all the strings have been alfabeticly sorted
};
#include <ISmmPlugin.h>
#include <sourcehook/sourcehook.h>
#include <voice_gamemgr.h>
#include "hl2sdk/convar.h"
#include "MapVote.h"
#include "BATMaps.h"
#include "ModInfo.h"
#include "BATSQL.h"
#include "AdminCmdManager.h"
#include "AdminCommands.h"
#include "TaskSystem.h"
#include "LoadAdminAccounts.h"
#include "ReservedSlotsSystem.h"
#include "MenuRconCmds.h"
#include "ienginesound.h"
#include <igameevents.h>
#include <iplayerinfo.h>
#include "Utils.h"
#include "cvars.h"
#include "const.h"
#include <sh_vector.h>
#include "Translation.h"
#include "MessageBuffer.h"
#include "PreformanceSampler.h"
extern BATMaps *m_BATMaps;
extern BATSQL *m_BATSQL;
extern ReservedSlotsSystem *m_ReservedSlots;
extern TaskSystem *m_TaskSystem;
extern MenuRconCmds *m_MenuRconCmds;
extern MessageBuffer *m_MessageBuffer;
class BATCore :
public ISmmPlugin,
public IMetamodListener,
public IGameEventListener2,
public IConCommandBaseAccessor,
public StrUtil
{
public:
bool Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late);
bool Unload(char *error, size_t maxlen);
void AllPluginsLoaded();
bool Pause(char *error, size_t maxlen)
{
AddLogEntry("BAT was paused, AdminInterface was unloaded and will properly not function until after a map change or server restart");
UnloadAdminInterface();
WriteLogBuffer();
return true;
}
bool Unpause(char *error, size_t maxlen)
{
AddLogEntry("BAT was unpaused, expect all sorts of minor issues, you should change map now");
UpdatePlayerInformation();
return true;
}
const char *GetAuthor()
{
return "EKS";
}
const char *GetName()
{
return "Basic Admin Tool";
}
const char *GetDescription()
{
return "A Basic Admin Tool, that provides admin command and a menu";
}
const char *GetURL()
{
return "http://www.TheXSoft.com";
}
const char *GetLicense()
{
return "zlib/libpng";
}
const char *GetVersion()
{
return BAT_VERSION;
}
const char *GetDate()
{
return __DATE__;
}
const char *GetLogTag()
{
return "BAT";
}
#if BAT_ORANGEBOX == 1
int GetApiVersion() { return METAMOD_PLAPI_VERSION; }
#else
#endif
//These functions are from IServerPluginCallbacks
//Note, the parameters might be a little different to match the actual calls!
//Called on LevelInit. Server plugins only have pMapName
bool LevelInit(const char *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
//Called on ServerActivate. Same definition as server plugins
void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
//Called on level shutdown. Same definition as server plugins
void LevelShutdown(void);
//Called on a game tick. Same definition as server plugins
void GameFrame(bool simulating);
//Client is activate (whatever that means). We get an extra parameter...
// "If bLoadGame is true, don't spawn the player because its state is already setup."
void ClientActive(edict_t *pEntity, bool bLoadGame);
//Client disconnects - same as server plugins
void ClientDisconnect(edict_t *pEntity);
void ClientPutInServer(edict_t *pEntity, char const *playername);//Client is put in server - same as server plugins
void SetCommandClient(int index);//Sets the client index - same as server plugins
//Called on client connect. Unlike server plugins, we return whether the
// connection is allowed rather than set it through a pointer in the first parameter.
// You can still supercede the GameDLL through RETURN_META_VALUE(MRES_SUPERCEDE, true/false)
bool ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
virtual bool RegisterConCommandBase(ConCommandBase *pVar);
#if BAT_ORANGEBOX == 1
void ClientCommand(edict_t *pEntity, const CCommand &args);
void ClientSay( const CCommand &command ); // This is where we get have the client say hooked.
#else
void ClientCommand(edict_t *pEntity);
void ClientSay();
#endif
/** End of SourceMM Functions */
//bool CanPlayerHearPlayer(CBasePlayer *pListener, CBasePlayer *pTalker);
IVEngineServer *GetEngine() { return m_Engine; }
BATVars GetBATVar() { return g_BATVars; } //FIXME: Make it return a pointer instead.
AdminCmd *GetAdminCmds() { return m_AdminCmds; }
BATSQL *GetBATSql() { return m_BATSQL; }
ReservedSlotsSystem *GetReservedSlotsSystem() { return m_ReservedSlots; }
IPlayerInfoManager *GetPlayerInfo() { return m_InfoMngr; }
IServerGameDLL *GetServerGameDll(){ return m_ServerDll; }
IServerPluginHelpers *GetHelpers(){ return m_Helpers; }
IEngineSound *GetSoundInterface(){ return m_Sound; }
Utils *GetUtils(){ return m_Utils; }
MapVote *GetMapVote(){ return m_MapVote; }
BATMaps *GetBATMaps(){ return m_BATMaps; }
TaskSystem *GetTaskSystem(){ return m_TaskSystem; }
LoadAdminAccounts* GetAdminLoader() { return m_LoadAdminAccounts; }
MenuRconCmds* GetMenuRconCmds() { return m_MenuRconCmds; }
MessageBuffer* GetMsgBuffer() {return m_MessageBuffer; }
void StartChangelevelCountDown(const char *NewMap); // Used to start the countdown for the nextmap, so we get a nice little timer
int FindPlayer(const char *PlayerID);
void EmitSound(int SoundRecivers,int SoundStartPoint,const char *SoundName);
float GetTimeLeft();
char *GetTimeleftString();
void ConsolePrint(int index, const char *msg, ...);
void SendHintMsg(int id,char *temp);
void SendCornerMsg(int id,const char *fmt, ...);
void ServerCommand(const char *fmt, ...);
void SendCSay(int id,const char *pText,bool IsReShowMsg = false);
void MessageAdmins(const char *msg, ...);
void MessagePlayer(int index, const char *msg, ...);
char *GetTeamName(int Team); // Returns the name of the current team
void ReloadSettings(); // Reloads settings and files, this only happens when the server loads for the first time or via admin commands
void GetFilePath(const char * FileName,char *NewFilePath);
void CheckUsersID(); // Checks if users steamdid is validated ( from STEAM_ID_PENDING to a real one )
void AddLogEntry(const char * LogInfo, ...); // Adds a log entry to the log buffer
void WriteLogBuffer(); // Forcefully writes the log buffer to file
bool IsValidTarget(int Admin_id,int Target_id,int Option);
bool HasAccess(int id,int Access,bool ShowWarrning = true);
bool IsUserAlive(int id);
const char *GetPlayerName(int id);
void FireGameEvent(IGameEvent *event);
void UpdatePlayerInformation(); // This function gets called after the plugin gets unpaused or late loaded, it updates the player list
void SetupPlayerInfo(int id);
private:
IGameEventManager2 *m_GameEventManager;
IVEngineServer *m_Engine;
IServerPluginHelpers *m_Helpers;
IServerGameDLL *m_ServerDll;
IServerGameClients *m_ServerClients;
IPlayerInfoManager *m_InfoMngr;
IEngineSound *m_Sound;
Utils *m_Utils;
MapVote *m_MapVote;
AdminCmd *m_AdminCmds;
LoadAdminAccounts *m_LoadAdminAccounts;
ConCommand *pSayCmd;
ConCommand *pSayTeamCmd;
SourceHook::CallClass<IVEngineServer> *m_Engine_CC;
SourceHook::CVector<int> m_hooks;
void LoadBATSettings(bool LateLoad);
void OneTimeInitBAT();
void GetLogFileName();
void ExecMapCfg();
void ExecBATCfg();
void SetupBasePath();
void CheckReservedSlots(int id);
void SetupModSpesficInfo(); // Gets the menu message id, for the running mod
int GetDaysSince1970();
int GetNextSpaceCount(char *Text,int CurIndex);
void UnloadAdminInterface(); // Used to inform plugins using the admin interface that its no longer usable
ConCommand *HookConsoleCmd(const char *CmdName);
void RemoveHookConsoleCmd(ConCommand *pTheCmd);
};
extern BATCore g_BATCore;
extern BATVars g_BATVars;
extern BATMenuMngr g_MenuMngr;
extern ConstPlayerInfo g_UserInfo[MAXPLAYERS+2];
extern int g_MaxClients;
extern bool g_IsConnected[MAXPLAYERS+1];
extern bool g_IsConnecting[MAXPLAYERS+1];
extern Translation *m_Translation;
extern char g_BasePath[256];
PLUGIN_GLOBALVARS();
#if BAT_ORANGEBOX == 0
#define GetGlobals g_SMAPI->pGlobals
class CCommand
{
public:
const char *ArgS()
{
return g_BATCore.GetEngine()->Cmd_Args();
}
int ArgC()
{
return g_BATCore.GetEngine()->Cmd_Argc();
}
const char *Arg(int index)
{
return g_BATCore.GetEngine()->Cmd_Argv(index);
}
};
extern ICvar *g_pCVar;
#else
#define GetGlobals g_SMAPI->GetCGlobals
#endif
extern CCommand g_LastCCommand;
#endif //_INCLUDE_SAMPLEPLUGIN_H