public string ToMessage(Command command) { string message = jsonParser.CommandToJson(command); #if DEBUG Console.WriteLine("Out: {0}", message); #endif return message; }
//fields public void RiseEvent(TcpClient client, Command command) { switch (command.CurrentCommand) { case "Connect": ConnectEvent(command.Data, client); break; } }
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); }
//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; } }
//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; } }
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; }
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)); } }
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); }
//methods public string CommandToJson(Command command) { return JsonConvert.SerializeObject(command); }