hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2024.06.04. 10:50



Jelenlévő felhasználók

Jelenleg 191 felhasználó van jelen :: 0 regisztrált, 0 rejtett és 191 vendég

A legtöbb felhasználó (1565 fő) 2020.11.21. 11:26-kor tartózkodott itt.

Regisztrált felhasználók: nincs regisztrált felhasználó az elmúlt 5 percben aktív felhasználók alapján

Utoljára aktív
Ahhoz hogy lásd ki volt utoljára aktív, be kell jelentkezned.



Az oldal teljeskörű
használatához regisztrálj.

Regisztráció

Kereső


Új téma nyitása  Hozzászólás a témához  [ 3 hozzászólás ] 
Szerző Üzenet
 Hozzászólás témája: Amx_gag javítás + bővítés
HozzászólásElküldve: 2016.02.25. 21:45 
Offline
GFX-Designer
Avatar

Csatlakozott: 2015.03.12. 15:06
Hozzászólások: 624
Megköszönt másnak: 199 alkalommal
Megköszönték neki: 78 alkalommal
Sziasztok,
A plugint adminok tudják használni játékosok némítására, de van vele 1 gondom.
Mikor beírom hogy amx_gagmenu, behozza a menüt, de egyből az ungag menürészbe rak, miközben a 8. gombon ott az Ungag választási lehetőség, és az Ungag alatt lehet némítani.
Lényegében valahogy meg van cserélve a menüben az "AmxGag Menu" és az "Ungag" rész.
Ezt kellene javítani.

Köszönöm előre a segítségeket!

