Exemplo n.º 1
0
 public string ToMessage(Command command)
 {
     string message = jsonParser.CommandToJson(command);
     #if DEBUG
     Console.WriteLine("Out: {0}", message);
     #endif
     return message;
 }
Exemplo n.º 2
0
 //fields
 public void RiseEvent(TcpClient client, Command command)
 {
     switch (command.CurrentCommand)
     {
         case "Connect":
             ConnectEvent(command.Data, client);
             break;
     }
 }
Exemplo n.º 3
0
        public void LoginTest()
        {
            Command commandA = new Command(Command.Commands.Connect, "AName");
            string messageA = protocol.ToMessage(commandA);
            messenger.SendMessage(tcpClientA, messageA);
            string responseA = messenger.ReadMessage(tcpClientA);
            Assert.AreEqual("123", responseA);

            Command commandB = new Command(Command.Commands.Connect, "BName");
            string messageB = protocol.ToMessage(commandB);
            string responseB = messenger.ReadMessage(tcpClientB);
            Assert.AreEqual("123", responseB);
        }
Exemplo n.º 4
0
 //methods
 public void RiseEvent(Game game, Client client, Command command)
 {
     switch (command.CurrentCommand)
     {
         case "Confirm":
             ConfirmEvent(game, client);
             break;
         case "Reject":
             RejectEvent(game, client);
             break;
         case "Move":
             MoveEvent(game, client, command.Data);
             break;
         case "Exit":
             ExitEvent(game, client);
             break;
     }
 }
Exemplo n.º 5
0
 //methods
 public void RiseEvent(Client client, Command command)
 {
     switch (command.CurrentCommand)
     {
         case "GetPlayers":
             GetPlayersEvent(client);
             break;
         case "Invite":
             InviteEvent(client, command.Data);
             break;
         case "Confirm":
             ConfirmEvent(client);
             break;
         case "Reject":
             RejectEvent(client);
             break;
         case "Exit":
             ExitEvent(client);
             break;
     }
 }
Exemplo n.º 6
0
 private void Reject(Client client)
 {
     Command command = new Command(Command.Commands.Reject, "");
     string message = clientList[client.Name].Protocol.ToMessage(command);
     clientList[client.Name].Client.SendMessage(message);
     client.InviterName = string.Empty;
 }
Exemplo n.º 7
0
 private void Invite(Client client, string destinationName)
 {
     if (client.Name != destinationName)
     {
         clientList[destinationName].Client.InviterName = client.Name;
         Command command = new Command(Command.Commands.Invite, client.Name);
         clientList[destinationName].Client.SendMessage(clientList[destinationName].Protocol.ToMessage(command));
     }
 }
Exemplo n.º 8
0
        private void GetPlayers(Client client)
        {
            List<Person> personList = new List<Person>();
            foreach (KeyValuePair<string, ClientThread> keyValuePair in clientList)
            {
                if (keyValuePair.Value.Client.Name != client.Name)
                {
                    personList.Add(new Person(keyValuePair.Value.Client.Name, keyValuePair.Value.Client.GameType));
                }
            }

            string data = clientList[client.Name].Protocol.PersonListToMessage(personList);
            Command command = new Command(Command.Commands.GetPlayers, data);
            string message = clientList[client.Name].Protocol.ToMessage(command);
            client.SendMessage(message);
        }
Exemplo n.º 9
0
 //methods
 public string CommandToJson(Command command)
 {
     return JsonConvert.SerializeObject(command);
 }