#include ww2x\_drm;

welcomeMsg()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_dead");

	if(isDefined(self.pers["welcdone"])) return;

	self.pers["welcdone"] = true;

	if(isDefined(self.wwx_name)) self thread clanWelcome();
	else
	{
		if(!level.wwx_pwelcome) return;
		
		// welcome message line 1
            if(level.wwx_linux_server == 1)
            {
		self iprintlnbold(&"WELCOME_MESSAGE_LINE1");
		self iprintlnbold(&"CUSTOM_SERVER_NAME", &"WELCOME_MESSAGE_LINE2");
		wait 4;
            }
            else if(level.wwx_linux_server == 2)
            {
            self iprintlnbold(&"WELCOME_MESSAGE_LINE1A", self.name);
		self iprintlnbold(&"CUSTOM_SERVER_NAME", &"WELCOME_MESSAGE_LINE2");
		wait 4;
            }
            else
            {
            self iprintlnbold(&"WELCOME_MESSAGE_LINE1A", self);
		self iprintlnbold(&"CUSTOM_SERVER_NAME", &"WELCOME_MESSAGE_LINE2");
		wait 4;
            }

		// welcome message line 2
            level.wwx_vote = [[level.wwx_cvardef]]("g_allowvote", 1, 0, 1, "int");
		if(level.wwx_clanvoting || level.wwx_vote == 0) self iprintlnbold(&"WELCOME_NO_VOTE");
		else self iprintlnbold(&"WELCOME_VOTE_ALLOWED");

		// welcome message line 3 - custom
		if(level.wwx_pwelmsg >= 1)
		{
			wait level.wwx_pweldelay;
			self iprintlnbold(&"CUSTOM_WELCOME_MESSAGE_1");
		}
		else return;

		// welcome message line 4 - custom
		if(level.wwx_pwelmsg >= 2)
		{
			wait level.wwx_pweldelay;
			self iprintlnbold(&"CUSTOM_WELCOME_MESSAGE_2");
		}
		else return;

		// welcome message line 5 - custom
		if(level.wwx_pwelmsg == 3)
		{
			wait level.wwx_pweldelay;
			self iprintlnbold(&"CUSTOM_WELCOME_MESSAGE_3");
		}
		else return;
	}
}
	
clanWelcome()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_dead");

	if(!level.wwx_clanWelcome) return;

      if(level.wwx_linux_server == 1)
      {
	self iprintlnbold(&"WELCOME_MESSAGE_LINE1");
	self iprintlnbold(&"CUSTOM_SERVER_NAME", &"WELCOME_MESSAGE_LINE2");
	wait 4;
      }
      else if(level.wwx_linux_server == 2)
      {
	self iprintlnbold(&"WELCOME_MESSAGE_LINE1A", self.name);
	self iprintlnbold(&"CUSTOM_SERVER_NAME", &"WELCOME_MESSAGE_LINE2");
	wait 4;
      }
      else
      {
	self iprintlnbold(&"WELCOME_MESSAGE_LINE1A", self);
	self iprintlnbold(&"CUSTOM_SERVER_NAME", &"WELCOME_MESSAGE_LINE2");
	wait 4;
      }

	if(level.wwx_clanvoting)
	{
		if(level.wwx_clvote[self.wwx_clid]) self iprintlnbold(self.pers["clantag"], &"WELCOME_CLAN_VOTE_ALLOWED");
		else self iprintlnbold(self.pers["clantag"], &"WELCOME_CLAN_NO_VOTE");
	}
	else self iprintlnbold(&"WELCOME_VOTE_ALLOWED");

	switch(self.wwx_clid)
	{
		case 1:
		self thread clan1msgs();
		break;

		case 2:
		self thread clan2msgs();
		break;

		case 3:
		self thread clan3msgs();
		break;

		case 4:
		self thread clan4msgs();
		break;
	}
}

clan1msgs()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_dead");

	// clan message line 3 - custom
	if(level.wwx_clan1msg >= 1)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN1_MESSAGE_1");
	}
	else return;

	// clan message line 4 - custom
	if(level.wwx_clan1msg >= 2)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN1_MESSAGE_2");
	}
	else return;

	// clan message line 5 - custom
	if(level.wwx_clan1msg == 3)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN1_MESSAGE_3");
	}
	else return;	
}

clan2msgs()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_dead");

	// clan message line 3 - custom
	if(level.wwx_clan2msg >= 1)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN2_MESSAGE_1");
	}
	else return;

	// clan message line 4 - custom
	if(level.wwx_clan2msg >= 2)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN2_MESSAGE_2");
	}
	else return;

	// clan message line 5 - custom
	if(level.wwx_clan2msg == 3)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN2_MESSAGE_3");
	}
	else return;	
}

