Пример #1
0
            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                packet.WriteUInt16(Icon);
                packet.WriteByte((byte)BarColor);
                return(packet);
            }
Пример #2
0
            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                packet.WriteUInt16(0);

                return(packet);
            }
Пример #3
0
        private void PacketHandler_0x4B_RequestNotification(Client client, ClientPacket packet)
        {
            var x60 = new ServerPacket(0x60);

            x60.WriteByte(0x01);
            x60.WriteUInt16((ushort)Game.Notification.Length);
            x60.Write(Game.Notification);
            client.Enqueue(x60);
        }
Пример #4
0
        public ServerPacket RenderToPacket(bool isClick = false)
        {
            var response = new ServerPacket(0x31);

            if (this is Mailbox)
            {
                response.WriteByte(0x04); // 0x02 - public, 0x04 - mail
                response.WriteByte(0x01); // ??? - needs to be odd number unless board in world has been clicked
                response.WriteUInt16(0);  // board ID;
                response.WriteString8("Mail");
                response.WriteByte(Math.Min((byte)this.Count(), (byte)Constants.MESSAGE_RETURN_SIZE));
                foreach (var message in this)
                {
                    response.WriteBoolean(!message.Read);
                    response.WriteInt16((short)message.Id);
                    response.WriteString8(message.Sender);
                    response.WriteByte((byte)message.Created.Month);
                    response.WriteByte((byte)message.Created.Day);
                    response.WriteString8(message.Subject);
                }
            }
            else if (this is Board)
            {
                // boardId 0 - get mail messages
                response.WriteByte(0x02); // 0x02 - public, 0x04 - mail
                response.WriteByte((byte)(isClick == true ? 0x02 : 0x01));
                // ??? - needs to be odd number unless board in world has been clicked
                response.WriteUInt16((ushort)Id);  // board ID;
                response.WriteString8(DisplayName);
                response.WriteByte(Math.Min((byte)this.Count(),
                                            (byte)Constants.MESSAGE_RETURN_SIZE));
                foreach (var message in this)
                {
                    response.WriteBoolean(message.Highlighted);
                    response.WriteInt16((short)message.Id);
                    response.WriteString8(message.Sender);
                    response.WriteByte((byte)message.Created.Month);
                    response.WriteByte((byte)message.Created.Day);
                    response.WriteString8(message.Subject);
                }
            }
            return(response);
        }
Пример #5
0
            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                packet.WriteUInt32(UserId);
                packet.WriteByte(Animation);
                packet.WriteUInt16(Speed);

                return(packet);
            }
Пример #6
0
            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                Console.WriteLine(String.Format("uid: {0}, Animation: {1}, speed {2}", UserId, Animation, Speed));
                packet.WriteUInt32(UserId);
                packet.WriteByte(Animation);
                packet.WriteUInt16(Speed);

                return(packet);
            }
Пример #7
0
            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                packet.WriteByte(Action);
                switch (Action)
                {
                case ExchangeActions.Initiate:
                {
                    packet.WriteUInt32(RequestorId);
                    packet.WriteString8(RequestorName);
                }
                break;

                case ExchangeActions.QuantityPrompt:
                {
                    packet.WriteByte(ItemSlot);
                }
                break;

                case ExchangeActions.ItemUpdate:
                {
                    packet.WriteByte((byte)(Side ? 0 : 1));
                    packet.WriteByte(ItemSlot);
                    packet.WriteUInt16((ushort)(0x8000 + ItemSprite));
                    packet.WriteByte(ItemColor);
                    packet.WriteString8(ItemName);
                }
                break;

                case ExchangeActions.GoldUpdate:
                {
                    packet.WriteByte((byte)(Side ? 0 : 1));
                    packet.WriteUInt32(Gold);
                }
                break;

                case ExchangeActions.Cancel:
                {
                    packet.WriteByte((byte)(Side ? 0 : 1));
                    packet.WriteString8(CancelMessage);
                }
                break;

                case ExchangeActions.Confirm:
                {
                    packet.WriteByte((byte)(Side ? 0 : 1));
                    packet.WriteString8(ConfirmMessage);
                }
                break;
                }
                return(packet);
            }
