/*********************************************************************************************
*						FFAC server side plugin v1.4
**********************************************************************************************
FFAChmp V1.4
hackziner : hackziner@gmail.com
FFAC Website : http://82.232.102.55/FFAC


Licence : CeCILL FREE SOFTWARE LICENSE AGREEMENT, there is a copy of the licence at the end of this file.

Use :
 Only run the plugin on your server. After the first player connection the server will be added to the server list
 No subscription require !

 	Features, ... :

	Global players stats  ( based on skill ) !
	FFA Team rank ( create a team with ffa player )
	Global CStats like rank ( based on Kill - Death ... )
	Servers stats ( graphs with connections by hours/day, total frag, ... )
	Show current skill,rank on a server
	Show top players of the serveur in motd
	Show your stats in motd
	Global Banlist
	Sentence log
	User can contact an admin on MSN through server/ffacmsnbot
	Map download from FFAC server 
	Package Manager 
	Package choice menu 
	Autoupdate
	Show if an admin is online, and explain how to contact througth msn if nobody is online
	No subscription require !

More informations, support, improvements, .... :
http://ufb.free.fr or http://82.232.102.55/FFAC/forum

	Cvar:
	ffac_showinfo ( default 1 ) : Show information ingame, like player skill ... ( commands are skill,ffac,score,allskill,ffac version )
	ffac_hudinfo ( default 0 ) : Show informations ( like skill ... ) in a hud message
	ffac_showpub ( default 1 ) : Show a little pub message for ffac every 180 secs
	ffac_ffacban ( default 1 ) : Use the FFAC banned steamid database
	ffac_skill_on_aim ( default 0 ) : show player level on aim ( eg Low/Middle/High )
	ffac_ban ( default 30 ) : Duration of a FFACBan in Min
	ffac_plog ( default 1 ) : Log sentence function ( when you say something with "log" inside, the sentence is logged and you can read it on the ffac website )
	ffac_msn_contact ( default "" ) : Set the msn adress for the ffac msn bot !
	ffac_ip_bind ( default "" ) : Set your public ip ( if you server is behind someting ... )
	ffac_autoupdate ( default 1 ) : enable autoupdate
	ffac_hpt ( default 1 ) : enable the packet manager
	
	Technicals Cvar :
	ffac_packetsize ( default 1024 ) :  Size of packets
	ffac_master_server ( default "82.232.102.55" ) : FFAC master server address
	
	admin commands :
	
	amx_ffac_ban <user id or steam id> : ban a player for amx_ffac_ffacban minuts, and repport the ban to the ffac server
	amx_ffac_map_download <map> : download a map from the ffac server on your server ! 
	amx_ffac_map_list : show the list of downloable maps
	amx_ffac_hpt_install <package> : Install a package on your server !
	amx_ffac_hpt_remove <package> : Remove a package 
	amx_ffac_hpt_menu : Show a menu with all packages available
	
	Players commands : ffac version,ffac changelog,skill,rank,topplayers,mystats,serverconnections,!log <sentence>,admin,!admin <message>,set nickname

	ffac version : display the ffac version
	ffac changelog : display ffac changelog
	serverconnections : show server connections stats in motd ( day & month )
	skill : show your skill
	/me : display your level
	admin : show number of admin online. If 0 and msn_contact set, explain the !admin command
	topplayers : show kill,deaths ... of all players in game
	mystats : show your stats ( kill, death, connections, online time, ... )
	rank : show your rank by skill and csstats ( global and server rank )
	!admin <message> : send a message to the msn contact ( on msn ^^ ) by the ffac msn bot
	!log <sentence> : Log a sentence ( you can view all your logged sentences on the ffac website )
	
	
	FFACBan :
	Ban player banned in the FFAC Database for 30 minute ! Not unlimited ban !
	
	
	Package manager syntax : 
	
	
	[Version]  // Check the require amx version 
	1.7
	[Download] // Download a file
	configs/hpt/remove_smallfun.hpt
	[Install] // Download and install a plugin
	plugins/spawnprotection.amxx
	spawnprotection.amxx

	
	Package : 
	smallfun ( amx_ffac_hpt_install smallfun ) ( this package contains, spawnprotection, bunnyhop and lastmanbets )
	sanksound ( amx_ffac_hpt_install sanksound ) ( this package contains sanksound plugin with sounds )
	matchdeluxe ( amx_ffac_hpt_install matchdeluxe ) ( this package contains amx_match_deluxe )
	...

	ToDo: 
	-stats improvement
	-few commands like online time, etcs
	-msn to server messages
	-autoupdate for all plugins
	-trombi/annuaire
	....
	
	Changelog:
	
	[21/4/2007] 1.4
	-allow multiple msn in msn_contact ( use  : ffac_msn_contact "msn@msn.com;msn2@msn.com" )
	-Extend max msn_contact size from 30 to 128 chars
	-Fix command display bug
	-Replace valve id lan or steam id lan by ip in the msn contact message
	-new natives for db_sys
	-indentation problems fix
	-multi language support
	-auto download language file if not found !
	-integration of the package manager in the amxmodmenu !
	-new say command : /me to display your level
	
	
	
	[6/5/2007] 1.3
	-amx_ffac_hpt_menu //Menu for install new plugin, autodownload the plugin list, ...
	-new comands to show server connections stats, say "serverconnections"
	-new commands to show changelog, say "ffac changelog"
	-new function to display player level on aim : set ffac_skill_on_aim 1
	-Some fix with the proxy

	[7/4/2007]	1.2
	-security fix ( package manager )
	-dynamic master server
	-new package matchdeluxe
	-now package manager and autoupdate are activate by default
	-spawn count fixed
	

*********************************************************************************************/

#include <amxmodx>
#include <amxmisc>
#include <sockets>

#define PLUGIN "FFAChmp\Tools"
#define VERSION "1.4"
#define AUTHOR "hackziner"

#define SOCKET_TASK 23233
#define SOCKET_PORT 19863

#define PUB_TASK 23234


#define HSPOINT 9

#define PUBLINE "FFAC commands : ffac version,ffac changelog,skill,rank,/me,topplayers,mystats,serverconnections"
#define PUBLINE1 "FFAC commands : !log <sentence>,!admin <message>,set nickname"

//Stats
new skill[33] 
new CDeath[33] //Death count
new CKill[33] //Kill count
new CHSG[33] //HS Giv
new CHST[33] //HS Tak
new SpawnCount[33]

//Stats display
new	RankSkill[33] //global rank by skill
new RankCSStats[33] //global rank by csstats
new	RankCSServer[33] //server rank by skill
new RankSkillServer[33] //server rank by csstats
new PlayerLastAim[33]

//V
new FFAReady[33]
new Server_ID

//Server
new port[16]
new thehostname[256]
new mapname[64]
new maxplayers

//Cvar
new ffac_showinfo
new ffac_hudinfo
new ffac_showpub
new ffac_skill_on_aim
new ffac_ffacban
new ffac_ffacban_duration
new ffac_plog
new ffac_autoupdate
new ffac_msn_contact[256]
new ffac_ip_bind[64]
new ffac_master_server[64]

//Packet Manager
new Amxmodx_version[8]
new PacketDataSize
new ActiveHpt
new HPTStatus
new HTPCurrentPacket[128]
new Item_Menu
new Item_MenuVal[32][32]

//Chaussette :)
new sckRemoteServer

//Packet manager
new MapDownSize // 0 = No download
new MapCurrentPacket
new MapCurrentPacketTO
new MapCurrentPacketTOF
new map[64]
new hpt_menu
new id_menu

//Native db sys
new ffac_db_sys
new registered_gvar[64]
new gvar_list[10][16]
new got_gvar[10][33][16]
new gvar_id

//Multilang support
new ffac_multi_lang

//global file support
new gbasedir[128]

