コード例 #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 Registration(Client client, object args)
        {
            object[] arg  = JsonConvert.DeserializeObject <object[]>(args.ToString());
            Person   user = new Person(arg[0].ToString(), arg[1].ToString(), arg[2].ToString());
            string   info = auth.api.Reg(user);

            Lobby.SendNotification(info, client);
        }
コード例 #3
0
        public void Dispacher(Client client, RequestObject info)
        {
            switch (info.Cmd)
            {
            case "Registration":
                string res = Registration(client, info.Args);
                lobby.SendNotification(res, client);
                break;

            case "LogIn":
                res = LogIn(client, info.Args);
                lobby.SendNotification(res, client);
                break;

            case "LogOut":
                LogOut(client);
                break;
            }
        }
コード例 #4
0
        private void LogIn(Client client, object args)
        {
            object[] arg  = JsonConvert.DeserializeObject <object[]>(args.ToString());
            Person   user = new Person(arg[0].ToString(), arg[1].ToString(), null);

            remove(client, user.name);
            string flag = auth.api.LogIn(user);

            if (flag == "true")
            {
                client.name = user.name;
                client.Write(new RequestObject("Auth", "LogIn", user.name));
            }
            else
            {
                Lobby.SendNotification("Please check that you have entered your login and password correctly", client);
            }
        }
コード例 #5
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);
        }