Пример #8
0
            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                packet.WriteUInt32(User.Id);
                packet.WriteByte(0x01);
                packet.WriteByte(213);
                packet.WriteByte((byte)User.Class);
                packet.WriteUInt16(0);

                return(packet);
            }
Пример #9
0
            internal ServerPacket Packet()
            {
                var packet = new ServerPacket(OpCode);

                packet.WriteByte(Slot);
                packet.WriteUInt16(Icon);
                packet.WriteByte(UseType);
                packet.WriteString8(Name);
                packet.WriteString8(Prompt);
                packet.WriteByte(Lines);

                return(packet);
            }
Пример #10
0
            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                packet.WriteByte(NationFlag);
                packet.WriteString8(GuildRank);
                packet.WriteByte(TitleCount);
                foreach (var id in TitleIds)
                {
                    packet.WriteByte(id);
                }
                packet.WriteByte(CurrentTitle);
                if (!IsGrouped)
                {
                    packet.WriteString8("No Group");
                }
                else
                {
                    var ret = "Group\n";
                    foreach (var member in Group.Members)
                    {
                        ret += $"{member.Name}\n";
                    }
                    packet.WriteString8(ret);
                }
                packet.WriteByte(CanGroup);
                packet.WriteByte(0x00);
                packet.WriteByte(Class);
                packet.WriteByte(0x01);
                packet.WriteByte(0x00);
                packet.WriteString8(Player.IsMaster ? "Master" : Player.Class.ToString());
                packet.WriteString8(GuildName != null ? GuildName : string.Empty);
                packet.WriteByte((byte)(Player.Legend.Count > 255 ? 255 : Player.Legend.Count));
                foreach (var mark in Player.Legend)
                {
                    packet.WriteByte((byte)mark.Icon);
                    packet.WriteByte((byte)mark.Color);
                    packet.WriteString8(mark.Prefix);
                    packet.WriteString8(mark.Text);
                }
                packet.WriteByte(0x00);
                packet.WriteUInt16(PlayerDisplay);
                packet.WriteByte(0x02);
                packet.WriteUInt32(0x00);
                packet.WriteByte(0x00);
                return(packet);
            }
Пример #11
0
        private void PacketHandler_0x57_ServerTable(Client client, ClientPacket packet)
        {
            var mismatch = packet.ReadByte();

            if (mismatch == 1)
            {
                var x56 = new ServerPacket(0x56);
                x56.WriteUInt16((ushort)Game.ServerTable.Length);
                x56.Write(Game.ServerTable);
                client.Enqueue(x56);
            }
            else
            {
                var server   = packet.ReadByte();
                var redirect = new Redirect(client, this, Game.Login, "socket", client.EncryptionSeed, client.EncryptionKey);
                client.Redirect(redirect);
            }
        }
Пример #12
0
            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                packet.WriteByte(NationFlag);
                packet.WriteString8(GuildRank);
                packet.WriteString8(CurrentTitle);
                if (!IsGrouped)
                {
                    packet.WriteString8("Adventuring Alone");
                }
                else
                {
                    var ret = "Group members\n";
                    foreach (var member in Group.Members)
                    {
                        ret += member == Group.Founder ? $"* {member.Name}\n" : $"  {member.Name}\n";
                    }
                    ret += $"Total {Group.Members.Count}";

                    packet.WriteString8(ret);
                }
                packet.WriteBoolean(CanGroup);
                packet.WriteByte(0x00);
                packet.WriteByte(Class);
                packet.WriteByte(0x01);
                packet.WriteByte(0x00);
                packet.WriteString8(Player.IsMaster ? "Master" : Player.Class.ToString());
                packet.WriteString8(GuildName != null ? GuildName : string.Empty);
                packet.WriteByte((byte)(Player.Legend.Count > 255 ? 255 : Player.Legend.Count));
                foreach (var mark in Player.Legend)
                {
                    packet.WriteByte((byte)mark.Icon);
                    packet.WriteByte((byte)mark.Color);
                    packet.WriteString8(mark.Prefix);
                    packet.WriteString8(mark.ToString());
                }
                packet.WriteByte(0x00);
                packet.WriteUInt16(PlayerDisplay);
                packet.WriteByte(0x02);
                packet.WriteUInt32(0x00);
                packet.WriteByte(0x00);
                return(packet);
            }
