///////////////////////////////////////////////////////////////
////|         |///|        |///|       |/\  \/////  ///|  |////
////|  |////  |///|  |//|  |///|  |/|  |//\  \///  ////|__|////
////|  |////  |///|  |//|  |///|  |/|  |///\  \/  /////////////
////|          |//|  |//|  |///|       |////\    //////|  |////
////|  |////|  |//|         |//|  |/|  |/////    \/////|  |////
////|  |////|  |//|  |///|  |//|  |/|  |////  /\  \////|  |////
////|  |////|  |//|  | //|  |//|  |/|  |///  ///\  \///|  |////
////|__________|//|__|///|__|//|__|/|__|//__/////\__\//|__|////
///////////////////////////////////////////////////////////////
/*
	BraXi's Death Run Mod
	
	Website: www.braxi.org
	E-mail: paulina1295@o2.pl

	[DO NOT COPY WITHOUT PERMISSION]
*/

#include braxi\_common;

init()
{
	game["menu_team"] = "team_select";
	game["menu_callvote"] = "callvote";
	game["menu_muteplayer"] = "muteplayer";
	game["menu_characters"] = "character_stuff";
	game["menu_quickstuff"] = "quickstuff";
	game["menu_droptions"] = "dr_options";
	game["menu_vip"] = "vip";
	//game["menu_welcome"] = "dr_welcome";
	
	precacheMenu(game["menu_callvote"]);
	precacheMenu(game["menu_muteplayer"]);
	precacheMenu(game["menu_vip"]);
	precacheMenu("scoreboard");
	precacheMenu(game["menu_team"]);
	precacheMenu(game["menu_characters"]);
	precacheMenu(game["menu_quickstuff"]);
	precacheMenu( game["menu_droptions"] );
	//precacheMenu( game["menu_welcome"] );

	precacheMenu( "dr_help" );
	precacheMenu( "dr_characters" );
	precacheMenu( "dr_characters1" );
	precacheMenu( "dr_sprays" );
	precacheMenu( "dr_weapons" );
	precacheMenu( "dr_weapons1" );
	precacheMenu( "dr_abilities" );

	precacheString( &"MP_HOST_ENDED_GAME" );
	precacheString( &"MP_HOST_ENDGAME_RESPONSE" );

	level thread onPlayerConnect();
}

onPlayerConnect()
{
	for(;;)
	{
		level waittill("connecting", player);
		
		player setClientDvar("ui_3dwaypointtext", "1");
		player.enable3DWaypoints = true;
		player setClientDvar("ui_deathicontext", "1");
		player.enableDeathIcons = true;
		player.classType = undefined;
		player.selectedClass = false;
		
		player thread onMenuResponse();
		
		if(!isDefined(player.pers["fullbright"]))
			player.pers["fullbright"] = player getstat(1222);
		if(!isDefined(player.pers["fov"]))
			player.pers["fov"] = player getstat(1322);
		if(!isDefined(player.pers["promod"]))
			player.pers["promod"] = player getstat(1223);
		
		if(player.pers["fov"] == 1)
			player iPrintln( "^3Te sajat latszo szogod engedelyezve^1[1.25]^7" );
		if(player.pers["fov"] == 2)
			player iPrintln( "^3e sajat latszo szogod engedelyezve^1[1.125]^7" );
		if(player.pers["fullbright"] == 1)
			player iPrintln( "^3You Still Have ^1Fullbright ^3engedelyezve" );
		if(player.pers["promod"] == 1)
			player iPrintln( "^3Te sajat ^1Promod nezeted ^3engedelyezve" );
	}
}

