private void Confirm(Client client) { if (client.Name != string.Empty) { Client secondClient = clientList[client.InviterName].Client; Exit(client.InviterName); Exit(client.Name); secondClient.InviterName = string.Empty; client.InviterName = string.Empty; NewGame(null, new GameEventArgs(client, secondClient)); } }
public void AddClient(Client client) { ClientThread clientThread = new ClientThread(); clientThread.Client = client; clientThread.Protocol = new Protocol(); clientThread.EventRiser = new ClientEventRiser(); clientThread.EventRiser.GetPlayersEvent += new ClientEventRiser.GetPlayers(GetPlayers); clientThread.EventRiser.InviteEvent += new ClientEventRiser.Invite(Invite); clientThread.EventRiser.ConfirmEvent += new ClientEventRiser.Confirm(Confirm); clientThread.EventRiser.RejectEvent += new ClientEventRiser.Reject(Reject); clientThread.EventRiser.ExitEvent += new ClientEventRiser.Exit(Exit); clientList.Add(client.Name, clientThread); clientThread.Start(); }
//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; } }
void Exit(Client client) { clientList[client.Name].Stop(); clientList.Remove(client.Name); //ClientListChanged(null, new ClientListEventArgs(clientList)); }
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); }