Пример #13
0
        private void PacketHandler_0x57_ServerTable(Client client, ClientPacket packet)
        {
            var mismatch = packet.ReadByte();

            if (mismatch == 1)
            {
                var x56 = new ServerPacket(0x56);
                x56.WriteUInt16((ushort)Game.ServerTable.Length);
                x56.Write(Game.ServerTable);
                Logger.InfoFormat("ServerTable: Sent: {0}", BitConverter.ToString(x56.ToArray()));
                client.Enqueue(x56);
            }
            else
            {
                var server   = packet.ReadByte();
                var redirect = new Redirect(client, this, Game.Login, "socket", client.EncryptionSeed, client.EncryptionKey);
                client.Redirect(redirect);
            }
        }
Пример #14
0
            internal List <ServerPacket> Packets()
            {
                var ret  = new List <ServerPacket>();
                var tile = 0;

                for (var row = 0; row < Map.Y; row++)
                {
                    ServerPacket packet = new ServerPacket(OpCode);

                    packet.WriteUInt16((ushort)row);
                    for (int column = 0; column < Map.X * 6; column += 2)
                    {
                        packet.WriteByte(Map.RawData[tile + 1]);
                        packet.WriteByte(Map.RawData[tile]);
                        tile += 2;
                    }
                    ret.Add(packet);
                }
                return(ret);
            }
Пример #15
0
        public void Redirect(Redirect redirect, bool isLogoff = false, int transmitDelay = 0)
        {
            GameLog.InfoFormat("Processing redirect");
            GlobalConnectionManifest.RegisterRedirect(this, redirect);
            GameLog.InfoFormat("Redirect: cid {0}", this.ConnectionId);
            GameLog.Info($"Redirect EncryptionKey is {Encoding.ASCII.GetString(redirect.EncryptionKey)}");
            if (isLogoff)
            {
                GlobalConnectionManifest.DeregisterClient(this);
            }
            redirect.Destination.ExpectedConnections.TryAdd(redirect.Id, redirect);

            var endPoint = Socket.RemoteEndPoint as IPEndPoint;

            byte[] addressBytes;

            if (Game.RedirectTarget != null)
            {
                addressBytes = Game.RedirectTarget.GetAddressBytes();
            }
            else
            {
                addressBytes = IPAddress.IsLoopback(endPoint.Address) ? IPAddress.Loopback.GetAddressBytes() : Game.IpAddress.GetAddressBytes();
            }

            Array.Reverse(addressBytes);

            var x03 = new ServerPacket(0x03);

            x03.Write(addressBytes);
            x03.WriteUInt16((ushort)redirect.Destination.Port);
            x03.WriteByte((byte)(redirect.EncryptionKey.Length + Encoding.ASCII.GetBytes(redirect.Name).Length + 7));
            x03.WriteByte(redirect.EncryptionSeed);
            x03.WriteByte((byte)redirect.EncryptionKey.Length);
            x03.Write(redirect.EncryptionKey);
            x03.WriteString8(redirect.Name);
            x03.WriteUInt32(redirect.Id);
            x03.TransmitDelay = transmitDelay == 0 ? 250 : transmitDelay;
            Enqueue(x03);
        }
Пример #16
0
            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                packet.WriteByte(0x00);
                if (Id != 0)
                {
                    packet.WriteUInt32(Id);
                    packet.WriteUInt32(SenderId == 0 ? Id : SenderId);
                    packet.WriteUInt16(AnimationId);
                    packet.WriteUInt16(SenderAnimationId == 0 ? ushort.MinValue : SenderAnimationId);
                    packet.WriteUInt16(Speed);
                    packet.WriteByte(0x00);
                }
                else
                {
                    packet.WriteUInt32(uint.MinValue);
                    packet.WriteUInt16(AnimationId);
                    packet.WriteUInt16(Speed);
                    packet.WriteUInt16(X);
                    packet.WriteUInt16(Y);
                }
                return(packet);
            }
