Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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);
        }