GLcommands = {};


Game:CreateVariable("gl_mapcycle_ffa","");
Game:CreateVariable("gl_mapcycle_tdm","");
Game:CreateVariable("gl_mapcycle_assault","");

Game:CreateVariable("gl_allow_teamkilling",0);  	--allow teamkilling
Game:CreateVariable("gl_free_teamkills",5);             --teamkills without punishment
Game:CreateVariable("gl_teamkill_extra_time",5);        --add respawntime for each teamkill> free_teamkills
Game:CreateVariable("gl_teamkill_force_spectate", 7);   --if player has this number of teamkills, he will only be able to spectate
Game:CreateVariable("gl_punish_protected",1);           --if 'protected names' should be punished
Game:CreateVariable("gl_log_teamkillers",0);            --log teamkillers to teamkillers_[x].log

Game:CreateVariable("gl_spawnmessage1","");
Game:CreateVariable("gl_spawnmessage2","");
Game:CreateVariable("gl_spawnmessage3","");
Game:CreateVariable("gl_spawnmessage4","");

Game:CreateVariable("gl_initial_ag36_nades",3); 
Game:CreateVariable("gl_pickup_ag36_nades",2); 
Game:CreateVariable("gl_droppickup_ag36_nades",1); 
Game:CreateVariable("gl_max_ag36_nades",3); 

Game:CreateVariable("gl_initial_oicw_nades",3); 
Game:CreateVariable("gl_pickup_oicw_nades",2); 
Game:CreateVariable("gl_droppickup_oicw_nades",1); 
Game:CreateVariable("gl_max_oicw_nades",3); 

Game:CreateVariable("gl_initial_rockets",10); 
Game:CreateVariable("gl_pickup_rockets",5); 
Game:CreateVariable("gl_droppickup_rockets",5); 
Game:CreateVariable("gl_max_rockets",10); 

Game:CreateVariable("gl_initial_sticky_explosives",3); 
Game:CreateVariable("gl_pickup_sticky_explosives",3); 
Game:CreateVariable("gl_droppickup_sticky_explosives",0); 
Game:CreateVariable("gl_max_sticky_explosives",3); 

Game:CreateVariable("gl_initial_sniper_ammo",20); 
Game:CreateVariable("gl_pickup_sniper_ammo",10); 
Game:CreateVariable("gl_droppickup_sniper_ammo",10); 
Game:CreateVariable("gl_max_sniper_ammo",30); 

Game:CreateVariable("gl_max_rockets_ffa",10);
Game:CreateVariable("gl_max_oicw_nades_ffa",10);
Game:CreateVariable("gl_max_ag36_nades_ffa",10);

Game:CreateVariable("gl_rocket_damage_factor",1);
Game:CreateVariable("gl_oicw_nade_damage_factor",1);
Game:CreateVariable("gl_ag36_nade_damage_factor",1);

Game:CreateVariable("gl_sniper_flashbang",0);
Game:CreateVariable("gl_scout_flashbang",0);
Game:CreateVariable("gl_engineer_flashbang",0);

Game:CreateVariable("gl_killing_spree",0); 
Game:CreateVariable("gl_killing_spree_display",0);  --0 display at each kill, 1 = display only at end of spree

Game:CreateVariable("gl_max_average_ping",0);     --0 means NO ping kick
Game:CreateVariable("gl_ping_check_interval",5);  --check ping each .. seconds
Game:CreateVariable("gl_ping_warnings",5);        --number of sequential warnings before kick
Game:CreateVariable("gl_ping_reset_on_connect", 0);  --ping stats reset on (re)connect
Game:CreateVariable("gl_last_checked",0);         --system variable. dont alter
Game:CreateVariable("gl_last_spawn_checked",0);         --system variable. dont alter

Game:CreateVariable("gl_announce_headshot",0);    -- 0 = no message, 1 = message on headshot kill
Game:CreateVariable("gl_headshot_message_private",1);  -- 0 = message to all, 1 = message to shooter

Game:CreateVariable("gl_flag_saved_message",1);         --display who saves flag
Game:CreateVariable("gl_flag_captured_message",1);      --display who captures flag 
Game:CreateVariable("gl_flag_startcapture_message",1);  --display who starts flag capture
Game:CreateVariable("gl_flag_warmup_time",15);		--time for flag to activate			
Game:CreateVariable("gl_forcebluejoin",0);
Game:CreateVariable("gl_forceredjoin",0);