Itt az .sma
  1. #include < amxmodx >
  2. #include < amxmisc >
  3. #include < engine >
  4. #include < sqlx >
  5.  
  6. #define MAX_PLAYERS 32
  7.  
  8. #define MAX_PATTERN_LEN 255
  9.  
  10. enum ( <<= 1 )
  11. {
  12.     GAG_CHAT = 1,
  13.     GAG_TEAMSAY,
  14.     GAG_VOICE
  15. };
  16.  
  17. enum _:GagData
  18. {
  19.     GAG_STEAMID[ 35 ],
  20.     GAG_TIME,
  21.     GAG_START,
  22.     GAG_FLAGS,
  23.     GAG_SAVE,
  24.     GAG_NOTIFY
  25. };
  26.  
  27. enum _:TimeUnit
  28. {
  29.     TIMEUNIT_SECONDS = 0,
  30.     TIMEUNIT_MINUTES,
  31.     TIMEUNIT_HOURS,
  32.     TIMEUNIT_DAYS,
  33.     TIMEUNIT_WEEKS
  34. };
  35.  
  36. new const g_szTimeUnitName[ TimeUnit ][ 2 ][ ] =
  37. {
  38.     { "second", "seconds" },
  39.     { "minute", "minutes" },
  40.     { "hour",   "hours"   },
  41.     { "day",    "days"    },
  42.     { "week",   "weeks"   }
  43. };
  44.  
  45. new const g_iTimeUnitMult[ TimeUnit ] =
  46. {
  47.     1,
  48.     60,
  49.     3600,
  50.     86400,
  51.     604800
  52. };
  53.  
  54. new const DATETIME_FORMAT[ ] = "%Y-%m-%d %H:%M:%S";
  55. const DATE_SIZE = 20;
  56.  
  57. new Array:g_aGagTimes;
  58. new Array:g_aGagData;
  59. new Trie:g_tArrayPos;
  60. new Trie:g_tTimeUnitWords;
  61.  
  62. new g_iGagged;
  63. new g_iThinker;
  64. new g_iTotalGagTimes;
  65. new g_iMsgSayText;
  66.  
  67. new g_szSteamID[ MAX_PLAYERS + 1 ][ 35 ];
  68. new g_iMenuOption[ MAX_PLAYERS + 1 ];
  69. new g_iMenuPosition[ MAX_PLAYERS + 1 ];
  70. new g_iMenuPlayers[ MAX_PLAYERS + 1 ][ 32 ];
  71. new g_iMenuFlags[ MAX_PLAYERS + 1 ];
  72.  
  73. new g_szGagFile[ 64 ];
  74.  
  75. new bool:g_bColorSupported;
  76.  
  77. new g_pCvarDefaultFlags;
  78. new g_pCvarDefaultTime;
  79. new g_pCvarTimeUnit;
  80. new g_pCvarMaxTime;
  81. new g_pCvarSQL;
  82. new g_pCvarSQLHost;
  83. new g_pCvarSQLUser;
  84. new g_pCvarSQLPass;
  85. new g_pCvarSQLDb;
  86.  
  87. new bool:g_bUsingSQL = false;
  88. new Handle:g_hSqlTuple;
  89.  
  90. new szQuery[ 1024 ];
  91.  
  92. public plugin_init( )
  93. {
  94.     register_plugin( "AMXX Gag", "1.5.0", "xPaw & Exolent" );
  95.    
  96.     register_clcmd( "say",        "CmdSay" );
  97.     register_clcmd( "say_team",   "CmdTeamSay" );
  98.    
  99.     register_concmd( "amx_gag",       "CmdGagPlayer",   ADMIN_KICK, "<nick or #userid> <time> <a|b|c> -- Use 0 time for permanent" );
  100.     register_concmd( "amx_addgag",    "CmdAddGag",      ADMIN_KICK, "<authid> <time> <a|b|c> -- Use 0 time for permanent" );
  101.     register_concmd( "amx_ungag",     "CmdUnGagPlayer", ADMIN_KICK, "<nick or #userid>" );
  102.     register_concmd( "amx_gagmenu",   "CmdGagMenu",     ADMIN_KICK, "- displays gag menu" );
  103.     register_srvcmd( "amx_gag_times", "CmdSetBanTimes" );
  104.    
  105.     register_menu( "Gag Menu", 1023, "ActionGagMenu" );
  106.     register_menu( "Gag Flags", 1023, "ActionGagFlags" );
  107.     register_message( get_user_msgid( "SayText" ), "MessageSayText" );
  108.    
  109.     g_pCvarDefaultFlags = register_cvar( "amx_gag_default_flags", "abc"   );
  110.     g_pCvarDefaultTime  = register_cvar( "amx_gag_default_time",  "600"   );
  111.     g_pCvarTimeUnit     = register_cvar( "amx_gag_time_units",    "0"     );
  112.     g_pCvarMaxTime      = register_cvar( "amx_gag_max_time",      "86400" );
  113.     g_pCvarSQL          = register_cvar( "amx_gag_sql",           "0"     );
  114.     g_pCvarSQLHost      = register_cvar( "amx_gag_sql_host",      ""      );
  115.     g_pCvarSQLUser      = register_cvar( "amx_gag_sql_user",      ""      );
  116.     g_pCvarSQLPass      = register_cvar( "amx_gag_sql_pass",      ""      );
  117.     g_pCvarSQLDb        = register_cvar( "amx_gag_sql_db",        ""      );
  118.    
  119.     g_tArrayPos       = TrieCreate( );
  120.     g_aGagTimes       = ArrayCreate( );
  121.     g_aGagData        = ArrayCreate( GagData );
  122.     g_bColorSupported = bool:colored_menus( );
  123.     g_iMsgSayText     = get_user_msgid( "SayText" );
  124.    
  125.     // Let words work with the time unit cvar
  126.     g_tTimeUnitWords = TrieCreate( );
  127.    
  128.     for( new i = 0; i < TimeUnit; i++ )
  129.     {
  130.         TrieSetCell( g_tTimeUnitWords, g_szTimeUnitName[ i ][ 0 ], i );
  131.         TrieSetCell( g_tTimeUnitWords, g_szTimeUnitName[ i ][ 1 ], i );
  132.     }
  133.    
  134.     // This is used for ungag in the menu
  135.     ArrayPushCell( g_aGagTimes, 0 );
  136.    
  137.     // Gag times for the gag menu (amx_gagmenu)
  138.     // Default values: 60 300 600 1800 3600 7200 86400
  139.     new const iDefaultTimes[ ] = { 60, 300, 600, 1800, 3600, 7200, 86400, 0 };
  140.    
  141.     // Load up standart times
  142.     for( new i = 0; i < sizeof( iDefaultTimes ); i++ )
  143.     {
  144.         ArrayPushCell( g_aGagTimes, iDefaultTimes[ i ] );
  145.     }
  146.    
  147.     g_iTotalGagTimes = sizeof( iDefaultTimes ) + 1;
  148.    
  149.     // Set up entity-thinker
  150.     new const szClassName[ ] = "gag_thinker";
  151.    
  152.     g_iThinker = create_entity( "info_target" );
  153.     entity_set_string( g_iThinker, EV_SZ_classname, szClassName );
  154.    
  155.     register_think( szClassName, "FwdThink" );
  156.    
  157.     // Load gags from file
  158.     get_datadir( g_szGagFile, charsmax( g_szGagFile ) );
  159.     add( g_szGagFile, charsmax( g_szGagFile ), "/gags.txt" );
  160.    
  161.     // Set server's SteamID to "SERVER"
  162.     copy( g_szSteamID[ 0 ], charsmax( g_szSteamID[ ] ), "SERVER" );
  163. }
  164.  
  165. public plugin_natives( )
  166. {
  167.     register_library( "amx_gag" );
  168.    
  169.     register_native( "is_user_gagged" , "_is_user_gagged"  );
  170.     register_native( "set_user_gagged", "_set_user_gagged" );
  171.     register_native( "get_gagtime"    , "_get_gagtime"     );
  172.    
  173.     register_native( "gag_check" , "_gag_check"  );
  174.     register_native( "gag_add"   , "_gag_add"    );
  175.     register_native( "gag_remove", "_gag_remove" );
  176. }
  177.  
  178. public _is_user_gagged( iPlugin, iParams )
  179. {
  180.     new iPlayer = get_param( 1 );
  181.    
  182.     return ( is_user_connected( iPlayer ) && TrieKeyExists( g_tArrayPos, g_szSteamID[ iPlayer ] ) );
  183. }
  184.  
  185. public _set_user_gagged( iPlugin, iParams )
  186. {
  187.     new iPlayer  = get_param( 1 );
  188.     new bGagged  = get_param( 2 );
  189.     new iSeconds = get_param( 3 );
  190.     new bSave    = get_param( 4 );
  191.     new iFlags   = get_param( 5 );
  192.    
  193.     if( !is_user_connected( iPlayer ) )
  194.     {
  195.         return 0;
  196.     }
  197.    
  198.     if( bGagged )
  199.     {
  200.         if( TrieKeyExists( g_tArrayPos, g_szSteamID[ iPlayer ] ) )
  201.         {
  202.             return 0;
  203.         }
  204.        
  205.         GagPlayer( 0, iPlayer, g_szSteamID[ iPlayer ], iSeconds, iFlags, bSave, 0 );
  206.     }
  207.     else
  208.     {
  209.         new iArrayPos;
  210.        
  211.         if( !TrieGetCell( g_tArrayPos, g_szSteamID[ iPlayer ], iArrayPos ) )
  212.         {
  213.             return 0;
  214.         }
  215.        
  216.         new data[ GagData ];
  217.         ArrayGetArray( g_aGagData, iArrayPos, data );
  218.        
  219.         DeleteGag( iArrayPos );
  220.    
  221.         if( !g_bUsingSQL && data[ GAG_SAVE ] )
  222.         {
  223.             SaveToFile( );
  224.         }
  225.     }
  226.    
  227.     return 1;
  228. }
  229.  
  230. public _get_gagtime( iPlugin, iParams )
  231. {
  232.     new iPlayer = get_param( 1 );
  233.     new iTime = 0;
  234.    
  235.     if( is_user_connected( iPlayer ) )
  236.     {
  237.         new iArrayPos;
  238.        
  239.         if( TrieGetCell( g_tArrayPos, g_szSteamID[ iPlayer ], iArrayPos ) )
  240.         {
  241.             new data[ GagData ];
  242.             ArrayGetArray( g_aGagData, iArrayPos, data );
  243.            
  244.             if( data[ GAG_TIME ] > 0 )
  245.             {
  246.                 iTime = data[ GAG_START ] + data[ GAG_TIME ] - get_systime( );
  247.             }
  248.         }
  249.     }
  250.    
  251.     return iTime;
  252. }
  253.  
  254. public _gag_check( iPlugin, iParams )
  255. {
  256.     new szSteamID[ 35 ];
  257.     get_string( 1, szSteamID, charsmax( szSteamID ) );
  258.    
  259.     return _:TrieKeyExists( g_tArrayPos, szSteamID );
  260. }
  261.  
  262. public _gag_add( iPlugin, iParams )
  263. {
  264.     new szSteamID[ 35 ];
  265.     get_string( 1, szSteamID, charsmax( szSteamID ) );
  266.    
  267.     if( TrieKeyExists( g_tArrayPos, szSteamID ) )
  268.     {
  269.         return 0;
  270.     }
  271.    
  272.     new iSeconds = get_param( 2 );
  273.     new bSave    = get_param( 3 );
  274.     new iFlags   = get_param( 4 );
  275.    
  276.     GagPlayer( 0, 0, szSteamID, iSeconds, iFlags, bSave, 0 );
  277.    
  278.     return 1;
  279. }
  280.  
  281. public _gag_remove( iPlugin, iParams )
  282. {
  283.     new szSteamID[ 35 ];
  284.     get_string( 1, szSteamID, charsmax( szSteamID ) );
  285.    
  286.     new iArrayPos;
  287.    
  288.     if( !TrieGetCell( g_tArrayPos, szSteamID, iArrayPos ) )
  289.     {
  290.         return 0;
  291.     }
  292.    
  293.     DeleteGag( iArrayPos );
  294.    
  295.     return 1;
  296. }
  297.  
  298. public plugin_cfg( )
  299. {
  300.     // Check SQL
  301.     InitSQL( );
  302.    
  303.     if( !g_bUsingSQL )
  304.     {
  305.         // If not using SQL, load from file
  306.         LoadFromFile( );
  307.     }
  308. }
  309.  
  310. InitSQL( )
  311. {
  312.     // Init SQL after configs were executed
  313.     if( get_pcvar_num( g_pCvarSQL ) )
  314.     {
  315.         new szHost[ 64 ], szUser[ 64 ], szPass[ 64 ], szDb[ 64 ];
  316.         get_pcvar_string( g_pCvarSQLHost, szHost, charsmax( szHost ) );
  317.         get_pcvar_string( g_pCvarSQLUser, szUser, charsmax( szUser ) );
  318.         get_pcvar_string( g_pCvarSQLPass, szPass, charsmax( szPass ) );
  319.         get_pcvar_string( g_pCvarSQLDb,   szDb,   charsmax( szDb   ) );
  320.        
  321.         g_hSqlTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDb );
  322.        
  323.         if( g_hSqlTuple == Empty_Handle ) return;
  324.        
  325.         // TABLE STRUCTURE
  326.         // admin_name VARCHAR(32) NOT NULL
  327.         // admin_steamid VARCHAR(35) NOT NULL
  328.         // admin_ip VARCHAR(15) NOT NULL
  329.         // player_name VARCHAR(32) NOT NULL
  330.         // player_steamid VARCHAR(35) NOT NULL PRIMARY KEY
  331.         // player_ip VARCHAR(15) NOT NULL
  332.         // date_gagged DATETIME NOT NULL
  333.         // date_ungag DATETIME NOT NULL
  334.         // gag_seconds INT NOT NULL
  335.         // gag_flags VARCHAR(3) NOT NULL
  336.        
  337.         new iError, szError[ 128 ];
  338.         new Handle:hDb = SQL_Connect( g_hSqlTuple, iError, szError, charsmax( szError ) );
  339.        
  340.         if( hDb == Empty_Handle )
  341.         {
  342.             log_amx( "Failed to connect to database: (%d) %s", iError, szError );
  343.             return;
  344.         }
  345.        
  346.         new Handle:hQuery = SQL_PrepareQuery( hDb, "CREATE TABLE IF NOT EXISTS gagged_players (\
  347.             admin_name VARCHAR(32) NOT NULL,\
  348.             admin_steamid VARCHAR(35) NOT NULL,\
  349.             admin_ip VARCHAR(15) NOT NULL,\
  350.             player_name VARCHAR(32) NOT NULL,\
  351.             player_steamid VARCHAR(35) NOT NULL PRIMARY KEY,\
  352.             player_ip VARCHAR(15) NOT NULL,\
  353.             date_gagged DATETIME NOT NULL,\
  354.             date_ungag DATETIME NOT NULL,\
  355.             gag_seconds INT NOT NULL,\
  356.             gag_flags VARCHAR(3) NOT NULL);" );
  357.        
  358.         if( !SQL_Execute( hQuery ) )
  359.         {
  360.             SQL_QueryError( hQuery, szError, charsmax( szError ) );
  361.             log_amx( "Failed create table query: %s", szError );
  362.         }
  363.         else
  364.         {
  365.             SQL_FreeHandle( hQuery );
  366.            
  367.             new szDate[ DATE_SIZE ];
  368.             get_time( DATETIME_FORMAT, szDate, charsmax( szDate ) );
  369.            
  370.             // Load all users
  371.             hQuery = SQL_PrepareQuery( hDb, "SELECT * FROM gagged_players WHERE date_ungag > '%s';", szDate );
  372.            
  373.             if( !SQL_Execute( hQuery ) )
  374.             {
  375.                 SQL_QueryError( hQuery, szError, charsmax( szError ) );
  376.                 log_amx( "Failed load gags query: %s", szError );
  377.             }
  378.             else
  379.             {
  380.                 g_bUsingSQL = true;
  381.                
  382.                 if( SQL_NumResults( hQuery ) )
  383.                 {
  384.                     new iSystime = get_systime( );
  385.                     new iShortestTime = 999999;
  386.                    
  387.                     new data[ GagData ];
  388.                     new szFlags[ 4 ];
  389.                     new iTimeLeft;
  390.                    
  391.                     data[ GAG_SAVE   ] = 1;
  392.                     data[ GAG_NOTIFY ] = 1;
  393.                    
  394.                     new iFieldSteamID = SQL_FieldNameToNum( hQuery, "player_steamid" );
  395.                     new iFieldDateGagged = SQL_FieldNameToNum( hQuery, "date_gagged" );
  396.                     new iFieldGagTime = SQL_FieldNameToNum( hQuery, "gag_seconds" );
  397.                     new iFieldGagFlags = SQL_FieldNameToNum( hQuery, "gag_flags" );
  398.                    
  399.                     while( SQL_MoreResults( hQuery ) )
  400.                     {
  401.                         SQL_ReadResult( hQuery, iFieldSteamID, data[ GAG_STEAMID ], charsmax( data[ GAG_STEAMID ] ) );
  402.                         SQL_ReadResult( hQuery, iFieldDateGagged, szDate, charsmax( szDate ) );
  403.                         data[ GAG_TIME ] = SQL_ReadResult( hQuery, iFieldGagTime );
  404.                         SQL_ReadResult( hQuery, iFieldGagFlags, szFlags, charsmax( szFlags ) );
  405.                        
  406.                         data[ GAG_START ] = strtotime( szDate );
  407.                         data[ GAG_FLAGS ] = read_flags( szFlags );
  408.                        
  409.                         if( data[ GAG_TIME ] > 0 )
  410.                         {
  411.                             iTimeLeft = data[ GAG_START ] + data[ GAG_TIME ] - iSystime;
  412.                            
  413.                             if( iShortestTime > iTimeLeft )
  414.                             {
  415.                                 iShortestTime = iTimeLeft;
  416.                             }
  417.                         }
  418.                        
  419.                         ArrayPushArray( g_aGagData, data );
  420.                         TrieSetCell( g_tArrayPos, data[ GAG_STEAMID ], g_iGagged );
  421.                         g_iGagged++;
  422.                        
  423.                         SQL_NextRow( hQuery );
  424.                     }
  425.                    
  426.                     if( iShortestTime < 999999 )
  427.                     {
  428.                         entity_set_float( g_iThinker, EV_FL_nextthink, get_gametime( ) + iShortestTime );
  429.                     }
  430.                 }
  431.             }
  432.         }
  433.        
  434.         SQL_FreeHandle( hQuery );
  435.         SQL_FreeHandle( hDb );
  436.     }
  437. }
  438.  
  439. public plugin_end( )
  440. {
  441.     TrieDestroy( g_tArrayPos );
  442.     ArrayDestroy( g_aGagData );
  443.     ArrayDestroy( g_aGagTimes );
  444.     TrieDestroy( g_tTimeUnitWords );
  445. }
  446.  
  447. public CmdSetBanTimes( )
  448. {
  449.     new iArgs = read_argc( );
  450.    
  451.     if( iArgs <= 1 )
  452.     {
  453.         server_print( "Usage: amx_gag_times <time1> [time2] [time3] ..." );
  454.         return PLUGIN_HANDLED;
  455.     }
  456.    
  457.     ArrayClear( g_aGagTimes );
  458.    
  459.     // This is used for ungag in the menu
  460.     ArrayPushCell( g_aGagTimes, 0 );
  461.     g_iTotalGagTimes = 1;
  462.    
  463.     // Get max time allowed
  464.     new iTimeLimit = get_pcvar_num( g_pCvarMaxTime );
  465.    
  466.     new szBuffer[ 32 ], iTime;
  467.     for( new i = 1; i < iArgs; i++ )
  468.     {
  469.         read_argv( i, szBuffer, 31 );
  470.        
  471.         if( !is_str_num( szBuffer ) )
  472.         {
  473.             server_print( "[AMXX GAG] Time must be an integer! (%s)", szBuffer );
  474.             continue;
  475.         }
  476.        
  477.         iTime = str_to_num( szBuffer );
  478.        
  479.         if( iTime < 0 )
  480.         {
  481.             server_print( "[AMXX GAG] Time must be a positive integer! (%d)", iTime );
  482.             continue;
  483.         }
  484.        
  485.         if( 0 < iTimeLimit < iTime )
  486.         {
  487.             server_print( "[AMXX GAG] Time more then %d is not allowed! (%d)", iTimeLimit, iTime );
  488.             continue;
  489.         }
  490.        
  491.         ArrayPushCell( g_aGagTimes, iTime );
  492.         g_iTotalGagTimes++;
  493.     }
  494.    
  495.     return PLUGIN_HANDLED;
  496. }
  497.  
  498. public client_putinserver( id )
  499. {
  500.     if( CheckGagFlag( id, GAG_VOICE ) )
  501.     {
  502.         set_speak( id, SPEAK_MUTED );
  503.     }
  504.    
  505.     // Default flags are "abc"
  506.     g_iMenuFlags[ id ] = GAG_CHAT | GAG_TEAMSAY | GAG_VOICE;
  507. }
  508.  
  509. public client_authorized( id )
  510. {
  511.     get_user_authid( id, g_szSteamID[ id ], 34 );
  512. }
  513.  
  514. public client_disconnect( id )
  515. {
  516.     if( TrieKeyExists( g_tArrayPos, g_szSteamID[ id ] ) )
  517.     {
  518.         new szName[ 32 ];
  519.         get_user_name( id, szName, 31 );
  520.        
  521.         new iPlayers[ 32 ], iNum, iPlayer;
  522.         get_players( iPlayers, iNum, "ch" );
  523.        
  524.         for( new i; i < iNum; i++ )
  525.         {
  526.             iPlayer = iPlayers[ i ];
  527.            
  528.             if( get_user_flags( iPlayer ) & ADMIN_KICK )
  529.             {
  530.                 if( g_bColorSupported )
  531.                 {
  532.                     GreenPrint( iPlayer, id, "^4[AMXX GAG]^1 Gagged player ^"^3%s^1<^4%s^1>^" has disconnected!", szName, g_szSteamID[ id ] );
  533.                 }
  534.                 else
  535.                 {
  536.                     client_print( iPlayer, print_chat, "[AMXX GAG] Gagged player ^"%s<%s>^" has disconnected!", szName, g_szSteamID[ id ] );
  537.                 }
  538.             }
  539.         }
  540.     }
  541.    
  542.     g_szSteamID[ id ][ 0 ] = '^0';
  543. }
  544.  
  545. public client_infochanged( id )
  546. {
  547.     if( !CheckGagFlag( id, ( GAG_CHAT | GAG_TEAMSAY ) ) )
  548.     {
  549.         return;
  550.     }
  551.    
  552.     static const name[ ] = "name";
  553.    
  554.     static szNewName[ 32 ], szOldName[ 32 ];
  555.     get_user_info( id, name, szNewName, 31 );
  556.     get_user_name( id, szOldName, 31 );
  557.    
  558.     if( !equal( szNewName, szOldName ) )
  559.     {
  560.         if( g_bColorSupported )
  561.         {
  562.             GreenPrint( id, id, "^4[AMXX GAG]^1 Gagged players cannot change their names!" );
  563.         }
  564.         else
  565.         {
  566.             client_print( id, print_chat, "[AMXX GAG] Gagged players cannot change their names!" );
  567.         }
  568.        
  569.         set_user_info( id, name, szOldName );
  570.     }
  571. }
  572.  
  573. public MessageSayText( )
  574. {
  575.     static const Cstrike_Name_Change[ ] = "#Cstrike_Name_Change";
  576.    
  577.     new szMessage[ sizeof( Cstrike_Name_Change ) + 1 ];
  578.     get_msg_arg_string( 2, szMessage, charsmax( szMessage ) );
  579.    
  580.     if( equal( szMessage, Cstrike_Name_Change ) )
  581.     {
  582.         new szName[ 32 ], id;
  583.         for( new i = 3; i <= 4; i++ )
  584.         {
  585.             get_msg_arg_string( i, szName, 31 );
  586.            
  587.             id = get_user_index( szName );
  588.            
  589.             if( is_user_connected( id ) )
  590.             {
  591.                 if( CheckGagFlag( id, ( GAG_CHAT | GAG_TEAMSAY ) ) )
  592.                 {
  593.                     return PLUGIN_HANDLED;
  594.                 }
  595.                
  596.                 break;
  597.             }
  598.         }
  599.     }
  600.    
  601.     return PLUGIN_CONTINUE;
  602. }
  603.  
  604. public FwdThink( const iEntity )
  605. {
  606.     if( !g_iGagged )
  607.     {
  608.         return;
  609.     }
  610.    
  611.     new iSystime = get_systime( );
  612.     new bool:bRemovedGags = false;
  613.    
  614.     new bool:bUsingSQL = g_bUsingSQL;
  615.     new Array:aRemoveSteamIDs, iNumRemoveSteamIDs;
  616.    
  617.     if( bUsingSQL )
  618.     {
  619.         aRemoveSteamIDs = ArrayCreate( 35 );
  620.         g_bUsingSQL = false;
  621.     }
  622.    
  623.     new data[ GagData ], id, szName[ 32 ];
  624.     for( new i = 0; i < g_iGagged; i++ )
  625.     {
  626.         ArrayGetArray( g_aGagData, i, data );
  627.        
  628.         if( data[ GAG_TIME ] > 0 && ( data[ GAG_START ] + data[ GAG_TIME ] ) <= iSystime )
  629.         {
  630.             id = find_player( "c", data[ GAG_STEAMID ] );
  631.            
  632.             if( is_user_connected( id ) )
  633.             {
  634.                 get_user_name( id, szName, 31 );
  635.                
  636.                 if( g_bColorSupported )
  637.                 {
  638.                     GreenPrint( 0, id, "^4[AMXX GAG]^1 Player ^"^3%s^1^" is no longer gagged", szName );
  639.                 }
  640.                 else
  641.                 {
  642.                     client_print( 0, print_chat, "[AMXX GAG] Player ^"%s^" is no longer gagged", szName );
  643.                 }
  644.             }
  645.             else
  646.             {
  647.                 if( g_bColorSupported )
  648.                 {
  649.                     GreenPrint( 0, 0, "^4[AMXX GAG]^1 SteamID ^"^3%s^1^" is no longer gagged", data[ GAG_STEAMID ] );
  650.                 }
  651.                 else
  652.                 {
  653.                     client_print( 0, print_chat, "[AMXX GAG] SteamID ^"%s^" is no longer gagged", data[ GAG_STEAMID ] );
  654.                 }
  655.             }
  656.            
  657.             DeleteGag( i-- );
  658.            
  659.             bRemovedGags = true;
  660.            
  661.             if( bUsingSQL )
  662.             {
  663.                 ArrayPushString( aRemoveSteamIDs, data[ GAG_STEAMID ] );
  664.                 iNumRemoveSteamIDs++;
  665.             }
  666.         }
  667.     }
  668.    
  669.     if( !bUsingSQL )
  670.     {
  671.         if( bRemovedGags )
  672.         {
  673.             SaveToFile( );
  674.         }
  675.     }
  676.     else
  677.     {
  678.         if( iNumRemoveSteamIDs )
  679.         {
  680.             new szNext[ 64 ], iNextLen, iDefaultLen, iLen = iDefaultLen = copy( szQuery, charsmax( szQuery ), "DELETE FROM gagged_players WHERE " );
  681.            
  682.             for( new i = 0; i < iNumRemoveSteamIDs; i++ )
  683.             {
  684.                 ArrayGetString( aRemoveSteamIDs, i, data[ GAG_STEAMID ], charsmax( data[ GAG_STEAMID ] ) );
  685.                
  686.                 iNextLen = formatex( szNext, charsmax( szNext ), "%splayer_steamid = ^"%s^"", i ? " OR " : "", data[ GAG_STEAMID ] );
  687.                
  688.                 if( ( iLen + iNextLen + 1 ) > charsmax( szQuery ) )
  689.                 {
  690.                     szQuery[ iLen++ ] = ';'
  691.                     szQuery[ iLen ] = 0;
  692.                    
  693.                     SQL_ThreadQuery( g_hSqlTuple, "HandleDefaultQuery", szQuery );
  694.                    
  695.                     szQuery[ ( iLen = iDefaultLen ) ] = 0;
  696.                 }
  697.                
  698.                 iLen += copy( szQuery[ iLen ], charsmax( szQuery ) - iLen, szNext );
  699.             }
  700.            
  701.             szQuery[ iLen++ ] = ';';
  702.             szQuery[ iLen ] = 0;
  703.            
  704.             SQL_ThreadQuery( g_hSqlTuple, "HandleDefaultQuery", szQuery );
  705.         }
  706.        
  707.         ArrayDestroy( aRemoveSteamIDs );
  708.        
  709.         g_bUsingSQL = true;
  710.     }
  711.    
  712.     if( !g_iGagged )
  713.         return;
  714.    
  715.     new iNextTime = 999999;
  716.     for( new i = 0; i < g_iGagged; i++ )
  717.     {
  718.         ArrayGetArray( g_aGagData, i, data );
  719.        
  720.         if( data[ GAG_TIME ] > 0 )
  721.             iNextTime = min( iNextTime, data[ GAG_START ] + data[ GAG_TIME ] - iSystime );
  722.     }
  723.    
  724.     if( iNextTime < 999999 )
  725.         entity_set_float( iEntity, EV_FL_nextthink, get_gametime( ) + iNextTime );
  726. }
  727.  
  728. public CmdSay( const id )
  729. {
  730.     return CheckSay( id, 0 );
  731. }
  732.  
  733. public CmdTeamSay( const id )
  734. {
  735.     return CheckSay( id, 1 );
  736. }
  737.  
  738. CheckSay( const id, const bIsTeam )
  739. {
  740.     new iArrayPos;
  741.    
  742.     if( TrieGetCell( g_tArrayPos, g_szSteamID[ id ], iArrayPos ) )
  743.     {
  744.         new data[ GagData ];
  745.         ArrayGetArray( g_aGagData, iArrayPos, data );
  746.        
  747.         new const iFlags[ ] = { GAG_CHAT, GAG_TEAMSAY };
  748.        
  749.         if( data[ GAG_FLAGS ] & iFlags[ bIsTeam ] )
  750.         {
  751.             if( data[ GAG_TIME ] > 0 )
  752.             {
  753.                 new szInfo[ 128 ], iTime = data[ GAG_START ] + data[ GAG_TIME ] - get_systime( );
  754.                
  755.                 GetTimeLength( iTime, szInfo, charsmax( szInfo ) );
  756.                
  757.                 if( g_bColorSupported )
  758.                 {
  759.                     GreenPrint( id, id, "^4[AMXX GAG]^3 %s^1 left before your ungag!", szInfo );
  760.                 }
  761.                 else
  762.                 {
  763.                     client_print( id, print_chat, "[AMXX GAG] %s left before your ungag!", szInfo );
  764.                 }
  765.             }
  766.             else
  767.             {
  768.                 if( g_bColorSupported )
  769.                 {
  770.                     GreenPrint( id, id, "^4[AMXX GAG]^3 You are gagged permanently!" );
  771.                 }
  772.                 else
  773.                 {
  774.                     client_print( id, print_chat, "[AMXX GAG] You are gagged permanently!" );
  775.                 }
  776.             }
  777.            
  778.             client_print( id, print_center, "** You are gagged from%s chat! **", bIsTeam ? " team" : "" );
  779.            
  780.             return PLUGIN_HANDLED;
  781.         }
  782.     }
  783.    
  784.     return PLUGIN_CONTINUE;
  785. }
  786.  
  787. public CmdGagPlayer( const id, const iLevel, const iCid )
  788. {
  789.     if( !cmd_access( id, iLevel, iCid, 2 ) )
  790.     {
  791.         console_print( id, "Flags: a - Chat | b - Team Chat | c - Voice communications" );
  792.         return PLUGIN_HANDLED;
  793.     }
  794.    
  795.     new szArg[ 32 ];
  796.     read_argv( 1, szArg, 31 );
  797.    
  798.     new iPlayer = cmd_target( id, szArg, CMDTARGET_OBEY_IMMUNITY | CMDTARGET_NO_BOTS );
  799.    
  800.     if( !iPlayer )
  801.     {
  802.         return PLUGIN_HANDLED;
  803.     }
  804.    
  805.     new szName[ 20 ];
  806.     get_user_name( iPlayer, szName, 19 );
  807.    
  808.     if( TrieKeyExists( g_tArrayPos, g_szSteamID[ iPlayer ] ) )
  809.     {
  810.         console_print( id, "User ^"%s^" is already gagged!", szName );
  811.         return PLUGIN_HANDLED;
  812.     }
  813.    
  814.     new iFlags;
  815.     new iGagTime = -1;
  816.    
  817.     read_argv( 2, szArg, 31 );
  818.    
  819.     if( szArg[ 0 ] ) // No time entered
  820.     {
  821.         if( is_str_num( szArg ) ) // Seconds entered
  822.         {
  823.             iGagTime = abs( str_to_num( szArg ) );
  824.         }
  825.         else
  826.         {
  827.             console_print( id, "The value must be in seconds!" );
  828.             return PLUGIN_HANDLED;
  829.         }
  830.        
  831.         read_argv( 3, szArg, 31 );
  832.        
  833.         if( szArg[ 0 ] )
  834.         {
  835.             iFlags = read_flags( szArg );
  836.         }
  837.     }
  838.    
  839.     GagPlayer( id, iPlayer, g_szSteamID[ iPlayer ], iGagTime, iFlags );
  840.    
  841.     return PLUGIN_HANDLED;
  842. }
  843.  
  844. GagPlayer( id, iPlayer, const szPlayerSteamID[ ], iGagTime, iFlags, bSave=1, bNotify=1 )
  845. {
  846.     new iMaxTime = get_pcvar_num( g_pCvarMaxTime );
  847.    
  848.     if( iGagTime == -1 )
  849.     {
  850.         iGagTime = clamp( get_pcvar_num( g_pCvarDefaultTime ), 0, iMaxTime );
  851.     }
  852.    
  853.     if( iGagTime )
  854.     {
  855.         new iTimeUnit = GetTimeUnit( );
  856.        
  857.         iGagTime = clamp( iGagTime, 1, iMaxTime ) * g_iTimeUnitMult[ iTimeUnit ];
  858.     }
  859.    
  860.     if( !iFlags )
  861.     {
  862.         new szFlags[ 27 ];
  863.         get_pcvar_string( g_pCvarDefaultFlags, szFlags, charsmax( szFlags ) );
  864.        
  865.         iFlags = read_flags( szFlags );
  866.     }
  867.    
  868.     new data[ GagData ];
  869.     data[ GAG_START ]  = get_systime( );
  870.     data[ GAG_TIME ]   = iGagTime;
  871.     data[ GAG_FLAGS ]  = iFlags;
  872.     data[ GAG_SAVE ]   = bSave;
  873.     data[ GAG_NOTIFY ] = bNotify;
  874.     copy( data[ GAG_STEAMID ], 34, szPlayerSteamID );
  875.    
  876.     TrieSetCell( g_tArrayPos, szPlayerSteamID, g_iGagged );
  877.     ArrayPushArray( g_aGagData, data );
  878.    
  879.     g_iGagged++;
  880.    
  881.     if( iGagTime > 0 )
  882.     {
  883.         new Float:flGametime = get_gametime( ), Float:flNextThink;
  884.         flNextThink = entity_get_float( g_iThinker, EV_FL_nextthink );
  885.        
  886.         if( !flNextThink || flNextThink > ( flGametime + iGagTime ) )
  887.         {
  888.             entity_set_float( g_iThinker, EV_FL_nextthink, flGametime + iGagTime );
  889.         }
  890.     }
  891.    
  892.     if( bSave )
  893.     {
  894.         if( g_bUsingSQL )
  895.         {
  896.             new szPlayerName[ 32 ], szPlayerIP[ 32 ];
  897.            
  898.             if( iPlayer )
  899.             {
  900.                 get_user_name( iPlayer, szPlayerName, charsmax( szPlayerName ) );
  901.                 get_user_ip( iPlayer, szPlayerIP, charsmax( szPlayerIP ), 1 );
  902.             }
  903.             else
  904.             {
  905.                 szPlayerName[ 0 ] = szPlayerIP[ 0 ] = '?';
  906.             }
  907.            
  908.             AddGag( id, g_szSteamID[ iPlayer ], szPlayerName, szPlayerIP, iGagTime, iFlags );
  909.         }
  910.         else
  911.         {
  912.             SaveToFile( );
  913.         }
  914.     }
  915.    
  916.     if( bNotify )
  917.     {
  918.         new szFrom[ 64 ];
  919.        
  920.         if( iFlags & GAG_CHAT )
  921.         {
  922.             copy( szFrom, 63, "say" );
  923.         }
  924.        
  925.         if( iFlags & GAG_TEAMSAY )
  926.         {
  927.             if( !szFrom[ 0 ] )
  928.                 copy( szFrom, 63, "say_team" );
  929.             else
  930.                 add( szFrom, 63, " / say_team" );
  931.         }
  932.        
  933.         if( iFlags & GAG_VOICE )
  934.         {
  935.             set_speak( iPlayer, SPEAK_MUTED );
  936.            
  937.             if( !szFrom[ 0 ] )
  938.                 copy( szFrom, 63, "voicecomm" );
  939.             else
  940.                 add( szFrom, 63, " / voicecomm" );
  941.         }
  942.        
  943.         new szName[ 64 ];
  944.        
  945.         if( iPlayer )
  946.         {
  947.             get_user_name( iPlayer, szName, 19 );
  948.         }
  949.         else
  950.         {
  951.             formatex( szName, charsmax( szName ), "a non-connected player <%s>", szPlayerSteamID );
  952.         }
  953.        
  954.         new szInfo[ 32 ], szAdmin[ 20 ];
  955.         get_user_name( id, szAdmin, 19 );
  956.        
  957.         if( iGagTime > 0 )
  958.         {
  959.             new iLen = copy( szInfo, 31, "for " );
  960.             GetTimeLength( iGagTime, szInfo[ iLen ], charsmax( szInfo ) - iLen );
  961.         }
  962.         else
  963.         {
  964.             copy( szInfo, 31, "permanently" );
  965.         }
  966.        
  967.         show_activity( id, szAdmin, "Has gagged %s from speaking %s! (%s)", szName, szInfo, szFrom );
  968.        
  969.         console_print( id, "You have gagged ^"%s^" (%s) !", szName, szFrom );
  970.        
  971.         log_amx( "Gag: ^"%s<%s>^" has gagged ^"%s<%s>^" %s. (%s)", szAdmin, g_szSteamID[ id ], szName, szPlayerSteamID, szInfo, szFrom );
  972.     }
  973. }
  974.  
  975. public CmdAddGag( const id, const iLevel, const iCid )
  976. {
  977.     if( !cmd_access( id, iLevel, iCid, 2 ) )
  978.     {
  979.         console_print( id, "Flags: a - Chat | b - Team Chat | c - Voice communications" );
  980.         return PLUGIN_HANDLED;
  981.     }
  982.    
  983.     new szArg[ 32 ];
  984.     read_argv( 1, szArg, 31 );
  985.    
  986.     if( !IsValidSteamID( szArg ) )
  987.     {
  988.         console_print( id, "Invalid SteamID provided (%s). Must be in ^"STEAM_0:X:XXXXX^" format (remember to use quotes!)", szArg );
  989.         return PLUGIN_HANDLED;
  990.     }
  991.    
  992.     new iPlayer = find_player( "c", szArg );
  993.    
  994.     if( is_user_connected( iPlayer ) )
  995.     {
  996.         new szTime[ 12 ], szFlags[ 4 ];
  997.         read_argv( 2, szTime,  charsmax( szTime  ) );
  998.         read_argv( 3, szFlags, charsmax( szFlags ) );
  999.        
  1000.         client_cmd( id, "amx_gag #%d ^"%s^" ^"%s^"", get_user_userid( iPlayer ), szTime, szFlags );
  1001.         return PLUGIN_HANDLED;
  1002.     }
  1003.    
  1004.     if( TrieKeyExists( g_tArrayPos, szArg ) )
  1005.     {
  1006.         console_print( id, "This user is already gagged!" );
  1007.         return PLUGIN_HANDLED;
  1008.     }
  1009.    
  1010.     if( GetAccessBySteamID( szArg ) & ADMIN_IMMUNITY )
  1011.     {
  1012.         console_print( id, "This user has immunity!" );
  1013.         return PLUGIN_HANDLED;
  1014.     }
  1015.    
  1016.     new data[ GagData ];
  1017.     copy( data[ GAG_STEAMID ], 34, szArg );
  1018.    
  1019.     get_pcvar_string( g_pCvarDefaultFlags, szArg, charsmax( szArg ) );
  1020.     new iFlags = read_flags( szArg );
  1021.    
  1022.     new iMaxTime = get_pcvar_num( g_pCvarMaxTime );
  1023.     new iGagTime = clamp( get_pcvar_num( g_pCvarDefaultTime ), 0, iMaxTime );
  1024.    
  1025.     read_argv( 2, szArg, 31 );
  1026.    
  1027.     if( szArg[ 0 ] ) // No time entered
  1028.     {
  1029.         if( is_str_num( szArg ) ) // Seconds entered
  1030.         {
  1031.             iGagTime = min( abs( str_to_num( szArg ) ), iMaxTime );
  1032.         }
  1033.         else
  1034.         {
  1035.             console_print( id, "The value must be in seconds!" );
  1036.             return PLUGIN_HANDLED;
  1037.         }
  1038.        
  1039.         read_argv( 3, szArg, 31 );
  1040.        
  1041.         if( szArg[ 0 ] )
  1042.         {
  1043.             iFlags = read_flags( szArg );
  1044.         }
  1045.     }
  1046.    
  1047.     new iTimeUnit = GetTimeUnit( );
  1048.    
  1049.     // convert to seconds
  1050.     iGagTime *= g_iTimeUnitMult[ iTimeUnit ];
  1051.    
  1052.     data[ GAG_START ] = get_systime( );
  1053.     data[ GAG_TIME ]  = iGagTime;
  1054.     data[ GAG_FLAGS ] = iFlags;
  1055.    
  1056.     TrieSetCell( g_tArrayPos, data[ GAG_STEAMID ], g_iGagged );
  1057.     ArrayPushArray( g_aGagData, data );
  1058.    
  1059.     new szFrom[ 64 ];
  1060.    
  1061.     if( iFlags & GAG_CHAT )
  1062.     {
  1063.         copy( szFrom, 63, "say" );
  1064.     }
  1065.    
  1066.     if( iFlags & GAG_TEAMSAY )
  1067.     {
  1068.         if( !szFrom[ 0 ] )
  1069.             copy( szFrom, 63, "say_team" );
  1070.         else
  1071.             add( szFrom, 63, " / say_team" );
  1072.     }
  1073.    
  1074.     if( iFlags & GAG_VOICE )
  1075.     {
  1076.         if( !szFrom[ 0 ] )
  1077.             copy( szFrom, 63, "voicecomm" );
  1078.         else
  1079.             add( szFrom, 63, " / voicecomm" );
  1080.     }
  1081.    
  1082.     g_iGagged++;
  1083.    
  1084.     if( iGagTime > 0 )
  1085.     {
  1086.         new Float:flGametime = get_gametime( ), Float:flNextThink;
  1087.         flNextThink = entity_get_float( g_iThinker, EV_FL_nextthink );
  1088.        
  1089.         if( !flNextThink || flNextThink > ( flGametime + iGagTime ) )
  1090.             entity_set_float( g_iThinker, EV_FL_nextthink, flGametime + iGagTime );
  1091.     }
  1092.    
  1093.     if( g_bUsingSQL )
  1094.     {
  1095.         AddGag( id, data[ GAG_STEAMID ], "?", "?", iGagTime, iFlags );
  1096.     }
  1097.     else
  1098.     {
  1099.         SaveToFile( );
  1100.     }
  1101.    
  1102.     new szInfo[ 32 ], szAdmin[ 20 ];
  1103.     get_user_name( id, szAdmin, 19 );
  1104.    
  1105.     if( iGagTime > 0 )
  1106.     {
  1107.         new iLen = copy( szInfo, 31, "for " );
  1108.         GetTimeLength( iGagTime, szInfo[ iLen ], charsmax( szInfo ) - iLen );
  1109.     }
  1110.     else
  1111.     {
  1112.         copy( szInfo, 31, "permanently" );
  1113.     }
  1114.    
  1115.     show_activity( id, szAdmin, "Has gagged a non-connected player <%s> from speaking %s! (%s)", data[ GAG_STEAMID ], szInfo, szFrom );
  1116.    
  1117.     console_print( id, "You have gagged ^"%s^" (%s) !", data[ GAG_STEAMID ], szFrom );
  1118.    
  1119.     log_amx( "Gag: ^"%s<%s>^" has gagged a non-connected player ^"<%s>^" %s. (%s)", szAdmin, g_szSteamID[ id ], data[ GAG_STEAMID ], szInfo, szFrom );
  1120.    
  1121.     return PLUGIN_HANDLED;
  1122. }
  1123.  
  1124. public CmdUnGagPlayer( const id, const iLevel, const iCid )
  1125. {
  1126.     if( !cmd_access( id, iLevel, iCid, 2 ) )
  1127.         return PLUGIN_HANDLED;
  1128.    
  1129.     new szArg[ 32 ];
  1130.     read_argv( 1, szArg, 31 );
  1131.    
  1132.     if( szArg[ 0 ] == '@' && equali( szArg[ 1 ], "all" ) )
  1133.     {
  1134.         if( !g_iGagged )
  1135.         {
  1136.             console_print( id, "No gagged players!" );
  1137.             return PLUGIN_HANDLED;
  1138.         }
  1139.        
  1140.         DeleteAllGags( );
  1141.        
  1142.         if( entity_get_float( g_iThinker, EV_FL_nextthink ) > 0.0 )
  1143.             entity_set_float( g_iThinker, EV_FL_nextthink, 0.0 );
  1144.        
  1145.         console_print( id, "You have ungagged all players!" );
  1146.        
  1147.         new szAdmin[ 32 ];
  1148.         get_user_name( id, szAdmin, 31 );
  1149.        
  1150.         show_activity( id, szAdmin, "Has ungagged all players." );
  1151.        
  1152.         log_amx( "UnGag: ^"%s<%s>^" has ungagged all players.", szAdmin, g_szSteamID[ id ] );
  1153.        
  1154.         return PLUGIN_HANDLED;
  1155.     }
  1156.    
  1157.     new iPlayer = cmd_target( id, szArg, CMDTARGET_NO_BOTS );
  1158.     new iArrayPos, szName[ 32 ];
  1159.    
  1160.     if( !iPlayer )
  1161.     {
  1162.         // Maybe it's a steamid
  1163.        
  1164.         if( !IsValidSteamID( szArg ) )
  1165.         {
  1166.             return PLUGIN_HANDLED;
  1167.         }
  1168.        
  1169.         if( !TrieGetCell( g_tArrayPos, szArg, iArrayPos ) )
  1170.         {
  1171.             console_print( id, "This steamid is not gagged!" );
  1172.             return PLUGIN_HANDLED;
  1173.         }
  1174.        
  1175.         copy( szName, charsmax( szName ), szArg );
  1176.     }
  1177.     else
  1178.     {
  1179.         get_user_name( iPlayer, szName, charsmax( szName ) );
  1180.        
  1181.         if( !TrieGetCell( g_tArrayPos, g_szSteamID[ iPlayer ], iArrayPos ) )
  1182.         {
  1183.             console_print( id, "User ^"%s^" is not gagged!", szName );
  1184.             return PLUGIN_HANDLED;
  1185.         }
  1186.     }
  1187.    
  1188.     DeleteGag( iArrayPos );
  1189.    
  1190.     if( !g_bUsingSQL )
  1191.     {
  1192.         SaveToFile( );
  1193.     }
  1194.    
  1195.     new szAdmin[ 32 ];
  1196.     get_user_name( id, szAdmin, 31 );
  1197.    
  1198.     show_activity( id, szAdmin, "Has ungagged %s.", szName );
  1199.    
  1200.     console_print( id, "You have ungagged ^"%s^" !", szName );
  1201.    
  1202.     log_amx( "UnGag: ^"%s<%s>^" has ungagged ^"%s<%s>^"", szAdmin, g_szSteamID[ id ], szName, g_szSteamID[ iPlayer ] );
  1203.    
  1204.     return PLUGIN_HANDLED;
  1205. }
  1206.  
  1207. public CmdGagMenu( const id, const iLevel, const iCid )
  1208. {
  1209.     if( !cmd_access( id, iLevel, iCid, 1 ) )
  1210.     {
  1211.         return PLUGIN_HANDLED;
  1212.     }
  1213.    
  1214.     g_iMenuOption[ id ] = 0;
  1215.     arrayset( g_iMenuPlayers[ id ], 0, 32 );
  1216.    
  1217.     DisplayGagMenu( id, g_iMenuPosition[ id ] = 0 );
  1218.    
  1219.     return PLUGIN_HANDLED;
  1220. }
  1221.  
  1222. #define PERPAGE 6
  1223.  
  1224. public ActionGagMenu( const id, const iKey )
  1225. {
  1226.     switch( iKey )
  1227.     {
  1228.         case 6: DisplayGagFlags( id );
  1229.         case 7:
  1230.         {
  1231.             ++g_iMenuOption[ id ];
  1232.             g_iMenuOption[ id ] %= g_iTotalGagTimes;
  1233.            
  1234.             DisplayGagMenu( id, g_iMenuPosition[ id ] );
  1235.         }
  1236.         case 8: DisplayGagMenu( id, ++g_iMenuPosition[ id ] );
  1237.         case 9: DisplayGagMenu( id, --g_iMenuPosition[ id ] );
  1238.         default:
  1239.         {
  1240.             new iPlayer = g_iMenuPlayers[ id ][ g_iMenuPosition[ id ] * PERPAGE + iKey ];
  1241.            
  1242.             if( is_user_connected( iPlayer ) )
  1243.             {
  1244.                 if( !g_iMenuOption[ id ] )
  1245.                 {
  1246.                     new iArrayPos;
  1247.                    
  1248.                     if( TrieGetCell( g_tArrayPos, g_szSteamID[ iPlayer ], iArrayPos ) )
  1249.                     {
  1250.                         DeleteGag( iArrayPos );
  1251.                        
  1252.                         if( !g_bUsingSQL )
  1253.                         {
  1254.                             SaveToFile( );
  1255.                         }
  1256.                        
  1257.                         new szName[ 32 ];
  1258.                         get_user_name( iPlayer, szName, 31 );
  1259.                        
  1260.                         new szAdmin[ 32 ];
  1261.                         get_user_name( id, szAdmin, 31 );
  1262.                        
  1263.                         show_activity( id, szAdmin, "Has ungagged %s.", szName );
  1264.                        
  1265.                         console_print( id, "You have ungagged ^"%s^" !", szName );
  1266.                        
  1267.                         log_amx( "UnGag: ^"%s<%s>^" has ungagged ^"%s<%s>^"", szAdmin, g_szSteamID[ id ], szName, g_szSteamID[ iPlayer ] );
  1268.                     }
  1269.                 }
  1270.                 else if( !TrieKeyExists( g_tArrayPos, g_szSteamID[ iPlayer ] ) )
  1271.                 {
  1272.                     GagPlayer( id, iPlayer, g_szSteamID[ iPlayer ], ArrayGetCell( g_aGagTimes, g_iMenuOption[ id ] ), g_iMenuFlags[ id ] );
  1273.                 }
  1274.             }
  1275.            
  1276.             DisplayGagMenu( id, g_iMenuPosition[ id ] );
  1277.         }
  1278.     }
  1279. }
  1280.  
  1281. // I just copied this from AMXX Ban menu, so don't blame me :D
  1282. DisplayGagMenu( const id, iPosition )
  1283. {
  1284.     if( iPosition < 0 )
  1285.     {
  1286.         arrayset( g_iMenuPlayers[ id ], 0, 32 );
  1287.         return;
  1288.     }
  1289.    
  1290.     new iPlayers[ 32 ], iNum, iCount, szMenu[ 512 ], iPlayer, iFlags, szName[ 32 ];
  1291.     get_players( iPlayers, iNum, "ch" ); // Ignore bots and hltv
  1292.    
  1293.     new iStart = iPosition * PERPAGE;
  1294.    
  1295.     if( iStart >= iNum )
  1296.         iStart = iPosition = g_iMenuPosition[ id ] = 0;
  1297.    
  1298.     new iEnd = iStart + PERPAGE, iKeys = MENU_KEY_0 | MENU_KEY_8;
  1299.     new iLen = formatex( szMenu, 511, g_bColorSupported ? "\rGag Menu\R%d/%d^n^n" : "Gag Menu %d/%d^n^n", iPosition + 1, ( ( iNum + PERPAGE - 1 ) / PERPAGE ) );
  1300.    
  1301.     new bool:bUngag = bool:!g_iMenuOption[ id ];
  1302.    
  1303.     if( iEnd > iNum ) iEnd = iNum;
  1304.    
  1305.     for( new i = iStart; i < iEnd; ++i )
  1306.     {
  1307.         iPlayer = iPlayers[ i ];
  1308.         iFlags  = get_user_flags( iPlayer );
  1309.         get_user_name( iPlayer, szName, 31 );
  1310.        
  1311.         if( iPlayer == id || ( iFlags & ADMIN_IMMUNITY ) || bUngag != TrieKeyExists( g_tArrayPos, g_szSteamID[ iPlayer ] ) )
  1312.         {
  1313.             ++iCount;
  1314.            
  1315.             if( g_bColorSupported )
  1316.                 iLen += formatex( szMenu[ iLen ], 511 - iLen, "\d%d. %s^n", iCount, szName );
  1317.             else
  1318.                 iLen += formatex( szMenu[ iLen ], 511 - iLen, "#. %s^n", szName );
  1319.         }
  1320.         else
  1321.         {
  1322.             iKeys |= ( 1 << iCount );
  1323.             ++iCount;
  1324.            
  1325.             iLen += formatex( szMenu[ iLen ], 511 - iLen, g_bColorSupported ? "\r%d.\w %s\y%s\r%s^n" : "%d. %s%s%s^n", iCount, szName, TrieKeyExists( g_tArrayPos, g_szSteamID[ iPlayer ] ) ? " GAGGED" : "", ( ~iFlags & ADMIN_USER ? " *" : "" ) );
  1326.         }
  1327.     }
  1328.    
  1329.     g_iMenuPlayers[ id ] = iPlayers;
  1330.    
  1331.     new szFlags[ 4 ];
  1332.     get_flags( g_iMenuFlags[ id ], szFlags, 3 );
  1333.    
  1334.     iLen += formatex( szMenu[ iLen ], 511 - iLen, g_bColorSupported ? ( bUngag ? "^n\d7. Flags: %s" : "^n\r7.\y Flags:\w %s" ) : ( bUngag ? "^n#. Flags: %s" : "^n7. Flags: %s" ), szFlags );
  1335.    
  1336.     if( !bUngag )
  1337.     {
  1338.         iKeys |= MENU_KEY_7;
  1339.        
  1340.         new iGagTime = ArrayGetCell( g_aGagTimes, g_iMenuOption[ id ] );
  1341.        
  1342.         if( iGagTime )
  1343.         {
  1344.             new szTime[ 128 ];
  1345.             GetTimeLength( iGagTime * g_iTimeUnitMult[ GetTimeUnit( ) ], szTime, charsmax( szTime ) );
  1346.            
  1347.             iLen += formatex( szMenu[ iLen ], 511 - iLen, g_bColorSupported ? "^n\r8.\y Time:\w %s^n" : "^n8. Time: %s^n", szTime );
  1348.         }
  1349.         else
  1350.             iLen += copy( szMenu[ iLen ], 511 - iLen, g_bColorSupported ? "^n\r8.\y Time: Permanent^n" : "^n8. Time: Permanent^n" );
  1351.     }
  1352.     else
  1353.         iLen += copy( szMenu[ iLen ], 511 - iLen, g_bColorSupported ? "^n\r8.\w Ungag^n" : "^n8. Ungag^n" );
  1354.    
  1355.     if( iEnd != iNum )
  1356.     {
  1357.         formatex( szMenu[ iLen ], 511 - iLen, g_bColorSupported ? "^n\r9.\w More...^n\r0.\w %s" : "^n9. More...^n0. %s", iPosition ? "Back" : "Exit" );
  1358.         iKeys |= MENU_KEY_9;
  1359.     }
  1360.     else
  1361.         formatex( szMenu[ iLen ], 511 - iLen, g_bColorSupported ? "^n\r0.\w %s" : "^n0. %s", iPosition ? "Back" : "Exit" );
  1362.    
  1363.     show_menu( id, iKeys, szMenu, -1, "Gag Menu" );
  1364. }
  1365.  
  1366. public ActionGagFlags( const id, const iKey )
  1367. {
  1368.     switch( iKey )
  1369.     {
  1370.         case 9: DisplayGagMenu( id, g_iMenuPosition[ id ] );
  1371.         default:
  1372.         {
  1373.             g_iMenuFlags[ id ] ^= ( 1 << iKey );
  1374.            
  1375.             DisplayGagFlags( id );
  1376.         }
  1377.     }
  1378. }
  1379.  
  1380. DisplayGagFlags( const id )
  1381. {
  1382.     new szMenu[ 512 ];
  1383.     new iLen = copy( szMenu, 511, g_bColorSupported ? "\rGag Flags^n^n" : "Gag Flags^n^n" );
  1384.    
  1385.     if( g_bColorSupported )
  1386.     {
  1387.         iLen += formatex( szMenu[ iLen ], 511 - iLen, "\r1.\w Chat: %s^n", ( g_iMenuFlags[ id ] & GAG_CHAT ) ? "\yYES" : "\rNO" );
  1388.         iLen += formatex( szMenu[ iLen ], 511 - iLen, "\r2.\w TeamSay: %s^n", ( g_iMenuFlags[ id ] & GAG_TEAMSAY ) ? "\yYES" : "\rNO" );
  1389.         iLen += formatex( szMenu[ iLen ], 511 - iLen, "\r3.\w Voice: %s^n", ( g_iMenuFlags[ id ] & GAG_VOICE ) ? "\yYES" : "\rNO" );
  1390.     }
  1391.     else
  1392.     {
  1393.         iLen += formatex( szMenu[ iLen ], 511 - iLen, "1. Chat: %s^n", ( g_iMenuFlags[ id ] & GAG_CHAT ) ? "YES" : "NO" );
  1394.         iLen += formatex( szMenu[ iLen ], 511 - iLen, "2. TeamSay: %s^n", ( g_iMenuFlags[ id ] & GAG_TEAMSAY ) ? "YES" : "NO" );
  1395.         iLen += formatex( szMenu[ iLen ], 511 - iLen, "3. Voice: %s^n", ( g_iMenuFlags[ id ] & GAG_VOICE ) ? "YES" : "NO" );
  1396.     }
  1397.    
  1398.     copy( szMenu[ iLen ], 511 - iLen, g_bColorSupported ? "^n\r0. \wBack to Gag Menu" : "^n0. Back to Gag Menu" );
  1399.    
  1400.     show_menu( id, ( MENU_KEY_1 | MENU_KEY_2 | MENU_KEY_3 | MENU_KEY_0 ), szMenu, -1, "Gag Flags" );
  1401. }
  1402.  
  1403. CheckGagFlag( const id, const iFlag )
  1404. {
  1405.     new iArrayPos;
  1406.    
  1407.     if( TrieGetCell( g_tArrayPos, g_szSteamID[ id ], iArrayPos ) )
  1408.     {
  1409.         new data[ GagData ];
  1410.         ArrayGetArray( g_aGagData, iArrayPos, data );
  1411.        
  1412.         return ( data[ GAG_FLAGS ] & iFlag );
  1413.     }
  1414.    
  1415.     return 0;
  1416. }
  1417.  
  1418. DeleteAllGags( )
  1419. {
  1420.     new data[ GagData ];
  1421.     new iPlayer;
  1422.    
  1423.     for( new i = 0; i < g_iGagged; i++ )
  1424.     {
  1425.         ArrayGetArray( g_aGagData, i, data );
  1426.        
  1427.         iPlayer = find_player( "c", data[ GAG_STEAMID ] );
  1428.        
  1429.         if( is_user_connected( iPlayer ) )
  1430.         {
  1431.             set_speak( iPlayer, SPEAK_NORMAL );
  1432.         }
  1433.     }
  1434.    
  1435.     ArrayClear( g_aGagData );
  1436.     TrieClear( g_tArrayPos );
  1437.    
  1438.     g_iGagged = 0;
  1439.    
  1440.     if( g_bUsingSQL )
  1441.     {
  1442.         SQL_ThreadQuery( g_hSqlTuple, "HandleDefaultQuery", "TRUNCATE TABLE gagged_players" );
  1443.     }
  1444. }
  1445.  
  1446. DeleteGag( const iArrayPos )
  1447. {
  1448.     new data[ GagData ];
  1449.     ArrayGetArray( g_aGagData, iArrayPos, data );
  1450.    
  1451.     if( data[ GAG_FLAGS ] & GAG_VOICE )
  1452.     {
  1453.         new iPlayer = find_player( "c", data[ GAG_STEAMID ] );
  1454.        
  1455.         if( is_user_connected( iPlayer ) )
  1456.         {
  1457.             set_speak( iPlayer, SPEAK_NORMAL );
  1458.         }
  1459.     }
  1460.    
  1461.     TrieDeleteKey( g_tArrayPos, data[ GAG_STEAMID ] );
  1462.     ArrayDeleteItem( g_aGagData, iArrayPos );
  1463.    
  1464.     g_iGagged--;
  1465.    
  1466.     for( new i = iArrayPos; i < g_iGagged; i++ )
  1467.     {
  1468.         ArrayGetArray( g_aGagData, i, data );
  1469.         TrieSetCell( g_tArrayPos, data[ GAG_STEAMID ], i );
  1470.     }
  1471.    
  1472.     if( g_bUsingSQL && data[ GAG_SAVE ] )
  1473.     {
  1474.         formatex( szQuery, charsmax( szQuery ), "DELETE FROM gagged_players WHERE player_steamid = '%s'", data[ GAG_STEAMID ] );
  1475.        
  1476.         SQL_ThreadQuery( g_hSqlTuple, "HandleDefaultQuery", szQuery );
  1477.     }
  1478. }
  1479.  
  1480. LoadFromFile( )
  1481. {
  1482.     new hFile = fopen( g_szGagFile, "rt" );
  1483.    
  1484.     if( hFile )
  1485.     {
  1486.         new szData[ 128 ], szTime[ 16 ], szStart[ 16 ], szFlags[ 4 ];
  1487.         new data[ GagData ], iSystime = get_systime( ), iTimeLeft, iShortestTime = 999999;
  1488.         new bool:bRemovedGags = false;
  1489.        
  1490.         data[ GAG_SAVE   ] = 1;
  1491.         data[ GAG_NOTIFY ] = 1;
  1492.        
  1493.         while( !feof( hFile ) )
  1494.         {
  1495.             fgets( hFile, szData, charsmax( szData ) );
  1496.             trim( szData );
  1497.            
  1498.             if( !szData[ 0 ] )
  1499.             {
  1500.                 continue;
  1501.             }
  1502.            
  1503.             parse( szData,
  1504.                 data[ GAG_STEAMID ], charsmax( data[ GAG_STEAMID ] ),
  1505.                 szTime, charsmax( szTime ),
  1506.                 szStart, charsmax( szStart ),
  1507.                 szFlags, charsmax( szFlags )
  1508.             );
  1509.            
  1510.             // Remove old gags
  1511.             if( contain( szStart, "." ) > 0 )
  1512.             {
  1513.                 continue;
  1514.             }
  1515.            
  1516.             data[ GAG_TIME ] = str_to_num( szTime );
  1517.             data[ GAG_START ] = str_to_num( szStart );
  1518.             data[ GAG_FLAGS ] = read_flags( szFlags );
  1519.            
  1520.             if( data[ GAG_TIME ] > 0 )
  1521.             {
  1522.                 iTimeLeft = data[ GAG_START ] + data[ GAG_TIME ] - iSystime;
  1523.                
  1524.                 if( iTimeLeft <= 0 )
  1525.                 {
  1526.                     bRemovedGags = true;
  1527.                     continue;
  1528.                 }
  1529.                
  1530.                 if( iShortestTime > iTimeLeft )
  1531.                 {
  1532.                     iShortestTime = iTimeLeft;
  1533.                 }
  1534.             }
  1535.            
  1536.             TrieSetCell( g_tArrayPos, data[ GAG_STEAMID ], g_iGagged );
  1537.             ArrayPushArray( g_aGagData, data );
  1538.             g_iGagged++;
  1539.         }
  1540.        
  1541.         fclose( hFile );
  1542.        
  1543.         if( bRemovedGags )
  1544.         {
  1545.             SaveToFile( );
  1546.         }
  1547.        
  1548.         if( iShortestTime < 999999 )
  1549.         {
  1550.             entity_set_float( g_iThinker, EV_FL_nextthink, get_gametime( ) + iShortestTime );
  1551.         }
  1552.     }
  1553. }
  1554.  
  1555. SaveToFile( )
  1556. {
  1557.     new hFile = fopen( g_szGagFile, "wt" );
  1558.    
  1559.     if( hFile )
  1560.     {
  1561.         new data[ GagData ], szFlags[ 4 ];
  1562.        
  1563.         for( new i = 0; i < g_iGagged; i++ )
  1564.         {
  1565.             ArrayGetArray( g_aGagData, i, data );
  1566.            
  1567.             if( data[ GAG_SAVE ] )
  1568.             {
  1569.                 get_flags( data[ GAG_FLAGS ], szFlags, charsmax( szFlags ) );
  1570.                
  1571.                 fprintf( hFile, "^"%s^" ^"%d^" ^"%d^" ^"%s^"^n", data[ GAG_STEAMID ], data[ GAG_TIME ], data[ GAG_START ], szFlags );
  1572.             }
  1573.         }
  1574.        
  1575.         fclose( hFile );
  1576.     }
  1577. }
  1578.  
  1579. GetTimeUnit( )
  1580. {
  1581.     new szTimeUnit[ 64 ], iTimeUnit;
  1582.     get_pcvar_string( g_pCvarTimeUnit, szTimeUnit, charsmax( szTimeUnit ) );
  1583.    
  1584.     if( is_str_num( szTimeUnit ) )
  1585.     {
  1586.         iTimeUnit = get_pcvar_num( g_pCvarTimeUnit );
  1587.        
  1588.         if( !( 0 <= iTimeUnit < TimeUnit ) )
  1589.         {
  1590.             iTimeUnit = -1;
  1591.         }
  1592.     }
  1593.     else
  1594.     {
  1595.         strtolower( szTimeUnit );
  1596.        
  1597.         if( !TrieGetCell( g_tTimeUnitWords, szTimeUnit, iTimeUnit ) )
  1598.         {
  1599.             iTimeUnit = -1;
  1600.         }
  1601.     }
  1602.    
  1603.     if( iTimeUnit == -1 )
  1604.     {
  1605.         iTimeUnit = TIMEUNIT_SECONDS;
  1606.        
  1607.         set_pcvar_num( g_pCvarTimeUnit, TIMEUNIT_SECONDS );
  1608.     }
  1609.    
  1610.     return iTimeUnit;
  1611. }
  1612.  
  1613. GetTimeLength( iTime, szOutput[ ], iOutputLen )
  1614. {
  1615.     new szTimes[ TimeUnit ][ 32 ];
  1616.     new iUnit, iValue, iTotalDisplay;
  1617.    
  1618.     for( new i = TimeUnit - 1; i >= 0; i-- )
  1619.     {
  1620.         iUnit = g_iTimeUnitMult[ i ];
  1621.         iValue = iTime / iUnit;
  1622.        
  1623.         if( iValue )
  1624.         {
  1625.             formatex( szTimes[ i ], charsmax( szTimes[ ] ), "%d %s", iValue, g_szTimeUnitName[ i ][ iValue != 1 ] );
  1626.            
  1627.             iTime %= iUnit;
  1628.            
  1629.             iTotalDisplay++;
  1630.         }
  1631.     }
  1632.    
  1633.     new iLen, iTotalLeft = iTotalDisplay;
  1634.     szOutput[ 0 ] = 0;
  1635.    
  1636.     for( new i = TimeUnit - 1; i >= 0; i-- )
  1637.     {
  1638.         if( szTimes[ i ][ 0 ] )
  1639.         {
  1640.             iLen += formatex( szOutput[ iLen ], iOutputLen - iLen, "%s%s%s",
  1641.                 ( iTotalDisplay > 2 && iLen ) ? ", " : "",
  1642.                 ( iTotalDisplay > 1 && iTotalLeft == 1 ) ? ( ( iTotalDisplay > 2 ) ? "and " : " and " ) : "",
  1643.                 szTimes[ i ]
  1644.             );
  1645.            
  1646.             iTotalLeft--;
  1647.         }
  1648.     }
  1649.    
  1650.     return iLen
  1651. }
  1652.  
  1653. GreenPrint( id, iSender, const szRawMessage[ ], any:... )
  1654. {
  1655.     if( !iSender )
  1656.     {
  1657.         new iPlayers[ 32 ], iNum;
  1658.         get_players( iPlayers, iNum, "ch" );
  1659.        
  1660.         if( !iNum ) return;
  1661.        
  1662.         iSender = iPlayers[ 0 ];
  1663.     }
  1664.    
  1665.     new szMessage[ 192 ];
  1666.     vformat( szMessage, charsmax( szMessage ), szRawMessage, 4 );
  1667.    
  1668.     message_begin( id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, g_iMsgSayText, _, id );
  1669.     write_byte( iSender );
  1670.     write_string( szMessage );
  1671.     message_end( );
  1672. }
  1673.  
  1674. bool:IsValidSteamID( const szSteamID[ ] )
  1675. {
  1676.     // STEAM_0:(0|1):\d+
  1677.     // 012345678    90
  1678.    
  1679.     // 0-7 = STEAM_0:
  1680.     // 8 = 0 or 1
  1681.     // 9 = :
  1682.     // 10+ = integer
  1683.    
  1684.     return ( ( '0' <= szSteamID[ 8 ] <= '1' ) && szSteamID[ 9 ] == ':' && equal( szSteamID, "STEAM_0:", 8 ) && is_str_num( szSteamID[ 10 ] ) );
  1685. }
  1686.  
  1687. GetAccessBySteamID( const szSteamID[ ] )
  1688. {
  1689.     new szAuthData[ 44 ], iCount = admins_num( );
  1690.    
  1691.     for( new i; i < iCount; i++ )
  1692.     {
  1693.         if( admins_lookup( i, AdminProp_Flags ) & FLAG_AUTHID )
  1694.         {
  1695.             admins_lookup( i, AdminProp_Auth, szAuthData, charsmax( szAuthData ) );
  1696.            
  1697.             if( equal( szAuthData, szSteamID ) )
  1698.             {
  1699.                 return admins_lookup( i, AdminProp_Access );
  1700.             }
  1701.         }
  1702.     }
  1703.    
  1704.     return 0;
  1705. }
  1706.  
  1707. strtotime( const string[ ] )
  1708. {
  1709.     new szTemp[ 32 ];
  1710.     new szYear[ 5 ], szMonth[ 3 ], szDay[ 3 ], szHour[ 3 ], szMinute[ 3 ], szSecond[ 3 ];
  1711.     strtok( string, szYear,   charsmax( szYear   ), szTemp,   charsmax( szTemp   ), '-' );
  1712.     strtok( szTemp, szMonth,  charsmax( szMonth  ), szTemp,   charsmax( szTemp   ), '-' );
  1713.     strtok( szTemp, szDay,    charsmax( szDay    ), szTemp,   charsmax( szTemp   ), ' ' );
  1714.     strtok( szTemp, szHour,   charsmax( szHour   ), szTemp,   charsmax( szTemp   ), ':' );
  1715.     strtok( szTemp, szMinute, charsmax( szMinute ), szSecond, charsmax( szSecond ), ':' );
  1716.    
  1717.     return TimeToUnix( str_to_num( szYear ), str_to_num( szMonth ), str_to_num( szDay ), str_to_num( szHour ), str_to_num( szMinute ), str_to_num( szSecond ) );
  1718. }
  1719.  
  1720. AddGag( admin, const szPlayerSteamID[ ], const szPlayerName[ ], const szPlayerIP[ ], iGagTime, iFlags )
  1721. {
  1722.     new szAdminName[ 32 ], szAdminIP[ 16 ];
  1723.    
  1724.     if( admin )
  1725.     {
  1726.         get_user_name( admin, szAdminName, charsmax( szAdminName ) );
  1727.     }
  1728.     else
  1729.     {
  1730.         copy( szAdminName, charsmax( szAdminName ), "SERVER" );
  1731.     }
  1732.    
  1733.     get_user_ip( admin, szAdminIP, charsmax( szAdminIP ), 1 );
  1734.    
  1735.     new szDateNow[ DATE_SIZE ], szDateUngag[ DATE_SIZE ];
  1736.     get_time( DATETIME_FORMAT, szDateNow, charsmax( szDateNow ) );
  1737.     format_time( szDateUngag, charsmax( szDateUngag ), DATETIME_FORMAT, get_systime( ) + iGagTime );
  1738.    
  1739.     new szFlags[ 4 ];
  1740.     get_flags( iFlags, szFlags, charsmax( szFlags ) );
  1741.    
  1742.     formatex( szQuery, charsmax( szQuery ), "REPLACE INTO gagged_players \
  1743.         (admin_name, admin_steamid, admin_ip, player_name, player_steamid, player_ip, date_gagged, date_ungag, gag_seconds, gag_flags) \
  1744.         VALUES \
  1745.         (^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", %d, ^"%s^")",\
  1746.         szAdminName,  g_szSteamID[ admin ], szAdminIP,\
  1747.         szPlayerName, szPlayerSteamID       , szPlayerIP,\
  1748.         szDateNow, szDateUngag, iGagTime, szFlags );
  1749.    
  1750.     SQL_ThreadQuery( g_hSqlTuple, "HandleDefaultQuery", szQuery );
  1751. }
  1752.  
  1753. public HandleDefaultQuery( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:flQueueTime )
  1754. {
  1755.     if( iFailState != TQUERY_SUCCESS )
  1756.     {
  1757.         switch( iFailState )
  1758.         {
  1759.             case TQUERY_CONNECT_FAILED: log_amx( "Failed to connect to database: (%d) %s", iError, szError );
  1760.             case TQUERY_QUERY_FAILED:   log_amx( "Failed to execute query: (%d) %s", iError, szError );
  1761.         }
  1762.     }
  1763. }
  1764.  
  1765. // CODE BELOW FROM BUGSY'S UNIX TIME INCLUDE
  1766. //
  1767.  
  1768. new const YearSeconds[ 2 ] =
  1769. {
  1770.     31536000,   //Normal year
  1771.     31622400    //Leap year
  1772. };
  1773.  
  1774. new const MonthSeconds[ 12 ] =
  1775. {
  1776.     2678400, //January  31
  1777.     2419200, //February 28
  1778.     2678400, //March    31
  1779.     2592000, //April    30
  1780.     2678400, //May      31
  1781.     2592000, //June     30
  1782.     2678400, //July     31
  1783.     2678400, //August   31
  1784.     2592000, //September    30
  1785.     2678400, //October  31
  1786.     2592000, //November 30
  1787.     2678400  //December 31
  1788. };
  1789.  
  1790. const DaySeconds = 86400;
  1791. const HourSeconds = 3600;
  1792. const MinuteSeconds = 60;
  1793.  
  1794. TimeToUnix( const iYear, const iMonth, const iDay, const iHour, const iMinute, const iSecond )
  1795. {
  1796.     new i, iTimeStamp;
  1797.  
  1798.     for( i = 1970; i < iYear; i++ )
  1799.         iTimeStamp += YearSeconds[ IsLeapYear( i ) ];
  1800.  
  1801.     for( i = 1; i < iMonth; i++ )
  1802.         iTimeStamp += SecondsInMonth( iYear, i );
  1803.  
  1804.     iTimeStamp += ( ( iDay - 1 ) * DaySeconds );
  1805.     iTimeStamp += ( iHour * HourSeconds );
  1806.     iTimeStamp += ( iMinute * MinuteSeconds );
  1807.     iTimeStamp += iSecond;
  1808.  
  1809.     return iTimeStamp;
  1810. }
  1811.  
  1812. SecondsInMonth( const iYear , const iMonth )
  1813. {
  1814.     return ( ( IsLeapYear( iYear ) && ( iMonth == 2 ) ) ? ( MonthSeconds[ iMonth - 1 ] + DaySeconds ) : MonthSeconds[ iMonth - 1 ] );
  1815. }
  1816.  
  1817. IsLeapYear( const iYear )
  1818. {
  1819.     return ( ( ( iYear % 4 ) == 0) && ( ( ( iYear % 100 ) != 0) || ( ( iYear % 400 ) == 0 ) ) );
  1820. }