Пример #17
0
 private void PacketHandler_0x4B_RequestNotification(Client client, ClientPacket packet)
 {
     var x60 = new ServerPacket(0x60);
     x60.WriteByte(0x01);
     x60.WriteUInt16((ushort)Game.Notification.Length);
     x60.Write(Game.Notification);
     client.Enqueue(x60);
 }
Пример #18
0
        private void PacketHandler_0x0B_ClientExit(Object obj, ClientPacket packet)
        {
            var user = (User) obj;
            var endSignal = packet.ReadByte();

            if (endSignal == 1)
            {
                var x4C = new ServerPacket(0x4C);
                x4C.WriteByte(0x01);
                x4C.WriteUInt16(0x00);
                user.Enqueue(x4C);
            }
            else
            {
                long connectionId;

                user.Save();
                user.UpdateLogoffTime();
                user.Map.Remove(user);
                Remove(user);
                DeleteUser(user.Name);
                user.SendRedirectAndLogoff(this, Game.Login, user.Name);

                if (ActiveUsersByName.TryRemove(user.Name, out connectionId))
                {
                    ((IDictionary) ActiveUsers).Remove(connectionId);
                }
                Logger.InfoFormat("cid {0}: {1} leaving world", connectionId, user.Name);
            }
        }
Пример #19
0
        public void Redirect(Redirect redirect)
        {
            Logger.DebugFormat("Processing redirect");
            GlobalConnectionManifest.DeregisterClient(this);

            redirect.Destination.ExpectedConnections.TryAdd(redirect.Id, redirect);

            var endPoint = Socket.RemoteEndPoint as IPEndPoint;

            byte[] addressBytes = IPAddress.IsLoopback(endPoint.Address) ? IPAddress.Loopback.GetAddressBytes() : Game.IpAddress.GetAddressBytes();

            Array.Reverse(addressBytes);

            var x03 = new ServerPacket(0x03);
            x03.Write(addressBytes);
            x03.WriteUInt16((ushort)redirect.Destination.Port);
            x03.WriteByte((byte)(redirect.EncryptionKey.Length + Encoding.GetEncoding(949).GetBytes(redirect.Name).Length + 7));
            x03.WriteByte(redirect.EncryptionSeed);
            x03.WriteByte((byte)redirect.EncryptionKey.Length);
            x03.Write(redirect.EncryptionKey);
            x03.WriteString8(redirect.Name);
            x03.WriteUInt32(redirect.Id);
            Enqueue(x03);
        }
Пример #20
0
        private void PacketHandler_0x18_ShowPlayerList(Object obj, ClientPacket packet)
        {
            var me = (User) obj;

            var list = from user in Users.Values
                       orderby user.IsMaster descending, user.Level descending, user.BaseHp + user.BaseMp * 2 descending, user.Name ascending
                       select user;

            var listPacket = new ServerPacket(0x36);
            listPacket.WriteUInt16((ushort)list.Count());
            listPacket.WriteUInt16((ushort)list.Count());

            foreach (var user in list)
            {
                int levelDifference = Math.Abs((int)user.Level - me.Level);

                listPacket.WriteByte((byte)user.Class);
                
                if (!string.IsNullOrEmpty(me.Guild) && user.Guild == me.Guild) listPacket.WriteByte(84);
                else if (levelDifference <= 5) listPacket.WriteByte(151);
                else listPacket.WriteByte(255);

                listPacket.WriteByte((byte)user.GroupStatus);
                listPacket.WriteString8(user.Title);
                listPacket.WriteBoolean(user.IsMaster);
                listPacket.WriteString8(user.Name);
            }
            me.Enqueue(listPacket);
        }
Пример #21
0
 private void PacketHandler_0x3B_AccessMessages(Object obj, ClientPacket packet)
 {
     var user = (User) obj;
     var messagePacket = new ServerPacket(0x31);
     messagePacket.WriteByte(0x01);
     messagePacket.WriteUInt16(0x00);
     messagePacket.WriteByte(0x00);
     user.Enqueue(messagePacket);
 }
