#include extreme\_ex_utils;

checkInit(checkrank)
{
	self endon("disconnect");

	// check guid number is authorised (this function is disabled until COD2 getGuid is fixed!
	//if(level.ex_security && !self checkGuid()) return;

	// check what clan they are in
	if(!self checkClan()) self.ex_name = undefined;

	// if the rank system is on, check if they have a preset rank
	if(level.ex_ranksystem && checkrank) self.pers["preset_rank"] = self checkPresetRank();
}

checkGuid()
{
	self endon("disconnect");

	playerGuid = self getGuid();

	if(!playerGuid) return false;

	count = 0;
		
	for(;;)
	{
		guid = [[level.ex_drm]]("ex_guid_", 0, 0, 999999, "int");

		if(!guid) break;
		else if(guid == playerGuid) return true;
		else count ++;
	}

	return false;
}

checkClan()
{
	self endon("disconnect");

	clan_num = false;
	
	for(i = 1; i < 5; i++)
		if(checkClanID(i)) clan_num = i;

	if(!clan_num) return false;

	clan = extreme\_ex_utils::monotone(level.ex_cltag[clan_num]);
	clanstr = extreme\_ex_utils::monotone(self.name);
	pn = "";

	for(i = clan.size; i < clanstr.size; i++) pn += clanstr[i];
			
	self.ex_name = pn;
	self.ex_clid = clan_num;

	clantag = [];
	clantag[1] = &"CUSTOM_CLAN1_TAG";
	clantag[2] = &"CUSTOM_CLAN2_TAG";
	clantag[3] = &"CUSTOM_CLAN3_TAG";
	clantag[4] = &"CUSTOM_CLAN4_TAG";
	self.pers["clantag"] = clantag[self.ex_clid];

	return true;
}

checkClanID(check)
{
	clanstr = extreme\_ex_utils::monotone(self.name);
	cn = "";
		
	if(clanstr.size <= level.ex_cltag[check].size) return 0;
	else
	{
		for ( i = 0; i <  level.ex_cltag[check].size; i++ )
			cn += clanstr[i];
	}

	if(cn ==  level.ex_cltag[check]) return 1;
	else return 0;
}

checkPresetRank()
{
	self endon("disconnect");

	// convert the players name
	playername = convertMUJ(self.name);

	count = 0;
		
	for(;;)
	{
		// get the preset player name
		name_check = [[level.ex_drm]]("ex_psr_name_" + count, "", "", "", "string");

		// check there is a preset player name, if not end here!
		if(name_check == "") break;

		// convert name_check
		name_check = convertMUJ(name_check);

		// if the names match, break here and set rank
		if(name_check == playername) break;
		else count ++;
	}

	if(name_check == "") return 0;
	else return [[level.ex_drm]]("ex_psr_rank_" + count, 0, 0, 12, "int");
}

set_ignore_player()
{
	self.pers["dontkick"] = false;
	// convert the players name
	playername = convertMUJ(self.name);

	count = 0;
		
	for(;;)
	{
		// get the preset player name
		name_check = [[level.ex_drm]]("ex_ddp_name_" + count, "", "", "", "string");

		// check there is a preset player name, if not end here!
		if(name_check == "") break;

		// convert name_check
		name_check = convertMUJ(name_check);

		// if the names match, break here and set rank
		if(name_check == playername) 
		{
			self.pers["dontkick"] = true;
			break;
		}
		
		
		else count ++;
	}
}
