Exemplo n.º 1
0
 /// <summary>
 /// The move action.
 /// </summary>
 /// <param name="client">The client that moved.</param>
 /// <param name="message">The move.</param>
 private void ActionMove(TcpClientHandler client, string message)
 {
     if ((this.Board.Turn == ChessColor.White && client == this.WhitePlayer.Client) || (this.Board.Turn == ChessColor.Black && client == this.BlackPlayer.Client))
     {
         string[] sqs = message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
         if (this.Board[sqs[0]].To(this.Board[sqs[1]]))
         {
             this.Server.Logger.LogIf(this.Server.Debug, "Move: " + message + " (" + client.Client.Client.RemoteEndPoint.ToString() + ")");
             this.SendMessageToAll("Moved " + sqs[0] + " " + sqs[1]);
             this.NextTurn();
         }
         else
         {
             this.Server.Logger.LogIf(this.Server.Debug, "Invalid move: " + message + " (" + client.Client.Client.RemoteEndPoint.ToString() + ")");
             client.SendMessage("YourTurn");
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// A method that handles receiving messages.
        /// </summary>
        /// <param name="client">The client the message came from.</param>
        /// <param name="message">The message.</param>
        protected internal void ReceivedMessage(TcpClientHandler client, string message)
        {
            try
            {
                if (this.BlackPlayer.Client != client && this.WhitePlayer.Client != client) return;

                Tuple<string, string> parts = ChessServer.GetParts(message);

                if (this.Actions.ContainsKey(parts.Item1))
                {
                    this.Actions[parts.Item1](client, parts.Item2);
                }
                else
                {
                    client.SendMessage("WTF");
                }
            }
            catch { }
        }