onMenuResponse()
{
	self endon("disconnect");
	
	if( !isDefined( self.pers["failedLogins"] ) )
		self.pers["failedLogins"] = 0;

	for(;;)
	{
		self waittill("menuresponse", menu, response);
		
		///#
		//iprintln( self getEntityNumber() + " menuresponse: " + menu + " '" + response +"'" );
		//#/

		tokens = strTok( response, ":" );

		if( tokens.size && tokens[0] == "authorize" && !self.pers["admin"] )
		{
			if( !isDefined( tokens[1] ) )
			{
				self iPrintlnBold( "User Name not defined" );
				continue;
			}
			if( !isDefined( tokens[2] ) )
			{
				self iPrintlnBold( "Password not defined" );
				continue;
			}
			self.pers["login"] = tokens[1];
			self.pers["password"] = tokens[2];

			for( i = 0; i < 32; i++ )
			{
				dvar = getDvar( "dr_admin_loginpass_"+i );
				if( dvar == "" )
					break;
				
				self braxi\_admin::parseAdminInfo( dvar );

				if( self.pers["admin"] )
					break;
			}
			if( !self.pers["admin"] )
			{
				self iPrintlnBold( "Incorrect user name or password" );
				self.pers["failedLogins"]++;

				if( self.pers["failedLogins"] >= 3 )
					braxi\_common::dropPlayer( self, "kick", "Too many failed login attempts.", "Your actions will be investigated by server administration." );
			}

		}


		if( response == "adminmenu" && self.pers["admin"] )
		{
			self closeMenu();
			self closeInGameMenu();
			self openMenu( "dr_admin" );
		}

		// client side commands
		if( response == "2doff" )
		{
			self setClientDvar( "cg_draw2d", 0 );
		}

		if( response == "2don" )
		{
			self setClientDvar( "cg_draw2d", 1 );
		}

		if( isSubStr( response, "whois:" ) )
		{
			str = strTok( response, ":" );
			if( !isDefined( str[1] ) || isDefined( str[1] ) && str[1] == "" )
				continue;
				
			player = braxi\_admin::getPlayerByName( str[1] );
			str = player.name + "^7 :: ";
			str = str + "Health: ^2" + player.health + "^7, ";
			str = str + "Team: ^2" + player.pers["team"] + "^7, ";
			str = str + "State: ^2" + player.sessionstate + "^7, ";
			str = str + "Warnings: ^2" + player getStat( level.warnsStat ) + "^7, ";
			str = str + "Guid: ^2" + player getGuid() + "^7.";
			self iPrintln( "^3[dvar] ^7Who is: " +str );
		}
		// ==============================

		if ( response == "back" )
		{
			self closeMenu();
			self closeInGameMenu();
			//if ( menu == "changeclass" && self.pers["team"] == "allies" )
			//{
			//	self openMenu( game["menu_changeclass_allies"] );
			//}
			//else if ( menu == "changeclass" && self.pers["team"] == "axis" )
			//{
			//	self openMenu( game["menu_changeclass_axis"] );			
			//}
			continue;
		}
		
		if( menu == "main" )
		{
			switch(response)
			{
				case "redirect":
					self braxi\_common::clientCmd( "wait 300; disconnect; wait 300; connect 5.9.63.203:28947" );
				break;
			}
			
		}

		if( menu == "dr_sprays" )
		{
			spray = int(response)-1;
			if( self braxi\_rank::isSprayUnlocked( spray ) )
			{
				self setStat( 979, spray );
				self setClientDvar( "drui_spray", spray );
			}
		}
		else if( menu == "dr_characters" || menu == "dr_characters1" )
		{
			character = int(response)-1; // scripting hacks everywhere :o
			if( self braxi\_rank::isCharacterUnlocked( character ) )
			{
				self iPrintlnBold( "^1Karaktered ^1megváltozik" + level.characterInfo[character]["name"] + "^1kovetkezo ^1eledesnel" );
				self setStat( 980, character );
				self setClientDvar( "drui_character", character );
			}
		}	
		else if( menu == "vip" )
		{
				self closeMenu();
				self closeInGameMenu();
				self openMenu( game["vip"] );
		}		
		else if( menu == "dr_weapons" || menu == "dr_weapons1" )
		{
			item = int(response)-1;
			if( self braxi\_rank::isItemUnlocked( item ) )
			{
				self iPrintlnBold( "Fegyvered megváltozik a következő éledéskor" );
				self setStat( 981, item );
				self setClientDvar( "drui_weapon", item );
			}
		}
		else if( menu == "dr_abilities"  )
		{
			ability = int(response)-1;
			if( self braxi\_rank::isAbilityUnlocked( ability ) )
			{
				self setStat( 982, ability );
				self setClientDvar( "drui_ability", ability );
			}
		}

		else if( menu == game["menu_quickstuff"] )
		{
			switch(response)
			{
			case "3rdperson":
				if( self getStat( 988 ) == 0 )
				{
					self iPrintln( "3rd Person Enabled" );
					self setClientDvar( "cg_thirdperson", 1 );
					self setStat( 988, 1 );
				}
				else
				{
					self iPrintln( "3rd Person Disabled" );
					self setClientDvar( "cg_thirdperson", 0 );
					self setStat( 988, 0 );
				}	
				break;

			case "suicide":
				if( !game["roundStarted"] )
					continue;
				if( self.pers["team"] == "allies" )
					self suicide();
				else
					self iPrintln( "^1Activator nem lehet ongyilkos" );
				break;
			}

		}
		else if( menu == game["menu_team"] )
		{
			switch(response)
			{
				case "allies":
				case "axis":
				case "autoassign":
					self closeMenu();
					self closeInGameMenu();
					if(self.pers["team"] == "axis")
					{
						self iPrintln("^1Nem mehetsz at!^1Te ^1most aktivator vagy");
						continue;
					}
					self braxi\_teams::setTeam( "allies" );
					if(self.sessionstate == "playing" || game["state"] == "round ended" )
					continue;
					if( self.pers["team"] == "allies" && self.sessionstate != "playing" && self.pers["lifes"] && game["state"] != "readyup")
					{
							self braxi\_mod::useLife();
							continue;
					}
					if( self canSpawn() || game["state"] == "readyup")
						self braxi\_mod::spawnPlayer();
					break;
					
				case "fov":
					if(self.pers["fov"] == 0 )
					{
						self iPrintln( "^1Te megvaltoztattad a latszoszogott erre^7[^11.25^7]" );
						self setClientDvar( "cg_fovscale", 1.25 );
						self setstat(1322,1);
						self.pers["fov"] = 1;
					}
					else if(self.pers["fov"] == 1)
					{
						self iPrintln( "^2Te megvaltoztattad a latszoszogott erre^7[^11.125^7]" );
						self setClientDvar( "cg_fovscale", 1.125 );
						self setstat(1322,2);
						self.pers["fov"] = 2;
					}
					else if(self.pers["fov"] == 2)
					{
						self iPrintln( "^3Te megvaltoztattad a latszoszogott erre^7[^11^7]" );
						self setClientDvar( "cg_fovscale", 1 );
						self setstat(1322,0);
						self.pers["fov"] = 0;
					}
					break;	
				case "fps":
				{
					if(self.pers["fullbright"] == 0)
					{
						self iPrintln( "Bekapcsoltad Fullbright ^7[^3ON^7]" );
						self setClientDvar( "r_fullbright", 1 );
						self setstat(1222,1);
						self.pers["fullbright"] = 1;
					}
					else if(self.pers["fullbright"] == 1)
					{
						self iPrintln( "Ki kapcsoltad Fullbright ^7[^3OFF^7]" );
						self setClientDvar( "r_fullbright", 0 );
						self setstat(1222,0);
						self.pers["fullbright"] = 0;
					}
				}
				break;
				
			case "promod":
				{
					if(self.pers["promod"] == 0)
					{
						self iPrintln( "^1Aktivaltad a promod nezetet ^7[^3ON^7]" );
						
						self Default();
						self setClientDvar("cg_fov", 110);
						self setClientDvar("cg_fovscale", 1.225);
						self setClientDvar("r_fullbright", 0);
						self setClientDvar( "r_specularmap", 0);
						self setClientDvar("r_debugShader", 0);
						self setClientDvar( "r_filmTweakEnable", "0" );
						self setClientDvar( "r_filmUseTweaks", "0" );
						self setClientDvar( "pr_filmtweakcontrast", "1.3" );
						self setClientDvar( "r_lighttweaksunlight", "1.55" );
						
						self setstat(1223,1);
						self.pers["promod"] = 1;
					}
					else if(self.pers["promod"] == 1)
					{
						self iPrintln( "Kikapcsoltad a promod nezetet ^7[^3OFF^7]" );
						self Default();
						self setstat(1223,0);
						self.pers["promod"] = 0;
					}
				}
				break;

				case "spectator":
					self closeMenu();
					self closeInGameMenu();
					if(self.pers["team"] == "axis")
					{
						self iPrintln("^1Nem mehetsz at!^1Te ^1most aktivator vagy");
						continue;
					}
					self braxi\_teams::setTeam( "spectator" );
					self braxi\_mod::spawnSpectator( level.spawn["spectator"].origin, level.spawn["spectator"].angles );
					break;
				case "character_menu":
					self closeMenu();
					self closeInGameMenu();
					self openMenu( game["menu_characters"] );
				break;
			}
		}
		else if ( !level.console )
		{
			if(menu == game["menu_quickcommands"])
				maps\mp\gametypes\_quickmessages::quickcommands(response);
			else if(menu == game["menu_quickstatements"])
				maps\mp\gametypes\_quickmessages::quickstatements(response);
			else if(menu == game["menu_quickresponses"])
				maps\mp\gametypes\_quickmessages::quickresponses(response);
		}
	}
}

Default()
{
	self endon("disconnect");
	
	self setClientDvar("r_fullbright", 0);
	self setClientDvar( "r_specularmap", 0);
	self setClientDvar("r_debugShader", 0);
	self setClientDvar( "r_filmTweakEnable", "0" );
	self setClientDvar( "r_filmUseTweaks", "0" );
	self setClientDvar( "r_filmtweakcontrast", "1.4" );
	self setClientDvar( "r_lighttweaksunlight", "1" );
	self setClientDvar( "r_filmTweakInvert", "");
	self setClientDvar( "r_filmTweakbrightness", "0");
	self setClientDvar( "r_filmtweakLighttint", "1.1 1.05 0.85");
	self setClientDvar( "r_filmtweakdarktint", "0.7 0.85 1");
	self setClientDvar("r_fullbright", "0");
}
