public virtual void HandleLoginFromWeb(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte error = pPacket.ReadByte();
            if (error != 0)
            {
                pConnection.Logger_WriteLine("Got Status: {0}", error);
                if (error == 0x07)
                {
                    pConnection.Logger_WriteLine("Already logged in!");
                }
                return;
            }

            int userid = pPacket.ReadInt();
            pPacket.ReadByte(); // Gender or GenderSelect/PinSelect
            pPacket.ReadByte();
            pPacket.ReadShort(); // Admin info!
            pPacket.ReadInt(); // ReadBytes(4)
            pPacket.ReadByte(); // 0x95
            string username = pPacket.ReadString(); // Username

            pPacket.ReadByte(); // 0?


            pPacket.ReadByte(); // Quiet Ban
            pPacket.ReadLong(); // Quiet Ban Time
            pPacket.ReadString(); // Username. Again.
            DateTime creationtime = DateTime.FromFileTime(pPacket.ReadLong()); // creation datetime
            pPacket.ReadInt();
            pPacket.ReadBytes(8); // CC key
            pPacket.ReadString();

            ParseLogin(pConnection, userid, username, creationtime);
        }
        public void Decode(MaplePacket pPacket)
        {
            pPacket.ReadByte(); // ?


            Running = new Dictionary<ushort, string>();
            Done = new Dictionary<ushort, long>();

            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                Running.Add(pPacket.ReadUShort(), pPacket.ReadString());
            }

            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.ReadString();
                pPacket.ReadString();
            }

            pPacket.ReadByte(); // ?

            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                Done.Add(pPacket.ReadUShort(), pPacket.ReadLong());
            }
        }
        public override void HandleLogin(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte error = pPacket.ReadByte();
            if (error != 0)
            {
                pConnection.Logger_WriteLine("Got Status: {0}", error);
                if (error == 0x07)
                {
                    pConnection.Logger_WriteLine("Already logged in?");
                }
                return;
            }

            int userid = pPacket.ReadInt();
            pPacket.ReadByte(); // Gender or GenderSelect/PinSelect
            pPacket.ReadByte();
            pPacket.ReadByte(); // Admin? Has bitflag 5
            string username = pPacket.ReadString(); // Username
            pPacket.ReadByte();
            pPacket.ReadByte();
            DateTime creationtime = DateTime.FromFileTime(pPacket.ReadLong()); // Incorrect :/. Nowhere to be found

            if (pPacket.ReadBool() == false)
                pPacket.ReadString(); // Username, with astriks as protection: 'd**mondo2*'

            pPacket.ReadString(); // wat.
            if (pPacket.ReadBool())
                pPacket.ReadBytes(15); // Every job that can be chosen

            pPacket.ReadInt(); // YYYYMMDDHH, as in character info -.-?


            ParseLogin(pConnection, userid, username, creationtime);
        }
        public void Decode(ClientConnection pConnection, MaplePacket pPacket)
        {
            var v = pPacket.ReadByte(); // ?


            Running = new Dictionary<ushort, string>();
            Done = new Dictionary<ushort, long>();

            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                Running.Add(pPacket.ReadUShort(), pPacket.ReadString());
            }

            if (v == 0)
            {
                for (int i = pPacket.ReadShort(); i > 0; i--)
                {
                    pPacket.ReadShort(); // UNK lol
                }
            }

            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.ReadString(); // 1NX1702337
                pPacket.ReadString(); // '1' or '0 ' ?!
            }

            var hurr = pPacket.ReadByte(); // ?

            // ADDED IN v.128 !!!!
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                // New method of creating dates...
                var id = pPacket.ReadUShort();
                var date = pPacket.ReadUInt();

                long ft = DecodeTimeFromInt(pConnection, date);

                if (!Done.ContainsKey(id))
                    Done.Add(id, ft);
                else
                    pConnection.Logger_WriteLine("Duplicate Quest (Done): {0}", id);

            }

            if (hurr == 0)
            {
                for (int i = pPacket.ReadShort(); i > 0; i--)
                {
                    Done.Add(pPacket.ReadUShort(), pPacket.ReadLong());
                }
            }
        }
        public virtual void HandleLogin(ClientConnection pConnection, MaplePacket pPacket)
        {
            int error = pPacket.ReadInt();
            pPacket.ReadShort();
            if (error != 0)
            {
                pConnection.Logger_WriteLine("Got Status: {0}", error);
                if (error == 0x07)
                {
                    pConnection.Logger_WriteLine("Already logged in!");
                }
                return;
            }

            int userid = pPacket.ReadInt();
            byte gender = pPacket.ReadByte(); // Gender or GenderSelect/PinSelect
            pPacket.ReadByte();
            short admin = pPacket.ReadShort();
            pPacket.ReadInt(); // ReadBytes(4)
            pPacket.ReadByte(); // 0x95
            string username = pPacket.ReadString(); // Username

            pPacket.ReadByte(); // 0?


            byte qban = pPacket.ReadByte(); // Quiet Ban
            DateTime qban_time = DateTime.FromFileTime(pPacket.ReadLong()); // Quiet Ban Time
            DateTime creationtime = DateTime.FromFileTime(pPacket.ReadLong()); // Creation Time
            pPacket.ReadInt(); // 78?
            pPacket.Skip(2); // 1 1
            pPacket.ReadBytes(8); // CC key

            ParseLogin(pConnection, userid, username, creationtime);
        }
Beispiel #6
0
        public void Decode(MaplePacket pPacket)
        {
            this.ID = pPacket.ReadInt();
            this.Name = pPacket.ReadString();
            this.Ranks = new string[5];
            for (int i = 0; i < 5; i++)
                this.Ranks[i] = pPacket.ReadString();

            byte guilds = pPacket.ReadByte();
            this.GuildIDs = new int[guilds];
            for (int i = 0; i < guilds; i++)
                this.GuildIDs[i] = pPacket.ReadInt();

            this.Capacity = pPacket.ReadInt();
            this.Notice = pPacket.ReadString();
        }
Beispiel #7
0
            public Ring(Ring.Type pType, MaplePacket pPacket, string pOwnName = null)
            {
                RingType = pType;
                if (pType == Type.Marriage)
                {
                    int marriageID = pPacket.ReadInt();

                    int characterID = pPacket.ReadInt();
                    int partnerID = pPacket.ReadInt();
                    pPacket.ReadShort(); // Most likely 3, marriage type?
                    int characterItemID = pPacket.ReadInt();
                    int partnerItemID = pPacket.ReadInt();
                    string characterName = pPacket.ReadString(13);
                    string partnerName = pPacket.ReadString(13);

                    if (pOwnName != FriendName)
                    {
                        FriendID = partnerID;
                        FriendName = partnerName;
                        RingCashID1 = characterItemID;
                        RingCashID2 = partnerItemID;
                    }
                    else
                    {
                        FriendID = characterID;
                        FriendName = characterName;
                        RingCashID1 = partnerItemID;
                        RingCashID2 = characterItemID;
                    }
                }
                else
                {
                    FriendID = pPacket.ReadInt();
                    FriendName = pPacket.ReadString(13);
                    RingCashID1 = pPacket.ReadLong();
                    RingCashID2 = pPacket.ReadLong();

                    if (pType == Type.Friend)
                    {
                        int itemID = pPacket.ReadInt();
                    }

                }
            }