public plugin_init() 
{
	new error, err[40]
	new cmd[256]
 
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
 	register_event("DeathMsg","death","a")
	register_event("ResetHUD", "client_spawn", "be")
	
	register_clcmd("fullupdate", "clcmd_fullupdate") 
	

	register_clcmd("say", "handle_say")
	
	//commands
	register_concmd("amx_ffac_ban","ffacban",ADMIN_LEVEL_B,"<authid, nick or #userid>")
	register_concmd("amx_ffac_map_download","MapDownload",ADMIN_LEVEL_B,"<mapname>")
	register_concmd("amx_ffac_map_list","MapList",ADMIN_LEVEL_B," List ffac donwloable maps")
	register_concmd("amx_ffac_hpt_install","hpt_install",ADMIN_LEVEL_B," <package name>")
	register_concmd("amx_ffac_hpt_remove","hpt_remove",ADMIN_LEVEL_B," <package name>")
	register_concmd("amx_ffac_hpt_menu","hpt_menur",ADMIN_LEVEL_B,"")
	
	//functions cvar
	register_cvar("ffac_showinfo","1") 
	register_cvar("ffac_hudinfo","0") 
	register_cvar("ffac_showpub","1") 
	register_cvar("ffac_skill_on_aim","0")
	register_cvar("ffac_ffacban","1",FCVAR_SERVER) 
	register_cvar("ffac_ffacban_duration","30",FCVAR_SERVER) 
	register_cvar("ffac_plog","1",FCVAR_SERVER)
	register_cvar("ffac_msn_contact","msn_adress")
	register_cvar("ffac_version",VERSION,FCVAR_SERVER)
	register_cvar("ffac_ip_bind","",FCVAR_SERVER)
	register_cvar("ffac_autoupdate","1",FCVAR_SERVER)	
	register_cvar("ffac_hpt","1",FCVAR_SERVER)
	register_cvar("ffac_db_sys","1",FCVAR_SERVER)
	register_cvar("ffac_multi_lang","0",FCVAR_SERVER)
	
	
	//tech Cvar
	register_cvar("ffac_packetsize","1024",FCVAR_SERVER)	
	register_cvar("ffac_master_server","82.232.102.55",FCVAR_SERVER)
	
	
	ffac_showinfo = get_cvar_num("ffac_showinfo")
	ffac_hudinfo= get_cvar_num("ffac_hudinfo")
	ffac_showpub= get_cvar_num("ffac_showpub")
	ffac_ffacban= get_cvar_num("ffac_ffacban")
	ffac_skill_on_aim = get_cvar_num("ffac_skill_on_aim")
	ActiveHpt= get_cvar_num("ffac_hpt")
	ffac_ffacban_duration= get_cvar_num("ffac_ffacban_duration")
	ffac_plog= get_cvar_num("ffac_plog")
	ffac_autoupdate = get_cvar_num("ffac_autoupdate")
	PacketDataSize=get_cvar_num("ffac_packetsize")
	ffac_db_sys=get_cvar_num("ffac_db_sys")
	ffac_multi_lang=get_cvar_num("ffac_multi_lang")
	
	get_cvar_string("hostname",thehostname,256) 
	get_cvar_string("port",port,15) 
	get_cvar_string("ffac_msn_contact",ffac_msn_contact,255) 
	get_cvar_string("amxmodx_version",Amxmodx_version,7)
	get_cvar_string("ffac_master_server",ffac_master_server,64) 
	get_cvar_string("ffac_ip_bind",ffac_ip_bind,64) 	
	
	get_mapname (mapname,64)
	maxplayers = get_maxplayers()
	MapDownSize=0 
	HPTStatus=0
	gvar_id=0
	
	get_basedir(gbasedir,127)
	format(cmd, 256,"%s/data/lang/ffac.txt",gbasedir)
	if (file_exists(cmd) && ffac_multi_lang==1)
		ffac_multi_lang=1
	else
		ffac_multi_lang=0
	
	if(ffac_multi_lang==1)
		register_dictionary ("ffac.txt")
	
	
	sckRemoteServer = socket_open(ffac_master_server,SOCKET_PORT, SOCKET_UDP,error)
	if(sckRemoteServer <= 0 || error)
			server_print("Couldn't connect to ffac/tools master server, error: %s",err)
			

			
	format(cmd, 256, "%s^"level!^"%s^"%s^"%s^"%d^"%s^"%s^"%d^"",VERSION,port,thehostname,mapname,maxplayers,ffac_msn_contact,ffac_ip_bind,ffac_autoupdate) 
	socket_send2(sckRemoteServer, cmd,255)
	set_task(0.05, "receive_info", SOCKET_TASK, "",0, "b")
	
	if (ffac_showpub)
		set_task(180.0, "website_pub", PUB_TASK, "",0, "b")
		

	
	AddMenuItem("FFAC package manager", "amx_ffac_hpt_menu", ADMIN_MENU, PLUGIN)
	
}

public plugin_end () 
{
	socket_close(sckRemoteServer)
	remove_task(SOCKET_TASK)

}



/******************************************************
Native-Native-Native-Native-Native-Native-Native-Native
******************************************************/

public plugin_natives()
{
	register_library("ffac_sys")
    
	register_native("ffac_get_skill","_ffac_get_skill")
//	register_native("ffac_register_gvar","_ffac_register_gvar")
//	register_native("ffac_set_player_gvar","_ffac_set_player_gvar")
//	register_native("ffac_get_player_gvar","_ffac_get_player_gvar")
}

public _ffac_get_skill(iPlugin,iParams)
{
	if(iParams != 1)
		return PLUGIN_CONTINUE
	new id = get_param(1)
	if(!id)
		return PLUGIN_CONTINUE	
	return skill[id]
}
/*
public _ffac_register_gvar(iPlugin,iParams)
{
	new gvar[16]
	if(iParams != 1)
		return PLUGIN_CONTINUE
	get_string(1,gvar,16)
	get_string(1,gvar_list[gvar_id],16)
	strcat(registered_gvar,gvar,64)
	gvar_id=gvar_id+1
	return PLUGIN_HANDLED
}
public _ffac_set_player_gvar(iPlugin,iParams)
{
	new gvar[16]
	new gvar_val[16]
	if(iParams != 1)
		return PLUGIN_CONTINUE
	new id = get_param(1)
	get_string(2,gvar,16)
	get_string(3,gvar_val,16)
	if(!id)
		return PLUGIN_CONTINUE	
	new  i
	for(i=0;i<11;i++)
		if (!strcmp(gvar_list[i],gvar,1))
			copy(got_gvar[i][id],16,gvar_val)
	return PLUGIN_HANDLED
}
public _ffac_get_player_gvar(iPlugin,iParams)
{
	new gvar[16]
//	if(iParams != 1)
//		return "ERROR_PARAM"
	new id = get_param(1)
	get_string(2,gvar,16)
//	if(!id)
//		return "ERROR_ID"	
	new  i
	for(i=0;i<11;i++)
		if (!strcmp(gvar_list[i],gvar,1))
			return got_gvar[i][id]
}
*/
/******************************************************
Native-Native-Native-Native-Native-Native-Native-Native
******************************************************/

public clcmd_fullupdate() {
    return PLUGIN_HANDLED
}

public client_putinserver(id)
{
	new szAuthID[33]
	new cmd[256]
	new szName[128]
	new szIP[64]
	
	get_user_authid(id,szAuthID,32)
	get_user_ip(id,szIP,64)
	get_user_name(id,szName,128)
 
	format(cmd, 256, "%s^"Score?^"%s^"%d^"%s^"%s^"%s^"%s^"",VERSION, szAuthID,id,szIP,port,szName,registered_gvar) 
	socket_send2(sckRemoteServer, cmd,255)
	FFAReady[id]=0

}

public client_disconnect(id)
{
	new cmd[256]
	new szAuthID[33]
	new szIP[64]
	get_user_ip(id,szIP,64)
	new ConnectTime
	ConnectTime = get_user_time(id)
	if(FFAReady[id])
	{
		get_user_authid(id,szAuthID,32)
		format(cmd, 256, "%s^"Score!^"%s^"%d^"%d^"%d^"%d^"%d^"%d^"%d^"%d^"%s^"",VERSION, szAuthID,skill[id],CDeath[id],CKill[id],ConnectTime,id,CHSG[id],CHST[id],SpawnCount[id],szIP) 
		socket_send2(sckRemoteServer, cmd,255)
	}
	FFAReady[id]=0
	skill[id]=0
	CKill[id]=0
	CDeath[id]=0
	CHSG[id]=0
	CHST[id]=0
	RankSkill[id]=0
	RankCSStats[id]=0
	RankCSServer[id]=0
	RankSkillServer[id]=0
	SpawnCount[id]=0

}

public death ()
{
  /*
  Skill calculation
  There are some server side skill checks. A server can give skill. If a player win 9 points an other MUST lost 9 points !
  You "can" change the calculation, but if you do a "bad calculation" you'll banned from ffac.
  */

	new killer
	new victim
	killer = read_data(1)
	victim = read_data(2)
	if(FFAReady[killer] && FFAReady[victim])
	{
		new scoredif
		new Float:scoreratio
		new Float:scorefinal  
		new score_num

		scoredif = skill[victim]-skill[killer] 
		if (scoredif>0)
		{
			scoredif=scoredif+1000
			scoreratio = floatlog(float(scoredif)) 
			scoreratio = floatpower(scoreratio, 2.5)
			scorefinal = floatmul(scoreratio, 4.5)
		}
		else
		{
			scorefinal = 60.0
		}
		score_num=floatround(scorefinal)
		skill[killer] = skill[killer]+score_num
		skill[victim] = skill[victim]-score_num
		CDeath[victim]=CDeath[victim]+1
		CKill[killer]=CKill[killer]+1
		if (ffac_showinfo)
		{	
		if	(ffac_multi_lang==1)
		{
			client_print(killer,print_chat,"FFAC : %d %L",score_num,LANG_PLAYER,"PT_WON")
			client_print(victim,print_chat,"FFAC : %d %L",score_num,LANG_PLAYER,"PT_LOST")
		}
		else
		{
			client_print(killer,print_chat,"FFAC : %d Points won",score_num)
			client_print(victim,print_chat,"FFAC : %d Points lost",score_num)
		}
		
		}
	}
	return PLUGIN_CONTINUE 
}
 
public  client_damage ( attacker, victim, damage, wpnindex, hitplace, TA )
{
	if (hitplace == 1 ) //Headshot
	{
		skill[attacker] = skill[attacker]+HSPOINT
		skill[victim] = skill[victim]-HSPOINT
		CHSG[attacker]=CHSG[attacker]+1
		CHST[victim]=CHSG[victim]+1
		if (ffac_showinfo)
		{	
			if	(ffac_multi_lang==1)
			{
				client_print(attacker,print_chat,"FFAC : HeadShot, 9 %L !",LANG_PLAYER,"PT_WON")
				client_print(victim,print_chat,"FFAC : HeadShot, 9 %L !",LANG_PLAYER,"PT_LOST")
			}
			else
			{
				client_print(attacker,print_chat,"FFAC : HeadShot, 9 points Won !")
				client_print(victim,print_chat,"FFAC : HeadShot, 9 points Lost !")
			}
		}
		if (ffac_hudinfo)
		{	
			set_hudmessage(255, 0, 0, 0.43, 0.77, 0, 6.0, 12.0)
			show_hudmessage(attacker, "Head Shoot ^n9 Points Won !")
			set_hudmessage(255, 0, 0, 0.43, 0.77, 0, 6.0, 12.0)
			show_hudmessage(victim, "Head Shoot ^n9 Points lost !")
			
		}
	} 
	
	return PLUGIN_CONTINUE 	
}
 
public	client_spawn ( id )
{
	if(FFAReady[id])
	{
		SpawnCount[id]=SpawnCount[id]+1
	}
} 

public MapDownload(id,level,cid) {
	if (!cmd_access(id,level,cid,2)) 
		return PLUGIN_HANDLED 
	new arg[32]
	read_argv(1, arg, 31)
	new cmd[256]
	new basedir[128]
	new mapdir[128]
	
	get_basedir(basedir,127)
	
	if(containi(arg,".bsp") == -1) 
		{
		format(mapdir, 127, "%s/../../maps/%s.bsp",basedir,arg) 
		format(cmd, 256, "%s*GetFile!*../../maps/%s.bsp*",VERSION, arg) 
		socket_send2(sckRemoteServer, cmd,255)
		client_print(0,print_chat,"Server download : %s",arg)

		}
	else
		{
		format(mapdir, 127, "%s/../../maps/%s",basedir,arg) 
		format(cmd, 256, "%s*GetFile!*../../maps/%s*",VERSION, arg) 
		socket_send2(sckRemoteServer, cmd,255)
		client_print(0,print_chat,"Server download : %s",arg)
		}
	return PLUGIN_HANDLED 	
	
} 

public hpt_menur(id,level,cid){
	new cmd[256]
	id_menu = id
	format(cmd, 256, "%s*GetPackageList!*Morgoth Catin :)*",VERSION) 
	socket_send2(sckRemoteServer, cmd,255)
	client_print(id,print_chat,"Server'll get the packages list !")
	hpt_menu = menu_create("\rFFAC Package Manager : Install Mode", "menu_handler")
	Item_Menu=0
	return PLUGIN_CONTINUE
}

public menu_handler(id, menu, item)
{
	new cmd[256]
	
	if (item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}
	new data[6], iName[64]
	new access, callback
	menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)	
	format(cmd, 256, "amx_ffac_hpt_install %s",Item_MenuVal[str_to_num(data)]) 
	client_print(id_menu,print_chat,"Command from menu %s",cmd)
	server_cmd(cmd)
	menu_destroy(menu)
	return PLUGIN_CONTINUE
}
public hpt_show_menu()
{
	menu_display(id_menu, hpt_menu, 0)
	return PLUGIN_HANDLED
}

