예제 #1
0
        /*
         * CheckVersion Packet
         * -------------------------
         * Client2Server Structure:
         *
         * ushort   : magic code
         * ushort   : size
         * int      : padding
         * ushort   : opcode
         *
         * int      : version1         #client version
         * int      : version2         #debug
         * int      : version3         #reserved
         * int      : version4         #reserved
         * -------------------------
         * Server2Client Structure:
         *
         * ushort   : magic code
         * ushort   : size
         * ushort   : opcode
         *
         * int      : version1         #client version
         * int      : version2         #debug
         * int      : version3         #reserved
         * int      : version4         #reserved
         */
        #endregion

        public static void CheckVersion(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            int version = packet.ReadInt();

            var conf = client.Metadata["conf"] as Configuration;

            if (conf == null)
            {
                return;
            }

            int clientVersion = conf.ClientVersion;

            // i dont like this one, should be way better: client.GetIpAddress();
            string ip   = client.RemoteEndPoint.ToString().Split(':')[0];
            bool   kick = false;

            if (conf.Debug)
            {
                // skipping on debug mode

                builder.New(0x7A);
                {
                    builder += version;     // Client Version
                    builder += 0;           // Debug
                    builder += 0;           // Reserved
                    builder += 0;           // Reserved
                }

                events.VersionMismatch("login.CheckVersion", new VersionCheckEventArgs(version, ip, VersionCheckResult.Match));

                client.Send(builder, "CheckVersion");
                return;
            }

            var result = VersionCheckResult.None;

            if (version != clientVersion)
            {
                result = version > clientVersion ? VersionCheckResult.NewerClient : VersionCheckResult.OlderClient;
                kick   = true;
                Log.Notice(string.Format("Failed CheckVersion Ip: {0} Client: {1}; Server: {2}", ip, version, clientVersion));
            }
            else
            {
                result = VersionCheckResult.Match;
            }

            events.VersionMismatch("login.CheckVersion", new VersionCheckEventArgs(version, ip, result));

            builder.New(0x7A);
            {
                builder += clientVersion;   // Client Version
                builder += 0;               // Debug
                builder += 0;               // Reserved
                builder += 0;               // Reserved
            }

            client.Send(builder, "CheckVersion");

            if (kick)
            {
                // we have to be sure that client will be disconnected
                // if client didnt closed it's connection, server will close after 800ms
                var waitKick = new Timer(800);
                waitKick.Elapsed += (s, _e) =>
                {
                    client.Disconnect();
                    waitKick.Stop();
                };

                waitKick.Start();
                return;
            }

            int id = -2;

            var sleep = new Timer(500);

            sleep.Elapsed += (s, _e) =>
            {
                if (id == -2)
                {
                    var syncServer = client.Metadata["syncServer"] as SyncReceiver;
                    id = Authentication.GetUser(syncServer, (ulong)client.Metadata["magic"]);
                }

                if (id > 0)
                {
                    client.AccountID = id;
                    SendChannels.SendChannelList(client);

                    var timer = new Timer(5000);
                    timer.AutoReset = true;
                    timer.Elapsed  += (sender, e) => { SendChannels.SendChannelList(client); };

                    timer.Start();
                    client.Metadata["timer"] = timer;
                }

                sleep.Stop();
            };

            sleep.Start();
        }
예제 #2
0
        public static void QueryCashItem(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            builder.New(0x1A2);
            {
                Character character  = client.Metadata["fullchar"] as Character;
                var       cid        = character.id;
                var       server     = (int)client.Metadata["server"];
                var       syncServer = client.Metadata["syncServer"] as SyncReceiver;

                var CashItens = CharacterManagement.GetCashItem(syncServer, server, cid / 8);


                /*
                 * builder += (int)2;          //item qnt
                 *
                 * builder += (int)1;          //item cashid
                 * builder += (int)163865;         //item idx
                 * builder += (byte)0xF4;
                 * builder += (byte)0x00;
                 * builder += (byte)0x00;
                 * builder += (byte)0x00;
                 * //builder += (int)0x000000E4;          //item opt extreme
                 * builder += (int)536871167;  //item opt old
                 * builder += (int)0;
                 * builder += (byte)31;         //duration
                 *
                 * builder += (int)2;          //item cashid
                 * builder += (int)24;         //item idx
                 * builder += (int)4;          //item opt extreme
                 * builder += (int)536871167;  //item opt old
                 * builder += (int)0;
                 * builder += (byte)17;        //duration
                 */



                builder += CashItens.Length;

                foreach (var i in CashItens)
                {
                    builder += (int)i.ID;
                    builder += (int)i.itemid;
                    builder += i.itemopt;
                    builder += (int)i.itemopt2;
                    builder += (byte)i.duration;
                }

                /*
                 * builder += (int)2; //item qnt
                 *
                 * builder += (int)1; //item cashid
                 * builder += (int)25; //item idx
                 * builder += (int)536880405; //item opt
                 * builder += (byte)0; //duration
                 *
                 * builder += (int)2; //item cashid
                 * builder += (int)25; //item idx
                 * builder += (int)0; //item opt
                 * builder += (byte)0; //duration*/
            }

            client.Send(builder, "QueryCashItem");
        }
