Пример #1
0
        public void doLogin(Socket clientSocket)
        {
            string[] fields   = Message.Split('|');
            string   username = fields[0];
            string   password = fields[1];
            User     user     = Singleton.Singleton.Instance.DatabaseConnection.isPasswordRight(username, password);

            if (user != null)
            {
                if (Singleton.Singleton.Instance.isUserLogged(username))
                {
                    BasicPacket bp = new BasicPacket(GameProtocol.AlreadyOnlinePacketID());
                    Othello.Server.SendPacket(clientSocket, bp.getData());
                }
                else
                {
                    user.InGame = false;
                    user.Socket = clientSocket;
                    Singleton.Singleton.Instance.ListOfUsersLogged.Add(user);
                    //Send to current user logged the list with all the users logged and the status of them
                    string PacketMessage = "";
                    foreach (User u in Singleton.Singleton.Instance.ListOfUsersLogged)
                    {
                        if (u.Username == username)
                        {
                            continue;
                        }
                        PacketMessage += u.Username + ":" + u.IsChallenged + ":" + u.InGame + "|";
                        MessagePacket messagePacket = new MessagePacket(GameProtocol.AlertUsersNewUserLoggedID(), username + ":False");
                        Othello.Server.SendPacket(u.Socket, messagePacket.getData());
                    }
                    MessagePacket packet = new MessagePacket(GameProtocol.UsersLoggedListPacketID(), PacketMessage);
                    Othello.Server.SendPacket(user.Socket, packet.getData());
                }
            }
            else
            {
                BasicPacket bp = new BasicPacket(GameProtocol.FailedLoginPacketID());
                Othello.Server.SendPacket(clientSocket, bp.getData());
            }
        }