public hpt_install(id,level,cid){
	if (!cmd_access(id,level,cid,2)) 
		return PLUGIN_HANDLED 
	if (ActiveHpt==1)
	{
	new arg[32]
	read_argv(1, arg, 31)
	new cmd[256]
	new basedir[128]
	new ddir[128]
	get_basedir(basedir,127)
	format(ddir, 127, "%s/configs/hpt/",basedir) 
	

	if(dir_exists ( ddir ) ==0)
		mkdir (ddir)
	
	HPTStatus=1
	format(cmd, 256, "%s*GetFile!*configs/hpt/%s.hpt*",VERSION, arg) 
	socket_send2(sckRemoteServer, cmd,255)
	client_print(0,print_chat,"Install Package: %s",arg)

	
	format(HTPCurrentPacket, 127, "%s/configs/hpt/%s.hpt",basedir,arg)
	}
	else
	{
		client_print(0,print_chat,"Package manager is disabled, set cvar ffac_apt 1 to enable it")
	}
	
	return PLUGIN_HANDLED

}

public hpt_remove(id,level,cid){
	if (!cmd_access(id,level,cid,2)) 
		return PLUGIN_HANDLED 
	new arg[32]
	read_argv(1, arg, 31)
	new basedir[128]
	
	get_basedir(basedir,127)
	
	HPTStatus=3
	format(HTPCurrentPacket, 127, "%s/configs/hpt/remove_%s.hpt",basedir,arg)
	client_print(0,print_chat,"Remove Package: %s",arg)
	packet_manager()
	return PLUGIN_HANDLED

}

public MapList(id) {
	new cmd[128]
	formatex(cmd, 127,"http://82.232.102.55/public/maps.txt")
	show_motd(id, cmd, "FFAC http://82.232.102.55/FFAC")
}