예제 #3
0
        public static void SkillToUser(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            var clients = (client.Metadata["map"] as IMap).GetSurroundingClients(client, 2);

            Character character = client.Metadata["fullchar"] as Character;
            var       id        = character.id;

            var skill = packet.ReadShort();

            if (skill == 0x014C)
            {
                var unk2 = packet.ReadByte();
                var unk3 = packet.ReadShort();
                var unk4 = packet.ReadInt();

                builder.New(0xAF);
                {
                    builder += skill;
                    builder += (short)0x08;
                    builder += unk3;
                    builder += unk4;
                }

                client.Send(builder, "SkillToUser");

                builder.New(0xDD);
                {
                    builder += skill;
                    builder += id;
                    builder += 0x0D;
                    builder += (short)0x0200;
                    builder += unk3;
                    builder += unk4;
                }

                foreach (var c in clients)
                {
                    c.Send(builder, "NFY_SkillToUser");
                }
            }

            if (skill == 0x014B)
            {
                var unk2 = packet.ReadByte();
                var unk3 = packet.ReadShort();
                var unk4 = packet.ReadInt();

                builder.New(0xAF);
                {
                    builder += skill;
                    builder += 0x14;
                    builder += unk3;
                    builder += unk4;
                }

                client.Send(builder, "SkillToUser");

                builder.New(0xDD);
                {
                    builder += skill;
                    builder += id;
                    builder += (short)0x0C;
                    builder += (int)0x040;
                    builder += (byte)2;
                    builder += unk3;
                    builder += unk4;
                }

                foreach (var c in clients)
                {
                    c.Send(builder, "NFY_SkillToUser");
                }
            }

            if (skill == 0x014A)
            {
                var unk2 = packet.ReadByte();
                var unk3 = packet.ReadShort();
                var unk4 = packet.ReadInt();

                builder.New(0xAF);
                {
                    builder += skill;
                    builder += 0x13;
                    builder += unk3;
                    builder += unk4;
                }

                client.Send(builder, "SkillToUser");

                builder.New(0xDD);
                {
                    builder += skill;
                    builder += id;
                    builder += (short)0x0820;
                    builder += (int)0xC8;
                    builder += (byte)2;
                    builder += unk3;
                    builder += unk4;
                }

                foreach (var c in clients)
                {
                    c.Send(builder, "NFY_SkillToUser");
                }
            }

            if (skill == 0x00D1)
            {
                var unk2 = packet.ReadByte();
                var x    = packet.ReadShort();
                var y    = packet.ReadShort();

                builder.New(0xAF);
                {
                    builder += skill;
                    builder += 0;
                    builder += (short)0x039C;
                }

                client.Send(builder, "SkillToUser");

                builder.New(0xDD);
                {
                    builder += skill;
                    builder += id;
                    builder += 1;
                    builder += x;
                    builder += y;
                }

                foreach (var c in clients)
                {
                    c.Send(builder, "NFY_SkillToUser");
                }
            }

            if (skill == 0x00D0)
            {
                var unk2 = packet.ReadByte();
                var x    = packet.ReadShort();
                var y    = packet.ReadShort();

                builder.New(0xAF);
                {
                    builder += skill;
                    builder += 0;
                    builder += (short)0x0395;
                }

                client.Send(builder, "SkillToUser");

                builder.New(0xDD);
                {
                    builder += skill;
                    builder += id;
                    builder += 1;
                    builder += x;
                    builder += y;
                }

                foreach (var c in clients)
                {
                    c.Send(builder, "NFY_SkillToUser");
                }
            }
        }
예제 #4
0
        public static void GetCharacters(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            var server     = (int)client.Metadata["server"];
            var syncServer = client.Metadata["syncServer"] as SyncReceiver;
            var id         = Authentication.GetUser(syncServer, (ulong)client.Metadata["magic"]);

            if (id <= 0)
            {
                client.Disconnect();
                return;
            }

            client.AccountID = id;

            var characters = CharacterManagement.GetCharacters(syncServer, server, id);
            var subpass    = SubpassManagement.GetSubpass(syncServer, id);
            var slotorder  = CharacterManagement.GetSlotOrder(syncServer, server, id);

            if (slotorder == -1)
            {
                slotorder = 0x00123456;
            }

            client.Metadata["slotorder"] = slotorder;

            builder.New(0x85);
            {
                if (!subpass)
                {
                    builder += 0;   // not exist
                }
                else
                {
                    builder += 1;   // exists
                }
                builder += new byte[9];
                builder += (byte)1;
                builder += 0;       // selected char id
                builder += slotorder;
                builder += 0;

                for (int i = 0; i < characters.Length; i++)
                {
                    var charId = characters[i].id;
                    var style  = (uint)characters[i]._class;
                    style += (uint)(characters[i].face << 8);
                    style += (uint)(characters[i].colour << 13);
                    style += (uint)(characters[i].hair << 17);
                    style += (!characters[i].gender) ? 0 : (uint)(1 << 26);

                    TimeSpan date = (characters[i].created - new DateTime(1970, 1, 1, 0, 0, 0));

                    var    eq        = characters[i].equipment;
                    ushort head      = (eq.head != null) ? (ushort)(BitConverter.ToUInt16(eq.head, 0) + (eq.head[0x02] * 0x2000)) : (ushort)0;
                    ushort body      = (eq.body != null) ? (ushort)(BitConverter.ToUInt16(eq.body, 0) + (eq.body[0x02] * 0x2000)) : (ushort)0;
                    ushort hands     = (eq.hands != null) ? (ushort)(BitConverter.ToUInt16(eq.hands, 0) + (eq.hands[0x02] * 0x2000)) : (ushort)0;
                    ushort feet      = (eq.feet != null) ? (ushort)(BitConverter.ToUInt16(eq.feet, 0) + (eq.feet[0x02] * 0x2000)) : (ushort)0;
                    ushort righthand = (eq.righthand != null) ? (ushort)(BitConverter.ToUInt16(eq.righthand, 0) + (eq.righthand[0x02] * 0x2000)) : (ushort)0;
                    ushort lefthand  = (eq.lefthand != null) ? (ushort)(BitConverter.ToUInt16(eq.lefthand, 0) + (eq.lefthand[0x02] * 0x2000)) : (ushort)0;
                    ushort back      = (eq.back != null) ? (ushort)(BitConverter.ToUInt16(eq.back, 0) + (eq.back[0x02] * 0x2000)) : (ushort)0;

                    builder += charId;
                    builder += (long)date.TotalSeconds;     // created
                    builder += style;
                    builder += characters[i].level;
                    builder += 1;
                    builder += 0;
                    builder += 0;
                    builder += (byte)0;
                    builder += characters[i].map;
                    builder += (ushort)characters[i].x;
                    builder += (ushort)characters[i].y;

                    builder += (long)head;
                    builder += (long)body;
                    builder += (long)hands;
                    builder += (long)feet;
                    builder += (long)righthand;
                    builder += (long)lefthand;
                    builder += (long)back;

                    builder += new byte[364];

                    builder += (byte)(characters[i].name.Length + 1);
                    builder += characters[i].name;
                    builder += (short)0;
                    builder += 0;
                    builder += 0;
                }
            }

            client.Send(builder, "GetMyChartr");
        }
