Thread: Edit a plugin
View Single Post
Author Message
Mikaeel123
Senior Member
Join Date: Oct 2018
Old 12-06-2018 , 10:32   Edit a plugin
Reply With Quote #1

Hi all This plugin have bug . players can use /g . im want block acc for players . and admins say /g players can gag all
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < engine >
#include < sqlx >

#define MAX_PLAYERS 32
#define MAX_PATTERN_LEN 255

enum ( <<= )
{
    
GAG_CHAT 1,
    
GAG_TEAMSAY,
    
GAG_VOICE
};

enum _:GagData
{
    
GAG_AUTHID35 ],
    
GAG_TIME,
    
GAG_START,
    
GAG_FLAGS
};

enum _:TimeUnit
{
    
TIMEUNIT_SECONDS 0,
    
TIMEUNIT_MINUTES,
    
TIMEUNIT_HOURS,
    
TIMEUNIT_DAYS,
    
TIMEUNIT_WEEKS
};

new const 
g_szTimeUnitNameTimeUnit ][ ][ ] =
{
    { 
"second""seconds" },
    { 
"minute""minutes" },
    { 
"hour",   "hours"   },
    { 
"day",    "days"    },
    { 
"week",   "weeks"   }
};

new const 
g_iTimeUnitMultTimeUnit ] =
{
    
1,
    
60,
    
3600,
    
86400,
    
604800
};

new const 
DATETIME_FORMAT[ ] = "%Y-%m-%d %H:%M:%S";
const 
DATE_SIZE 20;

new Array:
g_aGagTimes;
new Array:
g_aGagData;
new 
Trie:g_tArrayPos;
new 
Trie:g_tTimeUnitWords;

new 
g_iGagged;
new 
g_iThinker;
new 
g_iTotalGagTimes;
new 
g_iMsgSayText;

new 
g_szAuthidMAX_PLAYERS ][ 35 ];
new 
g_iMenuOptionMAX_PLAYERS ];
new 
g_iMenuPositionMAX_PLAYERS ];
new 
g_iMenuPlayersMAX_PLAYERS ][ 32 ];
new 
g_iMenuFlagsMAX_PLAYERS ];

new 
g_szGagFile64 ];

new 
bool:g_bColorSupported;

new 
g_pCvarDefaultFlags;
new 
g_pCvarDefaultTime;
new 
g_pCvarTimeUnit;
new 
g_pCvarMaxTime;
new 
g_pCvarSQL;
new 
g_pCvarSQLHost;
new 
g_pCvarSQLUser;
new 
g_pCvarSQLPass;
new 
g_pCvarSQLDb;

new 
bool:g_bUsingSQL false;
new 
Handle:g_hSqlTuple;

public 
plugin_init( )
{
    
register_plugin"AMXX Gag""1.4.9""xPaw & Exolent" );
    
    
register_clcmd"say",        "CmdSay" );
    
register_clcmd"say_team",   "CmdTeamSay" );
    
    
register_concmd"amx_gag",       "CmdGagPlayer",   ADMIN_KICK"<nick or #userid> <time> <a|b|c> -- Use 0 time for permanent" );
    
register_concmd"amx_addgag",    "CmdAddGag",      ADMIN_KICK"<authid> <time> <a|b|c> -- Use 0 time for permanent" );
    
register_concmd"amx_ungag",     "CmdUnGagPlayer"ADMIN_KICK"<nick or #userid>" );
    
register_concmd"amx_gagmenu",   "CmdGagMenu",     ADMIN_KICK"- displays gag menu" );
    
register_srvcmd"amx_gag_times""CmdSetBanTimes" );
    
    
register_menu"Gag Menu"1023"ActionGagMenu" );
    
register_menu"Gag Flags"1023"ActionGagFlags" );
    
register_messageget_user_msgid"SayText" ), "MessageSayText" );
    
    
g_pCvarDefaultFlags register_cvar"amx_gag_default_flags""abc"   );
    
g_pCvarDefaultTime  register_cvar"amx_gag_default_time",  "600"   );
    
g_pCvarTimeUnit     register_cvar"amx_gag_time_units",    "0"     );
    
g_pCvarMaxTime      register_cvar"amx_gag_max_time",      "86400" );
    
g_pCvarSQL          register_cvar"amx_gag_sql",           "0"     );
    
g_pCvarSQLHost      register_cvar"amx_gag_sql_host",      ""      );
    
g_pCvarSQLUser      register_cvar"amx_gag_sql_user",      ""      );
    
g_pCvarSQLPass      register_cvar"amx_gag_sql_pass",      ""      );
    
g_pCvarSQLDb        register_cvar"amx_gag_sql_db",        ""      );
    
    
g_tArrayPos       TrieCreate( );
    
g_aGagTimes       ArrayCreate( );
    
g_aGagData        ArrayCreateGagData );
    
g_bColorSupported bool:colored_menus( );
    
g_iMsgSayText     get_user_msgid"SayText" );
    
    
// let words work with the time unit cvar
    
g_tTimeUnitWords TrieCreate( );
    
    for( new 
0TimeUniti++ )
    {
        
TrieSetCellg_tTimeUnitWordsg_szTimeUnitName][ ], );
        
TrieSetCellg_tTimeUnitWordsg_szTimeUnitName][ ], );
    }
    
    
// this is used for ungag in the menu
    
ArrayPushCellg_aGagTimes);
    
    
// Gag times for the gag menu (amx_gagmenu)
    // Default values: 60 300 600 1800 3600 7200 86400
    
new const iDefaultTimes[ ] = { 6030060018003600720086400};
    
    
// Load up standart times
    
for( new 0sizeofiDefaultTimes ); i++ )
    {
        
ArrayPushCellg_aGagTimesiDefaultTimes] );
    }
    
    
g_iTotalGagTimes sizeofiDefaultTimes ) + 1;
    
    
// Set up entity-thinker
    
new const szClassName[ ] = "gag_thinker";
    
    
g_iThinker create_entity"info_target" );
    
entity_set_stringg_iThinkerEV_SZ_classnameszClassName );
    
    
register_thinkszClassName"FwdThink" );
    
    
// load gags from file
    
get_datadirg_szGagFilecharsmaxg_szGagFile ) );
    
addg_szGagFilecharsmaxg_szGagFile ), "/gags.txt" );
    
    
// set server's SteamID to "SERVER"
    
copyg_szAuthid], charsmaxg_szAuthid[ ] ), "SERVER" );
}

public 
plugin_cfg( )
{
    
// check SQL
    
InitSQL( );
    
    if( !
g_bUsingSQL )
    {
        
// if no SQL, load file
        
LoadFromFile( );
    }
}

InitSQL( )
{
    
// init SQL after configs were executed
    
if( get_pcvar_numg_pCvarSQL ) )
    {
        new 
szHost64 ], szUser64 ], szPass64 ], szDb64 ];
        
get_pcvar_stringg_pCvarSQLHostszHostcharsmaxszHost ) );
        
get_pcvar_stringg_pCvarSQLUserszUsercharsmaxszUser ) );
        
