private void SetActivePlayerReceived(HostName remoteAddress, NetworkMessagePacket message)
        {
            PlayerDetails activePlayer = Serialiser.DeserializeFromXml<PlayerDetails>(message.MessageText);

            if(!m_activePlayers.Contains(activePlayer))
            {
                m_activePlayers.Add(activePlayer);
            }

            if (OnSetActivePlayerReceived != null)
            {
                OnSetActivePlayerReceived(activePlayer);
            }
        }
 private void StartGameReceived(HostName remoteAddress, NetworkMessagePacket message)
 {
     if (OnStartGameReceived != null)
     {
         OnStartGameReceived(remoteAddress.CanonicalName);
     }
 }
 private void MessageAcknowledged(HostName remoteAddress, NetworkMessagePacket message)
 {
     RemoveMessageFromQueue(message.ID);
 }
        private void PlayersTurnDetailsReceived(HostName remoteAddress, NetworkMessagePacket message)
        {
            PlayersTurnDetails iPlayersTurnDetails = Serialiser.DeserializeFromXml<PlayersTurnDetails>(message.MessageText);

            if(OnPlayersTurnDetailsReceived != null)
            {
                OnPlayersTurnDetailsReceived(remoteAddress.CanonicalName, iPlayersTurnDetails);
            }
        }
        private void GameJoinedReceived(HostName remoteAddress, NetworkMessagePacket message)
        {
            PlayerDetails activePlayer = Serialiser.DeserializeFromXml<PlayerDetails>(message.MessageText);

            if (OnGameJoinedReceived != null)
            {
                OnGameJoinedReceived(remoteAddress.CanonicalName, activePlayer);
            }
        }
        private void LettersReceived(HostName remoteAddress, NetworkMessagePacket message)
        {
            GameLetters letters = Serialiser.DeserializeFromXml<GameLetters>(message.MessageText);

            if (OnLettersReceived != null)
            {
                OnLettersReceived(remoteAddress.CanonicalName, letters);
            }
        }
 private void GameCreatedReceived(HostName remoteAddress, NetworkMessagePacket message)
 {
     if (remoteAddress.CanonicalName != CurrentIPAddress())
     {
         GameDetails gameInformation = new GameDetails() { CreatorsIpAddress = remoteAddress.CanonicalName, GameTitle = message.MessageText };
         if (OnGameCreatedReceived != null)
         {
             OnGameCreatedReceived(gameInformation);
         }
     }
 }
        private void ExchangeLetterReceived(HostName remoteAddress, NetworkMessagePacket message)
        {
            TileDetails letter = Serialiser.DeserializeFromXml<TileDetails>(message.MessageText);

            if (OnLetterExchange != null)
            {
                OnLetterExchange(remoteAddress.CanonicalName, letter);
            }
        }
 /*
 public void CheckActivePlayers()
 {
     if (DateTime.Now.Subtract(m_lastCommunicationsCheck).TotalSeconds > 5)
     {
         m_lastCommunicationsCheck = DateTime.Now;
         if (m_activePlayers.Count > 0)
         {
             foreach (PlayerDetails iPlayerDetails in m_activePlayers)
             {
             }
         }
     }
 }
 */
 protected override void DecodeMessage(HostName remoteAddress, NetworkMessagePacket message)
 {
     try
     {
         switch (message.Command)
         {
             case eProtocol.Acknowledge:
                 MessageAcknowledged(remoteAddress, message);
                 break;
             case eProtocol.ExchangeLetter:
                 ExchangeLetterReceived(remoteAddress, message);
                 break;
             case eProtocol.GameCancelled:
                 GameCancelledReceived(remoteAddress, message);
                 break;
             case eProtocol.GameCreated:
                 GameCreatedReceived(remoteAddress, message);
                 break;
             case eProtocol.GameJoined:
                 GameJoinedReceived(remoteAddress, message);
                 break;
             case eProtocol.ReadyToStart:
                 ReadyToStartReceived(remoteAddress, message);
                 break;
             case eProtocol.SendLetters:
                 LettersReceived(remoteAddress, message);
                 break;
             case eProtocol.SetActivePlayer:
                 SetActivePlayerReceived(remoteAddress, message);
                 break;
             case eProtocol.StartGame:
                 StartGameReceived(remoteAddress, message);
                 break;
             case eProtocol.PlayersTurnDetails:
                 PlayersTurnDetailsReceived(remoteAddress, message);
                 break;
         }
     }
     catch (Exception ex)
     {
         PostMessage(ex.Message);
     }
 }
		protected abstract void DecodeMessage(HostName remoteAddress, NetworkMessagePacket message);
		private void AcknowledgedMessage(string recipientsIP, NetworkMessagePacket messagePacket)
		{
			if (messagePacket.Command != eProtocol.Acknowledge)
			{
				NetworkMessage message = new NetworkMessage()
				{
					RecipientsIP = recipientsIP,
					MessagePacket = new NetworkMessagePacket()
					{
						ID = messagePacket.ID,
						Command = eProtocol.Acknowledge
					}
				};

				AddMessageToQueue(message);
			}
		}