Пример #1
0
        public static SecretNetworkResponseType CheckCharacterAuthenticity(string sessionKey, string character, out string accountName, out uint accountId)
        {
            accountId   = 0;
            accountName = string.Empty;
            SecretNetworkResponseType response = SecretNetworkResponseType.Success;
            AccountModel account = LoginServerData.RetrieveAccountData(sessionKey);

            if (account == null)
            {
                response = SecretNetworkResponseType.SessionCouldNotBeFound;
            }
            else
            {
                accountId   = account.AccountId;
                accountName = account.AccountName;

                if (LoginServer.OnlineCharactersByAccount.ContainsKey(account.AccountName) && !LoginServer.OnlineCharactersByAccount[account.AccountName].Equals(character))
                {
                    response = SecretNetworkResponseType.AnotherCharacterOnline;
                }
                else
                {
                    bool isCharacterFound = false;
                    for (int i = 0; i < account.Characters.Count; i++)
                    {
                        if (account.Characters[i].CharacterName.Equals(character, StringComparison.InvariantCulture))
                        {
                            isCharacterFound = true;
                            LoginServerData.SetCharacterOnline(sessionKey, character);
                            break;
                        }
                    }

                    if (!isCharacterFound)
                    {
                        response = SecretNetworkResponseType.CharacterCouldNotBeFound;
                    }
                }
            }

            return(response);
        }
Пример #2
0
        private void HandleLoginPacket(string accountName, byte[] password)
        {
            //TODO: Check IP Ban

            if (string.IsNullOrEmpty(accountName))
            {
                Disconnect("Invalid account name.", Version);
                return;
            }

            byte[] hash           = LoginServer.PasswordHasher.ComputeHash(password);
            string hashedPassword = string.Empty;

            foreach (byte b in hash)
            {
                hashedPassword += b.ToString("x2");
            }

            string       sessionKey;
            AccountModel acc = LoginServerData.RetrieveAccountData(accountName, hashedPassword, out sessionKey);

            if (acc == null)
            {
                Disconnect("Account name or password is not correct.", Version);
                return;
            }

            OutputMessage message = OutputMessagePool.GetOutputMessage(this, false);

            message.AddByte((byte)ServerPacketType.MOTD);
            message.AddString(LoginServer.MOTD);

            message.AddByte((byte)ServerPacketType.SessionKey);
            message.AddString(sessionKey);

            message.AddByte((byte)ServerPacketType.CharacterList);
            message.AddByte((byte)LoginServer.GameWorlds.Count);
            foreach (GameWorldModel world in LoginServer.GameWorlds.Values)
            {
                message.AddByte(world.GameWorldId);
                message.AddString(world.GameWorldName);
                message.AddString(world.GameWorldIP);
                message.AddUInt16(world.GameWorldPort);
                message.AddByte(0);
            }

            message.AddByte((byte)acc.Characters.Count);
            foreach (AccountCharacterModel character in acc.Characters)
            {
                message.AddByte((byte)character.ServerId);
                message.AddString(character.CharacterName);
            }

            if (!acc.PremiumUntil.HasValue)
            {
                message.AddUInt16(0xFFFF);
            }
            else
            {
                TimeSpan premiumLeft = acc.PremiumUntil.Value - DateTime.Now;
                message.AddUInt16((ushort)premiumLeft.TotalDays);
            }

            message.DisconnectAfterMessage = true;
            OutputMessagePool.AddToQueue(message);
        }