예제 #1
0
        public override void Encode(OutPacket packet)
        {
            base.Encode(packet);

            packet.Encode <short>(0);
            packet.Encode <short>(0);
        }
예제 #2
0
        public static void Encode(this ItemSlotPet i, OutPacket p)
        {
            p.Encode <byte>(3);

            (i as ItemSlot).Encode(p);

            p.EncodeFixedString(i.PetName, 13);
            p.Encode <byte>(i.Level);
            p.Encode <short>(i.Tameness);
            p.Encode <byte>(i.Repleteness);

            if (i.DateDead == null)
            {
                p.Encode <long>(0);
            }
            else
            {
                p.Encode <DateTime>(i.DateDead.Value);
            }

            p.Encode <short>(i.PetAttribute);
            p.Encode <short>(i.PetSkill);
            p.Encode <int>(i.RemainLife);
            p.Encode <short>(i.Attribute);
        }
        private void OnDeleteCharacter(InPacket packet)
        {
            var spw         = packet.Decode <string>();
            var characterID = packet.Decode <int>();

            byte result = 0x0;

            if (!BCrypt.Net.BCrypt.Verify(spw, Account.SPW))
            {
                result = 0x14;
            }

            if (result == 0x0)
            {
                using (var db = _container.GetInstance <DataContext>())
                {
                    var data      = Account.Data.Single(a => a.WorldID == _selectedWorld.ID);
                    var character = data.Characters.Single(c => c.ID == characterID);

                    data.Characters.Remove(character);
                    db.Characters.Remove(character);
                    db.Update(Account);
                    db.SaveChanges();
                }
            }

            using (var p = new OutPacket(LoginSendOperations.DeleteCharacterResult))
            {
                p.Encode <int>(characterID);
                p.Encode <byte>(result);
                SendPacket(p);
            }
        }
예제 #4
0
        public override void ChannelActive(IChannelHandlerContext context)
        {
            var random = new Random();
            var socket = _socketFactory.Build(
                context.Channel,
                (uint)random.Next(),
                (uint)random.Next()
                );

            using (var p = new OutPacket())
            {
                p.Encode <short>(AESCipher.Version);
                p.Encode <string>("1");
                p.Encode <int>((int)socket.SeqRecv);
                p.Encode <int>((int)socket.SeqSend);
                p.Encode <byte>(8);

                socket.SendPacket(p);
            }

            context.Channel.GetAttribute(Socket.SocketKey).Set(socket);
            _server.Sockets.Add(socket);

            Logger.Debug($"Accepted connection from {context.Channel.RemoteAddress}");
        }
        private void OnUserChat(InPacket packet)
        {
            packet.Decode <int>();

            var message     = packet.Decode <string>();
            var onlyBalloon = packet.Decode <bool>();

            if (message.StartsWith("!"))
            {
                try
                {
                    Socket.WvsGame.CommandRegistry.Process(
                        this,
                        message.Substring(1)
                        );
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Message("An error has occured while executing that command.");
                }

                return;
            }

            using (var p = new OutPacket(GameSendOperations.UserChat))
            {
                p.Encode <int>(ID);
                p.Encode <bool>(false);
                p.Encode <string>(message);
                p.Encode <bool>(onlyBalloon);
                Field.BroadcastPacket(p);
            }
        }
        private void OnUserSitRequest(InPacket packet)
        {
            var id = packet.Decode <short>();

            using (var p = new OutPacket(GameSendOperations.UserSitResult))
            {
                if (id < 0)
                {
                    PortableChairID = null;
                    p.Encode <byte>(0);
                }
                else
                {
                    p.Encode <byte>(1);
                    p.Encode <short>(id); // TODO: proper checks for this
                }

                SendPacket(p);
            }

            if (PortableChairID != null)
            {
                return;
            }

            using (var p = new OutPacket(GameSendOperations.UserSetActivePortableChair))
            {
                p.Encode <int>(ID);
                p.Encode <int>(0);
                Field.BroadcastPacket(this, p);
            }
        }
        private void OnUserGatherItemRequest(InPacket packet)
        {
            packet.Decode <int>();

            var inventoryType = (ItemInventoryType)packet.Decode <byte>();
            var inventoryCopy = Character.GetInventory(inventoryType).Items
                                .Where(i => i.Position > 0)
                                .OrderBy(i => i.Position)
                                .ToList();
            short pos = 1;

            ModifyInventory(i =>
            {
                inventoryCopy.ForEach(i.Remove);
                inventoryCopy.ForEach(item => item.Position = pos++);
                inventoryCopy.ForEach(i.Set);
            }, true);

            using (var p = new OutPacket(GameSendOperations.GatherItemResult))
            {
                p.Encode <bool>(false);
                p.Encode <byte>((byte)inventoryType);
                SendPacket(p);
            }
        }
        public override void Encode(OutPacket packet)
        {
            base.Encode(packet);

            packet.Encode <byte>((byte)_templates.Count);
            _templates.ForEach(s => packet.Encode <int>(s));
        }
