/**
 * This class parses network events sent from the NetClient, such as players connecting or disconnecting from the game.
 */
class ChatMessageFormatNetwork
{
}

ChatMessageFormatNetwork.clientlist = class
{
	parse()
	{
		return { "text": getUsernameList() };
	}
};

ChatMessageFormatNetwork.connect = class
{
	parse(msg)
	{
		// HostEnhanced - START
		// This part executes in-game when someone is joining to the game 
		// Possibly could be separated?
		let playersBanned = botManagerHostEnhanced.get("ban").instance.getIds();		
		let joinedNameFull = g_PlayerAssignments[msg.guid] ? g_PlayerAssignments[msg.guid].name : "";	
		let joinedName = splitRatingFromNick(joinedNameFull).nick;
		log("debug ChatMessageFormatNetwork.js:joinedNameFull:"+joinedNameFull);	
		if ( playersBanned.some(elem => elem.toLowerCase() === joinedName.toLowerCase())) {
			log("debug ChatMessageFormatNetwork.js:PERMABAN FOUND, kicking..:");	
				kickPlayer(joinedNameFull, true);
		}
		// HostEnhanced - END
		
		return {
			"text": sprintf(
					g_PlayerAssignments[msg.guid].player != -1 ?
					// Translation: A player that left the game joins again
					translate("%(player)s is starting to rejoin the game.") :
					// Translation: A player joins the game for the first time					
					translate("%(player)s is starting to join the game."),
				{ "player": colorizePlayernameByGUID(msg.guid) })
		};
	
	}
};

ChatMessageFormatNetwork.disconnect = class
{
	parse(msg)
	{
		return {
			"text": sprintf(translate("%(player)s has left the game."), {
				"player": colorizePlayernameByGUID(msg.guid)
			})
		};
	}
};

ChatMessageFormatNetwork.kicked = class
{
	parse(msg)
	{
		return {
			"text": sprintf(
				msg.banned ?
					translate("%(username)s has been banned") :
					translate("%(username)s has been kicked"),
				{
					"username": colorizePlayernameHelper(
						msg.username,
						g_Players.findIndex(p => p.name == msg.username)
					)
				})
		};
	}
};

ChatMessageFormatNetwork.rejoined = class
{
	parse(msg)
	{
		return {
			"text": sprintf(
				g_PlayerAssignments[msg.guid].player != -1 ?
					// Translation: A player that left the game joins again
					translate("%(player)s has rejoined the game.") :
					// Translation: A player joins the game for the first time
					translate("%(player)s has joined the game."),
				{ "player": colorizePlayernameByGUID(msg.guid) })
		};
	}
};