Game:CreateVariable("gl_rm_needed_kills",4);   --number of kills needed to get rambo move message (0 to disable rambo move)
Game:CreateVariable("gl_rm_kill_addtime",5);   --time added for each kill. while time>gametime, rambo move is active. (when flag is activated, no time will be reducted).

Game:CreateVariable("gl_stats_export",0);            --export stats files (called : stats_[x].txt, x being a number)
Game:CreateVariable("gl_stats_dir","");              --directory to put logfiles in, defaults to farcry/ (USE /, NOT \)

Game:CreateVariable("gl_runspeed_factor",1);      --run speed factor
Game:CreateVariable("gl_stamina_use_run",1);      --stamina depletion factor when running
                                        
Game:CreateVariable("gr_discardclip",0);     --if 1, discard any ammo left in clip

Game:CreateVariable("gl_keep_lock",0);  --keep teamlocks on mapchange (no auto release)
                                        
Game:CreateVariable("gl_ssmod_version","$3Godlike SSMod version 3.6 by Niels Christian Grimminck & [HOC]KoRi");
Game:CreateVariable("gl_fulltime",0);  --both teams get same time (gr_timelimit)
Game:CreateVariable("gl_static_respawn",0);  --fixed respawn timer (0 is off)

Game:CreateVariable("gl_allow_spectators",1);  --spectating allowed or not

Game:CreateVariable("gl_keep_score",0);  -- keep score even when ppl join specators and then rejoin

Game:CreateVariable("gl_walkspeed_factor",1);
Game:CreateVariable("gl_swimspeed_factor",1);
Game:CreateVariable("gl_crouchspeed_factor",1);
Game:CreateVariable("gl_pronespeed_factor",1);
Game:CreateVariable("gl_jumpforce_factor",1);

Game:CreateVariable("gl_max_snipers",9999);  --max snipers in 1 team
Game:CreateVariable("gl_max_scouts",9999);  -- max scouts in 1 team
Game:CreateVariable("gl_max_engineers",9999);  --max engineers in 1 team

Game:CreateVariable("gl_se_rlfun",0);  

Game:CreateVariable("gl_ssmod_id", "$9-||$3GL$9||-$o");
Game:CreateVariable("gr_BackupRPTime",15);
setglobal("gr_BackupRPTime", tonumber(getglobal("gr_respawntime")));

--Game:CreateVariable("gl_debug",0);

protectedNames = {
	namelist={},
	vn=1,
}



