· 9 years ago · Dec 13, 2016, 12:02 AM
1public PlVers:__version =
2{
3 version = 5,
4 filevers = "1.6.0-dev+4131",
5 date = "11/22/2014",
6 time = "20:01:38"
7};
8new Float:NULL_VECTOR[3];
9new String:NULL_STRING[4];
10public Extension:__ext_core =
11{
12 name = "Core",
13 file = "core",
14 autoload = 0,
15 required = 0,
16};
17new MaxClients;
18public SharedPlugin:__pl_basecomm =
19{
20 name = "basecomm",
21 file = "basecomm.smx",
22 required = 1,
23};
24public SharedPlugin:__pl_sourcecomms =
25{
26 name = "sourcecomms",
27 file = "sourcecomms.smx",
28 required = 1,
29};
30public Extension:__ext_topmenus =
31{
32 name = "TopMenus",
33 file = "topmenus.ext",
34 autoload = 1,
35 required = 0,
36};
37public SharedPlugin:__pl_adminmenu =
38{
39 name = "adminmenu",
40 file = "adminmenu.smx",
41 required = 0,
42};
43public SharedPlugin:__pl_updater =
44{
45 name = "updater",
46 file = "updater.smx",
47 required = 0,
48};
49new iNumReasons;
50new String:g_sReasonDisplays[32][64];
51new String:g_sReasonKey[32][192];
52new iNumTimes;
53new g_iTimeMinutes[32];
54new String:g_sTimeDisplays[32][64];
55new DatabaseState:g_DatabaseState;
56new g_iConnectLock;
57new g_iSequence;
58new State:ConfigState;
59new Handle:ConfigParser;
60new Handle:hTopMenu;
61new Handle:CvarHostIp;
62new Handle:CvarPort;
63new String:ServerIp[24];
64new String:ServerPort[8];
65new Handle:g_hDatabase;
66new Handle:SQLiteDB;
67new String:DatabasePrefix[12] = "sb";
68new Handle:g_hPlayerRecheck[66];
69new Handle:g_hGagExpireTimer[66];
70new Handle:g_hMuteExpireTimer[66];
71new Float:RetryTime = 1097859072;
72new DefaultTime = 30;
73new DisUBImCheck;
74new ConsoleImmunity;
75new ConfigMaxLength;
76new ConfigWhiteListOnly;
77new serverID;
78new g_iPeskyPanels[66][5];
79new bool:g_bPlayerStatus[66];
80new String:g_sName[66][32];
81new bType:g_MuteType[66];
82new g_iMuteTime[66];
83new g_iMuteLength[66];
84new g_iMuteLevel[66];
85new String:g_sMuteAdminName[66][32];
86new String:g_sMuteReason[66][256];
87new String:g_sMuteAdminAuth[66][64];
88new bType:g_GagType[66];
89new g_iGagTime[66];
90new g_iGagLength[66];
91new g_iGagLevel[66];
92new String:g_sGagAdminName[66][32];
93new String:g_sGagReason[66][256];
94new String:g_sGagAdminAuth[66][64];
95new Handle:g_hServersWhiteList;
96public Plugin:myinfo =
97{
98 name = "SourceComms",
99 description = "Advanced punishments management for the Source engine in SourceBans style",
100 author = "Alex",
101 version = "0.9.266",
102 url = "https://forums.alliedmods.net/showthread.php?t=207176"
103};
104public __ext_core_SetNTVOptional()
105{
106 MarkNativeAsOptional("GetFeatureStatus");
107 MarkNativeAsOptional("RequireFeature");
108 MarkNativeAsOptional("AddCommandListener");
109 MarkNativeAsOptional("RemoveCommandListener");
110 MarkNativeAsOptional("BfWriteBool");
111 MarkNativeAsOptional("BfWriteByte");
112 MarkNativeAsOptional("BfWriteChar");
113 MarkNativeAsOptional("BfWriteShort");
114 MarkNativeAsOptional("BfWriteWord");
115 MarkNativeAsOptional("BfWriteNum");
116 MarkNativeAsOptional("BfWriteFloat");
117 MarkNativeAsOptional("BfWriteString");
118 MarkNativeAsOptional("BfWriteEntity");
119 MarkNativeAsOptional("BfWriteAngle");
120 MarkNativeAsOptional("BfWriteCoord");
121 MarkNativeAsOptional("BfWriteVecCoord");
122 MarkNativeAsOptional("BfWriteVecNormal");
123 MarkNativeAsOptional("BfWriteAngles");
124 MarkNativeAsOptional("BfReadBool");
125 MarkNativeAsOptional("BfReadByte");
126 MarkNativeAsOptional("BfReadChar");
127 MarkNativeAsOptional("BfReadShort");
128 MarkNativeAsOptional("BfReadWord");
129 MarkNativeAsOptional("BfReadNum");
130 MarkNativeAsOptional("BfReadFloat");
131 MarkNativeAsOptional("BfReadString");
132 MarkNativeAsOptional("BfReadEntity");
133 MarkNativeAsOptional("BfReadAngle");
134 MarkNativeAsOptional("BfReadCoord");
135 MarkNativeAsOptional("BfReadVecCoord");
136 MarkNativeAsOptional("BfReadVecNormal");
137 MarkNativeAsOptional("BfReadAngles");
138 MarkNativeAsOptional("BfGetNumBytesLeft");
139 MarkNativeAsOptional("PbReadInt");
140 MarkNativeAsOptional("PbReadFloat");
141 MarkNativeAsOptional("PbReadBool");
142 MarkNativeAsOptional("PbReadString");
143 MarkNativeAsOptional("PbReadColor");
144 MarkNativeAsOptional("PbReadAngle");
145 MarkNativeAsOptional("PbReadVector");
146 MarkNativeAsOptional("PbReadVector2D");
147 MarkNativeAsOptional("PbGetRepeatedFieldCount");
148 MarkNativeAsOptional("PbReadRepeatedInt");
149 MarkNativeAsOptional("PbReadRepeatedFloat");
150 MarkNativeAsOptional("PbReadRepeatedBool");
151 MarkNativeAsOptional("PbReadRepeatedString");
152 MarkNativeAsOptional("PbReadRepeatedColor");
153 MarkNativeAsOptional("PbReadRepeatedAngle");
154 MarkNativeAsOptional("PbReadRepeatedVector");
155 MarkNativeAsOptional("PbReadRepeatedVector2D");
156 MarkNativeAsOptional("PbSetInt");
157 MarkNativeAsOptional("PbSetFloat");
158 MarkNativeAsOptional("PbSetBool");
159 MarkNativeAsOptional("PbSetString");
160 MarkNativeAsOptional("PbSetColor");
161 MarkNativeAsOptional("PbSetAngle");
162 MarkNativeAsOptional("PbSetVector");
163 MarkNativeAsOptional("PbSetVector2D");
164 MarkNativeAsOptional("PbAddInt");
165 MarkNativeAsOptional("PbAddFloat");
166 MarkNativeAsOptional("PbAddBool");
167 MarkNativeAsOptional("PbAddString");
168 MarkNativeAsOptional("PbAddColor");
169 MarkNativeAsOptional("PbAddAngle");
170 MarkNativeAsOptional("PbAddVector");
171 MarkNativeAsOptional("PbAddVector2D");
172 MarkNativeAsOptional("PbReadMessage");
173 MarkNativeAsOptional("PbReadRepeatedMessage");
174 MarkNativeAsOptional("PbAddMessage");
175 VerifyCoreVersion();
176 return 0;
177}
178
179bool:operator>(Float:,Float:)(Float:oper1, Float:oper2)
180{
181 return FloatCompare(oper1, oper2) > 0;
182}
183
184bool:operator<(Float:,Float:)(Float:oper1, Float:oper2)
185{
186 return FloatCompare(oper1, oper2) < 0;
187}
188
189bool:StrEqual(String:str1[], String:str2[], bool:caseSensitive)
190{
191 return strcmp(str1, str2, caseSensitive) == 0;
192}
193
194ExplodeString(String:text[], String:split[], String:buffers[][], maxStrings, maxStringLength, bool:copyRemainder)
195{
196 new reloc_idx;
197 new idx;
198 new total;
199 new var1;
200 if (maxStrings < 1 || !split[0])
201 {
202 return 0;
203 }
204 while ((idx = SplitString(text[reloc_idx], split, buffers[total], maxStringLength)) != -1)
205 {
206 reloc_idx = idx + reloc_idx;
207 total++;
208 if (maxStrings == total)
209 {
210 if (copyRemainder)
211 {
212 strcopy(buffers[total + -1], maxStringLength, text[reloc_idx - idx]);
213 }
214 return total;
215 }
216 }
217 total++;
218 strcopy(buffers[total], maxStringLength, text[reloc_idx]);
219 return total;
220}
221
222Handle:SQLite_UseDatabase(String:database[], String:error[], maxlength)
223{
224 new Handle:kv;
225 new Handle:db;
226 kv = CreateKeyValues("", "", "");
227 KvSetString(kv, "driver", "sqlite");
228 KvSetString(kv, "database", database);
229 db = SQL_ConnectCustom(kv, error, maxlength, false);
230 CloseHandle(kv);
231 return db;
232}
233
234ReplyToTargetError(client, reason)
235{
236 switch (reason)
237 {
238 case -7:
239 {
240 ReplyToCommand(client, "[SM] %t", "More than one client matched");
241 }
242 case -6:
243 {
244 ReplyToCommand(client, "[SM] %t", "Cannot target bot");
245 }
246 case -5:
247 {
248 ReplyToCommand(client, "[SM] %t", "No matching clients");
249 }
250 case -4:
251 {
252 ReplyToCommand(client, "[SM] %t", "Unable to target");
253 }
254 case -3:
255 {
256 ReplyToCommand(client, "[SM] %t", "Target is not in game");
257 }
258 case -2:
259 {
260 ReplyToCommand(client, "[SM] %t", "Target must be dead");
261 }
262 case -1:
263 {
264 ReplyToCommand(client, "[SM] %t", "Target must be alive");
265 }
266 case 0:
267 {
268 ReplyToCommand(client, "[SM] %t", "No matching client");
269 }
270 default:
271 {
272 }
273 }
274 return 0;
275}
276
277public __pl_sourcecomms_SetNTVOptional()
278{
279 MarkNativeAsOptional("SourceComms_SetClientMute");
280 MarkNativeAsOptional("SourceComms_SetClientGag");
281 MarkNativeAsOptional("SourceComms_GetClientMuteType");
282 MarkNativeAsOptional("SourceComms_GetClientGagType");
283 return 0;
284}
285
286public __ext_topmenus_SetNTVOptional()
287{
288 MarkNativeAsOptional("CreateTopMenu");
289 MarkNativeAsOptional("LoadTopMenuConfig");
290 MarkNativeAsOptional("AddToTopMenu");
291 MarkNativeAsOptional("RemoveFromTopMenu");
292 MarkNativeAsOptional("DisplayTopMenu");
293 MarkNativeAsOptional("FindTopMenuCategory");
294 return 0;
295}
296
297public __pl_adminmenu_SetNTVOptional()
298{
299 MarkNativeAsOptional("GetAdminTopMenu");
300 MarkNativeAsOptional("AddTargetsToMenu");
301 MarkNativeAsOptional("AddTargetsToMenu2");
302 return 0;
303}
304
305ReloadPlugin(Handle:plugin)
306{
307 decl String:filename[64];
308 GetPluginFilename(plugin, filename, 64);
309 ServerCommand("sm plugins reload %s", filename);
310 return 0;
311}
312
313public __pl_updater_SetNTVOptional()
314{
315 MarkNativeAsOptional("Updater_AddPlugin");
316 MarkNativeAsOptional("Updater_RemovePlugin");
317 MarkNativeAsOptional("Updater_ForceUpdate");
318 return 0;
319}
320
321public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
322{
323 CreateNative("SourceComms_SetClientMute", Native_SetClientMute);
324 CreateNative("SourceComms_SetClientGag", Native_SetClientGag);
325 CreateNative("SourceComms_GetClientMuteType", Native_GetClientMuteType);
326 CreateNative("SourceComms_GetClientGagType", Native_GetClientGagType);
327 MarkNativeAsOptional("SQL_SetCharset");
328 RegPluginLibrary("sourcecomms");
329 return APLRes:0;
330}
331
332public OnPluginStart()
333{
334 LoadTranslations("common.phrases");
335 LoadTranslations("sourcecomms.phrases");
336 new Handle:hTemp;
337 new var1;
338 if (LibraryExists("adminmenu") && (hTemp = GetAdminTopMenu()))
339 {
340 OnAdminMenuReady(hTemp);
341 }
342 CvarHostIp = FindConVar("hostip");
343 CvarPort = FindConVar("hostport");
344 g_hServersWhiteList = CreateArray(1, 0);
345 CreateConVar("sourcecomms_version", "0.9.266", "", 270656, false, 0.0, false, 0.0);
346 AddCommandListener(CommandCallback, "sm_gag");
347 AddCommandListener(CommandCallback, "sm_mute");
348 AddCommandListener(CommandCallback, "sm_silence");
349 AddCommandListener(CommandCallback, "sm_ungag");
350 AddCommandListener(CommandCallback, "sm_unmute");
351 AddCommandListener(CommandCallback, "sm_unsilence");
352 RegServerCmd("sc_fw_block", FWBlock, "Blocking player comms by command from sourceban web site", 262144);
353 RegServerCmd("sc_fw_ungag", FWUngag, "Ungagging player by command from sourceban web site", 262144);
354 RegServerCmd("sc_fw_unmute", FWUnmute, "Unmuting player by command from sourceban web site", 262144);
355 RegConsoleCmd("sm_comms", CommandComms, "Shows current player communications status", 262144);
356 HookEvent("player_changename", Event_OnPlayerName, EventHookMode:1);
357 if (!SQL_CheckConfig("sourcecomms"))
358 {
359 SetFailState("Database failure: could not find database conf %s", "sourcecomms");
360 return 0;
361 }
362 DB_Connect();
363 InitializeBackupDB();
364 ServerInfo();
365 if (LibraryExists("updater"))
366 {
367 Updater_AddPlugin("http://s.ppalex.com/updater/sourcecomms-0.9/sc-updatefile.txt");
368 }
369 return 0;
370}
371
372public OnLibraryAdded(String:name[])
373{
374 if (StrEqual(name, "updater", true))
375 {
376 Updater_AddPlugin("http://s.ppalex.com/updater/sourcecomms-0.9/sc-updatefile.txt");
377 }
378 return 0;
379}
380
381public Updater_OnPluginUpdated()
382{
383 LogMessage("Plugin updated. Old version was %s. Now reloading.", "0.9.266");
384 ReloadPlugin(Handle:0);
385 return 0;
386}
387
388public OnLibraryRemoved(String:name[])
389{
390 if (StrEqual(name, "adminmenu", true))
391 {
392 hTopMenu = MissingTAG:0;
393 }
394 return 0;
395}
396
397public OnMapStart()
398{
399 ReadConfig();
400 return 0;
401}
402
403public OnMapEnd()
404{
405 if (g_hDatabase)
406 {
407 CloseHandle(g_hDatabase);
408 }
409 g_hDatabase = MissingTAG:0;
410 return 0;
411}
412
413public OnClientDisconnect(client)
414{
415 new var1;
416 if (g_hPlayerRecheck[client] && CloseHandle(g_hPlayerRecheck[client]))
417 {
418 g_hPlayerRecheck[client] = 0;
419 }
420 CloseMuteExpireTimer(client);
421 CloseGagExpireTimer(client);
422 return 0;
423}
424
425public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
426{
427 g_bPlayerStatus[client] = 0;
428 return true;
429}
430
431public OnClientConnected(client)
432{
433 g_sName[client][0] = MissingTAG:0;
434 MarkClientAsUnMuted(client);
435 MarkClientAsUnGagged(client);
436 return 0;
437}
438
439public OnClientPostAdminCheck(client)
440{
441 decl String:clientAuth[64];
442 GetClientAuthString(client, clientAuth, 64, true);
443 GetClientName(client, g_sName[client], 32);
444 new var1;
445 if (clientAuth[0] == 'B' || clientAuth[2] == 'L' || !DB_Connect())
446 {
447 g_bPlayerStatus[client] = 1;
448 return 0;
449 }
450 new var2;
451 if (client > 0 && IsClientInGame(client) && !IsFakeClient(client))
452 {
453 if (BaseComm_IsClientMuted(client))
454 {
455 MarkClientAsMuted(client, 0, -1, "CONSOLE", "STEAM_ID_SERVER", 0, "");
456 }
457 if (BaseComm_IsClientGagged(client))
458 {
459 MarkClientAsGagged(client, 0, -1, "CONSOLE", "STEAM_ID_SERVER", 0, "");
460 }
461 new String:sClAuthYZEscaped[132];
462 SQL_EscapeString(g_hDatabase, clientAuth[2], sClAuthYZEscaped, 129, 0);
463 decl String:Query[4096];
464 FormatEx(Query, 4096, "SELECT (c.ends - UNIX_TIMESTAMP()) AS remaining, c.length, c.type, c.created, c.reason, a.user, IF (a.immunity>=g.immunity, a.immunity, IFNULL(g.immunity,0)) AS immunity, c.aid, c.sid, a.authid FROM %s_comms AS c LEFT JOIN %s_admins AS a ON a.aid = c.aid LEFT JOIN %s_srvgroups AS g ON g.name = a.srv_group WHERE RemoveType IS NULL AND c.authid REGEXP '^STEAM_[0-9]:%s$' AND (length = '0' OR ends > UNIX_TIMESTAMP())", DatabasePrefix, DatabasePrefix, DatabasePrefix, sClAuthYZEscaped);
465 SQL_TQuery(g_hDatabase, Query_VerifyBlock, Query, GetClientUserId(client), DBPriority:0);
466 }
467 return 0;
468}
469
470public Action:Event_OnPlayerName(Handle:event, String:name[], bool:dontBroadcast)
471{
472 new client = GetClientOfUserId(GetEventInt(event, "userid"));
473 new var1;
474 if (client > 0 && IsClientInGame(client))
475 {
476 GetEventString(event, "newname", g_sName[client], 32);
477 }
478 return Action:0;
479}
480
481public BaseComm_OnClientMute(client, bool:muteState)
482{
483 new var1;
484 if (client > 0 && client <= MaxClients)
485 {
486 if (muteState)
487 {
488 if (g_MuteType[client])
489 {
490 }
491 else
492 {
493 MarkClientAsMuted(client, 0, -1, "CONSOLE", "STEAM_ID_SERVER", 0, "Muted through BaseComm natives");
494 SavePunishment(0, client, 1, -1, "Muted through BaseComm natives");
495 }
496 }
497 if (bType:0 < g_MuteType[client])
498 {
499 MarkClientAsUnMuted(client);
500 }
501 }
502 return 0;
503}
504
505public BaseComm_OnClientGag(client, bool:gagState)
506{
507 new var1;
508 if (client > 0 && client <= MaxClients)
509 {
510 if (gagState)
511 {
512 if (g_GagType[client])
513 {
514 }
515 else
516 {
517 MarkClientAsGagged(client, 0, -1, "CONSOLE", "STEAM_ID_SERVER", 0, "Gagged through BaseComm natives");
518 SavePunishment(0, client, 2, -1, "Gagged through BaseComm natives");
519 }
520 }
521 if (bType:0 < g_GagType[client])
522 {
523 MarkClientAsUnGagged(client);
524 }
525 }
526 return 0;
527}
528
529public Action:CommandComms(client, args)
530{
531 if (!client)
532 {
533 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "CommandComms_na");
534 return Action:0;
535 }
536 new var1;
537 if (g_MuteType[client] > bType:0 || g_GagType[client] > bType:0)
538 {
539 AdminMenu_ListTarget(client, client, 0, 0, 0);
540 }
541 else
542 {
543 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "CommandComms_nb");
544 }
545 return Action:3;
546}
547
548public Action:FWBlock(args)
549{
550 new String:arg_string[256];
551 new String:sArg[3][64] = "";
552 GetCmdArgString(arg_string, 256);
553 new type;
554 new length;
555 new var1;
556 if (ExplodeString(arg_string, " ", sArg, 3, 64, false) == 3 && !StringToIntEx(sArg[0][sArg], type, 10) && type < 1 && type > 3 && !StringToIntEx(sArg[1], length, 10))
557 {
558 LogError("Wrong usage of sc_fw_block");
559 return Action:4;
560 }
561 LogMessage("Received block command from web: steam %s, type %d, length %d", sArg[2], type, length);
562 new i = 1;
563 while (i <= MaxClients)
564 {
565 new var2;
566 if (IsClientInGame(i) && IsClientAuthorized(i) && !IsFakeClient(i))
567 {
568 decl String:clientAuth[64];
569 GetClientAuthString(i, clientAuth, 64, true);
570 if (!(strcmp(clientAuth, sArg[2], false)))
571 {
572 new var4;
573 if (g_MuteType[i] && (type == 1 || type == 3))
574 {
575 PerformMute(i, 0, length / 60, "CONSOLE", "STEAM_ID_SERVER", 0, "", 0);
576 PrintToChat(i, "%s%t", "\x04[SourceComms]\x01 ", "Muted on connect");
577 LogMessage("%s is muted from web", clientAuth);
578 }
579 new var6;
580 if (g_GagType[i] && (type == 2 || type == 3))
581 {
582 PerformGag(i, 0, length / 60, "CONSOLE", "STEAM_ID_SERVER", 0, "", 0);
583 PrintToChat(i, "%s%t", "\x04[SourceComms]\x01 ", "Gagged on connect");
584 LogMessage("%s is gagged from web", clientAuth);
585 }
586 return Action:3;
587 }
588 }
589 i++;
590 }
591 return Action:3;
592}
593
594public Action:FWUngag(args)
595{
596 new String:arg_string[256];
597 new String:sArg[1][64];
598 GetCmdArgString(arg_string, 256);
599 if (!ExplodeString(arg_string, " ", sArg, 1, 64, false))
600 {
601 LogError("Wrong usage of sc_fw_ungag");
602 return Action:4;
603 }
604 LogMessage("Received ungag command from web: steam %s", sArg[0][sArg]);
605 new i = 1;
606 while (i <= MaxClients)
607 {
608 new var1;
609 if (IsClientInGame(i) && IsClientAuthorized(i) && !IsFakeClient(i))
610 {
611 decl String:clientAuth[64];
612 GetClientAuthString(i, clientAuth, 64, true);
613 if (!(strcmp(clientAuth, sArg[0][sArg], false)))
614 {
615 if (bType:0 < g_GagType[i])
616 {
617 PerformUnGag(i);
618 PrintToChat(i, "%s%t", "\x04[SourceComms]\x01 ", "FWUngag");
619 LogMessage("%s is ungagged from web", clientAuth);
620 }
621 else
622 {
623 LogError("Can't ungag %s from web, it isn't gagged", clientAuth);
624 }
625 return Action:3;
626 }
627 }
628 i++;
629 }
630 return Action:3;
631}
632
633public Action:FWUnmute(args)
634{
635 new String:arg_string[256];
636 new String:sArg[1][64];
637 GetCmdArgString(arg_string, 256);
638 if (!ExplodeString(arg_string, " ", sArg, 1, 64, false))
639 {
640 LogError("Wrong usage of sc_fw_ungag");
641 return Action:4;
642 }
643 LogMessage("Received unmute command from web: steam %s", sArg[0][sArg]);
644 new i = 1;
645 while (i <= MaxClients)
646 {
647 new var1;
648 if (IsClientInGame(i) && IsClientAuthorized(i) && !IsFakeClient(i))
649 {
650 decl String:clientAuth[64];
651 GetClientAuthString(i, clientAuth, 64, true);
652 if (!(strcmp(clientAuth, sArg[0][sArg], false)))
653 {
654 if (bType:0 < g_MuteType[i])
655 {
656 PerformUnMute(i);
657 PrintToChat(i, "%s%t", "\x04[SourceComms]\x01 ", "FWUnmute");
658 LogMessage("%s is unmuted from web", clientAuth);
659 }
660 else
661 {
662 LogError("Can't unmute %s from web, it isn't muted", clientAuth);
663 }
664 return Action:3;
665 }
666 }
667 i++;
668 }
669 return Action:3;
670}
671
672public Action:CommandCallback(client, String:command[], args)
673{
674 new var1;
675 if (client && !CheckCommandAccess(client, command, 512, false))
676 {
677 return Action:0;
678 }
679 new type;
680 if (StrEqual(command, "sm_gag", false))
681 {
682 type = 2;
683 }
684 else
685 {
686 if (StrEqual(command, "sm_mute", false))
687 {
688 type = 1;
689 }
690 if (StrEqual(command, "sm_ungag", false))
691 {
692 type = 5;
693 }
694 if (StrEqual(command, "sm_unmute", false))
695 {
696 type = 4;
697 }
698 if (StrEqual(command, "sm_silence", false))
699 {
700 type = 3;
701 }
702 if (StrEqual(command, "sm_unsilence", false))
703 {
704 type = 6;
705 }
706 return Action:4;
707 }
708 if (args < 1)
709 {
710 new var2;
711 if (type <= 3)
712 {
713 var2[0] = 70664;
714 }
715 else
716 {
717 var2[0] = 70684;
718 }
719 ReplyToCommand(client, "%sUsage: %s <#userid|name> %s", "\x04[SourceComms]\x01 ", command, var2);
720 if (type <= 3)
721 {
722 ReplyToCommand(client, "%sUsage: %s <#userid|name> [reason]", "\x04[SourceComms]\x01 ", command);
723 }
724 return Action:4;
725 }
726 new String:sBuffer[256];
727 GetCmdArgString(sBuffer, 256);
728 if (type <= 3)
729 {
730 CreateBlock(client, 0, -1, type, "", sBuffer);
731 }
732 else
733 {
734 ProcessUnBlock(client, 0, type, "", sBuffer);
735 }
736 return Action:4;
737}
738
739public OnAdminMenuReady(Handle:topmenu)
740{
741 if (hTopMenu == topmenu)
742 {
743 return 0;
744 }
745 hTopMenu = topmenu;
746 new TopMenuObject:MenuObject = AddToTopMenu(hTopMenu, "sourcecomm_cmds", TopMenuObjectType:0, Handle_Commands, TopMenuObject:0, "", 0, "");
747 if (MenuObject)
748 {
749 AddToTopMenu(hTopMenu, "sourcecomm_gag", TopMenuObjectType:1, Handle_MenuGag, MenuObject, "sm_gag", 512, "");
750 AddToTopMenu(hTopMenu, "sourcecomm_ungag", TopMenuObjectType:1, Handle_MenuUnGag, MenuObject, "sm_ungag", 512, "");
751 AddToTopMenu(hTopMenu, "sourcecomm_mute", TopMenuObjectType:1, Handle_MenuMute, MenuObject, "sm_mute", 512, "");
752 AddToTopMenu(hTopMenu, "sourcecomm_unmute", TopMenuObjectType:1, Handle_MenuUnMute, MenuObject, "sm_unmute", 512, "");
753 AddToTopMenu(hTopMenu, "sourcecomm_silence", TopMenuObjectType:1, Handle_MenuSilence, MenuObject, "sm_silence", 512, "");
754 AddToTopMenu(hTopMenu, "sourcecomm_unsilence", TopMenuObjectType:1, Handle_MenuUnSilence, MenuObject, "sm_unsilence", 512, "");
755 AddToTopMenu(hTopMenu, "sourcecomm_list", TopMenuObjectType:1, Handle_MenuList, MenuObject, "sm_commlist", 512, "");
756 return 0;
757 }
758 return 0;
759}
760
761public Handle_Commands(Handle:menu, TopMenuAction:action, TopMenuObject:object_id, param1, String:buffer[], maxlength)
762{
763 switch (action)
764 {
765 case 0:
766 {
767 Format(buffer, maxlength, "%T", "AdminMenu_Main", param1);
768 }
769 case 1:
770 {
771 Format(buffer, maxlength, "%T", "AdminMenu_Select_Main", param1);
772 }
773 default:
774 {
775 }
776 }
777 return 0;
778}
779
780public Handle_MenuGag(Handle:menu, TopMenuAction:action, TopMenuObject:object_id, param1, String:buffer[], maxlength)
781{
782 if (action)
783 {
784 if (action == TopMenuAction:2)
785 {
786 AdminMenu_Target(param1, 2);
787 }
788 }
789 else
790 {
791 Format(buffer, maxlength, "%T", "AdminMenu_Gag", param1);
792 }
793 return 0;
794}
795
796public Handle_MenuUnGag(Handle:menu, TopMenuAction:action, TopMenuObject:object_id, param1, String:buffer[], maxlength)
797{
798 if (action)
799 {
800 if (action == TopMenuAction:2)
801 {
802 AdminMenu_Target(param1, 5);
803 }
804 }
805 else
806 {
807 Format(buffer, maxlength, "%T", "AdminMenu_UnGag", param1);
808 }
809 return 0;
810}
811
812public Handle_MenuMute(Handle:menu, TopMenuAction:action, TopMenuObject:object_id, param1, String:buffer[], maxlength)
813{
814 if (action)
815 {
816 if (action == TopMenuAction:2)
817 {
818 AdminMenu_Target(param1, 1);
819 }
820 }
821 else
822 {
823 Format(buffer, maxlength, "%T", "AdminMenu_Mute", param1);
824 }
825 return 0;
826}
827
828public Handle_MenuUnMute(Handle:menu, TopMenuAction:action, TopMenuObject:object_id, param1, String:buffer[], maxlength)
829{
830 if (action)
831 {
832 if (action == TopMenuAction:2)
833 {
834 AdminMenu_Target(param1, 4);
835 }
836 }
837 else
838 {
839 Format(buffer, maxlength, "%T", "AdminMenu_UnMute", param1);
840 }
841 return 0;
842}
843
844public Handle_MenuSilence(Handle:menu, TopMenuAction:action, TopMenuObject:object_id, param1, String:buffer[], maxlength)
845{
846 if (action)
847 {
848 if (action == TopMenuAction:2)
849 {
850 AdminMenu_Target(param1, 3);
851 }
852 }
853 else
854 {
855 Format(buffer, maxlength, "%T", "AdminMenu_Silence", param1);
856 }
857 return 0;
858}
859
860public Handle_MenuUnSilence(Handle:menu, TopMenuAction:action, TopMenuObject:object_id, param1, String:buffer[], maxlength)
861{
862 if (action)
863 {
864 if (action == TopMenuAction:2)
865 {
866 AdminMenu_Target(param1, 6);
867 }
868 }
869 else
870 {
871 Format(buffer, maxlength, "%T", "AdminMenu_UnSilence", param1);
872 }
873 return 0;
874}
875
876public Handle_MenuList(Handle:menu, TopMenuAction:action, TopMenuObject:object_id, param1, String:buffer[], maxlength)
877{
878 if (action)
879 {
880 if (action == TopMenuAction:2)
881 {
882 g_iPeskyPanels[param1][4] = 0;
883 AdminMenu_List(param1, 0);
884 }
885 }
886 else
887 {
888 Format(buffer, maxlength, "%T", "AdminMenu_List", param1);
889 }
890 return 0;
891}
892
893AdminMenu_Target(client, type)
894{
895 decl String:Title[192];
896 decl String:Option[32];
897 switch (type)
898 {
899 case 1:
900 {
901 Format(Title, 192, "%T", "AdminMenu_Select_Mute", client);
902 }
903 case 2:
904 {
905 Format(Title, 192, "%T", "AdminMenu_Select_Gag", client);
906 }
907 case 3:
908 {
909 Format(Title, 192, "%T", "AdminMenu_Select_Silence", client);
910 }
911 case 4:
912 {
913 Format(Title, 192, "%T", "AdminMenu_Select_Unmute", client);
914 }
915 case 5:
916 {
917 Format(Title, 192, "%T", "AdminMenu_Select_Ungag", client);
918 }
919 case 6:
920 {
921 Format(Title, 192, "%T", "AdminMenu_Select_Unsilence", client);
922 }
923 default:
924 {
925 }
926 }
927 new Handle:hMenu = CreateMenu(MenuHandler_MenuTarget, MenuAction:28);
928 SetMenuTitle(hMenu, Title);
929 SetMenuExitBackButton(hMenu, true);
930 new iClients;
931 if (type <= 3)
932 {
933 new i = 1;
934 while (i <= MaxClients)
935 {
936 new var1;
937 if (IsClientInGame(i) && !IsFakeClient(i))
938 {
939 switch (type)
940 {
941 case 1:
942 {
943 if (bType:0 < g_MuteType[i])
944 {
945 i++;
946 }
947 }
948 case 2:
949 {
950 if (bType:0 < g_GagType[i])
951 {
952 i++;
953 }
954 }
955 case 3:
956 {
957 new var2;
958 if (g_MuteType[i] > bType:0 || g_GagType[i] > bType:0)
959 {
960 i++;
961 }
962 }
963 default:
964 {
965 }
966 }
967 iClients++;
968 strcopy(Title, 192, g_sName[i]);
969 AdminMenu_GetPunishPhrase(client, i, Title, 192);
970 Format(Option, 32, "%d %d", GetClientUserId(i), type);
971 new var3;
972 if (CanUserTarget(client, i))
973 {
974 var3 = 0;
975 }
976 else
977 {
978 var3 = 1;
979 }
980 AddMenuItem(hMenu, Option, Title, var3);
981 }
982 i++;
983 }
984 }
985 else
986 {
987 new i = 1;
988 while (i <= MaxClients)
989 {
990 new var4;
991 if (IsClientInGame(i) && !IsFakeClient(i))
992 {
993 switch (type)
994 {
995 case 4:
996 {
997 if (bType:0 < g_MuteType[i])
998 {
999 iClients++;
1000 strcopy(Title, 192, g_sName[i]);
1001 Format(Option, 32, "%d %d", GetClientUserId(i), type);
1002 new var8;
1003 if (CanUserTarget(client, i))
1004 {
1005 var8 = 0;
1006 }
1007 else
1008 {
1009 var8 = 1;
1010 }
1011 AddMenuItem(hMenu, Option, Title, var8);
1012 }
1013 }
1014 case 5:
1015 {
1016 if (bType:0 < g_GagType[i])
1017 {
1018 iClients++;
1019 strcopy(Title, 192, g_sName[i]);
1020 Format(Option, 32, "%d %d", GetClientUserId(i), type);
1021 new var7;
1022 if (CanUserTarget(client, i))
1023 {
1024 var7 = 0;
1025 }
1026 else
1027 {
1028 var7 = 1;
1029 }
1030 AddMenuItem(hMenu, Option, Title, var7);
1031 }
1032 }
1033 case 6:
1034 {
1035 new var5;
1036 if (g_MuteType[i] > bType:0 && g_GagType[i] > bType:0)
1037 {
1038 iClients++;
1039 strcopy(Title, 192, g_sName[i]);
1040 Format(Option, 32, "%d %d", GetClientUserId(i), type);
1041 new var6;
1042 if (CanUserTarget(client, i))
1043 {
1044 var6 = 0;
1045 }
1046 else
1047 {
1048 var6 = 1;
1049 }
1050 AddMenuItem(hMenu, Option, Title, var6);
1051 }
1052 }
1053 default:
1054 {
1055 }
1056 }
1057 }
1058 i++;
1059 }
1060 }
1061 if (!iClients)
1062 {
1063 switch (type)
1064 {
1065 case 4:
1066 {
1067 Format(Title, 192, "%T", "AdminMenu_Option_Mute_Empty", client);
1068 }
1069 case 5:
1070 {
1071 Format(Title, 192, "%T", "AdminMenu_Option_Gag_Empty", client);
1072 }
1073 case 6:
1074 {
1075 Format(Title, 192, "%T", "AdminMenu_Option_Silence_Empty", client);
1076 }
1077 default:
1078 {
1079 Format(Title, 192, "%T", "AdminMenu_Option_Empty", client);
1080 }
1081 }
1082 AddMenuItem(hMenu, "0", Title, 1);
1083 }
1084 DisplayMenu(hMenu, client, 0);
1085 return 0;
1086}
1087
1088public MenuHandler_MenuTarget(Handle:menu, MenuAction:action, param1, param2)
1089{
1090 switch (action)
1091 {
1092 case 4:
1093 {
1094 decl String:Option[32];
1095 new String:Temp[2][8] = "\x08";
1096 GetMenuItem(menu, param2, Option, 32, 0, "", 0);
1097 ExplodeString(Option, " ", Temp, 2, 8, false);
1098 new target = GetClientOfUserId(StringToInt(Temp[0][Temp], 10));
1099 if (Bool_ValidMenuTarget(param1, target))
1100 {
1101 new type = StringToInt(Temp[1], 10);
1102 if (type <= 3)
1103 {
1104 AdminMenu_Duration(param1, target, type);
1105 }
1106 else
1107 {
1108 ProcessUnBlock(param1, target, type, "", "");
1109 }
1110 }
1111 }
1112 case 8:
1113 {
1114 new var1;
1115 if (param2 == -6 && hTopMenu)
1116 {
1117 DisplayTopMenu(hTopMenu, param1, TopMenuPosition:3);
1118 }
1119 }
1120 case 16:
1121 {
1122 CloseHandle(menu);
1123 }
1124 default:
1125 {
1126 }
1127 }
1128 return 0;
1129}
1130
1131AdminMenu_Duration(client, target, type)
1132{
1133 new Handle:hMenu = CreateMenu(MenuHandler_MenuDuration, MenuAction:28);
1134 decl String:sBuffer[192];
1135 decl String:sTemp[64];
1136 Format(sBuffer, 192, "%T", "AdminMenu_Title_Durations", client);
1137 SetMenuTitle(hMenu, sBuffer);
1138 SetMenuExitBackButton(hMenu, true);
1139 new i;
1140 while (i <= iNumTimes)
1141 {
1142 if (IsAllowedBlockLength(client, g_iTimeMinutes[i], 1))
1143 {
1144 Format(sTemp, 64, "%d %d %d", GetClientUserId(target), type, i);
1145 AddMenuItem(hMenu, sTemp, g_sTimeDisplays[i], 0);
1146 }
1147 i++;
1148 }
1149 DisplayMenu(hMenu, client, 0);
1150 return 0;
1151}
1152
1153public MenuHandler_MenuDuration(Handle:menu, MenuAction:action, param1, param2)
1154{
1155 switch (action)
1156 {
1157 case 4:
1158 {
1159 decl String:sOption[32];
1160 new String:sTemp[3][8] = "";
1161 GetMenuItem(menu, param2, sOption, 32, 0, "", 0);
1162 ExplodeString(sOption, " ", sTemp, 3, 8, false);
1163 new target = GetClientOfUserId(StringToInt(sTemp[0][sTemp], 10));
1164 if (Bool_ValidMenuTarget(param1, target))
1165 {
1166 new type = StringToInt(sTemp[1], 10);
1167 new lengthIndex = StringToInt(sTemp[2], 10);
1168 if (iNumReasons)
1169 {
1170 AdminMenu_Reason(param1, target, type, lengthIndex);
1171 }
1172 else
1173 {
1174 CreateBlock(param1, target, g_iTimeMinutes[lengthIndex], type, "", "");
1175 }
1176 }
1177 }
1178 case 8:
1179 {
1180 new var1;
1181 if (param2 == -6 && hTopMenu)
1182 {
1183 DisplayTopMenu(hTopMenu, param1, TopMenuPosition:3);
1184 }
1185 }
1186 case 16:
1187 {
1188 CloseHandle(menu);
1189 }
1190 default:
1191 {
1192 }
1193 }
1194 return 0;
1195}
1196
1197AdminMenu_Reason(client, target, type, lengthIndex)
1198{
1199 new Handle:hMenu = CreateMenu(MenuHandler_MenuReason, MenuAction:28);
1200 decl String:sBuffer[192];
1201 decl String:sTemp[64];
1202 Format(sBuffer, 192, "%T", "AdminMenu_Title_Reasons", client);
1203 SetMenuTitle(hMenu, sBuffer);
1204 SetMenuExitBackButton(hMenu, true);
1205 new i;
1206 while (i <= iNumReasons)
1207 {
1208 Format(sTemp, 64, "%d %d %d %d", GetClientUserId(target), type, i, lengthIndex);
1209 AddMenuItem(hMenu, sTemp, g_sReasonDisplays[i], 0);
1210 i++;
1211 }
1212 DisplayMenu(hMenu, client, 0);
1213 return 0;
1214}
1215
1216public MenuHandler_MenuReason(Handle:menu, MenuAction:action, param1, param2)
1217{
1218 switch (action)
1219 {
1220 case 4:
1221 {
1222 decl String:sOption[64];
1223 new String:sTemp[4][8] = "";
1224 GetMenuItem(menu, param2, sOption, 64, 0, "", 0);
1225 ExplodeString(sOption, " ", sTemp, 4, 8, false);
1226 new target = GetClientOfUserId(StringToInt(sTemp[0][sTemp], 10));
1227 if (Bool_ValidMenuTarget(param1, target))
1228 {
1229 new type = StringToInt(sTemp[1], 10);
1230 new reasonIndex = StringToInt(sTemp[2], 10);
1231 new lengthIndex = StringToInt(sTemp[3], 10);
1232 new length;
1233 new var2;
1234 if (lengthIndex >= 0 && lengthIndex <= iNumTimes)
1235 {
1236 length = g_iTimeMinutes[lengthIndex];
1237 }
1238 else
1239 {
1240 length = DefaultTime;
1241 LogError("Wrong length index in menu - using default time");
1242 }
1243 CreateBlock(param1, target, length, type, g_sReasonKey[reasonIndex], "");
1244 }
1245 }
1246 case 8:
1247 {
1248 new var1;
1249 if (param2 == -6 && hTopMenu)
1250 {
1251 DisplayTopMenu(hTopMenu, param1, TopMenuPosition:3);
1252 }
1253 }
1254 case 16:
1255 {
1256 CloseHandle(menu);
1257 }
1258 default:
1259 {
1260 }
1261 }
1262 return 0;
1263}
1264
1265AdminMenu_List(client, index)
1266{
1267 decl String:sTitle[192];
1268 decl String:sOption[32];
1269 Format(sTitle, 192, "%T", "AdminMenu_Select_List", client);
1270 new iClients;
1271 new Handle:hMenu = CreateMenu(MenuHandler_MenuList, MenuAction:28);
1272 SetMenuTitle(hMenu, sTitle);
1273 if (!g_iPeskyPanels[client][4])
1274 {
1275 SetMenuExitBackButton(hMenu, true);
1276 }
1277 new i = 1;
1278 while (i <= MaxClients)
1279 {
1280 new var2;
1281 if (IsClientInGame(i) && !IsFakeClient(i) && (g_MuteType[i] > bType:0 || g_GagType[i] > bType:0))
1282 {
1283 iClients++;
1284 strcopy(sTitle, 192, g_sName[i]);
1285 AdminMenu_GetPunishPhrase(client, i, sTitle, 192);
1286 Format(sOption, 32, "%d", GetClientUserId(i));
1287 AddMenuItem(hMenu, sOption, sTitle, 0);
1288 }
1289 i++;
1290 }
1291 if (!iClients)
1292 {
1293 Format(sTitle, 192, "%T", "ListMenu_Option_Empty", client);
1294 AddMenuItem(hMenu, "0", sTitle, 1);
1295 }
1296 DisplayMenuAtItem(hMenu, client, index, 0);
1297 return 0;
1298}
1299
1300public MenuHandler_MenuList(Handle:menu, MenuAction:action, param1, param2)
1301{
1302 switch (action)
1303 {
1304 case 4:
1305 {
1306 decl String:sOption[32];
1307 GetMenuItem(menu, param2, sOption, 32, 0, "", 0);
1308 new target = GetClientOfUserId(StringToInt(sOption, 10));
1309 if (Bool_ValidMenuTarget(param1, target))
1310 {
1311 AdminMenu_ListTarget(param1, target, GetMenuSelectionPosition(), 0, 0);
1312 }
1313 else
1314 {
1315 AdminMenu_List(param1, GetMenuSelectionPosition());
1316 }
1317 }
1318 case 8:
1319 {
1320 if (!g_iPeskyPanels[param1][4])
1321 {
1322 new var1;
1323 if (param2 == -6 && hTopMenu)
1324 {
1325 DisplayTopMenu(hTopMenu, param1, TopMenuPosition:3);
1326 }
1327 }
1328 }
1329 case 16:
1330 {
1331 CloseHandle(menu);
1332 }
1333 default:
1334 {
1335 }
1336 }
1337 return 0;
1338}
1339
1340AdminMenu_ListTarget(client, target, index, viewMute, viewGag)
1341{
1342 new userid = GetClientUserId(target);
1343 new Handle:hMenu = CreateMenu(MenuHandler_MenuListTarget, MenuAction:28);
1344 decl String:sBuffer[192];
1345 decl String:sOption[32];
1346 SetMenuTitle(hMenu, g_sName[target]);
1347 SetMenuPagination(hMenu, 0);
1348 SetMenuExitButton(hMenu, true);
1349 SetMenuExitBackButton(hMenu, false);
1350 if (bType:0 < g_MuteType[target])
1351 {
1352 Format(sBuffer, 192, "%T", "ListMenu_Option_Mute", client);
1353 Format(sOption, 32, "0 %d %d %b %b", userid, index, viewMute, viewGag);
1354 AddMenuItem(hMenu, sOption, sBuffer, 0);
1355 if (viewMute)
1356 {
1357 Format(sBuffer, 192, "%T", "ListMenu_Option_Admin", client, g_sMuteAdminName[target]);
1358 AddMenuItem(hMenu, "", sBuffer, 1);
1359 decl String:sMuteTemp[192];
1360 decl String:_sMuteTime[192];
1361 Format(sMuteTemp, 192, "%T", "ListMenu_Option_Duration", client);
1362 if (g_MuteType[target] == bType:3)
1363 {
1364 Format(sBuffer, 192, "%s%T", sMuteTemp, "ListMenu_Option_Duration_Perm", client);
1365 }
1366 else
1367 {
1368 if (g_MuteType[target] == bType:2)
1369 {
1370 Format(sBuffer, 192, "%s%T", sMuteTemp, "ListMenu_Option_Duration_Time", client, g_iMuteLength[target]);
1371 }
1372 if (g_MuteType[target] == bType:1)
1373 {
1374 Format(sBuffer, 192, "%s%T", sMuteTemp, "ListMenu_Option_Duration_Temp", client);
1375 }
1376 Format(sBuffer, 192, "error");
1377 }
1378 AddMenuItem(hMenu, "", sBuffer, 1);
1379 FormatTime(_sMuteTime, 192, NULL_STRING, g_iMuteTime[target]);
1380 Format(sBuffer, 192, "%T", "ListMenu_Option_Issue", client, _sMuteTime);
1381 AddMenuItem(hMenu, "", sBuffer, 1);
1382 Format(sMuteTemp, 192, "%T", "ListMenu_Option_Expire", client);
1383 if (g_MuteType[target] == bType:3)
1384 {
1385 Format(sBuffer, 192, "%s%T", sMuteTemp, "ListMenu_Option_Expire_Perm", client);
1386 }
1387 else
1388 {
1389 if (g_MuteType[target] == bType:2)
1390 {
1391 FormatTime(_sMuteTime, 192, NULL_STRING, g_iMuteTime[target][g_iMuteLength[target] * 60]);
1392 Format(sBuffer, 192, "%s%T", sMuteTemp, "ListMenu_Option_Expire_Time", client, _sMuteTime);
1393 }
1394 if (g_MuteType[target] == bType:1)
1395 {
1396 Format(sBuffer, 192, "%s%T", sMuteTemp, "ListMenu_Option_Expire_Temp_Reconnect", client);
1397 }
1398 Format(sBuffer, 192, "error");
1399 }
1400 AddMenuItem(hMenu, "", sBuffer, 1);
1401 if (0 < strlen(g_sMuteReason[target]))
1402 {
1403 Format(sBuffer, 192, "%T", "ListMenu_Option_Reason", client);
1404 Format(sOption, 32, "1 %d %d %b %b", userid, index, viewMute, viewGag);
1405 AddMenuItem(hMenu, sOption, sBuffer, 0);
1406 }
1407 else
1408 {
1409 Format(sBuffer, 192, "%T", "ListMenu_Option_Reason_None", client);
1410 AddMenuItem(hMenu, "", sBuffer, 1);
1411 }
1412 }
1413 }
1414 if (bType:0 < g_GagType[target])
1415 {
1416 Format(sBuffer, 192, "%T", "ListMenu_Option_Gag", client);
1417 Format(sOption, 32, "2 %d %d %b %b", userid, index, viewMute, viewGag);
1418 AddMenuItem(hMenu, sOption, sBuffer, 0);
1419 if (viewGag)
1420 {
1421 Format(sBuffer, 192, "%T", "ListMenu_Option_Admin", client, g_sGagAdminName[target]);
1422 AddMenuItem(hMenu, "", sBuffer, 1);
1423 decl String:sGagTemp[192];
1424 decl String:_sGagTime[192];
1425 Format(sGagTemp, 192, "%T", "ListMenu_Option_Duration", client);
1426 if (g_GagType[target] == bType:3)
1427 {
1428 Format(sBuffer, 192, "%s%T", sGagTemp, "ListMenu_Option_Duration_Perm", client);
1429 }
1430 else
1431 {
1432 if (g_GagType[target] == bType:2)
1433 {
1434 Format(sBuffer, 192, "%s%T", sGagTemp, "ListMenu_Option_Duration_Time", client, g_iGagLength[target]);
1435 }
1436 if (g_GagType[target] == bType:1)
1437 {
1438 Format(sBuffer, 192, "%s%T", sGagTemp, "ListMenu_Option_Duration_Temp", client);
1439 }
1440 Format(sBuffer, 192, "error");
1441 }
1442 AddMenuItem(hMenu, "", sBuffer, 1);
1443 FormatTime(_sGagTime, 192, NULL_STRING, g_iGagTime[target]);
1444 Format(sBuffer, 192, "%T", "ListMenu_Option_Issue", client, _sGagTime);
1445 AddMenuItem(hMenu, "", sBuffer, 1);
1446 Format(sGagTemp, 192, "%T", "ListMenu_Option_Expire", client);
1447 if (g_GagType[target] == bType:3)
1448 {
1449 Format(sBuffer, 192, "%s%T", sGagTemp, "ListMenu_Option_Expire_Perm", client);
1450 }
1451 else
1452 {
1453 if (g_GagType[target] == bType:2)
1454 {
1455 FormatTime(_sGagTime, 192, NULL_STRING, g_iGagTime[target][g_iGagLength[target] * 60]);
1456 Format(sBuffer, 192, "%s%T", sGagTemp, "ListMenu_Option_Expire_Time", client, _sGagTime);
1457 }
1458 if (g_GagType[target] == bType:1)
1459 {
1460 Format(sBuffer, 192, "%s%T", sGagTemp, "ListMenu_Option_Expire_Temp_Reconnect", client);
1461 }
1462 Format(sBuffer, 192, "error");
1463 }
1464 AddMenuItem(hMenu, "", sBuffer, 1);
1465 if (0 < strlen(g_sGagReason[target]))
1466 {
1467 Format(sBuffer, 192, "%T", "ListMenu_Option_Reason", client);
1468 Format(sOption, 32, "3 %d %d %b %b", userid, index, viewMute, viewGag);
1469 AddMenuItem(hMenu, sOption, sBuffer, 0);
1470 }
1471 else
1472 {
1473 Format(sBuffer, 192, "%T", "ListMenu_Option_Reason_None", client);
1474 AddMenuItem(hMenu, "", sBuffer, 1);
1475 }
1476 }
1477 }
1478 g_iPeskyPanels[client][1] = index;
1479 g_iPeskyPanels[client][0] = target;
1480 g_iPeskyPanels[client][3] = viewGag;
1481 g_iPeskyPanels[client][2] = viewMute;
1482 DisplayMenu(hMenu, client, 0);
1483 return 0;
1484}
1485
1486public MenuHandler_MenuListTarget(Handle:menu, MenuAction:action, param1, param2)
1487{
1488 switch (action)
1489 {
1490 case 4:
1491 {
1492 decl String:sOption[64];
1493 new String:sTemp[5][8] = "";
1494 GetMenuItem(menu, param2, sOption, 64, 0, "", 0);
1495 ExplodeString(sOption, " ", sTemp, 5, 8, false);
1496 new target = GetClientOfUserId(StringToInt(sTemp[1], 10));
1497 new var1;
1498 if (target != param1 && Bool_ValidMenuTarget(param1, target))
1499 {
1500 switch (StringToInt(sTemp[0][sTemp], 10))
1501 {
1502 case 0:
1503 {
1504 AdminMenu_ListTarget(param1, target, StringToInt(sTemp[2], 10), !StringToInt(sTemp[3], 10), 0);
1505 }
1506 case 1, 3:
1507 {
1508 AdminMenu_ListTargetReason(param1, target, g_iPeskyPanels[param1][2], g_iPeskyPanels[param1][3]);
1509 }
1510 case 2:
1511 {
1512 AdminMenu_ListTarget(param1, target, StringToInt(sTemp[2], 10), 0, !StringToInt(sTemp[4], 10));
1513 }
1514 default:
1515 {
1516 }
1517 }
1518 }
1519 else
1520 {
1521 AdminMenu_List(param1, StringToInt(sTemp[2], 10));
1522 }
1523 }
1524 case 8:
1525 {
1526 if (param2 == -6)
1527 {
1528 AdminMenu_List(param1, g_iPeskyPanels[param1][1]);
1529 }
1530 }
1531 case 16:
1532 {
1533 CloseHandle(menu);
1534 }
1535 default:
1536 {
1537 }
1538 }
1539 return 0;
1540}
1541
1542AdminMenu_ListTargetReason(client, target, showMute, showGag)
1543{
1544 decl String:sTemp[192];
1545 decl String:sBuffer[192];
1546 new Handle:hPanel = CreatePanel(Handle:0);
1547 SetPanelTitle(hPanel, g_sName[target], false);
1548 DrawPanelItem(hPanel, " ", 10);
1549 if (showMute)
1550 {
1551 Format(sTemp, 192, "%T", "ReasonPanel_Punishment_Mute", client);
1552 if (g_MuteType[target] == bType:3)
1553 {
1554 Format(sBuffer, 192, "%s%T", sTemp, "ReasonPanel_Perm", client);
1555 }
1556 else
1557 {
1558 if (g_MuteType[target] == bType:2)
1559 {
1560 Format(sBuffer, 192, "%s%T", sTemp, "ReasonPanel_Time", client, g_iMuteLength[target]);
1561 }
1562 if (g_MuteType[target] == bType:1)
1563 {
1564 Format(sBuffer, 192, "%s%T", sTemp, "ReasonPanel_Temp", client);
1565 }
1566 Format(sBuffer, 192, "error");
1567 }
1568 DrawPanelText(hPanel, sBuffer);
1569 Format(sBuffer, 192, "%T", "ReasonPanel_Reason", client, g_sMuteReason[target]);
1570 DrawPanelText(hPanel, sBuffer);
1571 }
1572 else
1573 {
1574 if (showGag)
1575 {
1576 Format(sTemp, 192, "%T", "ReasonPanel_Punishment_Gag", client);
1577 if (g_GagType[target] == bType:3)
1578 {
1579 Format(sBuffer, 192, "%s%T", sTemp, "ReasonPanel_Perm", client);
1580 }
1581 else
1582 {
1583 if (g_GagType[target] == bType:2)
1584 {
1585 Format(sBuffer, 192, "%s%T", sTemp, "ReasonPanel_Time", client, g_iGagLength[target]);
1586 }
1587 if (g_GagType[target] == bType:1)
1588 {
1589 Format(sBuffer, 192, "%s%T", sTemp, "ReasonPanel_Temp", client);
1590 }
1591 Format(sBuffer, 192, "error");
1592 }
1593 DrawPanelText(hPanel, sBuffer);
1594 Format(sBuffer, 192, "%T", "ReasonPanel_Reason", client, g_sGagReason[target]);
1595 DrawPanelText(hPanel, sBuffer);
1596 }
1597 }
1598 DrawPanelItem(hPanel, " ", 10);
1599 SetPanelCurrentKey(hPanel, 10);
1600 Format(sBuffer, 192, "%T", "ReasonPanel_Back", client);
1601 DrawPanelItem(hPanel, sBuffer, 0);
1602 SendPanelToClient(hPanel, client, PanelHandler_ListTargetReason, 0);
1603 CloseHandle(hPanel);
1604 return 0;
1605}
1606
1607public PanelHandler_ListTargetReason(Handle:menu, MenuAction:action, param1, param2)
1608{
1609 switch (action)
1610 {
1611 case 4:
1612 {
1613 AdminMenu_ListTarget(param1, g_iPeskyPanels[param1][0], g_iPeskyPanels[param1][1], g_iPeskyPanels[param1][2], g_iPeskyPanels[param1][3]);
1614 }
1615 default:
1616 {
1617 }
1618 }
1619 return 0;
1620}
1621
1622public GotDatabase(Handle:owner, Handle:hndl, String:error[], any:data)
1623{
1624 new var1;
1625 if (g_iConnectLock == data && g_hDatabase)
1626 {
1627 if (hndl)
1628 {
1629 CloseHandle(hndl);
1630 }
1631 return 0;
1632 }
1633 g_iConnectLock = 0;
1634 g_DatabaseState = MissingTAG:3;
1635 g_hDatabase = hndl;
1636 if (!g_hDatabase)
1637 {
1638 LogError("Connecting to database failed: %s", error);
1639 return 0;
1640 }
1641 if (GetFeatureStatus(FeatureType:0, "SQL_SetCharset"))
1642 {
1643 decl String:query[128];
1644 FormatEx(query, 128, "SET NAMES 'UTF8'");
1645 SQL_TQuery(g_hDatabase, Query_ErrorCheck, query, any:0, DBPriority:1);
1646 }
1647 else
1648 {
1649 SQL_SetCharset(g_hDatabase, "utf8");
1650 }
1651 SQL_TQuery(SQLiteDB, Query_ProcessQueue, "SELECT id, steam_id, time, start_time, reason, name, admin_id, admin_ip, type FROM queue2", any:0, DBPriority:1);
1652 ForcePlayersRecheck();
1653 return 0;
1654}
1655
1656public Query_AddBlockInsert(Handle:owner, Handle:hndl, String:error[], any:data)
1657{
1658 new var1;
1659 if (DB_Conn_Lost(hndl) || error[0])
1660 {
1661 LogError("Query_AddBlockInsert failed: %s", error);
1662 ResetPack(data, false);
1663 new length = ReadPackCell(data);
1664 new type = ReadPackCell(data);
1665 new String:reason[256];
1666 new String:name[32];
1667 new String:auth[64];
1668 new String:adminAuth[32];
1669 new String:adminIp[20];
1670 ReadPackString(data, name, 32);
1671 ReadPackString(data, auth, 64);
1672 ReadPackString(data, reason, 256);
1673 ReadPackString(data, adminAuth, 32);
1674 ReadPackString(data, adminIp, 20);
1675 InsertTempBlock(length, type, name, auth, reason, adminAuth, adminIp);
1676 }
1677 CloseHandle(data);
1678 return 0;
1679}
1680
1681public Query_UnBlockSelect(Handle:owner, Handle:hndl, String:error[], any:data)
1682{
1683 decl String:adminAuth[32];
1684 decl String:targetAuth[32];
1685 decl String:reason[256];
1686 ResetPack(data, false);
1687 new adminUserID = ReadPackCell(data);
1688 new targetUserID = ReadPackCell(data);
1689 new type = ReadPackCell(data);
1690 ReadPackString(data, adminAuth, 30);
1691 ReadPackString(data, targetAuth, 30);
1692 ReadPackString(data, reason, 256);
1693 new admin = GetClientOfUserId(adminUserID);
1694 new target = GetClientOfUserId(targetUserID);
1695 new String:targetName[32];
1696 new var1;
1697 if (target && IsClientInGame(target))
1698 {
1699 var2[0] = g_sName[target];
1700 }
1701 else
1702 {
1703 var2[0] = targetAuth;
1704 }
1705 strcopy(targetName, 32, var2);
1706 new bool:hasErrors;
1707 new var3;
1708 if (DB_Conn_Lost(hndl) || error[0])
1709 {
1710 LogError("Query_UnBlockSelect failed: %s", error);
1711 new var4;
1712 if (admin && IsClientInGame(admin))
1713 {
1714 PrintToChat(admin, "%s%T", "\x04[SourceComms]\x01 ", "Unblock Select Failed", admin, targetAuth);
1715 PrintToConsole(admin, "%s%T", "\x04[SourceComms]\x01 ", "Unblock Select Failed", admin, targetAuth);
1716 }
1717 else
1718 {
1719 PrintToServer("%s%T", "\x04[SourceComms]\x01 ", "Unblock Select Failed", 0, targetAuth);
1720 }
1721 hasErrors = true;
1722 }
1723 new var5;
1724 if (!DB_Conn_Lost(hndl) && !SQL_GetRowCount(hndl))
1725 {
1726 new var6;
1727 if (admin && IsClientInGame(admin))
1728 {
1729 PrintToChat(admin, "%s%t", "\x04[SourceComms]\x01 ", "No blocks found", targetAuth);
1730 PrintToConsole(admin, "%s%t", "\x04[SourceComms]\x01 ", "No blocks found", targetAuth);
1731 }
1732 else
1733 {
1734 PrintToServer("%s%T", "\x04[SourceComms]\x01 ", "No blocks found", 0, targetAuth);
1735 }
1736 hasErrors = true;
1737 }
1738 if (hasErrors)
1739 {
1740 TempUnBlock(data);
1741 return 0;
1742 }
1743 new bool:b_success;
1744 while (SQL_MoreRows(hndl))
1745 {
1746 if (SQL_FetchRow(hndl))
1747 {
1748 new bid = SQL_FetchInt(hndl, 0, 0);
1749 new iAID = SQL_FetchInt(hndl, 1, 0);
1750 new cAID = SQL_FetchInt(hndl, 2, 0);
1751 new cImmunity = SQL_FetchInt(hndl, 3, 0);
1752 new cType = SQL_FetchInt(hndl, 4, 0);
1753 new var9;
1754 if (cAID != iAID && (!admin && StrEqual(adminAuth, "STEAM_ID_SERVER", true)) && AdmHasFlag(admin) && (DisUBImCheck && GetAdmImmunity(admin) > cImmunity))
1755 {
1756 b_success = true;
1757 new var10;
1758 if (target && IsClientInGame(target))
1759 {
1760 switch (cType)
1761 {
1762 case 1:
1763 {
1764 PerformUnMute(target);
1765 LogAction(admin, target, "\"%L\" unmuted \"%L\" (reason \"%s\")", admin, target, reason);
1766 }
1767 case 2:
1768 {
1769 PerformUnGag(target);
1770 LogAction(admin, target, "\"%L\" ungagged \"%L\" (reason \"%s\")", admin, target, reason);
1771 }
1772 default:
1773 {
1774 }
1775 }
1776 }
1777 new Handle:dataPack = CreateDataPack();
1778 WritePackCell(dataPack, adminUserID);
1779 WritePackCell(dataPack, cType);
1780 WritePackString(dataPack, g_sName[target]);
1781 WritePackString(dataPack, targetAuth);
1782 new String:unbanReason[516];
1783 SQL_EscapeString(g_hDatabase, reason, unbanReason, 513, 0);
1784 decl String:query[2048];
1785 Format(query, 2048, "UPDATE %s_comms SET RemovedBy = %d, RemoveType = 'U', RemovedOn = UNIX_TIMESTAMP(), ureason = '%s' WHERE bid = %d", DatabasePrefix, iAID, unbanReason, bid);
1786 SQL_TQuery(g_hDatabase, Query_UnBlockUpdate, query, dataPack, DBPriority:1);
1787 }
1788 else
1789 {
1790 switch (cType)
1791 {
1792 case 1:
1793 {
1794 new var12;
1795 if (admin && IsClientInGame(admin))
1796 {
1797 PrintToChat(admin, "%s%t", "\x04[SourceComms]\x01 ", "No permission unmute", targetName);
1798 PrintToConsole(admin, "%s%t", "\x04[SourceComms]\x01 ", "No permission unmute", targetName);
1799 }
1800 LogAction(admin, target, "\"%L\" tried (and didn't have permission) to unmute %s (reason \"%s\")", admin, targetAuth, reason);
1801 }
1802 case 2:
1803 {
1804 new var11;
1805 if (admin && IsClientInGame(admin))
1806 {
1807 PrintToChat(admin, "%s%t", "\x04[SourceComms]\x01 ", "No permission ungag", targetName);
1808 PrintToConsole(admin, "%s%t", "\x04[SourceComms]\x01 ", "No permission ungag", targetName);
1809 }
1810 LogAction(admin, target, "\"%L\" tried (and didn't have permission) to ungag %s (reason \"%s\")", admin, targetAuth, reason);
1811 }
1812 default:
1813 {
1814 }
1815 }
1816 }
1817 }
1818 }
1819 new var13;
1820 if (b_success && target && IsClientInGame(target))
1821 {
1822 ShowActivityToServer(admin, type, 0, "", g_sName[target], false);
1823 if (type == 6)
1824 {
1825 SetPackPosition(data, 16);
1826 if (bType:0 < g_MuteType[target])
1827 {
1828 WritePackCell(data, 4);
1829 TempUnBlock(data);
1830 data = MissingTAG:0;
1831 }
1832 if (bType:0 < g_GagType[target])
1833 {
1834 WritePackCell(data, 5);
1835 TempUnBlock(data);
1836 data = MissingTAG:0;
1837 }
1838 }
1839 }
1840 if (data)
1841 {
1842 CloseHandle(data);
1843 }
1844 return 0;
1845}
1846
1847public Query_UnBlockUpdate(Handle:owner, Handle:hndl, String:error[], any:data)
1848{
1849 new admin;
1850 new type;
1851 new String:targetName[32];
1852 new String:targetAuth[32];
1853 ResetPack(data, false);
1854 admin = GetClientOfUserId(ReadPackCell(data));
1855 type = ReadPackCell(data);
1856 ReadPackString(data, targetName, 32);
1857 ReadPackString(data, targetAuth, 30);
1858 CloseHandle(data);
1859 new var1;
1860 if (DB_Conn_Lost(hndl) || error[0])
1861 {
1862 LogError("Query_UnBlockUpdate failed: %s", error);
1863 new var2;
1864 if (admin && IsClientInGame(admin))
1865 {
1866 PrintToChat(admin, "%s%t", "\x04[SourceComms]\x01 ", "Unblock insert failed");
1867 PrintToConsole(admin, "%s%t", "\x04[SourceComms]\x01 ", "Unblock insert failed");
1868 }
1869 return 0;
1870 }
1871 switch (type)
1872 {
1873 case 1:
1874 {
1875 LogAction(admin, -1, "\"%L\" removed mute for %s from DB", admin, targetAuth);
1876 new var4;
1877 if (admin && IsClientInGame(admin))
1878 {
1879 PrintToChat(admin, "%s%t", "\x04[SourceComms]\x01 ", "successfully unmuted", targetName);
1880 PrintToConsole(admin, "%s%t", "\x04[SourceComms]\x01 ", "successfully unmuted", targetName);
1881 }
1882 else
1883 {
1884 PrintToServer("%s%T", "\x04[SourceComms]\x01 ", "successfully unmuted", 0, targetName);
1885 }
1886 }
1887 case 2:
1888 {
1889 LogAction(admin, -1, "\"%L\" removed gag for %s from DB", admin, targetAuth);
1890 new var3;
1891 if (admin && IsClientInGame(admin))
1892 {
1893 PrintToChat(admin, "%s%t", "\x04[SourceComms]\x01 ", "successfully ungagged", targetName);
1894 PrintToConsole(admin, "%s%t", "\x04[SourceComms]\x01 ", "successfully ungagged", targetName);
1895 }
1896 else
1897 {
1898 PrintToServer("%s%T", "\x04[SourceComms]\x01 ", "successfully ungagged", 0, targetName);
1899 }
1900 }
1901 default:
1902 {
1903 }
1904 }
1905 return 0;
1906}
1907
1908public Query_ProcessQueue(Handle:owner, Handle:hndl, String:error[], any:data)
1909{
1910 new var1;
1911 if (hndl && error[0])
1912 {
1913 LogError("Query_ProcessQueue failed: %s", error);
1914 return 0;
1915 }
1916 decl String:auth[64];
1917 new String:name[32];
1918 decl String:reason[256];
1919 decl String:adminAuth[64];
1920 decl String:adminIp[20];
1921 decl String:query[4096];
1922 while (SQL_MoreRows(hndl))
1923 {
1924 if (SQL_FetchRow(hndl))
1925 {
1926 new String:sAuthEscaped[132];
1927 new String:banName[68];
1928 new String:banReason[516];
1929 new String:sAdmAuthEscaped[132];
1930 new String:sAdmAuthYZEscaped[132];
1931 new id = SQL_FetchInt(hndl, 0, 0);
1932 SQL_FetchString(hndl, 1, auth, 64, 0);
1933 new time = SQL_FetchInt(hndl, 2, 0);
1934 new startTime = SQL_FetchInt(hndl, 3, 0);
1935 SQL_FetchString(hndl, 4, reason, 256, 0);
1936 SQL_FetchString(hndl, 5, name, 32, 0);
1937 SQL_FetchString(hndl, 6, adminAuth, 64, 0);
1938 SQL_FetchString(hndl, 7, adminIp, 20, 0);
1939 new type = SQL_FetchInt(hndl, 8, 0);
1940 if (DB_Connect())
1941 {
1942 SQL_EscapeString(g_hDatabase, auth, sAuthEscaped, 129, 0);
1943 SQL_EscapeString(g_hDatabase, name, banName, 65, 0);
1944 SQL_EscapeString(g_hDatabase, reason, banReason, 513, 0);
1945 SQL_EscapeString(g_hDatabase, adminAuth, sAdmAuthEscaped, 129, 0);
1946 SQL_EscapeString(g_hDatabase, adminAuth[2], sAdmAuthYZEscaped, 129, 0);
1947 FormatEx(query, 4096, "INSERT INTO %s_comms (authid, name, created, ends, length, reason, aid, adminIp, sid, type) VALUES ('%s', '%s', %d, %d, %d, '%s', IFNULL((SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '0'), '%s', %d, %d)", DatabasePrefix, sAuthEscaped, banName, startTime, time * 60 + startTime, time * 60, banReason, DatabasePrefix, sAdmAuthEscaped, sAdmAuthYZEscaped, adminIp, serverID, type);
1948 SQL_TQuery(g_hDatabase, Query_AddBlockFromQueue, query, id, DBPriority:1);
1949 }
1950 }
1951 }
1952 return 0;
1953}
1954
1955public Query_AddBlockFromQueue(Handle:owner, Handle:hndl, String:error[], any:data)
1956{
1957 decl String:query[512];
1958 if (!error[0])
1959 {
1960 FormatEx(query, 512, "DELETE FROM queue2 WHERE id = %d", data);
1961 SQL_TQuery(SQLiteDB, Query_ErrorCheck, query, any:0, DBPriority:1);
1962 }
1963 return 0;
1964}
1965
1966public Query_ErrorCheck(Handle:owner, Handle:hndl, String:error[], any:data)
1967{
1968 new var1;
1969 if (DB_Conn_Lost(hndl) || error[0])
1970 {
1971 LogError("%T (%s)", "Failed to query database", 0, error);
1972 }
1973 return 0;
1974}
1975
1976public Query_VerifyBlock(Handle:owner, Handle:hndl, String:error[], any:userid)
1977{
1978 decl String:clientAuth[64];
1979 new client = GetClientOfUserId(userid);
1980 if (!client)
1981 {
1982 return 0;
1983 }
1984 if (DB_Conn_Lost(hndl))
1985 {
1986 LogError("Query_VerifyBlock failed: %s", error);
1987 if (!g_hPlayerRecheck[client])
1988 {
1989 g_hPlayerRecheck[client] = CreateTimer(RetryTime, ClientRecheck, userid, 0);
1990 }
1991 return 0;
1992 }
1993 GetClientAuthString(client, clientAuth, 64, true);
1994 if (0 < SQL_GetRowCount(hndl))
1995 {
1996 while (SQL_FetchRow(hndl))
1997 {
1998 if (!(NotApplyToThisServer(SQL_FetchInt(hndl, 8, 0))))
1999 {
2000 new String:sReason[256];
2001 new String:sAdmName[32];
2002 new String:sAdmAuth[64];
2003 new remaining_time = SQL_FetchInt(hndl, 0, 0);
2004 new length = SQL_FetchInt(hndl, 1, 0);
2005 new type = SQL_FetchInt(hndl, 2, 0);
2006 new time = SQL_FetchInt(hndl, 3, 0);
2007 SQL_FetchString(hndl, 4, sReason, 256, 0);
2008 SQL_FetchString(hndl, 5, sAdmName, 32, 0);
2009 new immunity = SQL_FetchInt(hndl, 6, 0);
2010 new aid = SQL_FetchInt(hndl, 7, 0);
2011 SQL_FetchString(hndl, 9, sAdmAuth, 64, 0);
2012 new var1;
2013 if (!aid && ConsoleImmunity > immunity)
2014 {
2015 immunity = ConsoleImmunity;
2016 }
2017 switch (type)
2018 {
2019 case 1:
2020 {
2021 if (g_MuteType[client] < bType:2)
2022 {
2023 PerformMute(client, time, length / 60, sAdmName, sAdmAuth, immunity, sReason, remaining_time);
2024 PrintToChat(client, "%s%t", "\x04[SourceComms]\x01 ", "Muted on connect");
2025 }
2026 }
2027 case 2:
2028 {
2029 if (g_GagType[client] < bType:2)
2030 {
2031 PerformGag(client, time, length / 60, sAdmName, sAdmAuth, immunity, sReason, remaining_time);
2032 PrintToChat(client, "%s%t", "\x04[SourceComms]\x01 ", "Gagged on connect");
2033 }
2034 }
2035 default:
2036 {
2037 }
2038 }
2039 }
2040 }
2041 }
2042 g_bPlayerStatus[client] = 1;
2043 return 0;
2044}
2045
2046public Action:ClientRecheck(Handle:timer, any:userid)
2047{
2048 new client = GetClientOfUserId(userid);
2049 if (!client)
2050 {
2051 return Action:0;
2052 }
2053 if (IsClientConnected(client))
2054 {
2055 OnClientPostAdminCheck(client);
2056 }
2057 g_hPlayerRecheck[client] = 0;
2058 return Action:0;
2059}
2060
2061public Action:Timer_MuteExpire(Handle:timer, any:userid)
2062{
2063 new client = GetClientOfUserId(userid);
2064 if (!client)
2065 {
2066 return Action:0;
2067 }
2068 PrintToChat(client, "%s%t", "\x04[SourceComms]\x01 ", "Mute expired");
2069 g_hMuteExpireTimer[client] = 0;
2070 MarkClientAsUnMuted(client);
2071 if (IsClientInGame(client))
2072 {
2073 BaseComm_SetClientMute(client, false);
2074 }
2075 return Action:0;
2076}
2077
2078public Action:Timer_GagExpire(Handle:timer, any:userid)
2079{
2080 new client = GetClientOfUserId(userid);
2081 if (!client)
2082 {
2083 return Action:0;
2084 }
2085 PrintToChat(client, "%s%t", "\x04[SourceComms]\x01 ", "Gag expired");
2086 g_hGagExpireTimer[client] = 0;
2087 MarkClientAsUnGagged(client);
2088 if (IsClientInGame(client))
2089 {
2090 BaseComm_SetClientGag(client, false);
2091 }
2092 return Action:0;
2093}
2094
2095public Action:Timer_StopWait(Handle:timer, any:data)
2096{
2097 g_DatabaseState = MissingTAG:0;
2098 DB_Connect();
2099 return Action:0;
2100}
2101
2102InitializeConfigParser()
2103{
2104 if (!ConfigParser)
2105 {
2106 ConfigParser = SMC_CreateParser();
2107 SMC_SetReaders(ConfigParser, ReadConfig_NewSection, ReadConfig_KeyValue, ReadConfig_EndSection);
2108 }
2109 return 0;
2110}
2111
2112InternalReadConfig(String:path[])
2113{
2114 ConfigState = MissingTAG:0;
2115 new SMCError:err = SMC_ParseFile(ConfigParser, path, 0, 0);
2116 if (err)
2117 {
2118 decl String:buffer[64];
2119 if (SMC_GetErrorString(err, buffer, 64))
2120 {
2121 PrintToServer(buffer);
2122 }
2123 else
2124 {
2125 PrintToServer("Fatal parse error");
2126 }
2127 }
2128 return 0;
2129}
2130
2131public SMCResult:ReadConfig_NewSection(Handle:smc, String:name[], bool:opt_quotes)
2132{
2133 if (name[0])
2134 {
2135 if (strcmp("Config", name, false))
2136 {
2137 if (strcmp("CommsReasons", name, false))
2138 {
2139 if (strcmp("CommsTimes", name, false))
2140 {
2141 if (!(strcmp("ServersWhiteList", name, false)))
2142 {
2143 ConfigState = MissingTAG:4;
2144 }
2145 }
2146 ConfigState = MissingTAG:3;
2147 }
2148 ConfigState = MissingTAG:2;
2149 }
2150 ConfigState = MissingTAG:1;
2151 }
2152 return SMCResult:0;
2153}
2154
2155public SMCResult:ReadConfig_KeyValue(Handle:smc, String:key[], String:value[], bool:key_quotes, bool:value_quotes)
2156{
2157 if (!key[0])
2158 {
2159 return SMCResult:0;
2160 }
2161 switch (ConfigState)
2162 {
2163 case 1:
2164 {
2165 if (strcmp("DatabasePrefix", key, false))
2166 {
2167 if (strcmp("RetryTime", key, false))
2168 {
2169 if (strcmp("ServerID", key, false))
2170 {
2171 if (strcmp("DefaultTime", key, false))
2172 {
2173 if (strcmp("DisableUnblockImmunityCheck", key, false))
2174 {
2175 if (strcmp("ConsoleImmunity", key, false))
2176 {
2177 if (strcmp("MaxLength", key, false))
2178 {
2179 if (!(strcmp("OnlyWhiteListServers", key, false)))
2180 {
2181 ConfigWhiteListOnly = StringToInt(value, 10);
2182 if (ConfigWhiteListOnly != 1)
2183 {
2184 ConfigWhiteListOnly = 0;
2185 }
2186 }
2187 }
2188 ConfigMaxLength = StringToInt(value, 10);
2189 }
2190 ConsoleImmunity = StringToInt(value, 10);
2191 new var2;
2192 if (ConsoleImmunity < 0 || ConsoleImmunity > 100)
2193 {
2194 ConsoleImmunity = 0;
2195 }
2196 }
2197 DisUBImCheck = StringToInt(value, 10);
2198 if (DisUBImCheck != 1)
2199 {
2200 DisUBImCheck = 0;
2201 }
2202 }
2203 DefaultTime = StringToInt(value, 10);
2204 if (0 > DefaultTime)
2205 {
2206 DefaultTime = -1;
2207 }
2208 if (DefaultTime)
2209 {
2210 }
2211 else
2212 {
2213 DefaultTime = 30;
2214 }
2215 }
2216 new var1;
2217 if (!StringToIntEx(value, serverID, 10) || serverID < 1)
2218 {
2219 serverID = 0;
2220 }
2221 }
2222 RetryTime = StringToFloat(value);
2223 if (RetryTime < 15.0)
2224 {
2225 RetryTime = 15.0;
2226 }
2227 else
2228 {
2229 if (RetryTime > 60.0)
2230 {
2231 RetryTime = 60.0;
2232 }
2233 }
2234 }
2235 else
2236 {
2237 strcopy(DatabasePrefix, 10, value);
2238 if (DatabasePrefix[0])
2239 {
2240 }
2241 }
2242 }
2243 case 2:
2244 {
2245 Format(g_sReasonKey[iNumReasons], 192, "%s", key);
2246 Format(g_sReasonDisplays[iNumReasons], 64, "%s", value);
2247 iNumReasons += 1;
2248 }
2249 case 3:
2250 {
2251 Format(g_sTimeDisplays[iNumTimes], 64, "%s", value);
2252 g_iTimeMinutes[iNumTimes] = StringToInt(key, 10);
2253 iNumTimes += 1;
2254 }
2255 case 4:
2256 {
2257 if (strcmp("id", key, false))
2258 {
2259 }
2260 else
2261 {
2262 new srvID = StringToInt(value, 10);
2263 if (0 <= srvID)
2264 {
2265 PushArrayCell(g_hServersWhiteList, srvID);
2266 }
2267 }
2268 }
2269 default:
2270 {
2271 }
2272 }
2273 return SMCResult:0;
2274}
2275
2276public SMCResult:ReadConfig_EndSection(Handle:smc)
2277{
2278 return SMCResult:0;
2279}
2280
2281bool:DB_Connect()
2282{
2283 if (g_hDatabase)
2284 {
2285 return true;
2286 }
2287 if (g_DatabaseState == DatabaseState:1)
2288 {
2289 return false;
2290 }
2291 if (g_DatabaseState != DatabaseState:2)
2292 {
2293 g_DatabaseState = MissingTAG:2;
2294 g_iSequence += 1;
2295 g_iConnectLock = g_iSequence;
2296 SQL_TConnect(GotDatabase, "sourcecomms", g_iConnectLock);
2297 }
2298 return false;
2299}
2300
2301bool:DB_Conn_Lost(Handle:hndl)
2302{
2303 if (hndl)
2304 {
2305 return false;
2306 }
2307 if (g_hDatabase)
2308 {
2309 LogError("Lost connection to DB. Reconnect after delay.");
2310 CloseHandle(g_hDatabase);
2311 g_hDatabase = MissingTAG:0;
2312 }
2313 if (g_DatabaseState != DatabaseState:1)
2314 {
2315 g_DatabaseState = MissingTAG:1;
2316 CreateTimer(RetryTime, Timer_StopWait, any:0, 2);
2317 }
2318 return true;
2319}
2320
2321InitializeBackupDB()
2322{
2323 decl String:error[256];
2324 SQLiteDB = SQLite_UseDatabase("sourcecomms-queue", error, 255);
2325 if (!SQLiteDB)
2326 {
2327 SetFailState(error);
2328 }
2329 SQL_TQuery(SQLiteDB, Query_ErrorCheck, "CREATE TABLE IF NOT EXISTS queue2 ( id INTEGER PRIMARY KEY, steam_id TEXT, time INTEGER, start_time INTEGER, reason TEXT, name TEXT, admin_id TEXT, admin_ip TEXT, type INTEGER)", any:0, DBPriority:1);
2330 return 0;
2331}
2332
2333CreateBlock(client, targetId, length, type, String:sReason[], String:sArgs[])
2334{
2335 decl target_list[65];
2336 decl target_count;
2337 decl bool:tn_is_ml;
2338 decl String:target_name[32];
2339 decl String:reason[256];
2340 new bool:skipped;
2341 if (targetId)
2342 {
2343 target_list[0] = targetId;
2344 target_count = 1;
2345 tn_is_ml = false;
2346 strcopy(target_name, 32, g_sName[targetId]);
2347 strcopy(reason, 256, sReason);
2348 }
2349 else
2350 {
2351 if (strlen(sArgs))
2352 {
2353 new String:sArg[3][192] = "";
2354 new var1;
2355 if (ExplodeString(sArgs, "\"", sArg, 3, 192, true) == 3 && strlen(sArg[0][sArg]))
2356 {
2357 new String:sTempArg[2][192] = "\x08";
2358 TrimString(sArg[2]);
2359 ExplodeString(sArg[2], " ", sTempArg, 2, 192, true);
2360 }
2361 else
2362 {
2363 ExplodeString(sArgs, " ", sArg, 3, 192, true);
2364 }
2365 if (0 >= (target_count = ProcessTargetString(sArg[0][sArg], client, target_list, 65, 32, target_name, 32, tn_is_ml)))
2366 {
2367 ReplyToTargetError(client, target_count);
2368 return 0;
2369 }
2370 if (!StringToIntEx(sArg[1], length, 10))
2371 {
2372 length = DefaultTime;
2373 Format(reason, 256, "%s %s", sArg[1], sArg[2]);
2374 }
2375 else
2376 {
2377 strcopy(reason, 256, sArg[2]);
2378 }
2379 TrimString(reason);
2380 StripQuotes(reason);
2381 if (!IsAllowedBlockLength(client, length, target_count))
2382 {
2383 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "no access");
2384 return 0;
2385 }
2386 }
2387 return 0;
2388 }
2389 new admImmunity = GetAdmImmunity(client);
2390 decl String:adminAuth[64];
2391 new var2;
2392 if (client && IsClientInGame(client))
2393 {
2394 GetClientAuthString(client, adminAuth, 64, true);
2395 }
2396 else
2397 {
2398 strcopy(adminAuth, 64, "STEAM_ID_SERVER");
2399 }
2400 new i;
2401 while (i < target_count)
2402 {
2403 new target = target_list[i];
2404 if (!g_bPlayerStatus[target])
2405 {
2406 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "Player Comms Not Verified");
2407 skipped = true;
2408 }
2409 else
2410 {
2411 switch (type)
2412 {
2413 case 1:
2414 {
2415 if (!BaseComm_IsClientMuted(target))
2416 {
2417 PerformMute(target, 0, length, g_sName[client], adminAuth, admImmunity, reason, 0);
2418 LogAction(client, target, "\"%L\" muted \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, length, reason);
2419 }
2420 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "Player already muted", g_sName[target]);
2421 skipped = true;
2422 }
2423 case 2:
2424 {
2425 if (!BaseComm_IsClientGagged(target))
2426 {
2427 PerformGag(target, 0, length, g_sName[client], adminAuth, admImmunity, reason, 0);
2428 LogAction(client, target, "\"%L\" gagged \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, length, reason);
2429 }
2430 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "Player already gagged", g_sName[target]);
2431 skipped = true;
2432 }
2433 case 3:
2434 {
2435 new var3;
2436 if (!BaseComm_IsClientGagged(target) && !BaseComm_IsClientMuted(target))
2437 {
2438 PerformMute(target, 0, length, g_sName[client], adminAuth, admImmunity, reason, 0);
2439 PerformGag(target, 0, length, g_sName[client], adminAuth, admImmunity, reason, 0);
2440 LogAction(client, target, "\"%L\" silenced \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, length, reason);
2441 }
2442 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "Player already silenced", g_sName[target]);
2443 skipped = true;
2444 }
2445 default:
2446 {
2447 }
2448 }
2449 }
2450 i++;
2451 }
2452 new var4;
2453 if (target_count == 1 && !skipped)
2454 {
2455 SavePunishment(client, target_list[0], type, length, reason);
2456 }
2457 new var5;
2458 if (target_count > 1 || !skipped)
2459 {
2460 ShowActivityToServer(client, type, length, reason, target_name, tn_is_ml);
2461 }
2462 return 0;
2463}
2464
2465ProcessUnBlock(client, targetId, type, String:sReason[], String:sArgs[])
2466{
2467 decl target_list[65];
2468 decl target_count;
2469 decl bool:tn_is_ml;
2470 decl String:target_name[32];
2471 decl String:reason[256];
2472 if (targetId)
2473 {
2474 target_list[0] = targetId;
2475 target_count = 1;
2476 tn_is_ml = false;
2477 strcopy(target_name, 32, g_sName[targetId]);
2478 strcopy(reason, 256, sReason);
2479 }
2480 else
2481 {
2482 new String:sBuffer[256];
2483 new String:sArg[3][192] = "";
2484 GetCmdArgString(sBuffer, 256);
2485 new var1;
2486 if (ExplodeString(sBuffer, "\"", sArg, 3, 192, true) == 3 && strlen(sArg[0][sArg]))
2487 {
2488 TrimString(sArg[2]);
2489 }
2490 else
2491 {
2492 ExplodeString(sBuffer, " ", sArg, 2, 192, true);
2493 }
2494 strcopy(reason, 256, sArg[1]);
2495 TrimString(reason);
2496 StripQuotes(reason);
2497 if (0 >= (target_count = ProcessTargetString(sArg[0][sArg], client, target_list, 65, 32, target_name, 32, tn_is_ml)))
2498 {
2499 ReplyToTargetError(client, target_count);
2500 return 0;
2501 }
2502 }
2503 decl String:adminAuth[64];
2504 decl String:targetAuth[64];
2505 new var2;
2506 if (client && IsClientInGame(client))
2507 {
2508 GetClientAuthString(client, adminAuth, 64, true);
2509 }
2510 else
2511 {
2512 strcopy(adminAuth, 64, "STEAM_ID_SERVER");
2513 }
2514 if (target_count > 1)
2515 {
2516 new i;
2517 while (i < target_count)
2518 {
2519 new target = target_list[i];
2520 if (IsClientInGame(target))
2521 {
2522 GetClientAuthString(target, targetAuth, 64, true);
2523 new Handle:dataPack = CreateDataPack();
2524 WritePackCell(dataPack, GetClientUserId2(client));
2525 WritePackCell(dataPack, GetClientUserId(target));
2526 WritePackCell(dataPack, type);
2527 WritePackString(dataPack, adminAuth);
2528 WritePackString(dataPack, targetAuth);
2529 WritePackString(dataPack, reason);
2530 TempUnBlock(dataPack);
2531 }
2532 i++;
2533 }
2534 ShowActivityToServer(client, type + 10, 0, "", target_name, tn_is_ml);
2535 }
2536 else
2537 {
2538 decl String:typeWHERE[100];
2539 new bool:dontCheckDB;
2540 new target = target_list[0];
2541 if (IsClientInGame(target))
2542 {
2543 GetClientAuthString(target, targetAuth, 64, true);
2544 switch (type)
2545 {
2546 case 4:
2547 {
2548 if (!BaseComm_IsClientMuted(target))
2549 {
2550 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "Player not muted");
2551 return 0;
2552 }
2553 FormatEx(typeWHERE, 100, "c.type = '%d'", 1);
2554 if (g_MuteType[target] == bType:1)
2555 {
2556 dontCheckDB = true;
2557 }
2558 }
2559 case 5:
2560 {
2561 if (!BaseComm_IsClientGagged(target))
2562 {
2563 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "Player not gagged");
2564 return 0;
2565 }
2566 FormatEx(typeWHERE, 100, "c.type = '%d'", 2);
2567 if (g_GagType[target] == bType:1)
2568 {
2569 dontCheckDB = true;
2570 }
2571 }
2572 case 6:
2573 {
2574 new var3;
2575 if (!BaseComm_IsClientMuted(target) || !BaseComm_IsClientGagged(target))
2576 {
2577 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "Player not silenced");
2578 return 0;
2579 }
2580 FormatEx(typeWHERE, 100, "(c.type = '%d' OR c.type = '%d')", 1, 2);
2581 new var4;
2582 if (g_MuteType[target] == bType:1 && g_GagType[target] == bType:1)
2583 {
2584 dontCheckDB = true;
2585 }
2586 }
2587 default:
2588 {
2589 }
2590 }
2591 new Handle:dataPack = CreateDataPack();
2592 WritePackCell(dataPack, GetClientUserId2(client));
2593 WritePackCell(dataPack, GetClientUserId(target));
2594 WritePackCell(dataPack, type);
2595 WritePackString(dataPack, adminAuth);
2596 WritePackString(dataPack, targetAuth);
2597 WritePackString(dataPack, reason);
2598 new var5;
2599 if (!dontCheckDB && DB_Connect())
2600 {
2601 new String:sAdminAuthEscaped[132];
2602 new String:sAdminAuthYZEscaped[132];
2603 new String:sTargetAuthEscaped[132];
2604 new String:sTargetAuthYZEscaped[132];
2605 SQL_EscapeString(g_hDatabase, adminAuth, sAdminAuthEscaped, 129, 0);
2606 SQL_EscapeString(g_hDatabase, adminAuth[2], sAdminAuthYZEscaped, 129, 0);
2607 SQL_EscapeString(g_hDatabase, targetAuth, sTargetAuthEscaped, 129, 0);
2608 SQL_EscapeString(g_hDatabase, targetAuth[2], sTargetAuthYZEscaped, 129, 0);
2609 decl String:query[4096];
2610 Format(query, 4096, "SELECT c.bid, IFNULL((SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '0') as iaid, c.aid, IF (a.immunity>=g.immunity, a.immunity, IFNULL(g.immunity,0)) as immunity, c.type FROM %s_comms AS c LEFT JOIN %s_admins AS a ON a.aid = c.aid LEFT JOIN %s_srvgroups AS g ON g.name = a.srv_group WHERE RemoveType IS NULL AND (c.authid = '%s' OR c.authid REGEXP '^STEAM_[0-9]:%s$') AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND %s", DatabasePrefix, sAdminAuthEscaped, sAdminAuthYZEscaped, DatabasePrefix, DatabasePrefix, DatabasePrefix, sTargetAuthEscaped, sTargetAuthYZEscaped, typeWHERE);
2611 SQL_TQuery(g_hDatabase, Query_UnBlockSelect, query, dataPack, DBPriority:1);
2612 }
2613 else
2614 {
2615 if (TempUnBlock(dataPack))
2616 {
2617 new String:sBuffer[256];
2618 ShowActivityToServer(client, type + 10, sBuffer, "", g_sName[target], false);
2619 }
2620 }
2621 }
2622 return 0;
2623 }
2624 return 0;
2625}
2626
2627bool:TempUnBlock(Handle:data)
2628{
2629 decl String:adminAuth[32];
2630 decl String:targetAuth[32];
2631 decl String:reason[256];
2632 ResetPack(data, false);
2633 new adminUserID = ReadPackCell(data);
2634 new targetUserID = ReadPackCell(data);
2635 new type = ReadPackCell(data);
2636 ReadPackString(data, adminAuth, 30);
2637 ReadPackString(data, targetAuth, 30);
2638 ReadPackString(data, reason, 256);
2639 CloseHandle(data);
2640 new admin = GetClientOfUserId(adminUserID);
2641 new target = GetClientOfUserId(targetUserID);
2642 if (!target)
2643 {
2644 return false;
2645 }
2646 new AdmImmunity = GetAdmImmunity(admin);
2647 decl bool:AdmImCheck;
2648 new var5;
2649 AdmImCheck = DisUBImCheck && ((type == 1 && AdmImmunity > g_iMuteLevel[target]) || (type == 2 && AdmImmunity > g_iGagLevel[target]) || (type == 3 && AdmImmunity > g_iMuteLevel[target] && AdmImmunity > g_iGagLevel[target]));
2650 decl bool:bHasPermission;
2651 new var6;
2652 bHasPermission = (!admin && StrEqual(adminAuth, "STEAM_ID_SERVER", true)) || (AdmHasFlag(admin) || AdmImCheck);
2653 if (!bHasPermission)
2654 {
2655 switch (type)
2656 {
2657 case 4:
2658 {
2659 bHasPermission = StrEqual(adminAuth, g_sMuteAdminAuth[target], true);
2660 }
2661 case 5:
2662 {
2663 bHasPermission = StrEqual(adminAuth, g_sGagAdminAuth[target], true);
2664 }
2665 case 6:
2666 {
2667 new var8;
2668 if (StrEqual(adminAuth, g_sMuteAdminAuth[target], true) && StrEqual(adminAuth, g_sGagAdminAuth[target], true))
2669 {
2670 }
2671 }
2672 default:
2673 {
2674 }
2675 }
2676 }
2677 if (bHasPermission)
2678 {
2679 switch (type)
2680 {
2681 case 4:
2682 {
2683 PerformUnMute(target);
2684 LogAction(admin, target, "\"%L\" temporary unmuted \"%L\" (reason \"%s\")", admin, target, reason);
2685 }
2686 case 5:
2687 {
2688 PerformUnGag(target);
2689 LogAction(admin, target, "\"%L\" temporary ungagged \"%L\" (reason \"%s\")", admin, target, reason);
2690 }
2691 case 6:
2692 {
2693 PerformUnMute(target);
2694 PerformUnGag(target);
2695 LogAction(admin, target, "\"%L\" temporary unsilenced \"%L\" (reason \"%s\")", admin, target, reason);
2696 }
2697 default:
2698 {
2699 return false;
2700 }
2701 }
2702 return true;
2703 }
2704 new var9;
2705 if (admin && IsClientInGame(admin))
2706 {
2707 PrintToChat(admin, "%s%t", "\x04[SourceComms]\x01 ", "No db error unlock perm");
2708 PrintToConsole(admin, "%s%t", "\x04[SourceComms]\x01 ", "No db error unlock perm");
2709 }
2710 return false;
2711}
2712
2713InsertTempBlock(length, type, String:name[], String:auth[], String:reason[], String:adminAuth[], String:adminIp[])
2714{
2715 LogMessage("Saving punishment for %s into queue", auth);
2716 new String:banName[68];
2717 new String:banReason[516];
2718 new String:sAuthEscaped[132];
2719 new String:sAdminAuthEscaped[132];
2720 decl String:sQuery[4096];
2721 decl String:sQueryVal[2048];
2722 new String:sQueryMute[2048];
2723 new String:sQueryGag[2048];
2724 SQL_EscapeString(SQLiteDB, name, banName, 65, 0);
2725 SQL_EscapeString(SQLiteDB, reason, banReason, 513, 0);
2726 SQL_EscapeString(SQLiteDB, auth, sAuthEscaped, 129, 0);
2727 SQL_EscapeString(SQLiteDB, adminAuth, sAdminAuthEscaped, 129, 0);
2728 FormatEx(sQueryVal, 2048, "'%s', %d, %d, '%s', '%s', '%s', '%s'", sAuthEscaped, length, GetTime({0,0}), banReason, banName, sAdminAuthEscaped, adminIp);
2729 new var1;
2730 if (type == 1 || type == 3)
2731 {
2732 FormatEx(sQueryMute, 2048, "(%s, %d)", sQueryVal, 1);
2733 }
2734 new var2;
2735 if (type == 2 || type == 3)
2736 {
2737 FormatEx(sQueryGag, 2048, "(%s, %d)", sQueryVal, 2);
2738 }
2739 new var3;
2740 if (type == 3)
2741 {
2742 var3[0] = 77480;
2743 }
2744 else
2745 {
2746 var3[0] = 77484;
2747 }
2748 FormatEx(sQuery, 4096, "INSERT INTO queue2 (steam_id, time, start_time, reason, name, admin_id, admin_ip, type) VALUES %s%s%s", sQueryMute, var3, sQueryGag);
2749 SQL_TQuery(SQLiteDB, Query_ErrorCheck, sQuery, any:0, DBPriority:1);
2750 return 0;
2751}
2752
2753ServerInfo()
2754{
2755 decl pieces[4];
2756 new longip = GetConVarInt(CvarHostIp);
2757 pieces[0] = longip >>> 24 & 255;
2758 pieces[1] = longip >>> 16 & 255;
2759 pieces[2] = longip >>> 8 & 255;
2760 pieces[3] = longip & 255;
2761 FormatEx(ServerIp, 24, "%d.%d.%d.%d", pieces, pieces[1], pieces[2], pieces[3]);
2762 GetConVarString(CvarPort, ServerPort, 7);
2763 return 0;
2764}
2765
2766ReadConfig()
2767{
2768 InitializeConfigParser();
2769 if (ConfigParser)
2770 {
2771 decl String:ConfigFile1[256];
2772 decl String:ConfigFile2[256];
2773 BuildPath(PathType:0, ConfigFile1, 256, "configs/sourcebans/sourcebans.cfg");
2774 BuildPath(PathType:0, ConfigFile2, 256, "configs/sourcebans/sourcecomms.cfg");
2775 if (FileExists(ConfigFile1, false))
2776 {
2777 PrintToServer("%sLoading configs/sourcebans/sourcebans.cfg config file", "\x04[SourceComms]\x01 ");
2778 InternalReadConfig(ConfigFile1);
2779 }
2780 else
2781 {
2782 SetFailState("FATAL *** ERROR *** can't find %s", ConfigFile1);
2783 }
2784 if (FileExists(ConfigFile2, false))
2785 {
2786 PrintToServer("%sLoading configs/sourcebans/sourcecomms.cfg config file", "\x04[SourceComms]\x01 ");
2787 iNumReasons = 0;
2788 iNumTimes = 0;
2789 InternalReadConfig(ConfigFile2);
2790 if (iNumReasons)
2791 {
2792 iNumReasons -= 1;
2793 }
2794 if (iNumTimes)
2795 {
2796 iNumTimes -= 1;
2797 }
2798 if (serverID)
2799 {
2800 }
2801 else
2802 {
2803 LogError("You must set valid `ServerID` value in sourcebans.cfg!");
2804 if (ConfigWhiteListOnly)
2805 {
2806 LogError("ServersWhiteList feature disabled!");
2807 ConfigWhiteListOnly = 0;
2808 }
2809 }
2810 }
2811 else
2812 {
2813 SetFailState("FATAL *** ERROR *** can't find %s", ConfigFile2);
2814 }
2815 return 0;
2816 }
2817 return 0;
2818}
2819
2820AdminMenu_GetPunishPhrase(client, target, String:name[], length)
2821{
2822 decl String:Buffer[192];
2823 new var1;
2824 if (g_MuteType[target] > bType:0 && g_GagType[target] > bType:0)
2825 {
2826 Format(Buffer, 192, "%T", "AdminMenu_Display_Silenced", client, name);
2827 }
2828 else
2829 {
2830 if (bType:0 < g_MuteType[target])
2831 {
2832 Format(Buffer, 192, "%T", "AdminMenu_Display_Muted", client, name);
2833 }
2834 if (bType:0 < g_GagType[target])
2835 {
2836 Format(Buffer, 192, "%T", "AdminMenu_Display_Gagged", client, name);
2837 }
2838 Format(Buffer, 192, "%T", "AdminMenu_Display_None", client, name);
2839 }
2840 strcopy(name, length, Buffer);
2841 return 0;
2842}
2843
2844bool:Bool_ValidMenuTarget(client, target)
2845{
2846 if (0 >= target)
2847 {
2848 if (client)
2849 {
2850 PrintToChat(client, "%s%t", "\x04[SourceComms]\x01 ", "AdminMenu_Not_Available");
2851 }
2852 else
2853 {
2854 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "AdminMenu_Not_Available");
2855 }
2856 return false;
2857 }
2858 if (!CanUserTarget(client, target))
2859 {
2860 if (client)
2861 {
2862 PrintToChat(client, "%s%t", "\x04[SourceComms]\x01 ", "Command_Target_Not_Targetable");
2863 }
2864 else
2865 {
2866 ReplyToCommand(client, "%s%t", "\x04[SourceComms]\x01 ", "Command_Target_Not_Targetable");
2867 }
2868 return false;
2869 }
2870 return true;
2871}
2872
2873bool:IsAllowedBlockLength(admin, length, target_count)
2874{
2875 if (target_count == 1)
2876 {
2877 if (!ConfigMaxLength)
2878 {
2879 return true;
2880 }
2881 if (!admin)
2882 {
2883 return true;
2884 }
2885 if (AdmHasFlag(admin))
2886 {
2887 return true;
2888 }
2889 new var1;
2890 if (!length || length > ConfigMaxLength)
2891 {
2892 return false;
2893 }
2894 return true;
2895 }
2896 if (0 > length)
2897 {
2898 return true;
2899 }
2900 if (!length)
2901 {
2902 return false;
2903 }
2904 if (length > 30)
2905 {
2906 return false;
2907 }
2908 if (length > DefaultTime)
2909 {
2910 return false;
2911 }
2912 return true;
2913}
2914
2915bool:AdmHasFlag(admin)
2916{
2917 new var1;
2918 return admin && CheckCommandAccess(admin, "", 65536, true);
2919}
2920
2921GetAdmImmunity(admin)
2922{
2923 new var1;
2924 if (admin > 0 && GetUserAdmin(admin) != -1)
2925 {
2926 return GetAdminImmunityLevel(GetUserAdmin(admin));
2927 }
2928 return 0;
2929}
2930
2931GetClientUserId2(client)
2932{
2933 if (client)
2934 {
2935 return GetClientUserId(client);
2936 }
2937 return 0;
2938}
2939
2940ForcePlayersRecheck()
2941{
2942 new i = 1;
2943 while (i <= MaxClients)
2944 {
2945 new var1;
2946 if (IsClientInGame(i) && IsClientAuthorized(i) && !IsFakeClient(i) && g_hPlayerRecheck[i])
2947 {
2948 g_hPlayerRecheck[i] = CreateTimer(float(i), ClientRecheck, GetClientUserId(i), 0);
2949 }
2950 i++;
2951 }
2952 return 0;
2953}
2954
2955bool:NotApplyToThisServer(srvID)
2956{
2957 new var1;
2958 if (ConfigWhiteListOnly && FindValueInArray(g_hServersWhiteList, srvID) == -1)
2959 {
2960 return true;
2961 }
2962 return false;
2963}
2964
2965MarkClientAsUnMuted(target)
2966{
2967 g_MuteType[target] = 0;
2968 g_iMuteTime[target] = 0;
2969 g_iMuteLength[target] = 0;
2970 g_iMuteLevel[target] = -1;
2971 g_sMuteAdminName[target][0] = MissingTAG:0;
2972 g_sMuteReason[target][0] = MissingTAG:0;
2973 g_sMuteAdminAuth[target][0] = MissingTAG:0;
2974 return 0;
2975}
2976
2977MarkClientAsUnGagged(target)
2978{
2979 g_GagType[target] = 0;
2980 g_iGagTime[target] = 0;
2981 g_iGagLength[target] = 0;
2982 g_iGagLevel[target] = -1;
2983 g_sGagAdminName[target][0] = MissingTAG:0;
2984 g_sGagReason[target][0] = MissingTAG:0;
2985 g_sGagAdminAuth[target][0] = MissingTAG:0;
2986 return 0;
2987}
2988
2989MarkClientAsMuted(target, time, length, String:adminName[], String:adminAuth[], adminImmunity, String:reason[])
2990{
2991 if (time)
2992 {
2993 g_iMuteTime[target] = time;
2994 }
2995 else
2996 {
2997 g_iMuteTime[target] = GetTime({0,0});
2998 }
2999 g_iMuteLength[target] = length;
3000 new var1;
3001 if (adminImmunity)
3002 {
3003 var1 = adminImmunity;
3004 }
3005 else
3006 {
3007 var1 = ConsoleImmunity;
3008 }
3009 g_iMuteLevel[target] = var1;
3010 strcopy(g_sMuteAdminName[target], 32, adminName);
3011 strcopy(g_sMuteReason[target], 256, reason);
3012 strcopy(g_sMuteAdminAuth[target], 64, adminAuth);
3013 if (0 < length)
3014 {
3015 g_MuteType[target] = 2;
3016 }
3017 else
3018 {
3019 if (length)
3020 {
3021 g_MuteType[target] = 1;
3022 }
3023 g_MuteType[target] = 3;
3024 }
3025 return 0;
3026}
3027
3028MarkClientAsGagged(target, time, length, String:adminName[], String:adminAuth[], adminImmunity, String:reason[])
3029{
3030 if (time)
3031 {
3032 g_iGagTime[target] = time;
3033 }
3034 else
3035 {
3036 g_iGagTime[target] = GetTime({0,0});
3037 }
3038 g_iGagLength[target] = length;
3039 new var1;
3040 if (adminImmunity)
3041 {
3042 var1 = adminImmunity;
3043 }
3044 else
3045 {
3046 var1 = ConsoleImmunity;
3047 }
3048 g_iGagLevel[target] = var1;
3049 strcopy(g_sGagAdminName[target], 32, adminName);
3050 strcopy(g_sGagReason[target], 256, reason);
3051 strcopy(g_sGagAdminAuth[target], 64, adminAuth);
3052 if (0 < length)
3053 {
3054 g_GagType[target] = 2;
3055 }
3056 else
3057 {
3058 if (length)
3059 {
3060 g_GagType[target] = 1;
3061 }
3062 g_GagType[target] = 3;
3063 }
3064 return 0;
3065}
3066
3067CloseMuteExpireTimer(target)
3068{
3069 new var1;
3070 if (g_hMuteExpireTimer[target] && CloseHandle(g_hMuteExpireTimer[target]))
3071 {
3072 g_hMuteExpireTimer[target] = 0;
3073 }
3074 return 0;
3075}
3076
3077CloseGagExpireTimer(target)
3078{
3079 new var1;
3080 if (g_hGagExpireTimer[target] && CloseHandle(g_hGagExpireTimer[target]))
3081 {
3082 g_hGagExpireTimer[target] = 0;
3083 }
3084 return 0;
3085}
3086
3087CreateMuteExpireTimer(target, remainingTime)
3088{
3089 if (0 < g_iMuteLength[target])
3090 {
3091 if (remainingTime)
3092 {
3093 g_hMuteExpireTimer[target] = CreateTimer(float(remainingTime), Timer_MuteExpire, GetClientUserId(target), 2);
3094 }
3095 g_hMuteExpireTimer[target] = CreateTimer(float(g_iMuteLength[target] * 60), Timer_MuteExpire, GetClientUserId(target), 2);
3096 }
3097 return 0;
3098}
3099
3100CreateGagExpireTimer(target, remainingTime)
3101{
3102 if (0 < g_iGagLength[target])
3103 {
3104 if (remainingTime)
3105 {
3106 g_hGagExpireTimer[target] = CreateTimer(float(remainingTime), Timer_GagExpire, GetClientUserId(target), 2);
3107 }
3108 g_hGagExpireTimer[target] = CreateTimer(float(g_iGagLength[target] * 60), Timer_GagExpire, GetClientUserId(target), 2);
3109 }
3110 return 0;
3111}
3112
3113PerformUnMute(target)
3114{
3115 MarkClientAsUnMuted(target);
3116 BaseComm_SetClientMute(target, false);
3117 CloseMuteExpireTimer(target);
3118 return 0;
3119}
3120
3121PerformUnGag(target)
3122{
3123 MarkClientAsUnGagged(target);
3124 BaseComm_SetClientGag(target, false);
3125 CloseGagExpireTimer(target);
3126 return 0;
3127}
3128
3129PerformMute(target, time, length, String:adminName[], String:adminAuth[], adminImmunity, String:reason[], remaining_time)
3130{
3131 MarkClientAsMuted(target, time, length, adminName, adminAuth, adminImmunity, reason);
3132 BaseComm_SetClientMute(target, true);
3133 CreateMuteExpireTimer(target, remaining_time);
3134 return 0;
3135}
3136
3137PerformGag(target, time, length, String:adminName[], String:adminAuth[], adminImmunity, String:reason[], remaining_time)
3138{
3139 MarkClientAsGagged(target, time, length, adminName, adminAuth, adminImmunity, reason);
3140 BaseComm_SetClientGag(target, true);
3141 CreateGagExpireTimer(target, remaining_time);
3142 return 0;
3143}
3144
3145SavePunishment(admin, target, type, length, String:reason[])
3146{
3147 new var1;
3148 if (type < 1 || type > 3)
3149 {
3150 return 0;
3151 }
3152 new String:targetAuth[64];
3153 if (IsClientInGame(target))
3154 {
3155 GetClientAuthString(target, targetAuth, 64, true);
3156 new String:adminIp[24];
3157 new String:adminAuth[64];
3158 new var2;
3159 if (admin && IsClientInGame(admin))
3160 {
3161 GetClientIP(admin, adminIp, 24, true);
3162 GetClientAuthString(admin, adminAuth, 64, true);
3163 }
3164 else
3165 {
3166 strcopy(adminAuth, 64, "STEAM_ID_SERVER");
3167 strcopy(adminIp, 24, ServerIp);
3168 }
3169 new String:sName[32];
3170 strcopy(sName, 32, g_sName[target]);
3171 if (DB_Connect())
3172 {
3173 new String:banName[68];
3174 new String:banReason[516];
3175 new String:sAuthidEscaped[132];
3176 new String:sAdminAuthIdEscaped[132];
3177 new String:sAdminAuthIdYZEscaped[132];
3178 decl String:sQuery[4096];
3179 decl String:sQueryAdm[512];
3180 decl String:sQueryVal[1024];
3181 new String:sQueryMute[1024];
3182 new String:sQueryGag[1024];
3183 SQL_EscapeString(g_hDatabase, sName, banName, 65, 0);
3184 SQL_EscapeString(g_hDatabase, reason, banReason, 513, 0);
3185 SQL_EscapeString(g_hDatabase, targetAuth, sAuthidEscaped, 129, 0);
3186 SQL_EscapeString(g_hDatabase, adminAuth, sAdminAuthIdEscaped, 129, 0);
3187 SQL_EscapeString(g_hDatabase, adminAuth[2], sAdminAuthIdYZEscaped, 129, 0);
3188 FormatEx(sQueryAdm, 512, "IFNULL((SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), 0)", DatabasePrefix, sAdminAuthIdEscaped, sAdminAuthIdYZEscaped);
3189 FormatEx(sQueryVal, 1024, "'%s', '%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', %s, '%s', %d", sAuthidEscaped, banName, length * 60, length * 60, banReason, sQueryAdm, adminIp, serverID);
3190 new var3;
3191 if (type == 1 || type == 3)
3192 {
3193 FormatEx(sQueryMute, 1024, "(%s, %d)", sQueryVal, 1);
3194 }
3195 new var4;
3196 if (type == 2 || type == 3)
3197 {
3198 FormatEx(sQueryGag, 1024, "(%s, %d)", sQueryVal, 2);
3199 }
3200 new var5;
3201 if (type == 3)
3202 {
3203 var5[0] = 78560;
3204 }
3205 else
3206 {
3207 var5[0] = 78564;
3208 }
3209 FormatEx(sQuery, 4096, "INSERT INTO %s_comms (authid, name, created, ends, length, reason, aid, adminIp, sid, type) VALUES %s%s%s", DatabasePrefix, sQueryMute, var5, sQueryGag);
3210 new Handle:dataPack = CreateDataPack();
3211 WritePackCell(dataPack, length);
3212 WritePackCell(dataPack, type);
3213 WritePackString(dataPack, sName);
3214 WritePackString(dataPack, targetAuth);
3215 WritePackString(dataPack, reason);
3216 WritePackString(dataPack, adminAuth);
3217 WritePackString(dataPack, adminIp);
3218 SQL_TQuery(g_hDatabase, Query_AddBlockInsert, sQuery, dataPack, DBPriority:0);
3219 }
3220 else
3221 {
3222 InsertTempBlock(length, type, sName, targetAuth, reason, adminAuth, adminIp);
3223 }
3224 return 0;
3225 }
3226 return 0;
3227}
3228
3229ShowActivityToServer(admin, type, length, String:reason[], String:targetName[], bool:ml)
3230{
3231 new String:actionName[32];
3232 new String:translationName[64];
3233 switch (type)
3234 {
3235 case 1:
3236 {
3237 if (0 < length)
3238 {
3239 strcopy(actionName, 32, "Muted");
3240 }
3241 else
3242 {
3243 if (length)
3244 {
3245 strcopy(actionName, 32, "Temp muted");
3246 }
3247 strcopy(actionName, 32, "Permamuted");
3248 }
3249 }
3250 case 2:
3251 {
3252 if (0 < length)
3253 {
3254 strcopy(actionName, 32, "Gagged");
3255 }
3256 else
3257 {
3258 if (length)
3259 {
3260 strcopy(actionName, 32, "Temp gagged");
3261 }
3262 strcopy(actionName, 32, "Permagagged");
3263 }
3264 }
3265 case 3:
3266 {
3267 if (0 < length)
3268 {
3269 strcopy(actionName, 32, "Silenced");
3270 }
3271 else
3272 {
3273 if (length)
3274 {
3275 strcopy(actionName, 32, "Temp silenced");
3276 }
3277 strcopy(actionName, 32, "Permasilenced");
3278 }
3279 }
3280 case 4:
3281 {
3282 strcopy(actionName, 32, "Unmuted");
3283 }
3284 case 5:
3285 {
3286 strcopy(actionName, 32, "Ungagged");
3287 }
3288 case 14:
3289 {
3290 strcopy(actionName, 32, "Temp unmuted");
3291 }
3292 case 15:
3293 {
3294 strcopy(actionName, 32, "Temp ungagged");
3295 }
3296 case 16:
3297 {
3298 strcopy(actionName, 32, "Temp unsilenced");
3299 }
3300 default:
3301 {
3302 return 0;
3303 }
3304 }
3305 new var1;
3306 if (reason[0])
3307 {
3308 var1[0] = 78760;
3309 }
3310 else
3311 {
3312 var1[0] = 78752;
3313 }
3314 Format(translationName, 64, "%s %s", actionName, var1);
3315 if (0 < length)
3316 {
3317 if (ml)
3318 {
3319 ShowActivity2(admin, "\x04[SourceComms]\x01 ", "%t", translationName, targetName, length, reason);
3320 }
3321 else
3322 {
3323 ShowActivity2(admin, "\x04[SourceComms]\x01 ", "%t", translationName, "_s", targetName, length, reason);
3324 }
3325 }
3326 else
3327 {
3328 if (ml)
3329 {
3330 ShowActivity2(admin, "\x04[SourceComms]\x01 ", "%t", translationName, targetName, reason);
3331 }
3332 ShowActivity2(admin, "\x04[SourceComms]\x01 ", "%t", translationName, "_s", targetName, reason);
3333 }
3334 return 0;
3335}
3336
3337public Native_SetClientMute(Handle:hPlugin, numParams)
3338{
3339 new target = GetNativeCell(1);
3340 new var1;
3341 if (target < 1 || target > MaxClients)
3342 {
3343 return ThrowNativeError(23, "Invalid client index %d", target);
3344 }
3345 if (!IsClientInGame(target))
3346 {
3347 return ThrowNativeError(23, "Client %d is not in game", target);
3348 }
3349 new bool:muteState = GetNativeCell(2);
3350 new muteLength = GetNativeCell(3);
3351 new var2;
3352 if (muteState && muteLength)
3353 {
3354 return ThrowNativeError(23, "Permanent mute is not allowed!");
3355 }
3356 new bool:bSaveToDB = GetNativeCell(4);
3357 new var3;
3358 if (!muteState && bSaveToDB)
3359 {
3360 return ThrowNativeError(23, "Removing punishments from DB is not allowed!");
3361 }
3362 decl String:sReason[256];
3363 GetNativeString(5, sReason, 256, 0);
3364 if (muteState)
3365 {
3366 if (bType:0 < g_MuteType[target])
3367 {
3368 return 0;
3369 }
3370 PerformMute(target, 0, muteLength, "CONSOLE", "STEAM_ID_SERVER", 0, sReason, 0);
3371 if (bSaveToDB)
3372 {
3373 SavePunishment(0, target, 1, muteLength, sReason);
3374 }
3375 }
3376 else
3377 {
3378 if (g_MuteType[target])
3379 {
3380 PerformUnMute(target);
3381 }
3382 return 0;
3383 }
3384 return 1;
3385}
3386
3387public Native_SetClientGag(Handle:hPlugin, numParams)
3388{
3389 new target = GetNativeCell(1);
3390 new var1;
3391 if (target < 1 || target > MaxClients)
3392 {
3393 return ThrowNativeError(23, "Invalid client index %d", target);
3394 }
3395 if (!IsClientInGame(target))
3396 {
3397 return ThrowNativeError(23, "Client %d is not in game", target);
3398 }
3399 new bool:gagState = GetNativeCell(2);
3400 new gagLength = GetNativeCell(3);
3401 new var2;
3402 if (gagState && gagLength)
3403 {
3404 return ThrowNativeError(23, "Permanent gag is not allowed!");
3405 }
3406 new bool:bSaveToDB = GetNativeCell(4);
3407 new var3;
3408 if (!gagState && bSaveToDB)
3409 {
3410 return ThrowNativeError(23, "Removing punishments from DB is not allowed!");
3411 }
3412 decl String:sReason[256];
3413 GetNativeString(5, sReason, 256, 0);
3414 if (gagState)
3415 {
3416 if (bType:0 < g_GagType[target])
3417 {
3418 return 0;
3419 }
3420 PerformGag(target, 0, gagLength, "CONSOLE", "STEAM_ID_SERVER", 0, sReason, 0);
3421 if (bSaveToDB)
3422 {
3423 SavePunishment(0, target, 2, gagLength, sReason);
3424 }
3425 }
3426 else
3427 {
3428 if (g_GagType[target])
3429 {
3430 PerformUnGag(target);
3431 }
3432 return 0;
3433 }
3434 return 1;
3435}
3436
3437public Native_GetClientMuteType(Handle:hPlugin, numParams)
3438{
3439 new target = GetNativeCell(1);
3440 new var1;
3441 if (target < 1 || target > MaxClients)
3442 {
3443 return ThrowNativeError(23, "Invalid client index %d", target);
3444 }
3445 if (!IsClientInGame(target))
3446 {
3447 return ThrowNativeError(23, "Client %d is not in game", target);
3448 }
3449 return g_MuteType[target];
3450}
3451
3452public Native_GetClientGagType(Handle:hPlugin, numParams)
3453{
3454 new target = GetNativeCell(1);
3455 new var1;
3456 if (target < 1 || target > MaxClients)
3457 {
3458 return ThrowNativeError(23, "Invalid client index %d", target);
3459 }
3460 if (!IsClientInGame(target))
3461 {
3462 return ThrowNativeError(23, "Client %d is not in game", target);
3463 }
3464 return g_GagType[target];
3465}