コード例 #1
0
        private void Invite(Client clientcreator, string invitedName, string gameName)
        {
            clientcreator.isBusy = true;
            Client clientinvited = clients.clientsList.Find(c => c.name == invitedName);

            if (clientinvited.inGame)
            {
                Lobby.SendNotification("This user is already in the game", clientinvited);
                Lobby.SendClients(clientinvited, clients.clientsList);
                return;
            }
            if (clientinvited == null)
            {
                Lobby.SendNotification("This user has already logged out", clientinvited);
                Lobby.SendClients(clientinvited, clients.clientsList);
                return;
            }
            if (clientinvited.isBusy)
            {
                Lobby.SendNotification("This user is busy", clientcreator);
                clientcreator.isBusy = false;
                return;
            }
            clientinvited.isBusy = true;
            LogProvider.AppendRecord(string.Format("{0} invited client [{1}] vs game [{2}]",
                                                   DateTime.Now.ToString(), clientcreator.name, gameName));

            clientinvited.Write(new RequestObject("HandShake", "Invited",
                                                  new object[] { clientcreator.name, gameName }));


            LogProvider.AppendRecord(string.Format("{0} Wait [{1}]", DateTime.Now.ToString(), clientcreator.name));
            clientcreator.Write(new RequestObject("HandShake", "Wait", null));
        }
コード例 #2
0
        private void Invite(Client clientcreator, string invitedName, string gameName)
        {
            clientcreator.isBusy = true;
            Client clientinvited = clients.clientsList.Find(c => c.name == invitedName);

            if (clientinvited.inGame)
            {
                Lobby lobby = new Lobby();
                lobby.SendNotification("Данный пользователь уже находится в игре", clientinvited);
                lobby.SendClients(clientinvited, clients.clientsList);
                return;
            }
            if (clientinvited == null)
            {
                Lobby lobby = new Lobby();
                lobby.SendNotification("Данный пользователь уже вышел из системы", clientinvited);
                lobby.SendClients(clientinvited, clients.clientsList);
                return;
            }
            if (clientinvited.isBusy)
            {
                Lobby lobby = new Lobby();
                lobby.SendNotification("Данный пользователь сейчас занят", clientcreator);
                clientcreator.isBusy = false;
                return;
            }
            clientinvited.isBusy = true;

            string strInfo = JsonConvert.SerializeObject(new RequestObject("HandShake", "Invited", new object[] { clientcreator.name, gameName }));

            clientinvited.Write(strInfo);


            strInfo = JsonConvert.SerializeObject(new RequestObject("HandShake", "Wait", "null"));
            clientcreator.Write(strInfo);
        }