--servermessage to all
Game:AddCommand("gl_ss","GLcommands:serverSay(%line);","gl_ss [text]");  
--move player to team. optional <forceteam>. 1= make them stay
Game:AddCommand("gl_move","GLcommands:movePlayerToTeam(%line);","gl_move [pId] [team=blue/red/spectators] <forceteam>");  
--move all but protected to team (can return)
Game:AddCommand("gl_release","GLcommands:ReleasePlayer(%1);","gl_release [pId] (remove teamforcing on player)");
--players (expect protected) cannot join team
Game:AddCommand("gl_lock","GLcommands:GLlockTeam(%1);","gl_lock [team=red/blue] (all players joining forced to blue)");
--unlock both teams
Game:AddCommand("gl_unlock","GLcommands:GLforceNone();","gl_unlock (unlocks both teams)");
--release ALL locks (forced player teams (gl_move),(gl_lock))
Game:AddCommand("gl_unlockall","GLcommands:GLunlockall();","gl_unlockall (removes ALL teamlocks)");
--change mapcycle to file in server.cfg [gl_mapcycle_ffa / gl_mapcycle_assault / gl_mapcycle_tdm]
Game:AddCommand("gl_ffa","GLcommands:changeMapCycleFfa();","gl_ffa (changes mapcycle to gl_mapcycle_ffa)");
Game:AddCommand("gl_tdm","GLcommands:changeMapCycleTdm();","gl_tdm (changes mapcycle to gl_mapcycle_tdm)");
Game:AddCommand("gl_assault","GLcommands:changeMapCycleAssault();","gl_assault (changes mapcycle to gl_mapcycle_assault)");
--displays detailed players list on assault/tdm games. also works in ffa, but not as good
Game:AddCommand("gl_list","GLcommands:GLListPlayers();","gl_list (displays detailed teamlist)");  
--reload protectednames file (profiles/server/p_names.txt)
Game:AddCommand("gl_load_protected","GLcommands:loadProtected();","gl_load_protected (reloads protected name file (profiles/server/p_names.txt");
--add a protected name
Game:AddCommand("gl_add_protected","GLcommands:addProtectedById(%1);","gl_add_protected [pId] (adds a name to protected list)");
--print protected names
Game:AddCommand("gl_list_protected","GLcommands:printProtectedNames();","gl_list_protected (displays all protected names)");
--clear protected names
Game:AddCommand("gl_clear_protected","GLcommands:clearProtected();","gl_clear_protected (unload all protected names)");
--save protected names
Game:AddCommand("gl_save_protected","GLcommands:saveProtected();","gl_save_protected (save current protected names to p_names.txt)");
--punish player, (player dies, and recieves optional extra respawn time)
Game:AddCommand("gl_punish","GLcommands:punishPlayer(%line);","gl_punish [pId] <extra time> <reason> (player dies, receives optional extra respawn)");
--change player class (on next respawn)
Game:AddCommand("gl_cpc","GLcommands:SetGlPlayerClass(%1, %2);","gl_cpc [pId] [class = sniper1..2/engineer1..2/scout1..6");
--(re)loads a config file
Game:AddCommand("gl_config","GLcommands:LoadConfig(%1);","gl_config [configfile]");
--(re)loads a config file and restarts
Game:AddCommand("gl_config1","GLcommands:LoadConfig1(%1);","gl_config1 [configfile]");
--creates a statsfile (automatically done when gl_stats_export = 1)
Game:AddCommand("gl_exportstats","GLplayerTrack:ExportStats();","");

--version 3.4
--create restart file, for use with 'farcry restarter program'
Game:AddCommand("gl_reboot_server","GLcommands:PlaceRestartFile();","gl_reboot_server"); 
--goto the next map
Game:AddCommand("gl_nextmap","GameRules:GotoNextMap();","gl_nextmap"); 
--switch teams
Game:AddCommand("gl_switchteams","GameRules:DoSwitchTeams();","gl_switchteams");

function GLcommands:serverSay(sMess)
	Server:BroadcastText(sMess);
end

function GLcommands:movePlayerToTeam(line)
	if (line) then
		toktable = tokenize(line);
		if (toktable[1] and toktable[2]) then
			local pId = tonumber(toktable[1]);
			local team = tostring(toktable[2]);
			local stay = 0;
			if (toktable[3]) then
				stay=tonumber(toktable[3]);
			end
			local ss = Server:GetServerSlotBySSId(pId);
			if team~="spectators" and team~="blue" and team~="red" and team~="players" then 
				System:LogAlways("usage : gl_move [pId] [team] <force 1/0>");
				return;
			end
			if ss and team then
				GameRules:ChangeTeam(ss,team,true);
				ss:Ready(nil);
		  		ss:ResetPlayTime();
				Server:BroadcastText(getglobal("gl_ssmod_id").." player "..ss:GetName().." $omoved to "..team);
				if (stay==1) and (team~="players") then
					GLplayerTrack:SetBySs(ss, "forcedteam", team, 0);
					System:LogAlways("player "..ss:GetName().."$o cannot change team now");
				end
				return;
			end
		end
	end
	System:LogAlways("usage : gl_move [pId] [team] <force 1/0>");
	return;
end

function GLcommands:ReleasePlayer(pId)
	GLplayerTrack:SetById(pId,"forcedteam","",0);
	System:LogAlways("released teamforcing on "..pId);
end

function GLcommands:changeMapCycleAssault()
	GLcommands:changeMapCycle("assault");
end
function GLcommands:changeMapCycleFfa()
	GLcommands:changeMapCycle("ffa");
end
function GLcommands:changeMapCycleTdm()
	GLcommands:changeMapCycle("tdm");
end