예제 #5
0
        public static void GetCharacters(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            //byte[] b;

            var proxy = client.Metadata["proxy"] as IChannelContracts;

            client.AccountID = proxy.GetUser((ulong)client.Metadata["magic"]);

            var database = client.Metadata["database"] as IDatabaseContracts;
            var server   = (int)client.Metadata["server"];

            // Get characters from dbo.characters
            var characters = database.GetCharacters(server, client.AccountID);

            builder.New(0x85);
            {
                builder += (byte)0;

                for (int i = 0; i < characters.Count; i++)
                {
                    // Now, let's get the character's inventory
                    //var eq = database.GetEquipment(server, (int)characters[i].Item1);
                    var eq = characters[i].Item2;

                    ushort head = (eq[0] != null) ?
                                  (ushort)(BitConverter.ToUInt16(eq[0], 0) + (eq[0][0x02] * 0x2000)) :
                                  (ushort)0;

                    ushort body = (eq[1] != null) ?
                                  (ushort)(BitConverter.ToUInt16(eq[1], 0) + (eq[1][0x02] * 0x2000)) :
                                  (ushort)0;

                    ushort hands = (eq[2] != null) ?
                                   (ushort)(BitConverter.ToUInt16(eq[2], 0) + (eq[2][0x02] * 0x2000)) :
                                   (ushort)0;

                    ushort feet = (eq[3] != null) ?
                                  (ushort)(BitConverter.ToUInt16(eq[3], 0) + (eq[3][0x02] * 0x2000)) :
                                  (ushort)0;

                    ushort righthand = (eq[4] != null) ?
                                       (ushort)(BitConverter.ToUInt16(eq[4], 0) + (eq[4][0x02] * 0x2000)) :
                                       (ushort)0;

                    ushort lefthand = (eq[5] != null) ?
                                      (ushort)(BitConverter.ToUInt16(eq[5], 0) + (eq[5][0x02] * 0x2000)) :
                                      (ushort)0;

                    ushort back = (eq[6] != null) ?
                                  (ushort)(BitConverter.ToUInt16(eq[6], 0) + (eq[6][0x02] * 0x2000)) :
                                  (ushort)0;

                    var character = characters[i].Item1;
                    var id        = client.AccountID * 8 + character.Item2;
                    var style     = (uint)character.Item5;
                    style += (uint)(character.Item6 << 8);
                    style += (uint)(character.Rest.Item1 << 13);
                    style += (uint)(character.Item7 << 17);
                    style += (!(bool)character.Rest.Item2) ? 0 : (uint)(1 << 26);

                    builder += id;
                    builder += (int)style;
                    builder += (int)character.Item4;                            // level
                    builder += (byte)0;
                    builder += (byte)1;
                    builder += (byte)1;
                    builder += (short)0;
                    builder += 0x004C4B40;                      // some kind of UNIX timestamp?
                    builder += 0;
                    builder += (byte)0;
                    builder += character.Rest.Item3;                            // map
                    builder += (short)character.Rest.Item4;                     // x
                    builder += (short)character.Rest.Item5;                     // y
                    builder += (short)head;
                    builder += (short)body;
                    builder += (short)hands;
                    builder += (short)feet;
                    builder += (short)righthand;
                    builder += (short)lefthand;
                    builder += (short)back;
                    builder += (short)0;
                    builder += 0;
                    builder += 0;
                    builder += 0;
                    builder += (byte)(character.Item3.Length + 1);
                    builder += character.Item3;
                }

                //b = builder.Data;
            }

            client.Send(builder, "GetMyChartr");
        }
예제 #6
0
        /*
         * CSC_ATTCKTOMOBS Packet
         * -------------------------
         * Client2Server Structure:
         *
         * ushort  : magic code
         * ushort  : size
         * int     : padding
         * ushort  : opcode
         *
         * ushort  : MobID
         * byte    : MapID
         * byte    : Unkn1             #so far its value as been 2
         * byte    : Unkn2             #so far its value as been 2 as well, so it could be just a short (512)
         * byte    : Unkn3             #so far its value as been 0
         * -------------------------
         * Server2Client Structure:
         *
         * ushort  : magic code
         * ushort  : size
         * ushort  : opcode
         *
         * ushort  : MobID
         * byte    : Unkn1
         * byte    : MapID
         * byte    : Unkn2
         * uint    : CurHp             #Current HP/Life character has.
         * uint    : CurMp             #Current MP/Mana character has.
         * byte[2] : Unkn4             #so far its value as been 00 00
         * byte    : AtkResult         #Enum AttackResult -> Critical = 1; Normal = 2; Block = 1B; Miss = 15;
         * byte    : HitCounter        #Counts number of attacks made to mob
         * byte    : Unkn5             #Usually value between 1 and 3
         * byte[6] : Unkn6             #00
         * uint    : Dmg               #Damage inflicted on mob, Miss = 0; Dmg = Attack - Mob Defense; if(dmg<=0 && !Miss) dmg = 1;
         * uint    : MobHp             #MobHp -= Dmg
         * ushort  : AP
         * uint    : AXP
         * byte    : TakeDmg           #Hp Cost/Hp Sacrifice; Boolean;
         * uint    : HpHover           #Hp where 0/20 sp is displayed if TakeDmg = 1.
         * uint    : DmgTaken          #Amount of dmg recieved/hp sacrificed if TakeDmg = 1.
         * -------------------------
         * Server sends Notify packet OpCode 0x00E1;
         */

        public static void NormalAttack(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            var map     = client.Metadata["map"] as IMap;
            var mapmobs = (client.Metadata["map"] as IMap).GetSurroundingMobs(client, 3);
            var mobdata = map.GetMobsData;

            var MobID = packet.ReadUShort();
            var unk1  = packet.ReadByte();
            var MapID = packet.ReadByte();
            var unk2  = packet.ReadUShort();

            Character character  = client.Metadata["fullchar"] as Character;
            var       cid        = character.id;
            var       server     = (int)client.Metadata["server"];
            var       syncServer = client.Metadata["syncServer"] as SyncReceiver;
            var       slot       = character.slot;

#if DEBUG
            Log.Message(string.Format("'{0}' '{1}' '{2}' '{3}'", MobID, unk1, MapID, unk2), ConsoleColor.Red, "PACKET RECV");
#endif

            var mi = mapmobs.Find(x => x.Id == MobID);

            var md = mobdata[mi.SId];


            //uint defense = Convert.ToUInt32(new Random().Next(1, 10));
            uint attack_rate = Convert.ToUInt32(new Random().Next(1, 10));
            //uint atk = character.stats.str_stat*2;   //Attempt dmg formula
            var atk = (int)client.Metadata["patk"];
            //uint dmg = atk - defense;

            var mobdef        = new Random().Next(md.Defense, md.DefRate);
            var normal_damage = atk - mobdef;
            var crit_damage   = normal_damage + (normal_damage * 20 / 100);
            var dmg           = 0;

            var atack_result = 0;

            if (attack_rate > 0)
            {
                if (attack_rate < 7)
                {
                    if (attack_rate <= 5)
                    {
                        atack_result        = 2;
                        dmg                 = normal_damage;
                        character.stats.exp = character.stats.exp + (ulong)dmg * 2;
                    }
                    if (attack_rate == 6)
                    {
                        atack_result        = 1;
                        dmg                 = crit_damage;
                        character.stats.exp = character.stats.exp + (ulong)dmg * 2;
                    }
                }
                if (attack_rate == 7)
                {
                    atack_result = 27;
                    dmg          = 0;
                }
                if (attack_rate >= 8)
                {
                    atack_result = 21;
                    dmg          = 0;
                }
            }

            if (dmg < md.Defense && dmg < 0)
            {
                dmg = new Random().Next(1, atk);
                character.stats.exp = character.stats.exp + 1;
            }
            if (dmg >= mi.CurrentHP)
            {
                dmg          = mi.CurrentHP;
                mi.CurrentHP = 0;
                //map.DropItem(mi.CurrentPosX, mi.CurrentPosX, 13, 1,1);
            }
            else
            {
                mi.CurrentHP = mi.CurrentHP - dmg;
            }

            ushort maxhp = character.stats.maxhp;
            ushort maxmp = character.stats.maxhp;

            ushort curhp = character.stats.curhp;
            ushort curmp = character.stats.curmp;

            builder.New(0x00B0);
            {
                builder += (short)MobID;
                builder += (byte)unk1;
                builder += (byte)MapID;
                builder += (byte)unk2;
                builder += (uint)curhp;
                builder += (uint)curmp;
                builder += new byte[2];               // Unknown4 ( so far always 00 00 )
                builder += (byte)atack_result;        // AttackResult;
                builder += (byte)0x1B;                // HitCounter
                builder += (byte)0x3;                 // Unknown5
                builder += new byte[6];               // Unknown6


                builder += (ulong)0;                    // OXP
                //builder += (uint)0;               // EXP
                builder += (uint)dmg;                   // DMG take on mob
                builder += (ushort)mi.CurrentHP;        // MobHp
                builder += (byte)0;                     // TakeDmg
                builder += (uint)0;                     // HpHover
                builder += (uint)0;                     // DmgTaken
                builder += (uint)curhp;
                builder += (uint)0;
            }



            if (curhp > 0)
            {
                character.stats.curhp = curhp;
                character.stats.curmp = curmp;
            }

            else
            {
                #region Death PacketInfo

                /*
                 * Death PacketInfo
                 * Server sends ErrorCode Msg (15 = Dead Menu where player can ressurect)
                 * Server sends Packet 0x042B
                 */
                #endregion

                character.stats.curhp = maxhp;
                character.stats.curmp = maxmp;

                var p = client.CreatePacket("ErrorCode", packet.Opcode, (ushort)0, (ushort)15, (ushort)map.ID);
                client.Send(p, "ErrorCode");

                builder.New(0x042B);
                {
                    builder += 0;
                    builder += 0;
                    builder += 0;
                }

                client.Send(builder, "unk2");
            }


#if DEBUG
            string notice = "";
            for (int i = 0; i < builder.Size; i++)
            {
                notice += builder.Data[i].ToString("X2") + " ";
            }

            Log.Notice(notice);
#endif

            client.Send(builder, "NormalAttack");

            if (mi.CurrentHP == 0)
            {
                mi.Spawn = Environment.TickCount + md.Respawn * 10;
            }
        }