Beispiel #8
0
        public void Decode(MaplePacket pPacket)
        {
            this.ID = pPacket.ReadInt();
            this.Type = pPacket.ReadByte();

            pPacket.ReadShort(); // X
            pPacket.ReadShort(); // Y
            pPacket.ReadByte(); // Stance
            pPacket.ReadShort(); // Foothold

            this.Skin = (byte)pPacket.ReadShort();
            this.Hair = pPacket.ReadShort();
            this.Face = pPacket.ReadShort();
            this.Name = pPacket.ReadString();

            this.Equips = new int[7];
            for (int i = 0; i < 7; i++)
                this.Equips[i] = pPacket.ReadInt();
        }
        public static void HandleTokenCheck(ClientConnection pConnection, MaplePacket pPacket)
        {
            string token = pPacket.ReadString();
            bool okay = false;
            int accountid = -1;

            okay = Queries.CheckAccountToken(token, out accountid);

            if (!okay)
            {
                pConnection.Logger_ErrorLog("Kicked client; token was not valid.");
                pConnection.Disconnect();
                return;
            }
            else
            {
                pConnection.Logger_WriteLine("Accepted client. Logged in with account ID {0}", accountid);

                pConnection.AccountID = accountid;
            }
        }
        public override void Decode(MaplePacket pPacket)
        {
            base.Decode(pPacket);


            this.Slots = pPacket.ReadByte();
            this.Scrolls = pPacket.ReadByte();
            this.Str = pPacket.ReadShort();
            this.Dex = pPacket.ReadShort();
            this.Int = pPacket.ReadShort();
            this.Luk = pPacket.ReadShort();
            this.HP = pPacket.ReadShort();
            this.MP = pPacket.ReadShort();
            this.Watk = pPacket.ReadShort();
            this.Matk = pPacket.ReadShort();
            this.Wdef = pPacket.ReadShort();
            this.Mdef = pPacket.ReadShort();
            this.Acc = pPacket.ReadShort();
            this.Avo = pPacket.ReadShort();
            this.Hands = pPacket.ReadShort();
            this.Speed = pPacket.ReadShort();
            this.Jump = pPacket.ReadShort();

            this.Name = pPacket.ReadString();
            this.Flags = pPacket.ReadShort();

            pPacket.ReadByte(); // Increases Skill
            this.Level = pPacket.ReadByte();

            pPacket.ReadInt();
            pPacket.ReadInt(); // 
            this.ViciousHammer = pPacket.ReadInt();

            pPacket.ReadShort(); // PVP damage

            pPacket.ReadByte();
            pPacket.ReadByte();

            this.Potential1 = pPacket.ReadShort();
            this.Potential2 = pPacket.ReadShort();
            this.Potential3 = pPacket.ReadShort();
            this.Potential4 = pPacket.ReadShort();
            this.Potential5 = pPacket.ReadShort();

            pPacket.ReadShort(); // New?

            this.SocketState = pPacket.ReadShort();
            this.Socket1 = pPacket.ReadShort();
            this.Socket2 = pPacket.ReadShort();
            this.Socket3 = pPacket.ReadShort();

            pPacket.ReadLong();

            pPacket.ReadLong();

            pPacket.ReadInt();
        }
Beispiel #11
0
        public override void Decode(ClientConnection pConnection, MaplePacket pPacket)
        {
            base.Decode(pConnection, pPacket);

            Petname = pPacket.ReadString(13);
            Level = pPacket.ReadByte();
            Closeness = pPacket.ReadShort();
            Fullness = pPacket.ReadByte();

            this.Expires = pPacket.ReadLong();
            pPacket.Skip(2 + 2 + 4 + 2 + 1 + 4 + 4 + 2);
            // Last 2:
            // - int: -1
            // - short: 100
            // V.132: + 2
        }
Beispiel #12
0
        public override void Decode(ClientConnection pConnection, MaplePacket pPacket)
        {
            base.Decode(pConnection, pPacket);

            Amount = pPacket.ReadShort();
            CraftName = pPacket.ReadString();
            Flags = pPacket.ReadShort();

            int itemtype = ItemID / 10000;
            if (itemtype == 233 || itemtype == 207 || itemtype == 287 || itemtype == 288 || itemtype == 289) // Stars, Bullets & Familiars
                UniqueID = pPacket.ReadLong();
        }
Beispiel #13
0
        public override void Decode(ClientConnection pConnection, MaplePacket pPacket)
        {
            base.Decode(pConnection, pPacket);


            List<string> flagsList = new List<string>();
            {
                {
                    uint flag = pPacket.ReadUInt();

                    this.Slots = FlaggedValue(pConnection, this.ItemID, flag, 0x01, pPacket, this.Slots);
                    this.Scrolls = FlaggedValue(pConnection, this.ItemID, flag, 0x02, pPacket, this.Scrolls);
                    this.Str = FlaggedValue(pConnection, this.ItemID, flag, 0x04, pPacket, this.Str);
                    this.Dex = FlaggedValue(pConnection, this.ItemID, flag, 0x08, pPacket, this.Dex);
                    this.Int = FlaggedValue(pConnection, this.ItemID, flag, 0x10, pPacket, this.Int);
                    this.Luk = FlaggedValue(pConnection, this.ItemID, flag, 0x20, pPacket, this.Luk);
                    this.HP = FlaggedValue(pConnection, this.ItemID, flag, 0x40, pPacket, this.HP);
                    this.MP = FlaggedValue(pConnection, this.ItemID, flag, 0x80, pPacket, this.MP);
                    this.Watk = FlaggedValue(pConnection, this.ItemID, flag, 0x100, pPacket, this.Watk);
                    this.Matk = FlaggedValue(pConnection, this.ItemID, flag, 0x200, pPacket, this.Matk);
                    this.Wdef = FlaggedValue(pConnection, this.ItemID, flag, 0x400, pPacket, this.Wdef);
                    this.Mdef = FlaggedValue(pConnection, this.ItemID, flag, 0x800, pPacket, this.Mdef);
                    this.Acc = FlaggedValue(pConnection, this.ItemID, flag, 0x1000, pPacket, this.Acc);
                    this.Avo = FlaggedValue(pConnection, this.ItemID, flag, 0x2000, pPacket, this.Avo);
                    this.Hands = FlaggedValue(pConnection, this.ItemID, flag, 0x4000, pPacket, this.Hands);
                    this.Speed = FlaggedValue(pConnection, this.ItemID, flag, 0x8000, pPacket, this.Speed);
                    this.Jump = FlaggedValue(pConnection, this.ItemID, flag, 0x10000, pPacket, this.Jump);
                    this.Flags = FlaggedValue(pConnection, this.ItemID, flag, 0x20000, pPacket, this.Flags);

                    this.IncreasesSkills = FlaggedValue(pConnection, this.ItemID, flag, 0x40000, pPacket, this.IncreasesSkills);

                    this.ItemLevel = FlaggedValue(pConnection, this.ItemID, flag, 0x80000, pPacket, this.ItemLevel);
                    this.ItemEXP = FlaggedValue(pConnection, this.ItemID, flag, 0x100000, pPacket, this.ItemEXP);


                    this.Durability = FlaggedValue(pConnection, this.ItemID, flag, 0x200000, pPacket, this.Durability);
                    this.ViciousHammer = FlaggedValue(pConnection, this.ItemID, flag, 0x400000, pPacket, this.ViciousHammer);

                    this.BattleModeDamage = FlaggedValue(pConnection, this.ItemID, flag, 0x800000, pPacket, this.BattleModeDamage);

                    FlaggedValue(pConnection, this.ItemID, flag, 0x1000000, pPacket, (byte)0, true); // Item level changer?
                    FlaggedValue(pConnection, this.ItemID, flag, 0x2000000, pPacket, (short)0, true); // Enhancement buff?
                    FlaggedValue(pConnection, this.ItemID, flag, 0x4000000, pPacket, (int)0, true);
                    FlaggedValue(pConnection, this.ItemID, flag, 0x8000000, pPacket, (byte)0, true); // Required level changer?!
                    FlaggedValue(pConnection, this.ItemID, flag, 0x10000000, pPacket, (byte)0, true); // Yggdrasil Wisdom?
                    FlaggedValue(pConnection, this.ItemID, flag, 0x20000000, pPacket, (byte)0, true); // Final Strike?
                    FlaggedValue(pConnection, this.ItemID, flag, 0x40000000, pPacket, (byte)0, true); // Boss Damage %?
                    FlaggedValue(pConnection, this.ItemID, flag, 0x80000000, pPacket, (byte)0, true); // Ignore Damage %?
                }

                {
                    uint flag = pPacket.ReadUInt();
                    FlaggedValue(pConnection, this.ItemID, flag, 0x01, pPacket, (byte)0, true); // Total damage?
                    FlaggedValue(pConnection, this.ItemID, flag, 0x02, pPacket, (byte)0, true); // All stats?
                    this.MaxScissors = FlaggedValue(pConnection, this.ItemID, flag, 0x04, pPacket, this.MaxScissors);
                    FlaggedValue(pConnection, this.ItemID, flag, 0x08, pPacket, (long)0, true);
                    FlaggedValue(pConnection, this.ItemID, flag, 0x10, pPacket, (int)0, true);
                }
            }

            this.Name = pPacket.ReadString();

            this.StatusFlags = pPacket.ReadUShort(); // Actually 2 bytes

            this.Potential1 = pPacket.ReadUShort();
            this.Potential2 = pPacket.ReadUShort();
            this.Potential3 = pPacket.ReadUShort();

            this.Potential4 = pPacket.ReadUShort();
            this.Potential5 = pPacket.ReadUShort();
            this.Potential6 = pPacket.ReadUShort();

            this.DisplayID = pPacket.ReadUShort();

#if LOCALE_GMS
            this.SocketState = pPacket.ReadUShort();
            this.Nebulite1 = pPacket.ReadShort();
            this.Nebulite2 = pPacket.ReadShort();
            this.Nebulite3 = pPacket.ReadShort();
#else
            pPacket.ReadShort();
#endif

            if (CashID == 0)
                this.UniqueID = pPacket.ReadLong();
            else
                this.UniqueID = 0;

            pPacket.ReadLong(); // Some weird expiration time


            pPacket.ReadInt(); // always -1?

#if (LOCALE_EMS || LOCALE_GMS)
            // Prolly RED patch related
            pPacket.ReadLong();
            pPacket.ReadLong(); // This is 94354848000000000; a default date for no expiration. 
            pPacket.ReadInt();
            for (int i = 0; i < 3; i++)
                pPacket.ReadInt();

#endif

            // Fix setflags
            if ((this.Flags & 0x80) == 0x80 && this.Name != "")
            {
                flagsList.Add("crafted");
            }

            this.SetFlags = string.Join(",", flagsList);
        }
        public virtual void HandleSpawnPlayer(ClientConnection pConnection, MaplePacket pPacket)
        {
            int id = pPacket.ReadInt();
            byte level = pPacket.ReadByte();
#if LOCALE_EMS
            pPacket.ReadByte();
#endif
            string name = pPacket.ReadString();
            string successor = pPacket.ReadString();
            string guildname = pPacket.ReadString();
            // pConnection.Logger_WriteLine("I see {0}! ID {1} Level {2}{3}, guild {4}", name, id, level, successor.Length == 0 ? "" : " (" + name + "'s Successor)", guildname);

            Queries.SeePlayer(id, name, GameHelper.GetAllianceWorldID(pConnection.WorldID), level, guildname, pConnection.CharData.Stats.MapID, pConnection.CharacterInternalID);

            if (!pConnection._CharactersInMap.Contains(name))
                pConnection._CharactersInMap.Add(name);
        }