clan3msgs()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_dead");

	// clan message line 3 - custom
	if(level.wwx_clan3msg >= 1)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN3_MESSAGE_1");
	}
	else return;

	// clan message line 4 - custom
	if(level.wwx_clan3msg >= 2)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN3_MESSAGE_2");
	}
	else return;

	// clan message line 5 - custom
	if(level.wwx_clan3msg == 3)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN3_MESSAGE_3");
	}
	else return;	
}

clan4msgs()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_dead");

	// clan message line 3 - custom
	if(level.wwx_clan4msg >= 1)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN4_MESSAGE_1");
	}
	else return;

	// clan message line 4 - custom
	if(level.wwx_clan4msg >= 2)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN4_MESSAGE_2");
	}
	else return;

	// clan message line 5 - custom
	if(level.wwx_clan4msg == 3)
	{
		wait level.wwx_clandelay;
		self iprintlnbold(&"CUSTOM_CLAN4_MESSAGE_3");
	}
	else return;	
}

serverMessages()
{
	level endon("wwx_gameover");

	svrmsg = [];
	svrmsg[0] = &"CUSTOM_SERVER_MESSAGE_1";
	svrmsg[1] = &"CUSTOM_SERVER_MESSAGE_2";
	svrmsg[2] = &"CUSTOM_SERVER_MESSAGE_3";
	svrmsg[3] = &"CUSTOM_SERVER_MESSAGE_4";
	svrmsg[4] = &"CUSTOM_SERVER_MESSAGE_5";
	svrmsg[5] = &"CUSTOM_SERVER_MESSAGE_6";
	svrmsg[6] = &"CUSTOM_SERVER_MESSAGE_7";
	svrmsg[7] = &"CUSTOM_SERVER_MESSAGE_8";
	svrmsg[8] = &"CUSTOM_SERVER_MESSAGE_9";
	svrmsg[9] = &"CUSTOM_SERVER_MESSAGE_10";

	level.wwx_pausesvrmsg = false;

	while(!level.wwx_gameover)
	{
		wait (level.wwx_svrmsg_delay_main / 2);

		while(level.wwx_pausesvrmsg) wait 1;

		for(i = 0; i < level.wwx_svrmsg; i++)
		{
			iprintln(svrmsg[i]);
			wait level.wwx_svrmsg_delay_msg;
		}
	
		if(level.wwx_svrmsg_info >= 1)
			thread ww2x\_wwx_maps::DisplayMapRotation();

		if(!level.wwx_svrmsg_loop)
			break;

		wait (level.wwx_svrmsg_delay_main / 2);
	}
}

spectatorMessages()
{
	level endon("wwx_gameover");
	self endon("disconnect");
	self endon("wwx_spawned");

	specmsg = [];
	specmsg[0] = &"CUSTOM_SPECTATOR_MESSAGE_1";
	specmsg[1] = &"CUSTOM_SPECTATOR_MESSAGE_2";
	specmsg[2] = &"CUSTOM_SPECTATOR_MESSAGE_3";
	specmsg[3] = &"CUSTOM_SPECTATOR_MESSAGE_4";
	specmsg[4] = &"CUSTOM_SPECTATOR_MESSAGE_5";
	specmsg[5] = &"CUSTOM_SPECTATOR_MESSAGE_6";
	specmsg[6] = &"CUSTOM_SPECTATOR_MESSAGE_7";
	specmsg[7] = &"CUSTOM_SPECTATOR_MESSAGE_8";
	specmsg[8] = &"CUSTOM_SPECTATOR_MESSAGE_9";
	specmsg[9] = &"CUSTOM_SPECTATOR_MESSAGE_10";

	while(isPlayer(self) && self.pers["team"] == "spectator")
	{
		for(i = 0; i < level.wwx_specmsg; i++)
		{
			self iprintln(specmsg[i]);
			wait level.wwx_specmsg_delay_msg;
		}

		wait (level.wwx_svrmsg_delay_main / 2);
	}
}

motdrotate()
{
	count = 1;
	
	for(;;)
	{
		cvarname = "wwx_motd" + count;
		msg = drm_getCvar(cvarname);

		if(isDefined(msg) && (msg.size > 0)) count = count + 1;
		else
		{
			msg = drm_getCvar("wwx_motd1" );
			count = 2;
		}

		setCvar("scr_motd", msg);
		wait level.wwx_motdrotdelay;
	}
}