function GLcommands:changeMapCycle(changeTo)
	local mcfile=getglobal("gl_mapcycle_"..changeTo);
	if mcfile~="" then
		setglobal("sv_mapcyclefile", mcfile);
		MapCycle:Reload();
		MapCycle:nextmap();
		Server:BroadcastText(getglobal("gl_ssmod_id").." mapcycle changed to "..changeTo);
	else
		System:LogAlways("mapcyclefile not found in server config (gl_mapcycle_"..changeTo..")");		
	end
end




function GLcommands:GLListPlayers()
	local Entity; 
	
	if GameRules then
		Entity = System:GetEntity(GameRules.idScoreboard).cnt;
	elseif ClientStuff then
		Entity = System:GetEntity(ClientStuff.idScoreboard).cnt;
	end

	local iY,X;
	local iLines=Entity:GetLineCount();
	local iColumns=Entity:GetColumnCount();
	local pteam ;
	local pclass;
	local tid;
	local prSpec=1;
	local prBlue=1;
	local prRed=1;
	local prPlay=1;
	System:LogAlways(getglobal("gl_ssmod_id").." Displaying detailed teamlist");
	for tid=-1,2 do

		for iY=0,iLines-1 do
			pteam="";
			pclass="";
			local iteam=Entity:GetEntryXY(ScoreboardTableColumns.iPlayerTeam,iY);
			local idThisClient = Entity:GetEntryXY(ScoreboardTableColumns.ClientID,iY)-1;
			
			if tid==iteam and idThisClient~=-1 then 
				if toNumberOrZero(tid)==-1 and prPlay==1 then
					System:LogAlways("$9[People]               $9Id  Class    Score  Name");
					prPlay=0;
				end
				if toNumberOrZero(tid)==0 and prSpec==1 then
					System:LogAlways("$9[Spectators]           $9Id  Class    Score  Name");
					prSpec=0;
				end
				if toNumberOrZero(tid)==1 and prRed==1 then
					System:LogAlways("$4[Team Red]             $9Id  Class    Score  Name");
					prRed=0;
				end
				if toNumberOrZero(tid)==2 and prBlue==1 then
					System:LogAlways("$2[Team Blue]            $9Id  Class    Score  Name");
					prBlue=0;
				end


				local iclass=Entity:GetEntryXY(ScoreboardTableColumns.iPlayerClass,iY);
				if toNumberOrZero(iclass)==-1 then
					pclass="$5         $1";
				end
				if toNumberOrZero(iclass)==0 then
					pclass="$5Scout    $1";
				end
				if toNumberOrZero(iclass)==1 then
					pclass="$5Engineer $1";
				end
				if toNumberOrZero(iclass)==2 then
					pclass="$5Sniper   $1";
				end
				
				local prcl=idThisClient;
				
				if tonumber(prcl)<10 then
					prcl=tostring(" "..prcl);
				end
				
				local ikscore;
				local pkillscore="   ";
				
				if toNumberOrZero(iteam)~=-1 then
					ikscore=Entity:GetEntryXY(ScoreboardTableColumns.iPlayerScore,iY);
					pkillscore=ikscore;
					if (tonumber(ikscore)<100) and (tonumber(ikscore)>9) then
						pkillscore=tostring(" "..ikscore);
					end
					if (tonumber(ikscore)<10) and (tonumber(ikscore)>-1) then
						pkillscore=tostring("  "..ikscore);
					end
					if (tonumber(ikscore)<0) and (tonumber(ikscore)>-10) then
						pkillscore=tostring(" "..ikscore);
					end
				end
				
				System:LogAlways("$5                       "..prcl.."  "..pclass.."$1"..pkillscore.."    "..Entity:GetEntryXY(ScoreboardTableColumns.sName,iY));
			end
		end
	end
	System:LogAlways("");
end


function GLcommands:GLforceNone()
	setglobal("gl_forcebluejoin",0);
	setglobal("gl_forceredjoin",0);
	System:LogAlways("teams unlocked");
end

function GLcommands:GLlockTeam(team)
	setglobal("gl_forcebluejoin",0);
	setglobal("gl_forceredjoin",0);
	if team=="red" then
		setglobal("gl_forcebluejoin",1);
		System:LogAlways("red team locked");
	end
	if team=="blue" then
		setglobal("gl_forceredjoin",1);
		System:LogAlways("blue team locked");
	end
	
end