Beispiel #15
0
        public void Decode(ClientConnection pConnection, MaplePacket pPacket)
        {
            pPacket.Skip(8); // Flag

#if LOCALE_GMS
            pPacket.Skip(1);
#endif

            {
                // Added GMS V.132 
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
            }

#if LOCALE_EMS
            pPacket.Skip(1);
#endif

            int tmp = pPacket.ReadByte();
            pPacket.Skip(tmp * 4);

            tmp = pPacket.ReadInt();
            pPacket.Skip(tmp * (4 + 8));


#if LOCALE_GMS
            pPacket.Skip(1);
#endif

            if (pPacket.ReadBool())
            {
                tmp = pPacket.ReadInt();
                pPacket.Skip(tmp * 8);
                tmp = pPacket.ReadInt();
                pPacket.Skip(tmp * 8);
            }

            Stats = new GW_CharacterStat();
            Stats.Decode(pPacket);

            this.BuddylistSize = pPacket.ReadByte();
#if LOCALE_EMS
            pPacket.ReadByte();
#endif

            if (pPacket.ReadBool()) BlessingOfTheFairy = pPacket.ReadString();
            else BlessingOfTheFairy = null;
            if (pPacket.ReadBool()) BlessingOfEmpress = pPacket.ReadString();
            else BlessingOfEmpress = null;
            if (pPacket.ReadBool()) UltimateExplorer = pPacket.ReadString();
            else UltimateExplorer = null;

            Stats.DecodeMesos(pPacket); // .-.

#if LOCALE_EMS
            pPacket.ReadByte(); // Bool check
            pPacket.ReadInt();
#endif


            // Unknown stuff here

            for (int i = pPacket.ReadInt(); i > 0; i--)
            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadLong();
            }

#if LOCALE_GMS
            // Magical potion pots!!!
            for (int i = pPacket.ReadInt(); i > 0; i--) // V.126
            {
                pPacket.ReadInt(); // Potion pot ID
                pPacket.ReadInt(); // Max value
                pPacket.ReadInt(); // HP
                pPacket.ReadInt(); // ??? (Not max value of MP)
                pPacket.ReadInt(); // MP

                pPacket.ReadLong(); // Start date O.o?
                pPacket.ReadLong(); // End date O.o?
            }
#endif


#if LOCALE_GMS
            // V.142 - RED stuff?

            for (int i = pPacket.ReadInt(); i > 0; i--)
            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadByte();
                pPacket.ReadInt();
                pPacket.ReadInt();
            }

            {
                pPacket.ReadInt();
                for (int i = 3; i > 0; i--)
                {
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                }
            }


            for (int i = pPacket.ReadInt(); i > 0; i--)
                pPacket.ReadInt();

            if (pPacket.ReadBool())
            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadLong();
                pPacket.ReadLong();
                pPacket.ReadLong();
            }

            for (int j = 0; j < 2; j++) // called 2 times under each other!
            {
                for (int i = pPacket.ReadByte(); i > 0; i--)
                {
                    pPacket.ReadByte();
                    pPacket.ReadInt();
                    pPacket.ReadByte();
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                    pPacket.ReadString();
                }
            }
#endif

#if LOCALE_EMS
            // REMOVED GMS V.141?!
            for (int i = pPacket.ReadInt(); i > 0; i--) // V.137
            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt(); 
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
            }

            pPacket.ReadInt();
            for (int i = 6; i > 0; i--)
            {
                pPacket.ReadInt();
            }


            for (int i = pPacket.ReadInt(); i > 0; i--)
            {
                pPacket.ReadInt();
            }


            for (int i = pPacket.ReadInt(); i > 0; i--)
            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadString();
            }


            for (int i = pPacket.ReadInt(); i > 0; i--)
            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadString();
            }