_________________
„Nem azért felejtünk el játszani, mert megöregszünk, hanem attól öregszünk meg, hogy elfelejtünk játszani.”

-MAXHACKED Website-
-HERViD Website-
► Spoiler mutatása


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: Amx_gag javítás + bővítés
HozzászólásElküldve: 2016.03.03. 18:18 
Offline
Fanatikus
Avatar

Csatlakozott: 2016.02.18. 19:24
Hozzászólások: 193
Megköszönt másnak: 12 alkalommal
Megköszönték neki: 20 alkalommal
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <engine>
  4.  
  5. #define PLUGIN "ADMIN Gag"
  6. #define VERSION "1.0.1"
  7. #define AUTHOR "RaZzoR"
  8.  
  9. #define GAG_FLAG ADMIN_BAN
  10. #define GAG_IMMUNITY ADMIN_IMMUNITY
  11.  
  12. #define DICTIONARY "admin_gag.txt"
  13. #define USE_COLOR_CHAT
  14.  
  15. #if defined USE_COLOR_CHAT
  16.     #include <colorchat>
  17. #endif
  18.  
  19. new const gag_file_name[] = "gagged_users.txt"
  20.  
  21. enum _:GagData {
  22.     gag_name[32],
  23.     gag_steamid[35],
  24.     gag_length,
  25.     ungag_time[32],
  26.     gag_reason[128]
  27. }
  28.  
  29. new Trie:g_trie
  30. new Array:g_array
  31. new total_gags, g_ungag_entity
  32. new gag_file[64], Float:get_gag_time[33], tempid[33]
  33.  
  34. new gag_immunity, gag_ungagcheck
  35.  
  36. public plugin_init() {
  37.     register_plugin(PLUGIN, VERSION, AUTHOR)
  38.  
  39.     #if defined USE_COLOR_CHAT
  40.         register_dictionary_colored(DICTIONARY)
  41.     #else
  42.         register_dictionary(DICTIONARY)
  43.     #endif
  44.  
  45.     gag_immunity = register_cvar("gag_immunity", "1")
  46.     gag_ungagcheck = register_cvar("gag_ungagcheck", "1.0")
  47.  
  48.     register_clcmd("say /gag_menu", "gag_menu")
  49.     register_clcmd("say /ungag_menu", "ungag_menu")
  50.  
  51.     register_clcmd("say", "gag_say")
  52.     register_clcmd("say_team", "gag_say")  
  53.  
  54.     register_clcmd("GAG_TIME", "clcmd_time")
  55.     register_clcmd("GAG_REASON", "clcmd_reason")
  56.  
  57.     register_concmd("gag_authid", "concmd_gag_authid", GAG_FLAG, "<nev, #userid, authid> <ido percben> <ok>")
  58.     register_concmd("gag_ip", "concmd_gag_ip", GAG_FLAG, "<nev, #userid, authid> <ido percben> <ok>")
  59.     register_concmd("gag_add", "concmd_gag_add", GAG_FLAG, "<nev> <authid vagy ip> <ido percben> <ok>")
  60.     register_concmd("gag_list", "concmd_gag_list", GAG_FLAG, "[start] -- megmutat minden nemitast")
  61.     register_concmd("ungag", "concmd_ungag", GAG_FLAG, "<authid vagy ip>")
  62.  
  63.     get_datadir(gag_file, sizeof(gag_file) - 1)
  64.     format(gag_file, sizeof(gag_file) - 1, "%s/%s", gag_file, gag_file_name)
  65.  
  66.     g_trie = TrieCreate()
  67.     g_array = ArrayCreate(GagData)
  68.  
  69.     LoadGags()
  70. }
  71.  
  72. public plugin_cfg() create_ungag_entity()
  73.  
  74. public client_PostThink(id) {
  75.     static authid[35]
  76.     get_user_authid(id, authid, sizeof(authid) - 1)
  77.  
  78.     static ip[35]
  79.     get_user_ip(id, ip, sizeof(ip) - 1, 1)
  80.  
  81.     static array_pos   
  82.     if(TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos)) set_speak(id, SPEAK_MUTED)
  83.     else set_speak(id, SPEAK_LISTENALL)
  84. }
  85.  
  86. public create_ungag_entity() {
  87.     static failtimes
  88.  
  89.     g_ungag_entity = create_entity("info_target")
  90.  
  91.     if(!is_valid_ent(g_ungag_entity)) {
  92.         ++failtimes
  93.  
  94.         log_amx("%L", LANG_SERVER, "FAILED_TO_CREATE_UNGAG_ENTITY", failtimes)
  95.  
  96.         if(failtimes < 10) set_task(1.0, "create_ungag_entity")
  97.         else log_amx("%L", LANG_SERVER, "COULD_NOT_CREATE_UNGAG_ENTITY")
  98.  
  99.         return
  100.     }
  101.  
  102.     entity_set_string(g_ungag_entity, EV_SZ_classname, "ungag_entity")
  103.     entity_set_float(g_ungag_entity, EV_FL_nextthink, get_gametime() + 1.0)
  104.  
  105.     register_think("ungag_entity", "UnGag_Check")
  106. }
  107.  
  108. public UnGag_Check(entity)
  109. {
  110.     if(entity != g_ungag_entity) return
  111.  
  112.     if(total_gags > 0)
  113.     {
  114.         static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7]
  115.         format_time(_hours, sizeof(_hours) - 1, "%H")
  116.         format_time(_minutes, sizeof(_minutes) - 1, "%M")
  117.         format_time(_seconds, sizeof(_seconds) - 1, "%S")
  118.         format_time(_month, sizeof(_month) - 1, "%m")
  119.         format_time(_day, sizeof(_day) - 1, "%d")
  120.         format_time(_year, sizeof(_year) - 1, "%Y")
  121.  
  122.  
  123.         new c_hours = str_to_num(_hours)
  124.         new c_minutes = str_to_num(_minutes)
  125.         new c_seconds = str_to_num(_seconds)
  126.         new c_month = str_to_num(_month)
  127.         new c_day = str_to_num(_day)
  128.         new c_year = str_to_num(_year)
  129.  
  130.         static load_ungag_time[32]
  131.         static u_hours, u_minutes, u_seconds, u_month, u_day, u_year
  132.  
  133.         for(new i = 0; i < total_gags; i++) {
  134.             static data[GagData]
  135.             ArrayGetArray(g_array, i, data)
  136.  
  137.             if(data[gag_length] == 0) continue
  138.  
  139.             copy(load_ungag_time, sizeof(load_ungag_time) - 1, data[ungag_time])
  140.  
  141.             replace_all(load_ungag_time, sizeof(load_ungag_time) - 1, ":", " ")
  142.             replace_all(load_ungag_time, sizeof(load_ungag_time) - 1, "/", " ")
  143.  
  144.             parse(load_ungag_time,\
  145.                 _hours, sizeof(_hours) - 1,\
  146.                 _minutes, sizeof(_minutes) - 1,\
  147.                 _seconds, sizeof(_seconds) - 1,\
  148.                 _month, sizeof(_month) - 1,\
  149.                 _day, sizeof(_day) - 1,\
  150.                 _year, sizeof(_year) - 1
  151.                 )
  152.  
  153.             u_hours = str_to_num(_hours)
  154.             u_minutes = str_to_num(_minutes)
  155.             u_seconds = str_to_num(_seconds)
  156.             u_month = str_to_num(_month)
  157.             u_day = str_to_num(_day)
  158.             u_year = str_to_num(_year)
  159.  
  160.             if( u_year < c_year
  161.             || u_year == c_year && u_month < c_month
  162.             || u_year == c_year && u_month == c_month && u_day < c_day
  163.             || u_year == c_year && u_month == c_month && u_day == c_day && u_hours < c_hours
  164.             || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes < c_minutes
  165.             || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes == c_minutes && u_seconds <= c_seconds ) {
  166.                 #if defined USE_COLOR_CHAT
  167.                     ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_EXPIRED", data[gag_name], data[gag_steamid], data[gag_reason])
  168.                 #else
  169.                     NoColorChat(0, "%L", LANG_PLAYER, "GAG_EXPIRED", data[gag_name], data[gag_steamid], data[gag_reason])
  170.                 #endif
  171.  
  172.                 RemoveGag(i, data[gag_steamid])
  173.  
  174.                 i--
  175.             }
  176.         }
  177.     }
  178.  
  179.     entity_set_float(g_ungag_entity, EV_FL_nextthink, get_gametime() + get_pcvar_float(gag_ungagcheck))
  180. }
  181.  
  182. public concmd_gag_authid(id, level, cid) {
  183.     if(!cmd_access(id, level, cid, 4)) return PLUGIN_HANDLED
  184.  
  185.     static arg[128]
  186.     read_argv(1, arg, sizeof(arg) - 1)
  187.  
  188.     new target = cmd_target(id, arg, GetTargetFlags(id))
  189.     if(!target) return PLUGIN_HANDLED
  190.  
  191.     static target_authid[35]
  192.     get_user_authid(target, target_authid, sizeof(target_authid) - 1)
  193.  
  194.     if(TrieKeyExists(g_trie, target_authid)) {
  195.         console_print(id, "%L", id, "ALREADY_GAGGED_STEAMID", target_authid)
  196.         return PLUGIN_HANDLED
  197.     }
  198.  
  199.     read_argv(2, arg, sizeof(arg) - 1)
  200.     new Float:length = str_to_float(arg)
  201.  
  202.     static ungag_time2[64], gag_time2[64]
  203.  
  204.     if(length == 0.0) formatex(ungag_time2, sizeof(ungag_time2) - 1, "%L", id, "PERMANENT_GAG")
  205.     else GenerateUnGagTime(length, ungag_time2, sizeof(ungag_time2) - 1)
  206.  
  207.     read_argv(3, arg, sizeof(arg) - 1)
  208.  
  209.     static admin_name[64], target_name[32]
  210.     get_user_name(id, admin_name, sizeof(admin_name) - 1)
  211.     get_user_name(target, target_name, sizeof(target_name) - 1)
  212.  
  213.     static admin_authid[35]
  214.     get_user_authid(id, admin_authid, sizeof(admin_authid) - 1)
  215.  
  216.     GagAdd(target_name, target_authid, arg, floatround(length * 60.0, floatround_floor), ungag_time2)
  217.  
  218.     GetGagTime(id, length, gag_time2, sizeof(gag_time2) - 1)
  219.  
  220.     #if defined USE_COLOR_CHAT
  221.         ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  222.     #else
  223.         NoColorChat(0, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  224.     #endif
  225.  
  226.     return PLUGIN_HANDLED
  227. }
  228.  
  229. public concmd_gag_ip(id, level, cid) {
  230.     if(!cmd_access(id, level, cid, 4)) return PLUGIN_HANDLED
  231.  
  232.     static arg[128]
  233.     read_argv(1, arg, sizeof(arg) - 1)
  234.  
  235.     new target = cmd_target(id, arg, GetTargetFlags(id))
  236.     if(!target) return PLUGIN_HANDLED
  237.  
  238.     static target_ip[35]
  239.     get_user_ip(target, target_ip, sizeof(target_ip) - 1, 1)
  240.  
  241.     if(TrieKeyExists(g_trie, target_ip)) {
  242.         console_print(id, "%L", id, "ALREADY_GAGGED_IP", target_ip)
  243.         return PLUGIN_HANDLED
  244.     }
  245.  
  246.     read_argv(2, arg, sizeof(arg) - 1)
  247.     new Float:length = str_to_float(arg)
  248.  
  249.     static ungag_time2[64], gag_time2[64]
  250.  
  251.     if(length == 0.0) formatex(ungag_time2, sizeof(ungag_time2) - 1, "%L", id, "PERMANENT_GAG")
  252.     else GenerateUnGagTime(length, ungag_time2, sizeof(ungag_time2) - 1)
  253.  
  254.     read_argv(3, arg, sizeof(arg) - 1)
  255.  
  256.     static admin_name[64], target_name[32]
  257.     get_user_name(id, admin_name, sizeof(admin_name) - 1)
  258.     get_user_name(target, target_name, sizeof(target_name) - 1)
  259.  
  260.     static admin_authid[35]
  261.     get_user_authid(id, admin_authid, sizeof(admin_authid) - 1)
  262.  
  263.     GagAdd(target_name, target_ip, arg, floatround(length * 60.0, floatround_floor), ungag_time2)
  264.  
  265.     GetGagTime(id, length, gag_time2, sizeof(gag_time2) - 1)
  266.  
  267.     #if defined USE_COLOR_CHAT
  268.         ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  269.     #else
  270.         NoColorChat(0, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  271.     #endif
  272.  
  273.     return PLUGIN_HANDLED
  274. }
  275.  
  276. public concmd_gag_add(id, level, cid) {
  277.     if(!cmd_access(id, level, cid, 5)) return PLUGIN_HANDLED
  278.  
  279.     static target_name[128], target_authid[128], gagtime[128], reason[128]
  280.     read_argv(1, target_name, sizeof(target_name) - 1)
  281.     read_argv(2, target_authid, sizeof(target_authid) - 1)
  282.     read_argv(3, gagtime, sizeof(gagtime) - 1)
  283.     read_argv(4, reason, sizeof(reason) - 1)
  284.  
  285.     new bool:is_ip = bool:(containi(target_authid, ".") != -1)
  286.  
  287.     if(TrieKeyExists(g_trie, target_authid)) {
  288.         console_print(id, "%L", id, is_ip ? "ALREADY_GAGGED_IP" : "ALREADY_GAGGED_STEAMID", target_authid)
  289.         return PLUGIN_HANDLED
  290.     }
  291.  
  292.     new Float:length = str_to_float(gagtime)
  293.     static ungag_time2[64], gag_time2[64]
  294.  
  295.     if(length == 0.0) formatex(ungag_time2, sizeof(ungag_time2) - 1, "%L", id, "PERMANENT_GAG")
  296.     else GenerateUnGagTime(length, ungag_time2, sizeof(ungag_time2) - 1)
  297.  
  298.     static admin_name[64]
  299.     get_user_name(id, admin_name, sizeof(admin_name) - 1)
  300.  
  301.     static admin_authid[35]
  302.     get_user_authid(id, admin_authid, sizeof(admin_authid) - 1)
  303.  
  304.     GagAdd(target_name, target_authid, reason, floatround(length * 60.0, floatround_floor), ungag_time2)
  305.  
  306.     GetGagTime(id, length, gag_time2, sizeof(gag_time2) - 1)
  307.  
  308.     #if defined USE_COLOR_CHAT
  309.         ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, reason, gag_time2, ungag_time2)
  310.     #else
  311.         NoColorChat(0, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, reason, gag_time2, ungag_time2)
  312.     #endif
  313.  
  314.     return PLUGIN_HANDLED
  315. }  
  316.  
  317. public concmd_ungag(id, level, cid) {
  318.     if(!cmd_access(id, level, cid, 2)) return PLUGIN_HANDLED
  319.  
  320.     static arg[35]
  321.     read_argv(1, arg, sizeof(arg) - 1)
  322.  
  323.     if(TrieKeyExists(g_trie, arg)) {
  324.         static array_pos;
  325.         TrieGetCell(g_trie, arg, array_pos);
  326.  
  327.         static data[GagData]
  328.         ArrayGetArray(g_array, array_pos, data)
  329.  
  330.         static admin_name[64]
  331.         get_user_name(id, admin_name, sizeof(admin_name) - 1)
  332.  
  333.         static authid[35]
  334.         get_user_authid(id, authid, sizeof(authid) - 1)
  335.  
  336.         #if defined USE_COLOR_CHAT
  337.             ColorChat(0, RED, "%L", LANG_PLAYER, "UNGAG_PLAYER", admin_name, authid, data[gag_name], data[gag_steamid], data[gag_reason])
  338.         #else
  339.             NoColorChat(0, "%L", LANG_PLAYER, "UNGAG_PLAYER", admin_name, authid, data[gag_name], data[gag_steamid], data[gag_reason])
  340.         #endif
  341.  
  342.         RemoveGag(array_pos, data[gag_steamid])
  343.  
  344.         return PLUGIN_HANDLED
  345.     }
  346.  
  347.     console_print(id, "%L", id, "NOT_IN_GAG_LIST", arg)
  348.  
  349.     return PLUGIN_HANDLED
  350. }
  351.  
  352. public concmd_gag_list(id, level, cid) {
  353.     if(!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
  354.  
  355.     if(!total_gags) {
  356.         console_print(id, "%L", id, "NO_GAGS")
  357.         return PLUGIN_HANDLED;
  358.     }
  359.  
  360.     static start
  361.     if(read_argc() > 1) {
  362.         static arg[5]
  363.         read_argv(1, arg, sizeof(arg) - 1)
  364.  
  365.         start = min(str_to_num(arg), total_gags) - 1
  366.     }
  367.  
  368.     else start = 0
  369.  
  370.     new last = min(start + 10, total_gags)
  371.  
  372.     if(id == 0) server_cmd("echo ^"%L^"", id, "GAG_LIST_NUM", start + 1, last)
  373.     else console_print(id, "%L", id, "GAG_LIST_NUM", start + 1, last)
  374.  
  375.     for(new i = start; i < last; i++) {
  376.         static data[GagData]
  377.         ArrayGetArray(g_array, i, data)
  378.  
  379.         PrintGagInfosToConsole(id, data[gag_name], data[gag_steamid], data[gag_length], data[gag_reason], data[ungag_time])
  380.     }
  381.  
  382.     if(++last < total_gags) {
  383.         if(id == 0) server_cmd("echo ^"%L^"", id, "GAG_LIST_NEXT", last)
  384.         else console_print(id, "%L", id, "GAG_LIST_NEXT", last)
  385.     }
  386.  
  387.     return PLUGIN_HANDLED
  388. }  
  389.  
  390. public gag_menu(id) {
  391.     if(!(get_user_flags(id) & GAG_FLAG))
  392.         return PLUGIN_HANDLED
  393.  
  394.     new menu_line[64], menu_newline[64], id_data[64]
  395.     format(menu_line, charsmax(menu_line), "\w%L^n%L", id, "GAG_MENU1", id, "GAG_MENU2")
  396.  
  397.     new menu = menu_create(menu_line, "gag_menu_handler")
  398.  
  399.     new players[32], name[32], num
  400.     get_players(players, num, "c")
  401.  
  402.     for(new i = 0; i <num; i++) {
  403.         new pid = players[i]
  404.         get_user_name(pid, name, 31)
  405.         num_to_str(pid, id_data, sizeof(id_data))
  406.  
  407.         format(menu_newline, charsmax(menu_newline), "%s", name)
  408.         menu_additem(menu, menu_newline, id_data, 0)
  409.     }
  410.  
  411.     menu_display(id, menu, 0)
  412.     return PLUGIN_CONTINUE
  413. }
  414.  
  415. public ungag_menu(id) {
  416.     if(!(get_user_flags(id) & GAG_FLAG))
  417.         return PLUGIN_HANDLED
  418.  
  419.     if(!total_gags) {
  420.         #if defined USE_COLOR_CHAT
  421.             ColorChat(id, RED, "%L", id, "NO_GAGS")
  422.         #else
  423.             client_print(id, print_chat, "%L", id, "NO_GAGS")
  424.         #endif
  425.  
  426.         return PLUGIN_HANDLED
  427.     }
  428.  
  429.     new menu_line[99], menu_newline[99]
  430.     format(menu_line, charsmax(menu_line), "\w%L^n%L", id, "GAG_MENU3", id, "GAG_MENU4")
  431.  
  432.     new menu = menu_create(menu_line, "ungag_menu_handler")
  433.  
  434.     for(new i = 0; i < total_gags; i++) {
  435.         static data[GagData]
  436.         ArrayGetArray(g_array, i, data)
  437.  
  438.         format(menu_newline, charsmax(menu_newline), "\r%s \w[%s]", data[gag_steamid], data[gag_reason])
  439.         menu_additem(menu, menu_newline, data[gag_steamid], 0)
  440.     }
  441.  
  442.     menu_display(id, menu, 0)
  443.     return PLUGIN_CONTINUE
  444. }
  445.  
  446. public gag_menu_handler(id, menu, item) {
  447.     if(item == MENU_EXIT) {
  448.         menu_destroy(menu)
  449.         return PLUGIN_HANDLED
  450.     }
  451.  
  452.     new data[64], szName[64]
  453.     new access, callback
  454.     menu_item_getinfo(menu, item, access, data,charsmax(data), szName,charsmax(szName), callback)
  455.  
  456.     tempid[id] = str_to_num(data)
  457.  
  458.     static authid[35]
  459.     get_user_authid(tempid[id], authid, sizeof(authid) - 1)
  460.  
  461.     static ip[35]
  462.     get_user_ip(tempid[id], ip, sizeof(ip) - 1, 1)
  463.     static array_pos   
  464.  
  465.     if(get_user_flags(tempid[id]) & GAG_IMMUNITY) {
  466.         #if defined USE_COLOR_CHAT
  467.             ColorChat(id, RED, "%L", id, "PLAYER_IMMUNITY")
  468.         #else
  469.             NoColorChat(id, "%L", id, "PLAYER_IMMUNITY")
  470.         #endif
  471.  
  472.         gag_menu(id)
  473.  
  474.         return PLUGIN_HANDLED
  475.     }
  476.  
  477.     else if(TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos)) {
  478.         static data[GagData]
  479.         ArrayGetArray(g_array, array_pos, data)
  480.  
  481.         static gag_length2[64]
  482.         new Float:gag_len = float(data[gag_length]) / 60.0
  483.         GetGagTime(id, gag_len, gag_length2, sizeof(gag_length2) - 1)
  484.  
  485.         #if defined USE_COLOR_CHAT
  486.             ColorChat(id, RED, "%L", id, "PLAYER_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  487.         #else
  488.             NoColorChat(id, "%L", id, "PLAYER_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  489.         #endif
  490.  
  491.         return PLUGIN_HANDLED
  492.     }
  493.  
  494.     else {
  495.         #if defined USE_COLOR_CHAT
  496.             ColorChat(id, RED, "%L", id, "TYPE_TIME")
  497.         #else
  498.             NoColorChat(id, "%L", id, "TYPE_TIME")
  499.         #endif
  500.  
  501.         client_cmd(id, "messagemode GAG_TIME")
  502.     }
  503.  
  504.     return PLUGIN_CONTINUE
  505. }
  506.  
  507. public ungag_menu_handler(id, menu, item) {
  508.     if(item == MENU_EXIT) {
  509.         menu_destroy(menu)
  510.         return PLUGIN_HANDLED
  511.     }
  512.  
  513.     new data[64], szName[64]
  514.     new access, callback
  515.     menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback)
  516.  
  517.     client_cmd(id, "ungag ^"%s^"", data)
  518.  
  519.     return PLUGIN_CONTINUE
  520. }
  521.  
  522. public clcmd_time(id) {
  523.     if(!(get_user_flags(id) & GAG_FLAG))
  524.         return PLUGIN_HANDLED
  525.  
  526.     new gag_times[33][100]
  527.     read_args(gag_times[id], 99)
  528.     remove_quotes(gag_times[id])
  529.  
  530.     get_gag_time[id] = str_to_float(gag_times[id])
  531.  
  532.     #if defined USE_COLOR_CHAT
  533.         ColorChat(id, RED, "%L", id, "TYPE_REASON")
  534.     #else
  535.         NoColorChat(id, "%L", id, "TYPE_REASON")
  536.     #endif
  537.  
  538.     client_cmd(id, "messagemode GAG_REASON")
  539.  
  540.     return PLUGIN_HANDLED
  541. }
  542.  
  543. public clcmd_reason(id) {
  544.     if(!(get_user_flags(id) & GAG_FLAG))
  545.         return PLUGIN_HANDLED
  546.  
  547.     new get_gag_reason[33][100]
  548.     read_args(get_gag_reason[id], 99)
  549.     remove_quotes(get_gag_reason[id])
  550.  
  551.     static target_name[32]
  552.     get_user_name(tempid[id], target_name, sizeof(target_name) - 1)
  553.  
  554.     if(is_user_steam(tempid[id])) client_cmd(id, "gag_authid ^"%s^" ^"%f^" ^"%s^"", target_name, get_gag_time[id], get_gag_reason[id])
  555.     else client_cmd(id, "gag_ip ^"%s^" ^"%f^" ^"%s^"", target_name, get_gag_time[id], get_gag_reason[id])
  556.  
  557.     return PLUGIN_HANDLED
  558. }
  559.  
  560. public gag_say(id) {
  561.     static authid[35]
  562.     get_user_authid(id, authid, sizeof(authid) - 1)
  563.  
  564.     static ip[35]
  565.     get_user_ip(id, ip, sizeof(ip) - 1, 1)
  566.  
  567.     static array_pos   
  568.     if(TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos)) {
  569.         static data[GagData]
  570.         ArrayGetArray(g_array, array_pos, data)
  571.  
  572.         static gag_length2[64]
  573.         new Float:gag_len = float(data[gag_length]) / 60.0
  574.         GetGagTime(id, gag_len, gag_length2, sizeof(gag_length2) - 1)
  575.  
  576.         #if defined USE_COLOR_CHAT
  577.             ColorChat(id, RED, "%L", id, "YOU_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  578.         #else
  579.             NoColorChat(id, "%L", id, "YOU_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  580.         #endif
  581.  
  582.         return PLUGIN_HANDLED
  583.     }
  584.  
  585.     return PLUGIN_CONTINUE
  586. }
  587.  
  588. public PrintGagInfosToConsole(index, const target_name[], const target_steamid[], const target_length, const target_reason[], const target_ungag_time[]) {
  589.     static gag_length2[64]
  590.     new bool:is_ip = bool:(containi(target_steamid, ".") != -1)
  591.  
  592.     if(index == 0) {
  593.         server_print("************************************************")
  594.         server_print("%L", index, "GAG_INFORMATION")
  595.         server_print("%L: %s", index, "GAG_NAME", target_name)
  596.         server_print("%L: %s", index, !is_ip ? "GAG_STEAMID" : "GAG_IP", target_steamid)
  597.         server_print("%L: %s", index, "GAG_REASON", target_reason)
  598.         if(target_length > 0) {
  599.             new Float:gag_len = float(target_length) / 60.0
  600.             GetGagTime(index, gag_len, gag_length2, sizeof(gag_length2) - 1)
  601.  
  602.             server_print("%L: %s", index, "GAG_TIME", gag_length2)
  603.         }
  604.         server_print("%L: %s", index, "UNGAG_TIME", target_ungag_time)
  605.         server_print("************************************************")
  606.     }
  607.  
  608.     else {
  609.         console_print(index, "************************************************")
  610.         console_print(index, "%L", index, "GAG_INFORMATION")
  611.         console_print(index, "%L: %s", index, "GAG_NAME", target_name)
  612.         console_print(index, "%L: %s", index, !is_ip ? "GAG_STEAMID" : "GAG_IP", target_steamid)
  613.         console_print(index, "%L: %s", index, "GAG_REASON", target_reason)
  614.         if(target_length > 0) {
  615.             new Float:gag_len = float(target_length) / 60.0
  616.             GetGagTime(index, gag_len, gag_length2, sizeof(gag_length2) - 1)
  617.  
  618.             console_print(index, "%L: %s", index, "GAG_TIME", gag_length2)
  619.         }
  620.         console_print(index, "%L: %s", index, "UNGAG_TIME", target_ungag_time)
  621.         console_print(index, "************************************************")
  622.     }
  623. }
  624.  
  625. public LoadGags() {
  626.     if(total_gags) {
  627.         TrieClear(g_trie)
  628.         ArrayClear(g_array)
  629.         total_gags = 0
  630.     }
  631.  
  632.     if(file_exists(gag_file)) {
  633.         new f = fopen(gag_file, "rt")
  634.         static filedata[512], length[10]
  635.  
  636.         static data[GagData]
  637.         while(!feof(f)){
  638.             fgets(f, filedata, sizeof(filedata) - 1)
  639.  
  640.             if(!filedata[0]) continue
  641.  
  642.             parse(filedata,\
  643.                 data[gag_steamid], sizeof(data[gag_steamid]) - 1,\
  644.                 data[gag_name], sizeof(data[gag_name]) - 1,\
  645.                 length, sizeof(length) - 1,\
  646.                 data[ungag_time], sizeof(data[ungag_time]) - 1,\
  647.                 data[gag_reason], sizeof(data[gag_reason]) - 1
  648.                 )
  649.  
  650.             data[gag_length] = str_to_num(length)
  651.  
  652.             ArrayPushArray(g_array, data)
  653.             TrieSetCell(g_trie, data[gag_steamid], total_gags)
  654.  
  655.             total_gags++
  656.         }
  657.  
  658.         fclose(f)
  659.     }
  660. }
  661.  
  662. public RemoveGag(pos, const authid[]) {
  663.     TrieDeleteKey(g_trie, authid)
  664.     ArrayDeleteItem(g_array, pos)
  665.  
  666.     total_gags--
  667.  
  668.     new f = fopen(gag_file, "wt")
  669.     new data[GagData]
  670.  
  671.     for(new i = 0; i < total_gags; i++ ) {
  672.         ArrayGetArray(g_array, i, data)
  673.         TrieSetCell(g_trie, data[gag_steamid], i)
  674.  
  675.         fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^"^n",\
  676.             data[gag_steamid],\
  677.             data[gag_name],\
  678.             data[gag_length],\
  679.             data[ungag_time],\
  680.             data[gag_reason]
  681.             )
  682.     }
  683.  
  684.     fclose(f)
  685. }
  686.  
  687. public GagAdd(const target_name[], const target_steamid[], const reason[], const length, const ungag_time3[]) {
  688.     new f = fopen(gag_file, "a+")
  689.  
  690.     fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^"^n",\
  691.         target_steamid,\
  692.         target_name,\
  693.         length,\
  694.         ungag_time3,\
  695.         reason
  696.         )
  697.  
  698.     fclose(f)
  699.  
  700.     static data[GagData]
  701.     copy(data[gag_name], sizeof(data[gag_name]) - 1, target_name)
  702.     copy(data[gag_steamid], sizeof(data[gag_steamid]) - 1, target_steamid)
  703.     data[gag_length] = length
  704.     copy(data[ungag_time], sizeof(data[ungag_time]) - 1, ungag_time3)
  705.     copy(data[gag_reason], sizeof(data[gag_reason]) - 1, reason)
  706.  
  707.     TrieSetCell(g_trie, target_steamid, total_gags)
  708.     ArrayPushArray(g_array, data)
  709.  
  710.     total_gags++
  711. }
  712.  
  713. GetGagTime(index, Float:gagtime, length[], len) {
  714.     new minutes = floatround(gagtime, floatround_floor)
  715.     new seconds = floatround(floatfract(gagtime) * 60, floatround_floor)
  716.     new hours = 0
  717.     new days = 0
  718.  
  719.     while(minutes >= 60) {
  720.         minutes -= 60
  721.         hours++
  722.     }
  723.  
  724.     while(hours >= 24) {
  725.         hours -= 24
  726.         days++
  727.     }
  728.  
  729.     new bool:add_before
  730.     if(seconds) {
  731.         formatex(length, len, "%i %L", seconds, index, "GAG_SECONDS")  
  732.         add_before = true
  733.     }
  734.  
  735.     if(minutes) {
  736.         if(add_before) format(length, len, "%i %L, %s", minutes, index, "GAG_MINUTES", length)
  737.  
  738.         else{
  739.             formatex(length, len, "%i %L", minutes, index, "GAG_MINUTES")          
  740.             add_before = true
  741.         }
  742.     }
  743.  
  744.     if(hours) {
  745.         if(add_before) format(length, len, "%i %L, %s", hours, index, "GAG_HOURS", length)
  746.  
  747.         else{
  748.             formatex(length, len, "%i %L", hours, index, "GAG_HOURS")          
  749.             add_before = true
  750.         }
  751.     }
  752.  
  753.     if(days) {
  754.         if(add_before) format(length, len, "%i %L, %s", days, index, "GAG_DAYS", length)
  755.  
  756.         else {
  757.             formatex(length, len, "%i %L", days, index, "GAG_DAYS")        
  758.             add_before = true
  759.         }
  760.     }
  761.  
  762.     if(!add_before) formatex(length, len, "%L", index, "PERMANENT_GAG")
  763. }
  764.  
  765. GetTargetFlags(index) {
  766.     static const flags_no_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS)
  767.     static const flags_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS|CMDTARGET_OBEY_IMMUNITY)
  768.  
  769.     switch(get_pcvar_num(gag_immunity)) {
  770.         case 1: return flags_immunity
  771.         case 2: return access(index, GAG_IMMUNITY) ? flags_no_immunity : flags_immunity
  772.     }
  773.  
  774.     return flags_no_immunity
  775. }
  776.  
  777. GenerateUnGagTime(const Float:input, output[], const len) {
  778.     static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7]
  779.     format_time(_hours, sizeof(_hours) - 1, "%H")
  780.     format_time(_minutes, sizeof(_minutes) - 1, "%M")
  781.     format_time(_seconds, sizeof(_seconds) - 1, "%S")
  782.     format_time(_month, sizeof(_month) - 1, "%m")
  783.     format_time(_day, sizeof(_day) - 1, "%d")
  784.     format_time(_year, sizeof(_year) - 1, "%Y")
  785.  
  786.     new hours = str_to_num(_hours)
  787.     new month = str_to_num(_month)
  788.     new day = str_to_num(_day)
  789.     new year = str_to_num(_year)
  790.  
  791.     new minutes = floatround(input, floatround_floor) + str_to_num(_minutes)
  792.     new seconds = floatround(floatfract(input) * 60, floatround_floor)
  793.  
  794.     while(minutes >= 60) {
  795.         minutes -= 60
  796.         hours++
  797.     }
  798.  
  799.     while(hours >= 24) {
  800.         hours -= 24
  801.         day++
  802.     }
  803.  
  804.     new max_days = GetDaysInMonth(month, year)
  805.     while(day > max_days) {
  806.         day -= max_days
  807.         month++
  808.     }
  809.  
  810.     while(month > 12) {
  811.         month -= 12
  812.         year++
  813.     }
  814.  
  815.     seconds += str_to_num(_seconds)
  816.     if(seconds > 59) {
  817.         seconds -= 60
  818.         if(minutes < 59) minutes++
  819.  
  820.         else {
  821.             minutes = 0
  822.             if(hours < 23) hours++
  823.  
  824.             else {
  825.                 hours = 0
  826.                 if(day < max_days) day++
  827.  
  828.                 else {
  829.                     day = 1
  830.                     if(month < 12) month++
  831.  
  832.                     else {
  833.                         month = 1
  834.                         year++
  835.                     }
  836.                 }
  837.             }
  838.         }
  839.     }  
  840.  
  841.     formatex(output, len, "%i:%02i:%02i %i/%i/%i", hours, minutes, seconds, month, day, year)
  842. }
  843.  
  844. GetDaysInMonth(month, year=0) {
  845.     switch(month) {
  846.         case 1: return 31 // January
  847.         case 2: return ((year % 4) == 0) ? 29 : 28 // February
  848.         case 3: return 31; // March
  849.         case 4: return 30; // April
  850.         case 5: return 31; // May
  851.         case 6: return 30; // June
  852.         case 7: return 31; // July
  853.         case 8: return 31; // August
  854.         case 9: return 30; // September
  855.         case 10: return 31; // October
  856.         case 11: return 30; // November
  857.         case 12: return 31; // December
  858.     }
  859.  
  860.     return 30
  861. }
  862.  
  863. stock NoColorChat(const id, const input[], any:...) {
  864.     new count = 1, players[32], i
  865.     static msg[191]
  866.     vformat(msg, 190, input, 3)
  867.  
  868.     replace_all(msg, 190, "!g", "")
  869.     replace_all(msg, 190, "!n", "")
  870.     replace_all(msg, 190, "!t", "")
  871.  
  872.     if(id)players[0] = id; else get_players(players, count, "ch")
  873.  
  874.     for(i = 0; i < count; i++) {
  875.         if(is_user_connected(players[i])) {
  876.             message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
  877.             write_byte(players[i])
  878.             write_string(msg)
  879.             message_end()
  880.         }
  881.     }
  882. }
  883.  
  884. stock is_user_steam(id) {
  885.         new g_Steam[32]
  886.         get_user_authid(id, g_Steam, charsmax(g_Steam))
  887.  
  888.         return bool:('0' <= g_Steam[8] <= '1')
  889. }