public ffacban(id,level,cid) 
{ 
	if (!cmd_access(id,level,cid,2)) 
		return PLUGIN_HANDLED 
	new cmd[128]
	new szAuthID[33]

	if (ffac_ffacban)
	{
		get_user_authid(id,szAuthID,32)
		server_cmd("amx_ban %c%s%c %d FFACBan",'"',cid,'"',ffac_ffacban_duration)
		format(cmd, 128, "%s^"FFACBAN!^"%s^"%s^"%d^"",VERSION, cid,szAuthID,ffac_ffacban_duration) 
		socket_send2(sckRemoteServer, cmd,128)
	}
	return PLUGIN_CONTINUE
}
public website_pub() 
{
	new i
	for(i=1;i<33;i++)
		{
		if (FFAReady[i]==1)
			{
			if	(ffac_multi_lang==1)
				client_print(i,print_chat,"%L : http://82.232.102.55/FFAC",LANG_PLAYER,"FFAC_TAKE_PART")
			else
				client_print(i,print_chat,"This server takes part in the FFAC Championship : http://82.232.102.55/FFAC")
			client_print(i,print_chat,PUBLINE)
			client_print(i,print_chat,PUBLINE1)
			}
		}
}	

public receive_info() 
{
 	new len
	new recv[1536]
	new cmdb[256]
	len=0
	
	if(MapDownSize>0)
		MapCurrentPacketTO=MapCurrentPacketTO+1
	if(MapCurrentPacketTO>5)
	{
		format(cmdb, 256, "%s*GetFileData!*%s*%d*%d*",VERSION, map,MapCurrentPacket,PacketDataSize ) 
		socket_send2(sckRemoteServer, cmdb,256 )
		MapCurrentPacketTO=0
		MapCurrentPacketTOF=MapCurrentPacketTOF+1
		if(MapCurrentPacketTOF>25)
			MapDownSize=0
	}
	
	if (socket_change(sckRemoteServer,1))
		len=socket_recv(sckRemoteServer, recv,1536)
		
	if (len > 8 ) 
	{
		new string_id[64]
		new string_type[64]
		new string_score[64]
		new string_sid[512]
		new string_a[128]
		new string_b[1300]
		strtok(recv,string_a,127,string_b,1299,'+')
		strtok(string_a,string_id,63,string_type,63,'*')
		strtok(string_b,string_score,63,string_sid,511,'*')

		if(  containi(string_score, "BANNED") != -1 )
		{
			client_print(str_to_num(string_id),print_chat,"FFAC : Your are BANNED from FFAC server, more info : http://82.232.102.55/FFAC")
			if (ffac_ffacban)
				server_cmd("amx_ban %c%s%c %d FFACBan",'"',string_sid,'"',ffac_ffacban_duration)
		}
		if(  containi(string_type, "ID_SERV") != -1 )
		{
			Server_ID = str_to_num(string_id)	
			if (ffac_autoupdate ==1)
			{
				if (containi(recv,VERSION)==-1)
				{
					server_cmd("amx_ffac_hpt_install ffachmp") //autoupdate
				}
				else
				{
					if (get_cvar_num("ffac_multi_lang")==1 && ffac_multi_lang==0 )
					{
						format(cmdb, 256, "%s*GetFile!*data/lang/ffac.txt*",VERSION) 
						socket_send2(sckRemoteServer, cmdb,255)
					}
				}
			}
		}
		if(  containi(string_type, "RANKPLAYERA") != -1 )
		{
			RankSkill[str_to_num(string_id)]=str_to_num(string_score)
			RankCSStats[str_to_num(string_id)]=str_to_num(string_sid)
			client_print(str_to_num(string_id),print_chat,"Rank on FFAC : %d by Skill, %d by Score",RankSkill[str_to_num(string_id)],RankCSStats[str_to_num(string_id)])		
		}
		if(  containi(string_type, "RANKPLAYERS") != -1 )
		{
			RankCSServer[str_to_num(string_id)]=str_to_num(string_sid)
			RankSkillServer[str_to_num(string_id)]=str_to_num(string_score)
			client_print(str_to_num(string_id),print_chat,"Server Rank : %d by Skill, %d by Score",RankSkillServer[str_to_num(string_id)],RankCSServer[str_to_num(string_id)])
		}
		if(  containi(string_type, "SAYPLAYER") != -1 )
		{
			client_print(str_to_num(string_id),print_chat,"%s",string_a)
		}		
		
		if(  containi(string_type, "SEND") != -1 )
		{
			skill[str_to_num(string_id)]=str_to_num(string_score)
			FFAReady[str_to_num(string_id)]=1
			if (ffac_showinfo)
			{
				if	(ffac_multi_lang==1)
					client_print(str_to_num(string_id),print_chat,"FFAC : Score loaded : %d ",str_to_num(string_score))
				else
					client_print(str_to_num(string_id),print_chat,"FFAC : %L : %d ",LANG_PLAYER,"SCORE_LOADED",str_to_num(string_score))
				
			}	
		}
		if(  containi(string_type, "PACKAGELIST") != -1 )		
		{
			new val[4]
			format(val,4,"%d",Item_Menu);
			menu_additem(hpt_menu,string_score ,val , ADMIN_BAN)
			copy(Item_MenuVal[Item_Menu],32,string_id)
			Item_Menu=Item_Menu+1
		}
		if(  containi(string_type, "PACKAGEENDLIST") != -1 )
		{
			hpt_show_menu()
		}
		if(  containi(string_type, "MAPINFO") != -1 )
		{
			new cmd[256]
			new basedir[128]
			new dire[128]
			get_basedir(basedir,127)
			MapCurrentPacketTOF=0
			format(dire, 127, "%s/%s",basedir,string_id) 
			MapDownSize=str_to_num(string_score) //Get size in o
			
			
			if (file_exists(dire)==1)
			{
				if (filesize(dire)==MapDownSize)
				{
					server_print ( "%s is already up to date ! ",string_id )
					client_print(0,print_chat," %s is already up to date",string_id)
					MapDownSize=0
					if (HPTStatus==1)
						HPTStatus=2
					if (HPTStatus==4)
					{
						HPTStatus=3
						packet_manager()
					}
				}
				else
				{
					delete_file(dire)
					server_print ( "Server start the upgrade of %s : size : %do",string_id,MapDownSize )
					client_print(0,print_chat,"Server start the upgrade of %s : size : %do",string_id,MapDownSize)
					MapCurrentPacket=0
					format(cmd, 256, "%s*GetFileData!*%s*0*%d*",VERSION, string_id,PacketDataSize)
					socket_send2(sckRemoteServer, cmd,255)
					if (HPTStatus==1)
						HPTStatus=2
				}
			}
			else
			{
				server_print ( "Server start the download of %s : size : %do",string_id,MapDownSize )
				client_print(0,print_chat,"Server start the download of %s : size : %do",string_id,MapDownSize)
				MapCurrentPacket=0
				format(cmd, 256, "%s*GetFileData!*%s*0*%d*",VERSION, string_id,PacketDataSize)
				socket_send2(sckRemoteServer, cmd,255)
				if (HPTStatus==1)
					HPTStatus=2
			}
		}
		if(  containi(string_type, "MAPDATA") != -1 )
		{
			new cmd[256]
			new basedir[128]
			new mapdir[128]
			new headerl[64]
			new Cursor
			new i
			MapCurrentPacketTOF=0
			strtok(string_id,headerl,63,map,63,'!')
			get_basedir(basedir,127)
			format(mapdir, 127, "%s/%s",basedir,map) 			 
			
			Cursor = str_to_num(string_score)
			server_print ( "Server Get data from %d to %d of %s ( header %d bytes) ",Cursor,Cursor+PacketDataSize,map,str_to_num(headerl) )

			if (Cursor == MapCurrentPacket )
			{
				new mapfile = fopen(mapdir,"ab+")
				fseek ( mapfile,SEEK_END  , 0)
				if ((MapDownSize-Cursor)<PacketDataSize )
				{	
					for(i = 0 ; i < MapDownSize-Cursor ; i++)
						fputc(mapfile, recv[str_to_num(headerl)+i])
					server_print ( "File Downloaded ! : %s",map )
					client_print(0,print_chat,"File Downloaded ! : %s",map  )
					set_hudmessage(255, 0, 0, 0.46, 0.17, 0, 6.0, 6.0)
					show_hudmessage(0, "%s Downloading^n Completed !",map)	
					MapDownSize=0
					if (HPTStatus==2 || HPTStatus==4 )
					{	
						HPTStatus=3
						server_print ( "Run packet installer !" )
						client_print(0,print_chat,"Run packet installer !"  )
						fclose(mapfile)
						packet_manager()
					
					}	
				}
				else
				{
					for(i = 0 ; i < PacketDataSize ; i++)
						fputc(mapfile, recv[str_to_num(headerl)+i])
					format(cmd, 256, "%s*GetFileData!*%s*%d*%d*",VERSION, map,Cursor+PacketDataSize,PacketDataSize ) //Ask the first block of 512 o of the map 
					MapCurrentPacket=Cursor+PacketDataSize
					socket_send2(sckRemoteServer, cmd,256 )
					MapCurrentPacketTO=0
					if (random(3)==2)
						{
						set_hudmessage(255, 0, 0, 0.46, 0.17, 0, 6.0, 2.0)
						show_hudmessage(0, "%s Downloading^n %dKo/%dKo Done",map,Cursor/1024,MapDownSize/1024)
						}
					fclose(mapfile)
				}
			}
			
		}
	}
	return PLUGIN_CONTINUE
}

public packet_manager(){

	if (ActiveHpt==1 && HPTStatus==3)
	{
		new line;
		new rien;
		new readline[128];
		new cmd[128];
		new extr[128];
		line=0
		new basedir[128]
		get_basedir(basedir,127)
		
		line= read_file(HTPCurrentPacket,line,readline,127,rien)
		while ( line>0 )
		{
			if (containi(readline,"[Done]")==-1)
			{
				
				if (containi(readline,"[Download]")!=-1)
				{
					write_file(HTPCurrentPacket,"[Done]",line-1)
					HPTStatus=4
					line= read_file(HTPCurrentPacket,line,extr,128,rien)
					write_file(HTPCurrentPacket,"[Done]",line-1)
					format(cmd, 256, "%s*GetFile!*%s*",VERSION,extr) 
					socket_send2(sckRemoteServer, cmd,255)
					client_print(0,print_chat,"Packet manager get : %s",extr)
					return PLUGIN_HANDLED 
				}
				if (containi(readline,"[Version]")!=-1)
				{
					write_file(HTPCurrentPacket,"[Done]",line-1)
					line= read_file(HTPCurrentPacket,line,extr,128,rien)
					write_file(HTPCurrentPacket,"[Done]",line-1)
					if (containi(Amxmodx_version,extr)==-1)
					{
						client_print(0,print_chat,"Wrong Amxmodx version, please check last version on http://www.amxmodx.org")
						HPTStatus=0
						client_print(0,print_chat,"Installation stopped")
						return PLUGIN_HANDLED 
					}
					client_print(0,print_chat,"Packet manager get : %s",extr)
					
				}
				if (containi(readline,"[MkDir]")!=-1)
				{
					write_file(HTPCurrentPacket,"[Done]",line-1)
					line= read_file(HTPCurrentPacket,line,extr,128,rien)
					write_file(HTPCurrentPacket,"[Done]",line-1)
					if(dir_exists ( extr ) ==0)
						mkdir (extr)
					client_print(0,print_chat,"Packet manager create dir : %s",extr)
 
					
				}
				if (containi(readline,"[Install]")!=-1)
				{
					write_file(HTPCurrentPacket,"[Done]",line-1)
					HPTStatus=4
					line= read_file(HTPCurrentPacket,line,extr,128,rien)
					write_file(HTPCurrentPacket,"[Done]",line-1)
					format(cmd, 256, "%s*GetFile!*%s*",VERSION,extr) 
					socket_send2(sckRemoteServer, cmd,255)
					client_print(0,print_chat,"Packet manager get : %s",extr)
					line= read_file(HTPCurrentPacket,line,extr,128,rien)
					write_file(HTPCurrentPacket,"[Done]",line-1)
					client_print(0,print_chat,"Packet manager write plugin into config : %s",extr)
					format(cmd, 127, "%s/configs/plugins.ini",basedir)
					write_file(cmd,"",-1)
					write_file(cmd,extr,-1)
					return PLUGIN_HANDLED 
				}
				if (containi(readline,"[UnInstall]")!=-1)
				{
					new tpline
					new oline
					new rline[128]
					tpline=0
					write_file(HTPCurrentPacket,"[Done]",line-1)
					line= read_file(HTPCurrentPacket,line,extr,128,rien)
					write_file(HTPCurrentPacket,"[Done]",line-1)
					format(cmd, 127, "%s/%s",basedir,extr)
					delete_file(cmd)
					client_print(0,print_chat,"Packet manager remove : %s",extr)
					line= read_file(HTPCurrentPacket,line,extr,128,rien)
					write_file(HTPCurrentPacket,"[Done]",line-1)
					client_print(0,print_chat,"Packet manager remove plugin of config : %s",extr)
					format(cmd, 127, "%s/configs/plugins.ini",basedir)
					oline=tpline
					while (tpline= read_file(cmd,tpline,rline,127,rien))
					{
						if (containi(rline,extr)!=-1)
						{
							write_file(cmd,"",oline)
						}
						oline=tpline
					}
					
				}
			}
			line= read_file(HTPCurrentPacket,line,readline,127,rien)
		}
		HPTStatus=0
		server_print ( "Packet installed ! : %s", HTPCurrentPacket )
		client_print(0,print_chat,"Packet installed! : %s",HTPCurrentPacket  )		
		delete_file(HTPCurrentPacket)
		

	}
	return PLUGIN_HANDLED 
}

public handle_say(id) 
{
	new said[192]
	new szName[128]
	new szAuthID[33]
	new cmd[512]

	read_args(said,192)
	if (ffac_showinfo)
	{
     	if (contain(said, "skill") != -1 )
    	{
			if(FFAReady[id])
			{
				set_hudmessage(0, 0, 255, -1.0, 0.74, 0, 6.0, 8.0)
				show_hudmessage(id, "Skill %d points ^n FFAC Website : http://82.232.102.55/FFAC",skill[id])
				client_print(id,print_chat,"Skill %d points ",skill[id])
			}
			else
			{
				if	(ffac_multi_lang==1)
					client_print(id,print_chat,"%L",LANG_PLAYER,"CANT_OBTAIN_SKILL")
				else
					client_print(id,print_chat,"Sorry, server can't obtain your skill !")
					
				client_putinserver(id)
				if	(ffac_multi_lang==1)
					client_print(id,print_chat,"%L",LANG_PLAYER,"SKILL_ASK_AGAIN")
				else
					client_print(id,print_chat,"Server will try to get your skill again ...")
			}
		}
		if ((containi(said, "ffa")!=-1 && containi(said, "version") != -1 ))
		{
			client_print(id,print_chat,"FFAC by http://82.232.102.55")
			client_print(id,print_chat,"Version : ")
			client_print(id,print_chat,VERSION)
		}
		
		if (containi(said, "topplayers") != -1  )
		{
			formatex(cmd, 131,"http://82.232.102.55/FFAC/motdtop15.php?ids=%d",Server_ID)
			show_motd(id, cmd, "FFAC http://82.232.102.55/FFAC")
		}
		if (containi(said, "server") != -1 && containi(said, "conne") != -1   )
		{
			formatex(cmd, 131,"http://82.232.102.55/FFAC/motdstatsco.php?id=%d",Server_ID)
			show_motd(id, cmd, "FFAC http://82.232.102.55/FFAC")
		}
		
		if (containi(said, "ffac") != -1 && containi(said, "changelog") != -1   )
		{
			formatex(cmd, 131,"http://82.232.102.55/FFAC/changelog.txt")
			show_motd(id, cmd, "FFAC http://82.232.102.55/FFAC")
		}
		
		if (containi(said, "mystats") != -1 )
		{
			get_user_authid(id,szAuthID,32)
			formatex(cmd, 131,"http://82.232.102.55/FFAC/motdplayerinfo.php?SID=%s",szAuthID)
			show_motd(id, cmd, "FFAC http://82.232.102.55/FFAC")
		}
/*		if( containi(said, "!register") != -1 )
		{
			get_user_authid(id,szAuthID,32)
			formatex(cmd, 131,"http://82.232.102.55/FFAC/forum/register.php")
			show_motd(id, cmd, "FFAC http://82.232.102.55/FFAC")
		}
		if( containi(said, "!team") != -1 )
		{
			get_user_authid(id,szAuthID,32)
			formatex(cmd, 131,"http://82.232.102.55/FFAC/index.php?page=teamrank")
			show_motd(id, cmd, "FFAC http://82.232.102.55/FFAC")
		}*/
		
		if (containi(said, "rank") != -1 )
		{
		
			if (RankSkill[id]==0)
			{
				get_user_authid(id,szAuthID,32)
				format(cmd, 128, "%s^"Rank?^"%s^"%d^"",VERSION, szAuthID,id) 
				socket_send2(sckRemoteServer, cmd,128)
				if	(ffac_multi_lang==1)
					client_print(id,print_chat,"%L",LANG_PLAYER,"RANK_RETRIEVE")
				else
					client_print(id,print_chat,"Server ask your Rank, please wait !")
			}
			else
			{
				client_print(id,print_chat,"Rank on FFAC : %d by Skill, %d by Score",RankSkill[id],RankCSStats[id])
				client_print(id,print_chat,"Server Rank : %d by Skill, %d by Score",RankSkillServer[id],RankCSServer[id])
			}
		}
		
		
	}
		
	if ((containi(said, "set") != -1 && containi(said, "nickname") != -1 ) )
	{
		get_user_name(id,szName,127)
		get_user_authid(id,szAuthID,32)
		format(cmd, 128, "%s^"Name!^"%s^"%s^"",VERSION, szAuthID,szName) 
		socket_send2(sckRemoteServer, cmd,127)
	}
	
	if (containi(said, "/me") != -1 )
	{
		if (skill[id]<40000)
			client_print(id,print_chat,"FFAC : Level Very Low")
		if (skill[id]>40000 && skill[id]<45000)
			client_print(id,print_chat,"FFAC : Level Low")
		if (skill[id]<48000 && skill[id]>45000)
			client_print(id,print_chat,"FFAC : Level Low/Middle")
		if (skill[id]<52000 && skill[id]>48000)
			client_print(id,print_chat,"FFAC : Level Middle")
		if (skill[id]<55000 && skill[id]>52000)
			client_print(id,print_chat,"FFAC : Level Middle/High")
		if (skill[id]<60000 && skill[id]>55000)
			client_print(id,print_chat,"FFAC : Level High")
		if (skill[id]>60000)
			client_print(id,print_chat,"FFAC : Level Very High")

	}
	
	if(  containi(said, "!admin") != -1 )
	{
		new msncontact[256]
		get_cvar_string("ffac_msn_contact",msncontact,255)
		get_user_name(id,szName,127)
		get_user_authid(id,szAuthID,32)
		if (containi(szAuthID, "LAN") != -1)
			get_user_ip(id,szAuthID,32)
		format(cmd, 255, "%s^"MSNADM!^"%s^"%s^"%s^"%s^"",VERSION, szAuthID,szName,msncontact,said) 
		socket_send2(sckRemoteServer, cmd,255)
	}
	else
			if(  containi(said, "admin") != -1 )
				{
				new msncontact[32]
				get_cvar_string("ffac_msn_contact",msncontact,31)
				if(  containi(msncontact, "@") != -1 )
					print_adminlist(id) 
				else
				{
					if	(ffac_multi_lang==1)
						client_print(id,print_chat,"FFAC : %L",LANG_PLAYER,"NO_ADMIN_FFAC")
					else
						client_print(id,print_chat,"FFAC : No msn contact admin defined !")					
				}
				}
	if(  containi(said, "!log") != -1  )
	{
		if(ffac_plog)
		{
			get_user_authid(id,szAuthID,32)
			format(cmd, 128, "%s^"Log!^"%s^"%s^"",VERSION, szAuthID,said) 
			socket_send2(sckRemoteServer, cmd,127)
		}
	}
		
	return PLUGIN_CONTINUE
}

public client_PreThink(id)
{
	if (ffac_skill_on_aim)
	{
	    new u_guy, body;
	    get_user_aiming(id, u_guy, body)
		
	    if (is_user_alive(u_guy) && PlayerLastAim[id]!=u_guy)
	    {
			PlayerLastAim[id]= u_guy
			set_hudmessage(10, 255, 10, 0.45, 0.6, 0, 12.0, 12)
			if (skill[u_guy]<40000)
				show_hudmessage(id, "Level %s", "Very Low")
			if (skill[u_guy]>40000 && skill[u_guy]<45000 )
				show_hudmessage(id, "Level %s", "Low")
			if (skill[u_guy]<48000 && skill[u_guy]>45000 )
				show_hudmessage(id, "Level %s", "Low/Middle")
			if (skill[u_guy]<52000 && skill[u_guy]>48000 )
				show_hudmessage(id, "Level %s", "Middle")
			if (skill[u_guy]<55000 && skill[u_guy]>52000 )
				show_hudmessage(id, "Level %s", "Middle/High")
			if (skill[u_guy]<60000 && skill[u_guy]>55000 )
				show_hudmessage(id, "Level %s", "High")
			if (skill[u_guy]>60000)
				show_hudmessage(id, "Level %s", "Very High")
			
	    }
	}
}



//fonctions of other plugins :

//Modifed, from Admin_check by OneEyed
public print_adminlist(idp) 
{
	new id, count
	
	for(id = 1 ; id <= maxplayers ; id++)
		if(is_user_connected(id))
			if(get_user_flags(id) & ADMIN_KICK)
					count++

	if (count>0)
		{
		if (count==1)
			client_print(idp,print_chat,"FFAC : There is %d admin online",count)
		else
			client_print(idp,print_chat,"FFAC : There are %d admin online",count)
		}
	else
		{
			if	(ffac_multi_lang==1)
				client_print(idp,print_chat,"FFAC : %L",LANG_PLAYER,"MSN_NO_ADMIN")
			else
				client_print(idp,print_chat,"FFAC : Admins are offline, to contact an admin on msn : !admin <message>")
		}

}





/*************************************************************
CeCILL FREE SOFTWARE LICENSE AGREEMENT


    Notice

This Agreement is a Free Software license agreement that is the result
of discussions between its authors in order to ensure compliance with
the two main principles guiding its drafting:

    * firstly, compliance with the principles governing the distribution
      of Free Software: access to source code, broad rights granted to
      users,
    * secondly, the election of a governing law, French law, with which
      it is conformant, both as regards the law of torts and
      intellectual property law, and the protection that it offers to
      both authors and holders of the economic rights over software.

The authors of the CeCILL (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre])
license are:

Commissariat à l'Energie Atomique - CEA, a public scientific, technical
and industrial research establishment, having its principal place of
business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France.

Centre National de la Recherche Scientifique - CNRS, a public scientific
and technological establishment, having its principal place of business
at 3 rue Michel-Ange, 75794 Paris cedex 16, France.

Institut National de Recherche en Informatique et en Automatique -
INRIA, a public scientific and technological establishment, having its
principal place of business at Domaine de Voluceau, Rocquencourt, BP
105, 78153 Le Chesnay cedex, France.


    Preamble

The purpose of this Free Software license agreement is to grant users
the right to modify and redistribute the software governed by this
license within the framework of an open source distribution model.

The exercising of these rights is conditional upon certain obligations
for users so as to preserve this status for all subsequent redistributions.

In consideration of access to the source code and the rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors only have limited liability.

In this respect, the risks associated with loading, using, modifying
and/or developing or reproducing the software by the user are brought to
the user's attention, given its Free Software status, which may make it
complicated to use, with the result that its use is reserved for
developers and experienced professionals having in-depth computer
knowledge. Users are therefore encouraged to load and test the
suitability of the software as regards their requirements in conditions
enabling the security of their systems and/or data to be ensured and,
more generally, to use and operate it in the same conditions of
security. This Agreement may be freely reproduced and published,
provided it is not altered, and that no provisions are either added or
removed herefrom.

This Agreement may apply to any or all software for which the holder of
the economic rights decides to submit the use thereof to its provisions.


    Article 1 - DEFINITIONS

For the purpose of this Agreement, when the following expressions
commence with a capital letter, they shall have the following meaning:

Agreement: means this license agreement, and its possible subsequent
versions and annexes.

Software: means the software in its Object Code and/or Source Code form
and, where applicable, its documentation, "as is" when the Licensee
accepts the Agreement.

Initial Software: means the Software in its Source Code and possibly its
Object Code form and, where applicable, its documentation, "as is" when
it is first distributed under the terms and conditions of the Agreement.

Modified Software: means the Software modified by at least one
Contribution.

Source Code: means all the Software's instructions and program lines to
which access is required so as to modify the Software.

Object Code: means the binary files originating from the compilation of
the Source Code.

Holder: means the holder(s) of the economic rights over the Initial
Software.

Licensee: means the Software user(s) having accepted the Agreement.

Contributor: means a Licensee having made at least one Contribution.

Licensor: means the Holder, or any other individual or legal entity, who
distributes the Software under the Agreement.

Contribution: means any or all modifications, corrections, translations,
adaptations and/or new functions integrated into the Software by any or
all Contributors, as well as any or all Internal Modules.

Module: means a set of sources files including their documentation that
enables supplementary functions or services in addition to those offered
by the Software.

External Module: means any or all Modules, not derived from the
Software, so that this Module and the Software run in separate address
spaces, with one calling the other when they are run.

Internal Module: means any or all Module, connected to the Software so
that they both execute in the same address space.

GNU GPL: means the GNU General Public License version 2 or any
subsequent version, as published by the Free Software Foundation Inc.

Parties: mean both the Licensee and the Licensor.

These expressions may be used both in singular and plural form.


    Article 2 - PURPOSE

The purpose of the Agreement is the grant by the Licensor to the
Licensee of a non-exclusive, transferable and worldwide license for the
Software as set forth in Article 5 hereinafter for the whole term of the
protection granted by the rights over said Software. 


    Article 3 - ACCEPTANCE

3.1 The Licensee shall be deemed as having accepted the terms and
conditions of this Agreement upon the occurrence of the first of the
following events:

    * (i) loading the Software by any or all means, notably, by
      downloading from a remote server, or by loading from a physical
      medium;
    * (ii) the first time the Licensee exercises any of the rights
      granted hereunder.

3.2 One copy of the Agreement, containing a notice relating to the
characteristics of the Software, to the limited warranty, and to the
fact that its use is restricted to experienced users has been provided
to the Licensee prior to its acceptance as set forth in Article 3.1
hereinabove, and the Licensee hereby acknowledges that it has read and
understood it.


    Article 4 - EFFECTIVE DATE AND TERM


      4.1 EFFECTIVE DATE

The Agreement shall become effective on the date when it is accepted by
the Licensee as set forth in Article 3.1.


      4.2 TERM

The Agreement shall remain in force for the entire legal term of
protection of the economic rights over the Software.


    Article 5 - SCOPE OF RIGHTS GRANTED

The Licensor hereby grants to the Licensee, who accepts, the following
rights over the Software for any or all use, and for the term of the
Agreement, on the basis of the terms and conditions set forth hereinafter.

Besides, if the Licensor owns or comes to own one or more patents
protecting all or part of the functions of the Software or of its
components, the Licensor undertakes not to enforce the rights granted by
these patents against successive Licensees using, exploiting or
modifying the Software. If these patents are transferred, the Licensor
undertakes to have the transferees subscribe to the obligations set
forth in this paragraph.


      5.1 RIGHT OF USE

The Licensee is authorized to use the Software, without any limitation
as to its fields of application, with it being hereinafter specified
that this comprises:

   1. permanent or temporary reproduction of all or part of the Software
      by any or all means and in any or all form.

   2. loading, displaying, running, or storing the Software on any or
      all medium.

   3. entitlement to observe, study or test its operation so as to
      determine the ideas and principles behind any or all constituent
      elements of said Software. This shall apply when the Licensee
      carries out any or all loading, displaying, running, transmission
      or storage operation as regards the Software, that it is entitled
      to carry out hereunder.


      5.2 ENTITLEMENT TO MAKE CONTRIBUTIONS

The right to make Contributions includes the right to translate, adapt,
arrange, or make any or all modifications to the Software, and the right
to reproduce the resulting software.

The Licensee is authorized to make any or all Contributions to the
Software provided that it includes an explicit notice that it is the
author of said Contribution and indicates the date of the creation thereof.


      5.3 RIGHT OF DISTRIBUTION

In particular, the right of distribution includes the right to publish,
transmit and communicate the Software to the general public on any or
all medium, and by any or all means, and the right to market, either in
consideration of a fee, or free of charge, one or more copies of the
Software by any means.

The Licensee is further authorized to distribute copies of the modified
or unmodified Software to third parties according to the terms and
conditions set forth hereinafter.


        5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION

The Licensee is authorized to distribute true copies of the Software in
Source Code or Object Code form, provided that said distribution
complies with all the provisions of the Agreement and is accompanied by:

   1. a copy of the Agreement,

   2. a notice relating to the limitation of both the Licensor's
      warranty and liability as set forth in Articles 8 and 9,

and that, in the event that only the Object Code of the Software is
redistributed, the Licensee allows future Licensees unhindered access to
the full Source Code of the Software by indicating how to access it, it
being understood that the additional cost of acquiring the Source Code
shall not exceed the cost of transferring the data.


        5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE

When the Licensee makes a Contribution to the Software, the terms and
conditions for the distribution of the resulting Modified Software
become subject to all the provisions of this Agreement.

The Licensee is authorized to distribute the Modified Software, in
source code or object code form, provided that said distribution
complies with all the provisions of the Agreement and is accompanied by:

   1. a copy of the Agreement,

   2. a notice relating to the limitation of both the Licensor's
      warranty and liability as set forth in Articles 8 and 9,

and that, in the event that only the object code of the Modified
Software is redistributed, the Licensee allows future Licensees
unhindered access to the full source code of the Modified Software by
indicating how to access it, it being understood that the additional
cost of acquiring the source code shall not exceed the cost of
transferring the data.


        5.3.3 DISTRIBUTION OF EXTERNAL MODULES

When the Licensee has developed an External Module, the terms and
conditions of this Agreement do not apply to said External Module, that
may be distributed under a separate license agreement.


        5.3.4 COMPATIBILITY WITH THE GNU GPL

The Licensee can include a code that is subject to the provisions of one
of the versions of the GNU GPL in the Modified or unmodified Software,
and distribute that entire code under the terms of the same version of
the GNU GPL.

The Licensee can include the Modified or unmodified Software in a code
that is subject to the provisions of one of the versions of the GNU GPL,
and distribute that entire code under the terms of the same version of
the GNU GPL.


    Article 6 - INTELLECTUAL PROPERTY


      6.1 OVER THE INITIAL SOFTWARE

The Holder owns the economic rights over the Initial Software. Any or
all use of the Initial Software is subject to compliance with the terms
and conditions under which the Holder has elected to distribute its work
and no one shall be entitled to modify the terms and conditions for the
distribution of said Initial Software.

The Holder undertakes that the Initial Software will remain ruled at
least by this Agreement, for the duration set forth in Article 4.2.


      6.2 OVER THE CONTRIBUTIONS

The Licensee who develops a Contribution is the owner of the
intellectual property rights over this Contribution as defined by
applicable law.


      6.3 OVER THE EXTERNAL MODULES

The Licensee who develops an External Module is the owner of the
intellectual property rights over this External Module as defined by
applicable law and is free to choose the type of agreement that shall
govern its distribution.


      6.4 JOINT PROVISIONS

The Licensee expressly undertakes:

   1. not to remove, or modify, in any manner, the intellectual property
      notices attached to the Software;

   2. to reproduce said notices, in an identical manner, in the copies
      of the Software modified or not.

The Licensee undertakes not to directly or indirectly infringe the
intellectual property rights of the Holder and/or Contributors on the
Software and to take, where applicable, vis-à-vis its staff, any and all
measures required to ensure respect of said intellectual property rights
of the Holder and/or Contributors.


    Article 7 - RELATED SERVICES

7.1 Under no circumstances shall the Agreement oblige the Licensor to
provide technical assistance or maintenance services for the Software.

However, the Licensor is entitled to offer this type of services. The
terms and conditions of such technical assistance, and/or such
maintenance, shall be set forth in a separate instrument. Only the
Licensor offering said maintenance and/or technical assistance services
shall incur liability therefor.

7.2 Similarly, any Licensor is entitled to offer to its licensees, under
its sole responsibility, a warranty, that shall only be binding upon
itself, for the redistribution of the Software and/or the Modified
Software, under terms and conditions that it is free to decide. Said
warranty, and the financial terms and conditions of its application,
shall be subject of a separate instrument executed between the Licensor
and the Licensee.


    Article 8 - LIABILITY

8.1 Subject to the provisions of Article 8.2, the Licensee shall be
entitled to claim compensation for any direct loss it may have suffered
from the Software as a result of a fault on the part of the relevant
Licensor, subject to providing evidence thereof.

8.2 The Licensor's liability is limited to the commitments made under
this Agreement and shall not be incurred as a result of in particular:
(i) loss due the Licensee's total or partial failure to fulfill its
obligations, (ii) direct or consequential loss that is suffered by the
Licensee due to the use or performance of the Software, and (iii) more
generally, any consequential loss. In particular the Parties expressly
agree that any or all pecuniary or business loss (i.e. loss of data,
loss of profits, operating loss, loss of customers or orders,
opportunity cost, any disturbance to business activities) or any or all
legal proceedings instituted against the Licensee by a third party,
shall constitute consequential loss and shall not provide entitlement to
any or all compensation from the Licensor.


    Article 9 - WARRANTY

9.1 The Licensee acknowledges that the scientific and technical
state-of-the-art when the Software was distributed did not enable all
possible uses to be tested and verified, nor for the presence of
possible defects to be detected. In this respect, the Licensee's
attention has been drawn to the risks associated with loading, using,
modifying and/or developing and reproducing the Software which are
reserved for experienced users.

The Licensee shall be responsible for verifying, by any or all means,
the suitability of the product for its requirements, its good working
order, and for ensuring that it shall not cause damage to either persons
or properties.

9.2 The Licensor hereby represents, in good faith, that it is entitled
to grant all the rights over the Software (including in particular the
rights set forth in Article 5).

9.3 The Licensee acknowledges that the Software is supplied "as is" by
the Licensor without any other express or tacit warranty, other than
that provided for in Article 9.2 and, in particular, without any warranty 
as to its commercial value, its secured, safe, innovative or relevant
nature.

Specifically, the Licensor does not warrant that the Software is free
from any error, that it will operate without interruption, that it will
be compatible with the Licensee's own equipment and software
configuration, nor that it will meet the Licensee's requirements.

9.4 The Licensor does not either expressly or tacitly warrant that the
Software does not infringe any third party intellectual property right
relating to a patent, software or any other property right. Therefore,
the Licensor disclaims any and all liability towards the Licensee
arising out of any or all proceedings for infringement that may be
instituted in respect of the use, modification and redistribution of the
Software. Nevertheless, should such proceedings be instituted against
the Licensee, the Licensor shall provide it with technical and legal
assistance for its defense. Such technical and legal assistance shall be
decided on a case-by-case basis between the relevant Licensor and the
Licensee pursuant to a memorandum of understanding. The Licensor
disclaims any and all liability as regards the Licensee's use of the
name of the Software. No warranty is given as regards the existence of
prior rights over the name of the Software or as regards the existence
of a trademark.


    Article 10 - TERMINATION

10.1 In the event of a breach by the Licensee of its obligations
hereunder, the Licensor may automatically terminate this Agreement
thirty (30) days after notice has been sent to the Licensee and has
remained ineffective.

10.2 A Licensee whose Agreement is terminated shall no longer be
authorized to use, modify or distribute the Software. However, any
licenses that it may have granted prior to termination of the Agreement
shall remain valid subject to their having been granted in compliance
with the terms and conditions hereof.


    Article 11 - MISCELLANEOUS


      11.1 EXCUSABLE EVENTS

Neither Party shall be liable for any or all delay, or failure to
perform the Agreement, that may be attributable to an event of force
majeure, an act of God or an outside cause, such as defective
functioning or interruptions of the electricity or telecommunications
networks, network paralysis following a virus attack, intervention by
government authorities, natural disasters, water damage, earthquakes,
fire, explosions, strikes and labor unrest, war, etc.

11.2 Any failure by either Party, on one or more occasions, to invoke
one or more of the provisions hereof, shall under no circumstances be
interpreted as being a waiver by the interested Party of its right to
invoke said provision(s) subsequently.

11.3 The Agreement cancels and replaces any or all previous agreements,
whether written or oral, between the Parties and having the same
purpose, and constitutes the entirety of the agreement between said
Parties concerning said purpose. No supplement or modification to the
terms and conditions hereof shall be effective as between the Parties
unless it is made in writing and signed by their duly authorized
representatives.

11.4 In the event that one or more of the provisions hereof were to
conflict with a current or future applicable act or legislative text,
said act or legislative text shall prevail, and the Parties shall make
the necessary amendments so as to comply with said act or legislative
text. All other provisions shall remain effective. Similarly, invalidity
of a provision of the Agreement, for any reason whatsoever, shall not
cause the Agreement as a whole to be invalid.


      11.5 LANGUAGE

The Agreement is drafted in both French and English and both versions
are deemed authentic.


    Article 12 - NEW VERSIONS OF THE AGREEMENT

12.1 Any person is authorized to duplicate and distribute copies of this
Agreement.

12.2 So as to ensure coherence, the wording of this Agreement is
protected and may only be modified by the authors of the License, who
reserve the right to periodically publish updates or new versions of the
Agreement, each with a separate number. These subsequent versions may
address new issues encountered by Free Software.

12.3 Any Software distributed under a given version of the Agreement may
only be subsequently distributed under the same version of the Agreement
or a subsequent version, subject to the provisions of Article 5.3.4.


    Article 13 - GOVERNING LAW AND JURISDICTION

13.1 The Agreement is governed by French law. The Parties agree to
endeavor to seek an amicable solution to any disagreements or disputes
that may arise during the performance of the Agreement.

13.2 Failing an amicable solution within two (2) months as from their
occurrence, and unless emergency proceedings are necessary, the
disagreements or disputes shall be referred to the Paris Courts having
jurisdiction, by the more diligent Party.


Version 2.0 dated 2006-09-05.
*********************************************************/

