/*
_ _ _______ _____ _ _ ____ _____ _______
/\ | \ | |__ __|_ _| | | | |/ __ \ / ____|__ __|
/ \ | \| | | | | | | |__| | | | | (___ | |
/ /\ \ | . ` | | | | | | __ | | | |\___ \ | |
/ ____ \| |\ | | | _| |_ | | | | |__| |____) | | |
/_/ \_\_| \_| |_| |_____| |_| |_|\____/|_____/ |_|
______ _____ _____ ____ _____
| ____| __ \| __ \ / __ \| __ \
| |__ | |__) | |__) | | | | |__) |
| __| | _ /| _ /| | | | _ /
| |____| | \ \| | \ \| |__| | | \ \
|______|_| \_\_| \_\\____/|_| \_\
//
Copyright © 2009, eXtreamCS #Dan
Anti Host Error is a free plugin used by AMX Mod X;
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 program 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.
# CHANGE LOG:
v. 1.0 - First Release ( 8 - MAY - 2009 )
# SITE:
http://www.eXtreamCS.com
# GOOD FOR NO:
- All host/game errors, one of them like svc_bad
- Reliable channel overflow
- Big latency, freezes and frecvently crashes
- Tweaking client & server side configuration
- Orphaned entities that cause svc_bad at next round
(Those will be killed by AHE -_^ )
# NOTE:
* This plugin do not guarantees you 100%, that the server
will be with-out any host/game bugs!
*/
#include <amxmodx>
#include <engine>
#include <cstrike>
#if AMXX_VERSION_NUM < 180
#assert AMX Mod X v.1.8.0 or newer is required to compile Anti Host Error (AHE) !
#endif
#define REQUIRED_PLAYERS 2
#define TIME_INTERVAL 0.2
#define PLAYERS_TO_KEEP 8
#define ENTITIES_TO_KILL 32
#define CONNECT_TIME 2.0
#define MAX_PLAYERS_JOIN 4
#define CUSTOM_HOSTNAME 0
#define USE_ALTERNATIVE_CONFIG 1
#define LAN_SERVER 0
#define IPX_SUPPORT 0
#define IP_v4_SUPPORT 0
#define BLOCK_CL_ALIAS 1
#define AHE_Start plugin_init
#define AHE_Modules plugin_modules
#define AHE_ClientConnected client_putinserver
#define AHE_ClientAuthentified client_authorized
#define AHE_ClientDropped client_disconnect
#define AHE_End plugin_end
new PLUGIN [/* PLUGIN NAME */] = "Anti Host Error";
new AUTHOR [/* PLUGIN AUTHOR */] = "eXtreamCS #Dan";
new VERSION [/* PLUGIN VERSION */] = "1.0";
new CVAR [/* VERSION CVAR STRING */] = "anti_hosterror";
#if CUSTOM_HOSTNAME==1
new HOSTNAME [/* SERVER NAME */] = "";
#endif
#if IP_v4_SUPPORT==1
new IP [/* IP v4 SUPPORT (XXX.XXX.XXX.XXX) */] = "";
new IP_CLIENTPORT [/* IP v4 SUPPORT (:27005) */] = "";
new IP_HOSTPORT [/* IP v4 SUPPORT (:27015) */] = "";
#endif
#if IPX_SUPPORT==1
new IPX_CLIENTPORT [/* IPX SUPPORT */] = "";
new IPX_HOSTPORT [/* IPX SUPPORT */] = "";
#endif
new /*CURRENT_PLAYERS,*/ CURRENT_TEAM, MAX_PLAYERS, PLAYERS_COUNT, PLAYERS_KEEP;
new MAX_ENTITIES, ENTITY_TO_DELETE, CSTRIKE_RUNNING;
new HLTV_START, ENTITY_DESTROYER, Float:HLTV_END;
new CONNECT_NUM, Float:CONNECT_T;
new CLIENT_PUT_IN_SERVER [/* Console */] = "* Anti Host Error will might change your configuration settings during game-play!";
new HLTV_START_MESSAGE [/* Chat */] = "* Anti Host Error is currently working on.";
new FAILED_LOAD_MODULES [/* Server */] = "* Anti Host Error is disabled. Check AMXX's modules file and folder!";
new SPEC [ 16 ]
/*
Anti Game / Host Error: SVC_BAD
http://developer.valvesoftware.com/wiki/NS_Variables
Server failed to transmit some messages
See more further information by running "cl_messages" command through console
*/
stock const AHE_Exec [][] = {
"sys_ticrate ^"1000^"",
"mp_decals ^"300^"",
"mp_dlmax ^"800^"",
"sv_resend ^"6^"",
"mp_updaterate ^"80^"",
"sv_cmdbackup ^"6^"",
"sv_cmdrate ^"80^"",
"sv_rate ^"20000^"",
"rate ^"20000^"",
"sv_maxunlag ^"1^"",
"sv_unlag ^"1^"",
"host_framerate ^"0^"",
"edgefriction ^"2^"",
"decalfrequency ^"60^"",
"sv_maxupdaterate ^"101^"",
"sv_maxspeed ^"999^"",
"sv_maxrate ^"7000^"",
"sv_allowupload ^"1^"",
"sv_clienttrace ^"1.0^"",
"sv_allowdownload ^1^"",
"sv_airaccelerate ^"10^"",
"sv_airmove ^"1^"",
"sv_timeout ^"22^"",
"mp_consistency ^"1^"",
#if LAN_SERVER==1
"sv_lan ^"1^"",
#else
"sv_lan ^"0^"",
#endif
#if BLOCK_CL_ALIAS==1
"alias ^"alias^"",
#endif
"sv_region ^"3^""
};
/*
Anti Reliable channel overflow
You have been disconnected from server. Reason: Reliable channel overflow.
http://supportwiki.steampowered.com/ro/Reliable_Channel_Overflow
*/
stock const Player_Exec [][] = {
"cl_updaterate ^"20^"",
"cl_cmdrate ^"30^"",
"rate ^"7500^"",
"cl_fixtimerate ^"7500^"",
"cl_cmdbackup ^"2^"",
"cl_rate ^"9999^"",
"cl_resend ^"6.0^"",
"fps_max ^"201^"",
"sys_ticrate ^"100^"",
"developer ^"0^"",
"cl_timeout ^"35^"",
"ex_interp ^"0.100^"",
"ex_extrapmax ^"1.200^"",
"ex_maxerrordistance ^"64^"",
"cl_dlmax ^"128^"",
"cl_smoothtime ^"0.1^"",
#if USE_ALTERNATIVE_CONFIG==1
"cl_cmdrate ^"65^"",
"cl_updaterate ^"30^"",
"ex_extrapmax ^"1.2^"",
"cl_cmdbackup ^"2^"",
"rate ^"15000^"",
"ex_interp ^"0.05^"",
#endif
"cl_nosmooth ^"0^""
};
/*
Registering the plugin
Setting plugin's version
Tweaking a little bit the configuration for IP / Port address
Registering the important events
*/
#if defined AHE_Start
public AHE_Start ( )
#else
public plugin_init ( )
#endif
{
register_plugin ( PLUGIN , VERSION , AUTHOR )
register_cvar ( CVAR , VERSION , FCVAR_SERVER & FCVAR_UNLOGGED & FCVAR_SPONLY )
set_cvar_string ( CVAR , VERSION )
server_cmd ( "alias ^"%s^"" , CVAR )
#if CUSTOM_HOSTNAME !=0
// server_cmd("hostname ^"^"")
#else
#if CUSTOM_HOSTNAME==1
set_cvar_string ( "hostname" , SERVER )
#endif
#endif
#if IP_v4_SUPPORT !=0
// server_cmd("ip ^"^"")
// server_cmd("ip_hostport ^"^"")
// server_cmd("ip_clientport ^"^"")
#else
#if IP_v4_SUPPORT==1
set_cvar_string ( "ip" , IP )
set_cvar_string ( "ip_hostport" , IP_HOSTPORT )
set_cvar_string ( "ip_clientport" , IP_CLIENTPORT )
#endif
#endif
#if IPX_SUPPORT !=0
// set_cvar_num("ipx_hostport", 0)
// set_cvar_num("ipx_clientport", 0)
#else
#if IPX_SUPPORT==1
set_cvar_string ( "ipx_hostport" , IPX_HOSTPORT )
set_cvar_string ( "ipx_clientport" , IPX_CLIENTPORT )
#endif
#endif
register_event ( "HLTV" , "AHE_NewRound" , "a" , "1=0" , "2=0" )
// register_event ( "GameStatus" , "AHE_EndRound" , "ab" , "1=2" )
register_event ( "SendAudio" , "AHE_EndRound" , "a" , "2&%!MRAD_terwin" )
register_event ( "SendAudio" , "AHE_EndRound" , "a" , "2&%!MRAD_ctwin" )
register_event ( "CurWeapon" , "AHE_NewRound" , "be" , "1=1", "2!29" )
register_event ( "TextMsg" , "AHE_NewRound" , "a" , "2&#Game_will_restart_in" )
register_event ( "TextMsg" , "AHE_NewRound" , "a" , "2&#Game_Commencing" )
register_message ( get_user_msgid("Health") , "AHE_NewRound" )
/* If flag is specified as 1, players connecting are also returned. */
// CURRENT_PLAYERS = get_playersnum()
MAX_PLAYERS = get_maxplayers ( )
MAX_ENTITIES = get_global_int ( GL_maxEntities )
CSTRIKE_RUNNING = get_modname ( "cstrike" , 7 )
CURRENT_TEAM = get_user_msgid ( "TeamInfo" )
copy ( SPEC , 15 , "SPECTATOR" )
set_msg_block ( 49 , BLOCK_SET )
return PLUGIN_CONTINUE
}
/*
Checking, veryfing the AMXX modules
This modules should be loaded automatically without any execution, ...
... but to ensure that the AHE can run it will require again.
*/
#if defined AHE_Modules
public AHE_Modules ( )
#else
public plugin_modules ( )
#endif
{
if ( !require_module ( "engine" ) && require_module ( "cstrike" ) ) {
server_print ( "%s" , FAILED_LOAD_MODULES )
return PLUGIN_HANDLED_MAIN
}
else if ( is_module_loaded ( "engine" ) != -1 && is_module_loaded ( "cstrike" ) != -1 ) return false
return PLUGIN_CONTINUE
}
/*
This is an event important.
When a player is joining into server, some tasks will begin to him ...
...in "background" (silently).
*/
#if defined AHE_ClientConnected
public AHE_ClientConnected ( id )
#else
public client_putinserver ( id )
#endif
{
for ( new i = 0 ; i <= MAX_PLAYERS ; i++ )
{
client_print ( i , print_console , "%s" , CLIENT_PUT_IN_SERVER )
if ( is_user_connected ( id ) && cs_get_user_team ( id ) == CS_TEAM_SPECTATOR )
return PLUGIN_HANDLED
else if ( is_user_connected ( i ) ) {// && is_user_alive(id)
if ( cs_get_user_team ( i ) == CS_TEAM_CT
|| cs_get_user_team ( i ) == CS_TEAM_T
|| cs_get_user_team ( i ) == CS_TEAM_UNASSIGNED )
{
set_task ( 31.5 , "AHE_DisplayMessage" , i )
return PLUGIN_CONTINUE
}
}
}
if ( !entity_get_int ( id , EV_INT_team ) )
return PLUGIN_CONTINUE
if ( get_gametime() - CONNECT_TIME > CONNECT_T )
CONNECT_NUM = 0
if ( CONNECT_NUM < MAX_PLAYERS_JOIN )
{
++CONNECT_NUM
if ( CONNECT_NUM == 1 )
CONNECT_T = get_gametime()
}
else
return PLUGIN_HANDLED
return PLUGIN_CONTINUE
}
#if defined AHE_ClientAuthentified
public AHE_ClientAuthentified ( id )
#else
public client_authorized ( id )
#endif
{
if ( is_user_connecting ( id ) )
{
message_begin ( MSG_ALL , CURRENT_TEAM )
write_byte ( id )
write_string ( SPEC )
message_end ( )
// ++MAX_PLAYERS
}
return PLUGIN_CONTINUE
}
#if defined AHE_ClientDropped
public AHE_ClientDropped ( id )
#else
public client_disconnect ( id )
#endif
{
if ( !is_user_connected ( id ) && ~task_exists ( id ) ) {
remove_task ( id )
return PLUGIN_HANDLED
// --MAX_PLAYERS
}
return PLUGIN_CONTINUE
}
public AHE_EndRound ( )
{
if ( !HLTV_START )
return
new PLAYERS_NUM = get_playersnum ( )
CONNECT_NUM = 0
CONNECT_T = get_gametime ( ) - CONNECT_TIME
HLTV_START = 0
HLTV_END = get_gametime ( )
for ( new SVR ; SVR < sizeof AHE_Exec ; SVR++ )
server_cmd ( AHE_Exec [ SVR ] )
for ( new ID = 0 ; /*ID < CURRENT_PLAYERS ;*/ ID < sizeof Player_Exec ; ID++ )
client_cmd ( ID , Player_Exec [ ID ] )
if ( !PLAYERS_KEEP && PLAYERS_NUM >= REQUIRED_PLAYERS )
set_task ( 5.9 - ( ( floatround ( float ( PLAYERS_NUM ) / float ( PLAYERS_TO_KEEP ) , floatround_ceil) - 1 ) * TIME_INTERVAL ) , "AHE_KeepPlayers" , 100 )
if ( !ENTITY_TO_DELETE )
{
ENTITY_TO_DELETE = MAX_PLAYERS + 1
ENTITY_DESTROYER = AHE_Target ( )
AHE_KillEntities ( )
}
set_task ( 6.0 , "AHE_BackupTime" , 300 )
}
public AHE_NewRound ( msgid , dest , id )
{
HLTV_START = 1
PLAYERS_KEEP = 0
PLAYERS_COUNT = 0
ENTITY_TO_DELETE = 0
if ( !is_user_alive ( id ) )
return PLUGIN_CONTINUE
static health
health = get_msg_arg_int ( 1 )
if ( health > 255 && ( health % 256 ) == 0 )
set_msg_arg_int ( 1 , ARG_BYTE , ++health )
set_cvar_num ( "sv_restart" , 0 )
set_cvar_num ( "sv_restartround" , 0 )
return PLUGIN_CONTINUE
}
public AHE_KeepPlayers ( )
{
for ( new id = PLAYERS_KEEP + 1; id <= MAX_PLAYERS; ++id )
{
if ( is_user_connected ( id ) )
{
PLAYERS_COUNT++
client_cmd ( id , "impulse 201" )
}
if ( PLAYERS_COUNT % PLAYERS_TO_KEEP == 0 )
break
PLAYERS_KEEP++
}
if ( PLAYERS_KEEP == MAX_PLAYERS )
{
PLAYERS_KEEP = 0
PLAYERS_COUNT = 0
}
else if ( get_gametime() - HLTV_END <= 7.0 )
set_task ( TIME_INTERVAL , "AHE_KeepPlayers" , 100 )
return PLUGIN_CONTINUE
}
public AHE_KillEntities ( )
{
if ( !is_valid_ent ( ENTITY_DESTROYER ) )
return
for ( new ENTITY_COUNT; ENTITY_TO_DELETE <= MAX_ENTITIES; ++ENTITY_TO_DELETE )
{
if ( !is_valid_ent ( ENTITY_TO_DELETE ) )
continue
new IUSER3 = entity_get_int ( ENTITY_TO_DELETE , EV_INT_iuser3 )
if ( ( IUSER3 == 15 && entity_get_edict ( ENTITY_TO_DELETE , EV_ENT_owner ) == 0 )
|| 24 <= IUSER3 <= 34
|| IUSER3 == 37
|| 41 <= IUSER3 <= 45
|| 47 <= IUSER3 <= 49
|| IUSER3 == 57 )
{
if ( ( CSTRIKE_RUNNING &&
( IUSER3 == 25 || IUSER3 == 26 ) ) )
continue
ENTITY_COUNT++
fake_touch ( ENTITY_DESTROYER , ENTITY_TO_DELETE )
remove_entity ( ENTITY_TO_DELETE )
}
else
continue
if ( ENTITY_COUNT == ENTITIES_TO_KILL )
break
}
if ( get_gametime() - HLTV_END <= 7.0
|| ENTITY_TO_DELETE != MAX_ENTITIES )
set_task( 0.3 , "AHE_KillEntities" , 200 )
else
{
ENTITY_TO_DELETE = 0
remove_entity ( ENTITY_DESTROYER )
}
}
public AHE_BackupTime ( )
{
remove_task ( 100 )
remove_task ( 200 )
return PLUGIN_HANDLED
}
public AHE_DisplayMessage ( id )
{
if ( is_user_alive ( id ) )
{
client_print ( id , print_chat , HLTV_START_MESSAGE )
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public AHE_Target ( )
{
new TARGET = create_entity ( "trigger_hurt" )
DispatchKeyValue ( TARGET , "classname" , "trigger_hurt" )
DispatchKeyValue ( TARGET , "dmg" , "19999" )
DispatchKeyValue ( TARGET , "damagetype" , "0" )
DispatchKeyValue ( TARGET , "origin" , "8192 8192 8192" )
DispatchSpawn ( TARGET )
entity_set_string( TARGET , EV_SZ_classname , "trigger_hurt" )
return TARGET
}
#if defined AHE_End
public AHE_End ( )
#else
public plugin_end ( )
#endif
{
if ( is_plugin_loaded ( "antiflood" ) == 1 && is_plugin_loaded ( "imessage" ) == 1 )
{
set_cvar_float ( "amx_flood_time" , 1.00 )
set_cvar_num ( "amx_freq_imessage" , 120 )
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/