/*
Copyleft © 2014, Kidev @ www.kidev.fr
"iChat" is free software;
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation.
This plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with "iChat"; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include < amxmodx >
#include < amxmisc >
#include < hamsandwich >
#include < fakemeta >
#pragma semicolon 1
#define ICHAT_VERSION "2.3.3"
#define ICHAT_HOST "forums.alliedmods.net"
#define ICHAT_THREAD "showthread.php?t=173113"
#define USE_TEAM_FIX
#define ICHAT_MAX_PLAYERS 32
#define ICHAT_MAX_SAID_LEN 128
#define ICHAT_MAX_MSG_LEN 496
#define TASK_NOTIFY 5987
#define NOTIFY_TASK_TIME 15.0
#define FORMAT_MAX_SIZE 264
#define FORMAT_SMALL_MAX_SIZE 36
#define MAX_CUSTOM_TAGS 2
#define MAX_CUSTOM_TAGS_SIZE 24
#define TEAM_AA_1 0
#define TEAM_AA_2 3
#define ICHAT_RETURN PLUGIN_HANDLED
#if defined USE_TEAM_FIX
#define TeamInfo_PlayerID 1
#define XO_PLAYER 5
#define m_iTeam 114
#define m_iDeaths 444
new gMsgScoreInfo;
#endif
enum _:formats
{
formatAllDefAlive = 0,
formatAllAdminAlive,
formatAllVIPAlive,
formatTeamDefAlive,
formatTeamAdminAlive,
formatTeamVIPAlive,
formatAllDefDead,
formatAllAdminDead,
formatAllVIPDead,
formatTeamDefDead,
formatTeamAdminDead,
formatTeamVIPDead,
formatMeMessage,
formatMeCommand,
formatClearCommand,
formatMax
};
enum _:formatTypes { formatDefAlive = 0, formatDefDead, formatTeamAlive, formatTeamDead, formatTypesMax };
enum _:messageType { messageToAll = 0, messageToTeam };
enum _:formatMode { USER = 0, ADMIN, VIP, CUSTOM };
enum _:teamTags { NONE = 0, T, CT, SPEC };
enum _:deadOrAlive { DEAD = 0, ALIVE };
enum _:usersFlags { FLAG_RELOAD = 0, FLAG_SPY, FLAG_ADMIN, FLAG_VIP, FLAG_CHAT, FLAG_SEE_CHAT };
new gszChatFormats[ formatMax ][ FORMAT_MAX_SIZE ];
new gszFormatTeamTags[ SPEC + 1 ][ ALIVE + 1 ][ FORMAT_SMALL_MAX_SIZE ];
new gszAccesFlags[ FLAG_SEE_CHAT + 1 ][ 26 ];
new gszCustomTags[ ICHAT_MAX_PLAYERS + 1 ][ MAX_CUSTOM_TAGS ][ MAX_CUSTOM_TAGS_SIZE ];
new gszAuthid[ ICHAT_MAX_PLAYERS + 1 ][ 35 ];
new Trie:gtCustomFormats[ formatTypesMax ];
new Trie:gtCustomFormatEnabled[ formatTypesMax ];
new giRemoveOnSlash;
new giUserNotify;
new giAdminsSpy;
new giUseCustomColor;
new giRemoveNameChanged;
new giRed;
new giGreen;
new giBlue;
new giPunishment;
new giAllTalk;
new giUseCustomTags;
new giUseCustomFormats;
new giForceSimplePrint;
new giMustBeUpdated;
new giAllowStop;
new giAdminOverrides;
new Float:gFlPrintRadiusAll;
new Float:gFlPrintRadiusTeam;
new giCheckArray[ 3 ][ ICHAT_MAX_PLAYERS + 1 ];
#define SetUserFirstSpawn(%1) giCheckArray[0][%1]=1
#define ClearUserFirstSpawn(%1) giCheckArray[0][%1]=0
#define IsFirstSpawn(%1) giCheckArray[0][%1]
#define EnableUserChat(%1) giCheckArray[1][%1]=1
#define DisableUserChat(%1) giCheckArray[1][%1]=0
#define IsUserChatEnabled(%1) giCheckArray[1][%1]
#define SetUserVip(%1) giCheckArray[2][%1]=1
#define ClearUserVip(%1) giCheckArray[2][%1]=0
#define IsUserVip(%1) giCheckArray[2][%1]
new giLocation;
new gszLocation[ ICHAT_MAX_PLAYERS + 1 ][ FORMAT_SMALL_MAX_SIZE ];
new gMsgSayText;
new gMsgTeamInfo;
new giPluginIndex;
public plugin_init( )
{
giPluginIndex = register_plugin( "iChat", ICHAT_VERSION, "Kidev" );
iChatCheckErrors( );
register_dictionary( "iChat.txt" );
register_dictionary( "common.txt" );
gMsgSayText = get_user_msgid( "SayText" );
gMsgTeamInfo = get_user_msgid( "TeamInfo" );
#if defined USE_TEAM_FIX
gMsgScoreInfo = get_user_msgid( "ScoreInfo" );
#endif
register_message( gMsgSayText, "messageSayText" );
RegisterHam( Ham_Spawn, "player", "hamPlayerSpawnPost", 1 );
register_concmd( "amx_reload_ichat", "iChatReloadConfig" );
register_clcmd( "say", "iChatHookSay", 0 );
register_clcmd( "say_team", "iChatHookSay", 1 );
new szModShortName[ 7 ];
if ( get_modname( szModShortName, charsmax( szModShortName ) ) == 5
&& equal( szModShortName, "czero" ) )
{
register_event( "Location", "eventLocation", "be" );
}
register_event( "TeamInfo", "eventTeamInfoAll", "a" );
new iSutppCvar = register_cvar( "ichat_version", ICHAT_VERSION, FCVAR_SERVER | FCVAR_EXTDLL | FCVAR_SPONLY );
set_pcvar_string( iSutppCvar, ICHAT_VERSION );
new iFormatType;
for ( iFormatType = 0; iFormatType < formatTypesMax; iFormatType++ )
{
gtCustomFormats[ iFormatType ] = TrieCreate( );
gtCustomFormatEnabled[ iFormatType ] = TrieCreate( );
}
iChatConfig( );
}
public plugin_unpause( )
{
iChatPause( 1, "ad", "Hiba: Valaki megprobalta leallitani az iChatet. iChat leallt.", "" );
}
public iChatPause( iForcePause, const szFlags[ ], const szError[ ], const szWarning[ ] )
{
if ( giAllowStop || iForcePause )
{
log_amx( szError );
pause( szFlags );
}
else
{
log_amx( szWarning );
}
}
public iChatCheckErrors( )
{
new iPluginsNum;
if ( ( giPluginIndex + 1 ) < ( iPluginsNum = get_pluginsnum( ) ) )
{
log_amx( "The following plugins are called after iChat. You have to fix this." );
new i, szFileName[ 15 ], szStatus[ 15 ];
for ( i = ( giPluginIndex + 1 ); i < iPluginsNum; i++ )
{
if ( get_plugin( i, szFileName, charsmax( szFileName ), _, _, _, _, _, _, szStatus, charsmax( szStatus ) ) >= 0 )
{
log_amx( "[%d] %s is %s", ( i + 1 ), szFileName, szStatus );
}
else break;
}
iChatPause( 0, "ad", "HIBA: iChat nem az utolso a plugins.ini-ben. iChat leallt.", "FIGYELEM: Az iChat nem az utolso plugin a plugins.ini-ben." );
}
if ( is_plugin_loaded( "Admin Chat Colors" ) != -1 )
{
log_amx( "FIGYELEM: iChat ezt a plugint talalta 'Admin Chat Colors' ami eppen fut. A plugin leallitva." );
pause( "acd", "Admin Chat Colors" );
}
}
public iChatCheckUpdates( ) // Being worked on
{
new iOutdated = 0;
if ( iOutdated )
{
log_amx( "FIGYELEM: Az iChat egy regebbi verziojat hasznalod. Toltsd le a frissitest itt http://%s/%s", ICHAT_HOST, ICHAT_THREAD );
giMustBeUpdated = 1;
}
}
public plugin_natives( )
{
register_library( "iChat" );
register_native( "iChatSendCustomData", "iChatSendCustomData" );
register_native( "iChatVipAction", "iChatVipAction" );
}
public iChatReloadConfig( id )
{
if ( !has_flag( id, gszAccesFlags[ FLAG_RELOAD ] ) && gszAccesFlags[ FLAG_RELOAD ][ 0 ] )
{
client_print( id, print_console, "%L", id, "NO_ACC_COM" );
return PLUGIN_HANDLED;
}
iChatConfig( );
client_print( id, print_console, "[iChat] %L", id, "ICHAT_RELOADED" );
return PLUGIN_CONTINUE;
}
public iChatConfig( )
{
new szCfgFile[ 128 ];
get_configsdir( szCfgFile, charsmax( szCfgFile ) );
formatex( szCfgFile, charsmax( szCfgFile ), "%s/ichat.cfg", szCfgFile );
new iCfgFileHandle = fopen( szCfgFile, "rt" );
if ( !iCfgFileHandle )
{
set_fail_state( "No configuration file" );
return;
}
new szLineData[ 364 ], szLineKey[ 96 ], szLineValue[ 264 ];
while ( !feof( iCfgFileHandle ) )
{
fgets( iCfgFileHandle, szLineData, charsmax( szLineData ) );
trim( szLineData );
if ( szLineData[ 0 ] == ';' || szLineData[ 0 ] == '#' || ( szLineData[ 0 ] == '/' && szLineData[ 1 ] == '/' ) || !szLineData[ 0 ] )
{
continue;
}
parse( szLineData, szLineKey, charsmax( szLineKey ), szLineValue, charsmax( szLineValue ) );
switch ( szLineKey[ 0 ] )
{
case 'F':
{
switch ( szLineKey[ 7 ] )
{
case 'D':
{
switch ( szLineKey[ 11 ] )
{
case 'A':
{
if ( equal( szLineKey, "FORMAT_DEF_ALIVE" ) )
{
copy( gszChatFormats[ formatAllDefAlive ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "FORMAT_DEF_DEAD" ) )
{
copy( gszChatFormats[ formatAllDefDead ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
}
}
case 'A':
{
switch ( szLineKey[ 13 ] )
{
case 'A':
{
if ( equal( szLineKey, "FORMAT_ADMIN_ALIVE" ) )
{
copy( gszChatFormats[ formatAllAdminAlive ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "FORMAT_ADMIN_DEAD" ) )
{
copy( gszChatFormats[ formatAllAdminDead ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
}
}
case 'V':
{
switch ( szLineKey[ 11 ] )
{
case 'A':
{
if ( equal( szLineKey, "FORMAT_VIP_ALIVE" ) )
{
copy( gszChatFormats[ formatAllVIPAlive ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "FORMAT_VIP_DEAD" ) )
{
copy( gszChatFormats[ formatAllVIPDead ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
}
}
case 'T':
{
switch ( szLineKey[ 12 ] )
{
case 'D':
{
switch ( szLineKey[ 16 ] )
{
case 'A':
{
if ( equal( szLineKey, "FORMAT_TEAM_DEF_ALIVE" ) )
{
copy( gszChatFormats[ formatTeamDefAlive ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "FORMAT_TEAM_DEF_DEAD" ) )
{
copy( gszChatFormats[ formatTeamDefDead ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
}
}
case 'A':
{
switch ( szLineKey[ 18 ] )
{
case 'A':
{
if ( equal( szLineKey, "FORMAT_TEAM_ADMIN_ALIVE" ) )
{
copy( gszChatFormats[ formatTeamAdminAlive ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "FORMAT_TEAM_ADMIN_DEAD" ) )
{
copy( gszChatFormats[ formatTeamAdminDead ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
}
}
case 'V':
{
switch ( szLineKey[ 16 ] )
{
case 'A':
{
if ( equal( szLineKey, "FORMAT_TEAM_VIP_ALIVE" ) )
{
copy( gszChatFormats[ formatTeamVIPAlive ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "FORMAT_TEAM_VIP_DEAD" ) )
{
copy( gszChatFormats[ formatTeamVIPDead ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
}
}
}
}
case 'M':
{
switch ( szLineKey[ 10 ] )
{
case 'M':
{
if ( equal( szLineKey, "FORMAT_ME_MESSAGE" ) )
{
copy( gszChatFormats[ formatMeMessage ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
case 'C':
{
if ( equal( szLineKey, "FORMAT_ME_COMMAND" ) )
{
copy( gszChatFormats[ formatMeCommand ], charsmax( gszChatFormats[ ] ), szLineValue );
add( gszChatFormats[ formatMeCommand ], charsmax( gszChatFormats[ ] ), " " );
}
}
}
}
}
}
case 'C':
{
switch ( szLineKey[ 5 ] )
{
case 'C':
{
switch ( szLineKey[ 11 ] )
{
case 'R':
{
if ( equal( szLineKey, "CHAT_CLCMD_REMOVE" ) )
{
giRemoveOnSlash = str_to_num( szLineValue );
}
}
case 'C':
{
if ( equal( szLineKey, "CHAT_CLCMD_CLEAR" ) )
{
copy( gszChatFormats[ formatClearCommand ], charsmax( gszChatFormats[ ] ), szLineValue );
}
}
case 'U':
{
if ( equal( szLineKey, "CHAT_CHECK_UPDATES" ) )
{
if ( str_to_num( szLineValue ) == 1 )
{
giMustBeUpdated = 0;
iChatCheckUpdates( );
}
}
}
case 'O':
{
if ( equal( szLineKey, "CHAT_CAN_STOP_ITSELF" ) )
{
giAllowStop = str_to_num( szLineValue );
}
}
}
}
case 'F':
{
switch ( szLineKey[ 10 ] )
{
case 'R':
{
if ( equal( szLineKey, "CHAT_FLAG_RELOAD" ) )
{
if ( equal( szLineValue, "ALL" ) )
{
gszAccesFlags[ FLAG_RELOAD ][ 0 ] = 0;
}
else
{
copy( gszAccesFlags[ FLAG_RELOAD ], charsmax( gszAccesFlags[ ] ), szLineValue );
}
}
}
case 'S':
{
switch ( szLineKey[ 11 ] )
{
case 'P':
{
if ( equal( szLineKey, "CHAT_FLAG_SPY" ) )
{
if ( equal( szLineValue, "ALL" ) )
{
gszAccesFlags[ FLAG_SPY ][ 0 ] = 0;
}
else
{
copy( gszAccesFlags[ FLAG_SPY ], charsmax( gszAccesFlags[ ] ), szLineValue );
}
}
}
case 'E':
{
if ( equal( szLineKey, "CHAT_FLAG_SEE_CHAT" ) )
{
if ( equal( szLineValue, "ALL" ) )
{
gszAccesFlags[ FLAG_SEE_CHAT ][ 0 ] = 0;
}
else
{
copy( gszAccesFlags[ FLAG_SEE_CHAT ], charsmax( gszAccesFlags[ ] ), szLineValue );
}
}
}
}
}
case 'A':
{
if ( equal( szLineKey, "CHAT_FLAG_ADMIN" ) )
{
if ( equal( szLineValue, "ALL" ) )
{
gszAccesFlags[ FLAG_ADMIN ][ 0 ] = 0;
}
else
{
copy( gszAccesFlags[ FLAG_ADMIN ], charsmax( gszAccesFlags[ ] ), szLineValue );
}
}
}
case 'V':
{
if ( equal( szLineKey, "CHAT_FLAG_VIP" ) )
{
if ( equal( szLineValue, "ALL" ) )
{
gszAccesFlags[ FLAG_VIP ][ 0 ] = 0;
}
else
{
copy( gszAccesFlags[ FLAG_VIP ], charsmax( gszAccesFlags[ ] ), szLineValue );
}
}
}
case 'C':
{
if ( equal( szLineKey, "CHAT_FLAG_CHAT" ) )
{
if ( equal( szLineValue, "ALL" ) )
{
gszAccesFlags[ FLAG_CHAT ][ 0 ] = 0;
}
else
{
copy( gszAccesFlags[ FLAG_CHAT ], charsmax( gszAccesFlags[ ] ), szLineValue );
}
}
}
case 'L':
{
if ( equal( szLineKey, "CHAT_NO_COLORS" ) )
{
giForceSimplePrint = str_to_num( szLineValue );
}
}
}
}
case 'A':
{
switch ( szLineKey[ 11 ] )
{
case 'S':
{
if ( equal( szLineKey, "CHAT_ADMIN_SPY" ) )
{
giAdminsSpy = str_to_num( szLineValue );
}
}
case 'L':
{
if ( equal( szLineKey, "CHAT_ALL_TALK" ) )
{
giAllTalk = str_to_num( szLineValue );
}
}
case 'O':
{
if ( equal( szLineKey, "CHAT_ADMIN_OVERRIDES" ) )
{
giAdminOverrides = str_to_num( szLineValue );
}
}
}
}
case 'D':
{
if ( equal( szLineKey, "CHAT_DEFAULT_COLOR" ) )
{
new iColor = str_to_num( szLineValue );
if ( iColor < 0 || iColor > 255255255 )
{
giUseCustomColor = 0;
}
else
{
giUseCustomColor = 1;
giRed = iColor / 1000000;
iColor %= 1000000;
giGreen = iColor / 1000;
giBlue = iColor % 1000;
}
}
}
case 'P':
{
if ( equal( szLineKey, "CHAT_PUNISHMENT" ) )
{
giPunishment = str_to_num( szLineValue );
if ( giPunishment > 1 || giPunishment < 0 )
{
giPunishment = 1;
}
}
}
case 'N':
{
if ( equal( szLineKey, "CHAT_NOTIFY" ) )
{
giUserNotify = str_to_num( szLineValue );
}
}
case 'R':
{
switch ( szLineKey[ 12 ] )
{
case 'A':
{
if ( equal( szLineKey, "CHAT_RADIUS_ALL" ) )
{
gFlPrintRadiusAll = str_to_float( szLineValue );
}
}
case 'T':
{
if ( equal( szLineKey, "CHAT_RADIUS_TEAM" ) )
{
gFlPrintRadiusTeam = str_to_float( szLineValue );
}
}
case 'C':
{
if ( equal( szLineKey, "CHAT_REMOVE_CHANGE_NAME" ) )
{
giRemoveNameChanged = str_to_num( szLineValue );
}
}
}
}
case 'T':
{
switch ( szLineKey[ 14 ] )
{
case '1':
{
switch ( szLineKey[ 16 ] )
{
case 'A':
{
if ( equal( szLineKey, "CHAT_TEAM_TAG_1_A" ) )
{
copy( gszFormatTeamTags[ T ][ ALIVE ], charsmax( gszFormatTeamTags[ ][ ] ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "CHAT_TEAM_TAG_1_D" ) )
{
copy( gszFormatTeamTags[ T ][ DEAD ], charsmax( gszFormatTeamTags[ ][ ] ), szLineValue );
}
}
}
}
case '2':
{
switch ( szLineKey[ 16 ] )
{
case 'A':
{
if ( equal( szLineKey, "CHAT_TEAM_TAG_2_A" ) )
{
copy( gszFormatTeamTags[ CT ][ ALIVE ], charsmax( gszFormatTeamTags[ ][ ] ), szLineValue );
}
}
case 'D':
{
if ( equal( szLineKey, "CHAT_TEAM_TAG_2_D" ) )
{
copy( gszFormatTeamTags[ CT ][ DEAD ], charsmax( gszFormatTeamTags[ ][ ] ), szLineValue );
}
}
}
}
case '3':
{
if ( equal( szLineKey, "CHAT_TEAM_TAG_3" ) )
{
copy( gszFormatTeamTags[ SPEC ][ DEAD ], charsmax( gszFormatTeamTags[ ][ ] ), szLineValue );
}
}
}
}
case 'U':
{
switch ( szLineKey[ 16 ] )
{
case 'T':
{
if ( equal( szLineKey, "CHAT_USE_CUSTOM_TAGS" ) )
{
giUseCustomTags = str_to_num( szLineValue );
}
}
case 'F':
{
if ( equal( szLineKey, "CHAT_USE_CUSTOM_FORMATS" ) )
{
giUseCustomFormats = str_to_num( szLineValue );
}
}
}
}
}
}
}
}
fclose( iCfgFileHandle );
if ( giUseCustomFormats )
{
iChatCustomFormats( );
}
}
public iChatCustomFormats( )
{
new szIniFile[ 128 ];
get_configsdir( szIniFile, charsmax( szIniFile ) );
formatex( szIniFile, charsmax( szIniFile ), "%s/ichat_custom_formats.ini", szIniFile );
new iIniFileHandle = fopen( szIniFile, "rt" );
if ( !iIniFileHandle )
{
set_fail_state( "No custom formats file" );
return;
}
new szLineData[ 456 ], szLineKey[ 96 ], szLineKeyValue[ 96 ], szLineValue[ 264 ], iFormatType;
for ( iFormatType = 0; iFormatType < formatTypesMax; iFormatType++ )
{
TrieClear( gtCustomFormats[ iFormatType ] );
TrieClear( gtCustomFormatEnabled[ iFormatType ] );
}
while ( !feof( iIniFileHandle ) )
{
fgets( iIniFileHandle, szLineData, charsmax( szLineData ) );
trim( szLineData );
if ( szLineData[ 0 ] == ';' || szLineData[ 0 ] == '#' || ( szLineData[ 0 ] == '/' && szLineData[ 1 ] == '/' ) || !szLineData[ 0 ] )
{
continue;
}
parse( szLineData, szLineKey, charsmax( szLineKey ), szLineKeyValue, charsmax( szLineKeyValue ), szLineValue, charsmax( szLineValue ) );
if ( ( iFormatType = iChatGetFormatFromString( szLineKeyValue ) ) < 0 )
{
continue;
}
if ( ( equal( szLineKey, "STEAM_", 6 ) || equal( szLineKey, "BOT" ) ) && szLineValue[ 0 ] )
{
TrieSetString( gtCustomFormats[ iFormatType ], szLineKey, szLineValue );
TrieSetCell( gtCustomFormatEnabled[ iFormatType ], szLineKey, 1 );
}
}
fclose( iIniFileHandle );
}
public iChatGetFormatFromString( const szKey[ ] )
{
switch ( szKey[ 5 ] )
{
case 'L': return formatDefAlive;
case 'E': return formatDefDead;
case 'A': return formatTeamAlive;
case 'D': return formatTeamDead;
}
return -1;
}
public iChatHookSay( id, iTeamMessage )
{
return iChatGenerateMessage( id, iTeamMessage );
}
public iChatGenerateMessage( id, iTeamMessage )
{
if ( !is_user_connected( id ) || ( !has_flag( id, gszAccesFlags[ FLAG_CHAT ] ) && gszAccesFlags[ FLAG_CHAT ][ 0 ] ) )
{
return ICHAT_RETURN;
}
new szSaid[ ICHAT_MAX_SAID_LEN ], iSaidLen;
iSaidLen = charsmax( szSaid );
read_args( szSaid, charsmax( szSaid ) );
remove_quotes( szSaid );
trim( szSaid );
if ( iChatIsChatValid( szSaid ) )
{
iChatSendToHLSW( id, szSaid, iTeamMessage );
}
if ( !contain( szSaid, gszChatFormats[ formatMeCommand ] ) )
{
iChatMeCommand( id, szSaid, iSaidLen );
return ICHAT_RETURN;
}
if ( !contain( szSaid, gszChatFormats[ formatClearCommand ] ) )
{
iChatChangeChatStatus( id, IsUserChatEnabled( id ) );
return ICHAT_RETURN;
}
if ( ( !szSaid[ 0 ] )
|| ( ( giRemoveOnSlash && ( szSaid[ 0 ] == '/' || szSaid[ 0 ] == '@' || szSaid[ 0 ] == '!' ) ) || ( szSaid[ 0 ] == ' ' ) )
|| ( !IsUserChatEnabled( id ) ) )
{
return ICHAT_RETURN;
}
new iAlive = is_user_alive( id );
new szMessage[ ICHAT_MAX_MSG_LEN ], szColor[ 16 ], szTeam[ 16 ];
get_user_team( id, szTeam, charsmax( szTeam ) );
iChatFormatMessage( id, iAlive, iTeamMessage, 0, szMessage, charsmax( szMessage ), szColor, charsmax( szColor ) );
if ( giForceSimplePrint > 0 )
{
client_print( 0, print_chat, szMessage );
return ICHAT_RETURN;
}
new iGenCheck = ( giAllTalk && !iTeamMessage );
iChatChangeTeamInfo( id, szColor, iGenCheck );
if ( iGenCheck )
{
iChatMessageAll( id, szMessage, szSaid );
}
else
{
iChatMessageRest( id, iAlive, iTeamMessage, szMessage, szSaid );
}
iChatChangeTeamInfo( id, szTeam, iGenCheck );
return ICHAT_RETURN;
}
public iChatMeCommand( id, szSaid[ ], iSaidLen )
{
new szMessage[ ICHAT_MAX_MSG_LEN ], szColor[ 16 ], szTeam[ 16 ];
get_user_team( id, szTeam, charsmax( szTeam ) );
replace_all( szSaid, iSaidLen, gszChatFormats[ formatMeCommand ], " " );
trim( szSaid );
iChatFormatMessage( id, ALIVE, 0, 1, szMessage, charsmax( szMessage ), szColor, charsmax( szColor ) );
if ( giForceSimplePrint > 0 )
{
client_print( 0, print_chat, szMessage );
}
else
{
iChatChangeTeamInfo( id, szColor, 1 );
iChatMessageAll( id, szMessage, szSaid );
iChatChangeTeamInfo( id, szTeam, 1 );
}
}
public iChatChangeChatStatus( id, iEnabled )
{
if ( iEnabled )
{
if ( giForceSimplePrint > 0 )
{
client_print( id, print_chat, "[iChat] %L", id, "ICHAT_CHAT_DISABLED_NOC" );
}
else
{
iChatSimplePrint( id, "!g[iChat]!d %L", id, "ICHAT_CHAT_DISABLED" );
}
DisableUserChat( id );
}
else
{
EnableUserChat( id );
if ( giForceSimplePrint > 0 )
{
client_print( id, print_chat, "[iChat] %L", id, "ICHAT_CHAT_ENABLED_NOC" );
}
else
{
iChatSimplePrint( id, "!g[iChat]!d %L", id, "ICHAT_CHAT_ENABLED" );
}
}
}
public iChatFormatMessage( id, iAlive, iSayTeam, iMeCmd, szMessage[ ], iMessageLen, szColor[ ], iColorLen )
{
new szLife[ 16 ], iLife, iTeam;
iLife = get_user_health( id );
num_to_str( iLife, szLife, charsmax( szLife ) );
iTeam = get_user_team( id );
if ( iTeam < NONE || iTeam > SPEC )
{
iTeam = 0;
}
if ( iMeCmd )
{
copy( szMessage, iMessageLen, gszChatFormats[ formatMeMessage ] );
}
else
{
new iFormatType = ( iSayTeam ? ( ( iAlive || iTeam == TEAM_AA_1 || iTeam == TEAM_AA_2 ) ? formatTeamAlive : formatTeamDead ) : ( ( iAlive || iTeam == TEAM_AA_1 || iTeam == TEAM_AA_2 ) ? formatDefAlive : formatDefDead ) );
new iHasCustom = 0;
if ( giUseCustomFormats )
{
if ( TrieKeyExists( gtCustomFormatEnabled[ iFormatType ], gszAuthid[ id ] ) )
{
TrieGetCell( gtCustomFormatEnabled[ iFormatType ], gszAuthid[ id ], iHasCustom );
}
}
new iModeFormat = USER;
new iCrusher = ( giAdminOverrides ? ADMIN : VIP );
new iCrushed = ( giAdminOverrides ? VIP : ADMIN );
if ( iHasCustom )
{
iModeFormat = CUSTOM;
}
else if ( has_flag( id, gszAccesFlags[ ( iCrusher + 1 ) ] ) || !gszAccesFlags[ ( iCrusher + 1 ) ][ 0 ] )
{
iModeFormat = iCrusher;
}
else if ( has_flag( id, gszAccesFlags[ ( iCrushed + 1 ) ] ) || IsUserVip( id ) || !gszAccesFlags[ ( iCrushed + 1 ) ][ 0 ] )
{
iModeFormat = iCrushed;
}
switch ( iModeFormat )
{
case USER:
{
switch ( iFormatType )
{
case formatTeamAlive: copy( szMessage, iMessageLen, gszChatFormats[ formatTeamDefAlive ] );
case formatTeamDead: copy( szMessage, iMessageLen, gszChatFormats[ formatTeamDefDead ] );
case formatDefAlive: copy( szMessage, iMessageLen, gszChatFormats[ formatAllDefAlive ] );
case formatDefDead: copy( szMessage, iMessageLen, gszChatFormats[ formatAllDefDead ] );
}
}
case ADMIN:
{
switch ( iFormatType )
{
case formatTeamAlive: copy( szMessage, iMessageLen, gszChatFormats[ formatTeamAdminAlive ] );
case formatTeamDead: copy( szMessage, iMessageLen, gszChatFormats[ formatTeamAdminDead ] );
case formatDefAlive: copy( szMessage, iMessageLen, gszChatFormats[ formatAllAdminAlive ] );
case formatDefDead: copy( szMessage, iMessageLen, gszChatFormats[ formatAllAdminDead ] );
}
}
case VIP:
{
switch ( iFormatType )
{
case formatTeamAlive: copy( szMessage, iMessageLen, gszChatFormats[ formatTeamVIPAlive ] );
case formatTeamDead: copy( szMessage, iMessageLen, gszChatFormats[ formatTeamVIPDead ] );
case formatDefAlive: copy( szMessage, iMessageLen, gszChatFormats[ formatAllVIPAlive ] );
case formatDefDead: copy( szMessage, iMessageLen, gszChatFormats[ formatAllVIPDead ] );
}
}
case CUSTOM:
{
TrieGetString( gtCustomFormats[ iFormatType ], gszAuthid[ id ], szMessage, iMessageLen );
}
}
}
new szFormatTemp[ 64 ], iCustomTagsCount;
replace_all( szMessage, iMessageLen, "%TEAMTAG%", gszFormatTeamTags[ iTeam ][ iAlive ] );
if ( giUseCustomTags )
{
for ( iCustomTagsCount = 0; iCustomTagsCount < MAX_CUSTOM_TAGS; iCustomTagsCount++ )
{
formatex( szFormatTemp, charsmax( szFormatTemp ), "#CUSTOM%i#", iCustomTagsCount );
replace_all( szMessage, iMessageLen, szFormatTemp, gszCustomTags[ id ][ iCustomTagsCount ] );
}
}
if ( giForceSimplePrint <= 0 )
{
replace_all( szMessage, iMessageLen, "<default>", "^1" );
replace_all( szMessage, iMessageLen, "<green>", "^4" );
if ( contain( szMessage, "<red>" ) != -1 )
{
copy( szColor, iColorLen, "TERRORIST" );
}
else if ( contain( szMessage, "<blue>" ) != -1 )
{
copy( szColor, iColorLen, "CT" );
}
else if ( contain( szMessage, "<grey>" ) != -1 )
{
copy( szColor, iColorLen, "SPECTATOR" );
}
else
{
get_user_team( id, szFormatTemp, iColorLen );
copy( szColor, iColorLen, szFormatTemp );
}
replace_all( szMessage, iMessageLen, "<team>", "^3" );
replace_all( szMessage, iMessageLen, "<red>", "^3" );
replace_all( szMessage, iMessageLen, "<blue>", "^3" );
replace_all( szMessage, iMessageLen, "<grey>", "^3" );
}
replace_all( szMessage, iMessageLen, "%STEAMID%", gszAuthid[ id ] );
replace_all( szMessage, iMessageLen, "%LIFE%", szLife );
replace_all( szMessage, iMessageLen, "%POS%", giLocation ? gszLocation[ id ] : "" );
new szLangOpt[ 16 ];
formatex( szLangOpt, charsmax( szLangOpt ), "ICHAT_TEAM%i", iTeam );
formatex( szFormatTemp, charsmax( szFormatTemp ), "%L", LANG_SERVER, szLangOpt );
replace_all( szMessage, iMessageLen, "%TEAM%", szFormatTemp );
replace_all( szMessage, iMessageLen, "%NAME%", "%s1" );
replace_all( szMessage, iMessageLen, "%MESSAGE%", "%s2" );
}
public iChatMessageAll( id, const szMessage[ ], const szSaid[ ] ) // szMessage is safe, generated by OP or plugin. szSaid is unsafe, generated by client
{
message_begin( MSG_BROADCAST, gMsgSayText, .player = id );
write_byte( id );
write_string( szMessage );
write_string( "" );
write_string( szSaid );
message_end( );
}
public iChatMessageRest( id, iAlive, iTeamMessage, const szMessage[ ], const szSaid[ ] )
{
new iTeam = get_user_team( id );
new iPlayers[ ICHAT_MAX_PLAYERS ], iNum, tid, iPlayerCounter, iTempAlive, iTempTeam, iTeamCheck, iRadiusCheck, iCanSeeCheck, iSupercedeCheck;
get_players( iPlayers, iNum );
for ( iPlayerCounter = 0; iPlayerCounter < iNum; iPlayerCounter++ )
{
tid = iPlayers[ iPlayerCounter ];
if ( !( iSupercedeCheck = ( id == tid ) ) )
{
iTempAlive = is_user_alive( tid );
if ( iTeamMessage )
{
iTempTeam = get_user_team( tid );
}
iTeamCheck = ( !iTeamMessage || ( iTeam == iTempTeam ) );
iRadiusCheck = iChatIsInRadius( id, tid, iTeamMessage, iAlive, iTempAlive );
iCanSeeCheck = ( ( has_flag( tid, gszAccesFlags[ FLAG_SEE_CHAT ] ) || !gszAccesFlags[ FLAG_SEE_CHAT ][ 0 ] ) && IsUserChatEnabled( tid ) );
}
if ( ( iSupercedeCheck )
|| ( ( ( ( giAllTalk || ( iAlive && iTempAlive ) ) || ( !iAlive && !iTempAlive ) ) && iTeamCheck && iRadiusCheck && iCanSeeCheck )
|| ( giAdminsSpy && ( has_flag( tid, gszAccesFlags[ FLAG_SPY ] ) || !gszAccesFlags[ FLAG_SPY ][ 0 ] ) )
|| ( is_user_hltv( tid ) ) ) )
{
message_begin( MSG_ONE, gMsgSayText, .player = tid );
write_byte( id );
write_string( szMessage );
write_string( "" );
write_string( szSaid );
message_end( );
}
}
}
public iChatIsInRadius( iSender, iReceiver, iTeamMessage, iSenderAlive, iReceiverAlive )
{
new Float:flSenderOrigin[ 3 ], Float:flRecieverOrigin[ 3 ], Float:flDistance, Float:flMaxRadius;
pev( iSender, pev_origin, flSenderOrigin );
pev( iReceiver, pev_origin, flRecieverOrigin );
flDistance = get_distance_f( flSenderOrigin, flRecieverOrigin );
if ( iTeamMessage )
{
flMaxRadius = gFlPrintRadiusTeam;
}
else
{
flMaxRadius = gFlPrintRadiusAll;
}
if ( flDistance <= flMaxRadius || flMaxRadius <= 0 || !iSenderAlive || !iReceiverAlive )
{
return 1;
}
return 0;
}
public eventLocation( id )
{
giLocation = 1;
if ( read_data( 1 ) == id )
{
read_data( 2, gszLocation[ id ], charsmax( gszLocation[ ] ) );
}
}
public client_putinserver( id )
{
if ( giUserNotify )
{
set_task( NOTIFY_TASK_TIME, "iChatNotify", id + TASK_NOTIFY );
}
get_user_authid( id, gszAuthid[ id ], charsmax( gszAuthid[ ] ) );
SetUserFirstSpawn( id );
EnableUserChat( id );
}
public plugin_end( )
{
new iFormatType;
for ( iFormatType = 0; iFormatType < formatTypesMax; iFormatType++ )
{
TrieDestroy( gtCustomFormats[ iFormatType ] );
TrieDestroy( gtCustomFormatEnabled[ iFormatType ] );
}
}
public hamPlayerSpawnPost( id )
{
if ( giUseCustomColor && is_user_connected( id ) && !is_user_bot( id ) && IsFirstSpawn( id ) )
{
iChatAskChangeCvar( id );
}
ClearUserFirstSpawn( id );
}
public iChatAskChangeCvar( id )
{
new szMenuFormat[ 164 ], iLen = charsmax( szMenuFormat );
formatex( szMenuFormat, iLen, "%L", id, "ICHAT_MENU_TITLE", giRed, giGreen, giBlue );
new iAskMenu = menu_create( szMenuFormat, "iChatAskMenuHandler" );
new szMenuAction[ 16 ];
formatex( szMenuAction, charsmax( szMenuAction ), "ICHAT_MENU_ACTION%i", giPunishment );
formatex( szMenuFormat, iLen, "%L %L", id, "ICHAT_MENU_NO", id, szMenuAction );
menu_additem( iAskMenu, szMenuFormat );
formatex( szMenuFormat, iLen, "%L", id, "ICHAT_MENU_YES" );
menu_additem( iAskMenu, szMenuFormat );
menu_setprop( iAskMenu, MPROP_EXIT, MEXIT_NEVER );
menu_display( id, iAskMenu );
}
public iChatAskMenuHandler( id, iMenu, iItem )
{
if ( iItem == 1 )
{
client_cmd( id, "con_color ^"%i %i %i^"", giRed, giGreen, giBlue );
}
else if ( giPunishment )
{
server_cmd( "kick #%d ^"%L^"", get_user_userid( id ), id, "ICHAT_KICK_REASON" );
}
menu_destroy( iMenu );
}
public iChatIsChatValid( const szChat[ ] )
{
new cChar, iCharCounter;
while ( ( cChar = szChat[ iCharCounter++ ] ) != EOS )
{
if ( cChar != ' ' )
{
return 1;
}
}
return 0;
}
public iChatSendToHLSW( id, const szSaid[ ], iTeamMessage )
{
new szName[ 32 ], szTeam[ 10 ];
get_user_name( id, szName, charsmax( szName ) );
get_user_team( id, szTeam, charsmax( szTeam ) );
if( szTeam[ 0 ] == 'U' )
{
szTeam[ 0 ] = EOS;
}
log_message( "^"%s<%d><%s><%s>^" %s ^"%s^"%s", szName, get_user_userid( id ), gszAuthid[ id ], szTeam, ( iTeamMessage ? "say_team" : "say" ), szSaid, is_user_alive( id ) ? "" : " (dead)" );
}
public iChatChangeTeamInfo( id, const szColor[ ], iToAll )
{
message_begin( ( iToAll ? MSG_BROADCAST : MSG_ONE_UNRELIABLE ), gMsgTeamInfo, .player = id );
write_byte( id );
write_string( szColor );
message_end( );
}
public messageSayText( iMsgId, iMsgDest, iMsgEntity )
{
if ( giRemoveNameChanged )
{
new szMessage[ 196 ];
get_msg_arg_string( 2, szMessage, charsmax( szMessage ) );
if ( equal( szMessage, "#Cstrike_Name_Change" ) )
{
return PLUGIN_HANDLED;
}
}
return PLUGIN_CONTINUE;
}
public iChatNotify( id )
{
id -= TASK_NOTIFY;
if ( giForceSimplePrint > 0 )
{
client_print( id, print_chat, "[iChat] Ez a szerver iChatet hasznal, fejlesztoje Kidev. Letoltesi link a konzolban." );
}
else
{
iChatSimplePrint( id, "!g[iChat]!d a szerver iChatet hasznal !tiChat!d fejlesztoje !tKidev!d. Letoltesi link a konzolban." );
}
if ( giMustBeUpdated && ( has_flag( id, gszAccesFlags[ FLAG_RELOAD ] ) || !gszAccesFlags[ FLAG_RELOAD ][ 0 ] ) )
{
client_print( id, print_chat, "[iChat] FIGYELEM! iChat elavult! Ajanlott frissiteni!" );
}
client_print( id, print_console, "[iChat] Toltsd le az 'iChat'-et 'https://forums.alliedmods.net/showthread.php?t=173113'." );
client_print( id, print_console, "[iChat] Vagy githubon 'https://github.com/Kidev/iChat'" );
}
public iChatSimplePrint( id, const szMessage[ ], any:... ) // Do not use if clients are able to modify anything in the string passed !
{
new szBuffer[ 512 ];
vformat( szBuffer, charsmax( szBuffer ), szMessage, 3 );
replace_all( szBuffer, charsmax( szBuffer ), "!d", "^1" );
replace_all( szBuffer, charsmax( szBuffer ), "!t", "^3" );
replace_all( szBuffer, charsmax( szBuffer ), "!g", "^4" );
message_begin( MSG_ONE, gMsgSayText, .player = id );
write_byte( id );
write_string( szBuffer );
write_string( "" );
write_string( "" );
message_end( );
}
#if defined USE_TEAM_FIX
public eventTeamInfoAll( )
{
new id = read_data( TeamInfo_PlayerID );
if ( !is_user_alive( id ) && is_user_connected( id ) )
{
new iTeam = get_pdata_int( id, m_iTeam, XO_PLAYER );
if ( iTeam != get_user_team( id ) )
{
emessage_begin( MSG_BROADCAST, gMsgScoreInfo );
ewrite_byte( id );
ewrite_short( get_user_frags( id ) );
ewrite_short( get_pdata_int( id, m_iDeaths, XO_PLAYER ) );
ewrite_short( 0 );
ewrite_short( iTeam );
emessage_end( );
}
}
}
#endif
public iChatSendCustomData( iPlugin, iParams )
{
new iTagIndex = get_param( 2 );
new szData[ MAX_CUSTOM_TAGS_SIZE ];
get_string( 3, szData, charsmax( szData ) );
copy( gszCustomTags[ get_param( 1 ) ][ ( ( iTagIndex < 0 || iTagIndex >= MAX_CUSTOM_TAGS ) ? 0 : iTagIndex ) ], charsmax( gszCustomTags[ ][ ] ), szData );
}
public iChatVipAction( iPlugin, iParams )
{
new id = get_param( 1 );
switch ( get_param( 2 ) )
{
case 0: return IsUserVip( id );
case 1: return SetUserVip( id );
case 2: return ClearUserVip( id );
}
return -1;
}