Exemplo n.º 1
0
        /// <summary>
        /// Client attempts to login.
        /// </summary>
        /// <param name="packet"></param>
        void OnLogin(PacketReader packet)
        {
            string accountName = packet.ReadUTF16Safe();
            string password    = packet.ReadUTF8();

            Console.WriteLine(password);

            // Check if this account is already logged in.
            if (Server.Database.IsAccountOnline(accountName))
            {
                Send(PacketGenerator.Login(5, ""));     // Tell client account is already connected to lobby.

                return;
            }

            // Load the account.
            Account = Server.Database.GetAccount(accountName);
            if (Account == null)
            {
                Send(PacketGenerator.Login(1, ""));     // Tell client there is no account with the given name.

                return;
            }
            Server.Database.AssignAccountToSession(Key, Account.Name);

            // Get the keybindings associated with this account.
            string keybindings = Server.Database.GetKeybindings(accountName);

            // Send all the required data to the client to complete the login.
            Send(PacketGenerator.Login(0, accountName));
            if (keybindings != null)
            {
                Send(PacketGenerator.Keybindings(keybindings));
            }
            Send(PacketGenerator.CharacterLicenses(Account.MaxCharacters, Account.CharacterLicenses));
            Send(PacketGenerator.CharacterList(Account.Characters));
            Send(PacketGenerator.SecondaryPassword(Account.SecondaryPassword != null, 0, false));
        }