function GLcommands:GLunlockall()
	GLcommands:GLforceNone();  --release forced team join
	for tr_id, player in PlayerTrack do
		local pId=player["pid"];
		GLplayerTrack:SetById(pId, "forcedteam", "", 0);
	end
	System:LogAlways("released ALL teamlocks");
end

--protected names functions--

function GLcommands:loadProtected()
	local namesFile = openfile("profiles/server/p_names.txt", "r");
	if(namesFile) then
		protectedNames.namelist = {};
		protectedNames.vn=1;
		local name = read(namesFile, "*l");
		while(name) do
			GLcommands:addProtectedName(name);
			name = read(namesFile, "*l");
		end
		closefile(namesFile);
		System:LogAlways("loaded protected names");
	else
		System:LogAlways("no protected names found (..profiles/server/p_names.txt)");
	end
end

function GLcommands:addProtectedById(pId)
	local ss = Server:GetServerSlotBySSId(pId);
	if ss then
		local name = ss:GetName();
		GLcommands:addProtectedName(name);
		System:LogAlways("$oadded "..name.." $oto protected names");
	else
		System:LogAlways("$oplayer id "..pId.." not found");
	end
end

function GLcommands:addProtectedName(name)
	protectedNames.namelist[protectedNames.vn]=name;
	protectedNames.vn=protectedNames.vn+1;
end

function GLcommands:clearProtected()
	protectedNames.namelist = {};
	protectedNames.vn=1;
	System:LogAlways("$ounloaded all protected names");
end


function GLcommands:printProtectedNames()
	for i, name in protectedNames.namelist do
		System:LogAlways(protectedNames.namelist[i]);
	end
end

function GLcommands:saveProtected()
	local namesFile = openfile("profiles/server/p_names.txt", "w");
	if(namesFile) then 
		for i, pname in protectedNames.namelist do
			write(namesFile, protectedNames.namelist[i].."\n");
		end
		closefile(namesFile);
		System:LogAlways("$osaved all protectednames to profiles/server/p_names.txt");
	end
end


function GLcommands:ProtectedName(name)
	for i, pname in protectedNames.namelist do
		if name==protectedNames.namelist[i] then
			return 1;
		end
	end
	return 0;
end

function GLcommands:requestSpawn(server_slot)
	--if toNumberOrZero(getglobal("gl_allow_teamkilling"))~=1 or toNumberOrZero(getglobal("gl_static_respawn"))>0 then
		local punishTime = toNumberOrZero(GLplayerTrack:GetBySs(server_slot, "extrarespawn"));

		if punishTime==0 then 
			return 1;
		end
		local waitSecs=(toNumberOrZero(server_slot.last_death)+punishTime)-floor(_time);
		if waitSecs>0 then
			local reason=tostring(GLplayerTrack:GetBySs(server_slot, "reason"));
			if reason == "" then
				reason="unknown";
			end
			reason=tostring("$o(reason: "..reason.."$o)");
			if tonumber(floor(_time))~=tonumber(GLplayerTrack:GetBySs(server_slot, "lastmess")) then 
				server_slot:SendText(getglobal("gl_ssmod_id").." Cannot spawn "..reason.." wait $6"..floor(waitSecs).."$o seconds");
				GLplayerTrack:SetBySs(server_slot, "lastmess", tonumber(floor(_time)),0);
				GLplayerTrack:SetBySs(server_slot, "requestedspawn", 1 , 0);
			end
			return 0;
		end
		GLplayerTrack:SetBySs(server_slot, "extrarespawn", 0, 0);
		GLplayerTrack:SetBySs(server_slot, "reason", "", 0);
		GLplayerTrack:SetBySs(server_slot, "lastmess", 0, 0);
	--end
	return 1;
end

function GLcommands:punishPlayer(line)
	--id, <time> <reason>
	if (line) then
		toktable = tokenize(line);
		local time=0;
		local reason="";
		if toktable[1] then
			local pId=tonumber(toktable[1]);
			if toktable[2] then 
				time=toNumberOrZero(toktable[2]);
			end
			tremove(toktable, 1);
			tremove(toktable, 1);
			reason = untokenize(toktable);
			local server_slot = Server:GetServerSlotBySSId(pId);
			if server_slot then
				GameRules:Invoke("OnKill", server_slot);
				if time>0 then
					GLplayerTrack:SetBySs(server_slot, "extrarespawn", time, 0);
					GLplayerTrack:SetBySs(server_slot, "reason", reason, 0);
				end
				if reason ~= "" then
					local timestr="";
					if time>0 then
						timestr=tostring("$o > $6"..time.." $osecond penalty");
					end
					Server:BroadcastText(getglobal("gl_ssmod_id").." player "..server_slot:GetName().." $ohas been punished (reason : "..reason.."$o)"..timestr);
				end
				return;
			end			
		end
	end
	System:LogAlways("usage: gl_punish [pId] <extra respawn time> <reason>");
