forked from xPaw/AMXX-Gag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amx_gag.sma
1821 lines (1436 loc) · 42.1 KB
/
amx_gag.sma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include < amxmodx >
#include < amxmisc >
#include < engine >
#include < sqlx >
#define MAX_PLAYERS 32
#define MAX_PATTERN_LEN 255
enum ( <<= 1 )
{
GAG_CHAT = 1,
GAG_TEAMSAY,
GAG_VOICE
};
enum _:GagData
{
GAG_STEAMID[ 35 ],
GAG_TIME,
GAG_START,
GAG_FLAGS,
GAG_SAVE,
GAG_NOTIFY
};
enum _:TimeUnit
{
TIMEUNIT_SECONDS = 0,
TIMEUNIT_MINUTES,
TIMEUNIT_HOURS,
TIMEUNIT_DAYS,
TIMEUNIT_WEEKS
};
new const g_szTimeUnitName[ TimeUnit ][ 2 ][ ] =
{
{ "second", "seconds" },
{ "minute", "minutes" },
{ "hour", "hours" },
{ "day", "days" },
{ "week", "weeks" }
};
new const g_iTimeUnitMult[ TimeUnit ] =
{
1,
60,
3600,
86400,
604800
};
new const DATETIME_FORMAT[ ] = "%Y-%m-%d %H:%M:%S";
const DATE_SIZE = 20;
new Array:g_aGagTimes;
new Array:g_aGagData;
new Trie:g_tArrayPos;
new Trie:g_tTimeUnitWords;
new g_iGagged;
new g_iThinker;
new g_iTotalGagTimes;
new g_iMsgSayText;
new g_szSteamID[ MAX_PLAYERS + 1 ][ 35 ];
new g_iMenuOption[ MAX_PLAYERS + 1 ];
new g_iMenuPosition[ MAX_PLAYERS + 1 ];
new g_iMenuPlayers[ MAX_PLAYERS + 1 ][ 32 ];
new g_iMenuFlags[ MAX_PLAYERS + 1 ];
new g_szGagFile[ 64 ];
new bool:g_bColorSupported;
new g_pCvarDefaultFlags;
new g_pCvarDefaultTime;
new g_pCvarTimeUnit;
new g_pCvarMaxTime;
new g_pCvarSQL;
new g_pCvarSQLHost;
new g_pCvarSQLUser;
new g_pCvarSQLPass;
new g_pCvarSQLDb;
new bool:g_bUsingSQL = false;
new Handle:g_hSqlTuple;
new szQuery[ 1024 ];
public plugin_init( )
{
register_plugin( "AMXX Gag", "1.5.0", "xPaw & Exolent" );
register_clcmd( "say", "CmdSay" );
register_clcmd( "say_team", "CmdTeamSay" );
register_concmd( "amx_gag", "CmdGagPlayer", ADMIN_KICK, "<nick or #userid> <time> <a|b|c> -- Use 0 time for permanent" );
register_concmd( "amx_addgag", "CmdAddGag", ADMIN_KICK, "<authid> <time> <a|b|c> -- Use 0 time for permanent" );
register_concmd( "amx_ungag", "CmdUnGagPlayer", ADMIN_KICK, "<nick or #userid>" );
register_concmd( "amx_gagmenu", "CmdGagMenu", ADMIN_KICK, "- displays gag menu" );
register_srvcmd( "amx_gag_times", "CmdSetBanTimes" );
register_menu( "Gag Menu", 1023, "ActionGagMenu" );
register_menu( "Gag Flags", 1023, "ActionGagFlags" );
register_message( get_user_msgid( "SayText" ), "MessageSayText" );
g_pCvarDefaultFlags = register_cvar( "amx_gag_default_flags", "abc" );
g_pCvarDefaultTime = register_cvar( "amx_gag_default_time", "600" );
g_pCvarTimeUnit = register_cvar( "amx_gag_time_units", "0" );
g_pCvarMaxTime = register_cvar( "amx_gag_max_time", "86400" );
g_pCvarSQL = register_cvar( "amx_gag_sql", "0" );
g_pCvarSQLHost = register_cvar( "amx_gag_sql_host", "" );
g_pCvarSQLUser = register_cvar( "amx_gag_sql_user", "" );
g_pCvarSQLPass = register_cvar( "amx_gag_sql_pass", "" );
g_pCvarSQLDb = register_cvar( "amx_gag_sql_db", "" );
g_tArrayPos = TrieCreate( );
g_aGagTimes = ArrayCreate( );
g_aGagData = ArrayCreate( GagData );
g_bColorSupported = bool:colored_menus( );
g_iMsgSayText = get_user_msgid( "SayText" );
// Let words work with the time unit cvar
g_tTimeUnitWords = TrieCreate( );
for( new i = 0; i < TimeUnit; i++ )
{
TrieSetCell( g_tTimeUnitWords, g_szTimeUnitName[ i ][ 0 ], i );
TrieSetCell( g_tTimeUnitWords, g_szTimeUnitName[ i ][ 1 ], i );
}
// This is used for ungag in the menu
ArrayPushCell( g_aGagTimes, 0 );
// Gag times for the gag menu (amx_gagmenu)
// Default values: 60 300 600 1800 3600 7200 86400
new const iDefaultTimes[ ] = { 60, 300, 600, 1800, 3600, 7200, 86400, 0 };
// Load up standart times
for( new i = 0; i < sizeof( iDefaultTimes ); i++ )
{
ArrayPushCell( g_aGagTimes, iDefaultTimes[ i ] );
}
g_iTotalGagTimes = sizeof( iDefaultTimes ) + 1;
// Set up entity-thinker
new const szClassName[ ] = "gag_thinker";
g_iThinker = create_entity( "info_target" );
entity_set_string( g_iThinker, EV_SZ_classname, szClassName );
register_think( szClassName, "FwdThink" );
// Load gags from file
get_datadir( g_szGagFile, charsmax( g_szGagFile ) );
add( g_szGagFile, charsmax( g_szGagFile ), "/gags.txt" );
// Set server's SteamID to "SERVER"
copy( g_szSteamID[ 0 ], charsmax( g_szSteamID[ ] ), "SERVER" );
}
public plugin_natives( )
{
register_library( "amx_gag" );
register_native( "is_user_gagged" , "_is_user_gagged" );
register_native( "set_user_gagged", "_set_user_gagged" );
register_native( "get_gagtime" , "_get_gagtime" );
register_native( "gag_check" , "_gag_check" );
register_native( "gag_add" , "_gag_add" );
register_native( "gag_remove", "_gag_remove" );
}
public _is_user_gagged( iPlugin, iParams )
{
new iPlayer = get_param( 1 );
return ( is_user_connected( iPlayer ) && TrieKeyExists( g_tArrayPos, g_szSteamID[ iPlayer ] ) );
}
public _set_user_gagged( iPlugin, iParams )
{
new iPlayer = get_param( 1 );
new bGagged = get_param( 2 );
new iSeconds = get_param( 3 );
new bSave = get_param( 4 );
new iFlags = get_param( 5 );
if( !is_user_connected( iPlayer ) )
{
return 0;
}
if( bGagged )
{
if( TrieKeyExists( g_tArrayPos, g_szSteamID[ iPlayer ] ) )
{
return 0;
}
GagPlayer( 0, iPlayer, g_szSteamID[ iPlayer ], iSeconds, iFlags, bSave, 0 );
}
else
{
new iArrayPos;
if( !TrieGetCell( g_tArrayPos, g_szSteamID[ iPlayer ], iArrayPos ) )
{
return 0;
}
new data[ GagData ];
ArrayGetArray( g_aGagData, iArrayPos, data );
DeleteGag( iArrayPos );
if( !g_bUsingSQL && data[ GAG_SAVE ] )
{
SaveToFile( );
}
}
return 1;
}
public _get_gagtime( iPlugin, iParams )
{
new iPlayer = get_param( 1 );
new iTime = 0;
if( is_user_connected( iPlayer ) )
{
new iArrayPos;
if( TrieGetCell( g_tArrayPos, g_szSteamID[ iPlayer ], iArrayPos ) )
{
new data[ GagData ];
ArrayGetArray( g_aGagData, iArrayPos, data );
if( data[ GAG_TIME ] > 0 )
{
iTime = data[ GAG_START ] + data[ GAG_TIME ] - get_systime( );
}
}
}
return iTime;
}
public _gag_check( iPlugin, iParams )
{
new szSteamID[ 35 ];
get_string( 1, szSteamID, charsmax( szSteamID ) );
return _:TrieKeyExists( g_tArrayPos, szSteamID );
}
public _gag_add( iPlugin, iParams )
{
new szSteamID[ 35 ];
get_string( 1, szSteamID, charsmax( szSteamID ) );
if( TrieKeyExists( g_tArrayPos, szSteamID ) )
{
return 0;
}
new iSeconds = get_param( 2 );
new bSave = get_param( 3 );
new iFlags = get_param( 4 );
GagPlayer( 0, 0, szSteamID, iSeconds, iFlags, bSave, 0 );
return 1;
}
public _gag_remove( iPlugin, iParams )
{
new szSteamID[ 35 ];
get_string( 1, szSteamID, charsmax( szSteamID ) );
new iArrayPos;
if( !TrieGetCell( g_tArrayPos, szSteamID, iArrayPos ) )
{
return 0;
}
DeleteGag( iArrayPos );
return 1;
}
public plugin_cfg( )
{
// Check SQL
InitSQL( );
if( !g_bUsingSQL )
{
// If not using SQL, load from file
LoadFromFile( );
}
}
InitSQL( )
{
// Init SQL after configs were executed
if( get_pcvar_num( g_pCvarSQL ) )
{
new szHost[ 64 ], szUser[ 64 ], szPass[ 64 ], szDb[ 64 ];
get_pcvar_string( g_pCvarSQLHost, szHost, charsmax( szHost ) );
get_pcvar_string( g_pCvarSQLUser, szUser, charsmax( szUser ) );
get_pcvar_string( g_pCvarSQLPass, szPass, charsmax( szPass ) );
get_pcvar_string( g_pCvarSQLDb, szDb, charsmax( szDb ) );
g_hSqlTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDb );
if( g_hSqlTuple == Empty_Handle ) return;
// TABLE STRUCTURE
// admin_name VARCHAR(32) NOT NULL
// admin_steamid VARCHAR(35) NOT NULL
// admin_ip VARCHAR(15) NOT NULL
// player_name VARCHAR(32) NOT NULL
// player_steamid VARCHAR(35) NOT NULL PRIMARY KEY
// player_ip VARCHAR(15) NOT NULL
// date_gagged DATETIME NOT NULL
// date_ungag DATETIME NOT NULL
// gag_seconds INT NOT NULL
// gag_flags VARCHAR(3) NOT NULL
new iError, szError[ 128 ];
new Handle:hDb = SQL_Connect( g_hSqlTuple, iError, szError, charsmax( szError ) );
if( hDb == Empty_Handle )
{
log_amx( "Failed to connect to database: (%d) %s", iError, szError );
return;
}
new Handle:hQuery = SQL_PrepareQuery( hDb, "CREATE TABLE IF NOT EXISTS gagged_players (\
admin_name VARCHAR(32) NOT NULL,\
admin_steamid VARCHAR(35) NOT NULL,\
admin_ip VARCHAR(15) NOT NULL,\
player_name VARCHAR(32) NOT NULL,\
player_steamid VARCHAR(35) NOT NULL PRIMARY KEY,\
player_ip VARCHAR(15) NOT NULL,\
date_gagged DATETIME NOT NULL,\
date_ungag DATETIME NOT NULL,\
gag_seconds INT NOT NULL,\
gag_flags VARCHAR(3) NOT NULL);" );
if( !SQL_Execute( hQuery ) )
{
SQL_QueryError( hQuery, szError, charsmax( szError ) );
log_amx( "Failed create table query: %s", szError );
}
else
{
SQL_FreeHandle( hQuery );
new szDate[ DATE_SIZE ];
get_time( DATETIME_FORMAT, szDate, charsmax( szDate ) );
// Load all users
hQuery = SQL_PrepareQuery( hDb, "SELECT * FROM gagged_players WHERE date_ungag > '%s' OR gag_seconds = 0;", szDate );
if( !SQL_Execute( hQuery ) )
{
SQL_QueryError( hQuery, szError, charsmax( szError ) );
log_amx( "Failed load gags query: %s", szError );
}
else
{
g_bUsingSQL = true;
if( SQL_NumResults( hQuery ) )
{
new iSystime = get_systime( );
new iShortestTime = 999999;
new data[ GagData ];
new szFlags[ 4 ];
new iTimeLeft;
data[ GAG_SAVE ] = 1;
data[ GAG_NOTIFY ] = 1;
new iFieldSteamID = SQL_FieldNameToNum( hQuery, "player_steamid" );
new iFieldDateGagged = SQL_FieldNameToNum( hQuery, "date_gagged" );
new iFieldGagTime = SQL_FieldNameToNum( hQuery, "gag_seconds" );
new iFieldGagFlags = SQL_FieldNameToNum( hQuery, "gag_flags" );
while( SQL_MoreResults( hQuery ) )
{
SQL_ReadResult( hQuery, iFieldSteamID, data[ GAG_STEAMID ], charsmax( data[ GAG_STEAMID ] ) );
SQL_ReadResult( hQuery, iFieldDateGagged, szDate, charsmax( szDate ) );
data[ GAG_TIME ] = SQL_ReadResult( hQuery, iFieldGagTime );
SQL_ReadResult( hQuery, iFieldGagFlags, szFlags, charsmax( szFlags ) );
data[ GAG_START ] = strtotime( szDate );
data[ GAG_FLAGS ] = read_flags( szFlags );
if( data[ GAG_TIME ] > 0 )
{
iTimeLeft = data[ GAG_START ] + data[ GAG_TIME ] - iSystime;
if( iShortestTime > iTimeLeft )
{
iShortestTime = iTimeLeft;
}
}
ArrayPushArray( g_aGagData, data );
TrieSetCell( g_tArrayPos, data[ GAG_STEAMID ], g_iGagged );
g_iGagged++;
SQL_NextRow( hQuery );
}
if( iShortestTime < 999999 )
{
entity_set_float( g_iThinker, EV_FL_nextthink, get_gametime( ) + iShortestTime );
}
}
}
}
SQL_FreeHandle( hQuery );
SQL_FreeHandle( hDb );
}
}
public plugin_end( )
{
TrieDestroy( g_tArrayPos );
ArrayDestroy( g_aGagData );
ArrayDestroy( g_aGagTimes );
TrieDestroy( g_tTimeUnitWords );
}
public CmdSetBanTimes( )
{
new iArgs = read_argc( );
if( iArgs <= 1 )
{
server_print( "Usage: amx_gag_times <time1> [time2] [time3] ..." );
return PLUGIN_HANDLED;
}
ArrayClear( g_aGagTimes );
// This is used for ungag in the menu
ArrayPushCell( g_aGagTimes, 0 );
g_iTotalGagTimes = 1;
// Get max time allowed
new iTimeLimit = get_pcvar_num( g_pCvarMaxTime );
new szBuffer[ 32 ], iTime;
for( new i = 1; i < iArgs; i++ )
{
read_argv( i, szBuffer, 31 );
if( !is_str_num( szBuffer ) )
{
server_print( "[AMXX GAG] Time must be an integer! (%s)", szBuffer );
continue;
}
iTime = str_to_num( szBuffer );
if( iTime < 0 )
{
server_print( "[AMXX GAG] Time must be a positive integer! (%d)", iTime );
continue;
}
if( 0 < iTimeLimit < iTime )
{
server_print( "[AMXX GAG] Time more then %d is not allowed! (%d)", iTimeLimit, iTime );
continue;
}
ArrayPushCell( g_aGagTimes, iTime );
g_iTotalGagTimes++;
}
return PLUGIN_HANDLED;
}
public client_putinserver( id )
{
if( CheckGagFlag( id, GAG_VOICE ) )
{
set_speak( id, SPEAK_MUTED );
}
// Default flags are "abc"
g_iMenuFlags[ id ] = GAG_CHAT | GAG_TEAMSAY | GAG_VOICE;
}
public client_authorized( id )
{
get_user_authid( id, g_szSteamID[ id ], 34 );
}
public client_disconnect( id )
{
if( TrieKeyExists( g_tArrayPos, g_szSteamID[ id ] ) )
{
new szName[ 32 ];
get_user_name( id, szName, 31 );
new iPlayers[ 32 ], iNum, iPlayer;
get_players( iPlayers, iNum, "ch" );
for( new i; i < iNum; i++ )
{
iPlayer = iPlayers[ i ];
if( get_user_flags( iPlayer ) & ADMIN_KICK )
{
if( g_bColorSupported )
{
GreenPrint( iPlayer, id, "^4[AMXX GAG]^1 Gagged player ^"^3%s^1<^4%s^1>^" has disconnected!", szName, g_szSteamID[ id ] );
}
else
{
client_print( iPlayer, print_chat, "[AMXX GAG] Gagged player ^"%s<%s>^" has disconnected!", szName, g_szSteamID[ id ] );
}
}
}
}
g_szSteamID[ id ][ 0 ] = '^0';
}
public client_infochanged( id )
{
if( !CheckGagFlag( id, ( GAG_CHAT | GAG_TEAMSAY ) ) )
{
return;
}
static const name[ ] = "name";
static szNewName[ 32 ], szOldName[ 32 ];
get_user_info( id, name, szNewName, 31 );
get_user_name( id, szOldName, 31 );
if( !equal( szNewName, szOldName ) )
{
if( g_bColorSupported )
{
GreenPrint( id, id, "^4[AMXX GAG]^1 Gagged players cannot change their names!" );
}
else
{
client_print( id, print_chat, "[AMXX GAG] Gagged players cannot change their names!" );
}
set_user_info( id, name, szOldName );
}
}
public MessageSayText( )
{
static const Cstrike_Name_Change[ ] = "#Cstrike_Name_Change";
new szMessage[ sizeof( Cstrike_Name_Change ) + 1 ];
get_msg_arg_string( 2, szMessage, charsmax( szMessage ) );
if( equal( szMessage, Cstrike_Name_Change ) )
{
new szName[ 32 ], id;
for( new i = 3; i <= 4; i++ )
{
get_msg_arg_string( i, szName, 31 );
id = get_user_index( szName );
if( is_user_connected( id ) )
{
if( CheckGagFlag( id, ( GAG_CHAT | GAG_TEAMSAY ) ) )
{
return PLUGIN_HANDLED;
}
break;
}
}
}
return PLUGIN_CONTINUE;
}
public FwdThink( const iEntity )
{
if( !g_iGagged )
{
return;
}
new iSystime = get_systime( );
new bool:bRemovedGags = false;
new bool:bUsingSQL = g_bUsingSQL;
new Array:aRemoveSteamIDs, iNumRemoveSteamIDs;
if( bUsingSQL )
{
aRemoveSteamIDs = ArrayCreate( 35 );
g_bUsingSQL = false;
}
new data[ GagData ], id, szName[ 32 ];
for( new i = 0; i < g_iGagged; i++ )
{
ArrayGetArray( g_aGagData, i, data );
if( data[ GAG_TIME ] > 0 && ( data[ GAG_START ] + data[ GAG_TIME ] ) <= iSystime )
{
id = find_player( "c", data[ GAG_STEAMID ] );
if( is_user_connected( id ) )
{
get_user_name( id, szName, 31 );
if( g_bColorSupported )
{
GreenPrint( 0, id, "^4[AMXX GAG]^1 Player ^"^3%s^1^" is no longer gagged", szName );
}
else
{
client_print( 0, print_chat, "[AMXX GAG] Player ^"%s^" is no longer gagged", szName );
}
}
else
{
if( g_bColorSupported )
{
GreenPrint( 0, 0, "^4[AMXX GAG]^1 SteamID ^"^3%s^1^" is no longer gagged", data[ GAG_STEAMID ] );
}
else
{
client_print( 0, print_chat, "[AMXX GAG] SteamID ^"%s^" is no longer gagged", data[ GAG_STEAMID ] );
}
}
DeleteGag( i-- );
bRemovedGags = true;
if( bUsingSQL )
{
ArrayPushString( aRemoveSteamIDs, data[ GAG_STEAMID ] );
iNumRemoveSteamIDs++;
}
}
}
if( !bUsingSQL )
{
if( bRemovedGags )
{
SaveToFile( );
}
}
else
{
if( iNumRemoveSteamIDs )
{
new szNext[ 64 ], iNextLen, iDefaultLen, iLen = iDefaultLen = copy( szQuery, charsmax( szQuery ), "DELETE FROM gagged_players WHERE " );
for( new i = 0; i < iNumRemoveSteamIDs; i++ )
{
ArrayGetString( aRemoveSteamIDs, i, data[ GAG_STEAMID ], charsmax( data[ GAG_STEAMID ] ) );
iNextLen = formatex( szNext, charsmax( szNext ), "%splayer_steamid = ^"%s^"", i ? " OR " : "", data[ GAG_STEAMID ] );
if( ( iLen + iNextLen + 1 ) > charsmax( szQuery ) )
{
szQuery[ iLen++ ] = ';'
szQuery[ iLen ] = 0;
SQL_ThreadQuery( g_hSqlTuple, "HandleDefaultQuery", szQuery );
szQuery[ ( iLen = iDefaultLen ) ] = 0;
}
iLen += copy( szQuery[ iLen ], charsmax( szQuery ) - iLen, szNext );
}
szQuery[ iLen++ ] = ';';
szQuery[ iLen ] = 0;
SQL_ThreadQuery( g_hSqlTuple, "HandleDefaultQuery", szQuery );
}
ArrayDestroy( aRemoveSteamIDs );
g_bUsingSQL = true;
}
if( !g_iGagged )
return;
new iNextTime = 999999;
for( new i = 0; i < g_iGagged; i++ )
{
ArrayGetArray( g_aGagData, i, data );
if( data[ GAG_TIME ] > 0 )
iNextTime = min( iNextTime, data[ GAG_START ] + data[ GAG_TIME ] - iSystime );
}
if( iNextTime < 999999 )
entity_set_float( iEntity, EV_FL_nextthink, get_gametime( ) + iNextTime );
}
public CmdSay( const id )
{
return CheckSay( id, 0 );
}
public CmdTeamSay( const id )
{
return CheckSay( id, 1 );
}
CheckSay( const id, const bIsTeam )
{
new iArrayPos;
if( TrieGetCell( g_tArrayPos, g_szSteamID[ id ], iArrayPos ) )
{
new data[ GagData ];
ArrayGetArray( g_aGagData, iArrayPos, data );
new const iFlags[ ] = { GAG_CHAT, GAG_TEAMSAY };
if( data[ GAG_FLAGS ] & iFlags[ bIsTeam ] )
{
if( data[ GAG_TIME ] > 0 )
{
new szInfo[ 128 ], iTime = data[ GAG_START ] + data[ GAG_TIME ] - get_systime( );
GetTimeLength( iTime, szInfo, charsmax( szInfo ) );
if( g_bColorSupported )
{
GreenPrint( id, id, "^4[AMXX GAG]^3 %s^1 left before your ungag!", szInfo );
}
else
{
client_print( id, print_chat, "[AMXX GAG] %s left before your ungag!", szInfo );
}
}
else
{
if( g_bColorSupported )
{
GreenPrint( id, id, "^4[AMXX GAG]^3 You are gagged permanently!" );
}
else
{
client_print( id, print_chat, "[AMXX GAG] You are gagged permanently!" );
}
}
client_print( id, print_center, "** You are gagged from%s chat! **", bIsTeam ? " team" : "" );
return PLUGIN_HANDLED;
}
}
return PLUGIN_CONTINUE;
}
public CmdGagPlayer( const id, const iLevel, const iCid )
{
if( !cmd_access( id, iLevel, iCid, 2 ) )
{
console_print( id, "Flags: a - Chat | b - Team Chat | c - Voice communications" );
return PLUGIN_HANDLED;
}
new szArg[ 32 ];
read_argv( 1, szArg, 31 );
new iPlayer = cmd_target( id, szArg, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_NO_BOTS );
if( !iPlayer )
{
return PLUGIN_HANDLED;
}
new szName[ 20 ];
get_user_name( iPlayer, szName, 19 );
if( TrieKeyExists( g_tArrayPos, g_szSteamID[ iPlayer ] ) )
{
console_print( id, "User ^"%s^" is already gagged!", szName );
return PLUGIN_HANDLED;
}
new iFlags;
new iGagTime = -1;
read_argv( 2, szArg, 31 );
if( szArg[ 0 ] ) // No time entered
{
if( is_str_num( szArg ) ) // Seconds entered
{
iGagTime = abs( str_to_num( szArg ) );
}
else
{
console_print( id, "The value must be in seconds!" );
return PLUGIN_HANDLED;
}
read_argv( 3, szArg, 31 );
if( szArg[ 0 ] )
{
iFlags = read_flags( szArg );
}
}
GagPlayer( id, iPlayer, g_szSteamID[ iPlayer ], iGagTime, iFlags );
return PLUGIN_HANDLED;
}
GagPlayer( id, iPlayer, const szPlayerSteamID[ ], iGagTime, iFlags, bSave=1, bNotify=1 )
{
new iMaxTime = get_pcvar_num( g_pCvarMaxTime );
if( iGagTime == -1 )
{
iGagTime = clamp( get_pcvar_num( g_pCvarDefaultTime ), 0, iMaxTime );
}
if( iGagTime )
{
new iTimeUnit = GetTimeUnit( );
iGagTime = clamp( iGagTime, 1, iMaxTime ) * g_iTimeUnitMult[ iTimeUnit ];
}
if( !iFlags )
{
new szFlags[ 27 ];
get_pcvar_string( g_pCvarDefaultFlags, szFlags, charsmax( szFlags ) );
iFlags = read_flags( szFlags );
}
new data[ GagData ];
data[ GAG_START ] = get_systime( );
data[ GAG_TIME ] = iGagTime;
data[ GAG_FLAGS ] = iFlags;
data[ GAG_SAVE ] = bSave;
data[ GAG_NOTIFY ] = bNotify;
copy( data[ GAG_STEAMID ], 34, szPlayerSteamID );
TrieSetCell( g_tArrayPos, szPlayerSteamID, g_iGagged );
ArrayPushArray( g_aGagData, data );
g_iGagged++;
if( iGagTime > 0 )
{
new Float:flGametime = get_gametime( ), Float:flNextThink;
flNextThink = entity_get_float( g_iThinker, EV_FL_nextthink );
if( !flNextThink || flNextThink > ( flGametime + iGagTime ) )
{
entity_set_float( g_iThinker, EV_FL_nextthink, flGametime + iGagTime );
}
}
if( bSave )
{
if( g_bUsingSQL )
{
new szPlayerName[ 32 ], szPlayerIP[ 32 ];
if( iPlayer )
{
get_user_name( iPlayer, szPlayerName, charsmax( szPlayerName ) );
get_user_ip( iPlayer, szPlayerIP, charsmax( szPlayerIP ), 1 );
}
else
{
szPlayerName[ 0 ] = szPlayerIP[ 0 ] = '?';
}
AddGag( id, g_szSteamID[ iPlayer ], szPlayerName, szPlayerIP, iGagTime, iFlags );
}
else
{
SaveToFile( );
}
}
if( bNotify )
{
new szFrom[ 64 ];
if( iFlags & GAG_CHAT )
{
copy( szFrom, 63, "say" );
}
if( iFlags & GAG_TEAMSAY )
{
if( !szFrom[ 0 ] )
copy( szFrom, 63, "say_team" );
else
add( szFrom, 63, " / say_team" );
}
if( iFlags & GAG_VOICE )
{
set_speak( iPlayer, SPEAK_MUTED );
if( !szFrom[ 0 ] )
copy( szFrom, 63, "voicecomm" );
else
add( szFrom, 63, " / voicecomm" );
}
new szName[ 64 ];
if( iPlayer )
{
get_user_name( iPlayer, szName, 19 );
}
else
{
formatex( szName, charsmax( szName ), "a non-connected player <%s>", szPlayerSteamID );
}
new szInfo[ 32 ], szAdmin[ 32 ];
get_user_name( id, szAdmin, 31 );
if( iGagTime > 0 )
{
new iLen = copy( szInfo, 31, "for " );
GetTimeLength( iGagTime, szInfo[ iLen ], charsmax( szInfo ) - iLen );
}
else
{
copy( szInfo, 31, "permanently" );
}
show_activity( id, szAdmin, "Has gagged %s from speaking %s! (%s)", szName, szInfo, szFrom );
console_print( id, "You have gagged ^"%s^" (%s) !", szName, szFrom );
log_amx( "Gag: ^"%s<%s>^" has gagged ^"%s<%s>^" %s. (%s)", szAdmin, g_szSteamID[ id ], szName, szPlayerSteamID, szInfo, szFrom );
}
}
public CmdAddGag( const id, const iLevel, const iCid )
{
if( !cmd_access( id, iLevel, iCid, 2 ) )
{
console_print( id, "Flags: a - Chat | b - Team Chat | c - Voice communications" );
return PLUGIN_HANDLED;
}
new szArg[ 32 ];
read_argv( 1, szArg, 31 );
if( !IsValidSteamID( szArg ) )
{
console_print( id, "Invalid SteamID provided (%s). Must be in ^"STEAM_0:X:XXXXX^" format (remember to use quotes!)", szArg );
return PLUGIN_HANDLED;
}
new iPlayer = find_player( "c", szArg );
if( is_user_connected( iPlayer ) )
{
new szTime[ 12 ], szFlags[ 4 ];
read_argv( 2, szTime, charsmax( szTime ) );
read_argv( 3, szFlags, charsmax( szFlags ) );
client_cmd( id, "amx_gag #%d ^"%s^" ^"%s^"", get_user_userid( iPlayer ), szTime, szFlags );