Пример #1
0
 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));
     }
 }
Пример #2
0
 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();
 }
Пример #3
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;
     }
 }
Пример #4
0
 void Exit(Client client)
 {
     clientList[client.Name].Stop();
     clientList.Remove(client.Name);
     //ClientListChanged(null, new ClientListEventArgs(clientList));
 }
Пример #5
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;
 }
Пример #6
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));
     }
 }
Пример #7
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);
        }