get_pcvar_stringg_pCvarSQLPassszPasscharsmaxszPass ) );
        
get_pcvar_stringg_pCvarSQLDb,   szDb,   charsmaxszDb   ) );
        
        
g_hSqlTuple SQL_MakeDbTupleszHostszUserszPassszDb );
        
        if( 
g_hSqlTuple == Empty_Handle ) return;
        
        
// TABLE STRUCTURE
        // admin_name VARCHAR(32) NOT NULL
        // admin_steamid VARCHAR(35) NOT NULL
        // admin_ip VARCHAR(15) NOT NULL
        // player_name VARCHAR(32) NOT NULL
        // player_steamid VARCHAR(35) NOT NULL PRIMARY KEY
        // player_ip VARCHAR(15) NOT NULL
        // date_gagged DATETIME NOT NULL
        // date_ungag DATETIME NOT NULL
        // gag_seconds INT NOT NULL
        // gag_flags VARCHAR(3) NOT NULL
        
        
new iErrorszError128 ];
        new 
Handle:hDb SQL_Connectg_hSqlTupleiErrorszErrorcharsmaxszError ) );
        
        if( 
hDb == Empty_Handle )
        {
            
log_amx"Failed to connect to database: (%d) %s"iErrorszError );
            return;
        }
        
        new 
Handle:hQuery SQL_PrepareQueryhDb"CREATE TABLE IF NOT EXISTS gagged_players (\
            admin_name VARCHAR(32) NOT NULL,\
            admin_steamid VARCHAR(35) NOT NULL,\
            admin_ip VARCHAR(15) NOT NULL,\
            player_name VARCHAR(32) NOT NULL,\
            player_steamid VARCHAR(35) NOT NULL PRIMARY KEY,\
            player_ip VARCHAR(15) NOT NULL,\
            date_gagged DATETIME NOT NULL,\
            date_ungag DATETIME NOT NULL,\
            gag_seconds INT NOT NULL,\
            gag_flags VARCHAR(3) NOT NULL);" 
);
        
        if( !
SQL_ExecutehQuery ) )
        {
            
SQL_QueryErrorhQueryszErrorcharsmaxszError ) );
            
log_amx"Failed create table query: %s"szError );
        }
        else
        {
            
SQL_FreeHandlehQuery );
            
            new 
szDateDATE_SIZE ];
            
get_timeDATETIME_FORMATszDatecharsmaxszDate ) );
            
            
// load all users
            
hQuery SQL_PrepareQueryhDb"SELECT * FROM gagged_players WHERE date_ungag > '%s';"szDate );
            
            if( !
SQL_ExecutehQuery ) )
            {
                
SQL_QueryErrorhQueryszErrorcharsmaxszError ) );
                
log_amx"Failed load gags query: %s"szError );
            }
            else
            {
                
g_bUsingSQL true;
                
                if( 
SQL_NumResultshQuery ) )
                {
                    new 
dataGagData ];
                    new 
szFlags];
                    
                    new 
iFieldSteamID SQL_FieldNameToNumhQuery"player_steamid" );
                    new 
iFieldDateGagged SQL_FieldNameToNumhQuery"date_gagged" );
                    new 
iFieldGagTime SQL_FieldNameToNumhQuery"gag_seconds" );
                    new 
iFieldGagFlags SQL_FieldNameToNumhQuery"gag_flags" );
                    
                    while( 
SQL_MoreResultshQuery ) )
                    {
                        
SQL_ReadResulthQueryiFieldSteamIDdataGAG_AUTHID ], charsmaxdataGAG_AUTHID ] ) );
                        
SQL_ReadResulthQueryiFieldDateGaggedszDatecharsmaxszDate ) );
                        
dataGAG_TIME ] = SQL_ReadResulthQueryiFieldGagTime );
                        
SQL_ReadResulthQueryiFieldGagFlagsszFlagscharsmaxszFlags ) );
                        
                        
dataGAG_START ] = strtotimeszDate );
                        
dataGAG_FLAGS ] = read_flagsszFlags );
                        
                        
ArrayPushArrayg_aGagDatadata );
                        
TrieSetCellg_tArrayPosdataGAG_AUTHID ], g_iGagged );
                        
g_iGagged++;
                        
                        
SQL_NextRowhQuery );
                    }
                }
            }
        }
        
        
SQL_FreeHandlehQuery );
        
SQL_FreeHandlehDb );
    }
}

public 
plugin_end( )
{
    
TrieDestroyg_tArrayPos );
    
ArrayDestroyg_aGagData );
    
ArrayDestroyg_aGagTimes );
    
TrieDestroyg_tTimeUnitWords );
}

public 
CmdSetBanTimes( )
{
    new 
iArgs read_argc( );
    
    if( 
iArgs <= )
    {
        
server_print"Usage: amx_gag_times <time1> [time2] [time3] ..." );
        return 
PLUGIN_HANDLED;
    }
    
    
ArrayClearg_aGagTimes );
    
    
// this is used for ungag in the menu
    
ArrayPushCellg_aGagTimes);
    
g_iTotalGagTimes 1;
    
    
// get max time allowed
    
new iTimeLimit get_pcvar_numg_pCvarMaxTime );
    
    new 
szBuffer32 ], iTime;
    for( new 
1iArgsi++ )
    {
        
read_argviszBuffer31 );
        
        if( !
is_str_numszBuffer ) )
        {
            
server_print"[AMXX GAG] Time must be an integer!" );
            continue;
        }
        
        
iTime str_to_numszBuffer );
        
        if( 
iTime )
        {
            
server_print"[AMXX GAG] Time must be a positive integer!" );
            continue;
        }
        
        if( 
iTimeLimit iTime )
        {
            
server_print"[AMXX GAG] Time more then %d is not allowed!"iTimeLimit );
            continue;
        }
        
        
ArrayPushCellg_aGagTimesiTime );
        
g_iTotalGagTimes++;
    }
    
    return 
PLUGIN_HANDLED;
}

public 
client_putinserverid )
{
    if( 
CheckGagFlagidGAG_VOICE ) )
    {
        
set_speakidSPEAK_MUTED );
    }
    
    
// default flags to "abc"
    
g_iMenuFlagsid ] = GAG_CHAT GAG_TEAMSAY GAG_VOICE;
}

public 
client_authorizedid )
    
get_user_authididg_szAuthidid ], 34 );

public 
client_disconnectid )
{
    if( 
TrieKeyExistsg_tArrayPosg_szAuthidid ] ) )
    {
        new 
szName32 ];
        
get_user_nameidszName31 );
        
        new 
iPlayers32 ], iNumiPlayer;
        
get_playersiPlayersiNum"ch" );
        
        for( new 
iiNumi++ )
        {
            
iPlayer iPlayers];
            
            if( 
get_user_flagsiPlayer ) & ADMIN_KICK )
            {
                if( 
g_bColorSupported )
                {
                    
GreenPrintiPlayerid"^4[AMXX GAG]^1 Gagged player ^"^3%s^1<^4%s^1>^" has disconnected!"szNameg_szAuthidid ] );
                }
                else
                {
                    
client_printiPlayerprint_chat"[AMXX GAG] Gagged player ^"%s<%s>^" has disconnected!"szNameg_szAuthidid ] );
                }
            }
        }
    }
    
    