예제 #7
0
        public static void WarpCommand(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            Character character = client.Metadata["fullchar"] as Character;
            var       npc       = packet.ReadUShort();
            var       unk1      = packet.ReadUShort();
            var       unk2      = packet.ReadByte();
            var       unk3      = packet.ReadByte();
            var       unk4      = packet.ReadByte();

            var y    = packet.ReadByte();
            var x    = packet.ReadByte();
            var unk5 = packet.ReadByte();
            var unk6 = packet.ReadByte();

            var warpID = packet.ReadUInt();

            var unk7  = packet.ReadByte();
            var unk8  = packet.ReadByte();
            var unk9  = packet.ReadByte();
            var unk10 = packet.ReadByte();
            var unk11 = packet.ReadByte();
            var unk12 = packet.ReadByte();
            var unk13 = packet.ReadByte();
            var unk14 = packet.ReadByte();

            var map   = (client.Metadata["map"] as IMap);
            var fee   = character.stats.alz;
            var alive = (warpID == 0 && npc != 54 && npc != 63);

            int[] dest = null;

            if (alive)
            {
                dest = map.GetWarpDestination(npc, 0);
            }
            else if (npc == 201)
            {
                warpID = (uint)map.ID;
            }
            else
            {
                dest = map.GetDeathDestination();
            }

            if (dest != null)
            {
                warpID = (byte)dest[0];
                x      = (byte)dest[1];
                y      = (byte)dest[2];
            }

            map.GetSurroundingClients(client, 1);
            map.RemoveClient(client);
            events.Warped("world.WarpCommand", client, (int)warpID, x, y);

            builder.New(0x00F4); // TODO: Load x,y values from WarpList
            {
                builder += (ushort)x;
                builder += (ushort)y;
                builder += (uint)character.stats.exp;
                builder += 0;                           //axp
                builder += fee;                         //Alz (for death penalty and fee?)
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (ulong)0;
                builder += warpID;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
                builder += (byte)1;
            }

            #region PacketAnalisys
#if DEBUG
            string notice = "";

            /*for (int i = 0; i< packet.Size-10; i++)
             * {
             *  notice += packet.ReadByte()+" ";
             * }
             */

            notice += npc + " " + unk1 + " " + unk2 + " " + unk3 + " " + unk4 + " " + x + " " + y + " " + unk5 + " " + unk6 + " " + warpID + " "
                      + unk7 + " " + unk8 + " " + unk9 + " " + unk10 + " " + unk11 + " " + unk12 + " " + unk13 + " " + unk14;
            Log.Notice(notice);
#endif
            #endregion

            client.Send(builder, "WarpCommand");

            character.map = (byte)warpID;
            character.x   = x;
            character.y   = y;

            CharacterManagement.UpdatePosition(client.Metadata["syncServer"] as SyncReceiver, (int)client.Metadata["server"], client.AccountID, character.slot, (byte)warpID, character.x, character.y);

            NewMobsList(packet, builder, client, events);
            //NewUserList(packet, builder, client, events);
        }
