

/* AMX Mod script.
*
* (c) Copyright 2002, OLO
* This file is provided as is (no warranties).
*
*/

/*  cvar:
*   set max. ping
*   amx_highping_max < value >
*
*   set in sec. how often the ping will be checked
*   amx_highping_time < value >
*
*   set min. number of checks before doing anything
*   amx_highping_tests < value >
*/

#include <amxmod>

new pping[33]
new psamples[33]

kick_player(id) {
	new name[33]
	get_user_name(id,name,32)
	client_print(0,print_chat,"[AMX] Player %s disconnected due to high ping.",name)
	client_cmd(id,"echo ^"[AMX] Bodoshi magram tqven gaikiket magali pingis gamo, try later...^";disconnect")
}

public check_ping(param[]){
	new id = param[0]
	new cping, closs
	get_user_ping(id,cping,closs)
	pping[id] += cping
	psamples[id]++
	if ((get_cvar_num("amx_highping_tests") < psamples[id]) && (get_cvar_num("amx_highping_max") < (pping[id] / psamples[id])))
			kick_player(id)
	return PLUGIN_CONTINUE
}

public client_putinserver(id){
	new Float:check_time = get_cvar_float("amx_highping_time")
	if (!is_user_bot(id)&&(check_time>0.0)){
		pping[id] = 0
		psamples[id] = 0
		new param[2]
		param[0] = id
		set_task(check_time,"check_ping",12345+id,param,2,"b")
	}
	return PLUGIN_CONTINUE
}

/* this is called only if player is put in server! (connect is not enough) */
public client_disconnect(id){
	if (!is_user_bot(id))
		remove_task(12345+id)
	return PLUGIN_CONTINUE
}

/* initialization */
public plugin_init(){
	register_plugin("High Ping Kicker","0.6","[SE]ErASor")
	register_cvar("amx_highping_max","250")
	register_cvar("amx_highping_time","10") /* check every 10 sec. */
	register_cvar("amx_highping_tests","12") /* so start kicking after 2 min. */
	return PLUGIN_CONTINUE
}


/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0\\ deftab720{\\ fonttbl{\\ f0\\ fswiss MS Sans Serif;}{\\ f1\\ froman\\ fcharset2 Symbol;}{\\ f2\\ fswiss\\ fcharset1 Tahoma;}{\\ f3\\ fswiss\\ fcharset1 Tahoma;}}\n{\\ colortbl\\ red0\\ green0\\ blue0;}\n\\ deflang1033\\ pard\\ plain\\ f2\\ fs16 \n\\ par }
*/