_________________
Global Offensive Mod[5000 ft/ Sql Mentes / 6 Lada / 135 Skin]


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: Amx_gag javítás + bővítés
HozzászólásElküldve: 2016.03.03. 18:19 
Offline
GFX-Designer
Avatar

Csatlakozott: 2015.03.12. 15:06
Hozzászólások: 624
Megköszönt másnak: 199 alkalommal
Megköszönték neki: 78 alkalommal
Pardon írta:
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <engine>
  4.  
  5. #define PLUGIN "ADMIN Gag"
  6. #define VERSION "1.0.1"
  7. #define AUTHOR "RaZzoR"
  8.  
  9. #define GAG_FLAG ADMIN_BAN
  10. #define GAG_IMMUNITY ADMIN_IMMUNITY
  11.  
  12. #define DICTIONARY "admin_gag.txt"
  13. #define USE_COLOR_CHAT
  14.  
  15. #if defined USE_COLOR_CHAT
  16.     #include <colorchat>
  17. #endif
  18.  
  19. new const gag_file_name[] = "gagged_users.txt"
  20.  
  21. enum _:GagData {
  22.     gag_name[32],
  23.     gag_steamid[35],
  24.     gag_length,
  25.     ungag_time[32],
  26.     gag_reason[128]
  27. }
  28.  
  29. new Trie:g_trie
  30. new Array:g_array
  31. new total_gags, g_ungag_entity
  32. new gag_file[64], Float:get_gag_time[33], tempid[33]
  33.  
  34. new gag_immunity, gag_ungagcheck
  35.  
  36. public plugin_init() {
  37.     register_plugin(PLUGIN, VERSION, AUTHOR)
  38.  
  39.     #if defined USE_COLOR_CHAT
  40.         register_dictionary_colored(DICTIONARY)
  41.     #else
  42.         register_dictionary(DICTIONARY)
  43.     #endif
  44.  
  45.     gag_immunity = register_cvar("gag_immunity", "1")
  46.     gag_ungagcheck = register_cvar("gag_ungagcheck", "1.0")
  47.  
  48.     register_clcmd("say /gag_menu", "gag_menu")
  49.     register_clcmd("say /ungag_menu", "ungag_menu")
  50.  
  51.     register_clcmd("say", "gag_say")
  52.     register_clcmd("say_team", "gag_say")  
  53.  
  54.     register_clcmd("GAG_TIME", "clcmd_time")
  55.     register_clcmd("GAG_REASON", "clcmd_reason")
  56.  
  57.     register_concmd("gag_authid", "concmd_gag_authid", GAG_FLAG, "<nev, #userid, authid> <ido percben> <ok>")
  58.     register_concmd("gag_ip", "concmd_gag_ip", GAG_FLAG, "<nev, #userid, authid> <ido percben> <ok>")
  59.     register_concmd("gag_add", "concmd_gag_add", GAG_FLAG, "<nev> <authid vagy ip> <ido percben> <ok>")
  60.     register_concmd("gag_list", "concmd_gag_list", GAG_FLAG, "[start] -- megmutat minden nemitast")
  61.     register_concmd("ungag", "concmd_ungag", GAG_FLAG, "<authid vagy ip>")
  62.  
  63.     get_datadir(gag_file, sizeof(gag_file) - 1)
  64.     format(gag_file, sizeof(gag_file) - 1, "%s/%s", gag_file, gag_file_name)
  65.  
  66.     g_trie = TrieCreate()
  67.     g_array = ArrayCreate(GagData)
  68.  
  69.     LoadGags()
  70. }
  71.  
  72. public plugin_cfg() create_ungag_entity()
  73.  
  74. public client_PostThink(id) {
  75.     static authid[35]
  76.     get_user_authid(id, authid, sizeof(authid) - 1)
  77.  
  78.     static ip[35]
  79.     get_user_ip(id, ip, sizeof(ip) - 1, 1)
  80.  
  81.     static array_pos   
  82.     if(TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos)) set_speak(id, SPEAK_MUTED)
  83.     else set_speak(id, SPEAK_LISTENALL)
  84. }
  85.  
  86. public create_ungag_entity() {
  87.     static failtimes
  88.  
  89.     g_ungag_entity = create_entity("info_target")
  90.  
  91.     if(!is_valid_ent(g_ungag_entity)) {
  92.         ++failtimes
  93.  
  94.         log_amx("%L", LANG_SERVER, "FAILED_TO_CREATE_UNGAG_ENTITY", failtimes)
  95.  
  96.         if(failtimes < 10) set_task(1.0, "create_ungag_entity")
  97.         else log_amx("%L", LANG_SERVER, "COULD_NOT_CREATE_UNGAG_ENTITY")
  98.  
  99.         return
  100.     }
  101.  
  102.     entity_set_string(g_ungag_entity, EV_SZ_classname, "ungag_entity")
  103.     entity_set_float(g_ungag_entity, EV_FL_nextthink, get_gametime() + 1.0)
  104.  
  105.     register_think("ungag_entity", "UnGag_Check")
  106. }
  107.  
  108. public UnGag_Check(entity)
  109. {
  110.     if(entity != g_ungag_entity) return
  111.  
  112.     if(total_gags > 0)
  113.     {
  114.         static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7]
  115.         format_time(_hours, sizeof(_hours) - 1, "%H")
  116.         format_time(_minutes, sizeof(_minutes) - 1, "%M")
  117.         format_time(_seconds, sizeof(_seconds) - 1, "%S")
  118.         format_time(_month, sizeof(_month) - 1, "%m")
  119.         format_time(_day, sizeof(_day) - 1, "%d")
  120.         format_time(_year, sizeof(_year) - 1, "%Y")
  121.  
  122.  
  123.         new c_hours = str_to_num(_hours)
  124.         new c_minutes = str_to_num(_minutes)
  125.         new c_seconds = str_to_num(_seconds)
  126.         new c_month = str_to_num(_month)
  127.         new c_day = str_to_num(_day)
  128.         new c_year = str_to_num(_year)
  129.  
  130.         static load_ungag_time[32]
  131.         static u_hours, u_minutes, u_seconds, u_month, u_day, u_year
  132.  
  133.         for(new i = 0; i < total_gags; i++) {
  134.             static data[GagData]
  135.             ArrayGetArray(g_array, i, data)
  136.  
  137.             if(data[gag_length] == 0) continue
  138.  
  139.             copy(load_ungag_time, sizeof(load_ungag_time) - 1, data[ungag_time])
  140.  
  141.             replace_all(load_ungag_time, sizeof(load_ungag_time) - 1, ":", " ")
  142.             replace_all(load_ungag_time, sizeof(load_ungag_time) - 1, "/", " ")
  143.  
  144.             parse(load_ungag_time,\
  145.                 _hours, sizeof(_hours) - 1,\
  146.                 _minutes, sizeof(_minutes) - 1,\
  147.                 _seconds, sizeof(_seconds) - 1,\
  148.                 _month, sizeof(_month) - 1,\
  149.                 _day, sizeof(_day) - 1,\
  150.                 _year, sizeof(_year) - 1
  151.                 )
  152.  
  153.             u_hours = str_to_num(_hours)
  154.             u_minutes = str_to_num(_minutes)
  155.             u_seconds = str_to_num(_seconds)
  156.             u_month = str_to_num(_month)
  157.             u_day = str_to_num(_day)
  158.             u_year = str_to_num(_year)
  159.  
  160.             if( u_year < c_year
  161.             || u_year == c_year && u_month < c_month
  162.             || u_year == c_year && u_month == c_month && u_day < c_day
  163.             || u_year == c_year && u_month == c_month && u_day == c_day && u_hours < c_hours
  164.             || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes < c_minutes
  165.             || u_year == c_year && u_month == c_month && u_day == c_day && u_hours == c_hours && u_minutes == c_minutes && u_seconds <= c_seconds ) {
  166.                 #if defined USE_COLOR_CHAT
  167.                     ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_EXPIRED", data[gag_name], data[gag_steamid], data[gag_reason])
  168.                 #else
  169.                     NoColorChat(0, "%L", LANG_PLAYER, "GAG_EXPIRED", data[gag_name], data[gag_steamid], data[gag_reason])
  170.                 #endif
  171.  
  172.                 RemoveGag(i, data[gag_steamid])
  173.  
  174.                 i--
  175.             }
  176.         }
  177.     }
  178.  
  179.     entity_set_float(g_ungag_entity, EV_FL_nextthink, get_gametime() + get_pcvar_float(gag_ungagcheck))
  180. }
  181.  
  182. public concmd_gag_authid(id, level, cid) {
  183.     if(!cmd_access(id, level, cid, 4)) return PLUGIN_HANDLED
  184.  
  185.     static arg[128]
  186.     read_argv(1, arg, sizeof(arg) - 1)
  187.  
  188.     new target = cmd_target(id, arg, GetTargetFlags(id))
  189.     if(!target) return PLUGIN_HANDLED
  190.  
  191.     static target_authid[35]
  192.     get_user_authid(target, target_authid, sizeof(target_authid) - 1)
  193.  
  194.     if(TrieKeyExists(g_trie, target_authid)) {
  195.         console_print(id, "%L", id, "ALREADY_GAGGED_STEAMID", target_authid)
  196.         return PLUGIN_HANDLED
  197.     }
  198.  
  199.     read_argv(2, arg, sizeof(arg) - 1)
  200.     new Float:length = str_to_float(arg)
  201.  
  202.     static ungag_time2[64], gag_time2[64]
  203.  
  204.     if(length == 0.0) formatex(ungag_time2, sizeof(ungag_time2) - 1, "%L", id, "PERMANENT_GAG")
  205.     else GenerateUnGagTime(length, ungag_time2, sizeof(ungag_time2) - 1)
  206.  
  207.     read_argv(3, arg, sizeof(arg) - 1)
  208.  
  209.     static admin_name[64], target_name[32]
  210.     get_user_name(id, admin_name, sizeof(admin_name) - 1)
  211.     get_user_name(target, target_name, sizeof(target_name) - 1)
  212.  
  213.     static admin_authid[35]
  214.     get_user_authid(id, admin_authid, sizeof(admin_authid) - 1)
  215.  
  216.     GagAdd(target_name, target_authid, arg, floatround(length * 60.0, floatround_floor), ungag_time2)
  217.  
  218.     GetGagTime(id, length, gag_time2, sizeof(gag_time2) - 1)
  219.  
  220.     #if defined USE_COLOR_CHAT
  221.         ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  222.     #else
  223.         NoColorChat(0, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  224.     #endif
  225.  
  226.     return PLUGIN_HANDLED
  227. }
  228.  
  229. public concmd_gag_ip(id, level, cid) {
  230.     if(!cmd_access(id, level, cid, 4)) return PLUGIN_HANDLED
  231.  
  232.     static arg[128]
  233.     read_argv(1, arg, sizeof(arg) - 1)
  234.  
  235.     new target = cmd_target(id, arg, GetTargetFlags(id))
  236.     if(!target) return PLUGIN_HANDLED
  237.  
  238.     static target_ip[35]
  239.     get_user_ip(target, target_ip, sizeof(target_ip) - 1, 1)
  240.  
  241.     if(TrieKeyExists(g_trie, target_ip)) {
  242.         console_print(id, "%L", id, "ALREADY_GAGGED_IP", target_ip)
  243.         return PLUGIN_HANDLED
  244.     }
  245.  
  246.     read_argv(2, arg, sizeof(arg) - 1)
  247.     new Float:length = str_to_float(arg)
  248.  
  249.     static ungag_time2[64], gag_time2[64]
  250.  
  251.     if(length == 0.0) formatex(ungag_time2, sizeof(ungag_time2) - 1, "%L", id, "PERMANENT_GAG")
  252.     else GenerateUnGagTime(length, ungag_time2, sizeof(ungag_time2) - 1)
  253.  
  254.     read_argv(3, arg, sizeof(arg) - 1)
  255.  
  256.     static admin_name[64], target_name[32]
  257.     get_user_name(id, admin_name, sizeof(admin_name) - 1)
  258.     get_user_name(target, target_name, sizeof(target_name) - 1)
  259.  
  260.     static admin_authid[35]
  261.     get_user_authid(id, admin_authid, sizeof(admin_authid) - 1)
  262.  
  263.     GagAdd(target_name, target_ip, arg, floatround(length * 60.0, floatround_floor), ungag_time2)
  264.  
  265.     GetGagTime(id, length, gag_time2, sizeof(gag_time2) - 1)
  266.  
  267.     #if defined USE_COLOR_CHAT
  268.         ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  269.     #else
  270.         NoColorChat(0, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, arg, gag_time2, ungag_time2)
  271.     #endif
  272.  
  273.     return PLUGIN_HANDLED
  274. }
  275.  
  276. public concmd_gag_add(id, level, cid) {
  277.     if(!cmd_access(id, level, cid, 5)) return PLUGIN_HANDLED
  278.  
  279.     static target_name[128], target_authid[128], gagtime[128], reason[128]
  280.     read_argv(1, target_name, sizeof(target_name) - 1)
  281.     read_argv(2, target_authid, sizeof(target_authid) - 1)
  282.     read_argv(3, gagtime, sizeof(gagtime) - 1)
  283.     read_argv(4, reason, sizeof(reason) - 1)
  284.  
  285.     new bool:is_ip = bool:(containi(target_authid, ".") != -1)
  286.  
  287.     if(TrieKeyExists(g_trie, target_authid)) {
  288.         console_print(id, "%L", id, is_ip ? "ALREADY_GAGGED_IP" : "ALREADY_GAGGED_STEAMID", target_authid)
  289.         return PLUGIN_HANDLED
  290.     }
  291.  
  292.     new Float:length = str_to_float(gagtime)
  293.     static ungag_time2[64], gag_time2[64]
  294.  
  295.     if(length == 0.0) formatex(ungag_time2, sizeof(ungag_time2) - 1, "%L", id, "PERMANENT_GAG")
  296.     else GenerateUnGagTime(length, ungag_time2, sizeof(ungag_time2) - 1)
  297.  
  298.     static admin_name[64]
  299.     get_user_name(id, admin_name, sizeof(admin_name) - 1)
  300.  
  301.     static admin_authid[35]
  302.     get_user_authid(id, admin_authid, sizeof(admin_authid) - 1)
  303.  
  304.     GagAdd(target_name, target_authid, reason, floatround(length * 60.0, floatround_floor), ungag_time2)
  305.  
  306.     GetGagTime(id, length, gag_time2, sizeof(gag_time2) - 1)
  307.  
  308.     #if defined USE_COLOR_CHAT
  309.         ColorChat(0, RED, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, reason, gag_time2, ungag_time2)
  310.     #else
  311.         NoColorChat(0, "%L", LANG_PLAYER, "GAG_PLAYER", admin_name, admin_authid, target_name, reason, gag_time2, ungag_time2)
  312.     #endif
  313.  
  314.     return PLUGIN_HANDLED
  315. }  
  316.  
  317. public concmd_ungag(id, level, cid) {
  318.     if(!cmd_access(id, level, cid, 2)) return PLUGIN_HANDLED
  319.  
  320.     static arg[35]
  321.     read_argv(1, arg, sizeof(arg) - 1)
  322.  
  323.     if(TrieKeyExists(g_trie, arg)) {
  324.         static array_pos;
  325.         TrieGetCell(g_trie, arg, array_pos);
  326.  
  327.         static data[GagData]
  328.         ArrayGetArray(g_array, array_pos, data)
  329.  
  330.         static admin_name[64]
  331.         get_user_name(id, admin_name, sizeof(admin_name) - 1)
  332.  
  333.         static authid[35]
  334.         get_user_authid(id, authid, sizeof(authid) - 1)
  335.  
  336.         #if defined USE_COLOR_CHAT
  337.             ColorChat(0, RED, "%L", LANG_PLAYER, "UNGAG_PLAYER", admin_name, authid, data[gag_name], data[gag_steamid], data[gag_reason])
  338.         #else
  339.             NoColorChat(0, "%L", LANG_PLAYER, "UNGAG_PLAYER", admin_name, authid, data[gag_name], data[gag_steamid], data[gag_reason])
  340.         #endif
  341.  
  342.         RemoveGag(array_pos, data[gag_steamid])
  343.  
  344.         return PLUGIN_HANDLED
  345.     }
  346.  
  347.     console_print(id, "%L", id, "NOT_IN_GAG_LIST", arg)
  348.  
  349.     return PLUGIN_HANDLED
  350. }
  351.  
  352. public concmd_gag_list(id, level, cid) {
  353.     if(!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
  354.  
  355.     if(!total_gags) {
  356.         console_print(id, "%L", id, "NO_GAGS")
  357.         return PLUGIN_HANDLED;
  358.     }
  359.  
  360.     static start
  361.     if(read_argc() > 1) {
  362.         static arg[5]
  363.         read_argv(1, arg, sizeof(arg) - 1)
  364.  
  365.         start = min(str_to_num(arg), total_gags) - 1
  366.     }
  367.  
  368.     else start = 0
  369.  
  370.     new last = min(start + 10, total_gags)
  371.  
  372.     if(id == 0) server_cmd("echo ^"%L^"", id, "GAG_LIST_NUM", start + 1, last)
  373.     else console_print(id, "%L", id, "GAG_LIST_NUM", start + 1, last)
  374.  
  375.     for(new i = start; i < last; i++) {
  376.         static data[GagData]
  377.         ArrayGetArray(g_array, i, data)
  378.  
  379.         PrintGagInfosToConsole(id, data[gag_name], data[gag_steamid], data[gag_length], data[gag_reason], data[ungag_time])
  380.     }
  381.  
  382.     if(++last < total_gags) {
  383.         if(id == 0) server_cmd("echo ^"%L^"", id, "GAG_LIST_NEXT", last)
  384.         else console_print(id, "%L", id, "GAG_LIST_NEXT", last)
  385.     }
  386.  
  387.     return PLUGIN_HANDLED
  388. }  
  389.  
  390. public gag_menu(id) {
  391.     if(!(get_user_flags(id) & GAG_FLAG))
  392.         return PLUGIN_HANDLED
  393.  
  394.     new menu_line[64], menu_newline[64], id_data[64]
  395.     format(menu_line, charsmax(menu_line), "\w%L^n%L", id, "GAG_MENU1", id, "GAG_MENU2")
  396.  
  397.     new menu = menu_create(menu_line, "gag_menu_handler")
  398.  
  399.     new players[32], name[32], num
  400.     get_players(players, num, "c")
  401.  
  402.     for(new i = 0; i <num; i++) {
  403.         new pid = players[i]
  404.         get_user_name(pid, name, 31)
  405.         num_to_str(pid, id_data, sizeof(id_data))
  406.  
  407.         format(menu_newline, charsmax(menu_newline), "%s", name)
  408.         menu_additem(menu, menu_newline, id_data, 0)
  409.     }
  410.  
  411.     menu_display(id, menu, 0)
  412.     return PLUGIN_CONTINUE
  413. }
  414.  
  415. public ungag_menu(id) {
  416.     if(!(get_user_flags(id) & GAG_FLAG))
  417.         return PLUGIN_HANDLED
  418.  
  419.     if(!total_gags) {
  420.         #if defined USE_COLOR_CHAT
  421.             ColorChat(id, RED, "%L", id, "NO_GAGS")
  422.         #else
  423.             client_print(id, print_chat, "%L", id, "NO_GAGS")
  424.         #endif
  425.  
  426.         return PLUGIN_HANDLED
  427.     }
  428.  
  429.     new menu_line[99], menu_newline[99]
  430.     format(menu_line, charsmax(menu_line), "\w%L^n%L", id, "GAG_MENU3", id, "GAG_MENU4")
  431.  
  432.     new menu = menu_create(menu_line, "ungag_menu_handler")
  433.  
  434.     for(new i = 0; i < total_gags; i++) {
  435.         static data[GagData]
  436.         ArrayGetArray(g_array, i, data)
  437.  
  438.         format(menu_newline, charsmax(menu_newline), "\r%s \w[%s]", data[gag_steamid], data[gag_reason])
  439.         menu_additem(menu, menu_newline, data[gag_steamid], 0)
  440.     }
  441.  
  442.     menu_display(id, menu, 0)
  443.     return PLUGIN_CONTINUE
  444. }
  445.  
  446. public gag_menu_handler(id, menu, item) {
  447.     if(item == MENU_EXIT) {
  448.         menu_destroy(menu)
  449.         return PLUGIN_HANDLED
  450.     }
  451.  
  452.     new data[64], szName[64]
  453.     new access, callback
  454.     menu_item_getinfo(menu, item, access, data,charsmax(data), szName,charsmax(szName), callback)
  455.  
  456.     tempid[id] = str_to_num(data)
  457.  
  458.     static authid[35]
  459.     get_user_authid(tempid[id], authid, sizeof(authid) - 1)
  460.  
  461.     static ip[35]
  462.     get_user_ip(tempid[id], ip, sizeof(ip) - 1, 1)
  463.     static array_pos   
  464.  
  465.     if(get_user_flags(tempid[id]) & GAG_IMMUNITY) {
  466.         #if defined USE_COLOR_CHAT
  467.             ColorChat(id, RED, "%L", id, "PLAYER_IMMUNITY")
  468.         #else
  469.             NoColorChat(id, "%L", id, "PLAYER_IMMUNITY")
  470.         #endif
  471.  
  472.         gag_menu(id)
  473.  
  474.         return PLUGIN_HANDLED
  475.     }
  476.  
  477.     else if(TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos)) {
  478.         static data[GagData]
  479.         ArrayGetArray(g_array, array_pos, data)
  480.  
  481.         static gag_length2[64]
  482.         new Float:gag_len = float(data[gag_length]) / 60.0
  483.         GetGagTime(id, gag_len, gag_length2, sizeof(gag_length2) - 1)
  484.  
  485.         #if defined USE_COLOR_CHAT
  486.             ColorChat(id, RED, "%L", id, "PLAYER_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  487.         #else
  488.             NoColorChat(id, "%L", id, "PLAYER_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  489.         #endif
  490.  
  491.         return PLUGIN_HANDLED
  492.     }
  493.  
  494.     else {
  495.         #if defined USE_COLOR_CHAT
  496.             ColorChat(id, RED, "%L", id, "TYPE_TIME")
  497.         #else
  498.             NoColorChat(id, "%L", id, "TYPE_TIME")
  499.         #endif
  500.  
  501.         client_cmd(id, "messagemode GAG_TIME")
  502.     }
  503.  
  504.     return PLUGIN_CONTINUE
  505. }
  506.  
  507. public ungag_menu_handler(id, menu, item) {
  508.     if(item == MENU_EXIT) {
  509.         menu_destroy(menu)
  510.         return PLUGIN_HANDLED
  511.     }
  512.  
  513.     new data[64], szName[64]
  514.     new access, callback
  515.     menu_item_getinfo(menu, item, access, data, charsmax(data), szName, charsmax(szName), callback)
  516.  
  517.     client_cmd(id, "ungag ^"%s^"", data)
  518.  
  519.     return PLUGIN_CONTINUE
  520. }
  521.  
  522. public clcmd_time(id) {
  523.     if(!(get_user_flags(id) & GAG_FLAG))
  524.         return PLUGIN_HANDLED
  525.  
  526.     new gag_times[33][100]
  527.     read_args(gag_times[id], 99)
  528.     remove_quotes(gag_times[id])
  529.  
  530.     get_gag_time[id] = str_to_float(gag_times[id])
  531.  
  532.     #if defined USE_COLOR_CHAT
  533.         ColorChat(id, RED, "%L", id, "TYPE_REASON")
  534.     #else
  535.         NoColorChat(id, "%L", id, "TYPE_REASON")
  536.     #endif
  537.  
  538.     client_cmd(id, "messagemode GAG_REASON")
  539.  
  540.     return PLUGIN_HANDLED
  541. }
  542.  
  543. public clcmd_reason(id) {
  544.     if(!(get_user_flags(id) & GAG_FLAG))
  545.         return PLUGIN_HANDLED
  546.  
  547.     new get_gag_reason[33][100]
  548.     read_args(get_gag_reason[id], 99)
  549.     remove_quotes(get_gag_reason[id])
  550.  
  551.     static target_name[32]
  552.     get_user_name(tempid[id], target_name, sizeof(target_name) - 1)
  553.  
  554.     if(is_user_steam(tempid[id])) client_cmd(id, "gag_authid ^"%s^" ^"%f^" ^"%s^"", target_name, get_gag_time[id], get_gag_reason[id])
  555.     else client_cmd(id, "gag_ip ^"%s^" ^"%f^" ^"%s^"", target_name, get_gag_time[id], get_gag_reason[id])
  556.  
  557.     return PLUGIN_HANDLED
  558. }
  559.  
  560. public gag_say(id) {
  561.     static authid[35]
  562.     get_user_authid(id, authid, sizeof(authid) - 1)
  563.  
  564.     static ip[35]
  565.     get_user_ip(id, ip, sizeof(ip) - 1, 1)
  566.  
  567.     static array_pos   
  568.     if(TrieGetCell(g_trie, authid, array_pos) || TrieGetCell(g_trie, ip, array_pos)) {
  569.         static data[GagData]
  570.         ArrayGetArray(g_array, array_pos, data)
  571.  
  572.         static gag_length2[64]
  573.         new Float:gag_len = float(data[gag_length]) / 60.0
  574.         GetGagTime(id, gag_len, gag_length2, sizeof(gag_length2) - 1)
  575.  
  576.         #if defined USE_COLOR_CHAT
  577.             ColorChat(id, RED, "%L", id, "YOU_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  578.         #else
  579.             NoColorChat(id, "%L", id, "YOU_GAGGED", data[gag_reason], gag_length2, data[ungag_time])
  580.         #endif
  581.  
  582.         return PLUGIN_HANDLED
  583.     }
  584.  
  585.     return PLUGIN_CONTINUE
  586. }
  587.  
  588. public PrintGagInfosToConsole(index, const target_name[], const target_steamid[], const target_length, const target_reason[], const target_ungag_time[]) {
  589.     static gag_length2[64]
  590.     new bool:is_ip = bool:(containi(target_steamid, ".") != -1)
  591.  
  592.     if(index == 0) {
  593.         server_print("************************************************")
  594.         server_print("%L", index, "GAG_INFORMATION")
  595.         server_print("%L: %s", index, "GAG_NAME", target_name)
  596.         server_print("%L: %s", index, !is_ip ? "GAG_STEAMID" : "GAG_IP", target_steamid)
  597.         server_print("%L: %s", index, "GAG_REASON", target_reason)
  598.         if(target_length > 0) {
  599.             new Float:gag_len = float(target_length) / 60.0
  600.             GetGagTime(index, gag_len, gag_length2, sizeof(gag_length2) - 1)
  601.  
  602.             server_print("%L: %s", index, "GAG_TIME", gag_length2)
  603.         }
  604.         server_print("%L: %s", index, "UNGAG_TIME", target_ungag_time)
  605.         server_print("************************************************")
  606.     }
  607.  
  608.     else {
  609.         console_print(index, "************************************************")
  610.         console_print(index, "%L", index, "GAG_INFORMATION")
  611.         console_print(index, "%L: %s", index, "GAG_NAME", target_name)
  612.         console_print(index, "%L: %s", index, !is_ip ? "GAG_STEAMID" : "GAG_IP", target_steamid)
  613.         console_print(index, "%L: %s", index, "GAG_REASON", target_reason)
  614.         if(target_length > 0) {
  615.             new Float:gag_len = float(target_length) / 60.0
  616.             GetGagTime(index, gag_len, gag_length2, sizeof(gag_length2) - 1)
  617.  
  618.             console_print(index, "%L: %s", index, "GAG_TIME", gag_length2)
  619.         }
  620.         console_print(index, "%L: %s", index, "UNGAG_TIME", target_ungag_time)
  621.         console_print(index, "************************************************")
  622.     }
  623. }
  624.  
  625. public LoadGags() {
  626.     if(total_gags) {
  627.         TrieClear(g_trie)
  628.         ArrayClear(g_array)
  629.         total_gags = 0
  630.     }
  631.  
  632.     if(file_exists(gag_file)) {
  633.         new f = fopen(gag_file, "rt")
  634.         static filedata[512], length[10]
  635.  
  636.         static data[GagData]
  637.         while(!feof(f)){
  638.             fgets(f, filedata, sizeof(filedata) - 1)
  639.  
  640.             if(!filedata[0]) continue
  641.  
  642.             parse(filedata,\
  643.                 data[gag_steamid], sizeof(data[gag_steamid]) - 1,\
  644.                 data[gag_name], sizeof(data[gag_name]) - 1,\
  645.                 length, sizeof(length) - 1,\
  646.                 data[ungag_time], sizeof(data[ungag_time]) - 1,\
  647.                 data[gag_reason], sizeof(data[gag_reason]) - 1
  648.                 )
  649.  
  650.             data[gag_length] = str_to_num(length)
  651.  
  652.             ArrayPushArray(g_array, data)
  653.             TrieSetCell(g_trie, data[gag_steamid], total_gags)
  654.  
  655.             total_gags++
  656.         }
  657.  
  658.         fclose(f)
  659.     }
  660. }
  661.  
  662. public RemoveGag(pos, const authid[]) {
  663.     TrieDeleteKey(g_trie, authid)
  664.     ArrayDeleteItem(g_array, pos)
  665.  
  666.     total_gags--
  667.  
  668.     new f = fopen(gag_file, "wt")
  669.     new data[GagData]
  670.  
  671.     for(new i = 0; i < total_gags; i++ ) {
  672.         ArrayGetArray(g_array, i, data)
  673.         TrieSetCell(g_trie, data[gag_steamid], i)
  674.  
  675.         fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^"^n",\
  676.             data[gag_steamid],\
  677.             data[gag_name],\
  678.             data[gag_length],\
  679.             data[ungag_time],\
  680.             data[gag_reason]
  681.             )
  682.     }
  683.  
  684.     fclose(f)
  685. }
  686.  
  687. public GagAdd(const target_name[], const target_steamid[], const reason[], const length, const ungag_time3[]) {
  688.     new f = fopen(gag_file, "a+")
  689.  
  690.     fprintf(f, "^"%s^" ^"%s^" %i ^"%s^" ^"%s^"^n",\
  691.         target_steamid,\
  692.         target_name,\
  693.         length,\
  694.         ungag_time3,\
  695.         reason
  696.         )
  697.  
  698.     fclose(f)
  699.  
  700.     static data[GagData]
  701.     copy(data[gag_name], sizeof(data[gag_name]) - 1, target_name)
  702.     copy(data[gag_steamid], sizeof(data[gag_steamid]) - 1, target_steamid)
  703.     data[gag_length] = length
  704.     copy(data[ungag_time], sizeof(data[ungag_time]) - 1, ungag_time3)
  705.     copy(data[gag_reason], sizeof(data[gag_reason]) - 1, reason)
  706.  
  707.     TrieSetCell(g_trie, target_steamid, total_gags)
  708.     ArrayPushArray(g_array, data)
  709.  
  710.     total_gags++
  711. }
  712.  
  713. GetGagTime(index, Float:gagtime, length[], len) {
  714.     new minutes = floatround(gagtime, floatround_floor)
  715.     new seconds = floatround(floatfract(gagtime) * 60, floatround_floor)
  716.     new hours = 0
  717.     new days = 0
  718.  
  719.     while(minutes >= 60) {
  720.         minutes -= 60
  721.         hours++
  722.     }
  723.  
  724.     while(hours >= 24) {
  725.         hours -= 24
  726.         days++
  727.     }
  728.  
  729.     new bool:add_before
  730.     if(seconds) {
  731.         formatex(length, len, "%i %L", seconds, index, "GAG_SECONDS")  
  732.         add_before = true
  733.     }
  734.  
  735.     if(minutes) {
  736.         if(add_before) format(length, len, "%i %L, %s", minutes, index, "GAG_MINUTES", length)
  737.  
  738.         else{
  739.             formatex(length, len, "%i %L", minutes, index, "GAG_MINUTES")          
  740.             add_before = true
  741.         }
  742.     }
  743.  
  744.     if(hours) {
  745.         if(add_before) format(length, len, "%i %L, %s", hours, index, "GAG_HOURS", length)
  746.  
  747.         else{
  748.             formatex(length, len, "%i %L", hours, index, "GAG_HOURS")          
  749.             add_before = true
  750.         }
  751.     }
  752.  
  753.     if(days) {
  754.         if(add_before) format(length, len, "%i %L, %s", days, index, "GAG_DAYS", length)
  755.  
  756.         else {
  757.             formatex(length, len, "%i %L", days, index, "GAG_DAYS")        
  758.             add_before = true
  759.         }
  760.     }
  761.  
  762.     if(!add_before) formatex(length, len, "%L", index, "PERMANENT_GAG")
  763. }
  764.  
  765. GetTargetFlags(index) {
  766.     static const flags_no_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS)
  767.     static const flags_immunity = (CMDTARGET_ALLOW_SELF|CMDTARGET_NO_BOTS|CMDTARGET_OBEY_IMMUNITY)
  768.  
  769.     switch(get_pcvar_num(gag_immunity)) {
  770.         case 1: return flags_immunity
  771.         case 2: return access(index, GAG_IMMUNITY) ? flags_no_immunity : flags_immunity
  772.     }
  773.  
  774.     return flags_no_immunity
  775. }
  776.  
  777. GenerateUnGagTime(const Float:input, output[], const len) {
  778.     static _hours[5], _minutes[5], _seconds[5], _month[5], _day[5], _year[7]
  779.     format_time(_hours, sizeof(_hours) - 1, "%H")
  780.     format_time(_minutes, sizeof(_minutes) - 1, "%M")
  781.     format_time(_seconds, sizeof(_seconds) - 1, "%S")
  782.     format_time(_month, sizeof(_month) - 1, "%m")
  783.     format_time(_day, sizeof(_day) - 1, "%d")
  784.     format_time(_year, sizeof(_year) - 1, "%Y")
  785.  
  786.     new hours = str_to_num(_hours)
  787.     new month = str_to_num(_month)
  788.     new day = str_to_num(_day)
  789.     new year = str_to_num(_year)
  790.  
  791.     new minutes = floatround(input, floatround_floor) + str_to_num(_minutes)
  792.     new seconds = floatround(floatfract(input) * 60, floatround_floor)
  793.  
  794.     while(minutes >= 60) {
  795.         minutes -= 60
  796.         hours++
  797.     }
  798.  
  799.     while(hours >= 24) {
  800.         hours -= 24
  801.         day++
  802.     }
  803.  
  804.     new max_days = GetDaysInMonth(month, year)
  805.     while(day > max_days) {
  806.         day -= max_days
  807.         month++
  808.     }
  809.  
  810.     while(month > 12) {
  811.         month -= 12
  812.         year++
  813.     }
  814.  
  815.     seconds += str_to_num(_seconds)
  816.     if(seconds > 59) {
  817.         seconds -= 60
  818.         if(minutes < 59) minutes++
  819.  
  820.         else {
  821.             minutes = 0
  822.             if(hours < 23) hours++
  823.  
  824.             else {
  825.                 hours = 0
  826.                 if(day < max_days) day++
  827.  
  828.                 else {
  829.                     day = 1
  830.                     if(month < 12) month++
  831.  
  832.                     else {
  833.                         month = 1
  834.                         year++
  835.                     }
  836.                 }
  837.             }
  838.         }
  839.     }  
  840.  
  841.     formatex(output, len, "%i:%02i:%02i %i/%i/%i", hours, minutes, seconds, month, day, year)
  842. }
  843.  
  844. GetDaysInMonth(month, year=0) {
  845.     switch(month) {
  846.         case 1: return 31 // January
  847.         case 2: return ((year % 4) == 0) ? 29 : 28 // February
  848.         case 3: return 31; // March
  849.         case 4: return 30; // April
  850.         case 5: return 31; // May
  851.         case 6: return 30; // June
  852.         case 7: return 31; // July
  853.         case 8: return 31; // August
  854.         case 9: return 30; // September
  855.         case 10: return 31; // October
  856.         case 11: return 30; // November
  857.         case 12: return 31; // December
  858.     }
  859.  
  860.     return 30
  861. }
  862.  
  863. stock NoColorChat(const id, const input[], any:...) {
  864.     new count = 1, players[32], i
  865.     static msg[191]
  866.     vformat(msg, 190, input, 3)
  867.  
  868.     replace_all(msg, 190, "!g", "")
  869.     replace_all(msg, 190, "!n", "")
  870.     replace_all(msg, 190, "!t", "")
  871.  
  872.     if(id)players[0] = id; else get_players(players, count, "ch")
  873.  
  874.     for(i = 0; i < count; i++) {
  875.         if(is_user_connected(players[i])) {
  876.             message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
  877.             write_byte(players[i])
  878.             write_string(msg)
  879.             message_end()
  880.         }
  881.     }
  882. }
  883.  
  884. stock is_user_steam(id) {
  885.         new g_Steam[32]
  886.         get_user_authid(id, g_Steam, charsmax(g_Steam))
  887.  
  888.         return bool:('0' <= g_Steam[8] <= '1')
  889. }


Köszi, de nem ez kell :?

_________________
„Nem azért felejtünk el játszani, mert megöregszünk, hanem attól öregszünk meg, hogy elfelejtünk játszani.”

-MAXHACKED Website-
-HERViD Website-
► Spoiler mutatása


Hozzászólás jelentése
Vissza a tetejére
   
Hozzászólások megjelenítése:  Rendezés  
Új téma nyitása  Hozzászólás a témához  [ 3 hozzászólás ] 


Ki van itt

Jelenlévő fórumozók: nincs regisztrált felhasználó valamint 41 vendég


Nyithatsz új témákat ebben a fórumban.
Válaszolhatsz egy témára ebben a fórumban.
Nem szerkesztheted a hozzászólásaidat ebben a fórumban.
Nem törölheted a hozzászólásaidat ebben a fórumban.
Nem küldhetsz csatolmányokat ebben a fórumban.

Keresés:
Ugrás:  
Powered by phpBB® Forum Software © phpBB Limited
Magyar fordítás © Magyar phpBB Közösség
Portal: Kiss Portal Extension © Michael O'Toole