예제 #8
0
        public static void SkillToMobs(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            var map     = client.Metadata["map"] as IMap;
            var mapmobs = (client.Metadata["map"] as IMap).GetSurroundingMobs(client, 3);
            var mobdata = map.GetMobsData;



            var skillid = packet.ReadUShort();
            var unk     = packet.ReadInt();
            var unk1    = packet.ReadByte();
            var unk2    = packet.ReadUShort();
            var unk3    = packet.ReadShort();
            var unk4    = packet.ReadByte();
            var dmg     = packet.ReadUInt();
            var unk5    = packet.ReadByte();
            var unk6    = packet.ReadShort();
            var unk7    = packet.ReadShort();
            var unk8    = packet.ReadShort();
            var unk9    = packet.ReadShort();
            var mobid   = packet.ReadShort();
            var unk11   = packet.ReadByte();
            var unk12   = packet.ReadShort();
            var unk13   = packet.ReadShort();

#if DEBUG
            Log.Notice("SkillID:" + skillid + " SkillSlot:" + unk + " unk1:" + unk1 + " unk2:" + unk2 + " unk3:" + unk3 + " unk4:" + unk4 + " dmg:" + dmg + " unk5:" + unk5 + " unk6:" + unk6 + " unk7:" + unk7 + " unk8:" + unk8 + " unk9:" + unk9 + " MobID:" + mobid + " unk11:" + unk11 + " unk12:" + unk12 + " unk13:" + unk13 + "");
#endif

            //packet.Skip(6);
            var attack = packet.ReadUShort();

            Character character = client.Metadata["fullchar"] as Character;
            uint      hp        = character.stats.curhp;
            uint      mp        = character.stats.curmp;

            SkillLoader s         = new SkillLoader();
            var         skilllist = s.LoadSkillData(skillid);
            var         sid       = skilllist.Find(x => x.ID == skillid);

            var char_atk = (int)client.Metadata["patk"];

            if (sid.Type == 1)
            {
                char_atk = (int)client.Metadata["patk"];
            }
            if (sid.Type == 2)
            {
                char_atk = (int)client.Metadata["matk"];
            }

            var mi = mapmobs.Find(x => x.Id == mobid);
            var md = mobdata[mi.SId];

            uint attack_rate = Convert.ToUInt32(new Random().Next(1, 10));

            var normal_atk = char_atk + (sid.Attack + ((sid.Amp / 100) * sid.Attack));

            var mobdef = new Random().Next(md.Defense, md.DefRate);

            var normal_damage = normal_atk - mobdef;
            var crit_damage   = normal_damage + (normal_damage * sid.Critical);

            var damage = 0;

            var atack_result = 0;

            if (attack_rate <= 5)
            {
                atack_result        = 2;
                damage              = normal_damage;
                character.stats.exp = character.stats.exp + (ulong)damage * 2;
            }
            if (attack_rate == 6)
            {
                atack_result        = 1;
                damage              = crit_damage;
                character.stats.exp = character.stats.exp + (ulong)damage * 2;
            }
            if (attack_rate == 7)
            {
                atack_result = 27;
            }

            if (attack_rate >= 8)
            {
                atack_result = 21;
            }

            //Damage Maked
            if (damage < md.Defense && damage > 0)
            {
                damage = new Random().Next(1, 5);
            }

            if (damage >= mi.CurrentHP && damage > 0)
            {
                damage       = mi.CurrentHP;
                mi.CurrentHP = 0;
                //map.DropItem(mi.CurrentPosX, mi.CurrentPosX, 13, 1,1);
            }
            else
            {
                mi.CurrentHP = mi.CurrentHP - damage;
            }


            var exp      = character.stats.exp;
            var skillexp = character.stats.swordrank + sid.Attack;


            builder.New(0x00AE);
            {
                builder += (ushort)skillid;     //skillid
                builder += hp;                  //Hp
                builder += mp;                  //Mp
                builder += (ushort)0;           //SP
                builder += (ulong)exp;          //Exp
                builder += (ulong)0;            //OXP
                builder += (ulong)skillexp;     //SkillEXP

                builder += new byte[26];

                builder += (uint)0xFFFFFFFF;
                builder += (byte)0;
                builder += hp;
                builder += (uint)0;

                builder += (byte)1;

                builder += (byte)mobid;

                builder += (byte)0;

                builder += (byte)map.ID;
                builder += (byte)2;
                builder += (byte)2;

                builder += (byte)atack_result;

                builder += (int)damage;

                builder += (int)mi.CurrentHP;

                builder += new byte[12];
                builder += (byte)1;
            }

            client.Send(builder, "SkillToMobs");

            if (mi.CurrentHP == 0)
            {
                mi.Spawn = Environment.TickCount + md.Respawn * 10;

                mapmobs.Remove(mi);
            }
        }
