コード例 #1
0
        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);
            }
        }
コード例 #2
0
 private void StartGameReceived(HostName remoteAddress, NetworkMessagePacket message)
 {
     if (OnStartGameReceived != null)
     {
         OnStartGameReceived(remoteAddress.CanonicalName);
     }
 }
コード例 #3
0
 private void MessageAcknowledged(HostName remoteAddress, NetworkMessagePacket message)
 {
     RemoveMessageFromQueue(message.ID);
 }
コード例 #4
0
        private void PlayersTurnDetailsReceived(HostName remoteAddress, NetworkMessagePacket message)
        {
            PlayersTurnDetails iPlayersTurnDetails = Serialiser.DeserializeFromXml<PlayersTurnDetails>(message.MessageText);

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

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

            if (OnLettersReceived != null)
            {
                OnLettersReceived(remoteAddress.CanonicalName, letters);
            }
        }
コード例 #7
0
 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);
         }
     }
 }
コード例 #8
0
        private void ExchangeLetterReceived(HostName remoteAddress, NetworkMessagePacket message)
        {
            TileDetails letter = Serialiser.DeserializeFromXml<TileDetails>(message.MessageText);

            if (OnLetterExchange != null)
            {
                OnLetterExchange(remoteAddress.CanonicalName, letter);
            }
        }
コード例 #9
0
 /*
 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);
     }
 }
コード例 #10
0
		protected abstract void DecodeMessage(HostName remoteAddress, NetworkMessagePacket message);
コード例 #11
0
		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);
			}
		}