/* Plugin generated by AMXX-Studio */

/*
Anti FastFire v1.2 by DarkSnow
This plugin will detect and ban cheaters using external application that screw up the tick counter for cs,
thus allowing nearly unlimmited speed in certain aspects. These cheaters may deplete a whole M249(machinegun)
in just a second. You have seen em, i have seen em - everyone have been disturbed by these cheaters.

Id like to point out that this is my second plugin and i would aprishiate any feedback on how you find
it usefull, if it works, how i may improve this plugin etc.

This plugin, just as my previous "Anti SpeedHack" plugin work to 100% with VAC2. It is untested with any
other forms of anti cheat but should run just fine.


Controll
There are 4 cvars;
"amx_af_max" | def.val=16 - Defines the maximum Bp/S a player may spray before ban
"amx_af" | def.val=1 - Activates or deactivates Anti FastFire where 1=On ; 0=Off
"amx_af_amxban" | def.val=0 - Use amxbans? (requires amxbans plugin) 1=On ; 0=Off
"amx_af_bantime" | def.val=30 - Ban users for how long? (requires amxbans plugin)


The Works
Just like my previous plugin, this one is just equaly simple. Basicly, all this plugin does is to cound how
many bullets per second (which we futher will call Bp/S) a player is currently spraying. If a players Bp/S
exeeds a certain value the plugin will administer a ban on that player, save a log entry and publicly announce
that the player have cheated.


Required modules
#include <amxmodx>
#include <amxmisc>

Is the plugin safe to use?
Yes, this script unlike my previous is very secure. You can trust this script to 100%. As refference,
i have also included in the readme file the complete list of all Bp/S values for all buyable weapons in CS.


WARNING!
If this program makes your milk in the fridge sour, kidnaps the u.s pressident (mr. george w bush jr aka
"sexual_animal" on various forums) and leaves a random note in your name to the secret service, starts
ww3 or anything unwanted - dont blaim me. In other words, by using this you agree to not sue me or any
similar B.S if anything goes wrong.
Common, im busting my ass doing this crapp and you want to break my legs just for the sake of it not working
propperly? If you dont like it, if it does not work - dont use it.

WARNING #2
I have not 100% tested it since the program i used to speed up the CS client also speeded up the dedicated
server equaly making it impossible for the server to know any timely difference. Im truly sory about that,
but as of right now i cant setup any other server so im hoping someone with the resources of doing so
will send me feedback about how it went.

You can speed up CS with the following application:
http://www.foredu.com/speed_up/

Sorry about posting a link to a application that may be used as a cheat, but its better to deal with a
problem instead of pretending it does not exists - right?


Credits
XxAvalanchexX - For posting most of what i made my codebase (http://www.amxmodx.org/forums/viewtopic.php?t=17725)
... and your truly, DarkSnow

Please send me any feedback, questions ect either on amxx forums (http://www.amxmodx.org/forums) or;
mathias.frendin@telia.com - msn
-Darkie
*/

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Anti FastFire"
#define VERSION "1.2"
#define AUTHOR "DarkSnow" //Respect ;)

#pragma tabsize 0
#define MAX_PLAYERS 32 

new countBullets[MAX_PLAYERS+1]
new g_amxban
new g_nCurWeapon[MAX_PLAYERS][2]
new g_MaxPlayers

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event( "CurWeapon", "Event_ShotFired",  "b" )
	register_cvar("amx_af_max","16")
	register_cvar("amx_af","1")
	register_cvar("amx_af_amxban", "0") //dissabled by default
	register_cvar("amx_af_bantime", "30")
	set_task(1.0, "checkBulletCount",127,_,_,"b")
}

public Event_ShotFired( id ) 
{ 
	new weaponID = read_data( 2 ) 
	new wAmmo = read_data( 3 ) 

	g_MaxPlayers = get_maxplayers()
	
	if( g_nCurWeapon[id-1][0] != weaponID ) // User Changed Weapons.. 
	{ 
		g_nCurWeapon[id-1][0] = weaponID 
		g_nCurWeapon[id-1][1] = wAmmo 
		return PLUGIN_CONTINUE 
	} 
	if( g_nCurWeapon[id-1][1] < wAmmo ) // User Reloaded.. 
	{ 
		g_nCurWeapon[id-1][1] = wAmmo 
		return PLUGIN_CONTINUE 
	} 
	if( g_nCurWeapon[id-1][1] == wAmmo ) // User did something else, but didn't shoot.. 
		return PLUGIN_CONTINUE 
	g_nCurWeapon[id-1][1] = wAmmo 
	g_nCurWeapon[id-1][0] = weaponID 

	countBullets[id]++ //Counting the bullets, one by one, all day long :)

	return PLUGIN_CONTINUE 
}  

public checkBulletCount()
{
	if (get_cvar_num("amx_af") == 1)
	{
		for(new i=1;i<=g_MaxPlayers;i++)
		{
			if(is_user_alive(i))
			{
				//client_print(i,print_chat,"%i",countBullets[i])
				if (countBullets[i] > get_cvar_num("amx_af_max"))
				{
					new Authid[35],Name[32],CurrentTime[29],Map[32],ping,loss,Message[256]
					//client_print(0,print_chat,"%i",countBullets[i])
					get_user_name(i,Name,31)
					get_user_authid(i,Authid,34)
					get_mapname(Map,31)
					get_user_ping(i,ping,loss)
					get_time("%d/%m-%Y - %H:%M:%S",CurrentTime,29)
					
					format(Message,255,"[Anti FastFire %s - %s] %s<%s> using FastFire type of cheat (Ping: %d )",CurrentTime,Map,Name,Authid,ping)
					log_amx(Message)

					client_print(0, print_chat, "%s booted by AF plugin.",Name)

					if (get_cvar_num("amx_af") == 0)
					{
						server_cmd("kick #%d Banned for cheating",get_user_userid(i))
						server_cmd("banid 0.0 %s",Authid)
						server_cmd("writeid")
					}
					else
					{
						server_cmd("amx_ban %i %s Banned for cheating", get_cvar_num("amx_af_bantime"), i)
					}
				}
			}
			countBullets[i] = 0
		}
	}
}