g_szAuthidid ][ ] = '^0';
}

public 
client_infochangedid )
{
    if( !
CheckGagFlagid, ( GAG_CHAT GAG_TEAMSAY ) ) )
    {
        return;
    }
    
    static const 
name[ ] = "name";
    
    static 
szNewName32 ], szOldName32 ];
    
get_user_infoidnameszNewName31 );
    
get_user_nameidszOldName31 );
    
    if( !
equalszNewNameszOldName ) )
    {
        if( 
g_bColorSupported )
        {
            
GreenPrintidid"^4[AMXX GAG]^1 Gagged players cannot change their names!" );
        }
        else
        {
            
client_printidprint_chat"[AMXX GAG] Gagged players cannot change their names!" );
        }
        
        
set_user_infoidnameszOldName );
    }
}

public 
MessageSayText( )
{
    static const 
Cstrike_Name_Change[ ] = "#Cstrike_Name_Change";
    
    new 
szMessagesizeofCstrike_Name_Change ) + ];
    
get_msg_arg_string2szMessagecharsmaxszMessage ) );
    
    if( 
equalszMessageCstrike_Name_Change ) )
    {
        new 
szName32 ], id;
        for( new 
3<= 4i++ )
        {
            
get_msg_arg_stringiszName31 );
            
            
id get_user_indexszName );
            
            if( 
is_user_connectedid ) )
            {
                if( 
CheckGagFlagid, ( GAG_CHAT GAG_TEAMSAY ) ) )
                {
                    return 
PLUGIN_HANDLED;
                }
                
                break;
            }
        }
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
FwdThink( const iEntity )
{
    if( !
g_iGagged )
        return;
    
    new 
iSystime get_systime( );
    new 
bool:bRemovedGags false;
    
    new 
bool:bUsingSQL g_bUsingSQL;
    new Array:
aRemoveSteamIDsiNumRemoveSteamIDs;
    
    if( 
bUsingSQL )
    {
        
aRemoveSteamIDs ArrayCreate35 );
        
g_bUsingSQL false;
    }
    
    new 
dataGagData ], idszName32 ];
    for( new 
0g_iGaggedi++ )
    {
        
ArrayGetArrayg_aGagDataidata );
        
        if( 
dataGAG_TIME ] > && ( dataGAG_START ] + dataGAG_TIME ] ) <= iSystime )
        {
            
id find_player"c"dataGAG_AUTHID ] );
            
            if( 
is_user_connectedid ) )
            {
                
get_user_nameidszName31 );
                
                if( 
g_bColorSupported )
                {
                    
GreenPrint0id"^4[AMXX GAG]^1 Player ^"^3%s^1^" is no longer gagged"szName );
                }
                else
                {
                    
client_print0print_chat"[AMXX GAG] Player ^"%s^" is no longer gagged"szName );
                }
            }
            else
            {
                if( 
g_bColorSupported )
                {
                    
GreenPrint00"^4[AMXX GAG]^1 SteamID ^"^3%s^1^" is no longer gagged"dataGAG_AUTHID ] );
                }
                else
                {
                    
client_print0print_chat"[AMXX GAG] SteamID ^"%s^" is no longer gagged"dataGAG_AUTHID ] );
                }
            }
            
            
DeleteGagi-- );
            
            
bRemovedGags true;
            
            if( 
bUsingSQL )
            {
                
ArrayPushStringaRemoveSteamIDsdataGAG_AUTHID ] );
                
