· 5 years ago · Mar 22, 2020, 01:50 PM
1/**
2 * vim: set filetype=c :
3 *
4 * =============================================================================
5 * PermaMute
6 *
7 * Copyright 2008 Ryan Mannion. All Rights Reserved.
8 *
9 * Modified by TheJCS
10 * =============================================================================
11 *
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include <sourcemod>
27#include <clientprefs>
28
29#undef REQUIRE_PLUGIN
30#include <adminmenu>
31#define REQUIRE_PLUGIN
32
33#pragma semicolon 1
34
35#define TEMPMUTE_VERSION "0.4"
36
37#define CVAR_VERSION 0
38#define CVAR_NUM_CVARS 1
39
40#define ACCESS_FLAG ADMFLAG_CHAT
41
42new Handle:g_cvars[CVAR_NUM_CVARS];
43new g_gagged = 0;
44new Handle:g_adminMenu = INVALID_HANDLE;
45
46// Tempvars for the menu
47new g_PMuteTarget[64];
48new TCommType:g_PMuteType[64];
49
50// Database
51new Handle:g_hDb;
52
53enum TCommType {
54 TCommType_TMute = 0,
55 TCommType_TUnMute,
56 TCommType_TGag,
57 TCommType_TUnGag,
58 TCommType_TSilence,
59 TCommType_TUnSilence,
60 TCommType_NumTypes
61};
62
63public Plugin:myinfo = {
64 name = "TempMute",
65 author = "TheJCS (original by FLOOR_MASTER)",
66 description = "Enable temp muting or gagging a player.",
67 version = TEMPMUTE_VERSION,
68 url = "http://www.thejcs.com.br"
69};
70
71public OnPluginStart() {
72 LoadTranslations("common.phrases");
73
74 g_cvars[CVAR_VERSION] = CreateConVar("sm_tempmute", TEMPMUTE_VERSION, "TempMute Version", FCVAR_PLUGIN|FCVAR_REPLICATED|FCVAR_NOTIFY);
75
76 RegConsoleCmd("say", Command_Say);
77 RegConsoleCmd("say_team", Command_Say);
78
79 RegAdminCmd("sm_tmute", Command_TMute, ACCESS_FLAG, "sm_tmute <player> <time> - Removes a player's ability to use voice for [time] minutes (-1 = forever).");
80 RegAdminCmd("sm_tmuteid", Command_TMuteId, ACCESS_FLAG, "sm_tmuteid <player> <time> - Removes a player's ability to use voice for [time] minutes (-1 = forever).");
81 RegAdminCmd("sm_tunmuteid", Command_TMuteId, ACCESS_FLAG, "sm_tunmuteid <player> <time> - Removes a player's ability to use voice for [time] minutes (-1 = forever).");
82 RegAdminCmd("sm_tunmute", Command_TUnMute, ACCESS_FLAG, "sm_tunmute <player> - Restores a player's ability to use voice.");
83 RegAdminCmd("sm_tgag", Command_TGag, ACCESS_FLAG, "sm_tgag <player> <time> - Permanently removes a player's ability to use chat for [time] minutes (-1 = forever).");
84 RegAdminCmd("sm_tgagid", Command_TGagId, ACCESS_FLAG, "sm_tgagid <player> <time> - Permanently removes a player's ability to use chat for [time] minutes (-1 = forever).");
85 RegAdminCmd("sm_tungag", Command_TUnGag, ACCESS_FLAG, "sm_tungag <player> - Restores a player's ability to use chat.");
86 RegAdminCmd("sm_tungag", Command_TUnGag, ACCESS_FLAG, "sm_tungagid <player> - Restores a player's ability to use chat.");
87 RegAdminCmd("sm_tsilence", Command_TSilence, ACCESS_FLAG, "sm_tsilence <player> <time> - Removes a player's ability to use voice and chat for [time] minutes (-1 = forever).");
88 RegAdminCmd("sm_tsilenceid", Command_TSilenceId, ACCESS_FLAG, "sm_tsilenceid <player> <time> - Removes a player's ability to use voice and chat for [time] minutes (-1 = forever).");
89 RegAdminCmd("sm_tunsilenceid", Command_TUnSilenceId, ACCESS_FLAG, "sm_tunsilence <player> - Restores a player's ability to use voice and chat.");
90 RegAdminCmd("sm_tunsilence", Command_TUnSilence, ACCESS_FLAG, "sm_tunsilence <player> - Restores a player's ability to use voice and chat.");
91
92 RegConsoleCmd("sm_tempmute_status", Command_Status, "sm_tempmute_status - Show your temp mute status.");
93
94 new Handle:topmenu;
95 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
96 {
97 OnAdminMenuReady(topmenu);
98 }
99
100 if (!PluginExists("basecomm.smx"))
101 {
102 LogError("FATAL: This plugin requires basecomm. Please load basecomm and try loading this plugin again.");
103 SetFailState("This plugin requires basecomm. Please load basecomm and try loading this plugin again.");
104 }
105
106 ConnectToDatabase();
107}
108
109public Action:timerUnmute(Handle:timer, any:client) {
110 if (IsClientInGame(client))
111 {
112 new time = GetTime();
113 decl val;
114 decl String:authid[64];
115
116 GetClientAuthString(client, authid, sizeof(authid));
117
118 val = GetMuteStatus(authid);
119 if (val > 0 && val < time)
120 {
121 PerformTMute(0, client, TCommType_TUnMute);
122 }
123
124 val = GetGagStatus(authid);
125 if (val > 0 && val < time)
126 {
127 PerformTMute(0, client, TCommType_TUnGag);
128 }
129 }
130}
131
132stock bool:PluginExists(const String:plugin_name[]) {
133 new Handle:iter = GetPluginIterator();
134 new Handle:plugin = INVALID_HANDLE;
135 decl String:name[64];
136
137 while (MorePlugins(iter))
138 {
139 plugin = ReadPlugin(iter);
140 GetPluginFilename(plugin, name, sizeof(name));
141 if (StrEqual(name, plugin_name))
142 {
143 CloseHandle(iter);
144 return true;
145 }
146 }
147
148 CloseHandle(iter);
149 return false;
150}
151
152public OnLibraryRemoved(const String:name[]) {
153 if (StrEqual(name, "adminmenu"))
154 {
155 g_adminMenu = INVALID_HANDLE;
156 }
157}
158
159public OnAdminMenuReady(Handle:topmenu) {
160 if (topmenu == g_adminMenu)
161 {
162 return;
163 }
164
165 g_adminMenu = topmenu;
166
167 new TopMenuObject:player_commands = FindTopMenuCategory(g_adminMenu, ADMINMENU_PLAYERCOMMANDS);
168
169 if (player_commands == INVALID_TOPMENUOBJECT)
170 {
171 return;
172 }
173
174 AddToTopMenu(g_adminMenu, "sm_pmute", TopMenuObject_Item, AdminMenu_PMute,
175 player_commands, "sm_pmute", ACCESS_FLAG);
176}
177
178public AdminMenu_PMute(Handle:topmenu, TopMenuAction:action, TopMenuObject:object_id, param, String:buffer[], maxlength) {
179 switch (action)
180 {
181 case TopMenuAction_DisplayOption:
182 {
183 Format(buffer, maxlength, "TempGag/TempMute player");
184 }
185 case TopMenuAction_SelectOption:
186 {
187 DisplayPMutePlayerMenu(param);
188 }
189 }
190}
191
192stock DisplayPMutePlayerMenu(client) {
193 new Handle:menu = CreateMenu(MenuHandler_TMutePlayer);
194
195 decl String:title[100];
196 Format(title, sizeof(title), "TempGag/TempMute player:");
197 SetMenuTitle(menu, title);
198 SetMenuExitBackButton(menu, true);
199 AddTargetsToMenu(menu, client, true, false);
200 DisplayMenu(menu, client, MENU_TIME_FOREVER);
201}
202
203public MenuHandler_TMutePlayer(Handle:menu, MenuAction:action, param1, param2) {
204 new client = param1;
205
206 switch (action) {
207 case MenuAction_End:
208 {
209 CloseHandle(menu);
210 }
211 case MenuAction_Cancel:
212 {
213 if (param2 == MenuCancel_ExitBack && g_adminMenu != INVALID_HANDLE)
214 {
215 DisplayTopMenu(g_adminMenu, client, TopMenuPosition_LastCategory);
216 }
217 }
218 case MenuAction_Select:
219 {
220 decl String:info[32];
221
222 GetMenuItem(menu, param2, info, sizeof(info));
223 new userid = StringToInt(info);
224 new target = GetClientOfUserId(userid);
225
226 if (!target)
227 {
228 PrintToChat(client, "[TEMPMUTE] %t", "Player no longer available");
229 }
230 else if (!CanUserTarget(client, target))
231 {
232 PrintToChat(client, "[TEMPMUTE] %t", "Unable to target");
233 }
234 else
235 {
236 g_PMuteTarget[client] = target;
237 DisplayPMuteTypesMenu(client, target);
238 }
239 }
240 }
241}
242
243stock DisplayPMuteTypesMenu(client, target) {
244 new Handle:menu = CreateMenu(MenuHandler_TMuteTypes);
245
246 decl String:title[100];
247 Format(title, sizeof(title), "Choose Type:");
248 SetMenuTitle(menu, title);
249 SetMenuExitBackButton(menu, true);
250
251 decl val;
252 new time = GetTime();
253 new bool:silenced = true;
254
255 decl String:authid[64];
256 GetClientAuthString(target, authid, sizeof(authid));
257
258 val = GetMuteStatus(authid);
259 if (val < time)
260 {
261 AddMenuItem(menu, "0", "TempMute Player");
262 silenced = false;
263 }
264 else
265 {
266 AddMenuItem(menu, "1", "UnTempMute Player");
267 }
268
269 val = GetGagStatus(authid);
270 if (val < time)
271 {
272 AddMenuItem(menu, "2", "TempGag Player");
273 silenced = false;
274 }
275 else
276 {
277 AddMenuItem(menu, "3", "UnTempGag Player");
278 }
279
280 if (silenced)
281 {
282 AddMenuItem(menu, "5", "UnTempSilence Player");
283 }
284 else
285 {
286 AddMenuItem(menu, "4", "TempSilence Player");
287 }
288
289 DisplayMenu(menu, client, MENU_TIME_FOREVER);
290}
291
292public MenuHandler_TMuteTypes(Handle:menu, MenuAction:action, param1, param2) {
293 new client = param1;
294
295 switch (action)
296 {
297 case MenuAction_End:
298 {
299 CloseHandle(menu);
300 }
301 case MenuAction_Cancel:
302 {
303 if (param1 == MenuCancel_ExitBack && g_adminMenu != INVALID_HANDLE)
304 {
305 DisplayTopMenu(g_adminMenu, client, TopMenuPosition_LastCategory);
306 }
307 }
308 case MenuAction_Select:
309 {
310 decl String:info[32];
311
312 GetMenuItem(menu, param2, info, sizeof(info));
313 new TCommType:type = TCommType:StringToInt(info);
314
315 if(type == TCommType_TUnMute || type == TCommType_TUnGag || type == TCommType_TUnSilence)
316 {
317 PerformTMute(client, g_PMuteTarget[client], type);
318 }
319 else
320 {
321 g_PMuteType[client] = type;
322 DisplayPMuteTimeMenu(client, g_PMuteTarget[client]);
323 }
324 }
325 }
326}
327
328stock DisplayPMuteTimeMenu(client, target) {
329 new Handle:menu = CreateMenu(MenuHandler_TMuteTime);
330
331 decl String:title[100];
332 Format(title, sizeof(title), "Choose Time:");
333 SetMenuTitle(menu, title);
334 SetMenuExitBackButton(menu, true);
335
336 AddMenuItem(menu, "1", "1 Minute");
337 AddMenuItem(menu, "5", "5 Minutes");
338 AddMenuItem(menu, "10", "10 Minutes");
339 AddMenuItem(menu, "30", "30 Minutes");
340 AddMenuItem(menu, "60", "1 Hour");
341 AddMenuItem(menu, "240", "4 Hours");
342 AddMenuItem(menu, "480", "8 Hours");
343 AddMenuItem(menu, "720", "12 Hours");
344 AddMenuItem(menu, "1440", "1 Day");
345 AddMenuItem(menu, "4320", "3 Days");
346 AddMenuItem(menu, "21600", "15 Days");
347 AddMenuItem(menu, "44640", "1 Month");
348 AddMenuItem(menu, "-1", "Forever");
349
350 DisplayMenu(menu, client, MENU_TIME_FOREVER);
351}
352
353public MenuHandler_TMuteTime(Handle:menu, MenuAction:action, param1, param2) {
354 new client = param1;
355
356 switch (action) {
357 case MenuAction_End:
358 {
359 CloseHandle(menu);
360 }
361 case MenuAction_Cancel:
362 {
363 if (param1 == MenuCancel_ExitBack && g_adminMenu != INVALID_HANDLE)
364 {
365 DisplayTopMenu(g_adminMenu, client, TopMenuPosition_LastCategory);
366 }
367 }
368 case MenuAction_Select:
369 {
370 decl String:time[16];
371
372 GetMenuItem(menu, param2, time, sizeof(time));
373
374 PerformTMute(client, g_PMuteTarget[client], g_PMuteType[client], time);
375 }
376 }
377}
378
379stock PerformTMute(client, target, TCommType:type, String:time[]="") {
380 decl String:cmd[32];
381 new target_userid = GetClientUserId(target);
382 decl String:target_name[MAX_NAME_LENGTH];
383 GetClientName(target, target_name, sizeof(target_name));
384
385 decl String:authid[64];
386 GetClientAuthString(target, authid, sizeof(authid));
387
388 switch (type) {
389 case TCommType_TMute:
390 {
391 Format(cmd, sizeof(cmd), "sm_mute #%d", target_userid);
392 ServerCommand(cmd);
393
394 new val = StringToInt(time);
395 if(val > 0)
396 {
397 val = GetTime() + (val*60);
398 }
399 decl String:dur[64];
400 IntToString(val, dur, sizeof(dur));
401
402 SetMuteStatus(authid, val);
403
404 if(val > 0)
405 {
406 CreateTimer(float(val - GetTime() + 1), timerUnmute, target);
407 }
408
409 if (client) {
410 ShowActivity2(client, "[TEMPMUTE] ", "Muted %N for %s minutes", target, time);
411 }
412 }
413 case TCommType_TUnMute:
414 {
415 Format(cmd, sizeof(cmd), "sm_unmute #%d", target_userid);
416 ServerCommand(cmd);
417
418 SetMuteStatus(authid, 0);
419
420 if (client) {
421 ShowActivity2(client, "[TEMPMUTE] ", "UnMuted %N", target);
422 }
423 }
424 case TCommType_TGag:
425 {
426 Format(cmd, sizeof(cmd), "sm_gag #%d", target_userid);
427 ServerCommand(cmd);
428
429 new val = StringToInt(time);
430 if(val > 0)
431 {
432 val = GetTime() + (val*60);
433 }
434 decl String:dur[64];
435 IntToString(val, dur, sizeof(dur));
436
437 SetGagStatus(authid, val);
438
439 if(val > 0)
440 {
441 CreateTimer(float(val - GetTime() + 1), timerUnmute, target);
442 }
443
444 if (client) {
445 ShowActivity2(client, "[TEMPMUTE] ", "Gagged %N for %s minutes", target, time);
446 }
447 }
448 case TCommType_TUnGag:
449 {
450 Format(cmd, sizeof(cmd), "sm_ungag #%d", target_userid);
451 ServerCommand(cmd);
452
453 SetGagStatus(authid, 0);
454
455 if (client) {
456 ShowActivity2(client, "[TEMPMUTE] ", "UnGagged %N", target);
457 }
458 }
459 case TCommType_TSilence:
460 {
461 PerformTMute(client, target, TCommType_TMute, time);
462 PerformTMute(client, target, TCommType_TGag, time);
463 }
464 case TCommType_TUnSilence:
465 {
466 PerformTMute(client, target, TCommType_TUnMute);
467 PerformTMute(client, target, TCommType_TUnGag);
468 }
469 }
470
471}
472
473public Action:Command_Status(client, args) {
474 decl String:authid[64];
475 new bool:mute = false;
476 new bool:gag = false;
477
478 GetClientAuthString(client, authid, sizeof(authid));
479
480 new time = GetTime();
481 new mute_time = GetMuteStatus(authid);
482 new gag_time = GetGagStatus(authid);
483
484 if(mute_time > time || mute_time < 0)
485 mute = true;
486 if(gag_time > time || gag_time < 0)
487 gag = true;
488
489 if(gag && mute)
490 {
491 decl String:until[64];
492 new val = (gag_time > mute_time ? mute_time : gag_time);
493
494 if(val < 0)
495 {
496 strcopy(until, sizeof(until), "forever");
497 }
498 else
499 {
500 FormatTime(until, sizeof(until), "until %x %X", val);
501 }
502
503 ReplyToCommand(client, "You are silenced %s", until);
504 }
505 else if(gag)
506 {
507 decl String:until[64];
508
509 if(gag_time < 0)
510 {
511 strcopy(until, sizeof(until), "forever");
512 }
513 else
514 {
515 FormatTime(until, sizeof(until), "until %x %X", gag_time);
516 }
517
518 ReplyToCommand(client, "You are gagged %s", until);
519 }
520 else if(mute)
521 {
522 decl String:until[64];
523
524 if(mute_time < 0)
525 {
526 strcopy(until, sizeof(until), "forever");
527 }
528 else
529 {
530 FormatTime(until, sizeof(until), "until %x %X", mute_time);
531 }
532
533 ReplyToCommand(client, "You are gagged %s", until);
534 }
535 else
536 {
537 ReplyToCommand(client, "You are not gagged nor muted");
538 }
539}
540
541public Action:Command_Say(client, args) {
542 if (g_gagged & (1 << (client - 1)))
543 {
544 return Plugin_Handled;
545 }
546 return Plugin_Continue;
547}
548
549public OnClientPostAdminCheck(client) {
550 ProcessDB(client);
551}
552
553stock ProcessDB(client) {
554 decl String:authid[64];
555 new userid = GetClientUserId(client);
556 new time = GetTime();
557 new val;
558
559 GetClientAuthString(client, authid, sizeof(authid));
560
561 val = GetMuteStatus(authid);
562 if(val > time || val < 0)
563 {
564 decl String:date[64];
565 FormatTime(date, sizeof(date), "%x %X", val);
566 PrintToServer("[TEMPMUTE] %s is muted until %s", authid, date);
567
568 decl String:cmd[32];
569 Format(cmd, sizeof(cmd), "sm_mute #%d", userid);
570 ServerCommand(cmd);
571
572 if(val > 0)
573 {
574 CreateTimer(float(val - GetTime() + 1), timerUnmute, client);
575 }
576 }
577 else if(val != 0)
578 {
579 SetMuteStatus(authid, 0);
580 }
581
582 val = GetGagStatus(authid);
583 if(val > time || val < 0)
584 {
585 decl String:date[64];
586 FormatTime(date, sizeof(date), "%x %X", val);
587 PrintToServer("[TEMPMUTE] %s is gagged until %s", authid, date);
588
589 decl String:cmd[32];
590 Format(cmd, sizeof(cmd), "sm_gag #%d", userid);
591 ServerCommand(cmd);
592
593 if(val > 0)
594 {
595 CreateTimer(float(val - GetTime() + 1), timerUnmute, client);
596 }
597 }
598 else if(val != 0)
599 {
600 SetGagStatus(authid, 0);
601 }
602}
603
604public Action:Command_TMute(client, args) {
605 if (args < 2)
606 {
607 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tmute <player> <time>");
608 return Plugin_Handled;
609 }
610
611 decl String:arg[64];
612 GetCmdArg(1, arg, sizeof(arg));
613 decl String:arg2[64];
614 GetCmdArg(2, arg2, sizeof(arg2));
615
616 TargetedAction(client, TCommType_TMute, arg, arg2);
617 return Plugin_Handled;
618}
619
620public Action:Command_TMuteId(client, args) {
621 if (args < 2)
622 {
623 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tmuteid <player> <time>");
624 return Plugin_Handled;
625 }
626
627 decl String:arg[64];
628 GetCmdArg(1, arg, sizeof(arg));
629 decl String:arg2[64];
630 GetCmdArg(2, arg2, sizeof(arg2));
631
632 new val = StringToInt(arg2);
633 if(val > 0)
634 val = GetTime() + (val*60);
635 SetMuteStatus(arg, val);
636 return Plugin_Handled;
637}
638
639public Action:Command_TUnMuteId(client, args) {
640 if (args < 2)
641 {
642 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tunmuteid <player> <time>");
643 return Plugin_Handled;
644 }
645
646 decl String:arg[64];
647 GetCmdArg(1, arg, sizeof(arg));
648 decl String:arg2[64];
649 GetCmdArg(2, arg2, sizeof(arg2));
650
651 SetMuteStatus(arg, 0);
652 return Plugin_Handled;
653}
654
655public Action:Command_TUnMute(client, args) {
656 if (args < 1)
657 {
658 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tunmute <player>");
659 return Plugin_Handled;
660 }
661
662 decl String:arg[64];
663 GetCmdArg(1, arg, sizeof(arg));
664
665 TargetedAction(client, TCommType_TUnMute, arg);
666 return Plugin_Handled;
667}
668
669public Action:Command_TGag(client, args) {
670 if (args < 2)
671 {
672 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tgag <player> <time>");
673 return Plugin_Handled;
674 }
675
676 decl String:arg[64];
677 GetCmdArg(1, arg, sizeof(arg));
678 decl String:arg2[64];
679 GetCmdArg(2, arg2, sizeof(arg2));
680
681 TargetedAction(client, TCommType_TGag, arg, arg2);
682 return Plugin_Handled;
683}
684
685public Action:Command_TGagId(client, args) {
686 if (args < 2)
687 {
688 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tgagid <player> <time>");
689 return Plugin_Handled;
690 }
691
692 decl String:arg[64];
693 GetCmdArg(1, arg, sizeof(arg));
694 decl String:arg2[64];
695 GetCmdArg(2, arg2, sizeof(arg2));
696
697 new val = StringToInt(arg2);
698 if(val > 0)
699 val = GetTime() + (val*60);
700 SetGagStatus(arg, val);
701 return Plugin_Handled;
702}
703
704public Action:Command_TUnGagId(client, args) {
705 if (args < 2)
706 {
707 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tungagid <player> <time>");
708 return Plugin_Handled;
709 }
710
711 decl String:arg[64];
712 GetCmdArg(1, arg, sizeof(arg));
713 decl String:arg2[64];
714 GetCmdArg(2, arg2, sizeof(arg2));
715
716 SetGagStatus(arg, 0);
717 return Plugin_Handled;
718}
719
720public Action:Command_TUnGag(client, args) {
721 if (args < 1)
722 {
723 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tungag <player>");
724 return Plugin_Handled;
725 }
726
727 decl String:arg[64];
728 GetCmdArg(1, arg, sizeof(arg));
729
730 TargetedAction(client, TCommType_TUnGag, arg);
731 return Plugin_Handled;
732}
733
734public Action:Command_TSilence(client, args) {
735 if (args < 2)
736 {
737 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tsilence <player> <time>");
738 return Plugin_Handled;
739 }
740
741 decl String:arg[64];
742 GetCmdArg(1, arg, sizeof(arg));
743 decl String:arg2[64];
744 GetCmdArg(2, arg2, sizeof(arg2));
745
746 TargetedAction(client, TCommType_TSilence, arg, arg2);
747 return Plugin_Handled;
748}
749
750public Action:Command_TSilenceId(client, args) {
751 if (args < 2)
752 {
753 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tsilenceid <player> <time>");
754 return Plugin_Handled;
755 }
756
757 decl String:arg[64];
758 GetCmdArg(1, arg, sizeof(arg));
759 decl String:arg2[64];
760 GetCmdArg(2, arg2, sizeof(arg2));
761
762 new val = StringToInt(arg2);
763 if(val > 0)
764 val = GetTime() + (val*60);
765 SetMuteStatus(arg, val);
766 SetGagStatus(arg, val);
767 return Plugin_Handled;
768}
769
770public Action:Command_TUnSilenceId(client, args) {
771 if (args < 2)
772 {
773 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_tunsilenceid <player> <time>");
774 return Plugin_Handled;
775 }
776
777 decl String:arg[64];
778 GetCmdArg(1, arg, sizeof(arg));
779 decl String:arg2[64];
780 GetCmdArg(2, arg2, sizeof(arg2));
781
782 SetMuteStatus(arg, 0);
783 SetGagStatus(arg, 0);
784 return Plugin_Handled;
785}
786
787public Action:Command_TUnSilence(client, args) {
788 if (args < 1)
789 {
790 ReplyToCommand(client, "[TEMPMUTE] Usage: sm_punsilence <player>");
791 return Plugin_Handled;
792 }
793
794 decl String:arg[64];
795 GetCmdArg(1, arg, sizeof(arg));
796
797 TargetedAction(client, TCommType_TUnSilence, arg);
798 return Plugin_Handled;
799}
800
801stock TargetedAction(client, TCommType:type, const String:target_string[], String:time[]="") {
802 decl String:target_name[MAX_TARGET_LENGTH];
803 decl target_list[MAXPLAYERS];
804 decl target_count;
805 decl bool:tn_is_ml;
806
807 if ((target_count = ProcessTargetString(
808 target_string,
809 client,
810 target_list,
811 MAXPLAYERS,
812 0,
813 target_name,
814 sizeof(target_name),
815 tn_is_ml)) <= 0) {
816 ReplyToTargetError(client, target_count);
817 return;
818 }
819
820 for (new i = 0; i < target_count; i++)
821 {
822 PerformTMute(client, target_list[i], type, time);
823 }
824}
825
826ConnectToDatabase() {
827 new String:error[255];
828
829 if (SQL_CheckConfig("tempmute"))
830 {
831 g_hDb = SQL_Connect("tempmute",true,error, sizeof(error));
832 if (g_hDb == INVALID_HANDLE)
833 SetFailState("Failed to connect: %s", error);
834
835 decl String:query[255];
836 Format(query, sizeof(query), "SET NAMES 'utf8'");
837 if (!SQL_FastQuery(g_hDb, query))
838 LogMessage("Can't select character set (%s)", query);
839
840 CreateTablesMySQL();
841 }
842 else
843 {
844 g_hDb = SQLite_UseDatabase("tempmute", error, sizeof(error));
845 if (g_hDb == INVALID_HANDLE)
846 SetFailState("SQL error: %s", error);
847
848 CreateTablesSQLite();
849 }
850}
851
852CreateTablesMySQL() {
853 SQL_FastQuery(g_hDb, "CREATE TABLE IF NOT EXISTS `tempmutes_entries` (`steamid` varchar(25) NOT NULL, `mute` int(12) NOT NULL default '0', `gag` int(1) NOT NULL default '0', PRIMARY KEY (`steamid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
854}
855
856CreateTablesSQLite() {
857 SQL_FastQuery(g_hDb, "CREATE TABLE IF NOT EXISTS `tempmutes_entries` (`steamid` TEXT, `mute` INTEGER, `gag` INTEGER);");
858}
859
860GetMuteStatus(const String:steamid[]) {
861 decl String:query[128];
862 new Handle:result;
863
864 Format(query, sizeof(query), "SELECT `mute` FROM `tempmutes_entries` WHERE steamid = '%s'", steamid);
865 result = SQL_Query(g_hDb, query);
866
867 new mute = 0;
868
869 if(SQL_GetRowCount(result) != 0)
870 {
871 SQL_FetchRow(result);
872 mute = SQL_FetchInt(result, 0);
873 }
874
875 CloseHandle(result);
876
877 return mute;
878}
879
880SetMuteStatus(const String:steamid[], time) {
881 decl String:query[128];
882 new Handle:result;
883
884 Format(query, sizeof(query), "SELECT `mute` FROM `tempmutes_entries` WHERE steamid = '%s'", steamid);
885 result = SQL_Query(g_hDb, query);
886
887 if(SQL_GetRowCount(result) == 0)
888 {
889 Format(query, sizeof(query), "INSERT INTO `tempmutes_entries` (steamid) VALUES ('%s')", steamid);
890 SQL_Query(g_hDb, query);
891 }
892
893 Format(query, sizeof(query), "UPDATE `tempmutes_entries` SET `mute` = %i WHERE steamid = '%s'", time, steamid);
894
895 SQL_Query(g_hDb, query);
896 CloseHandle(result);
897}
898
899GetGagStatus(const String:steamid[]) {
900 decl String:query[128];
901 new Handle:result;
902
903 Format(query, sizeof(query), "SELECT `gag` FROM `tempmutes_entries` WHERE steamid = '%s'", steamid);
904 result = SQL_Query(g_hDb, query);
905
906 new gag = 0;
907
908 if(SQL_GetRowCount(result) != 0)
909 {
910 SQL_FetchRow(result);
911 gag = SQL_FetchInt(result, 0);
912 }
913
914 CloseHandle(result);
915
916 return gag;
917}
918
919SetGagStatus(const String:steamid[], time) {
920 decl String:query[128];
921 new Handle:result;
922
923 Format(query, sizeof(query), "SELECT `gag` FROM `tempmutes_entries` WHERE steamid = '%s'", steamid);
924 result = SQL_Query(g_hDb, query);
925
926 if(SQL_GetRowCount(result) == 0)
927 {
928 Format(query, sizeof(query), "INSERT INTO `tempmutes_entries` (steamid) VALUES ('%s')", steamid);
929 SQL_Query(g_hDb, query);
930 }
931
932 Format(query, sizeof(query), "UPDATE `tempmutes_entries` SET `gag` = %i WHERE steamid = '%s'", time, steamid);
933
934 SQL_Query(g_hDb, query);
935 CloseHandle(result);
936}