Ejemplo n.º 1
0
 public void Close()
 {
     socket.Close();
     Manager.UserDisconnect(Username);
     AuthPool.BeginRemoveObject(Username);
     LogProvider.AppendRecord(string.Format("[{0}] disconnected", Username));
 }
Ejemplo n.º 2
0
        public RequestObject Move(object info)
        {
            object[] args = JsonConvert.DeserializeObject <object[]>(info.ToString());

            if (turn == args[3].ToString())
            {
                int x = Convert.ToInt32(args[2]);
                if (matrix[x] == "")
                {
                    string tmp = args[1].ToString();
                    matrix[x] = tmp;
                    if (args[3].ToString() == client1Name)
                    {
                        turn = client2Name;
                    }
                    else
                    {
                        turn = client1Name;
                    }

                    LogProvider.AppendRecord(string.Format("user [{0}] - {1} [{2}]", turn, tmp, x.ToString()));
                    return(new RequestObject("Game", "Move", new object[] { tmp, x.ToString() }));
                }
            }
            return(null);
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        private void AuthFacebook(Client client, object args)
        {
            string name = args.ToString();

            remove(client, name);
            LogProvider.AppendRecord(string.Format("loggin facebook user [{0}]", name));
            client.name = name;
            client.Write(new RequestObject("Auth", "LogIn", name));
        }
Ejemplo n.º 5
0
        private void Cancle(Client invitedClient, string creatorName)
        {
            Client creator = clients.clientsList.Find(c => c.name == creatorName);

            creator.isBusy       = false;
            invitedClient.isBusy = false;
            LogProvider.AppendRecord(string.Format("{0} handShake Cancle [{1}]", DateTime.Now.ToString(), creatorName));
            creator.Write(new RequestObject("HandShake", "Cancle", null));
        }
Ejemplo n.º 6
0
        public bool IsOver()
        {
            if (game.IsOver())
            {
                for (int i = 0; i < clients.Count; i++)
                {
                    clients[i].inGame = false;
                    clients[i].isBusy = false;
                    LogProvider.AppendRecord(string.Format("Game Over [{0}]", clients[0].name));

                    clients[i].Write(new RequestObject("Game", "Over", game.Result));
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        public Room(List <Client> clients, string gameName)
        {
            this.clients = clients;
            switch (gameName)
            {
            case "XO":
                game = new XO(clients[0].name, clients[1].name);
                clients[0].inGame = true;
                clients[1].inGame = true;

                LogProvider.AppendRecord(string.Format("user [{0}] - X/0 ", clients[0].name));
                LogProvider.AppendRecord(string.Format("user [{0}] - X/0 ", clients[1].name));

                break;
            }
        }
Ejemplo n.º 8
0
        private void Start(Client invitedClient, string creatorName, string gameName)
        {
            Client        creatorClient = this.clients.clientsList.Find(c => c.name == creatorName);
            List <Client> tmpclients    = new List <Client>();

            tmpclients.Add(creatorClient);
            tmpclients.Add(invitedClient);

            rooms.Add(tmpclients, gameName);

            for (int i = 0; i < tmpclients.Count; i++)
            {
                LogProvider.AppendRecord(string.Format("{0} Start [{1}]", DateTime.Now.ToString(), tmpclients[i].name));
                tmpclients[i].Write(new RequestObject("Game", "Start", new object[] { rooms.rooms.Count - 1, gameName, tmpclients[0].name }));
            }
        }
Ejemplo n.º 9
0
        public bool Handle(IClientObject client, RequestObject request)
        {
            if (request.Module != "auth")
            {
                return(false);
            }

            string key = request.Args.ToString();

            AuthPool.PoolObject obj = AuthPool.GetRecordByKey(key);

            if (obj == null)
            {
                client.SendMessage(ResponseConstructor.GetErrorNotification("authorization failed", "login"));
                return(true);
            }
            if (Manager.FindClient(obj.Username) != null)
            {
                client.SendMessage(ResponseConstructor.GetErrorNotification("You have already logged in", "login"));
                client.Close();
                return(true);
            }
            client.Username = obj.Username;
            switch (obj.status)
            {
            case AuthStatus.User:
                client.Role = new User(client);
                client.SendMessage(ResponseConstructor.GetLoginResultNotification("user", obj.Username));
                LogProvider.AppendRecord(string.Format("[{0}]: Logged in as user", client.Username));
                break;

            case AuthStatus.Banned:
                client.Role = new BannedUser(client, obj.banTill);
                client.SendMessage(ResponseConstructor.GetLoginResultNotification("banned", obj.Username));
                LogProvider.AppendRecord(string.Format("[{0}]: Logged in as banned user", client.Username));
                break;

            case AuthStatus.Admin:
                client.Role = new Admin(client);
                client.SendMessage(ResponseConstructor.GetLoginResultNotification("admin", obj.Username));
                LogProvider.AppendRecord(string.Format("[{0}]: Logged in as admin", client.Username));
                break;
            }
            Manager.AddClient(client);
            return(true);
        }
Ejemplo n.º 10
0
        public virtual void Handle(IClientObject client, string request)
        {
            RequestObject req = null;

            try
            {
                req = JsonConvert.DeserializeObject <RequestObject>(request);
            }
            catch (Exception e)
            {
                LogProvider.AppendRecord(string.Format("user {0} sent bad request {1}", client.Username, request));
                return;
            }

            foreach (IHandlerModule module in client.Role.Handlers)
            {
                if (module.Handle(client, req))
                {
                    break;
                }
            }
        }
Ejemplo n.º 11
0
 public void Dell(Client client)
 {
     LogProvider.AppendRecord(string.Format("Remove client [{0}]", client.name));
     clientsList.Remove(client);
 }