#endif

            Inventory = new CharacterInventory();
            Inventory.Decode(pConnection, pPacket);

            //UnknownIntegerListNumber3 = new Dictionary<int, long>();
            for (int i = pPacket.ReadInt(); i > 0; i--)
            {
                pPacket.ReadInt();
                pPacket.ReadLong();
                //UnknownIntegerListNumber3.Add(pPacket.ReadInt(), pPacket.ReadLong());
            }

            //UnknownIntegerListNumber4 = new Dictionary<long, long>();
            for (int i = pPacket.ReadInt(); i > 0; i--)
            {
                pPacket.ReadLong();
                pPacket.ReadLong();
                //UnknownIntegerListNumber4.Add(pPacket.ReadLong(), pPacket.ReadLong());
            }


            while (true)
            {
                byte val = pPacket.ReadByte();
                if (val == 0) break;

                {
                    pPacket.ReadInt();
                    pPacket.ReadByte();
                    pPacket.ReadByte();
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                    pPacket.ReadByte();
                    pPacket.ReadInt();
                    pPacket.ReadLong();
                    pPacket.ReadLong();
                    pPacket.ReadLong();
                    pPacket.ReadLong();
                }
            }


            Skills = new CharacterSkills();
            Skills.Decode(pConnection, pPacket);

            Quests = new CharacterQuests();
            Quests.Decode(pConnection, pPacket);


            // Match
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
            }


            {

                Rings = new List<Ring>();
                MarriedWith = null;

                // Couple
                for (int i = pPacket.ReadShort(); i > 0; i--)
                {
                    Rings.Add(new Ring(Ring.Type.Couple, pPacket));
                }

                // Friend
                for (int i = pPacket.ReadShort(); i > 0; i--)
                {
                    Rings.Add(new Ring(Ring.Type.Friend, pPacket));
                }

                // Marriage
                for (int i = pPacket.ReadShort(); i > 0; i--)
                {
                    Ring ring = new Ring(Ring.Type.Marriage, pPacket, Stats.Name);
                    Rings.Add(ring);

                    MarriedWith = ring.FriendName;
                }
            }


            Inventory.DecodeTeleportRocks(pPacket);

#if LOCALE_GMS
            Monsterbook = new CharacterMonsterBook();
            Monsterbook.Decode(pPacket);

            pPacket.ReadInt(); // -1?

            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.ReadShort();
            }

            {
                // Newyear cards... meh
                // WHAT MEH, SOMEONE HAS THIS FFS D:!!!

                for (short i = pPacket.ReadShort(); i > 0; i--)
                {
                    pPacket.ReadInt(); // Card ID?
                    pPacket.ReadInt(); // Sender ID
                    pPacket.ReadString(); // Sender name
                    pPacket.ReadByte(); // GENDER..?
                    pPacket.ReadLong(); // Sent at?
                    pPacket.ReadInt(); // Receiver ID
                    pPacket.ReadString(); // Receiver name
                    pPacket.ReadByte();
                    pPacket.ReadByte();
                    pPacket.ReadLong(); // Receive date?
                    pPacket.ReadString(); // Message
                }
            }
#else
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.ReadShort();
                pPacket.ReadString();
            }
#endif

            Quests.DecodePQ(pConnection, pPacket);

            if (GameHelper.IsWildHunter(Stats.JobID))
            {
                pPacket.ReadByte(); // Level

                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt(); // Caught mob
            }

            Quests.DecodePQDone(pConnection, pPacket);

            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                short cnt = pPacket.ReadShort();
                int unk = pPacket.ReadInt(); // 9010040 | Conor (NPC)
                if (cnt > 0 && unk > 0)
                {
                    for (short j = 0; j < cnt; j++)
                    {
                        pPacket.ReadInt(); // 9010040 | Conor (NPC)
                        pPacket.ReadShort();
                        pPacket.ReadInt(); // 4330019 | Pink Coin Purse
                        pPacket.ReadShort();
                    }
                }
            }

            for (int i = 13; i > 0; i--)
            {
                pPacket.ReadInt(); // Stolen Skills
            }

            for (int i = 4; i > 0; i--)
            {
                pPacket.ReadInt(); // Chosen Skills?
            }

            // Inner Stats
            Abilities = new List<Tuple<byte, int, byte>>();
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                byte id = pPacket.ReadByte(); // 'ID'
                int skillid = pPacket.ReadInt(); // Skill ID
                byte level = pPacket.ReadByte(); // Level
                pPacket.ReadByte(); // Rank
                Abilities.Add(new Tuple<byte, int, byte>(id, skillid, level));
            }

#if LOCALE_GMS
            {
                // V.134
                for (int i = pPacket.ReadInt(); i > 0; i--)
                {
                    pPacket.ReadString();

                    pPacket.ReadInt();
                    pPacket.ReadString();

                    for (int j = pPacket.ReadInt(); j > 0; j--)
                    {
                        pPacket.ReadByte();
                    }
                }

                pPacket.ReadByte();
            }
#endif

            Stats.HonourLevel = pPacket.ReadInt();
            Stats.HonourExp = pPacket.ReadInt();

            {
                byte unk = pPacket.ReadByte();
                if (unk == 1)
                {
                    while (true)
                    {
                        tmp = pPacket.ReadUShort();
                        if (tmp <= 0) break;

                        while (true)
                        {
                            ushort tmp2 = pPacket.ReadUShort();
                            if (tmp2 <= 0) break;

                            pPacket.ReadInt();
                            pPacket.ReadInt();
                        }
                    }
                }
                else
                {
                    while (true)
                    {
                        tmp = pPacket.ReadUShort();
                        if (tmp <= 0) break;

                        pPacket.ReadUShort();
                        pPacket.ReadInt();
                        pPacket.ReadInt();
                    }
                }
            }

            if (pPacket.ReadBool())
            {
                // Wat.
                ItemBase.DecodeItemData(pConnection, pPacket);
                pPacket.ReadInt();
            }


            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadByte();
            }


            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadLong();
            }

#if LOCALE_EMS
            pPacket.ReadBool();
            pPacket.ReadBool();
#endif
            {
                EvolutionCards = new List<EvolutionCard>();

                for (short i = pPacket.ReadShort(); i > 0; i--)
                {
                    var card = new EvolutionCard();
                    card.Decode(pConnection, pPacket);
                    card.Block = 1;
                    EvolutionCards.Add(card);
                }

                for (short i = pPacket.ReadShort(); i > 0; i--)
                {
                    var card = new EvolutionCard();
                    card.Decode(pConnection, pPacket);
                    card.Block = 2;
                    EvolutionCards.Add(card);
                }

            }

#if LOCALE_EMS
            if (pPacket.ReadBool())
            {
                // Wat.
                ItemBase.DecodeItemData(pConnection, pPacket);
                pPacket.ReadInt();
                pPacket.ReadInt();
            }
#endif

#if LOCALE_EMS
            // No farm info

            for (short i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.Skip(20);
            }

#else
            {
                // V.134
                for (byte i = pPacket.ReadByte(); i > 0; i--)
                {
                    pPacket.ReadInt();
                    pPacket.ReadLong();
                }
            }

            {
                // V.134
                // FARM INFO. Creating... = not yet created farm. Else: farmname
                pPacket.ReadString(); // Creating...
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadByte();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();

                pPacket.ReadInt();
                pPacket.ReadInt();
            }

#if LOCALE_GMS
            if (pPacket.ReadBool())
            {
                // Wat.
                ItemBase.DecodeItemData(pConnection, pPacket);
                pPacket.ReadInt();
                pPacket.ReadInt();
            }
#endif

            {
                // V.141
                pPacket.ReadInt();
                pPacket.ReadLong(); // A bit off here, should be filetime value
                pPacket.ReadInt();
            }

            pPacket.Skip(84); // I don't even

            pPacket.ReadByte();

            {
                for (short i = pPacket.ReadShort(); i > 0; i--)
                {
                    pPacket.ReadShort();
                    pPacket.ReadShort();
                }
            }

            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();

                pPacket.Skip(32);
            }

            {
                if (pPacket.ReadInt() > 0)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        pPacket.Skip(4 + 4 + 4);
                        pPacket.ReadString();
                        pPacket.Skip(4 * 7);
                        pPacket.Skip(8 * 4);
                        pPacket.Skip(4 * 4);
                        pPacket.Skip(1 * 5);
                        pPacket.Skip(4 * 3);
                        pPacket.ReadString();
                        pPacket.Skip(4 * 2);
                        pPacket.ReadByte();

                        byte tmptmp = pPacket.ReadByte();
                        if ((tmptmp & 0x01) != 0)
                        {
                            pPacket.ReadInt();
                            pPacket.ReadString();
                            pPacket.Skip(24);
                        }

                        for (int j = pPacket.ReadInt(); j > 0; j++)
                        {
                            pPacket.Skip(4 * 9);
                        }
                    }
                }
            }

            // Removed in V.141
            //pPacket.ReadInt(); // I DONT EVEN D:
#endif
        }
        public void Decode(MaplePacket pPacket)
        {
            this.ID = pPacket.ReadInt();
            this.Name = pPacket.ReadString(13);

            Logger.WriteLine("FOUND CHARACTER {0} (ID: {1})", this.Name, this.ID);

            this.Gender = pPacket.ReadByte();
            this.Skin = pPacket.ReadByte();
            this.Face = pPacket.ReadInt();
            this.Hair = pPacket.ReadInt();

#if LOCALE_EMS
            this.Pets = new long[3] { 0, 0, 0 }; // Not defined!?
#else
            this.Pets = new long[3] { pPacket.ReadLong(), pPacket.ReadLong(), pPacket.ReadLong() };
#endif

            this.Level = pPacket.ReadByte();


            this.JobID = pPacket.ReadShort();
            this.Str = pPacket.ReadShort();
            this.Dex = pPacket.ReadShort();
            this.Int = pPacket.ReadShort();
            this.Luk = pPacket.ReadShort();
            this.HP = pPacket.ReadInt();
            this.MaxHP = pPacket.ReadInt();
            this.MP = pPacket.ReadInt();
            this.MaxMP = pPacket.ReadInt();

            this.AP = pPacket.ReadShort();

            SPData = new List<KeyValuePair<byte, int>>();
            if (GameHelper.IsExtendedSPJob(this.JobID))
            {
                byte amnt = pPacket.ReadByte();
                List<byte> haslist = new List<byte>();
                for (int j = 0; j < amnt; j++)
                {
                    byte v1 = pPacket.ReadByte(); // Job ID
                    int v2 = pPacket.ReadInt(); // Amount
                    SPData.Add(new KeyValuePair<byte, int>(v1, v2));

                    haslist.Add(v1);
                }
                for (byte j = 1; j < 20; j++)
                {
                    if (!haslist.Contains(j))
                        SPData.Add(new KeyValuePair<byte, int>(j, 0));
                }
            }
            else
            {
                SPData.Add(new KeyValuePair<byte, int>(0, pPacket.ReadShort()));
            }

            this.EXP = pPacket.ReadLong();
            this.Fame = pPacket.ReadInt();
#if LOCALE_GMS
            pPacket.ReadInt(); // Gacha EXP
            pPacket.ReadInt(); // V.141, unknown
#elif LOCALE_EMS
            pPacket.ReadLong();
            pPacket.ReadLong();
#endif
            this.MapID = pPacket.ReadInt();
            this.MapPos = pPacket.ReadByte();

#if LOCALE_GMS
            pPacket.ReadInt();
#endif
            this.JobSubID = pPacket.ReadShort();


            if (this.JobID / 100 == 31 || this.JobID / 100 == 36 || this.JobID == 3001 || this.JobID == 3002)
            {
                this.DemonMark = pPacket.ReadInt();
            }

            //this.JobType = pPacket.ReadByte();
            pPacket.ReadByte(); // Fatigue ?

            this.DateThing = pPacket.ReadInt(); // YYYYMMDDhh

            this.Traits = new int[6] { 
                pPacket.ReadInt(), // Charisma
                pPacket.ReadInt(), // Insight
                pPacket.ReadInt(), // Willpower
                pPacket.ReadInt(), // Craft/Diligence
                pPacket.ReadInt(), // Empathy
                pPacket.ReadInt()  // Charm
            };

            this.TraitsToday = new ushort[6] { 
                pPacket.ReadUShort(), // Charisma
                pPacket.ReadUShort(), // Insight
                pPacket.ReadUShort(), // Willpower
                pPacket.ReadUShort(), // Craft/Diligence
                pPacket.ReadUShort(), // Empathy
                pPacket.ReadUShort()  // Charm
            };


            pPacket.Skip(21 - 12); // Leftover: 9 bytes

            pPacket.ReadInt();

            pPacket.ReadByte();
            pPacket.ReadInt();
            pPacket.ReadByte();
            pPacket.ReadByte();
            pPacket.ReadInt();
            pPacket.ReadByte();

            pPacket.ReadInt();
            pPacket.ReadInt();

            pPacket.ReadInt();
            pPacket.ReadByte(); // != 0 check

            // List of Parttime jobs?
            for (int i = 1; i <= 9; i++)
            {
                pPacket.ReadInt(); // Character ID
                pPacket.ReadByte(); // Level
                pPacket.ReadInt(); // Job ID
            }

            pPacket.ReadInt();
            pPacket.ReadInt();

#if LOCALE_EMS
            pPacket.ReadInt();
#endif
        }
        public override void OnPacket(MaplePacket pPacket)
        {
            byte type = pPacket.ReadByte();
            ushort header = pPacket.ReadUShort();
            if (header >= 0xEE00)
            {
                if (header == 0xEEFF)
                {
                    string version = pPacket.ReadString();
                    if (version != Logger.Version)
                    {

                        if (frmMain.Instance != null)
                        {
                            frmMain.Instance.Invoke((System.Windows.Forms.MethodInvoker)delegate
                            {
                                System.Windows.Forms.MessageBox.Show(frmMain.Instance, "You are using an outdated version of Mapler.me! Check the site for the latest updates.", "Mapler.me server connection error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                            });
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("You are using an outdated version of Mapler.me! Check the site for the latest updates.", "Mapler.me server connection error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        }
                        Environment.Exit(3);
                        return;
                    }


                    // Crypto
                    byte[] sendkey = pPacket.ReadBytes(32),
                        recvkey = pPacket.ReadBytes(32);

                    SetKeys(sendkey, recvkey);

                    _validHeaders = new List<ushort>[(byte)MaplePacket.CommunicationType.AMOUNT];
                    for (byte i = 0; i < (byte)MaplePacket.CommunicationType.AMOUNT; i++)
                    {
                        _validHeaders[i] = new List<ushort>();
                        for (ushort j = pPacket.ReadUShort(); j > 0; j--)
                        {
                            ushort tmp = pPacket.ReadUShort();
                            // Logger.WriteLine("{0} accepts 0x{1:X4}", (MaplePacket.CommunicationType)i, tmp);
                            _validHeaders[i].Add(tmp);
                        }
                    }


                    for (byte j = pPacket.ReadByte(); j > 0; j--)
                    {
                        string ip = pPacket.ReadString();
                        AcceptedIPs.Add(ip);
                    }

                    if (pPacket.ReadBool())
                        MapleStoryCryptoKey = pPacket.ReadBytes(32);

                    AcceptedMapleStoryLocale = pPacket.ReadByte();
                    AcceptedMapleStoryVersion = pPacket.ReadUShort();
                    Logger.WriteLine("Initialized keys and valid headers");

                    SendToken(Program.Token);
                }
                else if (header == 0xEEFE)
                {
                    // Create screenshot and send to server

                    string url = pPacket.ReadString();
                    string data = pPacket.ReadString();

                    string filename = System.IO.Path.GetTempFileName();

                    bool done = Screenshot.MakeScreenshotOfMaple(filename);
                    if (done)
                    {
                        Screenshot.Upload(url, data, filename);
                    }
                }
                else if (header == 0xEEFD)
                {
                    string charname = pPacket.ReadString();
                    frmMain.Instance.Invoke((System.Windows.Forms.MethodInvoker)delegate
                    {
                        frmMain.Instance.lblLastUpdate.Text = string.Format("{0} (Character: {1})", DateTime.Now, charname);
                    });
                }
                else if (header == 0xEEFC)
                {
                    frmMain.Instance.Invoke((System.Windows.Forms.MethodInvoker)delegate
                    {
                        frmMain.Instance.lblInfo.Text = pPacket.ReadString();
                    });
                }
                else if (header == 0xEE01)
                {
                    // Pingpong
                    using (MaplePacket mp = new MaplePacket(MaplePacket.CommunicationType.ClientPacket, 0xEE01))
                    {
                        SendPacket(mp);
                    }
                }
            }

            pPacket.Dispose();
            pPacket = null;
        }
Beispiel #18
0
        public void Decode(MaplePacket pPacket)
        {
            ID = pPacket.ReadInt();
            Name = pPacket.ReadString();

            for (byte i = 0; i < 5; i++)
                Ranks[i] = pPacket.ReadString();

            Players = pPacket.ReadByte();

            Members = new List<GuildMember>();
            for (byte i = 0; i < Players; i++)
            {
                var id = pPacket.ReadInt(); // Player ID

                Members.Add(new GuildMember() { CharacterID = id });
            }

            for (byte i = 0; i < Players; i++)
            {
                GuildMember tmp = Members[i];

                pPacket.ReadString(13); // Name
                pPacket.ReadInt(); // Job ID
                pPacket.ReadInt(); // Level OR -1
                tmp.Rank = (byte)pPacket.ReadInt(); // Guild Rank
                pPacket.ReadInt(); // Online
                pPacket.ReadInt(); // Alliance Rank
                tmp.Contribution = pPacket.ReadInt(); // Contribution
            }

            Capacity = (byte)pPacket.ReadInt();
            Background = pPacket.ReadShort();
            BackgroundColor = pPacket.ReadByte();
            Foreground = pPacket.ReadShort();
            ForegroundColor = pPacket.ReadByte();

            Notice = pPacket.ReadString();

            Points = pPacket.ReadInt();
            pPacket.ReadInt(); // Today's points
            AllianceID = pPacket.ReadInt();

            pPacket.ReadByte(); // Unk
            pPacket.ReadShort(); // Herp

            Skills = new List<GuildSkill>();
            var skills = pPacket.ReadShort(); // Buffs
            for (var i = 0; i < skills; i++)
            {
                GuildSkill gb = new GuildSkill()
                {
                    SkillID = pPacket.ReadInt(),
                    Level = pPacket.ReadShort(),
                    BoughtAt = pPacket.ReadLong(),
                    BoughtBy = pPacket.ReadString(),
                    Unknown = pPacket.ReadString()
                };

                Skills.Add(gb);
            }
        }
        public virtual void HandleBuddyList(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte mode = pPacket.ReadByte();
            if (mode != 0x07) return;

            MySQL_Connection.Instance.RunQuery(string.Format("DELETE FROM buddies WHERE character_id = {0}", pConnection.CharacterInternalID));
            using (InsertQueryBuilder buddies = new InsertQueryBuilder("buddies"))
            {
                buddies.OnDuplicateUpdate = true;
                buddies.AddColumn("character_id");
                buddies.AddColumn("friend_id");
                buddies.AddColumns(true, "friend_name", "group_name");

                byte amount = pPacket.ReadByte();
                for (byte i = 0; i < amount; i++)
                {
                    int bid = pPacket.ReadInt();
                    string bname = pPacket.ReadString(13);
                    pPacket.Skip(1 + 4);
                    string gname = pPacket.ReadString(13);
                    pPacket.Skip(4);

                    buddies.AddRow(
                        pConnection.CharacterInternalID,
                        bid,
                        bname,
                        gname
                        );
                }
                buddies.RunQuery();
            }
        }
        public virtual void HandleFamiliarList(ClientConnection pConnection, MaplePacket pPacket)
        {
            using (InsertQueryBuilder familiars = new InsertQueryBuilder("familiars"))
            {
                familiars.OnDuplicateUpdate = true;

                familiars.AddColumn("character_id");
                familiars.AddColumn("mobid");
                familiars.AddColumns(true,
                    "name", "fitality_cur", "fitality_max",
                    "starttime", "endtime", "unktime"
                );

                for (int i = pPacket.ReadInt(); i > 0; i--)
                {
                    pPacket.ReadInt(); // Weird id?
                    int mobid = pPacket.ReadInt();
                    string name = pPacket.ReadString(13);
                    byte currentfit = pPacket.ReadByte();
                    byte maxfit = pPacket.ReadByte();
                    pPacket.ReadInt();
                    pPacket.ReadByte();
                    DateTime starttime = DateTime.FromFileTime(pPacket.ReadLong());
                    DateTime unktime = DateTime.FromFileTime(pPacket.ReadLong());
                    DateTime endtime = DateTime.FromFileTime(pPacket.ReadLong());

                    pPacket.ReadByte();
                    pPacket.ReadByte();


                    familiars.AddRow(
                        pConnection.CharacterInternalID,
                        mobid,
                        name,
                        currentfit,
                        maxfit,
                        starttime,
                        endtime,
                        unktime
                        );

                }

                familiars.RunQuery();
            }
        }
 public virtual void HandleSkillMacros(ClientConnection pConnection, MaplePacket pPacket)
 {
     byte count = pPacket.ReadByte();
     if (count == 0) return;
     string q = string.Format("DELETE FROM skillmacros WHERE character_id = {0};\r\n", pConnection.CharacterInternalID);
     q += "INSERT INTO skillmacros VALUES \r\n";
     for (int i = 0; i < count; i++)
     {
         string name = pPacket.ReadString();
         bool shout = pPacket.ReadBool();
         int skill1 = pPacket.ReadInt();
         int skill2 = pPacket.ReadInt();
         int skill3 = pPacket.ReadInt();
         q += string.Format("({0}, {1}, '{2}', {3}, {4}, {5}, {6}),", pConnection.CharacterInternalID, i, MySql.Data.MySqlClient.MySqlHelper.EscapeString(name), shout, skill1, skill2, skill3);
     }
     q = q.TrimEnd(',');
     MySQL_Connection.Instance.RunQuery(q);
 }
Beispiel #22
0
        internal bool BufferTCPPacket(TcpPacket pTCPPacket, bool pInbound)
        {
            if (pTCPPacket.Syn && pTCPPacket.Ack)
            {
                mInboundSequence = (uint)(pTCPPacket.SequenceNumber + 1); 
                return true;
            }
            if (pTCPPacket.PayloadData.Length == 0) return true;
            if (_mapleVersion == 0)
            {
                if (pTCPPacket.PayloadData.Length < 13) return false;
                byte[] tcpData = pTCPPacket.PayloadData;

                MaplePacket pr = new MaplePacket(tcpData);
                pr.ReadShort();
                _mapleVersion = pr.ReadUShort();
                var pos = pr.Position;
                {
                    var shrt = pr.ReadShort();
                    if (shrt < 0 || shrt > 0x0020)
                    {
                        return false;
                    }
                }
                pr.Reset(pos);
                _maplePatchLocation = pr.ReadString();
                byte[] localIV = pr.ReadBytes(4);
                byte[] remoteIV = pr.ReadBytes(4);
                _mapleLocale = pr.ReadByte();

                if (pr.Length > pr.Position || _mapleLocale > 0x12)
                {
                    return false;
                }

                pr.Dispose();
                pr = null;

                mOutboundStream = new PacketStream(localIV, _mapleLocale, _mapleVersion, !pInbound);
                mInboundStream = new PacketStream(remoteIV, _mapleLocale, (ushort)(0xFFFF - _mapleVersion), pInbound);
                mInboundSequence += (uint)tcpData.Length;

            }
            if (!pInbound) ProcessTCPPacket(pTCPPacket, ref mOutboundSequence, mOutboundBuffer, mOutboundStream, pInbound);
            else ProcessTCPPacket(pTCPPacket, ref mInboundSequence, mInboundBuffer, mInboundStream, pInbound);

            return true;
        }
        public virtual void HandleMessage(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte type = pPacket.ReadByte();
            if (type == 0x0C)
            {
                ushort id = pPacket.ReadUShort();
                string data = pPacket.ReadString();
                // Server data update
                using (InsertQueryBuilder iqb = new InsertQueryBuilder("quests_running_party"))
                {
                    iqb.OnDuplicateUpdate = true;
                    iqb.AddColumn("character_id");
                    iqb.AddColumn("questid");
                    iqb.AddColumn("data", true);

                    iqb.AddRow(pConnection.CharacterInternalID, id, data);
                    iqb.RunQuery();
                }
            }
            else if (type == 0x01)
            {
                ushort id = pPacket.ReadUShort();
                byte mode = pPacket.ReadByte();

                if (mode == 1)
                {
                    string text = pPacket.ReadString();

                    using (InsertQueryBuilder iqb = new InsertQueryBuilder("quests_running"))
                    {
                        iqb.OnDuplicateUpdate = true;
                        iqb.AddColumn("character_id");
                        iqb.AddColumn("questid");
                        iqb.AddColumn("data", true);

                        iqb.AddRow(pConnection.CharacterInternalID, id, text);
                        iqb.RunQuery();
                    }

                }
                else if (mode == 2)
                {
                    // Quest complete
                    long time = pPacket.ReadLong();

                    using (DeleteQueryBuilder dqb = new DeleteQueryBuilder("quests_running"))
                    {
                        dqb.SetWhereColumn("character_id", pConnection.CharacterInternalID);
                        dqb.SetWhereColumn("questid", id);
                        dqb.RunQuery();
                    }

                    using (InsertQueryBuilder iqb = new InsertQueryBuilder("quests_done"))
                    {
                        iqb.OnDuplicateUpdate = true;
                        iqb.AddColumn("character_id");
                        iqb.AddColumn("questid");
                        iqb.AddColumn("time", true);

                        iqb.AddRow(pConnection.CharacterInternalID, id, time);
                        iqb.RunQuery();
                    }

                }
            }
        }
        public override void Decode(MaplePacket pPacket)
        {
            base.Decode(pPacket);

            Amount = pPacket.ReadShort();
            CraftName = pPacket.ReadString();
            Flags = pPacket.ReadShort();

            int itemtype = ItemID / 10000;
            if (itemtype == 233 || itemtype == 207)
                UniqueID = pPacket.ReadLong();
        }
        public override void Decode(MaplePacket pPacket)
        {
            base.Decode(pPacket);

            Petname = pPacket.ReadString(13);
            Level = pPacket.ReadByte();
            Closeness = pPacket.ReadShort();
            Fullness = pPacket.ReadByte();


            pPacket.Skip(8 + 2 + 2 + 4 + 2 + 1 + 4 + 4);
        }
        public virtual void HandleChangeMap(ClientConnection pConnection, MaplePacket pPacket)
        {

            int tmp = pPacket.ReadShort();
            pPacket.Skip(tmp * (4 + 4));

            int channelid = pPacket.ReadInt();
            pConnection.ChannelID = (byte)channelid;

#if LOCALE_EMS
            pPacket.ReadByte();
#endif
            pPacket.Skip(1 + 4);
            pPacket.Skip(1); // Portals taken
            pPacket.Skip(4);

            bool isConnecting = pPacket.ReadBool();

            if (!isConnecting && pConnection.CharData == null)
            {
                return;
            }

            pConnection._CharactersInMap.Clear();

            tmp = pPacket.ReadShort(); // Contains Message (Not used anymore lol.)
            if (tmp > 0)
            {
                pPacket.ReadString(); // Title
                for (int i = 0; i < tmp; i++)
                {
                    pPacket.ReadString(); // Line N
                }
            }

            if (isConnecting)
            {
                pPacket.Skip(12); // RNGs

                pConnection.Logger_WriteLine("--------- Started parsing Character Info ----------");

                CharacterData data = new CharacterData();
                data.Decode(pConnection, pPacket);

                pConnection.Logger_WriteLine("--------- Done parsing Character Info ----------");

                // Quick duplicate check
                Tuple<int, byte, byte, ushort> conflicted = null;
                using (var reader = MySQL_Connection.Instance.RunQuery("SELECT id, level, world_id, job FROM characters WHERE id <> " + data.Stats.ID + " AND name = " + MySQL_Connection.Escape(data.Stats.Name)) as MySql.Data.MySqlClient.MySqlDataReader)
                {
                    if (reader.Read())
                    {
                        // CONFLICTS
                        conflicted = new Tuple<int, byte, byte, ushort>(reader.GetInt32(0), reader.GetByte(1), reader.GetByte(2), reader.GetUInt16(3));
                    }
                }
                if (conflicted == null)
                {
                    if (!data.SaveData(pConnection))
                        return;

                    pConnection.CharData = data;

                    pConnection.Logger_WriteLine("--------- Saved parsed Character Info ----------");


                    pConnection.LastLoggedCharacterName = pConnection.CharData.Stats.Name;
                    pConnection.LastLoggedDate = pConnection.CharData.Stats.DateThing.ToString();

                    pConnection.LogFilename += "-" + pConnection.CharacterInternalID;

                    pConnection.LastExpPoint = (byte)EXPTable.GetLevelPercentage(data.Stats.Level, data.Stats.EXP);

                    pConnection.SendInfoText("Your character {0} has been saved!", pConnection.CharData.Stats.Name);

                    // Save SessionRestart Info
                    SessionRestartCache.Instance.StoreInfo(pConnection.IP, pConnection.MachineID, pConnection.CharacterID, pConnection.WorldID);

                }
                else
                {
                    pConnection.LogFilename += "-(CONFLICT)" + data.Stats.Name;

                    pConnection.Logger_WriteLine("!!!!!! FOUND CHARACTER NAME CONFLICT ! Expected Character ID {0}, found Character ID {1} in database!", data.Stats.ID, conflicted.Item1);
                    pConnection.Logger_WriteLine("Level diff: {0} - {1}", data.Stats.Level, conflicted.Item3);
                    pConnection.Logger_WriteLine("Job diff: {0} - {1}", data.Stats.JobID, conflicted.Item4);
                    pConnection.Logger_WriteLine("World diff: {0} - {1}", pConnection.WorldID, conflicted.Item2);
                    pConnection.SendInfoText("A different character has already this name! Delete this character via the website first!");
                }


                Queries.SaveServerIP(pConnection.ConnectedToIP, pConnection.ConnectedToPort, GameHelper.GetAllianceWorldID(pConnection.WorldID), pConnection.ChannelID);
            }
            else
            {
                pPacket.ReadByte();

                int mapid = pPacket.ReadInt();
                byte mappos = pPacket.ReadByte();
                pConnection.Logger_WriteLine("New MapID: {0} ({1})", mapid, mappos);

                pConnection.CharData.Stats.MapID = mapid;
                pConnection.CharData.Stats.MapPos = mappos;

                int hp = pPacket.ReadInt();
                pConnection.CharData.Stats.HP = hp;

                if (pPacket.ReadBool())
                {
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                }

                MySQL_Connection.Instance.RunQuery(string.Format("UPDATE characters SET chp = {0}, map = {1}, pos = {2} WHERE internal_id = {3}", hp, mapid, mappos, pConnection.CharacterInternalID));
            }

            pPacket.ReadLong();
            //DateTime servertime = DateTime.FromFileTime(pPacket.ReadLong());
            pPacket.ReadInt(); // 100?
            pPacket.ReadByte(); // 0
            pPacket.ReadByte(); // 0
            pPacket.ReadByte(); // 1

            if (pPacket.Position != pPacket.Length)
            {
                pConnection.Logger_WriteLine("Data not fully read. Halp.: {0} of {1} read", pPacket.Position, pPacket.Length);
            }


            pConnection.SendTimeUpdate();
        }
Beispiel #27
0
 public void DecodePQ(ClientConnection pConnection, MaplePacket pPacket)
 {
     PartyQuestsRunning = new Dictionary<ushort, string>();
     for (int i = pPacket.ReadShort(); i > 0; i--)
     {
         ushort id = pPacket.ReadUShort();
         string value = pPacket.ReadString();
         if (!PartyQuestsRunning.ContainsKey(id))
             PartyQuestsRunning.Add(id, value);
         else
             pConnection.Logger_WriteLine("Duplicate PQ (Running): {0}", id);
     }
 }
        public void Decode(MaplePacket pPacket)
        {
            Stats = new GW_CharacterStat();
            Stats.Decode(pPacket);

            this.BuddylistSize = pPacket.ReadByte();

            if (pPacket.ReadBool()) BlessingOfTheFairy = pPacket.ReadString();
            else BlessingOfTheFairy = null;
            if (pPacket.ReadBool()) BlessingOfEmpress = pPacket.ReadString();
            else BlessingOfEmpress = null;
            if (pPacket.ReadBool()) UltimateExplorer = pPacket.ReadString();
            else UltimateExplorer = null;

            Stats.DecodeMesos(pPacket); // .-.

            // Unknown stuff here

            int amount = pPacket.ReadInt();
            UnknownIntegerList = new List<UnknownListOfIntegers>();
            for (int i = 0; i < amount; i++)
            {
                UnknownListOfIntegers vals = new UnknownListOfIntegers();
                vals.Decode(pPacket);
                UnknownIntegerList.Add(vals);
            }


            Inventory = new CharacterInventory();
            Inventory.Decode(pPacket);

            UnknownIntegerListNumber2 = new List<int>();
            while (true)
            {
                int unkval = pPacket.ReadInt();
                if (unkval == -1) break;
                UnknownIntegerListNumber2.Add(unkval);
            }

            UnknownIntegerListNumber3 = new Dictionary<int, long>();
            amount = pPacket.ReadInt();
            for (int i = 0; i < amount; i++)
            {
                UnknownIntegerListNumber3.Add(pPacket.ReadInt(), pPacket.ReadLong());
            }

            {
                UnknownIntegerListNumber4 = new Dictionary<long, long>();
                amount = pPacket.ReadInt();
                for (int i = 0; i < amount; i++)
                {
                    UnknownIntegerListNumber4.Add(pPacket.ReadLong(), pPacket.ReadLong());
                }


                while (true)
                {

                    byte val = pPacket.ReadByte();
                    if (val == 0) break;
                    {
                        pPacket.ReadInt();
                        pPacket.ReadByte();
                        pPacket.ReadByte();
                        pPacket.ReadInt();
                        pPacket.ReadInt();
                        pPacket.ReadInt();
                        pPacket.ReadInt();
                        pPacket.ReadByte();
                        pPacket.ReadInt();
                        pPacket.ReadLong();
                        pPacket.ReadLong();
                        pPacket.ReadLong();
                        pPacket.ReadLong();
                    }
                }
            }


            Skills = new CharacterSkills();
            Skills.Decode(pPacket);

            Quests = new CharacterQuests();
            Quests.Decode(pPacket);

            // Match
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
            }

            // Couple
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.ReadBytes(33);
            }

            // Friend
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.ReadBytes(37);
            }

            // Marriage
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                pPacket.ReadBytes(48);
            }

            Inventory.DecodeTeleportRocks(pPacket);


        }
        public static void HandleServerConnectionStatus(ClientConnection pConnection, MaplePacket pPacket)
        {
            if (pPacket.ReadBool())
            {
                string ip = pPacket.ReadString();
                ushort port = pPacket.ReadUShort();
                pConnection.Logger_WriteLine("- Client got connection with MapleStory server @ {0}:{1}", ip, port);

                pConnection.ConnectedToIP = ip;
                pConnection.ConnectedToPort = port;

                if (port == 8484)
                {
                    pConnection.SendInfoText("Mapler.me is awaiting account check! Happy mapling!");
                    var info = SessionRestartCache.Instance.GetInfoForConnection(pConnection);
                    if (info != null)
                        SessionRestartCache.Instance.RemoveInfo(info);


                    pConnection.ChannelID = 255;
                }
                else
                {
                    pConnection.SendInfoText("You successfully connected, or are in the Cash Shop!");
                }

                pConnection.ConnectedTimeToServer = MasterThread.CurrentDate;
            }
            else
            {
                pConnection.Logger_WriteLine("- Client lost connection with MapleStory server");
                pConnection.SendInfoText("Maplestory is closed, or not connected properly.");

                pConnection.ConnectedToIP = "0.0.0.0";
                pConnection.ConnectedToPort = 0;

                if (pConnection.ConnectedTimeToServer != DateTime.MinValue)
                {
                    var timespan = MasterThread.CurrentDate - pConnection.ConnectedTimeToServer;
                    pConnection.Logger_WriteLine("Player was connected for {0}", timespan);

                    if (timespan.TotalSeconds < 5)
                    {
                        pConnection.Logger_WriteLine("CLIENT PROBABLY FAILED TO CONNECT!!!");
                    }

                    if (pConnection.CharData != null)
                    {
                        // Probably CC-ing or something. record

                        MySQL_Connection.Instance.RunQuery("INSERT INTO connection_log VALUES " + MySQL_Connection.BuildValuesRow(pConnection.AccountID, pConnection.CharacterInternalID, pConnection.ChannelID, pConnection.ConnectedTimeToServer, new MySQL_Connection.NowType()));

                    }
                }

                // Delete if there's session info
                var info = SessionRestartCache.Instance.GetInfoForConnection(pConnection);
                if (info != null)
                    SessionRestartCache.Instance.RemoveInfo(info);

                pConnection.CharData = null;
                pConnection.CharacterInternalID = -1;
                pConnection.CharacterID = -1;
                pConnection.ChannelID = 255;
            }
        }
        public virtual void HandleTradeData(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte type = pPacket.ReadByte();
            pPacket.ReadByte();
            if (type == 0x0A)
            {
                pPacket.ReadByte();
                pPacket.ReadShort();
                int merchid = pPacket.ReadInt();
                string merchname = pPacket.ReadString();
                pPacket.ReadByte();
                while (true)
                {
                    byte slot = pPacket.ReadByte();
                    if (slot == 255) break;

                    pPacket.ReadInt(); // Player ID
                    ParseAvatar(pPacket);
                    pPacket.ReadString(); // Player Name
                    pPacket.ReadShort(); // Job
                }

                pPacket.ReadShort();
                pPacket.ReadString(); // Owner name
                pPacket.ReadShort(); // Shop cash ID
                pPacket.ReadString(); // Shop name
                pPacket.ReadInt(); // ???
                pPacket.ReadByte(); // ???

                byte items = pPacket.ReadByte();

                using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items_trades"))
                {
                    for (int i = 0; i < items; i++)
                    {
                        short slot = pPacket.ReadShort(); // Slot?
                        pPacket.ReadShort();
                        pPacket.ReadInt(); // Price
                        Queries.SaveItem(pConnection, (ushort)0, slot, ItemBase.DecodeItemData(pConnection, pPacket), itemsTable, true);
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM items_trades"); // Clear table

                    itemsTable.RunQuery();
                }
            }
        }