示例#1
0
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="args">the arguments for the command.</param>
 /// <param name="client">the client that gave the command</param>
 /// <returns></returns>
 public TaskResult Execute(string[] args, TcpClient client = null)
 {
     // needs to be only one argument.
     if (args.Length != 1)
     {
         return(new TaskResult("bad args", false));
     }
     try
     {
         string name = args[0];
         // find the game to close.
         MultiPlayerGame game = model.GetGame(client);
         // get the client we need to send him the close msg.
         TcpClient opp = game.GetOpponent(client);
         // error - eather no opp or no game.
         if (game == null || opp == null)
         {
             return(new TaskResult(null, false));
         }
         // send the opp the game is over.
         ch.SendMessage(opp, "game over");
         // disconnect the current client.
         return(new TaskResult("disconnect", false));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(new TaskResult("error occured", false));
     }
 }
示例#2
0
 /// <summary>
 /// Executes the command.
 /// </summary>
 /// <param name="args">the arguments for the command.</param>
 /// <param name="client">the client that gave the command</param>
 /// <returns></returns>
 public TaskResult Execute(string[] args, TcpClient client = null)
 {
     // needs to be only one argument.
     if (args.Length != 1)
     {
         return(new TaskResult("bad args", false));
     }
     try
     {
         string move = args[0];
         // find the playing game.
         MultiPlayerGame game = model.GetGame(client);
         // get the client we need to send him the close msg.
         TcpClient opp = game.GetOpponent(client);
         if (game == null || opp == null)
         {
             return(new TaskResult(null, false));
         }
         // json solution.
         JObject sol = new JObject
         {
             { "Name", game.Name },
             { "Direction", move }
         };
         string Jsol = JsonConvert.SerializeObject(sol);
         // send the opp the players move.
         ch.SendMessage(opp, Jsol);
         // stay connected.
         return(new TaskResult("", true));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(new TaskResult("error occured", false));
     }
 }