-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathironsystem.sp
More file actions
430 lines (369 loc) · 15.7 KB
/
ironsystem.sp
File metadata and controls
430 lines (369 loc) · 15.7 KB
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#include <sourcemod>
#include <csgocolors>
#include <cstrike>
#include <clientprefs>
#include <sdktools>
#include <sdkhooks>
#include <adminmenu>
#include <cstrike_weapons>
//#include <dhooks>
#include <emitsoundany>
#define MESSAGE_PREFIX "[{DARKBLUE}fGaming{NORMAL}] "
#pragma semicolon 1
#define PLUGIN_VERSION "1.1.52"
#define PLUGIN_NAME "fGaming"
public Plugin:myinfo =
{
name = PLUGIN_NAME,
author = "C0mp4ct",
description = "fGaming",
version = PLUGIN_VERSION
}
// Variables for Database
new Handle:DB = INVALID_HANDLE;
new g_PlayerId[MAXPLAYERS+1];
new Handle:kvAdmins;
// Cookies
new Handle:g_cookieAutoBhop;
new Handle:g_cookieMusic;
new Handle:g_cookieDmg;
new Handle:g_cookieBuyMenu;
//new Handle:g_hHideRestricted = INVALID_HANDLE;
// Admin Spectate
//new Handle:hIsValidTarget;
new Handle:mp_forcecamera;
new Handle:mp_autokick;
//new bool:g_bCheckNullPtr = false;
// Music
new Handle:g_hPlayType = INVALID_HANDLE;
new bool:g_PlayMusic[MAXPLAYERS+1];
// Chat antispam
new bool:g_GlobalAntispam[MAXPLAYERS+1];
// Client spend time
new g_hours[MAXPLAYERS+1];
new g_minutes[MAXPLAYERS+1];
new g_seconds[MAXPLAYERS+1];
// BHOPPING
new VelocityOffset_0;
new VelocityOffset_1;
new BaseVelocityOffset;
new g_roundCounter;
new String:g_AdminsPath[PLATFORM_MAX_PATH];
new String:g_VipWeaponNamesPath[PLATFORM_MAX_PATH];
new Handle:hTopMenu = INVALID_HANDLE;
#include "ironsystem/generic.sp"
#include "ironsystem/vip.sp"
#include "ironsystem/adminmenu.sp"
#include "ironsystem/bans.sp"
#include "ironsystem/eloranking.sp"
#include "ironsystem/sounds.sp"
#include "ironsystem/events.sp"
#include "ironsystem/timers.sp"
//public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) {
// MarkNativeAsOptional("DHookIsNullParam");
// return APLRes_Success;
//}
public OnPluginStart()
{
CreateConVar("sm_ironsystem_version", PLUGIN_VERSION, "IronSystem Version");
g_hPlayType = CreateConVar("sm_ironsystem_playtype", "1", "1 - Random, 2- Play in queue", FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY);
g_cookieMusic = RegClientCookie("g_PlayMusic", "", CookieAccess_Private);
g_cookieAutoBhop = RegClientCookie("g_Autobhop", "", CookieAccess_Private);
g_cookieDmg = RegClientCookie("g_showDmg", "", CookieAccess_Private);
g_cookieBuyMenu = RegClientCookie("g_BuyMenu", "", CookieAccess_Private);
BuildPath(Path_SM, g_BanReasonsPath, sizeof(g_BanReasonsPath), "configs/banreasons.txt");
BuildPath(Path_SM, g_AdminsPath, sizeof(g_AdminsPath), "configs/admins.cfg");
BuildPath(Path_SM, g_VipWeaponNamesPath, sizeof(g_VipWeaponNamesPath), "configs/ironsystem.weapons.txt");
LoadTranslations("common.phrases");
LoadTranslations("basebans.phrases");
LoadTranslations("core.phrases");
RegAdminCmd("sm_ban", Command_BanPlayer, ADMFLAG_BAN, "Ban player on the server");
RegAdminCmd("sm_megaspeed", Command_MegaSpeed, ADMFLAG_BAN, "Give MegaSpeed");
RegConsoleCmd("sm_elo", Command_show);
//RegConsoleCmd("sm_blink", Command_Teleport);
RegConsoleCmd("sm_speed", Command_Speed);
RegServerCmd("sm_vipadd", Command_VipAdd);
AddCommandListener(Command_Say, "say");
AddCommandListener(Command_SayTeam, "say_team");
AddCommandListener(Command_Callvote, "callvote");
HookEvent("player_changename", Event_player_changename);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("round_start", Event_RoundStart);
HookEvent("round_end", Event_RoundEnd);
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
HookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Post);
HookEvent("player_jump",Event_PlayerJump);
HookEvent("round_mvp", Event_RoundMvp);
HookEvent("server_cvar", Event_ServerCvar, EventHookMode_Pre);
HookEvent("cs_win_panel_match", Event_MatchOver);
LoadBanReasons();
CheckWeaponArrays();
new Handle:topmenu;
if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
OnAdminMenuReady(topmenu);
//ADMIN SPECT
mp_forcecamera = FindConVar("mp_forcecamera");
mp_autokick = FindConVar("mp_autokick");
//if(!mp_forcecamera)
// SetFailState("Failed to locate mp_forcecamera");
//new Handle:temp = LoadGameConfigFile("allow-spec.games");
//if(!temp)
// SetFailState("Failed to load allow-spec.games.txt");
//new offset = GameConfGetOffset(temp, "IsValidObserverTarget");
//hIsValidTarget = DHookCreate(offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity, IsValidTarget);
//DHookAddParam(hIsValidTarget, HookParamType_CBaseEntity);
//CloseHandle(temp);
//g_bCheckNullPtr = (GetFeatureStatus(FeatureType_Native, "DHookIsNullParam") == FeatureStatus_Available);
//BHOPING
VelocityOffset_0 = FindSendPropInfo("CBasePlayer", "m_vecVelocity[0]");
if(VelocityOffset_0 == -1) {
SetFailState("[BunnyHop] Error: Failed to find Velocity[0] offset, aborting");
}
VelocityOffset_1 = FindSendPropInfo("CBasePlayer", "m_vecVelocity[1]");
if(VelocityOffset_1 == -1) {
SetFailState("[BunnyHop] Error: Failed to find Velocity[1] offset, aborting");
}
BaseVelocityOffset = FindSendPropInfo("CBasePlayer", "m_vecBaseVelocity");
if(BaseVelocityOffset == -1) {
SetFailState("[BunnyHop] Error: Failed to find the BaseVelocity offset, aborting");
}
InitDB();
}
public OnMapStart()
{
LoadMusic();
CreateTimer(4.0, Timer_PostMapStart);
g_PlayedSound = false;
}
public OnConfigsExecuted()
{
if (!LoadVipBuyConfig())
IronLog(false, "Unable to load %s", g_VipWeaponNamesPath);
}
public OnClientPostAdminCheck(client)
{
if (!IsValidClient(client)) {
return;
}
if (AreClientCookiesCached(client)) {
new String:value[16];
GetClientCookie(client, g_cookieMusic, value, sizeof(value));
if(strlen(value) > 0) {
g_PlayMusic[client] = StringToInt(value) == 1;
} else {
g_PlayMusic[client] = true;
SetClientCookie(client, g_cookieMusic, "1");
}
UnsetPlayerVip(client);
//IronLog(true, "Checked and resetet %d", client);
//g_canPlayerTeleport[client] = true;
}
if(DB != INVALID_HANDLE) {
CheckClientInDB(client);
CreateTimer(6.5, Timer_CheckClientBan, GetClientSerial(client));
} else {
IronLog(false, "Database failure on Authorize!");
}
CreateTimer(16.0, Timer_WelcomeMessage, GetClientSerial(client));
CreateTimer(60.0, Timer_VipMessage, GetClientSerial(client));
CreateTimer(4.0, Timer_ResetAntiSpams, GetClientSerial(client), TIMER_REPEAT);
CreateTimer(20.0, Timer_TimeCounter, GetClientSerial(client), TIMER_REPEAT);
if(CheckCommandAccess(client, "admin_allspec_flag", ADMFLAG_BAN)) {
SendConVarValue(client, mp_forcecamera, "0");
if(!SendConVarValue(client, mp_autokick, "0")) {
IronLog(false, "Cant unset autokick");
}
ServerCommand("mp_disable_autokick %d", GetClientUserId(client));
}
}
public OnClientDisconnect(client)
{
if(!IsValidClient(client)) {
return;
}
new String:steamid[32], String:datetime[32], String:DBQuery[256];
new String:time[16], String:times[3][16], String:hours[16], String:minutes[16], String:seconds[16];
IntToString(g_hours[client], hours, sizeof(hours));
IntToString(g_minutes[client], minutes, sizeof(minutes));
IntToString(g_seconds[client], seconds, sizeof(seconds));
times[0] = hours;
times[1] = minutes;
times[2] = seconds;
ImplodeStrings(times, 3, ":", time, sizeof(time));
FormatTime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", GetTime());
GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
Format(DBQuery, sizeof(DBQuery), "UPDATE players SET lastConnect='%s', spendedTime='%s' WHERE steamid='%s'", datetime, time, steamid);
SQL_TQuery(DB, SQLErrorCheckCallback, DBQuery);
UnsetPlayerVip(client);
}
InitDB() {
if (SQL_CheckConfig("fGaming")) {
SQL_TConnect(DBConnect, "fGaming");
} else {
SQL_TConnect(DBConnect, "storage-local");
}
}
public DBConnect(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if (hndl == INVALID_HANDLE) {
IronLog(false, "Database failure: %s", error);
return;
}
DB = hndl;
decl String:ident[16], bool:sqlite;
SQL_ReadDriver(DB, ident, sizeof(ident));
if (strcmp(ident, "mysql", false) == 0) {
sqlite = false;
} else if(strcmp(ident, "sqlite", false) == 0) {
sqlite = true;
} else {
LogError("Invalid database.");
return;
}
if (sqlite) {
SQL_TQuery(DB, SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS elostats (idPlayer INTEGER, rating INTEGER, kills INTEGER, assists INTEGER, deaths INTEGER, notify INTEGER)");
SQL_TQuery(DB, SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS players (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, steamid TEXT, vip INTEGER, lastConnect TEXT, ip TEXT, spendedTime TEXT)");
SQL_TQuery(DB, SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS admins (idPlayer INTEGER, adminFlag TEXT)");
SQL_TQuery(DB, SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS banlist (idPlayer INTEGER, idAdmin INTEGER, bantime INTEGER, length INTEGER, reason TEXT, date TEXT)");
} else {
SQL_TQuery(DB, SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS elostats (idPlayer int(8), rating int(8) NOT NULL, kills int(8) NOT NULL, assists int(8) NOT NULL deaths int(8) NOT NULL, notify int(2) NOT NULL)");
SQL_TQuery(DB, SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS players (id int(8), name varchar(255), steamid varchar(32), vip int(1), lastConnect varchar(64), ip varchar(64), spendedTime varchar(64))");
SQL_TQuery(DB, SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS admins (idPlayer int(8), adminFlag varchar(1)");
SQL_TQuery(DB, SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS banlist (idPlayer int(8), idAdmin int(8), bantime int(10), length int(10), reason varchar(128), date varchar(64)");
}
CheckAdminsInDB();
}
CheckClientInDB(const client)
{
new String:steamid[32], String:DBQuery[256];
GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
Format(DBQuery, sizeof(DBQuery), "SELECT vip, spendedTime, id FROM players WHERE steamid='%s'", steamid);
SQL_TQuery(DB, CheckClientInDBCallback, DBQuery, GetClientUserId(client));
}
public CheckClientInDBCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
new client = GetClientOfUserId(data);
if(!IsValidClient(client)) {
IronLog(false, "Invalid client: %d", client);
return;
}
if(hndl == INVALID_HANDLE) {
IronLog(false, "Query failed: %s", error);
return;
}
new String:steamid[32], String:name[64], String:ip[32], String:datetime[32], String:DBQuery[512];
GetClientAuthId(client, AuthId_Steam2, steamid, sizeof(steamid));
GetClientName(client, name, sizeof(name));
ReplaceString(name, sizeof(name), "'", "");
GetClientIP(client, ip, sizeof(ip));
if (SQL_GetRowCount(hndl) < 1) {
FormatTime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", GetTime());
Format(DBQuery, sizeof(DBQuery), "INSERT INTO players(name, steamid, vip, lastConnect, ip, spendedTime) VALUES('%s','%s','%d','%s','%s','00:00:00')", name, steamid, 0, datetime, ip);
SQL_TQuery(DB, SQLErrorCheckCallback, DBQuery);
CheckPlayerID(client);
} else {
new String:time[16], String:times[3][16];
// VIP INIT
SQL_FetchRow(hndl);
if(SQL_FetchInt(hndl, 0) == 1) {
SetPlayerVip(client);
}
// STORE PLAYER DATA
SQL_FetchString(hndl, 1, time, sizeof(time));
ExplodeString(time, ":", times, 3, sizeof(time));
g_hours[client] = StringToInt(times[0]);
g_minutes[client] = StringToInt(times[1]);
g_seconds[client] = StringToInt(times[2]);
Format(DBQuery, sizeof(DBQuery), "UPDATE players SET name='%s', ip='%s' WHERE steamid='%s'", name, ip, steamid);
SQL_TQuery(DB, SQLErrorCheckCallback, DBQuery);
// STORE PLAYER ID
g_PlayerId[client] = SQL_FetchInt(hndl, 2);
}
CheckClientInElo(client);
if(HasPlayerVip(client)) {
SendConVarValue(client, mp_forcecamera, "0");
ServerCommand("mp_disable_autokick %d", GetClientUserId(client));
SetFullVipAdvs(client);
LoadVipCookies(client);
}
}
CheckAdminsInDB()
{
kvAdmins = CreateKeyValues("Admins");
if(!FileToKeyValues(kvAdmins, g_AdminsPath)) {
IronLog(false, "Failed to load admins");
return false;
}
if(!KvGotoFirstSubKey(kvAdmins)) {
IronLog(false, "Failed to load admins sub key");
return false;
}
decl String:buffer[64], String:DBQuery[512];
new Handle:data = CreateArray(ByteCountToCells(64));
KvGetString(kvAdmins, "auth", buffer, sizeof(buffer));
if (StrEqual("steam", buffer)) {
KvGetString(kvAdmins, "identity", buffer, sizeof(buffer));
Format(DBQuery, sizeof(DBQuery), "SELECT idPlayer, adminFlag FROM admins JOIN players ON admins.idPlayer=players.id WHERE players.steamid='%s'", buffer);
PushArrayString(data, buffer);
SQL_TQuery(DB, CheckAdminsInDBCallback, DBQuery, data);
}
CreateTimer(6.0, Timer_CheckAdminsInDB, _);
return true;
}
public CheckAdminsInDBCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
new String:dataString[64], String:DBQuery[256];
GetArrayString(data, 0, dataString, sizeof(dataString));
if(hndl == INVALID_HANDLE) {
IronLog(false, "Query to DBCallback failed: %s", error);
return;
}
if (SQL_GetRowCount(hndl) < 1) {
Format(DBQuery, sizeof(DBQuery), "SELECT id, name FROM players WHERE steamid='%s'", dataString);
SQL_TQuery(DB, CallbackToInsertAdmin, DBQuery, data);
} else {
decl String:buffer[64], String:flags[64];
SQL_FetchRow(hndl);
SQL_FetchString(hndl, 1, flags, sizeof(buffer));
KvGetString(kvAdmins, "flags", buffer, sizeof(buffer));
if(!StrEqual(buffer, flags, false)) {
Format(DBQuery, sizeof(DBQuery), "UPDATE admins SET adminFlag='%s' WHERE idPlayer='%d'", buffer, SQL_FetchInt(hndl, 0));
IronLog(true, "Admin %s was updated in database.", dataString);
SQL_TQuery(DB, SQLErrorCheckCallback, DBQuery);
}
}
}
public CallbackToInsertAdmin(Handle:owner, Handle:hndl, const String:error[], any:data)
{
if(hndl == INVALID_HANDLE) {
IronLog(false, "Query to DBCallback2 failed: %s", error);
return;
}
if(!SQL_GetRowCount(hndl)) {
return;
}
new String:dataString[64], String:DBQuery[256];
GetArrayString(data, 0, dataString, sizeof(dataString));
SQL_FetchRow(hndl);
new id = SQL_FetchInt(hndl, 0);
new String:name[64], String:buffer[64];
SQL_FetchString(hndl, 1, name, sizeof(name));
KvGetString(kvAdmins, "flags", buffer, sizeof(buffer));
Format(DBQuery, sizeof(DBQuery), "INSERT INTO admins(idPlayer, adminFlag) VALUES('%d','%s')", id, buffer);
IronLog(true, "Admin %s was inserted into database.", name);
SQL_TQuery(DB, SQLErrorCheckCallback, DBQuery);
}
//public MRESReturn:IsValidTarget(this, Handle:hReturn, Handle:hParams)
//{
// As of DHooks 1.0.12 we must check for a null param.
// if (g_bCheckNullPtr && DHookIsNullParam(hParams, 1))
// return MRES_Ignored;
// new target = DHookGetParam(hParams, 1);
// if(target <= 0 || target > MaxClients || !IsClientInGame(this) || !IsClientInGame(target) || !IsPlayerAlive(target) || IsPlayerAlive(this) || GetClientTeam(this) <= 1 || GetClientTeam(target) <= 1) {
// return MRES_Ignored;
// }
// else {
// DHookSetReturn(hReturn, true);
// return MRES_Override;
// }
//}