예제 #9
0
        public override void Encode(OutPacket packet)
        {
            base.Encode(packet);

            packet.Encode <byte>((byte)_skills.Count);
            _skills.ForEach(s => packet.Encode <int>((int)s));
        }
예제 #10
0
 public virtual void Encode(OutPacket packet)
 {
     packet.Encode <byte>(SpeakerTypeID);
     packet.Encode <int>(SpeakerTemplateID);
     packet.Encode <byte>(MessageType);
     packet.Encode <byte>((byte)SpeakerParam);
 }
 public void Encode(OutPacket packet)
 {
     packet.Encode <string>(Name);
     packet.Encode <int>(UserNo);
     packet.Encode <byte>(WorldID);
     packet.Encode <byte>(ID);
     packet.Encode <bool>(AdultChannel);
 }
예제 #12
0
        public override void Encode(OutPacket packet)
        {
            base.Encode(packet);

            packet.Encode <string>(_text);
            packet.Encode <string>(_textDefault);
            packet.Encode <short>(_col);
            packet.Encode <short>(_line);
        }
예제 #13
0
        public override void Encode(OutPacket packet)
        {
            base.Encode(packet);

            packet.Encode <string>(_text);
            packet.Encode <int>(_def);
            packet.Encode <int>(_min);
            packet.Encode <int>(_max);
        }
예제 #14
0
 public override OutPacket GetChangeControllerPacket(bool setAsController)
 {
     using (var p = new OutPacket(GameSendOperations.NpcChangeController))
     {
         p.Encode <bool>(setAsController);
         p.Encode <int>(ID);
         return(p);
     }
 }
예제 #15
0
        public override void Encode(OutPacket packet)
        {
            base.Encode(packet);

            packet.Encode <string>(_text);
            packet.Encode <string>(_textDefault);
            packet.Encode <short>(_lenMin);
            packet.Encode <short>(_lenMax);
        }
예제 #16
0
 public override OutPacket GetLeaveFieldPacket()
 {
     using (var p = new OutPacket(GameSendOperations.MessageBoxLeaveField))
     {
         p.Encode <bool>(true);
         p.Encode <int>(ID);
         return(p);
     }
 }
예제 #17
0
 public override OutPacket GetLeaveFieldPacket()
 {
     using (var p = new OutPacket(GameSendOperations.MobLeaveField))
     {
         p.Encode <int>(ID);
         p.Encode <byte>(1);
         return(p);
     }
 }
        private void OnCheckUserLimit(InPacket packet)
        {
            using (var p = new OutPacket(LoginSendOperations.CheckUserLimitResult))
            {
                p.Encode <byte>(0); // bOverUserLimit
                p.Encode <byte>(0); // bPopulateLevel

                SendPacket(p);
            }
        }
예제 #19
0
        public override void Encode(OutPacket packet)
        {
            base.Encode(packet);

            if ((SpeakerParam & SpeakerParamType.NPCReplacedByNPC) != 0)
            {
                packet.Encode <int>(SpeakerTemplateID);
            }
            packet.Encode <string>(_text);
            packet.Encode <bool>(_prev);
            packet.Encode <bool>(_next);
        }
예제 #20
0
        public Task ModifySkill(Action <ModifySkillContext> action = null, bool exclRequest = false)
        {
            var context = new ModifySkillContext(Character);

            action?.Invoke(context);
            ValidateStat();
            using (var p = new OutPacket(GameSendOperations.ChangeSkillRecordResult))
            {
                p.Encode <bool>(exclRequest);
                context.Encode(p);
                p.Encode <bool>(true);
                return(SendPacket(p));
            }
        }