Пример #22
0
        private void PacketHandler_0x7B_RequestMetafile(Object obj, ClientPacket packet)
        {
            var user = (User) obj;
            var all = packet.ReadBoolean();

            if (all)
            {
                var x6F = new ServerPacket(0x6F);
                x6F.WriteBoolean(all);
                x6F.WriteUInt16((ushort) Metafiles.Count);
                foreach (var metafile in Metafiles.Values)
                {
                    x6F.WriteString8(metafile.Name);
                    x6F.WriteUInt32(metafile.Checksum);
                }
                user.Enqueue(x6F);
            }
            else
            {
                var name = packet.ReadString8();
                if (Metafiles.ContainsKey(name))
                {
                    var file = Metafiles[name];

                    var x6F = new ServerPacket(0x6F);
                    x6F.WriteBoolean(all);
                    x6F.WriteString8(file.Name);
                    x6F.WriteUInt32(file.Checksum);
                    x6F.WriteUInt16((ushort) file.Data.Length);
                    x6F.Write(file.Data);
                    user.Enqueue(x6F);
                }
            }
        }
Пример #23
0
        private void PacketHandler_0x05_RequestMap(Object obj, ClientPacket packet)
        {
            var user = (User) obj;
            int index = 0;

            for (ushort row = 0; row < user.Map.Y; ++row)
            {
                var x3C = new ServerPacket(0x3C);
                x3C.WriteUInt16(row);
                for (int col = 0; col < user.Map.X*6; col += 2)
                {
                    x3C.WriteByte(user.Map.RawData[index + 1]);
                    x3C.WriteByte(user.Map.RawData[index]);
                    index += 2;
                }
                user.Enqueue(x3C);
            }
        }
Пример #24
0
            internal ServerPacket Packet()
            {
                var packet = new ServerPacket(OpCode);

                packet.WriteByte((byte)MerchantDialogType);
                packet.WriteByte((byte)MerchantDialogObjectType);
                packet.WriteUInt32(ObjectId);
                packet.WriteByte(0);
                packet.WriteInt16((short)Tile1);
                packet.WriteByte(0);
                packet.WriteByte(1);
                packet.WriteInt16((short)Tile1);
                packet.WriteByte(0);
                packet.WriteByte(0);
                packet.WriteString8(Name);
                packet.WriteString16(Text);
                if (MerchantDialogType == MerchantDialogType.Options)
                {
                    packet.WriteByte(Options.OptionsCount);
                    foreach (var opt in Options.Options)
                    {
                        packet.WriteString8(opt.Text);
                        packet.WriteUInt16(opt.Id);
                    }
                }
                if (MerchantDialogType == MerchantDialogType.OptionsWithArgument)
                {
                    packet.WriteString8(OptionsWithArgument.Argument);
                    packet.WriteByte(OptionsWithArgument.OptionsCount);
                    foreach (var opt in OptionsWithArgument.Options)
                    {
                        packet.WriteString8(opt.Text);
                        packet.WriteUInt16(opt.Id);
                    }
                }
                if (MerchantDialogType == MerchantDialogType.Input)
                {
                    packet.WriteUInt16(Input.Id);
                }
                if (MerchantDialogType == MerchantDialogType.InputWithArgument)
                {
                    packet.WriteString8(InputWithArgument.Argument);
                    packet.WriteUInt16(InputWithArgument.Id);
                }
                if (MerchantDialogType == MerchantDialogType.MerchantShopItems)
                {
                    packet.WriteUInt16(ShopItems.Id);
                    packet.WriteUInt16(ShopItems.ItemsCount);
                    foreach (var item in ShopItems.Items)
                    {
                        packet.WriteUInt16(item.Tile);
                        packet.WriteByte(item.Color);
                        packet.WriteUInt32(item.Price);
                        packet.WriteString8(item.Name);
                        packet.WriteString8(item.Description);
                    }
                }
                if (MerchantDialogType == MerchantDialogType.MerchantSkills)
                {
                    packet.WriteUInt16(Skills.Id);
                    packet.WriteUInt16(Skills.SkillsCount);
                    foreach (var skill in Skills.Skills)
                    {
                        packet.WriteByte(skill.IconType);
                        packet.WriteUInt16(skill.Icon);
                        packet.WriteByte(skill.Color);
                        packet.WriteString8(skill.Name);
                    }
                }
                if (MerchantDialogType == MerchantDialogType.MerchantSpells)
                {
                    packet.WriteUInt16(Spells.Id);
                    packet.WriteUInt16(Spells.SpellsCount);
                    foreach (var spell in Spells.Spells)
                    {
                        packet.WriteByte(spell.IconType);
                        packet.WriteUInt16(spell.Icon);
                        packet.WriteByte(spell.Color);
                        packet.WriteString8(spell.Name);
                    }
                }
                if (MerchantDialogType == MerchantDialogType.UserSkillBook)
                {
                    packet.WriteUInt16(UserSkills.Id);
                }
                if (MerchantDialogType == MerchantDialogType.UserSpellBook)
                {
                    packet.WriteUInt16(UserSpells.Id);
                }
                if (MerchantDialogType == MerchantDialogType.UserInventoryItems)
                {
                    packet.WriteUInt16(UserInventoryItems.Id);
                    packet.WriteByte(UserInventoryItems.InventorySlotsCount);
                    foreach (var slot in UserInventoryItems.InventorySlots)
                    {
                        packet.WriteByte(slot);
                    }
                }

                return(packet);
            }
