· 8 years ago · Dec 21, 2017, 08:18 PM
1#include <sourcemod>
2#include <sdktools>
3#include <sdkhooks>
4#include <cstrike>
5
6#undef REQUIRE_PLUGIN
7#include <adminmenu>
8
9#define MAPSVOTE_MENU_TITLE "★ Next Map Vote ★"
10#define VOTING_TIME (12) // Seconds.
11#define DEFAULT_GAG_MINUTES (5) // Minutes, only if not specified.
12
13new Handle:g_pConnection = INVALID_HANDLE;
14new String:g_VotedMaps[3][32];
15new g_VotedMapsVotes[3] = { 0, ... };
16new g_VotedMapsCount = 0;
17new Handle:g_pAdminMenu = INVALID_HANDLE;
18new Handle:g_pNames = INVALID_HANDLE;
19new Handle:g_pIPs = INVALID_HANDLE;
20new Handle:g_pSteams = INVALID_HANDLE;
21new bool:g_Gagged[128 + 1] = { false, ... };
22
23
24#define MAX_WORDS 200
25#define MAX_REPLACE 50
26
27new Handle: cvarswearmode;
28new String:badwordfile[PLATFORM_MAX_PATH];
29new String:g_swearwords[MAX_WORDS][32];
30new MAX_PLAYERS;
31new g_swearNum;
32
33MakeNameFriendly(String:Name[], Size)
34{
35 ReplaceString(Name, Size, "'", "*");
36 ReplaceString(Name, Size, "\\", "*");
37 ReplaceString(Name, Size, "\"", "*");
38 ReplaceString(Name, Size, "`", "*");
39}
40
41public OnMapStart(){
42 CreateTimer(0.1, Read_Files);
43 MAX_PLAYERS = GetMaxClients();
44}
45
46public OnMapEnd(){
47 g_swearNum = 0;
48}
49
50public Action:Read_Files(Handle:timer){
51 BuildPath(Path_SM,badwordfile,sizeof(badwordfile),"configs/badwords.txt");
52 if(!FileExists(badwordfile)) {
53 LogMessage("badwords.txt nu a fost gasit!");
54 }else{
55 new Handle:badwordshandle = OpenFile(badwordfile, "r");
56 new i = 0;
57 while( i < MAX_WORDS && !IsEndOfFile(badwordshandle)){
58 ReadFileLine(badwordshandle, g_swearwords[i], sizeof(g_swearwords[]));
59 TrimString(g_swearwords[i]);
60 i++;
61 g_swearNum++;
62 }
63 CloseHandle(badwordshandle);
64 }
65}
66
67public Action:Command_Say(client,args){
68 if(client != 0){
69 decl String:speech[191];
70 decl String:clientname[64];
71 GetClientName(client,clientname,64);
72 GetCmdArgString(speech,sizeof(speech));
73
74
75 new startidx = 0;
76 if (speech[0] == '"'){
77 startidx = 1;
78
79 new len = strlen(speech);
80 if (speech[len-1] == '"'){
81 speech[len-1] = '\0';
82 }
83 }
84
85 decl String:originalstring[191];
86 strcopy(originalstring, sizeof(speech), speech[startidx]);
87 string_cleaner(speech[startidx], sizeof(speech) - startidx);
88
89 new i = 0;
90 new found;
91 while (i < g_swearNum){
92 if (StrContains(speech[startidx], g_swearwords[i], false) != -1 ){
93
94 new String:replacement[32];
95 strcopy(replacement, sizeof(replacement), g_swearwords[i]);
96 new k, leng = strlen(replacement);
97 for(k=0; k<leng; k++)
98 {
99 replacement[k]= '*';
100 }
101 if(strlen(speech)>0)
102 {
103 ReplaceString(speech, strlen(speech), g_swearwords[i], replacement, false);
104 found = true;
105 }
106 }
107 i++;
108 }
109 if (found){
110 if (GetConVarInt(cvarswearmode) == 2){
111 if(GetClientTeam(client)== CS_TEAM_T)
112 {
113 if(!g_Gagged[client])
114 {
115 PrintToChatAll(" \x09%s\x01: %s", clientname, speech[startidx]);
116 }
117 }
118 else if(GetClientTeam(client)== CS_TEAM_CT)
119 {
120 if(!g_Gagged[client])
121 {
122 PrintToChatAll(" \x0B%s\x01: %s", clientname, speech[startidx]);
123 }
124 }
125 else
126 {
127 if(!g_Gagged[client])
128 {
129 PrintToChatAll("%s: %s", clientname, speech[startidx]);
130 }
131 }
132 PrintToChat(client, " \x04Atentie la limbaj!");
133 return Plugin_Handled;
134 }
135 }
136
137 }
138 return Plugin_Continue;
139}
140
141public Action:Command_TeamSay(client,args){
142 if(client != 0){
143 decl String:speech[191];
144 decl String:clientname[64];
145 GetClientName(client,clientname,64);
146 GetCmdArgString(speech,sizeof(speech));
147
148 new startidx = 0;
149 if (speech[0] == '"'){
150 startidx = 1;
151
152 new len = strlen(speech);
153 if (speech[len-1] == '"'){
154 speech[len-1] = '\0';
155 }
156 }
157 decl String:originalstring[191];
158 strcopy(originalstring, sizeof(speech), speech[startidx]);
159
160 string_cleaner(speech[startidx], sizeof(speech) - startidx);
161
162 new i = 0;
163 new found;
164 while (i < g_swearNum){
165 if (StrContains(speech[startidx], g_swearwords[i], false) != -1 ){
166 new String:replacement[32];
167 strcopy(replacement, sizeof(replacement), g_swearwords[i]);
168 new k, leng = strlen(replacement);
169 for(k=0; k<leng; k++)
170 {
171 replacement[k]= '*';
172 }
173 ReplaceString(speech, strlen(speech), g_swearwords[i], replacement,false);
174 found = true;
175 }
176 i++;
177 }
178 if (found){
179 if (GetConVarInt(cvarswearmode) == 2){
180 for (new j = 1; j < MAX_PLAYERS; j++){
181 if(IsClientConnected(j) && IsClientInGame(j) && IsClientInGame(client)){
182 if(GetClientTeam(j) == GetClientTeam(client)){
183 if(GetClientTeam(j)== CS_TEAM_T)
184 {
185 if(!g_Gagged[client])
186 {
187 PrintToChat(j, "(Team) \x09%s\x01: %s", clientname, speech[startidx]);
188 }
189 }
190 else if(GetClientTeam(j)== CS_TEAM_CT)
191 {
192 if(!g_Gagged[client])
193 {
194 PrintToChat(j, "(Team) \x0B%s\x01: %s", clientname, speech[startidx]);
195 }
196 }
197 else
198 {
199 if(!g_Gagged[client])
200 {
201 PrintToChat(j, "(Team) %s: %s", clientname, speech[startidx]);
202 }
203 }
204 }
205 }
206 }
207 PrintToChat(client, " \x04Atentie la limbaj!");
208 return Plugin_Handled;
209 }
210 }
211
212 }
213 return Plugin_Continue;
214}
215
216string_cleaner(String:str[], maxlength){
217 new i, len = strlen(str);
218 if (GetConVarInt(cvarswearmode) != 2){
219 ReplaceString ( str, maxlength, " ", "" );
220 }
221
222 ReplaceString(str, maxlength, "|<", "k");
223 ReplaceString(str, maxlength, "|>", "p");
224 ReplaceString(str, maxlength, "()", "o");
225 ReplaceString(str, maxlength, "[]", "o");
226 ReplaceString(str, maxlength, "{}", "o");
227
228 for(i = 0; i < len; i++)
229 {
230 if(str[i] == '@')
231 str[i] = 'a';
232
233 if(str[i] == '$')
234 str[i] = 's';
235
236 if(str[i] == '0')
237 str[i] = 'o';
238
239 if(str[i] == '7')
240 str[i] = 't';
241
242 if(str[i] == '3')
243 str[i] = 'e';
244
245 if(str[i] == '5')
246 str[i] = 's';
247
248 if(str[i] == '<')
249 str[i] = 'c';
250
251 if(GetConVarInt(cvarswearmode) != 2){
252 if(str[i] == '3')
253 str[i] = 'e';
254 }
255
256 }
257}
258
259ShortenMapName(String:Old[64], String:New[64])
260{
261 static Iterator, CopyFrom;
262
263 CopyFrom = 0xFF;
264 Old[0] = CharToUpper(Old[0]);
265 ReplaceString(Old, sizeof(Old), "_", " ");
266
267 if (StrContains(Old, " ") != -1)
268 {
269 for (Iterator = 0; Iterator < strlen(Old); Iterator++)
270 {
271 if (Old[Iterator] == ' ')
272 {
273 CopyFrom = Iterator + 1;
274 break;
275 }
276 }
277 }
278
279 if (CopyFrom != 0xFF)
280 {
281 strcopy(New, sizeof(New), Old[CopyFrom]);
282 New[0] = CharToUpper(New[0]);
283
284 for (Iterator = 0; Iterator < strlen(New); Iterator++)
285 {
286 if (Iterator > 0 && New[Iterator - 1] == ' ')
287 New[Iterator] = CharToUpper(New[Iterator]);
288 }
289 }
290
291 else
292 strcopy(New, sizeof(New), Old);
293}
294
295AddCommas(Number, String:Output[16])
296{
297 static String:Temporary[16], outPos, noPos, noLen;
298 outPos = noPos = 0;
299
300 if (Number < 0)
301 Output[outPos++] = '-', Number = -Number;
302
303 if ((noLen = IntToString(Number, Temporary, sizeof(Temporary))) <= 3)
304 outPos = strcopy(Output[outPos], sizeof(Output), Temporary);
305
306 else
307 {
308 while (noPos < noLen)
309 {
310 Output[outPos++] = Temporary[noPos++];
311
312 if ((noLen - noPos) && !((noLen - noPos) % 3))
313 Output[outPos++] = ',';
314 }
315
316 Output[outPos] = EOS;
317 }
318}
319
320bool:ValidPlayer(Player)
321{
322 return Player >= 1 && Player <= MaxClients ? true : false;
323}
324
325bool:BadPlayer(Client, bool:CheckIfConnected = true, bool:CheckIfFake = true)
326{
327 if (!ValidPlayer(Client))
328 return true;
329
330 if (CheckIfConnected && !IsClientInGame(Client))
331 return true;
332
333 if (CheckIfFake && IsFakeClient(Client))
334 return true;
335
336 if (IsClientInKickQueue(Client) || IsClientSourceTV(Client))
337 return true;
338
339 return false;
340}
341
342public OnPluginStart()
343{
344 LoadTranslations("common.phrases");
345
346 RegAdminCmd("sm_votemap", CommandVoteMap, ADMFLAG_VOTE, "sm_votemap <map 1> [map 2] [map 3] - Votes maps.");
347 RegAdminCmd("sm_votemaps", CommandVoteMap, ADMFLAG_VOTE, "sm_votemaps <map 1> [map 2] [map 3] - Votes maps.");
348
349 cvarswearmode = CreateConVar("sm_swear_replace_mode","2","2 (stars)",0);
350 RegConsoleCmd("say", Command_Say);
351 RegConsoleCmd("say_team", Command_TeamSay);
352
353 new String:Error[256];
354 g_pConnection = SQL_Connect("gags", false, Error, sizeof(Error));
355
356 new Handle:pTopMenu = INVALID_HANDLE;
357 if (LibraryExists("adminmenu") && ((pTopMenu = GetAdminTopMenu()) != INVALID_HANDLE))
358 OnAdminMenuReady(pTopMenu);
359
360 if (g_pConnection != INVALID_HANDLE)
361 {
362 RegAdminCmd("sm_last", CommandLast, ADMFLAG_SLAY, "sm_last - Lists all disconnected players.");
363
364 RegAdminCmd("sm_gag", CommandGag, ADMFLAG_SLAY, "sm_gag <target> <minutes> [reason] - Gags player by time and reason (retry resistant).");
365 RegAdminCmd("sm_ungag", CommandUngag, ADMFLAG_SLAY, "sm_ungag <target> - Ungags player.");
366
367 RegAdminCmd("sm_silence", CommandGag, ADMFLAG_SLAY, "sm_silence <target> <minutes> [reason] - Gags player by time and reason (retry resistant).");
368 RegAdminCmd("sm_unsilence", CommandUngag, ADMFLAG_SLAY, "sm_unsilence <target> - Ungags player.");
369
370 RegAdminCmd("sm_mute", CommandGag, ADMFLAG_SLAY, "sm_mute <target> <minutes> [reason] - Gags player by time and reason (retry resistant).");
371 RegAdminCmd("sm_unmute", CommandUngag, ADMFLAG_SLAY, "sm_unmute <target> - Ungags player.");
372
373 SQL_SetCharset(g_pConnection, "utf8");
374 SQL_TQuery(g_pConnection, EmptyFunction, "CREATE TABLE IF NOT EXISTS Gagged (Name TEXT, Steam TEXT, Ip TEXT, gagTime NUMERIC, gagLength NUMERIC, ungagTime NUMERIC, adminName TEXT, adminSteam TEXT, adminIp TEXT, Reason TEXT);");
375
376 CreateTimer(60.0, Timer_CheckGags, _, TIMER_REPEAT);
377 }
378
379 else
380 LogError("SQL_Connect() @ OnPluginStart() resulted error: %s", Error);
381
382 RegConsoleCmd("say", CommandSay);
383 RegConsoleCmd("say_team", CommandSay);
384
385 g_pIPs = CreateArray(64);
386 g_pNames = CreateArray(64);
387 g_pSteams = CreateArray(64);
388}
389
390public OnLibraryRemoved(const String:Name[])
391{
392 if (StrEqual(Name, "adminmenu"))
393 g_pAdminMenu = INVALID_HANDLE;
394}
395
396public OnAdminMenuReady(Handle:pTopMenu)
397{
398 if (pTopMenu == g_pAdminMenu)
399 return;
400
401 g_pAdminMenu = pTopMenu;
402
403 new TopMenuObject:pPlrCmds = FindTopMenuCategory(g_pAdminMenu, ADMINMENU_PLAYERCOMMANDS);
404 if (g_pConnection != INVALID_HANDLE)
405 {
406 AddToTopMenu(g_pAdminMenu, "sm_gag", TopMenuObject_Item, GagTopMenuHandler, pPlrCmds, "sm_gag", ADMFLAG_SLAY);
407 AddToTopMenu(g_pAdminMenu, "sm_ungag", TopMenuObject_Item, UngagTopMenuHandler, pPlrCmds, "sm_ungag", ADMFLAG_SLAY);
408 }
409}
410
411public GagTopMenuHandler(Handle:pTopMenu, TopMenuAction:iAction, TopMenuObject:pObject, Param, String:Buffer[], maxLen)
412{
413 if (iAction == TopMenuAction_DisplayOption)
414 FormatEx(Buffer, maxLen, "Gag+Mute+Silence (+Retry Support)");
415
416 else if (iAction == TopMenuAction_SelectOption)
417 GagPlayersMenu(Param);
418}
419
420public UngagTopMenuHandler(Handle:pTopMenu, TopMenuAction:iAction, TopMenuObject:pObject, Param, String:Buffer[], maxLen)
421{
422 if (iAction == TopMenuAction_DisplayOption)
423 FormatEx(Buffer, maxLen, "Ungag+Unmute+Unsilence (+Retry Support)");
424
425 else if (iAction == TopMenuAction_SelectOption)
426 UngagPlayersMenu(Param);
427}
428
429GagPlayersMenu(client)
430{
431 new Handle:pMenu = CreateMenu(GagPlayersMenuHandler);
432 SetMenuTitle(pMenu, "Gag+Mute+Silence (+Retry Support)");
433
434 new String:Name[64], String:Info[8];
435 for (new Plr = 1; Plr <= MaxClients; Plr++)
436 {
437 if (IsClientInGame(Plr) && !g_Gagged[Plr] && !IsFakeClient(Plr) && !IsClientSourceTV(Plr))
438 {
439 GetClientName(Plr, Name, sizeof(Name));
440 IntToString(GetClientUserId(Plr), Info, sizeof(Info));
441 AddMenuItem(pMenu, Info, Name);
442 }
443 }
444
445 DisplayMenu(pMenu, client, MENU_TIME_FOREVER);
446}
447
448UngagPlayersMenu(client)
449{
450 new Handle:pMenu = CreateMenu(UngagPlayersMenuHandler);
451 SetMenuTitle(pMenu, "Ungag+Unmute+Unsilence (+Retry Support)");
452
453 new String:Name[64], String:Info[8];
454 for (new Plr = 1; Plr <= MaxClients; Plr++)
455 {
456 if (IsClientInGame(Plr) && g_Gagged[Plr] && !IsFakeClient(Plr) && !IsClientSourceTV(Plr))
457 {
458 GetClientName(Plr, Name, sizeof(Name));
459 IntToString(GetClientUserId(Plr), Info, sizeof(Info));
460 AddMenuItem(pMenu, Info, Name);
461 }
462 }
463
464 DisplayMenu(pMenu, client, MENU_TIME_FOREVER);
465}
466
467public GagPlayersMenuHandler(Handle:pMenu, MenuAction:iAction, Client, Selection)
468{
469 if (iAction == MenuAction_Select)
470 {
471 new String:Info[64];
472 GetMenuItem(pMenu, Selection, Info, sizeof(Info));
473 ClientCommand(Client, "sm_gag #%d %d", StringToInt(Info), DEFAULT_GAG_MINUTES);
474 }
475
476 else if (iAction == MenuAction_End)
477 CloseHandle(pMenu);
478}
479
480public UngagPlayersMenuHandler(Handle:pMenu, MenuAction:iAction, Client, Selection)
481{
482 if (iAction == MenuAction_Select)
483 {
484 new String:Info[64];
485 GetMenuItem(pMenu, Selection, Info, sizeof(Info));
486 ClientCommand(Client, "sm_ungag #%d", StringToInt(Info));
487 }
488
489 else if (iAction == MenuAction_End)
490 CloseHandle(pMenu);
491}
492
493public OnGameFrame()
494{
495 if (g_pConnection != INVALID_HANDLE)
496 {
497 for (new Plr = 1; Plr <= MaxClients; Plr++)
498 {
499 if (g_Gagged[Plr] && IsClientInGame(Plr) && !IsFakeClient(Plr) && !IsClientSourceTV(Plr))
500 {
501 SetClientListeningFlags(Plr, VOICE_MUTED);
502 }
503 }
504 }
505}
506
507public Action: CommandSay(Id, Args)
508{
509 static String:Fmt[256], String:Steam[64];
510
511 if (!BadPlayer(Id))
512 {
513 if (g_Gagged[Id])
514 {
515 GetClientAuthId(Id, AuthId_Engine, Steam, sizeof(Steam));
516 FormatEx(Fmt, sizeof(Fmt), "SELECT ungagTime FROM Gagged WHERE Steam = '%s';", Steam);
517 SQL_TQuery(g_pConnection, PrintLeft, Fmt, Id);
518
519 return Plugin_Handled;
520 }
521 }
522
523 return Plugin_Continue;
524}
525
526public Action: Timer_CheckGags(Handle:pTimer, any:Data)
527{
528 if (g_pConnection != INVALID_HANDLE)
529 SQL_TQuery(g_pConnection, ManageGags, "SELECT Name, Steam, ungagTime, Reason FROM Gagged;");
530}
531
532public OnClientPutInServer(Id)
533{
534 if (g_pConnection != INVALID_HANDLE && !IsFakeClient(Id) && !IsClientSourceTV(Id))
535 {
536 new String:Steam[64];
537 GetClientAuthId(Id, AuthId_Engine, Steam, sizeof(Steam));
538
539 new String:Fmt[256];
540 FormatEx(Fmt, sizeof(Fmt), "SELECT gagTime FROM Gagged WHERE Steam = '%s';", Steam);
541
542 SQL_TQuery(g_pConnection, RetrieveGag, Fmt, Id);
543 }
544}
545
546public EmptyFunction(Handle:Db, Handle:Query, String:Error[], Data)
547{
548 if (strlen(Error))
549 LogError("SQL_TQuery() @ EmptyFunction() reported: %s", Error);
550}
551
552public RetrieveGag(Handle:Db, Handle:Query, String:Error[], Data)
553{
554 if (!strlen(Error))
555 {
556 if (IsClientInGame(Data) && SQL_HasResultSet(Query) && SQL_GetRowCount(Query) > 0)
557 g_Gagged[Data] = true;
558 }
559
560 else
561 LogError("SQL_TQuery() @ RetrieveGag() reported: %s", Error);
562}
563
564public OnClientDisconnect(Id)
565{
566 static String:Name[64], String:Steam[64], String:Ip[64];
567
568 GetClientName(Id, Name, sizeof(Name));
569 GetClientIP(Id, Ip, sizeof(Ip), true);
570 GetClientAuthId(Id, AuthId_Engine, Steam, sizeof(Steam));
571
572 if (g_Gagged[Id])
573 {
574 PrintToChatAll("\x01Gagged player\x03 %s\x01 has left, but their gag remains.", Name);
575 g_Gagged[Id] = false;
576 }
577
578 PushArrayString(g_pNames, Name);
579 PushArrayString(g_pSteams, Steam);
580 PushArrayString(g_pIPs, Ip);
581}
582
583public PrintLeft(Handle:Db, Handle:Query, String:Error[], Data)
584{
585 if (!strlen(Error))
586 {
587 if (IsClientInGame(Data) && SQL_HasResultSet(Query) && SQL_GetRowCount(Query) > 0 && SQL_FetchRow(Query))
588 {
589 new ungagTime = SQL_FetchInt(Query, 0);
590 new remainingMinutes = (ungagTime - GetTime()) / 60;
591
592 if (remainingMinutes < 1)
593 PrintToChat(Data, "\x01You will be ungagged in less than\x04 1 minute\x01.");
594
595 else if (remainingMinutes == 1)
596 PrintToChat(Data, "\x01You will be ungagged in\x04 1 minute\x01.");
597
598 else
599 PrintToChat(Data, "\x01You will be ungagged in\x04 %d minutes\x01.", remainingMinutes);
600 }
601 }
602
603 else
604 LogError("SQL_TQuery() @ PrintLeft() reported: %s", Error);
605}
606
607public ManageGags(Handle:Db, Handle:Query, String:Error[], Data)
608{
609 static String:gaggedName[64], ungagTime = 0, String:gaggedSteam[64], Now = 0, String:Fmt[256], String:PlrSteam[64], \
610 String:Reason[64], Plr;
611
612 if (!strlen(Error))
613 {
614 if (SQL_HasResultSet(Query))
615 {
616 Now = GetTime();
617
618 while (SQL_FetchRow(Query))
619 {
620 SQL_FetchString(Query, 0, gaggedName, sizeof(gaggedName));
621 SQL_FetchString(Query, 1, gaggedSteam, sizeof(gaggedSteam));
622 ungagTime = SQL_FetchInt(Query, 2);
623 SQL_FetchString(Query, 3, Reason, sizeof(Reason));
624
625 if (ungagTime < Now)
626 {
627 FormatEx(Fmt, sizeof(Fmt), "DELETE FROM Gagged WHERE Steam = '%s';", gaggedSteam);
628 SQL_TQuery(g_pConnection, UngagEntry, Fmt);
629
630 if (strlen(Reason) > 0)
631 PrintToChatAll("\x01Gag for\x03 %s\x01 expired! Reason\x04 %s\x01.", gaggedName, Reason);
632
633 else
634 PrintToChatAll("\x01Gag for\x03 %s\x01 expired!", gaggedName);
635
636 for (Plr = 1; Plr <= MaxClients; Plr++)
637 {
638 if (!IsClientInGame(Plr))
639 continue;
640
641 GetClientAuthId(Plr,AuthId_Engine, PlrSteam, sizeof(PlrSteam));
642 if (strcmp(PlrSteam, gaggedSteam) == 0)
643 {
644 g_Gagged[Plr] = false;
645 SetClientListeningFlags(Plr, VOICE_NORMAL);
646 }
647 }
648 }
649 }
650 }
651 }
652
653 else
654 LogError("SQL_TQuery() @ ManageGags() reported: %s", Error);
655}
656
657public UngagEntry(Handle:Db, Handle:Query, String:Error[], Data)
658{
659 if (strlen(Error) > 0)
660 LogError("SQL_TQuery() @ UngagEntry() reported: %s", Error);
661}
662
663public Action: CommandLast(Client, Args)
664{
665 if (GetArraySize(g_pNames) == 0)
666 {
667 PrintToConsole(Client, "There are no disconnected clients!");
668 return Plugin_Stop;
669 }
670
671 new String:Name[64], String:Steam[64], String:Ip[64], Total = 0;
672
673 PrintToConsole(Client, "%32s %32s %32s", "Name", "Steam", "IP Address");
674
675 for (new Iter = GetArraySize(g_pNames) - 1; Iter >= 0; Iter--)
676 {
677 GetArrayString(g_pNames, Iter, Name, sizeof(Name));
678 GetArrayString(g_pSteams, Iter, Steam, sizeof(Steam));
679 GetArrayString(g_pIPs, Iter, Ip, sizeof(Ip));
680
681 PrintToConsole(Client, "%32s %32s %32s", Name, Steam, Ip);
682
683 if (++Total >= 20)
684 break;
685 }
686
687 return Plugin_Stop;
688}
689
690public Action: CommandGag(Client, Args)
691{
692 if (Args < 1)
693 {
694 ReplyToCommand(Client, "[SM] Usage: sm_gag <target> <minutes> [reason] - Gags player by time and reason (retry resistant).");
695 return Plugin_Stop;
696 }
697
698 new String:Victim[32], iVictim = 0, String:Minutes[32], iMinutes = 0, iSeconds = 0, String:Reason[32], String:MinutesFmt[16], \
699 String:VictimName[32], String:VictimSteam[32], String:AdminName[32], String:AdminSteam[32], String:VictimIp[32], \
700 String:AdminIp[32], Targets[MAXPLAYERS], Res, bool:bTnIsML, Now = GetTime(), String:TargetName[4], String:Fmt[512];
701
702 GetCmdArg(1, Victim, sizeof(Victim));
703 GetCmdArg(2, Minutes, sizeof(Minutes));
704
705 if (Args >= 3)
706 GetCmdArg(3, Reason, sizeof(Reason));
707
708 iMinutes = StringToInt(Minutes);
709
710 if (iMinutes == 0)
711 iMinutes = DEFAULT_GAG_MINUTES;
712
713 if (iMinutes < 1)
714 {
715 ReplyToCommand(Client, "[SM] You must specify at least one minute.");
716 return Plugin_Stop;
717 }
718
719 if (iMinutes > 1440)
720 {
721 ReplyToCommand(Client, "[SM] You must specify at most 1,440 minutes (1 day).");
722 return Plugin_Stop;
723 }
724
725 iSeconds = iMinutes * 60;
726
727 GetCmdArg(1, Victim, sizeof(Victim));
728 if ((Res = ProcessTargetString(Victim, Client, Targets, MAXPLAYERS, COMMAND_FILTER_NO_MULTI | COMMAND_FILTER_NO_BOTS, TargetName, sizeof(TargetName), bTnIsML)) <= COMMAND_TARGET_NONE)
729 {
730 ReplyToTargetError(Client, Res);
731 return Plugin_Stop;
732 }
733
734 iVictim = Targets[0];
735 if (g_Gagged[iVictim])
736 {
737 ReplyToCommand(Client, "[SM] This user is already gagged.");
738 return Plugin_Stop;
739 }
740
741 if (IsClientSourceTV(iVictim))
742 {
743 ReplyToCommand(Client, "[SM] This user is a GOTV client.");
744 return Plugin_Stop;
745 }
746
747 GetClientName(iVictim, VictimName, sizeof(VictimName));
748 GetClientAuthId(iVictim, AuthId_Engine, VictimSteam, sizeof(VictimSteam));
749 GetClientIP(iVictim, VictimIp, sizeof(VictimIp), true);
750
751 GetClientName(Client, AdminName, sizeof(AdminName));
752 GetClientAuthId(Client,AuthId_Engine, AdminSteam, sizeof(AdminSteam));
753 GetClientIP(Client, AdminIp, sizeof(AdminIp), true);
754
755 MakeNameFriendly(AdminName, sizeof(AdminName));
756 MakeNameFriendly(VictimName, sizeof(VictimName));
757 MakeNameFriendly(Reason, sizeof(Reason));
758
759 FormatEx(Fmt, sizeof(Fmt), "INSERT INTO Gagged VALUES ('%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', '%s');", \
760 VictimName, VictimSteam, VictimIp, Now, iMinutes, Now + iSeconds, AdminName, AdminSteam, AdminIp, Reason);
761
762 SQL_TQuery(g_pConnection, AddGag, Fmt);
763
764 AddCommas(iMinutes, MinutesFmt);
765
766 if (strlen(Reason) > 0)
767 PrintToChatAll("\x01Admin\x03 %s\x01 gagged\x03 %s\x01 for\x04 %s minute%s\x01. Reason\x03 %s\x01.", AdminName, VictimName, MinutesFmt, iMinutes == 1 ? "" : "s", Reason);
768
769 else
770 PrintToChatAll("\x01Admin\x03 %s\x01 gagged\x03 %s\x01 for\x04 %s minute%s\x01.", AdminName, VictimName, MinutesFmt, iMinutes == 1 ? "" : "s");
771
772 if (strlen(Reason) > 0)
773 LogMessage("Admin %s (%s) gagged %s (%s) for %s minute%s. Reason %s.", AdminName, AdminSteam, VictimName, VictimSteam, MinutesFmt, iMinutes == 1 ? "" : "s", Reason);
774
775 else
776 LogMessage("Admin %s (%s) gagged %s (%s) for %s minute%s.", AdminName, AdminSteam, VictimName, VictimSteam, MinutesFmt, iMinutes == 1 ? "" : "s");
777
778 g_Gagged[iVictim] = true;
779 return Plugin_Stop;
780}
781
782public Action: CommandUngag(Client, Args)
783{
784 if (Args < 1)
785 {
786 ReplyToCommand(Client, "[SM] Usage: sm_ungag <target> - Ungags player.");
787 return Plugin_Stop;
788 }
789
790 new String:Victim[32], iVictim = 0, String:VictimName[32], String:VictimSteam[32], String:AdminName[32], \
791 String:AdminSteam[32], String:VictimIp[32], String:AdminIp[32], Targets[MAXPLAYERS], Res = 0, bool:bTnIsML = false, \
792 String:TargetName[4], String:Fmt[256];
793
794 GetCmdArg(1, Victim, sizeof(Victim));
795 if ((Res = ProcessTargetString(Victim, Client, Targets, MAXPLAYERS, COMMAND_FILTER_NO_MULTI | COMMAND_FILTER_NO_BOTS, TargetName, sizeof(TargetName), bTnIsML)) <= COMMAND_TARGET_NONE)
796 {
797 ReplyToTargetError(Client, Res);
798 return Plugin_Stop;
799 }
800
801 iVictim = Targets[0];
802 if (!g_Gagged[iVictim])
803 {
804 ReplyToCommand(Client, "[SM] This user is not gagged.");
805 return Plugin_Stop;
806 }
807
808 if (IsClientSourceTV(iVictim))
809 {
810 ReplyToCommand(Client, "[SM] This user is a GOTV client.");
811 return Plugin_Stop;
812 }
813
814 GetClientName(iVictim, VictimName, sizeof(VictimName));
815 GetClientAuthId(iVictim, AuthId_Engine, VictimSteam, sizeof(VictimSteam));
816 GetClientIP(iVictim, VictimIp, sizeof(VictimIp), true);
817
818 GetClientName(Client, AdminName, sizeof(AdminName));
819 GetClientAuthId(Client, AuthId_Engine, AdminSteam, sizeof(AdminSteam));
820 GetClientIP(Client, AdminIp, sizeof(AdminIp), true);
821
822 FormatEx(Fmt, sizeof(Fmt), "DELETE FROM Gagged WHERE Steam = '%s';", VictimSteam);
823 SQL_TQuery(g_pConnection, UngagSQL, Fmt);
824
825 PrintToChatAll("\x01Admin\x03 %s\x01 ungagged\x03 %s\x01.", AdminName, VictimName);
826 LogMessage("Admin %s (%s) ungagged %s (%s).", AdminName, AdminSteam, VictimName, VictimSteam);
827
828 g_Gagged[iVictim] = false;
829 SetClientListeningFlags(iVictim, VOICE_NORMAL);
830
831 return Plugin_Stop;
832}
833
834public AddGag(Handle:Db, Handle:Query, String:Error[], Data)
835{
836 if (strlen(Error) > 0)
837 LogError("SQL_TQuery() @ AddGag() reported: %s", Error);
838}
839
840public UngagSQL(Handle:Db, Handle:Query, String:Error[], Data)
841{
842 if (strlen(Error) > 0)
843 LogError("SQL_TQuery() @ UngagSQL() reported: %s", Error);
844}
845
846public Action: CommandVoteMap(Client, Args)
847{
848 if (Args < 1)
849 {
850 ReplyToCommand(Client, "[SM] Usage: sm_votemap <map 1> [map 2] [map 3] - Votes maps.");
851 return Plugin_Stop;
852 }
853
854 if (IsVoteInProgress())
855 {
856 ReplyToCommand(Client, "[SM] Vote in progress!");
857 return Plugin_Stop;
858 }
859
860 new String:MapsFull[3][128], Keys = 0;
861
862 if (Args >= 1)
863 GetCmdArg(1, g_VotedMaps[0], sizeof(g_VotedMaps[])), g_VotedMapsCount = 1;
864
865 if (Args >= 2)
866 GetCmdArg(2, g_VotedMaps[1], sizeof(g_VotedMaps[])), g_VotedMapsCount = 2;
867
868 if (Args >= 3)
869 GetCmdArg(3, g_VotedMaps[2], sizeof(g_VotedMaps[])), g_VotedMapsCount = 3;
870
871 switch (g_VotedMapsCount)
872 {
873 case 1:
874 {
875 FormatEx(MapsFull[0], sizeof(MapsFull[]), "maps/%s.bsp", g_VotedMaps[0]);
876 if (!FileExists(MapsFull[0]))
877 {
878 ReplyToCommand(Client, "[SM] Maps '%s' is not valid!", g_VotedMaps[0]);
879 return Plugin_Stop;
880 }
881
882 Keys = 1 << 0;
883 }
884
885 case 2:
886 {
887 FormatEx(MapsFull[0], sizeof(MapsFull[]), "maps/%s.bsp", g_VotedMaps[0]);
888 if (!FileExists(MapsFull[0]))
889 {
890 ReplyToCommand(Client, "[SM] Maps '%s' is not valid!", g_VotedMaps[0]);
891 return Plugin_Stop;
892 }
893
894 FormatEx(MapsFull[1], sizeof(MapsFull[]), "maps/%s.bsp", g_VotedMaps[1]);
895 if (!FileExists(MapsFull[1]))
896 {
897 ReplyToCommand(Client, "[SM] Maps '%s' is not valid!", g_VotedMaps[1]);
898 return Plugin_Stop;
899 }
900
901 Keys = 1 << 0 | 1 << 1;
902 }
903
904 case 3:
905 {
906 FormatEx(MapsFull[0], sizeof(MapsFull[]), "maps/%s.bsp", g_VotedMaps[0]);
907 if (!FileExists(MapsFull[0]))
908 {
909 ReplyToCommand(Client, "[SM] Maps '%s' is not valid!", g_VotedMaps[0]);
910 return Plugin_Stop;
911 }
912
913 FormatEx(MapsFull[1], sizeof(MapsFull[]), "maps/%s.bsp", g_VotedMaps[1]);
914 if (!FileExists(MapsFull[1]))
915 {
916 ReplyToCommand(Client, "[SM] Maps '%s' is not valid!", g_VotedMaps[1]);
917 return Plugin_Stop;
918 }
919
920 FormatEx(MapsFull[2], sizeof(MapsFull[]), "maps/%s.bsp", g_VotedMaps[2]);
921 if (!FileExists(MapsFull[2]))
922 {
923 ReplyToCommand(Client, "[SM] Maps '%s' is not valid!", g_VotedMaps[2]);
924 return Plugin_Stop;
925 }
926
927 Keys = 1 << 0 | 1 << 1 | 1 << 2;
928 }
929 }
930
931 new Handle:Menu_Handle = CreatePanel();
932
933 SetPanelKeys(Menu_Handle, Keys);
934 SetPanelTitle(Menu_Handle, MAPSVOTE_MENU_TITLE);
935 DrawPanelText(Menu_Handle, " \n");
936
937 switch (g_VotedMapsCount)
938 {
939 case 1:
940 {
941 new String:Buffer[128], String:Shorten[64], String:Old[64], String:Name[64], String:Steam[64];
942
943 FormatEx(Old, sizeof(Old), "%s", g_VotedMaps[0]);
944 ShortenMapName(Old, Shorten);
945
946 FormatEx(Buffer, sizeof(Buffer), "1. %s", Shorten);
947 DrawPanelText(Menu_Handle, Buffer);
948
949 GetClientName(Client, Name, sizeof(Name));
950 GetClientAuthId(Client, AuthId_Engine, Steam, sizeof(Steam));
951 LogMessage("Admin %s (%s) voted %s [sm_votemap]", Name, Steam, g_VotedMaps[0]);
952 PrintToChatAll("\x01Admin\x03 %s\x01 initiated a vote [\x04 %s\x01 ].", Name, g_VotedMaps[0]);
953 }
954
955 case 2:
956 {
957 new String:Buffer[128], String:Shorten[64], String:Old[64], String:Name[64], String:Steam[64];
958
959 FormatEx(Old, sizeof(Old), "%s", g_VotedMaps[0]);
960 ShortenMapName(Old, Shorten);
961
962 FormatEx(Buffer, sizeof(Buffer), "1. %s", Shorten);
963 DrawPanelText(Menu_Handle, Buffer);
964
965 FormatEx(Old, sizeof(Old), "%s", g_VotedMaps[1]);
966 ShortenMapName(Old, Shorten);
967
968 FormatEx(Buffer, sizeof(Buffer), "2. %s", Shorten);
969 DrawPanelText(Menu_Handle, Buffer);
970
971 GetClientName(Client, Name, sizeof(Name));
972 GetClientAuthId(Client, AuthId_Engine, Steam, sizeof(Steam));
973 PrintToChatAll("\x01Admin\x03 %s\x01 initiated a vote [\x04 %s\x01 |\x04 %s\x01 ].", Name, g_VotedMaps[0], g_VotedMaps[1]);
974 LogMessage("Admin %s (%s) voted %s | %s [sm_votemap]", Name, Steam, g_VotedMaps[0], g_VotedMaps[1]);
975 }
976
977 case 3:
978 {
979 new String:Buffer[128], String:Shorten[64], String:Old[64], String:Name[64], String:Steam[64];
980
981 FormatEx(Old, sizeof(Old), "%s", g_VotedMaps[0]);
982 ShortenMapName(Old, Shorten);
983
984 FormatEx(Buffer, sizeof(Buffer), "1. %s", Shorten);
985 DrawPanelText(Menu_Handle, Buffer);
986
987 FormatEx(Old, sizeof(Old), "%s", g_VotedMaps[1]);
988 ShortenMapName(Old, Shorten);
989
990 FormatEx(Buffer, sizeof(Buffer), "2. %s", Shorten);
991 DrawPanelText(Menu_Handle, Buffer);
992
993 FormatEx(Old, sizeof(Old), "%s", g_VotedMaps[2]);
994 ShortenMapName(Old, Shorten);
995
996 FormatEx(Buffer, sizeof(Buffer), "3. %s", Shorten);
997 DrawPanelText(Menu_Handle, Buffer);
998
999 GetClientName(Client, Name, sizeof(Name));
1000 GetClientAuthId(Client,AuthId_Engine, Steam, sizeof(Steam));
1001 PrintToChatAll("\x01Admin\x03 %s\x01 initiated a vote [\x04 %s\x01 |\x04 %s\x01 |\x04 %s\x01 ].", Name, g_VotedMaps[0], g_VotedMaps[1], g_VotedMaps[2]);
1002 LogMessage("Admin %s (%s) voted %s | %s | %s [sm_votemap]", Name, Steam, g_VotedMaps[0], g_VotedMaps[1], g_VotedMaps[2]);
1003 }
1004 }
1005
1006 g_VotedMapsVotes[0] = 0;
1007 g_VotedMapsVotes[1] = 0;
1008 g_VotedMapsVotes[2] = 0;
1009
1010 for (new Other = 1; Other <= MaxClients; Other++)
1011 {
1012 if (IsClientInGame(Other) && !IsFakeClient(Other) && !IsClientSourceTV(Other))
1013 SendPanelToClient(Menu_Handle, Other, VoteMapsMenuHandler, VOTING_TIME);
1014 }
1015
1016 CloseHandle(Menu_Handle);
1017
1018 CreateTimer(float(VOTING_TIME + 1), Timer_CheckVotesCount, _, TIMER_FLAG_NO_MAPCHANGE);
1019 return Plugin_Stop;
1020}
1021
1022public VoteMapsMenuHandler(Handle:Menu_Handle, MenuAction:Menu_Action, Param_A, Param_B)
1023{
1024 if (Menu_Action == MenuAction_Select && !BadPlayer(Param_A))
1025 {
1026 g_VotedMapsVotes[Param_B - 1]++;
1027
1028 new String:Old[64], String:Shorten[64];
1029 FormatEx(Old, sizeof(Old), "%s", g_VotedMaps[Param_B - 1]);
1030
1031 ShortenMapName(Old, Shorten);
1032 PrintToChat(Param_A, "\x01You voted for\x04 %s\x01.", Shorten);
1033 }
1034}
1035
1036public Action: Timer_CheckVotesCount(Handle:pTimer, any:Data)
1037{
1038 new MaxVotes = -999999, Winner = -1, Votes = 0;
1039 for (new Map = 0; Map < g_VotedMapsCount; Map++)
1040 {
1041 Votes = g_VotedMapsVotes[Map];
1042 if (Votes > MaxVotes)
1043 {
1044 Winner = Map;
1045 MaxVotes = Votes;
1046 }
1047 }
1048
1049 if (Winner != -1)
1050 {
1051 new Flags = GetConVarFlags(FindConVar("sm_nextmap")), NewFlags = 0;
1052 if (Flags & FCVAR_NOTIFY)
1053 {
1054 NewFlags = Flags;
1055 NewFlags &= ~FCVAR_NOTIFY;
1056
1057 SetConVarFlags(FindConVar("sm_nextmap"), NewFlags);
1058 }
1059
1060 SetNextMap(g_VotedMaps[Winner]);
1061 SetConVarFlags(FindConVar("sm_nextmap"), Flags);
1062
1063 new String:Old[64], String:Shorten[64];
1064 FormatEx(Old, sizeof(Old), "%s", g_VotedMaps[Winner]);
1065
1066 ShortenMapName(Old, Shorten);
1067 PrintToChatAll("\x01The next map will be\x04 %s\x01 (\x03%d vote%s\x01).", Shorten, MaxVotes, MaxVotes == 1 ? "" : "s");
1068 }
1069}