private void ProcessSelectCharacter(ClientConnection client, SubPacket packet)
        {
            SelectCharacterPacket selectCharRequest = new SelectCharacterPacket(packet.data);

            Program.Log.Info("{0} => Select character id {1}", client.currentUserId == 0 ? client.GetAddress() : "User " + client.currentUserId, selectCharRequest.characterId);

            Character chara = Database.GetCharacter(client.currentUserId, selectCharRequest.characterId);
            World     world = null;

            if (chara != null)
            {
                world = Database.GetServer(chara.serverId);
            }

            if (world == null)
            {
                ErrorPacket errorPacket = new ErrorPacket(selectCharRequest.sequence, 0, 0, 13001, "World Does not exist or is inactive.");
                SubPacket   subpacket   = errorPacket.BuildPacket();
                BasePacket  basePacket  = BasePacket.CreatePacket(subpacket, true, false);
                BasePacket.EncryptPacket(client.blowfish, basePacket);
                client.QueuePacket(basePacket);
                return;
            }

            SelectCharacterConfirmPacket connectCharacter = new SelectCharacterConfirmPacket(selectCharRequest.sequence, selectCharRequest.characterId, client.currentSessionToken, world.address, world.port, selectCharRequest.ticket);

            BasePacket outgoingPacket = BasePacket.CreatePacket(connectCharacter.BuildPackets(), true, false);

            BasePacket.EncryptPacket(client.blowfish, outgoingPacket);
            client.QueuePacket(outgoingPacket);
        }
Beispiel #2
0
        public static void OnSelectCharacter(WorldClient client, IPacketStream packet)
        {
            var selectCharacterPacket = new SelectCharacterPacket(packet);

            using var database = DependencyContainer.Instance.Resolve <IDatabase>();
            var character = database.Charaters.Include(c => c.Items).Where(c => c.Id == selectCharacterPacket.CharacterId).FirstOrDefault();

            WorldPacketFactory.SendSelectedCharacter(client, character);
        }
    //캐릭터 선택 -> Server
    public void SelectCharacter(int index)
    {
        Debug.Log("캐릭터 선택");

        SelectCharacterData   selectCharacterData   = new SelectCharacterData((byte)index);
        SelectCharacterPacket selectCharacterPacket = new SelectCharacterPacket(selectCharacterData);

        selectCharacterPacket.SetPacketId((int)ClientPacketId.SelectCharacter);

        DataPacket packet = new DataPacket(CreatePacket(selectCharacterPacket), null);

        sendMsgs.Enqueue(packet);
    }
        /// <summary>
        /// Selects character and loads it into game world.
        /// </summary>
        private async void HandleSelectCharacter(SelectCharacterPacket selectCharacterPacket)
        {
            var character = await _gameWorld.LoadPlayer(selectCharacterPacket.CharacterId, _client);

            if (character != null)
            {
                _client.CharID = character.Id;

                using var packet = new Packet(PacketType.SELECT_CHARACTER);
                packet.WriteByte(0); // ok response
                packet.Write(character.Id);
                _client.SendPacket(packet);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Selects character and loads it into game world.
        /// </summary>
        private async void HandleSelectCharacter(SelectCharacterPacket selectCharacterPacket)
        {
            var gameWorld = DependencyContainer.Instance.Resolve <IGameWorld>();
            var character = await gameWorld.LoadPlayer(selectCharacterPacket.CharacterId, _client);

            if (character != null)
            {
                _client.CharID = character.Id;

                using var packet = new Packet(PacketType.SELECT_CHARACTER);
                packet.WriteByte(0); // ok response
                packet.Write(character.Id);
                _client.SendPacket(packet);
            }
        }
        public async Task Handle(WorldClient client, SelectCharacterPacket packet)
        {
            var character = await _characterFactory.CreateCharacter(client.UserId, packet.CharacterId);

            if (character is null)
            {
                _packetFactory.SendCharacterSelected(client, false, 0);
                return;
            }

            var ok = _gameWorld.TryLoadPlayer(character);

            if (!ok)
            {
                _packetFactory.SendCharacterSelected(client, false, 0);
                return;
            }

            _packetFactory.SendCharacterSelected(client, true, character.Id);

            _packetFactory.SendWorldDay(client); // TODO: why do we need it?
            _packetFactory.SendGuildList(client, await _guildManager.GetAllGuilds(_countryProvider.Country == CountryType.Light ? Fraction.Light : Fraction.Dark));

            var online    = new List <DbCharacter>();
            var notOnline = new List <DbCharacter>();

            foreach (var m in _guildManager.GuildMembers)
            {
                if (_gameWorld.Players.ContainsKey(m.Id))
                {
                    online.Add(m);
                }
                else
                {
                    notOnline.Add(m);
                }
            }
            _packetFactory.SendGuildMembersOnline(client, online, true);
            _packetFactory.SendGuildMembersOnline(client, notOnline, false);


            _packetFactory.SendDetails(client, character);

            _packetFactory.SendAdditionalStats(client, character);

            _packetFactory.SendCurrentHitpoints(client, character.HealthManager.CurrentHP, character.HealthManager.CurrentMP, character.HealthManager.CurrentSP);

            _packetFactory.SendInventoryItems(client, character.InventoryManager.InventoryItems.Values); // WARNING: some servers expanded invetory to 6 bags(os is 5 bags), if you send item in 6 bag, client will crash!
            foreach (var item in character.InventoryManager.InventoryItems.Values.Where(i => i.ExpirationTime != null))
            {
                _packetFactory.SendItemExpiration(client, item);
            }

            _packetFactory.SendLearnedSkills(client, character);

            _packetFactory.SendOpenQuests(client, character.QuestsManager.Quests.Where(q => !q.IsFinished));
            _packetFactory.SendFinishedQuests(client, character.QuestsManager.Quests.Where(q => q.IsFinished));

            _packetFactory.SendActiveBuffs(client, character.BuffsManager.ActiveBuffs);

            _packetFactory.SendFriends(client, character.FriendsManager.Friends.Values);

            _packetFactory.SendBlessAmount(client, character.CountryProvider.Country, character.CountryProvider.Country == CountryType.Light ? Bless.Instance.LightAmount : Bless.Instance.DarkAmount, Bless.Instance.RemainingTime);

            _packetFactory.SendBankItems(client, character.BankManager.BankItems.Values);

            _packetFactory.SendWarehouseItems(client, character.WarehouseManager.Items.Values);

            _packetFactory.SendTeleportSavedPositions(client, character.TeleportationManager.SavedPositions);

            if (character.GuildManager.HasGuild)
            {
                _packetFactory.SendGuildNpcs(client, await character.GuildManager.GetGuildNpcs());
            }

            _packetFactory.SendAutoStats(client, _statsManager.AutoStr, _statsManager.AutoDex, _statsManager.AutoRec, _statsManager.AutoInt, _statsManager.AutoWis, _statsManager.AutoLuc);

#if !EP8_V2
            _packetFactory.SendAccountPoints(client, character.AdditionalInfoManager.Points); // WARNING: This is necessary if you have an in-game item mall.
#endif

            _packetFactory.SendSkillBar(client, character.QuickItems); // Should be always the last! Changes packet encryption to xor!
            client.CryptoManager.UseExpandedKey = true;
        }