예제 #21
0
        private void OnMigrationRegisterResult(InPacket packet)
        {
            var sessionKey = packet.Decode <string>();
            var server     = _wvsCenter.InteropServer.Sockets.Single(s => s.SessionKey == sessionKey);

            using (var p = new OutPacket(InteropSendOperations.MigrationResult))
            {
                p.Encode <string>(packet.Decode <string>());

                var result = packet.Decode <bool>();

                p.Encode <bool>(result);

                if (!result)
                {
                    return;
                }

                p.Encode <int>(packet.Decode <int>());

                p.Encode <byte>(packet.Decode <byte>());
                p.Encode <byte>(packet.Decode <byte>());
                p.Encode <byte>(packet.Decode <byte>());
                p.Encode <byte>(packet.Decode <byte>());
                p.Encode <short>(packet.Decode <short>());

                server.SendPacket(p);
            }
        }
예제 #22
0
        public static void Encode(this ItemSlot i, OutPacket p)
        {
            p.Encode <int>(i.TemplateID);
            p.Encode <bool>(false);

            if (i.DateExpire == null)
            {
                p.Encode <long>(0);
            }
            else
            {
                p.Encode <DateTime>(i.DateExpire.Value);
            }
        }
예제 #23
0
        private void OnMigrateIn(InPacket packet)
        {
            var characterID = packet.Decode <int>();

            if (!WvsGame.PendingMigrations.Remove(characterID))
            {
                Channel.CloseAsync();
                return;
            }

            using (var db = _container.GetInstance <DataContext>())
            {
                var character = db.Characters
                                .Include(c => c.Data)
                                .ThenInclude(a => a.Account)
                                .Include(c => c.FunctionKeys)
                                .Include(c => c.Inventories)
                                .ThenInclude(c => c.Items)
                                .Include(c => c.SkillRecords)
                                .Single(c => c.ID == characterID);

                character.Data.Account.State = AccountState.LoggedIn;
                db.Update(character);
                db.SaveChanges();

                var field     = WvsGame.FieldFactory.Get(character.FieldID);
                var fieldUser = new FieldUser(this, character);

                Random    = new Rand32(0x0, 0x0, 0x0);
                FieldUser = fieldUser;
                field.Enter(fieldUser);

                using (var p = new OutPacket(GameSendOperations.FuncKeyMappedInit))
                {
                    var functionKeys = character.FunctionKeys;

                    p.Encode <bool>(false);
                    for (var i = 0; i < 90; i++)
                    {
                        var functionKey = functionKeys.SingleOrDefault(f => f.Key == i);

                        p.Encode <byte>(functionKey?.Type ?? 0);
                        p.Encode <int>(functionKey?.Action ?? 0);
                    }

                    SendPacket(p);
                }
            }
        }
        private void OnUserEmotion(InPacket packet)
        {
            var emotion      = packet.Decode <int>();
            var duration     = packet.Decode <int>();
            var byItemOption = packet.Decode <bool>();

            using (var p = new OutPacket(GameSendOperations.UserEmotion))
            {
                p.Encode <int>(ID);
                p.Encode <int>(emotion);
                p.Encode <int>(duration);
                p.Encode <bool>(byItemOption);
                Field.BroadcastPacket(this, p);
            }
        }
예제 #25
0
        public static void Encode(this ItemSlotBundle i, OutPacket p)
        {
            p.Encode <byte>(2);

            (i as ItemSlot).Encode(p);

            p.Encode <short>(i.Number);
            p.Encode <string>(i.Title);
            p.Encode <short>(i.Attribute);

            if (ItemInfo.IsRechargeableItem(i.TemplateID))
            {
                p.Encode <long>(0);
            }
        }