end

function GLcommands:SetGlPlayerClass(id,pclx)
	local server_slot = Server:GetServerSlotBySSId(id);
	if server_slot then
		if pclx=="sniper1" then
			GLcommands:SetPC(server_slot,"Sniper",1,1,1,0);
		elseif pclx=="sniper2" then
			GLcommands:SetPC(server_slot,"Sniper",1,1,2,0);
		elseif pclx=="engineer1" then
			GLcommands:SetPC(server_slot,"Support",1,1,1,1);
		elseif pclx=="engineer2" then
			GLcommands:SetPC(server_slot,"Support",1,2,1,1);
		elseif pclx=="scout1" then
			GLcommands:SetPC(server_slot,"Grunt",1,1,1,1);
		elseif pclx=="scout2" then
			GLcommands:SetPC(server_slot,"Grunt",1,1,1,2);
		elseif pclx=="scout3" then
			GLcommands:SetPC(server_slot,"Grunt",1,1,1,3);
		elseif pclx=="scout4" then
			GLcommands:SetPC(server_slot,"Grunt",1,1,2,1);
		elseif pclx=="scout5" then
			GLcommands:SetPC(server_slot,"Grunt",1,1,2,2);
		elseif pclx=="scout6" then
			GLcommands:SetPC(server_slot,"Grunt",1,1,2,3);
		else
			System:LogAlways("usuage: gl_cpc [playerid] [class]");
			System:LogAlways("possible classes:");
			System:LogAlways("sniper1   - sniper with sniperrifle");
			System:LogAlways("sniper2   - sniper with rocketlauncher");
			System:LogAlways("engineer1 - engineer with medpacks");
			System:LogAlways("engineer2 - engineer with m16");
			System:LogAlways("scout1    - scout with p90 and ag36");
			System:LogAlways("scout2    - scout with p90 and oicw");
			System:LogAlways("scout3    - scout with p90 and saw");
			System:LogAlways("scout4    - scout with shotgun and ag36");
			System:LogAlways("scout5    - scout with shotgun and oicw");
			System:LogAlways("scout6    - scout with shotgun and saw");
		end
	else
		System:LogAlways("invalid playerid. usuage: gl_cpc [playerid] [class]");
	end
end

function GLcommands:SetPC(server_slot, pcl, weapon1, weapon2,  weapon3, weapon4)
	local pclass=MultiplayerClassDefiniton.PlayerClasses[pcl];
	if pclass~=nil then
		server_slot.InitialPlayerProperties={};
		server_slot.InitialPlayerProperties.StaminaTable=pclass.StaminaTable;
		server_slot.InitialPlayerProperties.move_params=pclass.move_params;
		server_slot.InitialPlayerProperties.health=pclass.health;
		server_slot.InitialPlayerProperties.armor=pclass.armor;
		server_slot.InitialPlayerProperties.model=pclass.model;
			
		local mypack={};
		local no=1;
		
		if weapon1 and pclass.weapon1[weapon1] then
			mypack[no]={ Type="Weapon", Name=pclass.weapon1[weapon1], };
			no=no+1;
		end
		if weapon2 and pclass.weapon2[weapon2] then
			mypack[no]={ Type="Weapon", Name=pclass.weapon2[weapon2], };
			no=no+1;
		end
		if weapon3 and pclass.weapon3[weapon3] then
			mypack[no]={ Type="Weapon", Name=pclass.weapon3[weapon3], };
			no=no+1;
		end
		if weapon4 and pclass.weapon4[weapon4] then
			mypack[no]={ Type="Weapon", Name=pclass.weapon4[weapon4], };
			no=no+1;
		end
		

		if (pclass.primaryWeaponSlot ~= nil) then
			mypack[pclass.primaryWeaponSlot].Primary = 1;
		end
		mypack.Ammo=pclass.InitialAmmo;


		if (pclass.items ~= nil) then
			for i, item in pclass.items do
				mypack[no] = { Type="Item", Name = item, };
				no = no + 1;
			end
		end
		local PlayerEntity=GetSlotPlayer(server_slot);
		local packname;


		if not server_slot.uniqueServerSlotName then
			server_slot.uniqueServerSlotName = "NetPlayerPack" .. count(EquipPacks);
		end
		packname = server_slot.uniqueServerSlotName;
		EquipPacks[ packname ] = mypack; 
		server_slot.InitialPlayerProperties.equipEquipment=packname;
		server_slot.InitialPlayerProperties.sPlayerClass=pcl;
			
		local team = Game:GetEntityTeam(PlayerEntity.id);
		if team~="spectators" then
			local iCurstate=GameRules:GetGameState();
			if iCurstate~=CGS_INPROGRESS then
				GameRules:ChangeTeam(server_slot,team,1);	
			end
		end
	end