예제 #9
0
 public static void Unknown194(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
 {
     builder.New(0x0194);
     client.Send(builder, "Unknown194");
 }
예제 #10
0
        public static void EnterWorld(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            if (packet.Size < 14)
            {
                return;
            }
            var id = packet.ReadInt();

            var server     = (int)client.Metadata["server"];
            var syncServer = client.Metadata["syncServer"] as SyncReceiver;

            ServerData[] servers     = GetChannels(syncServer);
            ChannelData  channelData = null;

            foreach (var svr in servers)
            {
                if (svr.id == server)
                {
                    foreach (var chn in svr.channels)
                    {
                        if (chn.id == (int)client.Metadata["channel"])
                        {
                            channelData = chn;
                        }
                    }
                }
            }

            if (channelData == null)
            {
                return;
            }

            var charslot = id % 8;
            var ip       = BitConverter.ToUInt32(Configuration.channelIp.GetAddressBytes(), 0);
            var chport   = Configuration.channelPort;

            if (client.AccountID <= 0)
            {
                client.AccountID = Authentication.GetUser(syncServer, (ulong)client.Metadata["magic"]);
            }


            Character character = CharacterManagement.GetFullCharacter(syncServer, server, client.AccountID, charslot);

            client.Metadata["fullchar"] = character;
            client.Metadata["id"]       = (int)id;

            client.Metadata["map"] = null;

            var equipment = character.equipment.GetEquipment();

            var level = character.level;
            var map   = character.map;
            var x     = (ushort)character.x;
            var y     = (ushort)character.y;

            var matk = (int)(character.stats.matk + (character.stats.int_stat * 1.2));
            var patk = (int)(character.stats.patk + (character.stats.str_stat * 1.2));
            var def  = (int)(character.stats.def + (character.stats.dex_stat * 1.2));

            client.Metadata["dest_x"] = x;
            client.Metadata["dest_y"] = y;

            client.Metadata["matk"] = matk;
            client.Metadata["patk"] = patk;
            client.Metadata["def"]  = def;



            var style = (int)character._class;

            style += (int)character.stats.rank << 3;
            style += (character.face << 8);
            style += (character.colour << 13);
            style += (character.hair << 17);
            style += (!character.gender) ? 0 : (1 << 26);


            client.Metadata["style"]     = style;
            client.Metadata["equipment"] = equipment;


            var ditems = new List <byte[]>();
            var citems = new List <byte[]>();

            foreach (var i in character.inv)
            {
                var di   = (DItem)(i.item.ToStructure <DItem>());
                var slot = i.slot;
                var ci   = (CItem)(di.ToClient(slot));
                var item = ci.ToByteArray();

                if (i.amount != 0)
                {
                    BitConverter.GetBytes(i.amount).CopyTo(item, 12);
                }

                ditems.Add(di.ToByteArray());
                citems.Add(item);
            }

            client.Metadata["inventory"] = ditems;

            builder.New(0x8E, true);
            {
                builder += new byte[58];
                builder += (byte)0x14;
                builder += (byte)server;
                builder += (short)channelData.id;
                builder += new byte[22];
                builder += (byte)255;
                builder += (short)channelData.maxPlayers;
                builder += ip;                                          // channel ip
                builder += (ushort)chport;                              // channel port
                builder += (long)1;
                builder += 0x01002607;
                builder += (int)map;                                    // map
                builder += 0;
                builder += x;                                           // x
                builder += y;                                           // y
                builder += character.stats.exp;                         // exp
                builder += character.stats.alz;                         // alz
                builder += character.stats.wexp;                        // wexp
                builder += level;                                       // level
                builder += 0;
                builder += character.stats.str_stat;                    // str
                builder += character.stats.dex_stat;                    // dex
                builder += character.stats.int_stat;                    // int
                builder += character.stats.pnt_stat;                    // points
                builder += character.stats.swordrank;                   // sword rank
                builder += (byte)0;                                     // magic rank **UNUSED**
                builder += new byte[6];
                builder += (uint)character.stats.maxhp;                 // max hp
                builder += (uint)character.stats.curhp;                 // curr hp
                builder += (uint)character.stats.maxmp;                 // max mp
                builder += (uint)character.stats.curmp;                 // curr mp
                builder += character.stats.maxsp;                       // max sp
                builder += character.stats.cursp;                       // curr sp
                builder += 8;                                           // max rage
                builder += (uint)0;                                     // DP
                builder += (ushort)0x2A30;
                builder += (ushort)0;
                builder += (uint)0;
                builder += (uint)character.stats.magicrank; //SkillExpBars
                builder += (uint)character.stats.swordxp;   //SkillExp
                builder += (uint)character.stats.swordpts;  //SkillPoints
                builder += (ushort)0;                       //Unk 0x33
                builder += (uint)0;                         //Honor Points
                builder += (uint)0;
                builder += (uint)0;
                builder += (uint)0;
                builder += (uint)0;
                builder += (uint)0;
                builder += (ushort)0;
                builder += (ushort)0;
                builder += (uint)0;
                builder += ip;                                          // unk server ip
                builder += (ushort)chport;                              // unk server port
                builder += ip;                                          // unk server ip Possible AuctionServer
                builder += (ushort)chport;                              // unk server port Possible AuctionServer
                builder += ip;                                          // unk server ip
                builder += (ushort)chport;                              // unk server port
                builder += (ushort)0xBBEE;
                builder += new byte[5];
                builder += 0x3FFFFF;                                    // warp codes?
                builder += 0x3FFFFF;                                    // map codes?
                builder += style;                                       // style
                builder += new byte[244];
                builder += (ushort)equipment.Count;                     // equip count
                builder += (ushort)citems.Count;                        // items count
                builder += (ushort)0;
                builder += (ushort)character.skills.Length;             // skills count
                builder += (ushort)character.qslots.Length;             // quickslots count
                builder += new byte[1304];
                builder += 1;
                builder += 0;
                builder += 0;
                builder += 0;
                builder += 0;
                builder += 0;
                builder += 1;
                builder += new byte[79];
                builder += 1;
                builder += new byte[131];
                builder += 0x03E8;                                      // help window..?
                builder += 0;
                builder += new byte[2065];



                /*
                 * builder += new byte[1975];
                 * builder += (int)1;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;                                      // 2 -> Unlimited Warp Active until 2000-00:00:00?
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;                                      // 1 or 0
                 * builder += (int)0;
                 * builder += (int)0;                                      // 0 or 1
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (int)0;
                 * builder += (byte)0;
                 * builder += (byte)0;
                 * builder += (int)0;                                      // My Merit Points (See UI for more accurate perception)
                 * builder += (int)0;                                      // Merit Point (See UI for more accurate perception)
                 * builder += (int)0;                                      // if 15 and the value bellow Force Gems is >2000 then Unlimited Warp Active until 2000-00:00:00?
                 * builder += (int)0;                                      // Force Gems
                 * builder += (int)0;                                      // Unknown Value Max (9999)?
                 */

                /*builder += new byte[2103];
                 * /*builder += (uint)0xFFFFFFFE;
                 * builder += new byte[2059];
                 * builder += (uint)0;                                     // Raise Spirit (millisecs)
                 * builder += new byte[16];
                 * builder += (int)0;                                      // My Merit Points (See UI for more accurate perception)
                 * builder += (int)0;                                      // Merit Point (See UI for more accurate perception)
                 * builder += (int)0;                                      // Unknown
                 * builder += (int)0;                                      // Force Gems
                 * builder += (int)0;                                      // Unknown*/

                builder += (byte)0;                                     // Raise Spirit (millisecs)
                builder += (byte)0;
                builder += (byte)0;
                builder += (int)0;
                builder += (int)0;
                builder += (int)0;
                builder += (int)0;

                builder += (int)0;

                /*
                 * builder += (byte)0;
                 * builder += (byte)0;
                 * builder += (byte)0;
                 * builder += (byte)0;                                     // Unknown MertisSlots*/


                builder += (int)0;                                  // Merit Points Max 50 (See UI for more accurate perception)
                builder += (int)0;                                  // My Merit Points (See UI for more accurate perception)

                builder += (ushort)0;                               // Unknown
                builder += (ushort)0;                               // Unknown

                builder += (int)0;                                  // Force Gems
                builder += (int)0;                                  //Unknown Value Max(9999) ?

                builder += (int)0;                                  // OverlordLevel
                builder += (ulong)0;                                // OverlordEXP

                builder += (byte)0;                                 // Unknown
                builder += (byte)(character.name.Length + 1);       // name length + 1
                builder += character.name;                          // name

                foreach (var e in equipment)
                {
                    builder += e.ToByteArray();
                }

                foreach (var i in citems)
                {
                    builder += i;
                }

                foreach (var s in character.skills)
                {
                    builder += (short)s.skill;                          // Skill ID
                    builder += s.level;                                 // Skill Level
                    builder += s.slot;                                  // Skill Slot
                    builder += (byte)0;
                }

                foreach (var q in character.qslots)
                {
                    builder += (short)q.skill;                          // Skill ID (referenced by Skill Slot)
                    builder += (short)q.slot;                           // Slot (in quickslot bars)
                }
            }

            client.Send(builder, "Initialized");
            events.Warped("world.Initialized", client, map, x, y);
            Authentication.UpdateOnline(syncServer, client.AccountID, true);

            //NewUserList(packet, builder, client, events);
            NewMobsList(packet, builder, client, events);
        }
예제 #11
0
        public static void MessageEvent(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            Character character = client.Metadata["fullchar"] as Character;
            var       name      = character.name;
            var       x         = (ushort)character.x;
            var       y         = (ushort)character.y;
            var       id        = character.id;
            var       map       = client.Metadata["map"] as IMap;
            var       clients   = map.GetSurroundingClients(client, 1);

            int unk = packet.ReadInt();

            packet.Skip(4);
            int size = packet.ReadShort() - 3;

            packet.Skip(2);
            var type = packet.ReadByte();
            var msg  = packet.ReadString(size);

            var smsg = msg.Split(' ');

            if (msg == "/quit")
            {
                CharacterManagement.UpdatePosition(client.Metadata["syncServer"] as SyncReceiver, (int)client.Metadata["server"], client.AccountID, character.slot, character.map, character.x, character.y);

                client.Disconnect();
                return;
            }

            #region DebugCommands
#if DEBUG
            if (smsg.Length > 1 && string.IsNullOrEmpty(smsg[0]) == false)
            {
                switch (smsg[0])
                {
                case "_drop":
                    int itemid = 0;

                    if (int.TryParse(smsg[1], out itemid))
                    {
                        map.DropItem(x, y, itemid, (uint)id, (uint)id);
                    }

                    break;

                case "_slm":
                    Unknown_86C(packet, builder, client, events);
                    break;

                case "_warp":
                    ushort mapid = 0;
                    ushort curx  = 0;
                    ushort cury  = 0;

                    if (!ushort.TryParse(smsg[1], out mapid))
                    {
                        return;
                    }

                    if (!ushort.TryParse(smsg[2], out curx))
                    {
                        return;
                    }

                    if (!ushort.TryParse(smsg[3], out cury))
                    {
                        return;
                    }

                    var p = client.CreatePacket("PC_WarpCommand", mapid, curx, cury, client);

                    events.Warped("world.Initialized", client, mapid, curx, cury);

                    client.Send(p, "PC_WarpCommand");

                    break;

                case "_levelup":
                    ushort level = 0;

                    var exp = character.stats.exp;

                    if (!ushort.TryParse(smsg[1], out level))
                    {
                        return;
                    }

                    character.stats.exp = 0;


                    /*
                     * builder.New(0x011F); // 3: Increase Hp, 4: Increase Mp, 5: SP, 8: Party Exp Bonus, 9:
                     * {
                     *  builder += (byte)9;
                     *  builder += (uint)0x5;
                     * }*/

                    //client.Send(builder, "LevelUp1");

                    builder.New(0x0120);
                    {
                        builder += (byte)level;
                        builder += character.id;
                    }

                    character.level += 1;

                    client.Send(builder, "LevelUp");

                    NFY_ChargeInfo(packet, builder, client, events);

                    Unknown9D6(packet, builder, client, events);

                    Unknown9E0(packet, builder, client, events);

                    builder.New(0x03F0);
                    {
                        builder += (byte)4;
                        builder += (uint)1428;
                        builder += (uint)1431;
                        builder += (uint)1430;
                        builder += (uint)1429;
                    }

                    client.Send(builder, "Unk3F0");

                    break;

                case "_spawn":
                    ushort mobid  = 0;
                    ushort specid = 0;

                    if (!ushort.TryParse(smsg[1], out mobid))
                    {
                        return;
                    }

                    if (!ushort.TryParse(smsg[2], out specid))
                    {
                        return;
                    }

                    var p1 = client.CreatePacket("MobSpawned", mobid, specid);

                    client.Send(p1, "MobSpawned");

                    break;

                case "/Partytime":
                    uint pid = 1337;

                    foreach (var c in clients)
                    {
                        builder.New(0xC9);
                        {
                            builder += (int)pid;
                            builder += (byte)12;

                            //b = builder.Data;
                        }

                        var timestamp = (uint)c.Metadata["timestamp"];
                        var style     = (uint)c.Metadata["style"];

                        c.Send(builder, "NFY_DelUserList");

                        builder.New(0xC8);
                        {
                            builder += (short)0x3101;
                            builder += (int)pid++;
                            builder += (short)0x000D;
                            builder += (short)0x0100;
                            builder += 1;
                            builder += Environment.TickCount - (int)timestamp;
                            builder += (short)(x + 1);
                            builder += (short)y;
                            builder += (short)(x + 1);
                            builder += (short)y;
                            builder += (byte)0;
                            builder += 0;
                            builder += (short)0;
                            builder += (int)style;
                            builder += (byte)1;
                            builder += (byte)0;
                            builder += 0;
                            builder += 0;
                            builder += (byte)0;

                            var equipment = (List <CItem>)c.Metadata["equipment"];

                            builder += (byte)(equipment.Count);
                            builder += (short)0;
                            builder += (byte)0;
                            builder += 0;

                            name = "PARTY TIME!!";

                            builder += (byte)(name.Length + 1);
                            builder += name;
                            builder += (byte)0;

                            foreach (var e in equipment)
                            {
                                builder += (short)e.ID;
                                builder += e.Slot;
                            }
                        }

                        c.Send(builder, "NFY_NewUserList");
                    }
                    return;
                }
            }
#endif
            #endregion

            builder.New(0xD9);
            {
                builder += id;
                builder += (byte)0;
                builder += (byte)unk;
                builder += (byte)0;
                builder += (byte)(msg.Length + 3);
                builder += (byte)0;
                builder += (byte)254;
                builder += (byte)254;
                builder += type;
                builder += msg;
                builder += new byte[3];
            }

            foreach (var c in clients)
            {
                c.Send(builder, "NFY_MessageEvnt");
            }

            events.SaidLocal("world.MessageEvnt", id, name, msg);
        }
예제 #12
0
        public static void MessageEvent(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            //byte[] b;

            var name = client.Metadata["name"] as string;
            var x    = (ushort)client.Metadata["x"];
            var y    = (ushort)client.Metadata["y"];
            var id   = (uint)client.Metadata["id"];
            var cid  = (uint)client.Metadata["cid"];
            var map  = client.Metadata["map"] as IMap;

            int size = packet.ReadByte() - 3;

            packet.Skip(2);
            var type = packet.ReadByte();
            var msg  = packet.ReadString(size);
            var smsg = msg.Split(' ');

            if (msg == "/quit")
            {
                client.Disconnect();
                return;
            }

            if (smsg.Length > 1 && smsg[0] == "/drop")
            {
                int itemid = 0;

                if (int.TryParse(smsg[1], out itemid))
                {
                    map.DropItem(x, y, itemid, cid, id);
                }

                return;
            }

            var clients = map.GetSurroundingClients(client, 1);

            if (smsg.Length > 1 && smsg[0] == "/spawn")
            {
                ushort mobid = 0;

                if (!ushort.TryParse(smsg[1], out mobid))
                {
                    return;
                }

                var p = client.CreatePacket("MobSpawned", mobid);

                client.Send(p, "MobSpawned");

                return;
            }

            if (msg == "/partytime")
            {
                uint pid = 1337;

                foreach (var c in clients)
                {
                    builder.New(0xC9);
                    {
                        builder += (int)pid;
                        builder += (byte)12;

                        //b = builder.Data;
                    }

                    var timestamp = (uint)c.Metadata["timestamp"];
                    var style     = (uint)c.Metadata["style"];

                    c.Send(builder, "UnknownPacket_0xC9");

                    builder.New(0xC8);
                    {
                        builder += (short)0x3101;
                        builder += (int)pid++;
                        builder += (short)0x000D;
                        builder += (short)0x0100;
                        builder += 1;
                        builder += Environment.TickCount - (int)timestamp;
                        builder += (short)(x + 1);
                        builder += (short)y;
                        builder += (short)(x + 1);
                        builder += (short)y;
                        builder += (byte)0;
                        builder += 0;
                        builder += (short)0;
                        builder += (int)style;
                        builder += (byte)1;
                        builder += (byte)0;
                        builder += 0;
                        builder += 0;
                        builder += (byte)0;

                        var equipment = (List <CItem>)c.Metadata["equipment"];

                        builder += (byte)(equipment.Count);
                        builder += (short)0;
                        builder += (byte)0;
                        builder += 0;

                        name = "PARTY TIME!!";

                        builder += (byte)(name.Length + 1);
                        builder += name;
                        builder += (byte)0;

                        foreach (var e in equipment)
                        {
                            builder += (short)e.ID;
                            builder += (byte)e.Slot;
                        }

                        //b = builder.Data;
                    }

                    c.Send(builder, "UnknownPacket_0xC8");
                }

                return;
            }

            foreach (var c in clients)
            {
                builder.New(0xD9);
                {
                    builder += (int)cid;
                    builder += (byte)(msg.Length + 3);
                    builder += (byte)0xFE;
                    builder += (byte)0xFE;
                    builder += type;
                    builder += msg;

                    //b = builder.Data;
                }

                c.Send(builder, "MessageEvnt");
            }

            events.SaidLocal("world.700.MessageEvnt", (int)cid, name, msg);
        }
예제 #13
0
        public static void ChangeMapCell(PacketReader packet, PacketBuilder builder, ClientHandler client, EventHandler events)
        {
            //byte[] b;

            packet.Skip(4);
            var x = packet.ReadShort();
            var y = packet.ReadShort();

            var map = client.Metadata["map"] as IMap;

            map.MoveClient(client, x / 16, y / 16);

            var clients = (client.Metadata["map"] as IMap).GetSurroundingClients(client, 2);

            if (clients.Count > 1)
            {
                builder.New(0xC8);
                {
                    builder += (short)(clients.Count - 1);

                    foreach (var c in clients)
                    {
                        if (c == client)
                        {
                            continue;
                        }
                        //if (!c.Metadata.ContainsKey("id") || (uint)c.Metadata["cid"] == 0) continue;

                        var id        = (uint)c.Metadata["cid"];
                        var level     = (uint)c.Metadata["level"];
                        var timestamp = (uint)c.Metadata["timestamp"];
                        var px        = (ushort)c.Metadata["x"];
                        var py        = (ushort)c.Metadata["y"];
                        var dx        = (ushort)c.Metadata["dest_x"];
                        var dy        = (ushort)c.Metadata["dest_y"];
                        var style     = (uint)c.Metadata["style"];

                        builder += (int)id;
                        builder += (short)0x000D;
                        builder += (short)0x0100;
                        builder += (int)level;
                        builder += Environment.TickCount - (int)timestamp;
                        builder += (short)px;
                        builder += (short)py;
                        builder += (short)dx;
                        builder += (short)dy;
                        builder += (byte)0;                             // PK penalty
                        builder += 0;
                        builder += (short)0;
                        builder += (int)style;
                        builder += (byte)0;                             // Animation ID
                        builder += 0;
                        builder += 0;
                        builder += (byte)0;
                        builder += (byte)0;                             // 1 = dead

                        var equipment = (List <CItem>)c.Metadata["equipment"];

                        builder += (byte)equipment.Count;
                        builder += (short)0;
                        builder += (byte)0;                             // 1 = has private shop open
                        builder += 0;

                        var name = c.Metadata["name"] as string;

                        builder += (byte)(name.Length + 1);
                        builder += name;
                        builder += (byte)0;

                        foreach (var e in equipment)
                        {
                            builder += (short)e.ID;
                            builder += (byte)e.Slot;
                        }
                    }

                    //b = builder.Data;
                }

                client.Send(builder, "UnknownPacket_0xC8");

                // nested wooooooo!
                {
                    var id        = (uint)client.Metadata["cid"];
                    var level     = (uint)client.Metadata["level"];
                    var timestamp = (uint)client.Metadata["timestamp"];
                    var px        = (ushort)client.Metadata["x"];
                    var py        = (ushort)client.Metadata["y"];
                    var dx        = (ushort)client.Metadata["dest_x"];
                    var dy        = (ushort)client.Metadata["dest_y"];
                    var style     = (uint)client.Metadata["style"];

                    builder.New(0xC8);
                    {
                        builder += (ushort)0x3101;
                        builder += (int)id;
                        builder += (short)0x000D;
                        builder += (short)0x0100;
                        builder += (int)level;
                        builder += Environment.TickCount - (int)timestamp;
                        builder += (short)px;
                        builder += (short)py;
                        builder += (short)dx;
                        builder += (short)dy;
                        builder += (byte)0;                             // PK penalty
                        builder += 0;
                        builder += (short)0;
                        builder += (int)style;
                        builder += (byte)0;                             // Animation ID
                        builder += 0;
                        builder += 0;
                        builder += (byte)0;
                        builder += (byte)0;                             // 1 = dead

                        var equipment = (List <CItem>)client.Metadata["equipment"];

                        builder += (byte)equipment.Count;
                        builder += (short)0;
                        builder += (byte)0;
                        builder += 0;

                        var name = client.Metadata["name"] as string;

                        builder += (byte)(name.Length + 1);
                        builder += name;
                        builder += (byte)0;

                        foreach (var e in equipment)
                        {
                            builder += e.ID;
                            builder += (byte)e.Slot;
                        }

                        //b = builder.Data;
                    }

                    foreach (var c in clients)
                    {
                        if (c == client)
                        {
                            continue;
                        }

                        //var b2 = b;

                        c.Send(builder, "UnknownPacket_0xC8");
                    }
                }
            }
        }