예제 #26
0
        public static void EncodeForRemote(OutPacket packet, ICollection <TemporaryStatEntry> stats)
        {
            EncodeMask(packet, stats);

            var dictionary = stats.ToDictionary(s => s.Type, s => s);

            dictionary.GetValueOrDefault(TemporaryStatType.Speed)?.EncodeRemote(packet, 1);
            dictionary.GetValueOrDefault(TemporaryStatType.ComboCounter)?.EncodeRemote(packet, 1);
            dictionary.GetValueOrDefault(TemporaryStatType.WeaponCharge)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Stun)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Darkness)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Seal)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Weakness)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Curse)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Poison)?.EncodeRemote(packet, 2);
            dictionary.GetValueOrDefault(TemporaryStatType.Poison)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.ShadowPartner)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Morph)?.EncodeRemote(packet, 2);
            dictionary.GetValueOrDefault(TemporaryStatType.Ghost)?.EncodeRemote(packet, 2);
            dictionary.GetValueOrDefault(TemporaryStatType.Attract)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.SpiritJavelin)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.BanMap)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Barrier)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.DojangShield)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.ReverseInput)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.RespectPImmune)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.RespectMImmune)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.DefenseAtt)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.DefenseState)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.RepeatEffect)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.StopPortion)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.StopMotion)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Fear)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.MagicShield)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Frozen)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.SuddenDeath)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.FinalCut)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.Cyclone)?.EncodeRemote(packet, 1);
            dictionary.GetValueOrDefault(TemporaryStatType.Mechanic)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.DarkAura)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.BlueAura)?.EncodeRemote(packet, 4);
            dictionary.GetValueOrDefault(TemporaryStatType.YellowAura)?.EncodeRemote(packet, 4);

            packet.Encode <byte>(0); // nDefenseAtt
            packet.Encode <byte>(0); // nDefenseState

            // TODO: TwoState
        }
        private void OnWorldInfoRequest(InPacket packet)
        {
            var latestConnectedWorld = 0;

            _wvsLogin.InteropClients.ForEach(c =>
            {
                var worldInformation = c.Socket.WorldInformation;

                latestConnectedWorld = worldInformation.ID;
                using (var p = new OutPacket(LoginSendOperations.WorldInformation))
                {
                    worldInformation.Encode(p);
                    p.Encode <short>(0); // nBalloonCount
                    SendPacket(p);
                }
            });

            using (var p = new OutPacket(LoginSendOperations.WorldInformation))
            {
                p.Encode <byte>(0xFF);
                SendPacket(p);
            }

            // TODO: Proper latest connected world
            using (var p = new OutPacket(LoginSendOperations.LatestConnectedWorld))
            {
                p.Encode <int>(latestConnectedWorld);
                SendPacket(p);
            }
        }
        private void OnUserAttack(AttackInfo info)
        {
            using (var p = new OutPacket(
                       info is MeleeAttackInfo ? GameSendOperations.UserMeleeAttack :
                       info is ShootAttackInfo ? GameSendOperations.UserShootAttack :
                       info is MagicAttackInfo ? GameSendOperations.UserMagicAttack :
                       info is BodyAttackInfo ? GameSendOperations.UserBodyAttack :
                       GameSendOperations.UserMeleeAttack
                       ))
            {
                p.Encode <int>(ID);
                info.Encode(p);

                Field.BroadcastPacket(this, p);
            }

            info.Entries.ForEach(e =>
            {
                var fieldObject = Field.GetObject(e.MobID);
                var totalDamage = e.Damage.Sum();

                if (fieldObject is FieldMob mob)
                {
                    mob.Damage(this, Math.Min(mob.HP, totalDamage));
                }
            });
        }
        private void OnEnableSPWRequest(InPacket packet, bool vac)
        {
            packet.Decode <bool>(); // ?
            var characterID = packet.Decode <int>();

            if (vac)
            {
                packet.Decode <int>(); // Unknown
            }
            packet.Decode <string>();  // sMacAddress
            packet.Decode <string>();  // sMacAddressWithHDDSerial
            var spw = packet.Decode <string>();

            if (!string.IsNullOrEmpty(Account.SPW))
            {
                return;
            }
            if (BCrypt.Net.BCrypt.Verify(spw, Account.Password))
            {
                using (var p = new OutPacket(LoginSendOperations.EnableSPWResult))
                {
                    p.Encode <bool>(false);
                    p.Encode <byte>(0x16);
                    SendPacket(p);
                }

                return;
            }

            using (var db = _container.GetInstance <DataContext>())
            {
                Account.SPW = BCrypt.Net.BCrypt.HashPassword(spw);
                db.Update(Account);
                db.SaveChanges();
            }

            var world = _wvsLogin.InteropClients.Single(c => c.Socket.WorldInformation.ID == _selectedWorld.ID);

            using (var p = new OutPacket(InteropRecvOperations.MigrationRequest))
            {
                p.Encode <byte>((byte)ServerType.Game);
                p.Encode <byte>(_selectedChannel.ID);
                p.Encode <string>(SessionKey);
                p.Encode <int>(characterID);
                world.Socket.SendPacket(p);
            }
        }
        public void EncodeRemote(OutPacket packet, int size)
        {
            switch (size)
            {
            case 1:
                packet.Encode <byte>((byte)Option);
                break;

            case 2:
                packet.Encode <short>(Option);
                break;

            case 4:
                packet.Encode <int>(Option);
                break;
            }
        }