Пример #25
0
            // General notes about this god awful packet:

            /* Offsets:
             * 00-0F: no human body + pants
             * 10-1F: male human body + pants
             * 20-2F: female human body, no pants
             * 30-3F: male spirit + pants
             * 40-4F: female spirit, no pants
             * 50-5F: invisible male body + pants
             * 60-6F: invisible female body, no pants
             * 70-7F: male doll body + pants
             * 80-8F: male mounted body + pants
             * 90-9F: female mounted body, no pants
             * A0-FF: no human body + pants
             */

            internal ServerPacket Packet()
            {
                ServerPacket packet = new ServerPacket(OpCode);

                packet.WriteUInt16(X);
                packet.WriteUInt16(Y);
                packet.WriteByte((byte)Direction);
                packet.WriteUInt32(Id);
                packet.WriteUInt16(Helmet);
                GameLog.InfoFormat($"Gender is {Gender}");
                if (!DisplayAsMonster)
                {
                    packet.WriteByte((byte)(((byte)Gender * 16) + BodySpriteOffset));
                    packet.WriteUInt16(Armor);
                    packet.WriteByte(Boots);
                    packet.WriteUInt16(Armor);
                    packet.WriteByte(Shield);
                    packet.WriteUInt16(Weapon);
                    packet.WriteByte(HairColor);
                    packet.WriteByte(BootsColor);
                    packet.WriteByte(FirstAccColor);
                    packet.WriteUInt16(FirstAcc);
                    packet.WriteByte(SecondAccColor);
                    packet.WriteUInt16(SecondAcc);
                    packet.WriteByte(ThirdAccColor);
                    packet.WriteUInt16(ThirdAcc);
                    packet.WriteByte((byte)LanternSize);
                    packet.WriteByte((byte)RestPosition);
                    packet.WriteUInt16(Overcoat);
                    packet.WriteByte(OvercoatColor);
                    packet.WriteByte((byte)SkinColor);
                    packet.WriteBoolean(Invisible);
                    packet.WriteByte(FaceShape);
                }
                else
                {
                    packet.WriteUInt16(MonsterSprite);
                    packet.WriteByte(HairColor);
                    packet.WriteByte(BootsColor);
                    // Unknown
                    packet.WriteByte(0x00);
                    packet.WriteByte(0x00);
                    packet.WriteByte(0x00);
                    packet.WriteByte(0x00);
                    packet.WriteByte(0x00);
                    packet.WriteByte(0x00);
                }
                packet.WriteByte((byte)NameStyle);
                packet.WriteString8(Name ?? string.Empty);
                packet.WriteString8(GroupName ?? string.Empty);

                return(packet);
            }