end

function GLcommands:DisplaySpawnMessage(server_slot)
	local mes;
	for i=1, 4 do
		mes=tostring(getglobal("gl_spawnmessage"..i));
		if mes~="" then
			server_slot:SendText(mes,3);
			

		end
	end
end

function GLcommands:LoadConfig(fname)
	GLcommands:LoadConfigfile(fname,0);
end

function GLcommands:LoadConfig1(fname)
	GLcommands:LoadConfigfile(fname,1);
end


function GLcommands:LoadConfigfile(fname,restart)
	if (Script:LoadScript('profiles/server/'..tostring(fname)..'.cfg', 1, 0)) then
		System:LogAlways("\001settings loaded '"..fname.."'.");
		if (toNumberOrZero(restart) == 1) then
			
			Game:LoadLevelMPServer(getglobal('gr_NextMap'));
			Script:LoadScript("scripts/default/entities/weapons/WeaponsParams.lua");
			Script:LoadScript("scripts/default/entities/weapons/OICWgrenade.lua");
			Script:LoadScript("scripts/default/entities/weapons/Rocket.lua");
			Script:LoadScript("scripts/default/entities/weapons/AG36Grenade.lua");
			
		end
		return 1;
	elseif (Script:LoadScript('profiles/server/'..tostring(fname), 1, 0)) then
		System:LogAlways("\001settings loaded '"..fname.."'.");
		if (toNumberOrZero(restart) == 1) then
			
			Game:LoadLevelMPServer(getglobal('gr_NextMap'));
			Script:LoadScript("scripts/default/entities/weapons/WeaponsParams.lua");
			Script:LoadScript("scripts/default/entities/weapons/OICWgrenade.lua");
			Script:LoadScript("scripts/default/entities/weapons/Rocket.lua");
			Script:LoadScript("scripts/default/entities/weapons/AG36Grenade.lua");
			
		end
		return 1;
	elseif (Script:LoadScript(tostring(fname), 1, 0)) then
		System:LogAlways("\001settings loaded '"..fname.."'.");
		if (toNumberOrZero(restart) == 1) then
			Game:LoadLevelMPServer(getglobal('gr_NextMap'));
			Script:LoadScript("scripts/default/entities/weapons/WeaponsParams.lua");
			Script:LoadScript("scripts/default/entities/weapons/OICWgrenade.lua");
			Script:LoadScript("scripts/default/entities/weapons/Rocket.lua");
			Script:LoadScript("scripts/default/entities/weapons/AG36Grenade.lua");
			
		end
		return 1;
	end
	
	System:LogAlways("\001failed to open file '"..fname.."'.");
	
	return nil;
end


function GLcommands:PlaceRestartFile()
	local file=openfile("winsv_restart.txt","w");
	if file then 
		closefile(file);
		System:LogAlways("Reboot file created.. server will reboot");
		Server:BroadcastText(getglobal("gl_ssmod_id").." $4<<<THIS SERVER WILL $6SHUTDOWN $4AND $3RESTART $4IN A FEW SECONDS>>>");
	end
end

System:LogAlways(getglobal("gl_ssmod_version"));
System:LogAlways("$3Visit farcry.mine.nu for updates");
--load the protected names
GLcommands:loadProtected();