iNumRemoveSteamIDs++;
            }
        }
    }
    
    if( !
bUsingSQL )
    {
        if( 
bRemovedGags )
        {
            
SaveToFile( );
        }
    }
    else
    {
        if( 
iNumRemoveSteamIDs )
        {
            static 
szQuery1024 ];
            new 
iLen copyszQuerycharsmaxszQuery ), "DELETE FROM gagged_players WHERE " );
            
            for( new 
0iNumRemoveSteamIDsi++ )
            {
                
ArrayGetStringaRemoveSteamIDsidataGAG_AUTHID ], charsmaxdataGAG_AUTHID ] ) );
                
                
iLen += formatexszQueryiLen ], charsmaxszQuery ) - iLen"%splayer_steamid = ^"%s^""" OR " ""dataGAG_AUTHID ] );
            }
            
            
szQueryiLen++ ] = ';';
            
szQueryiLen ] = 0;
            
            
SQL_ThreadQueryg_hSqlTuple"QueryDeleteMultiple"szQuery );
        }
        
        
ArrayDestroyaRemoveSteamIDs );
        
        
g_bUsingSQL true;
    }
    
    if( !
g_iGagged )
        return;
    
    new 
iNextTime 999999;
    for( new 
0g_iGaggedi++ )
    {
        
ArrayGetArrayg_aGagDataidata );
        
        if( 
dataGAG_TIME ] > )
            
iNextTime miniNextTimedataGAG_START ] + dataGAG_TIME ] - iSystime );
    }
    
    if( 
iNextTime 999999 )
        
entity_set_floatiEntityEV_FL_nextthinkget_gametime( ) + iNextTime );
}

public 
QueryDeleteMultipleiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:flQueueTime )
{
    switch( 
iFailState )
    {
        case 
TQUERY_CONNECT_FAILEDlog_amx"Failed to connect to database: (%d) %s"iErrorszError );
        case 
TQUERY_QUERY_FAILED:   log_amx"Failed delete multiple query: (%d) %s"iErrorszError );
    }
}

public 
CmdSay( const id )
    return 
CheckSayid);

public 
CmdTeamSay( const id )
    return 
CheckSayid);

CheckSay( const id, const bTeam )
{
    new 
iArrayPos;
    if( 
TrieGetCellg_tArrayPosg_szAuthidid ], iArrayPos ) )
    {
        new 
dataGagData ];
        
ArrayGetArrayg_aGagDataiArrayPosdata );
        
        new const 
iFlags[ ] = { GAG_CHATGAG_TEAMSAY };
        
        if( 
dataGAG_FLAGS ] & iFlagsbTeam ] )
        {
            if( 
dataGAG_TIME ] > )
            {
                new 
szInfo128 ], iTime dataGAG_START ] + dataGAG_TIME ] - get_systime( );
                
                
GetTimeLengthiTimeszInfocharsmaxszInfo ) );
                
                if( 
g_bColorSupported )
                {
                    
GreenPrintidid"^4[AMXX GAG]^3 %s^1 left before your ungag!"szInfo );
                }
                else
                {
                    
client_printidprint_chat"[AMXX GAG] %s left before your ungag!"szInfo );
                }
            }
            else
            {
                if( 
g_bColorSupported )
                {
                    
GreenPrintidid"^4[AMXX GAG]^3 You are gagged permanently!" );
                }
                else
                {
                    
client_printidprint_chat"[AMXX GAG] You are gagged permanently!" );
                }
            }
            
            
client_printidprint_center"** You are gagged from%s chat! **"bTeam " team" "" );
            
            return 
PLUGIN_HANDLED;
        }
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
CmdGagPlayer( const id, const iLevel, const iCid )
{
    if( !
cmd_accessidiLeveliCid) )
    {
        
console_printid"Flags: a - Chat | b - Team Chat | c - Voice communications" );
        return 
PLUGIN_HANDLED;
    }
    
    new 
szArg32 ];
    
read_argv1szArg31 );
    
    new 
iPlayer cmd_targetidszArgCMDTARGET_OBEY_IMMUNITY CMDTARGET_NO_BOTS );
    
    if( !
iPlayer )
    {
        return 
PLUGIN_HANDLED;
    }
    
    new 
szName20 ];
    
get_user_nameiPlayerszName19 );
    
    if( 
TrieKeyExistsg_tArrayPosg_szAuthidiPlayer ] ) )
    {
        
console_printid"User ^"%s^" is already gagged!"szName );
        return 
PLUGIN_HANDLED;
    }
    
    new 
iFlags;
    new 
iGagTime;
    
    
read_argv2szArg31 );
    
    if( 
szArg] ) // No time entered
    
{
        if( 
is_str_numszArg ) ) // Seconds entered
        
{
            
iGagTime absstr_to_numszArg ) );
        }
        else
        {
            
console_printid"The value must be in seconds!" );
            return 
PLUGIN_HANDLED;
        }
        
        
read_argv3szArg31 );
        
        if( 
szArg] )
        {
            
iFlags read_flagsszArg );
        }
    }
    
    
GagPlayeridiPlayeriGagTimeiFlags );
    
    return 
PLUGIN_HANDLED;
}

GagPlayeridiPlayeriGagTimeiFlags )
{
    new 
iTimeUnit GetTimeUnit( );
    new 
iMaxTime get_pcvar_numg_pCvarMaxTime );
    
iGagTime clampiGagTime1iMaxTime ) * g_iTimeUnitMultiTimeUnit ];
    
    if( !
iFlags )
    {
        new 
szFlags27 ];
        
get_pcvar_stringg_pCvarDefaultFlagsszFlagscharsmaxszFlags ) );
        
        
iFlags read_flagsszFlags );
    }
    
    new 
dataGagData ];
    
dataGAG_START ] = get_systime( );
    
dataGAG_TIME ]  = iGagTime;
    
dataGAG_FLAGS ] = iFlags;
    
copydataGAG_AUTHID ], 34g_szAuthidiPlayer ] );
    
    
TrieSetCellg_tArrayPosg_szAuthidiPlayer ], g_iGagged );
    
ArrayPushArrayg_aGagDatadata );
    
    new 
szFrom64 ];
    
    if( 
iFlags GAG_CHAT )
    {
        
copyszFrom63"say" );
    }
    
    if( 
iFlags GAG_TEAMSAY )
    {
        if( !
szFrom] )
            
copyszFrom63"say_team" );
        else
            
addszFrom63" / say_team" );
    }
    
    if( 
iFlags GAG_VOICE )
    {
        
set_speakiPlayerSPEAK_MUTED );
        
        if( !
szFrom] )
            
copyszFrom63"voicecomm" );
        else
            
addszFrom63" / voicecomm" );
    }
    
    
g_iGagged++;
    
    if( 
iGagTime )
    {
        new 
Float:flGametime get_gametime( ), Float:flNextThink;
        
flNextThink entity_get_floatg_iThinkerEV_FL_nextthink );
        
        if( !
flNextThink || flNextThink > ( flGametime iGagTime ) )
            
entity_set_floatg_iThinkerEV_FL_nextthinkflGametime iGagTime );
    }
    
    if( 
g_bUsingSQL )
    {
        
AddGagidiPlayeriGagTimeiFlags );
    }
    else
    {
        
SaveToFile( );
    }
    
    new 
szName20 ];
    
get_user_nameiPlayerszName19 );
    
    new 
szInfo32 ], szAdmin20 ];
    
get_user_nameidszAdmin19 );
    
    if( 
iGagTime )
    {
        new 
iLen copyszInfo31"for " );
        
GetTimeLengthiGagTimeszInfoiLen ], charsmaxszInfo ) - iLen );
    }
    else
    {
        
copyszInfo31"permanently" );
    }
    
    
show_activityidszAdmin"Has gagged %s from speaking %s! (%s)"szNameszInfoszFrom );
    
    
console_printid"You have gagged ^"%s^" (%s) !"szNameszFrom );
    
    
log_amx"Gag: ^"%s<%s>^" has gagged ^"%s<%s>^" %s. (%s)"szAdming_szAuthidid ], szNameg_szAuthidiPlayer ], szInfoszFrom );
}

public 
CmdAddGag( const id, const iLevel, const iCid )
{
    if( !
cmd_accessidiLeveliCid) )
    {
        
console_printid"Flags: a - Chat | b - Team Chat | c - Voice communications" );
        return 
PLUGIN_HANDLED;
    }
    
    new 
szArg32 ];
    
read_argv1szArg31 );
    
    if( !
IsValidSteamIDszArg ) )
    {
        
console_printid"Invalid SteamID provided (%s). Must be in ^"STEAM_0:X:XXXXX^" format (remember to use quotes!)"szArg );
        return 
PLUGIN_HANDLED;
    }
    
    new 
iPlayer find_player"c"szArg );
    
    if( 
is_user_connectediPlayer ) )
    {
        new 
szTime12 ], szFlags];
        
read_argv2szTime,  charsmaxszTime  ) );
        
read_argv3szFlagscharsmaxszFlags ) );
        
        
client_cmdid"amx_gag #%d ^"%s^" ^"%s^""get_user_useridiPlayer ), szTimeszFlags );
        return 
PLUGIN_HANDLED;
    }
    
    if( 
TrieKeyExistsg_tArrayPosszArg ) )
    {
        
console_printid"This user is already gagged!" );
        return 
PLUGIN_HANDLED;
    }
    
    if( 
GetAccessBySteamIDszArg ) & ADMIN_IMMUNITY )
    {
        
console_printid"This user has immunity!" );
        return 
PLUGIN_HANDLED;
    }
    
    new 
dataGagData ];
    
copydataGAG_AUTHID ], 34szArg );
    
    
get_pcvar_stringg_pCvarDefaultFlagsszArgcharsmaxszArg ) );
    new 
iFlags read_flagsszArg );
    
    new 
iTimeUnit GetTimeUnit( );
    new 
iMaxTime get_pcvar_numg_pCvarMaxTime );
    new 
iGagTime clampget_pcvar_numg_pCvarDefaultTime ), 1iMaxTime );
    
    
read_argv2szArg31 );
    
    if( 
szArg] ) // No time entered
    
{
        if( 
is_str_numszArg ) ) // Seconds entered
        
{
            
iGagTime minabsstr_to_numszArg ) ), iMaxTime );
        }
        else
        {
            
console_printid"The value must be in seconds!" );
            return 
PLUGIN_HANDLED;
        }
        
        
read_argv3szArg31 );
        
        if( 
szArg] )
        {
            
iFlags read_flagsszArg );
        }
    }
    
    
// convert to seconds
    
iGagTime *= g_iTimeUnitMultiTimeUnit ];
    
    
dataGAG_START ] = get_systime( );
    
dataGAG_TIME ]  = iGagTime;
    
dataGAG_FLAGS ] = iFlags;
    
    
TrieSetCellg_tArrayPosdataGAG_AUTHID ], g_iGagged );
    
ArrayPushArrayg_aGagDatadata );
    
    new 
szFrom64 ];
    
    if( 
iFlags GAG_CHAT )
    {
        
copyszFrom63"say" );
    }
    
    if( 
iFlags GAG_TEAMSAY )
    {
        if( !
szFrom] )
            
copyszFrom63"say_team" );
        else
            
addszFrom63" / say_team" );
    }
    
    if( 
iFlags GAG_VOICE )
    {
        if( !
szFrom] )
            
copyszFrom63"voicecomm" );
        else
            
addszFrom63" / voicecomm" );
    }
    
    
g_iGagged++;
    
    if( 
iGagTime )
    {
        new 
Float:flGametime get_gametime( ), Float:flNextThink;
        
flNextThink entity_get_floatg_iThinkerEV_FL_nextthink );
        
        if( !
flNextThink || flNextThink > ( flGametime iGagTime ) )
            
entity_set_floatg_iThinkerEV_FL_nextthinkflGametime iGagTime );
    }
    
    if( 
g_bUsingSQL )
    {
        
AddGagidiPlayeriGagTimeiFlags );
    }
    else
    {
        
SaveToFile( );
    }
    
    new 
szInfo32 ], szAdmin20 ];
    
get_user_nameidszAdmin19 );
    
    if( 
iGagTime )
    {
        new 
iLen copyszInfo31"for " );
        
GetTimeLengthiGagTimeszInfoiLen ], charsmaxszInfo ) - iLen );
    }
    else
    {
        
copyszInfo31"permanently" );
    }
    
    
show_activityidszAdmin"Has gagged a non-connected player <%s> from speaking %s! (%s)"dataGAG_AUTHID ], szInfoszFrom );
    
    
console_printid"You have gagged ^"%s^" (%s) !"dataGAG_AUTHID ], szFrom );
    
    
log_amx"Gag: ^"%s<%s>^" has gagged a non-connected player ^"<%s>^" %s. (%s)"szAdming_szAuthidid ], dataGAG_AUTHID ], szInfoszFrom );
    
    return 
PLUGIN_HANDLED;
}

public 
CmdUnGagPlayer( const id, const iLevel, const iCid )
{
    if( !
cmd_accessidiLeveliCid) )
        return 
PLUGIN_HANDLED;
    
    new 
szArg32 ];
    
read_argv1szArg31 );
    
    if( 
szArg] == '@' && equaliszArg], "all" ) )
    {
        if( !
g_iGagged )
        {
            
console_printid"No gagged players!" );
            return 
PLUGIN_HANDLED;
        }
        
        
DeleteAllGags( );
        
        if( 
entity_get_floatg_iThinkerEV_FL_nextthink ) > 0.0 )
            
entity_set_floatg_iThinkerEV_FL_nextthink0.0 );
        
        
console_printid"You have ungagged all players!" );
        
        new 
szAdmin32 ];
        
get_user_nameidszAdmin31 );
        
        
show_activityidszAdmin"Has ungagged all players." );
        
        
log_amx"UnGag: ^"%s<%s>^" has ungagged all players."szAdming_szAuthidid ] );
        
        return 
PLUGIN_HANDLED;
    }
    
    new 
iPlayer cmd_targetidszArgCMDTARGET_NO_BOTS );
    new 
iArrayPosszName32 ];
    
    if( !
iPlayer )
    {
        
// Maybe it's a steamid
        
        
if( !IsValidSteamIDszArg ) )
        {
            return 
PLUGIN_HANDLED;
        }
        
        if( !
TrieGetCellg_tArrayPosszArgiArrayPos ) )
        {
            
console_printid"This steamid is not gagged!" );
            return 
PLUGIN_HANDLED;
        }
        
        
copyszNamecharsmaxszName ), szArg );
    }
    else
    {
        
get_user_nameiPlayerszNamecharsmaxszName ) );
        
        if( !
TrieGetCellg_tArrayPosg_szAuthidiPlayer ], iArrayPos ) )
        {
            
console_printid"User ^"%s^" is not gagged!"szName );
            return 
PLUGIN_HANDLED;
        }
    }
    
    
DeleteGagiArrayPos );
    
    if( !
g_bUsingSQL )
    {
        
SaveToFile( );
    }
    
    new 
szAdmin32 ];
    
get_user_nameidszAdmin31 );
    
    
show_activityidszAdmin"Has ungagged %s."szName );
    
    
console_printid"You have ungagged ^"%s^" !"szName );
    
    
log_amx"UnGag: ^"%s<%s>^" has ungagged ^"%s<%s>^""szAdming_szAuthidid ], szNameg_szAuthidiPlayer ] );
    
    return 
PLUGIN_HANDLED;
}

public 
CmdGagMenu( const id, const iLevel, const iCid )
{
    if( !
cmd_accessidiLeveliCid) )
    {
        return 
PLUGIN_HANDLED;
    }
    
    
g_iMenuOptionid ] = 0;
    
arraysetg_iMenuPlayersid ], 032 );
    
    
DisplayGagMenuidg_iMenuPositionid ] = );
    
    return 
PLUGIN_HANDLED;
}

#define PERPAGE 6

public ActionGagMenu( const id, const iKey )
{
    switch( 
iKey )
    {
        case 
6DisplayGagFlagsid );
        case 
7:
        {
            ++
g_iMenuOptionid ];
            
g_iMenuOptionid ] %= g_iTotalGagTimes;
            
            
DisplayGagMenuidg_iMenuPositionid ] );
        }
        case 
8DisplayGagMenuid, ++g_iMenuPositionid ] );
        case 
9DisplayGagMenuid, --g_iMenuPositionid ] );
        default:
        {
            new 
iPlayer g_iMenuPlayersid ][ g_iMenuPositionid ] * PERPAGE iKey ];
            
            if( 
is_user_connectediPlayer ) )
            {
                if( !
g_iMenuOptionid ] )
                {
                    
//client_cmd( id, "amx_ungag #%i", get_user_userid( iPlayer ) );
                    
                    
new iArrayPos;
                    
                    if( 
TrieGetCellg_tArrayPosg_szAuthidiPlayer ], iArrayPos ) )
                    {
                        
DeleteGagiArrayPos );
                        
                        if( !
g_bUsingSQL )
                        {
                            
SaveToFile( );
                        }
                        
                        new 
szName32 ];
                        
get_user_nameiPlayerszName31 );
                        
                        new 
szAdmin32 ];
                        
get_user_nameidszAdmin31 );
                        
                        
show_activityidszAdmin"Has ungagged %s."szName );
                        
                        
console_printid"You have ungagged ^"%s^" !"szName );
                        
                        
log_amx"UnGag: ^"%s<%s>^" has ungagged ^"%s<%s>^""szAdming_szAuthidid ], szNameg_szAuthidiPlayer ] );
                    }
                }
                else if( !
TrieKeyExistsg_tArrayPosg_szAuthidiPlayer ] ) )
                {
                    
/*new szFlags[ 4 ];
                    get_flags( g_iMenuFlags[ id ], szFlags, 3 );
                    
                    client_cmd( id, "amx_gag #%i %i %s", get_user_userid( iPlayer ), ArrayGetCell( g_aGagTimes, g_iMenuOption[ id ] ), szFlags );*/
                    
                    
GagPlayeridiPlayerArrayGetCellg_aGagTimesg_iMenuOptionid ] ), g_iMenuFlagsid ] );
                }
            }
            
            
DisplayGagMenuidg_iMenuPositionid ] );
        }
    }
}

// I just copied this from AMXX Ban menu, so don't blame me :D
DisplayGagMenu( const idiPosition )
{
    if( 
iPosition )
    {
        
arraysetg_iMenuPlayersid ], 032 );
        return;
    }
    
    new 
iPlayers32 ], iNumiCountszMenu512 ], iPlayeriFlagsszName32 ];
    
get_playersiPlayersiNum"ch" ); // Ignore bots and hltv
    
    
new iStart iPosition PERPAGE;
    
    if( 
iStart >= iNum )
        
iStart iPosition g_iMenuPositionid ] = 0;
    
    new 
iEnd iStart PERPAGEiKeys MENU_KEY_0 MENU_KEY_8;
    new 
iLen formatexszMenu511g_bColorSupported "\rGag Menu\R%i/%i^n^n" "Gag Menu %i/%i^n^n"iPosition 1, ( ( iNum PERPAGE ) / PERPAGE ) );
    
    new 
bool:bUngag bool:!g_iMenuOptionid ];
    
    if( 
iEnd iNum iEnd iNum;
    
    for( new 
iStartiEnd; ++)
    {
        
iPlayer iPlayers];
        
iFlags  get_user_flagsiPlayer );
        
get_user_nameiPlayerszName31 );
        
        if( 
iPlayer == id || ( iFlags ADMIN_IMMUNITY ) || bUngag != TrieKeyExistsg_tArrayPosg_szAuthidiPlayer ] ) )
        {
            ++
iCount;
            
            if( 
g_bColorSupported )
                
iLen += formatexszMenuiLen ], 511 iLen"\d%i. %s^n"iCountszName );
            else
                
iLen += formatexszMenuiLen ], 511 iLen"#. %s^n"szName );
        }
        else
        {
            
iKeys |= ( << iCount );
            ++
iCount;
            
            
iLen += formatexszMenuiLen ], 511 iLeng_bColorSupported "\r%i.\w %s\y%s\r%s^n" "%i. %s%s%s^n"iCountszNameTrieKeyExistsg_tArrayPosg_szAuthidiPlayer ] ) ? " GAGGED" "", ( ~iFlags ADMIN_USER " *" "" ) );
        }
    }
    
    
g_iMenuPlayersid ] = iPlayers;
    
    new 
szFlags];
    
get_flagsg_iMenuFlagsid ], szFlags);
    
    
iLen += formatexszMenuiLen ], 511 iLeng_bColorSupported ? ( bUngag "^n\d7. Flags: %s" "^n\r7.\y Flags:\w %s" ) : ( bUngag "^n#. Flags: %s" "^n7. Flags: %s" ), szFlags );
    
    if( !
bUngag )
    {
        
iKeys |= MENU_KEY_7;
        
        new 
iGagTime ArrayGetCellg_aGagTimesg_iMenuOptionid ] );
        
        if( 
iGagTime )
        {
            new 
szTime128 ];
            
GetTimeLengthiGagTime g_iTimeUnitMultGetTimeUnit( ) ], szTimecharsmaxszTime ) );
            
            
iLen += formatexszMenuiLen ], 511 iLeng_bColorSupported "^n\r8.\y Time:\w %s^n" "^n8. Time: %s^n"szTime );
        }
        else
            
iLen += copyszMenuiLen ], 511 iLeng_bColorSupported "^n\r8.\y Time: Permanent^n" "^n8. Time: Permanent^n" );
    }
    else
        
iLen += copyszMenuiLen ], 511 iLeng_bColorSupported "^n\r8.\w Ungag^n" "^n8. Ungag^n" );
    
    if( 
iEnd != iNum )
    {
        
formatexszMenuiLen ], 511 iLeng_bColorSupported "^n\r9.\w More...^n\r0.\w %s" "^n9. More...^n0. %s"iPosition "Back" "Exit" );
        
iKeys |= MENU_KEY_9;
    }
    else
        
formatexszMenuiLen ], 511 iLeng_bColorSupported "^n\r0.\w %s" "^n0. %s"iPosition "Back" "Exit" );
    
    
show_menuidiKeysszMenu, -1"Gag Menu" );
}

public 
ActionGagFlags( const id, const iKey )
{
    switch( 
iKey )
    {
        case 
9DisplayGagMenuidg_iMenuPositionid ] );
        default:
        {
            
g_iMenuFlagsid ] ^= ( << iKey );
            
            
DisplayGagFlagsid );
        }
    }
}

DisplayGagFlags( const id )
{
    new 
szMenu512 ];
    new 
iLen copyszMenu511g_bColorSupported "\rGag Flags^n^n" "Gag Flags^n^n" );
    
    if( 
g_bColorSupported )
    {
        
iLen += formatexszMenuiLen ], 511 iLen"\r1.\w Chat: %s^n", ( g_iMenuFlagsid ] & GAG_CHAT ) ? "\yYES" "\rNO" );
        
iLen += formatexszMenuiLen ], 511 iLen"\r2.\w TeamSay: %s^n", ( g_iMenuFlagsid ] & GAG_TEAMSAY ) ? "\yYES" "\rNO" );
        
iLen += formatexszMenuiLen ], 511 iLen"\r3.\w Voice: %s^n", ( g_iMenuFlagsid ] & GAG_VOICE ) ? "\yYES" "\rNO" );
    }
    else
    {
        
iLen += formatexszMenuiLen ], 511 iLen"1. Chat: %s^n", ( g_iMenuFlagsid ] & GAG_CHAT ) ? "YES" "NO" );
        
iLen += formatexszMenuiLen ], 511 iLen"2. TeamSay: %s^n", ( g_iMenuFlagsid ] & GAG_TEAMSAY ) ? "YES" "NO" );
        
iLen += formatexszMenuiLen ], 511 iLen"3. Voice: %s^n", ( g_iMenuFlagsid ] & GAG_VOICE ) ? "YES" "NO" );
    }
    
    
copyszMenuiLen ], 511 iLeng_bColorSupported "^n\r0. \wBack to Gag Menu" "^n0. Back to Gag Menu" );
    
    
show_menuid, ( MENU_KEY_1 MENU_KEY_2 MENU_KEY_3 MENU_KEY_0 ), szMenu, -1"Gag Flags" );
}

CheckGagFlag( const id, const iFlag )
{
    new 
iArrayPos;
    
    if( 
TrieGetCellg_tArrayPosg_szAuthidid ], iArrayPos ) )
    {
        new 
dataGagData ];
        
ArrayGetArrayg_aGagDataiArrayPosdata );
        
        return ( 
dataGAG_FLAGS ] & iFlag );
    }
    
    return 
0;
}

DeleteAllGags( )
{
    new 
dataGagData ];
    new 
iPlayer;
    
    for( new 
0g_iGaggedi++ )
    {
        
ArrayGetArrayg_aGagDataidata );
        
        
iPlayer find_player"c"dataGAG_AUTHID ] );
        if( 
is_user_connectediPlayer ) )
            
set_speakiPlayerSPEAK_NORMAL );
    }
    
    
ArrayClearg_aGagData );
    
TrieClearg_tArrayPos );
    
g_iGagged 0;
    
    if( 
g_bUsingSQL )
    {
        
SQL_ThreadQueryg_hSqlTuple"QueryDeleteAll""DELETE FROM gagged_players;" );
    }
}

public 
QueryDeleteAlliFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:flQueueTime )
{
    switch( 
iFailState )
    {
        case 
TQUERY_CONNECT_FAILEDlog_amx"Failed to connect to database: (%d) %s"iErrorszError );
        case 
TQUERY_QUERY_FAILED:   log_amx"Failed delete all query: (%d) %s"iErrorszError );
    }
}

DeleteGag( const iArrayPos )
{
    new 
dataGagData ];
    
ArrayGetArrayg_aGagDataiArrayPosdata );
    
    if( 
dataGAG_FLAGS ] & GAG_VOICE )
    {
        new 
iPlayer find_player"c"dataGAG_AUTHID ] );
        if( 
is_user_connectediPlayer ) )
            
set_speakiPlayerSPEAK_NORMAL );
    }
    
    
TrieDeleteKeyg_tArrayPosdataGAG_AUTHID ] );
    
ArrayDeleteItemg_aGagDataiArrayPos );
    
g_iGagged--;
    
    for( new 
iArrayPosg_iGaggedi++ )
    {
        
ArrayGetArrayg_aGagDataidata );
        
TrieSetCellg_tArrayPosdataGAG_AUTHID ], );
    }
    
    if( 
g_bUsingSQL )
    {
        new 
szQuery128 ];
        
formatexszQuerycharsmaxszQuery ), "DELETE FROM gagged_players WHERE player_steamid = '%s';"dataGAG_AUTHID ] );
        
        
SQL_ThreadQueryg_hSqlTuple"QueryDelete"szQuery );
    }
}

public 
QueryDeleteiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:flQueueTime )
{
    switch( 
iFailState )
    {
        case 
TQUERY_CONNECT_FAILEDlog_amx"Failed to connect to database: (%d) %s"iErrorszError );
        case 
TQUERY_QUERY_FAILED:   log_amx"Failed delete query: (%d) %s"iErrorszError );
    }
}

LoadFromFile( )
{
    new 
hFile fopeng_szGagFile"rt" );
    
    if( 
hFile )
    {
        new 
szData128 ], szTime16 ], szStart16 ], szFlags];
        new 
dataGagData ], iSystime get_systime( ), iTimeLeftiShortestTime 999999;
        new 
bool:bRemovedGags false;
        
        while( !
feofhFile ) )
        {
            
fgetshFileszDatacharsmaxszData ) );
            
trimszData );
            
            if( !
szData] ) continue;
            
            
parseszData,
                
dataGAG_AUTHID ], charsmaxdataGAG_AUTHID ] ),
                
szTimecharsmaxszTime ),
                
szStartcharsmaxszStart ),
                
szFlagscharsmaxszFlags )
            );
            
            
// remove old gags
            
if( containszStart"." ) > ) continue;
            
            
dataGAG_TIME ] = str_to_numszTime );
            
dataGAG_START ] = str_to_numszStart );
            
dataGAG_FLAGS ] = read_flagsszFlags );
            
            if( 
dataGAG_TIME ] > )
            {
                
iTimeLeft dataGAG_START ] + dataGAG_TIME ] - iSystime;
                
                if( 
iTimeLeft <= )
                {
                    
bRemovedGags true;
                    continue;
                }
                
                if( 
iShortestTime iTimeLeft )
                {
                    
iShortestTime iTimeLeft;
                }
            }
            
            
TrieSetCellg_tArrayPosdataGAG_AUTHID ], g_iGagged );
            
ArrayPushArrayg_aGagDatadata );
            
g_iGagged++;
        }
        
        
fclosehFile );
        
        if( 
bRemovedGags )
        {
            
SaveToFile( );
        }
        
        if( 
iShortestTime 999999 )
        {
            
entity_set_floatg_iThinkerEV_FL_nextthinkget_gametime( ) + iShortestTime );
        }
    }
}

SaveToFile( )
{
    new 
hFile fopeng_szGagFile"wt" );
    
    if( 
hFile )
    {
        new 
dataGagData ], szFlags];
        
        for( new 
0g_iGaggedi++ )
        {
            
ArrayGetArrayg_aGagDataidata );
            
            
get_flagsdataGAG_FLAGS ], szFlagscharsmaxszFlags ) );
            
            
fprintfhFile"^"%s^" ^"%i^" ^"%i^" ^"%s^"^n"dataGAG_AUTHID ], dataGAG_TIME ], dataGAG_START ], szFlags );
        }
        
        
fclosehFile );
    }
}

GetTimeUnit( )
{
    new 
szTimeUnit64 ], iTimeUnit;
    
get_pcvar_stringg_pCvarTimeUnitszTimeUnitcharsmaxszTimeUnit ) );
    
    if( 
is_str_numszTimeUnit ) )
    {
        
iTimeUnit get_pcvar_numg_pCvarTimeUnit );
        
        if( !( 
<= iTimeUnit TimeUnit ) )
        {
            
iTimeUnit = -1;
        }
    }
    else
    {
        
strtolowerszTimeUnit );
        
        if( !
TrieGetCellg_tTimeUnitWordsszTimeUnitiTimeUnit ) )
        {
            
iTimeUnit = -1;
        }
    }
    
    if( 
iTimeUnit == -)
    {
        
iTimeUnit TIMEUNIT_SECONDS;
        
        
set_pcvar_numg_pCvarTimeUnitTIMEUNIT_SECONDS );
    }
    
    return 
iTimeUnit;
}

GetTimeLengthiTimeszOutput[ ], iOutputLen )
{
    new 
szTimesTimeUnit ][ 32 ];
    new 
iUnitiValueiTotalDisplay;
    
    for( new 
TimeUnit 1>= 0i-- )
    {
        
iUnit g_iTimeUnitMult];
        
iValue iTime iUnit;
        
        if( 
iValue )
        {
            
formatexszTimes], charsmaxszTimes[ ] ), "%d %s"iValueg_szTimeUnitName][ iValue != ] );
            
            
iTime %= iUnit;
            
            
iTotalDisplay++;
        }
    }
    
    new 
iLeniTotalLeft iTotalDisplay;
    
szOutput] = 0;
    
    for( new 
TimeUnit 1>= 0i-- )
    {
        if( 
szTimes][ ] )
        {
            
iLen += formatexszOutputiLen ], iOutputLen iLen"%s%s%s",
                ( 
iTotalDisplay && iLen ) ? ", " "",
                ( 
iTotalDisplay && iTotalLeft == ) ? ( ( iTotalDisplay ) ? "and " " and " ) : "",
                
szTimes]
            );
            
            
iTotalLeft--;
        }
    }
    
    return 
iLen
}

GreenPrintidiSender, const szRawMessage[ ], any:... )
{
    if( !
iSender )
    {
        new 
iPlayers32 ], iNum;
        
get_playersiPlayersiNum"ch" );
        
        if( !
iNum ) return;
        
        
iSender iPlayers];
    }
    
    new 
szMessage192 ];
    
vformatszMessagecharsmaxszMessage ), szRawMessage);
    
    
message_beginid MSG_ONE_UNRELIABLE MSG_BROADCASTg_iMsgSayText_id );
    
write_byteiSender );
    
write_stringszMessage );
    
message_end( );
}

bool:IsValidSteamID( const szSteamID[ ] )
{
    
// STEAM_0:(0|1):\d+
    // 012345678    90
    
    // 0-7 = STEAM_0:
    // 8 = 0 or 1
    // 9 = :
    // 10+ = integer
    
    
return ( ( '0' <= szSteamID] <= '1' ) && szSteamID] == ':' && equalszSteamID"STEAM_0:") && is_str_numszSteamID10 ] ) );
}

GetAccessBySteamID( const szSteamID[ ] )
{
    new 
szAuthData44 ], iCount admins_num( );
    
    for( new 
iiCounti++ )
    {
        if( 
admins_lookupiAdminProp_Flags ) & FLAG_AUTHID )
        {
            
admins_lookupiAdminProp_AuthszAuthDatacharsmaxszAuthData ) );
            
            if( 
equalszAuthDataszSteamID ) )
            {
                return 
admins_lookupiAdminProp_Access );
            }
        }
    }
    
    return 
0;
}

strtotime(const string[])
{
    new 
szTemp32 ];
    new 
szYear], szMonth], szDay], szHour], szMinute], szSecond];
    
strtokstringszYear,   charsmaxszYear   ), szTemp,   charsmaxszTemp   ), '-' );
    
strtokszTempszMonth,  charsmaxszMonth  ), szTemp,   charsmaxszTemp   ), '-' );
    
strtokszTempszDay,    charsmaxszDay    ), szTemp,   charsmaxszTemp   ), ' ' );
    
strtokszTempszHour,   charsmaxszHour   ), szTemp,   charsmaxszTemp   ), ':' );
    
strtokszTempszMinutecharsmaxszMinute ), szSecondcharsmaxszSecond ), ':' );
    
    return 
TimeToUnixstr_to_numszYear ), str_to_numszMonth ), str_to_numszDay ), str_to_numszHour ), str_to_numszMinute ), str_to_numszSecond ) );
}

AddGagadminplayeriGagTimeiFlags )
{
    new 
szAdminName32 ], szAdminIP16 ];
    
    if( 
admin )
    {
        
get_user_nameadminszAdminNamecharsmaxszAdminName ) );
    }
    else
    {
        
copyszAdminNamecharsmaxszAdminName ), "SERVER" );
    }
    
    
get_user_ipadminszAdminIPcharsmaxszAdminIP ), );
    
    new 
szPlayerName32 ], szPlayerIP16 ];
    
get_user_nameplayerszPlayerNamecharsmaxszPlayerName ) );
    
get_user_ipplayerszPlayerIPcharsmaxszPlayerIP ), );
    
    new 
szDateNowDATE_SIZE ], szDateUngagDATE_SIZE ];
    
get_timeDATETIME_FORMATszDateNowcharsmaxszDateNow ) );
    
format_timeszDateUngagcharsmaxszDateUngag ), DATETIME_FORMATget_systime( ) + iGagTime );
    
    new 
szFlags];
    
get_flagsiFlagsszFlagscharsmaxszFlags ) );
    
    new 
szQuery256 ];
    
formatexszQuerycharsmaxszQuery ), "REPLACE INTO gagged_players \
        (admin_name, admin_steamid, admin_ip, player_name, player_steamid, player_ip, date_gagged, date_ungag, gag_seconds, gag_flags) \
        VALUES \
        (^"
%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", ^"%s^", %d, ^"%s^");",\
        
szAdminName,  g_szAuthidadmin  ], szAdminIP,\
        
szPlayerNameg_szAuthidplayer ], szPlayerIP,\
        
szDateNowszDateUngagiGagTimeszFlags );
    
    
SQL_ThreadQueryg_hSqlTuple"QueryAdd"szQuery );
}

public 
QueryAddiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:flQueueTime )
{
    switch( 
iFailState )
    {
        case 
TQUERY_CONNECT_FAILEDlog_amx"Failed to connect to database: (%d) %s"iErrorszError );
        case 
TQUERY_QUERY_FAILED:   log_amx"Failed add gag query: (%d) %s"iErrorszError );
    }
}

// CODE BELOW FROM BUGSY'S UNIX TIME INCLUDE
// 

stock const YearSeconds[2] = 

    
31536000,    //Normal year
    
31622400     //Leap year
};

stock const MonthSeconds[12] = 

    
2678400//January    31 
    
2419200//February    28
    
2678400//March    31
    
2592000//April    30
    
2678400//May        31
    
2592000//June        30
    
2678400//July        31
    
2678400//August    31
    
2592000//September    30
    
2678400//October    31
    
2592000//November    30
    
2678400  //December    31
};

stock const DaySeconds 86400;
stock const HourSeconds 3600;
stock const MinuteSeconds 60;

stock TimeToUnix( const iYear , const iMonth , const iDay , const iHour , const iMinute , const iSecond )
{
    new 
i;
    new 
iTimeStamp;

    for ( 
1970 iYear i++ )
        
iTimeStamp += YearSecondsIsLeapYear(i) ];

    for ( 
iMonth i++ )
        
iTimeStamp += SecondsInMonthiYear );

    
iTimeStamp += ( ( iDay ) * DaySeconds );
    
iTimeStamp += ( iHour HourSeconds );
    
iTimeStamp += ( iMinute MinuteSeconds );
    
iTimeStamp += iSecond;

    return 
iTimeStamp;
}

stock SecondsInMonth( const iYear , const iMonth 
{
    return ( ( 
IsLeapYeariYear ) && ( iMonth == ) ) ? ( MonthSeconds[iMonth 1] + DaySeconds ) : MonthSeconds[iMonth 1] );
}

stock IsLeapYear( const iYear 
{
    return ( ( (
iYear 4) == 0) && ( ( (iYear 100) != 0) || ( (iYear 400) == ) ) );

Mikaeel123 is offline