public virtual void HandleVersion(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte locale = pPacket.ReadByte();
            ushort version = pPacket.ReadUShort();
            ushort subversion = pPacket.ReadUShort();

            pConnection.Logger_WriteLine("Detected MapleStory version of client: {1}.{2} (locale: {0})", locale, version, subversion);
            pConnection.MapleVersion = version;

            pConnection.CharData = null; // Back to the LoginServer!!!
            if (locale != ServerMapleInfo.LOCALE)
            {
                pConnection.Logger_WriteLine("Incompatible MapleStory locale detected!!!!");
                pConnection.SendInfoText("Unsupported MapleStory client detected. Mapler.me only supports MapleStory Global version {0} at the moment.", ServerMapleInfo.VERSION); // This should _never_ happen XD (different encryption and such)
                pConnection.Disconnect();
            }
            else if (version > ServerMapleInfo.VERSION)
            {
                pConnection.Logger_WriteLine("MapleStory client of user is outdated/incorrect. Disconnect.");
                pConnection.SendInfoText("Your MapleStory client seems outdated. Update your client in order to use the Mapler.me service.\r\nVersion identified: {0}\r\nSupported version: {1}", version, ServerMapleInfo.VERSION);
                pConnection.Disconnect();
            }
            else if (version < ServerMapleInfo.VERSION)
            {
                pConnection.Logger_WriteLine("MapleStory client of user is more up-to-date than Mapler.me service!!!");
                pConnection.SendInfoText("As your client is more up-to-date than the Mapler.me service, you are unable to use the Mapler.me service at this time.\r\nCheck the Mapler.me website and/or Twitter (@maplerme) for updates!\r\n\r\nCurrently supported version: {0}\r\nYour version: {1}", ServerMapleInfo.VERSION, version);
                pConnection.Disconnect();
            }

        }
        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);
        }
        public virtual void HandleVersion(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte   locale     = pPacket.ReadByte();
            ushort version    = pPacket.ReadUShort();
            ushort subversion = pPacket.ReadUShort();

            pConnection.Logger_WriteLine("Detected MapleStory version of client: {1}.{2} (locale: {0})", locale, version, subversion);
            pConnection.MapleVersion = version;

            pConnection.CharData = null; // Back to the LoginServer!!!
            if (locale != ServerMapleInfo.LOCALE)
            {
                pConnection.Logger_WriteLine("Incompatible MapleStory locale detected!!!!");
                pConnection.SendInfoText("Unsupported MapleStory client detected. Mapler.me only supports MapleStory Global version {0} at the moment.", ServerMapleInfo.VERSION); // This should _never_ happen XD (different encryption and such)
                pConnection.Disconnect();
            }
            else if (version > ServerMapleInfo.VERSION)
            {
                pConnection.Logger_WriteLine("MapleStory client of user is outdated/incorrect. Disconnect.");
                pConnection.SendInfoText("Your MapleStory client seems outdated. Update your client in order to use the Mapler.me service.\r\nVersion identified: {0}\r\nSupported version: {1}", version, ServerMapleInfo.VERSION);
                pConnection.Disconnect();
            }
            else if (version < ServerMapleInfo.VERSION)
            {
                pConnection.Logger_WriteLine("MapleStory client of user is more up-to-date than Mapler.me service!!!");
                pConnection.SendInfoText("As your client is more up-to-date than the Mapler.me service, you are unable to use the Mapler.me service at this time.\r\nCheck the Mapler.me website and/or Twitter (@maplerme) for updates!\r\n\r\nCurrently supported version: {0}\r\nYour version: {1}", ServerMapleInfo.VERSION, version);
                pConnection.Disconnect();
            }
        }
        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 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(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());
                }
            }
        }
Beispiel #7
0
        public void TryRestartSession(ClientConnection pConnection, int pCharacterID, byte[] pMachineID)
        {
            RestartInfo restartInfo = Cache.Find((i) => { return(i.CharacterID == pCharacterID && i.CompareMachineID(pMachineID) && i.IP == pConnection.IP); });

            if (restartInfo != null)
            {
                // Found character
                // NOTE:
                // When a player/IP has 2 characters with the same ID on 2 different worlds
                // And the connection resets. And the player changes to the other character.
                // And a blue moon. Then worlds collide and apocalypse

                var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(pCharacterID, restartInfo.WorldID);

                if (info != null)
                {
                    if (info.AccountID != pConnection.AccountID)
                    {
                        pConnection.Logger_WriteLine("Unable to restore session for {0} (IP: {1})! Account id not the same! (Trying to hack it?)", pCharacterID, pConnection.IP);
                        return;
                    }
                    // Okay. We got this
                    pConnection.WorldID = info.WorldID;
                    pConnection.UserID  = info.UserID;
                    // Do not set the IDs of the character
                    // pConnection.CharacterInternalID = info.InternalID;

                    pConnection.Logger_WriteLine("Restored session for characterid {0} world {1} (IP: {2})", pCharacterID, info.WorldID, pConnection.IP);

                    // Scratch him off the cache list
                    Cache.Remove(restartInfo);
                }
                else
                {
                    pConnection.Logger_WriteLine("Unable to restore session for {0} (IP: {1})! Not found in Internal Storage.", pCharacterID, pConnection.IP);
                }
            }
            else
            {
                pConnection.Logger_WriteLine("No info found for character id {0} (IP: {1})", pCharacterID, pConnection.IP);
            }
        }
        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 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);
        }
Beispiel #10
0
        private long DecodeTimeFromInt(ClientConnection pConnection, uint pValue)
        {

            long ft = 0;
            DateTime temp;
            if (DateTime.TryParseExact(pValue.ToString(), "yyMMddHHmm", provider, DateTimeStyles.None, out temp))
                ft = temp.ToFileTime();
            else
            {
                pConnection.Logger_WriteLine("Unable to parse {0} as date. GG nexon.", pValue);
                ft = 150842304000000000L; // GG Nexon.
            }

            return ft;
        }
Beispiel #11
0
 private static long FlaggedValue(ClientConnection pConnection, int pItemID, uint pValue, uint pFlag, MaplePacket pPacket, long pTypeValue, bool pLogIfFound = false)
 {
     if (pValue.HasFlag(pFlag))
     {
         var val = pPacket.ReadLong();
         if (pLogIfFound)
         {
             pConnection.Logger_WriteLine("Found flag {3} {0:X8}: {1} | ItemID: {2}", pFlag, val, pItemID, pTypeValue.GetType().Name);
         }
         return(val);
     }
     else
     {
         return(0);
     }
 }
        public virtual void HandleCharacterLoadRequest(ClientConnection pConnection, MaplePacket pPacket)
        {
            if (!(pConnection.ConnectedToPort >= 8585 && pConnection.ConnectedToPort <= 8600))
            {
                pConnection.Logger_WriteLine("Ignoring Character Load Request; not connected to a channel server");
                return;
            }

            int characterid = pPacket.ReadInt();
            byte[] machineid = pPacket.ReadBytes(16);
            pConnection.MachineID = machineid;

            if (pConnection.UserID == -1)
            {
                SessionRestartCache.Instance.TryRestartSession(pConnection, characterid, machineid);
            }
        }
Beispiel #13
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);
         }
     }
 }
Beispiel #14
0
        private long DecodeTimeFromInt(ClientConnection pConnection, uint pValue)
        {
            long     ft = 0;
            DateTime temp;

            if (DateTime.TryParseExact(pValue.ToString(), "yyMMddHHmm", provider, DateTimeStyles.None, out temp))
            {
                ft = temp.ToFileTime();
            }
            else
            {
                pConnection.Logger_WriteLine("Unable to parse {0} as date. GG nexon.", pValue);
                ft = 150842304000000000L; // GG Nexon.
            }

            return(ft);
        }
        public virtual void HandleCharacterLoadRequest(ClientConnection pConnection, MaplePacket pPacket)
        {
            if (!(pConnection.ConnectedToPort >= 8585 && pConnection.ConnectedToPort <= 8600))
            {
                pConnection.Logger_WriteLine("Ignoring Character Load Request; not connected to a channel server");
                return;
            }

            int characterid = pPacket.ReadInt();

            byte[] machineid = pPacket.ReadBytes(16);
            pConnection.MachineID = machineid;

            if (pConnection.UserID == -1)
            {
                SessionRestartCache.Instance.TryRestartSession(pConnection, characterid, machineid);
            }
        }
        public virtual void HandleKeymapUpdate(ClientConnection pConnection, MaplePacket pPacket)
        {
            int mode = pPacket.ReadInt();

            if (mode == 0)
            {
                Dictionary <byte, KeyValuePair <byte, int> > modifieds = new Dictionary <byte, KeyValuePair <byte, int> >();
                int amount = pPacket.ReadInt();
                for (int i = 0; i < amount; i++)
                {
                    int  idx   = pPacket.ReadInt();
                    byte type  = pPacket.ReadByte();
                    int  value = pPacket.ReadInt();

                    if (idx < 0 || idx > ServerMapleInfo.KEYMAP_SLOTS)
                    {
                        pConnection.Logger_WriteLine("ERROR: Keymap contained invalid index!");
                        return;
                    }

                    if (modifieds.ContainsKey((byte)idx))
                    {
                        continue;                                   // -.-''
                    }
                    modifieds.Add((byte)idx, new KeyValuePair <byte, int>(type, value));
                }

                if (modifieds.Count == 0)
                {
                    return;
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("UPDATE character_keymaps SET ");
                foreach (var kvp in modifieds)
                {
                    sb.AppendFormat("map_{0}_type = {1}, map_{0}_value = {2},", kvp.Key, kvp.Value.Key, kvp.Value.Value);
                }

                sb.Append(" WHERE character_id = " + pConnection.CharacterInternalID);

                MySQL_Connection.Instance.RunQuery(sb.ToString().Replace(", WHERE", " WHERE"));
            }
        }
Beispiel #17
0
        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;
            }
        }
Beispiel #18
0
        public void DecodePQDone(ClientConnection pConnection, MaplePacket pPacket)
        {
            PartyQuestsDone = new Dictionary <ushort, long>();
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                ushort id = pPacket.ReadUShort();
#if LOCALE_EMS
                var date = pPacket.ReadUInt();

                long time = DecodeTimeFromInt(pConnection, date);
#else
                long time = pPacket.ReadLong();
#endif
                if (!PartyQuestsDone.ContainsKey(id))
                {
                    PartyQuestsDone.Add(id, time);
                }
                else
                {
                    pConnection.Logger_WriteLine("Duplicate PQ (Done): {0}", id);
                }
            }
        }
        public virtual void HandleKeymapUpdate(ClientConnection pConnection, MaplePacket pPacket)
        {
            int mode = pPacket.ReadInt();
            if (mode == 0)
            {
                Dictionary<byte, KeyValuePair<byte, int>> modifieds = new Dictionary<byte, KeyValuePair<byte, int>>();
                int amount = pPacket.ReadInt();
                for (int i = 0; i < amount; i++)
                {
                    int idx = pPacket.ReadInt();
                    byte type = pPacket.ReadByte();
                    int value = pPacket.ReadInt();

                    if (idx < 0 || idx > ServerMapleInfo.KEYMAP_SLOTS)
                    {
                        pConnection.Logger_WriteLine("ERROR: Keymap contained invalid index!");
                        return;
                    }

                    if (modifieds.ContainsKey((byte)idx)) continue; // -.-''

                    modifieds.Add((byte)idx, new KeyValuePair<byte, int>(type, value));
                }

                if (modifieds.Count == 0) return;

                StringBuilder sb = new StringBuilder();
                sb.Append("UPDATE character_keymaps SET ");
                foreach (var kvp in modifieds)
                    sb.AppendFormat("map_{0}_type = {1}, map_{0}_value = {2},", kvp.Key, kvp.Value.Key, kvp.Value.Value);

                sb.Append(" WHERE character_id = " + pConnection.CharacterInternalID);

                MySQL_Connection.Instance.RunQuery(sb.ToString().Replace(", WHERE", " WHERE"));

            }
        }
Beispiel #20
0
        public void Decode(ClientConnection pConnection, MaplePacket pPacket)
        {
            if (pPacket.ReadBool())
            {
                for (short i = pPacket.ReadShort(); i > 0; i--)
                {
                    Skill skill = new Skill();
                    skill.ID         = pPacket.ReadInt();
                    skill.Level      = pPacket.ReadInt();
                    skill.Expiration = pPacket.ReadLong();

                    if (GameHelper.is_skill_need_master_level(skill.ID))
                    {
                        skill.MasterLevel = pPacket.ReadInt();
                    }
                    else
                    {
                        skill.MasterLevel = -1;
                    }

                    if (SkillList.ContainsKey(skill.ID)) // NEXON
                    {
                        pConnection.Logger_WriteLine("Found duplicate skill {0}", skill.ID);
                    }
                    else
                    {
                        SkillList.Add(skill.ID, skill);
                    }
                }

                // Link skills
                for (int i = pPacket.ReadShort(); i > 0; i--)
                {
                    pPacket.ReadInt();
                    pPacket.ReadShort();
                }
            }
            else
            {
                pConnection.Logger_WriteLine("Character has 'new' skilllist!");
                // 0.0
                for (short i = pPacket.ReadShort(); i > 0; i--)
                {
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                }

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

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

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

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

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

            short amnt = pPacket.ReadShort();

            for (short i = 0; i < amnt; i++)
            {
                Cooldowns.Add(pPacket.ReadInt(), pPacket.ReadInt());
            }
        }
Beispiel #21
0
        public static int AddOrUpdateCharacter(
            ClientConnection pConnection, int pID, string pName, int pUserID, byte pWorldID, byte pChannelID, byte pLevel,
            short pJob, short pStr, short pDex, short pInt, short pLuk,
            int pHP, int pMaxHP, int pMP, int pMaxMP, short pAP, short pSP,
            long pEXP, int pFame, int pMap, byte pMapPos,
            int pHonourLevel, int pHonourEXP, long pMesos, int pDemonMark,
            byte pGender, byte pSkin,
            int pEyes, int pHair,

            byte[] pSlots, string pBoF, string pBoE, string pUE,
            long[] pPetIDs, int[] pTraits,
            string pMarriedWith
            )
        {
            CharacterCacheInfo cci = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(pID, pWorldID);

            if (cci != null)
            {
                int internal_id = cci.InternalID;
                using (UpdateQueryBuilder query = new UpdateQueryBuilder("characters"))
                {
                    query.SetColumn("name", pName);
                    query.SetColumn("userid", pUserID);
                    query.SetColumn("world_id", pWorldID);
                    query.SetColumn("channel_id", pChannelID);
                    query.SetColumn("level", pLevel);
                    query.SetColumn("job", pJob);
                    query.SetColumn("str", pStr);
                    query.SetColumn("dex", pDex);
                    query.SetColumn("int", pInt);
                    query.SetColumn("luk", pLuk);
                    query.SetColumn("chp", pHP);
                    query.SetColumn("mhp", pMaxHP);
                    query.SetColumn("cmp", pMP);
                    query.SetColumn("mmp", pMaxMP);
                    query.SetColumn("ap", pAP);
                    query.SetColumn("sp", pSP);
                    query.SetColumn("exp", pEXP);
                    query.SetColumn("fame", pFame);
                    query.SetColumn("map", pMap);
                    query.SetColumn("pos", pMapPos);
                    query.SetColumn("gender", pGender);
                    query.SetColumn("skin", pSkin);
                    query.SetColumn("eyes", pEyes);
                    query.SetColumn("hair", pHair);
                    query.SetColumn("last_update", MySQL_Connection.NOW);

                    query.SetColumn("honourlevel", pHonourLevel);
                    query.SetColumn("honourexp", pHonourEXP);
                    query.SetColumn("mesos", pMesos);
                    query.SetColumn("demonmark", pDemonMark);

                    query.SetColumn("eqp_slots", pSlots[0]);
                    query.SetColumn("use_slots", pSlots[1]);
                    query.SetColumn("setup_slots", pSlots[2]);
                    query.SetColumn("etc_slots", pSlots[3]);
                    query.SetColumn("cash_slots", pSlots[4]);

                    query.SetColumn("blessingoffairy", pBoF);
                    query.SetColumn("blessingofempress", pBoE);
                    query.SetColumn("ultimateexplorer", pUE);

                    query.SetColumn("petcashid1", pPetIDs[0]);
                    query.SetColumn("petcashid2", pPetIDs[1]);
                    query.SetColumn("petcashid3", pPetIDs[2]);

                    query.SetColumn("trait_charisma", pTraits[0]);
                    query.SetColumn("trait_insight", pTraits[1]);
                    query.SetColumn("trait_willpower", pTraits[2]);
                    query.SetColumn("trait_craft_dili", pTraits[3]);
                    query.SetColumn("trait_empathy", pTraits[4]);
                    query.SetColumn("trait_charm", pTraits[5]);

                    query.SetColumn("married_with", pMarriedWith);

                    query.SetWhereColumn("internal_id", internal_id);

                    int result = query.RunQuery("sql_addorupdate.sql");

                    if (result >= 1)
                    {
                        //pConnection.Logger_WriteLine("Updated character info: {0}", internal_id);
                        return(cci.InternalID);
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Failed to update character info: " + query.ToString());
                    }
                }
            }
            else
            {
                using (InsertQueryBuilder query = new InsertQueryBuilder("characters"))
                {
                    query.OnDuplicateUpdate = false;
                    query.AddColumnWithValue("internal_id", null);

                    query.AddColumnWithValue("id", pID, false);
                    query.AddColumnWithValue("name", pName);
                    query.AddColumnWithValue("userid", pUserID);
                    query.AddColumnWithValue("world_id", pWorldID);
                    query.AddColumnWithValue("channel_id", pChannelID);
                    query.AddColumnWithValue("level", pLevel);
                    query.AddColumnWithValue("job", pJob);
                    query.AddColumnWithValue("str", pStr);
                    query.AddColumnWithValue("dex", pDex);
                    query.AddColumnWithValue("int", pInt);
                    query.AddColumnWithValue("luk", pLuk);
                    query.AddColumnWithValue("chp", pHP);
                    query.AddColumnWithValue("mhp", pMaxHP);
                    query.AddColumnWithValue("cmp", pMP);
                    query.AddColumnWithValue("mmp", pMaxMP);
                    query.AddColumnWithValue("ap", pAP);
                    query.AddColumnWithValue("sp", pSP);
                    query.AddColumnWithValue("exp", pEXP);
                    query.AddColumnWithValue("fame", pFame);
                    query.AddColumnWithValue("map", pMap);
                    query.AddColumnWithValue("pos", pMapPos);
                    query.AddColumnWithValue("gender", pGender);
                    query.AddColumnWithValue("skin", pSkin);
                    query.AddColumnWithValue("eyes", pEyes);
                    query.AddColumnWithValue("hair", pHair);
                    query.AddColumnWithValue("last_update", MySQL_Connection.NOW);

                    query.AddColumnWithValue("honourlevel", pHonourLevel);
                    query.AddColumnWithValue("honourexp", pHonourEXP);
                    query.AddColumnWithValue("mesos", pMesos);
                    query.AddColumnWithValue("demonmark", pDemonMark);

                    query.AddColumnWithValue("eqp_slots", pSlots[0]);
                    query.AddColumnWithValue("use_slots", pSlots[1]);
                    query.AddColumnWithValue("setup_slots", pSlots[2]);
                    query.AddColumnWithValue("etc_slots", pSlots[3]);
                    query.AddColumnWithValue("cash_slots", pSlots[4]);

                    query.AddColumnWithValue("blessingoffairy", pBoF);
                    query.AddColumnWithValue("blessingofempress", pBoE);
                    query.AddColumnWithValue("ultimateexplorer", pUE);


                    query.AddColumnWithValue("petcashid1", pPetIDs[0]);
                    query.AddColumnWithValue("petcashid2", pPetIDs[1]);
                    query.AddColumnWithValue("petcashid3", pPetIDs[2]);

                    query.AddColumnWithValue("trait_charisma", pTraits[0]);
                    query.AddColumnWithValue("trait_insight", pTraits[1]);
                    query.AddColumnWithValue("trait_willpower", pTraits[2]);
                    query.AddColumnWithValue("trait_craft_dili", pTraits[3]);
                    query.AddColumnWithValue("trait_empathy", pTraits[4]);
                    query.AddColumnWithValue("trait_charm", pTraits[5]);

                    query.AddColumnWithValue("married_with", pMarriedWith);

                    string q = query.ToString();

                    System.IO.File.WriteAllText("sql_addorupdate_insert.sql", q);

                    int result = (int)MySQL_Connection.Instance.RunQuery(q);

                    if (result >= 1)
                    {
                        int internalid = MySQL_Connection.Instance.GetLastInsertId();
                        pConnection.Logger_WriteLine("Inserted character info: {0}", internalid);
                        return(internalid);
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Failed to insert character info: " + q);
                    }
                }
            }

            Logger.WriteLine("ERROR WHILE ADDING OR UPDATING CHARACTER");

            return(-1);
        }
        public virtual void HandleSkillUpdate(ClientConnection pConnection, MaplePacket pPacket)
        {
            pPacket.ReadByte(); // Unstuck
            pPacket.ReadByte();
            ushort amount = pPacket.ReadUShort();

            using (InsertQueryBuilder skillTable = new InsertQueryBuilder("skills"))
            {
                skillTable.OnDuplicateUpdate = true;
                skillTable.AddColumn("character_id", false);
                skillTable.AddColumn("skillid", false);
                skillTable.AddColumn("level", true);
                skillTable.AddColumn("maxlevel", true);
                skillTable.AddColumn("expires", true);

                for (ushort i = 0; i < amount; i++)
                {
                    int skillid = pPacket.ReadInt();
                    int level = pPacket.ReadInt();
                    int masterlevel = pPacket.ReadInt();
                    long expiration = pPacket.ReadLong();

                    Timeline.Instance.PushSkillUP(pConnection, skillid, level);

                    skillTable.AddRow(pConnection.CharacterInternalID, skillid, level, masterlevel == 0 ? null : (object)masterlevel, expiration);
                }

                if (skillTable.RowCount > 0)
                {
                    string q = skillTable.ToString();
                    System.IO.File.WriteAllText("insert-update-skills-packet.sql", q);
                    int result = (int)MySQL_Connection.Instance.RunQuery(q);
                    pConnection.Logger_WriteLine("Result Skills: {0}", result);

                    pConnection.SendTimeUpdate();
                }

            }
        }
        public virtual void HandleStatUpdate(ClientConnection pConnection, MaplePacket pPacket)
        {
            pPacket.ReadByte();
            long updateFlag = pPacket.ReadLong();
            if (updateFlag == 0) return; // Fake Update -.- / Unstuck

            bool didsomething = false;

            if (CheckFlag(updateFlag, 1)) // Skin
            {
                didsomething = true;
                pConnection.CharData.Stats.Skin = pPacket.ReadByte();
            }
            if (CheckFlag(updateFlag, 2)) // Eyes
            {
                didsomething = true;
                pConnection.CharData.Stats.Face = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 4)) // Eyes
            {
                didsomething = true;
                pConnection.CharData.Stats.Hair = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 8))
            {
                didsomething = true;
                pConnection.CharData.Stats.Pets[0] = pPacket.ReadLong();
            }
            if (CheckFlag(updateFlag, 0x80000))
            {
                var value = pPacket.ReadLong();
                pConnection.Logger_WriteLine("0x80000 | {0}", value);
            }
            if (CheckFlag(updateFlag, 0x100000))
            {
                var value = pPacket.ReadLong();
                pConnection.Logger_WriteLine("0x100000 | {0}", value);
            }
            if (CheckFlag(updateFlag, 0x10))
            {
                didsomething = true;
                var level = pPacket.ReadByte();
                Timeline.Instance.PushLevelUP(pConnection, level);
                pConnection.CharData.Stats.Level = level;
                pConnection.Logger_WriteLine("{0} leveled up to level {1}!!!", pConnection.CharData.Stats.Name, level);
            }
            if (CheckFlag(updateFlag, 0x20))
            {
                didsomething = true;
                var jobid = pPacket.ReadShort();
                Timeline.Instance.PushJobUP(pConnection, (ushort)jobid);
                pConnection.CharData.Stats.JobID = jobid;
                pConnection.Logger_WriteLine("{0} changed to job {1}!!!", pConnection.CharData.Stats.Name, jobid);
            }
            if (CheckFlag(updateFlag, 0x40))
            {
                didsomething = true;
                pConnection.CharData.Stats.Str = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x80))
            {
                didsomething = true;
                pConnection.CharData.Stats.Dex = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x100))
            {
                didsomething = true;
                pConnection.CharData.Stats.Int = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x200))
            {
                didsomething = true;
                pConnection.CharData.Stats.Luk = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x400))
            {
                didsomething = true;
                pConnection.CharData.Stats.HP = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 0x800))
            {
                didsomething = true;
                pConnection.CharData.Stats.MaxHP = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 0x1000))
            {
                didsomething = true;
                pConnection.CharData.Stats.MP = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 0x2000))
            {
                didsomething = true;
                pConnection.CharData.Stats.MaxMP = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 0x4000))
            {
                didsomething = true;
                pConnection.CharData.Stats.AP = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x8000))
            {
                didsomething = true;

                short a1 = pConnection.CharData.Stats.JobID;
                pConnection.CharData.Stats.SPData.Clear();

                if (GameHelper.IsExtendedSPJob(pConnection.CharData.Stats.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
                        pConnection.CharData.Stats.SPData.Add(new KeyValuePair<byte, int>(v1, v2));

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

                }
                else
                {
                    pConnection.CharData.Stats.SPData.Add(new KeyValuePair<byte, int>(0, pPacket.ReadShort()));
                }
            }

            if (CheckFlag(updateFlag, 0x10000))
            {
                didsomething = true;
                long newexp = pPacket.ReadLong();
                byte point = (byte)EXPTable.GetLevelPercentage(pConnection.CharData.Stats.Level, newexp);

                if (pConnection.LastExpPoint != point)
                {
                    // Ohhh
                    Timeline.Instance.PushExpPoint(pConnection, point);
                }

                pConnection.CharData.Stats.EXP = newexp;
                pConnection.LastExpPoint = point;

            }

            if (CheckFlag(updateFlag, 0x20000))
            {
                didsomething = true;
                int fame = pPacket.ReadInt();
                Timeline.Instance.PushGotFame(pConnection, fame - pConnection.CharData.Stats.Fame, fame);
                pConnection.CharData.Stats.Fame = fame;
            }

            if (CheckFlag(updateFlag, 0x40000))
            {
                didsomething = true;
                pConnection.CharData.Stats.Mesos = pPacket.ReadLong();
            }
            if (CheckFlag(updateFlag, 0x200000))
            {
                var value = pPacket.ReadInt();
                pConnection.Logger_WriteLine("0x200000 | {0}", value);
            }

            if (CheckFlag(updateFlag, 0x400000))
            {
                var value = pPacket.ReadByte();
                pConnection.Logger_WriteLine("0x400000 | {0}", value);
            }

            if (CheckFlag(updateFlag, 0x800000))
            {
                // Ambition/Charisma D:
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Charisma] = pPacket.ReadInt();
            }

            if (CheckFlag(updateFlag, 0x1000000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Insight] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x2000000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Willpower] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x4000000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.CraftDiligence] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x8000000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Empathy] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x10000000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Charm] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x20000000))
            {
                pPacket.ReadBytes(21);
            }

            if (CheckFlag(updateFlag, 0x40000000))
            {
                pPacket.ReadByte();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadByte();
            }

            if (CheckFlag(updateFlag, 0x80000000))
            {
                for (byte i = 0; i < 9; i++)
                {
                    pPacket.ReadInt();
                    pPacket.ReadByte();
                    pPacket.ReadInt();
                }
            }

            if (CheckFlag(updateFlag, 0x100000000))
            {
                var value1 = pPacket.ReadByte();
                var value2 = pPacket.ReadByte();
                pConnection.Logger_WriteLine("0x100000000 | {0} | {1}", value1, value2);
            }

            if (CheckFlag(updateFlag, 0x200000000))
            {
                var value = pPacket.ReadInt();
                pConnection.Logger_WriteLine("0x200000000 | {0}", value);
            }

            if (didsomething)
            {
                pConnection.CharData.SaveCharacterInfo(pConnection);

                pConnection.SendTimeUpdate();
            }
        }
Beispiel #24
0
 private static long FlaggedValue(ClientConnection pConnection, int pItemID, uint pValue, uint pFlag, MaplePacket pPacket, long pTypeValue, bool pLogIfFound = false)
 {
     if (pValue.HasFlag(pFlag))
     {
         var val = pPacket.ReadLong();
         if (pLogIfFound)
             pConnection.Logger_WriteLine("Found flag {3} {0:X8}: {1} | ItemID: {2}", pFlag, val, pItemID, pTypeValue.GetType().Name);
         return val;
     }
     else
         return 0;
 }
        protected void ParseLogin(ClientConnection pConnection, int pUserID, string pUsername, DateTime pCreationDate)
        {
            pConnection.Logger_WriteLine("User logged into Nexon account '{1}', userid {0}", pUserID, pUsername);

            if (AccountDataCache.Instance.KnownUserlist.ContainsKey(pUserID))
            {
                int tmp = AccountDataCache.Instance.KnownUserlist[pUserID];
                if (tmp == 2)
                {
                    pConnection.Logger_WriteLine("User bound to temporary account. Allocating current account to it.");

                    using (UpdateQueryBuilder q = new UpdateQueryBuilder("users"))
                    {
                        q.SetColumn("account_id", pConnection.AccountID);
                        q.SetColumn("last_check", MySQL_Connection.NOW);
                        q.SetColumn("creation_date", pCreationDate);
                        q.SetWhereColumn("ID", pUserID);
                        q.RunQuery();
                    }

                    AccountDataCache.Instance.KnownUserlist[pUserID] = pConnection.AccountID;
                    pConnection.UserID = pUserID;
                }
                else if (tmp == pConnection.AccountID)
                {
                    // Correct account, continue
                    pConnection.Logger_WriteLine("User bound to same account. kay");

                    using (UpdateQueryBuilder q = new UpdateQueryBuilder("users"))
                    {
                        q.SetColumn("last_check", MySQL_Connection.NOW);
                        q.SetWhereColumn("ID", pUserID);
                        q.RunQuery();
                    }

                    pConnection.UserID = pUserID;
                }
                else
                {
                    pConnection.Logger_WriteLine("User ID not bound to this account!!! Ignoring...");
                    pConnection.SendInfoText("WARNING: This Nexon account ({0}) is not yours! Please login into the correct Mapler.me account.", pUsername);
                    return;
                }
            }
            else
            {
                pConnection.Logger_WriteLine("Creating user for accountID {0}", pConnection.AccountID);

                using (InsertQueryBuilder insertq = new InsertQueryBuilder("users"))
                {
                    insertq.OnDuplicateUpdate = true;

                    insertq.AddColumn("account_id");
                    insertq.AddColumn("ID");
                    insertq.AddColumn("creation_date");
                    insertq.AddColumn("last_check", true);
                    insertq.AddColumn("maplepoints");

                    insertq.AddRow(pConnection.AccountID, pUserID, pCreationDate, MySQL_Connection.NOW, 0);
                    insertq.RunQuery();
                }

                pConnection.UserID = pUserID;
                AccountDataCache.Instance.KnownUserlist.Add(pUserID, pConnection.AccountID);
            }


            pConnection.SendInfoText("Identified account {0}. You can now select your character.", pUsername);

            if (pConnection.LogFilename == "Unknown")
                pConnection.LogFilename = "";
            else
                pConnection.LogFilename += "_";
            pConnection.LogFilename += pConnection.AccountID.ToString();

            // Save IP of loginserver
            if (pConnection.ConnectedToIP != null)
                Queries.SaveServerIP(pConnection.ConnectedToIP, pConnection.ConnectedToPort, 0, 0);
        }
 public virtual void HandleAlliance(ClientConnection pConnection, MaplePacket pPacket)
 {
     byte type = pPacket.ReadByte();
     if (type == 0x0C)
     {
         bool hasAlliance = pPacket.ReadBool();
         if (hasAlliance)
         {
             Alliance alliance = new Alliance();
             alliance.Decode(pPacket);
             alliance.Save(pConnection.WorldID);
             pConnection.Logger_WriteLine("{0} must be in Alliance {1}", pConnection.LastLoggedCharacterName, alliance.Name);
         }
     }
     else if (type == 0x0D)
     {
         Alliance.DecodeGuilds(pPacket, pConnection.WorldID);
     }
 }
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 override void HandleStatUpdate(ClientConnection pConnection, MaplePacket pPacket)
        {
            pPacket.ReadByte();
            long updateFlag = pPacket.ReadLong();

            if (updateFlag == 0)
            {
                return;                  // Fake Update -.- / Unstuck
            }
            bool didsomething = false;

            if (CheckFlag(updateFlag, 1)) // Skin
            {
                didsomething = true;
                pConnection.CharData.Stats.Skin = pPacket.ReadByte();
            }
            if (CheckFlag(updateFlag, 2)) // Eyes
            {
                didsomething = true;
                pConnection.CharData.Stats.Face = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 4)) // Eyes
            {
                didsomething = true;
                pConnection.CharData.Stats.Hair = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 0x10))
            {
                didsomething = true;
                var level = pPacket.ReadByte();
                Timeline.Instance.PushLevelUP(pConnection, level);
                pConnection.CharData.Stats.Level = level;
                pConnection.Logger_WriteLine("{0} leveled up to level {1}!!!", pConnection.CharData.Stats.Name, level);
            }
            if (CheckFlag(updateFlag, 0x20))
            {
                didsomething = true;
                var jobid = pPacket.ReadShort();
                Timeline.Instance.PushJobUP(pConnection, (ushort)jobid);
                pConnection.CharData.Stats.JobID = jobid;
                pConnection.Logger_WriteLine("{0} changed to job {1}!!!", pConnection.CharData.Stats.Name, jobid);
            }
            if (CheckFlag(updateFlag, 0x40))
            {
                didsomething = true;
                pConnection.CharData.Stats.Str = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x80))
            {
                didsomething = true;
                pConnection.CharData.Stats.Dex = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x100))
            {
                didsomething = true;
                pConnection.CharData.Stats.Int = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x200))
            {
                didsomething = true;
                pConnection.CharData.Stats.Luk = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x400))
            {
                didsomething = true;
                pConnection.CharData.Stats.HP = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 0x800))
            {
                didsomething = true;
                pConnection.CharData.Stats.MaxHP = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 0x1000))
            {
                didsomething = true;
                pConnection.CharData.Stats.MP = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 0x2000))
            {
                didsomething = true;
                pConnection.CharData.Stats.MaxMP = pPacket.ReadInt();
            }
            if (CheckFlag(updateFlag, 0x4000))
            {
                didsomething = true;
                pConnection.CharData.Stats.AP = pPacket.ReadShort();
            }
            if (CheckFlag(updateFlag, 0x8000))
            {
                didsomething = true;

                short a1 = pConnection.CharData.Stats.JobID;
                pConnection.CharData.Stats.SPData.Clear();

                if (GameHelper.IsExtendedSPJob(pConnection.CharData.Stats.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
                        pConnection.CharData.Stats.SPData.Add(new KeyValuePair <byte, int>(v1, v2));

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

            if (CheckFlag(updateFlag, 0x10000))
            {
                didsomething = true;
                long newexp = pPacket.ReadLong();
                byte point  = (byte)EXPTable.GetLevelPercentage(pConnection.CharData.Stats.Level, newexp);

                if (pConnection.LastExpPoint != point)
                {
                    // Ohhh
                    Timeline.Instance.PushExpPoint(pConnection, point);
                }

                pConnection.CharData.Stats.EXP = newexp;
                pConnection.LastExpPoint       = point;
            }

            if (CheckFlag(updateFlag, 0x20000))
            {
                didsomething = true;
                int fame = pPacket.ReadInt();
                Timeline.Instance.PushGotFame(pConnection, fame - pConnection.CharData.Stats.Fame, fame);
                pConnection.CharData.Stats.Fame = fame;
            }

            if (CheckFlag(updateFlag, 0x40000))
            {
                didsomething = true;
                pConnection.CharData.Stats.Mesos = pPacket.ReadLong();
            }
            // EMS Weird stuff
            if (CheckFlag(updateFlag, 0x80000))
            {
                var value = pPacket.ReadLong();
                pConnection.Logger_WriteLine("0x80000 | {0}", value);
            }
            if (CheckFlag(updateFlag, 0x100000))
            {
                var value = pPacket.ReadByte();
                pConnection.Logger_WriteLine("0x100000 | {0}", value);
            }

            if (CheckFlag(updateFlag, 0x200000))
            {
                // Ambition/Charisma D:
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Charisma] = pPacket.ReadInt();
            }

            if (CheckFlag(updateFlag, 0x400000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Insight] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x800000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Willpower] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x1000000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.CraftDiligence] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x2000000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Empathy] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x4000000))
            {
                pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Charm] = pPacket.ReadInt();
                didsomething = true;
            }

            if (CheckFlag(updateFlag, 0x8000000))
            {
                pPacket.ReadBytes(21);
            }

            if (CheckFlag(updateFlag, 0x10000000))
            {
                pPacket.ReadByte();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadInt();
                pPacket.ReadByte();
            }

            if (CheckFlag(updateFlag, 0x20000000))
            {
                for (byte i = 0; i < 9; i++)
                {
                    pPacket.ReadInt();
                    pPacket.ReadByte();
                    pPacket.ReadInt();
                }
            }

            if (CheckFlag(updateFlag, 0x40000000))
            {
                var value1 = pPacket.ReadInt();
                var value2 = pPacket.ReadByte();
                var value3 = pPacket.ReadInt();
                pConnection.Logger_WriteLine("0x40000000 | {0} | {1} | {2}", value1, value2, value3);
            }

            if (CheckFlag(updateFlag, 0x80000000))
            {
                var value1 = pPacket.ReadByte();
                var value2 = pPacket.ReadByte();
                pConnection.Logger_WriteLine("0x80000000 | {0} | {1}", value1, value2);
            }

            if (CheckFlag(updateFlag, 0x100000000))
            {
                var value = pPacket.ReadInt();
                pConnection.Logger_WriteLine("0x100000000 | {0}", value);
            }

            if (CheckFlag(updateFlag, 0x200000000))
            {
                var value = pPacket.ReadInt();
                pConnection.Logger_WriteLine("0x200000000 | {0}", value);
            }

            if (didsomething)
            {
                pConnection.CharData.SaveCharacterInfo(pConnection);

                pConnection.SendTimeUpdate();
            }
        }
Beispiel #29
0
        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 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 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();
        }
        public virtual void HandleKeymap(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte mode = pPacket.ReadByte();
            if (mode == 0)
            {
                // Keymap
                if (pPacket.Length - pPacket.Position != (1 + 4) * ServerMapleInfo.KEYMAP_SLOTS)
                {
                    pConnection.Logger_ErrorLog("Keymap size not correct. {0} != {1}", pPacket.Length - pPacket.Position, (1 + 4) * ServerMapleInfo.KEYMAP_SLOTS);
                    return;
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("DELETE FROM character_keymaps WHERE character_id = " + pConnection.CharacterInternalID + ";");
                sb.Append("INSERT INTO character_keymaps VALUES (" + pConnection.CharacterInternalID);
                for (int i = 0; i < ServerMapleInfo.KEYMAP_SLOTS; i++)
                    sb.Append("," + pPacket.ReadByte() + "," + pPacket.ReadInt());

                sb.Append(");");

                MySQL_Connection.Instance.RunQuery(sb.ToString());

                pConnection.Logger_WriteLine("Saved keymap!");
            }
        }
        public virtual void HandleCharacterDeletion(ClientConnection pConnection, MaplePacket pPacket)
        {
            int id = pPacket.ReadInt();
            bool notok = pPacket.ReadBool();

            if (!notok && pConnection.UserID != -1)
            {
                pConnection.Logger_WriteLine("Deleting character with ID {0}", id);

                // Oh jolly...
                // *crosses fingers*

                // Delete from local cache
                int internalid = 0;
                if (AccountDataCache.Instance.DeleteCharacterInfo(id, pConnection.WorldID, pConnection.AccountID, out internalid))
                {

                    MySQL_Connection.Instance.RunQuery("DELETE FROM characters WHERE internal_id = " + internalid);
                }
                else
                {
                    Logger.WriteLine("Failed to delete character. Invalid accountid, worldid, characterid or maybe not stored?");
                }
            }
            else
            {
                pConnection.Logger_WriteLine("Account failed deleting ID {0}", id);
            }
        }
Beispiel #34
0
        public bool SaveData(ClientConnection pConnection)
        {
            int internalid = pConnection.CharacterInternalID = SaveCharacterInfo(pConnection);

            if (internalid == -1)
            {
                // Failure!
                return(false);
            }

            using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items"))
                using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets"))
                {
                    var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(Stats.ID, pConnection.WorldID);

                    if (info != null)
                    {
                        // Update info!
                        pConnection.CharacterID = Stats.ID;

                        CharacterInventory inventory = Inventory;

                        for (byte i = 0; i < Inventory.EquipmentItems.Length; i++)
                        {
                            var equips = Inventory.EquipmentItems[i];
                            foreach (var equipdata in equips)
                            {
                                short slot   = equipdata.Key;
                                var   equip  = equipdata.Value;
                                bool  addrow = false;

                                if (info.SlotHashes.ContainsKey(0) && info.SlotHashes[0].ContainsKey(slot))
                                {
                                    int hash    = info.SlotHashes[0][slot];
                                    int objhash = equipdata.Value.GetChecksum();
                                    if (hash != objhash)
                                    {
                                        pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                        addrow = true;
                                    }

                                    info.SlotHashes[0].Remove(slot);
                                }
                                else
                                {
                                    addrow = true;
                                }

                                if (addrow)
                                {
                                    Queries.SaveItem(pConnection, 0, slot, equip, itemsTable, true);
                                }
                            }
                        }

                        pConnection.Logger_WriteLine("Done equips");

                        for (int i = 0; i < Inventory.InventoryItems.Length; i++)
                        {
                            var items = Inventory.InventoryItems[i];
                            foreach (var itemdata in items)
                            {
                                var  item   = itemdata.Value;
                                bool addrow = false;
                                if (info.SlotHashes.ContainsKey(i + 1) && info.SlotHashes[i + 1].ContainsKey(itemdata.Key))
                                {
                                    int hash    = info.SlotHashes[i + 1][itemdata.Key];
                                    int objhash = itemdata.Value.GetChecksum();
                                    if (hash != objhash)
                                    {
                                        pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                        addrow = true;
                                    }


                                    info.SlotHashes[i + 1].Remove(itemdata.Key);
                                }
                                else
                                {
                                    addrow = true;
                                }

                                if (addrow)
                                {
                                    Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true);

                                    if (item is ItemPet)
                                    {
                                        Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                    }
                                }
                            }
                        }
                        pConnection.Logger_WriteLine("Done items");

                        foreach (var bag in Inventory.BagItems)
                        {
                            ushort i = (ushort)bag.Key;
                            foreach (var itemdata in bag.Value.Items)
                            {
                                var  item   = itemdata.Value;
                                bool addrow = false;
                                if (info.SlotHashes.ContainsKey(i) && info.SlotHashes[i].ContainsKey(itemdata.Key))
                                {
                                    int hash    = info.SlotHashes[i][itemdata.Key];
                                    int objhash = itemdata.Value.GetChecksum();
                                    if (hash != objhash)
                                    {
                                        pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                        addrow = true;
                                    }


                                    info.SlotHashes[i].Remove(itemdata.Key);
                                }
                                else
                                {
                                    addrow = true;
                                }

                                if (addrow)
                                {
                                    Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true);

                                    if (item is ItemPet)
                                    {
                                        Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                    }
                                }
                            }
                        }

                        pConnection.Logger_WriteLine("Done bag items");

                        {
                            string removequery = "";
                            bool   added       = false;
                            foreach (var hashlist in info.SlotHashes)
                            {
                                foreach (var leftovers in hashlist.Value)
                                {
                                    pConnection.Logger_WriteLine("Deleting item @ inv {0} slot {1}", hashlist.Key, leftovers.Key);
                                    added        = true;
                                    removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", hashlist.Key, leftovers.Key, internalid);
                                }
                            }
                            if (added)
                            {
                                System.IO.File.WriteAllText("removequery.sql", removequery);
                                MySQL_Connection.Instance.RunQuery(removequery);
                            }
                        }
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Saving Items");

                        pConnection.CharacterInternalID = internalid;
                        pConnection.CharacterID         = Stats.ID;

                        string itemlist = "";
                        itemlist += "INSERT INTO items VALUES ";
                        List <string> querylist = new List <string>();
                        for (byte i = 0; i < Inventory.EquipmentItems.Length; i++)
                        {
                            var equips = Inventory.EquipmentItems[i];
                            foreach (var equipdata in equips)
                            {
                                var equip = equipdata.Value;
                                Queries.SaveItem(pConnection, 0, equipdata.Key, equip, itemsTable, true);
                            }
                        }

                        pConnection.Logger_WriteLine("Done equips");

                        for (int i = 0; i < Inventory.InventoryItems.Length; i++)
                        {
                            var items = Inventory.InventoryItems[i];
                            foreach (var itemdata in items)
                            {
                                var item = itemdata.Value;

                                Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true);

                                if (item is ItemPet)
                                {
                                    Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                }
                            }
                        }

                        pConnection.Logger_WriteLine("Done items");

                        foreach (var bag in Inventory.BagItems)
                        {
                            ushort i = (ushort)(bag.Key);
                            foreach (var itemdata in bag.Value.Items)
                            {
                                var item = itemdata.Value;
                                Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true);

                                if (item is ItemPet)
                                {
                                    Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                }
                            }
                        }

                        pConnection.Logger_WriteLine("Done bag items");

                        AccountDataCache.Instance.LoadBaseData(Stats.Name);
                    }

                    itemsTable.RunQuery();

                    pConnection.Logger_WriteLine("Saved item data");

                    petTable.RunQuery();

                    pConnection.Logger_WriteLine("Saved pet data");


                    AccountDataCache.Instance.LoadInventoryHashes(internalid, true);



                    MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running WHERE character_id = " + internalid);
                    using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running"))
                    {
                        questsTable.OnDuplicateUpdate = true;
                        questsTable.AddColumn("character_id", false);
                        questsTable.AddColumn("questid", true);
                        questsTable.AddColumn("data", true);

                        foreach (var quest in Quests.Running)
                        {
                            questsTable.AddRow(internalid, quest.Key, quest.Value);
                        }

                        questsTable.RunQuery("insert-update-quests.sql");
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done WHERE character_id = " + internalid);
                    using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done"))
                    {
                        doneTable.AddColumn("character_id", false);
                        doneTable.AddColumn("questid", false);
                        doneTable.AddColumn("time", false);

                        foreach (var quest in Quests.Done)
                        {
                            doneTable.AddRow(internalid, quest.Key, quest.Value);
                        }

                        doneTable.RunQuery("insert-update-quests-done.sql");
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running_party WHERE character_id = " + internalid);
                    using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running_party"))
                    {
                        questsTable.OnDuplicateUpdate = true;
                        questsTable.AddColumn("character_id", false);
                        questsTable.AddColumn("questid", true);
                        questsTable.AddColumn("data", true);

                        foreach (var quest in Quests.PartyQuestsRunning)
                        {
                            questsTable.AddRow(internalid, quest.Key, quest.Value);
                        }

                        questsTable.RunQuery();
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done_party WHERE character_id = " + internalid);
                    using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done_party"))
                    {
                        doneTable.AddColumn("character_id", false);
                        doneTable.AddColumn("questid", false);
                        doneTable.AddColumn("time", false);

                        foreach (var quest in Quests.PartyQuestsDone)
                        {
                            doneTable.AddRow(internalid, quest.Key, quest.Value);
                        }

                        doneTable.RunQuery();
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM skills WHERE character_id = " + internalid);
                    using (InsertQueryBuilder skillTable = new InsertQueryBuilder("skills"))
                    {
                        skillTable.OnDuplicateUpdate = true;
                        skillTable.AddColumn("character_id", false);
                        skillTable.AddColumn("skillid", false);
                        skillTable.AddColumn("level", true);
                        skillTable.AddColumn("maxlevel", true);
                        skillTable.AddColumn("expires", true);

                        foreach (var skill in Skills.SkillList)
                        {
                            skillTable.AddRow(internalid, skill.Key, skill.Value.Level, skill.Value.MasterLevel != -1 ? (object)skill.Value.MasterLevel : null, skill.Value.Expiration);
                        }

                        skillTable.RunQuery();
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM sp_data WHERE character_id = " + internalid);
                    using (InsertQueryBuilder spTable = new InsertQueryBuilder("sp_data"))
                    {
                        spTable.OnDuplicateUpdate = true;
                        spTable.AddColumn("character_id", false);
                        spTable.AddColumn("slot", false);
                        spTable.AddColumn("amount", true);

                        foreach (var kvp in Stats.SPData)
                        {
                            spTable.AddRow(internalid, kvp.Key, kvp.Value);
                        }

                        spTable.RunQuery();
                    }

                    using (InsertQueryBuilder teleportRocks = new InsertQueryBuilder("teleport_rock_locations"))
                    {
                        teleportRocks.OnDuplicateUpdate = true;

                        teleportRocks.AddColumn("character_id");
                        for (int i = 0; i < 41; i++)
                        {
                            teleportRocks.AddColumn("map" + i, true);
                        }

                        teleportRocks.AddRowUnsafe(
                            pConnection.CharacterInternalID,
                            Inventory.TeleportRocks.ToList()
                            );

                        teleportRocks.RunQuery();
                    }

                    MySQL_Connection.Instance.RunQuery("DELETE FROM evolution_levels WHERE character_id = " + internalid);
                    using (InsertQueryBuilder table = new InsertQueryBuilder("evolution_levels"))
                    {
                        table.AddColumn("character_id");
                        table.AddColumn("block");
                        table.AddColumn("index");
                        table.AddColumn("card", true);
                        table.AddColumn("level", true);

                        foreach (var card in EvolutionCards)
                        {
                            table.AddRow(
                                pConnection.CharacterInternalID,
                                card.Block,
                                card.ID,
                                card.ItemID,
                                card.Level
                                );
                        }

                        table.RunQuery();
                    }


                    MySQL_Connection.Instance.RunQuery("DELETE FROM character_rings WHERE character_id = " + pConnection.CharacterInternalID);
                    using (InsertQueryBuilder table = new InsertQueryBuilder("character_rings"))
                    {
                        table.AddColumn("character_id");
                        table.AddColumn("friend_name");
                        table.AddColumn("cashid1");
                        table.AddColumn("cashid2");
                        table.AddColumn("type");

                        foreach (var ring in Rings)
                        {
                            string type = "";
                            switch (ring.RingType)
                            {
                            case Ring.Type.Couple: type = "couple"; break;

                            case Ring.Type.Marriage: type = "marriage"; break;

                            case Ring.Type.Friend: type = "friend"; break;
                            }

                            table.AddRow(
                                pConnection.CharacterInternalID,
                                ring.FriendName,
                                ring.RingCashID1,
                                ring.RingCashID1,
                                type
                                );
                        }

                        table.RunQuery();
                    }


                    MySQL_Connection.Instance.RunQuery("DELETE FROM character_abilities WHERE character_id = " + pConnection.CharacterInternalID);
                    using (InsertQueryBuilder table = new InsertQueryBuilder("character_abilities"))
                    {
                        table.AddColumn("character_id");
                        table.AddColumn("id");
                        table.AddColumn("skill_id");
                        table.AddColumn("level");

                        foreach (var stat in Abilities)
                        {
                            table.AddRow(
                                pConnection.CharacterInternalID,
                                stat.Item1,
                                stat.Item2,
                                stat.Item3
                                );
                        }

                        table.RunQuery();
                    }

                    return(true);
                }
        }
        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 HandleInventoryUpdate(ClientConnection pConnection, MaplePacket pPacket)
        {
            CharacterInventory inventory = pConnection.CharData.Inventory;

            byte type1 = pPacket.ReadByte();
            byte items = pPacket.ReadByte();
            byte type3 = pPacket.ReadByte();
            if (type3 == 0) // Add or update item
            {
                for (var amnt = 0; amnt < items; amnt++)
                {
                    byte type4 = pPacket.ReadByte();
                    byte inv = pPacket.ReadByte();
                    short slot = pPacket.ReadShort();
                    inv -= 1;

                    if (type4 == 0) // New Item
                    {

                        ItemBase item = ItemBase.DecodeItemData(pConnection, pPacket);

                        if (inv == 0)
                        {
                            // Equip
                            byte internalInventory = CharacterInventory.GetEquipInventoryFromSlot(slot);
                            slot = CharacterInventory.CorrectEquipSlot(internalInventory, slot);

                            if (!inventory.EquipmentItems[internalInventory].ContainsKey(slot))
                                inventory.EquipmentItems[internalInventory].Add(slot, item as ItemEquip);
                            else
                                inventory.EquipmentItems[internalInventory][slot] = item as ItemEquip;
                        }
                        else
                        {
                            if (!inventory.InventoryItems[inv - 1].ContainsKey((byte)slot))
                                inventory.InventoryItems[inv - 1].Add((byte)slot, item);
                            else
                                inventory.InventoryItems[inv - 1][(byte)slot] = item;
                        }

                        using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items"))
                        {
                            itemsTable.OnDuplicateUpdate = true;
                            Queries.SaveItem(pConnection, inv, slot, item, itemsTable);
                            itemsTable.RunQuery();

                        }

                        if (item is ItemPet)
                        {
                            var pet = item as ItemPet;
                            using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets"))
                            {
                                petTable.OnDuplicateUpdate = true;
                                Queries.SavePet(pConnection.CharacterInternalID, pet, petTable);
                                petTable.RunQuery();
                            }
                        }

                    }
                    else if (type4 == 1) // Update amount
                    {
                        short amount = pPacket.ReadShort();
                        if (inv == 0)
                        {
                            pConnection.Logger_WriteLine("WUTWUT"); // Should _never_ happen
                            continue;
                        }

                        ItemBase item = inventory.InventoryItems[inv - 1][(byte)slot];
                        item.Amount = amount;

                        AccountDataCache.Instance.SetChecksumOfSlot(pConnection.CharacterID, pConnection.WorldID, inv, slot, item.GetChecksum());

                        using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                        {
                            itemTable.SetColumn("amount", amount);
                            itemTable.SetColumn("checksum", item.GetChecksum());
                            itemTable.SetWhereColumn("inventory", inv);
                            itemTable.SetWhereColumn("slot", slot);
                            itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                            MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                        }


                    }
                    else if (type4 == 2) // Swap
                    {
                        short slotfrom = slot;
                        short slotto = pPacket.ReadShort();

                        bool founditem = false;

                        if (inv == 0)
                        {
                            // Equips!
                            byte internalInventoryFrom = CharacterInventory.GetEquipInventoryFromSlot(slotfrom);
                            byte internalInventoryTo = CharacterInventory.GetEquipInventoryFromSlot(slotto);
                            slotfrom = CharacterInventory.CorrectEquipSlot(internalInventoryFrom, slotfrom);
                            slotto = CharacterInventory.CorrectEquipSlot(internalInventoryTo, slotto);

                            // Switch Equips
                            ItemEquip item = inventory.EquipmentItems[internalInventoryFrom][slotfrom];
                            if (inventory.EquipmentItems[internalInventoryTo].ContainsKey(slotto))
                            {
                                inventory.EquipmentItems[internalInventoryFrom][slotfrom] =
                                    inventory.EquipmentItems[internalInventoryTo][slotto];

                                inventory.EquipmentItems[internalInventoryTo].Remove(slotto); // Remove item
                                founditem = true;
                            }
                            else
                            {
                                inventory.EquipmentItems[internalInventoryFrom].Remove(slotfrom);
                            }
                            inventory.EquipmentItems[internalInventoryTo].Add(slotto, item);
                        }
                        else
                        {
                            // Switch Items
                            ItemBase item = inventory.InventoryItems[inv - 1][(byte)slotfrom];
                            if (inventory.InventoryItems[inv - 1].ContainsKey((byte)slotto))
                            {
                                inventory.InventoryItems[inv - 1][(byte)slotfrom] =
                                    inventory.InventoryItems[inv - 1][(byte)slotto];
                                inventory.InventoryItems[inv - 1].Remove((byte)slotto); // Remove item
                                founditem = true;
                            }
                            else
                            {
                                inventory.InventoryItems[inv - 1].Remove((byte)slotfrom);
                            }
                            inventory.InventoryItems[inv - 1].Add((byte)slotto, item);
                        }

                        if (founditem) // New slot contained item
                        {
                            using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                            {
                                itemTable.SetColumn("slot", slotfrom + 3000);
                                itemTable.SetWhereColumn("inventory", inv);
                                itemTable.SetWhereColumn("slot", slotto);
                                itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                                MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                            }
                        }

                        using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                        {
                            itemTable.SetColumn("slot", slotto);
                            itemTable.SetWhereColumn("inventory", inv);
                            itemTable.SetWhereColumn("slot", slotfrom);
                            itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                            MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                        }

                        if (founditem) // Fix other slot
                        {
                            using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                            {
                                itemTable.SetColumn("slot", slotfrom);
                                itemTable.SetWhereColumn("inventory", inv);
                                itemTable.SetWhereColumn("slot", slotfrom + 3000);
                                itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                                MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                            }
                        }
                    }
                    else if (type4 == 3)
                    {
                        // Drop/delete item.

                        if (inv == 0)
                        {
                            // Equips!
                            byte internalInventory = CharacterInventory.GetEquipInventoryFromSlot(slot);
                            slot = CharacterInventory.CorrectEquipSlot(internalInventory, slot);

                            if (inventory.EquipmentItems[internalInventory].ContainsKey(slot))
                            {
                                inventory.EquipmentItems[internalInventory].Remove(slot);
                                AccountDataCache.Instance.DeleteItemChecksum(pConnection, 0, slot);
                            }
                            else
                                pConnection.Logger_WriteLine("!!! Could not find item @ {0} {1}", inv, slot);
                        }
                        else
                        {
                            if (inventory.InventoryItems[inv - 1].ContainsKey((byte)slot))
                            {
                                inventory.InventoryItems[inv - 1].Remove((byte)slot);
                                AccountDataCache.Instance.DeleteItemChecksum(pConnection, (ushort)(inv - 1), slot);
                            }
                            else
                                pConnection.Logger_WriteLine("!!! Could not find item @ {0} {1}", inv, slot);


                        }

                        using (DeleteQueryBuilder itemTable = new DeleteQueryBuilder("items"))
                        {
                            itemTable.SetWhereColumn("inventory", inv);
                            itemTable.SetWhereColumn("slot", slot);
                            itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);
                            itemTable.RunQuery();
                        }
                    }

                    else if (type4 == 4)
                    {
                        pPacket.ReadLong(); // Unknown..?
                    }
                    else if (type4 == 5)
                    {
                        // 'Swap' items from and to bags
                        inv -= 1;

                        short from = slot;
                        byte slotfrom = (byte)(from % 100);
                        byte bagfrom = (byte)(from / 100);

                        short to = pPacket.ReadShort();
                        byte slotto = (byte)(to % 100);
                        byte bagto = (byte)(to / 100);


                        slotfrom -= 1;
                        slotto -= 1;
                        if (bagto == 0)
                            bagto = 255;
                        else
                            bagto -= 1;
                        if (bagfrom == 0)
                            bagfrom = 255;
                        else
                            bagfrom -= 1;


                        ushort invto = bagto == 255 ? inv : GameHelper.GetBagID(bagto, inv);
                        ushort invfrom = bagfrom == 255 ? inv : GameHelper.GetBagID(bagfrom, inv);


                        if (
                            (bagfrom != 255 && bagto != 255) ||
                            (bagfrom == bagto) || // Check if the item is being moved to itself or something

                            (bagfrom == 255 && !inventory.InventoryItems[inv].ContainsKey(slotfrom)) ||
                            (bagfrom != 255 && (!inventory.BagItems.ContainsKey(invfrom) || !inventory.BagItems[invfrom].Items.ContainsKey(slotfrom))) ||

                            (bagto != 255 && !inventory.BagItems.ContainsKey(invto)) // Only check if bag exists
                            )
                        {
                            pConnection.Logger_WriteLine("Invalid item movement in bag !!!");
                            continue;
                        }

                        bool founditem = false;
                        if (bagfrom == 255)
                        {
                            // Move to bag
                            ItemBase ib = inventory.InventoryItems[inv][slotfrom];
                            if (inventory.BagItems[invto].Items.ContainsKey(slotto))
                            {
                                inventory.InventoryItems[inv][slotfrom] = inventory.BagItems[invto].Items[slotto];
                                inventory.BagItems[invto].Items.Remove(slotto);
                                founditem = true;
                            }

                            inventory.BagItems[invto].Items.Add(slotto, ib);



                        }
                        else
                        {
                            // Move to normal slot
                            ItemBase ib = inventory.BagItems[invfrom].Items[slotfrom];
                            if (inventory.InventoryItems[inv].ContainsKey(slotto))
                            {
                                inventory.BagItems[invfrom].Items[slotfrom] = inventory.InventoryItems[inv][slotto];
                                inventory.InventoryItems[inv].Remove(slotto);
                            }

                            inventory.InventoryItems[inv].Add(slotto, ib);



                            using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items"))
                            {
                                itemsTable.OnDuplicateUpdate = true;
                                Queries.SaveItem(pConnection, inv, slot, ib, itemsTable);
                                itemsTable.RunQuery();
                            }


                        }

                        /*
                         * Item A: item being used to move/swap | inv 3, slot 21 (Etc) | slotfrom, invfrom
                         * Item B: item that is being swapped with A | inv 11, slot 3 (Bag 2) | slotto, invto
                         * 
                         * Move B to a temp slot, to the new inventory: inv 11 -> inv 3, slot 3 -> slot 3021
                         * Move A to B: inv 3 -> inv 11, slot 21 -> slot 3
                         * Move B to A: slot 3021 -> slot 21
                         * 
                        */


                        if (founditem) // New slot contained item
                        {
                            // Temporary moving item
                            using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                            {
                                itemTable.SetColumn("slot", slotfrom + 3000);
                                itemTable.SetColumn("inventory", invfrom);
                                itemTable.SetWhereColumn("inventory", invto);
                                itemTable.SetWhereColumn("slot", slotto);
                                itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                                MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                            }
                        }

                        using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                        {
                            itemTable.SetColumn("slot", slotto);
                            itemTable.SetColumn("inventory", invto);
                            itemTable.SetWhereColumn("inventory", invfrom);
                            itemTable.SetWhereColumn("slot", slotfrom);
                            itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                            MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                        }

                        if (founditem) // Fix other slot
                        {
                            using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                            {
                                itemTable.SetColumn("slot", slotfrom);
                                itemTable.SetWhereColumn("inventory", invfrom);
                                itemTable.SetWhereColumn("slot", slotfrom + 3000);
                                itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                                MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                            }
                        }
                    }
                    else if (type4 == 6)
                    {
                        // Update bag item amount
                        inv -= 1;

                        short from = slot;
                        byte slotfrom = (byte)(from % 100);
                        byte bagfrom = (byte)(from / 100);

                        short amount = pPacket.ReadShort();


                        slotfrom -= 1;
                        if (bagfrom == 0)
                        {
                            pConnection.Logger_WriteLine("Invalid item bag!");
                            continue;
                        }
                        else
                            bagfrom -= 1;

                        ushort invfrom = GameHelper.GetBagID(bagfrom, inv);

                        if (
                            !inventory.BagItems.ContainsKey(invfrom) || !inventory.BagItems[invfrom].Items.ContainsKey(slotfrom)
                            )
                        {
                            pConnection.Logger_WriteLine("Invalid item movement in bag (item did not exist)!!!");
                            continue;
                        }



                        ItemBase item = inventory.BagItems[invfrom].Items[slotfrom];
                        item.Amount = amount;

                        AccountDataCache.Instance.SetChecksumOfSlot(pConnection.CharacterID, pConnection.WorldID, inv, slot, item.GetChecksum());

                        using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                        {
                            itemTable.SetColumn("amount", amount);
                            itemTable.SetColumn("checksum", item.GetChecksum());
                            itemTable.SetWhereColumn("inventory", invfrom);
                            itemTable.SetWhereColumn("slot", slot);
                            itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                            MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                        }
                    }
                    else if (type4 == 7)
                    {
                        // Delete/drop bag item D:
                        inv -= 1;

                        short from = slot;
                        byte slotfrom = (byte)(from % 100);
                        byte bagfrom = (byte)(from / 100);

                        slotfrom -= 1;
                        bagfrom -= 1;
                        ushort invfrom = GameHelper.GetBagID(bagfrom, inv);


                        using (DeleteQueryBuilder itemTable = new DeleteQueryBuilder("items"))
                        {
                            itemTable.SetWhereColumn("inventory", invfrom);
                            itemTable.SetWhereColumn("slot", slotfrom);
                            itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                            MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                        }
                    }
                    else if (type4 == 8)
                    {
                        // Swap/move item in bags
                        inv -= 1;

                        short from = slot;
                        byte slotfrom = (byte)(from % 100);
                        byte bagfrom = (byte)(from / 100);

                        short to = pPacket.ReadShort();
                        byte slotto = (byte)(to % 100);
                        byte bagto = (byte)(to / 100);

                        slotfrom -= 1;
                        slotto -= 1;
                        bagto -= 1;
                        bagfrom -= 1;


                        ushort invto = GameHelper.GetBagID(bagto, inv);
                        ushort invfrom = GameHelper.GetBagID(bagfrom, inv);


                        if (!inventory.BagItems.ContainsKey(invfrom) || !inventory.BagItems.ContainsKey(invto))
                        {
                            pConnection.Logger_WriteLine("Invalid item movement in bag");
                            continue;
                        }

                        if (!inventory.BagItems[invfrom].Items.ContainsKey(slotfrom))
                        {
                            pConnection.Logger_WriteLine("Invalid item movement in bag (item not found)");
                            continue;
                        }

                        ItemBase item = inventory.BagItems[invfrom].Items[slotfrom];

                        bool founditem = false;

                        if (inventory.BagItems[invto].Items.ContainsKey(slotto))
                        {
                            // Swap

                            inventory.BagItems[invfrom].Items[slotfrom] = inventory.BagItems[invto].Items[slotto];
                            inventory.BagItems[invto].Items.Remove(slotto); // Delete item
                            founditem = true;
                        }
                        inventory.BagItems[invto].Items.Add(slotto, item);




                        if (founditem) // New slot contained item
                        {
                            // Temporary moving item
                            using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                            {
                                itemTable.SetColumn("slot", slotfrom + 3000);
                                itemTable.SetColumn("inventory", invfrom);
                                itemTable.SetWhereColumn("inventory", invto);
                                itemTable.SetWhereColumn("slot", slotto);
                                itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                                MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                            }
                        }

                        using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                        {
                            itemTable.SetColumn("slot", slotto);
                            itemTable.SetColumn("inventory", invto);
                            itemTable.SetWhereColumn("inventory", invfrom);
                            itemTable.SetWhereColumn("slot", slotfrom);
                            itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                            MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                        }

                        if (founditem) // Fix other slot
                        {
                            using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items"))
                            {
                                itemTable.SetColumn("slot", slotfrom);
                                itemTable.SetWhereColumn("inventory", invfrom);
                                itemTable.SetWhereColumn("slot", slotfrom + 3000);
                                itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID);

                                MySQL_Connection.Instance.RunQuery(itemTable.ToString());
                            }
                        }
                    }
                    else if (type4 == 9)
                    {
                        // Add item directly to bag
                        inv -= 1;

                        ItemBase item = ItemBase.DecodeItemData(pConnection, pPacket);

                        short from = slot;
                        byte slotfrom = (byte)(from % 100);
                        byte bagfrom = (byte)(from / 100);

                        slotfrom -= 1;
                        bagfrom -= 1;
                        ushort invfrom = GameHelper.GetBagID(bagfrom, inv);

                        if (!inventory.BagItems.ContainsKey(invfrom)) continue;

                        inventory.BagItems[invfrom].Items[slotfrom] = item;


                        using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items"))
                        {
                            itemsTable.OnDuplicateUpdate = true;
                            Queries.SaveItem(pConnection, invfrom, slotfrom, item, itemsTable);
                            itemsTable.RunQuery();

                        }
                        if (item is ItemPet)
                        {
                            var pet = item as ItemPet;
                            using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets"))
                            {
                                petTable.OnDuplicateUpdate = true;
                                Queries.SavePet(pConnection.CharacterInternalID, pet, petTable);
                                petTable.RunQuery();
                            }
                        }
                    }
                    else if (type4 == 10)
                    {
                        pConnection.Logger_WriteLine("Player probably removed some bag item... O.o?");
                    }
                }
            }
            pConnection.SendTimeUpdate();
        }
Beispiel #37
0
        public void DecodePQDone(ClientConnection pConnection, MaplePacket pPacket)
        {
            PartyQuestsDone = new Dictionary<ushort, long>();
            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                ushort id = pPacket.ReadUShort();
#if LOCALE_EMS
                var date = pPacket.ReadUInt();

                long time = DecodeTimeFromInt(pConnection, date);
#else
                long time = pPacket.ReadLong();
#endif
                if (!PartyQuestsDone.ContainsKey(id))
                    PartyQuestsDone.Add(id, time);
                else
                    pConnection.Logger_WriteLine("Duplicate PQ (Done): {0}", id);
            }
        }
        public void TryRestartSession(ClientConnection pConnection, int pCharacterID, byte[] pMachineID)
        {
            RestartInfo restartInfo = Cache.Find((i) => { return (i.CharacterID == pCharacterID && i.CompareMachineID(pMachineID) && i.IP == pConnection.IP); });
            if (restartInfo != null)
            {
                // Found character
                // NOTE:
                // When a player/IP has 2 characters with the same ID on 2 different worlds
                // And the connection resets. And the player changes to the other character.
                // And a blue moon. Then worlds collide and apocalypse

                var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(pCharacterID, restartInfo.WorldID);

                if (info != null)
                {
                    if (info.AccountID != pConnection.AccountID)
                    {
                        pConnection.Logger_WriteLine("Unable to restore session for {0} (IP: {1})! Account id not the same! (Trying to hack it?)", pCharacterID, pConnection.IP);
                        return;
                    }
                    // Okay. We got this
                    pConnection.WorldID = info.WorldID;
                    pConnection.UserID = info.UserID;
                    // Do not set the IDs of the character
                    // pConnection.CharacterInternalID = info.InternalID;

                    pConnection.Logger_WriteLine("Restored session for characterid {0} world {1} (IP: {2})", pCharacterID, info.WorldID, pConnection.IP);

                    // Scratch him off the cache list
                    Cache.Remove(restartInfo);
                }
                else
                {
                    pConnection.Logger_WriteLine("Unable to restore session for {0} (IP: {1})! Not found in Internal Storage.", pCharacterID, pConnection.IP);
                }
            }
            else
            {
                pConnection.Logger_WriteLine("No info found for character id {0} (IP: {1})", pCharacterID, pConnection.IP);

            }
        }
Beispiel #39
0
        public static int AddOrUpdateCharacter(
            ClientConnection pConnection, int pID, string pName, int pUserID, byte pWorldID, byte pChannelID, byte pLevel,
            short pJob, short pStr, short pDex, short pInt, short pLuk,
            int pHP, int pMaxHP, int pMP, int pMaxMP, short pAP, short pSP,
            long pEXP, int pFame, int pMap, byte pMapPos,
            int pHonourLevel, int pHonourEXP, long pMesos, int pDemonMark,
            byte pGender, byte pSkin,
            int pEyes, int pHair,

            byte[] pSlots, string pBoF, string pBoE, string pUE,
            long[] pPetIDs, int[] pTraits,
            string pMarriedWith
            )
        {
            CharacterCacheInfo cci = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(pID, pWorldID);
            if (cci != null)
            {
                int internal_id = cci.InternalID;
                using (UpdateQueryBuilder query = new UpdateQueryBuilder("characters"))
                {
                    query.SetColumn("name", pName);
                    query.SetColumn("userid", pUserID);
                    query.SetColumn("world_id", pWorldID);
                    query.SetColumn("channel_id", pChannelID);
                    query.SetColumn("level", pLevel);
                    query.SetColumn("job", pJob);
                    query.SetColumn("str", pStr);
                    query.SetColumn("dex", pDex);
                    query.SetColumn("int", pInt);
                    query.SetColumn("luk", pLuk);
                    query.SetColumn("chp", pHP);
                    query.SetColumn("mhp", pMaxHP);
                    query.SetColumn("cmp", pMP);
                    query.SetColumn("mmp", pMaxMP);
                    query.SetColumn("ap", pAP);
                    query.SetColumn("sp", pSP);
                    query.SetColumn("exp", pEXP);
                    query.SetColumn("fame", pFame);
                    query.SetColumn("map", pMap);
                    query.SetColumn("pos", pMapPos);
                    query.SetColumn("gender", pGender);
                    query.SetColumn("skin", pSkin);
                    query.SetColumn("eyes", pEyes);
                    query.SetColumn("hair", pHair);
                    query.SetColumn("last_update", MySQL_Connection.NOW);

                    query.SetColumn("honourlevel", pHonourLevel);
                    query.SetColumn("honourexp", pHonourEXP);
                    query.SetColumn("mesos", pMesos);
                    query.SetColumn("demonmark", pDemonMark);

                    query.SetColumn("eqp_slots", pSlots[0]);
                    query.SetColumn("use_slots", pSlots[1]);
                    query.SetColumn("setup_slots", pSlots[2]);
                    query.SetColumn("etc_slots", pSlots[3]);
                    query.SetColumn("cash_slots", pSlots[4]);

                    query.SetColumn("blessingoffairy", pBoF);
                    query.SetColumn("blessingofempress", pBoE);
                    query.SetColumn("ultimateexplorer", pUE);

                    query.SetColumn("petcashid1", pPetIDs[0]);
                    query.SetColumn("petcashid2", pPetIDs[1]);
                    query.SetColumn("petcashid3", pPetIDs[2]);

                    query.SetColumn("trait_charisma", pTraits[0]);
                    query.SetColumn("trait_insight", pTraits[1]);
                    query.SetColumn("trait_willpower", pTraits[2]);
                    query.SetColumn("trait_craft_dili", pTraits[3]);
                    query.SetColumn("trait_empathy", pTraits[4]);
                    query.SetColumn("trait_charm", pTraits[5]);

                    query.SetColumn("married_with", pMarriedWith);

                    query.SetWhereColumn("internal_id", internal_id);

                    int result = query.RunQuery("sql_addorupdate.sql");

                    if (result >= 1)
                    {
                        //pConnection.Logger_WriteLine("Updated character info: {0}", internal_id);
                        return cci.InternalID;
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Failed to update character info: " + query.ToString());
                    }
                }
            }
            else
            {
                using (InsertQueryBuilder query = new InsertQueryBuilder("characters"))
                {
                    query.OnDuplicateUpdate = false;
                    query.AddColumnWithValue("internal_id", null);

                    query.AddColumnWithValue("id", pID, false);
                    query.AddColumnWithValue("name", pName);
                    query.AddColumnWithValue("userid", pUserID);
                    query.AddColumnWithValue("world_id", pWorldID);
                    query.AddColumnWithValue("channel_id", pChannelID);
                    query.AddColumnWithValue("level", pLevel);
                    query.AddColumnWithValue("job", pJob);
                    query.AddColumnWithValue("str", pStr);
                    query.AddColumnWithValue("dex", pDex);
                    query.AddColumnWithValue("int", pInt);
                    query.AddColumnWithValue("luk", pLuk);
                    query.AddColumnWithValue("chp", pHP);
                    query.AddColumnWithValue("mhp", pMaxHP);
                    query.AddColumnWithValue("cmp", pMP);
                    query.AddColumnWithValue("mmp", pMaxMP);
                    query.AddColumnWithValue("ap", pAP);
                    query.AddColumnWithValue("sp", pSP);
                    query.AddColumnWithValue("exp", pEXP);
                    query.AddColumnWithValue("fame", pFame);
                    query.AddColumnWithValue("map", pMap);
                    query.AddColumnWithValue("pos", pMapPos);
                    query.AddColumnWithValue("gender", pGender);
                    query.AddColumnWithValue("skin", pSkin);
                    query.AddColumnWithValue("eyes", pEyes);
                    query.AddColumnWithValue("hair", pHair);
                    query.AddColumnWithValue("last_update", MySQL_Connection.NOW);

                    query.AddColumnWithValue("honourlevel", pHonourLevel);
                    query.AddColumnWithValue("honourexp", pHonourEXP);
                    query.AddColumnWithValue("mesos", pMesos);
                    query.AddColumnWithValue("demonmark", pDemonMark);

                    query.AddColumnWithValue("eqp_slots", pSlots[0]);
                    query.AddColumnWithValue("use_slots", pSlots[1]);
                    query.AddColumnWithValue("setup_slots", pSlots[2]);
                    query.AddColumnWithValue("etc_slots", pSlots[3]);
                    query.AddColumnWithValue("cash_slots", pSlots[4]);

                    query.AddColumnWithValue("blessingoffairy", pBoF);
                    query.AddColumnWithValue("blessingofempress", pBoE);
                    query.AddColumnWithValue("ultimateexplorer", pUE);


                    query.AddColumnWithValue("petcashid1", pPetIDs[0]);
                    query.AddColumnWithValue("petcashid2", pPetIDs[1]);
                    query.AddColumnWithValue("petcashid3", pPetIDs[2]);

                    query.AddColumnWithValue("trait_charisma", pTraits[0]);
                    query.AddColumnWithValue("trait_insight", pTraits[1]);
                    query.AddColumnWithValue("trait_willpower", pTraits[2]);
                    query.AddColumnWithValue("trait_craft_dili", pTraits[3]);
                    query.AddColumnWithValue("trait_empathy", pTraits[4]);
                    query.AddColumnWithValue("trait_charm", pTraits[5]);

                    query.AddColumnWithValue("married_with", pMarriedWith);

                    string q = query.ToString();

                    System.IO.File.WriteAllText("sql_addorupdate_insert.sql", q);

                    int result = (int)MySQL_Connection.Instance.RunQuery(q);

                    if (result >= 1)
                    {
                        int internalid = MySQL_Connection.Instance.GetLastInsertId();
                        pConnection.Logger_WriteLine("Inserted character info: {0}", internalid);
                        return internalid;
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Failed to insert character info: " + q);
                    }
                }
            }

            Logger.WriteLine("ERROR WHILE ADDING OR UPDATING CHARACTER");

            return -1;
        }
        public virtual void HandleGuild(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte type = pPacket.ReadByte();
            if (type == 0x20)
            {
                bool hasGuild = pPacket.ReadBool();
                if (hasGuild)
                {
                    Guild guild = new Guild();
                    guild.Decode(pPacket);
                    guild.Save(pConnection.WorldID);

                    pConnection.Logger_WriteLine("{0} must be in Guild {1}", pConnection.LastLoggedCharacterName, guild.Name);
                }
                else
                {
                    // Not in a guild, anymore?
                    MySQL_Connection.Instance.RunQuery("DELETE FROM guild_members WHERE character_id = " + pConnection.CharacterInternalID + " AND world_id = " + GameHelper.GetAllianceWorldID(pConnection.WorldID));
                }
            }
        }
Beispiel #41
0
        public bool SaveData(ClientConnection pConnection)
        {
            int internalid = pConnection.CharacterInternalID = SaveCharacterInfo(pConnection);
            if (internalid == -1)
            {
                // Failure!
                return false;
            }

            using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items"))
            using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets"))
            {
                var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(Stats.ID, pConnection.WorldID);

                if (info != null)
                {
                    // Update info!
                    pConnection.CharacterID = Stats.ID;

                    CharacterInventory inventory = Inventory;

                    for (byte i = 0; i < Inventory.EquipmentItems.Length; i++)
                    {
                        var equips = Inventory.EquipmentItems[i];
                        foreach (var equipdata in equips)
                        {
                            short slot = equipdata.Key;
                            var equip = equipdata.Value;
                            bool addrow = false;

                            if (info.SlotHashes.ContainsKey(0) && info.SlotHashes[0].ContainsKey(slot))
                            {
                                int hash = info.SlotHashes[0][slot];
                                int objhash = equipdata.Value.GetChecksum();
                                if (hash != objhash)
                                {
                                    pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                    addrow = true;
                                }

                                info.SlotHashes[0].Remove(slot);
                            }
                            else
                            {
                                addrow = true;
                            }

                            if (addrow)
                                Queries.SaveItem(pConnection, 0, slot, equip, itemsTable, true);
                        }
                    }

                    pConnection.Logger_WriteLine("Done equips");

                    for (int i = 0; i < Inventory.InventoryItems.Length; i++)
                    {
                        var items = Inventory.InventoryItems[i];
                        foreach (var itemdata in items)
                        {
                            var item = itemdata.Value;
                            bool addrow = false;
                            if (info.SlotHashes.ContainsKey(i + 1) && info.SlotHashes[i + 1].ContainsKey(itemdata.Key))
                            {
                                int hash = info.SlotHashes[i + 1][itemdata.Key];
                                int objhash = itemdata.Value.GetChecksum();
                                if (hash != objhash)
                                {
                                    pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                    addrow = true;
                                }


                                info.SlotHashes[i + 1].Remove(itemdata.Key);
                            }
                            else
                            {
                                addrow = true;
                            }

                            if (addrow)
                            {
                                Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true);

                                if (item is ItemPet)
                                {
                                    Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                }
                            }
                        }
                    }
                    pConnection.Logger_WriteLine("Done items");

                    foreach (var bag in Inventory.BagItems)
                    {
                        ushort i = (ushort)bag.Key;
                        foreach (var itemdata in bag.Value.Items)
                        {
                            var item = itemdata.Value;
                            bool addrow = false;
                            if (info.SlotHashes.ContainsKey(i) && info.SlotHashes[i].ContainsKey(itemdata.Key))
                            {
                                int hash = info.SlotHashes[i][itemdata.Key];
                                int objhash = itemdata.Value.GetChecksum();
                                if (hash != objhash)
                                {
                                    pConnection.Logger_WriteLine("{0} != {1}", hash, objhash);
                                    addrow = true;
                                }


                                info.SlotHashes[i].Remove(itemdata.Key);
                            }
                            else
                            {
                                addrow = true;
                            }

                            if (addrow)
                            {
                                Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true);

                                if (item is ItemPet)
                                {
                                    Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                                }
                            }
                        }
                    }

                    pConnection.Logger_WriteLine("Done bag items");

                    {
                        string removequery = "";
                        bool added = false;
                        foreach (var hashlist in info.SlotHashes)
                        {
                            foreach (var leftovers in hashlist.Value)
                            {
                                pConnection.Logger_WriteLine("Deleting item @ inv {0} slot {1}", hashlist.Key, leftovers.Key);
                                added = true;
                                removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", hashlist.Key, leftovers.Key, internalid);
                            }
                        }
                        if (added)
                        {
                            System.IO.File.WriteAllText("removequery.sql", removequery);
                            MySQL_Connection.Instance.RunQuery(removequery);
                        }
                    }

                }
                else
                {

                    pConnection.Logger_WriteLine("Saving Items");

                    pConnection.CharacterInternalID = internalid;
                    pConnection.CharacterID = Stats.ID;

                    string itemlist = "";
                    itemlist += "INSERT INTO items VALUES ";
                    List<string> querylist = new List<string>();
                    for (byte i = 0; i < Inventory.EquipmentItems.Length; i++)
                    {
                        var equips = Inventory.EquipmentItems[i];
                        foreach (var equipdata in equips)
                        {
                            var equip = equipdata.Value;
                            Queries.SaveItem(pConnection, 0, equipdata.Key, equip, itemsTable, true);
                        }
                    }

                    pConnection.Logger_WriteLine("Done equips");

                    for (int i = 0; i < Inventory.InventoryItems.Length; i++)
                    {
                        var items = Inventory.InventoryItems[i];
                        foreach (var itemdata in items)
                        {
                            var item = itemdata.Value;

                            Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true);

                            if (item is ItemPet)
                            {
                                Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                            }
                        }
                    }

                    pConnection.Logger_WriteLine("Done items");

                    foreach (var bag in Inventory.BagItems)
                    {
                        ushort i = (ushort)(bag.Key);
                        foreach (var itemdata in bag.Value.Items)
                        {
                            var item = itemdata.Value;
                            Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true);

                            if (item is ItemPet)
                            {
                                Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable);
                            }
                        }
                    }

                    pConnection.Logger_WriteLine("Done bag items");

                    AccountDataCache.Instance.LoadBaseData(Stats.Name);

                }

                itemsTable.RunQuery();

                pConnection.Logger_WriteLine("Saved item data");

                petTable.RunQuery();

                pConnection.Logger_WriteLine("Saved pet data");


                AccountDataCache.Instance.LoadInventoryHashes(internalid, true);



                MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running WHERE character_id = " + internalid);
                using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running"))
                {
                    questsTable.OnDuplicateUpdate = true;
                    questsTable.AddColumn("character_id", false);
                    questsTable.AddColumn("questid", true);
                    questsTable.AddColumn("data", true);

                    foreach (var quest in Quests.Running)
                    {
                        questsTable.AddRow(internalid, quest.Key, quest.Value);
                    }

                    questsTable.RunQuery("insert-update-quests.sql");
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done WHERE character_id = " + internalid);
                using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done"))
                {
                    doneTable.AddColumn("character_id", false);
                    doneTable.AddColumn("questid", false);
                    doneTable.AddColumn("time", false);

                    foreach (var quest in Quests.Done)
                    {
                        doneTable.AddRow(internalid, quest.Key, quest.Value);
                    }

                    doneTable.RunQuery("insert-update-quests-done.sql");
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running_party WHERE character_id = " + internalid);
                using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running_party"))
                {
                    questsTable.OnDuplicateUpdate = true;
                    questsTable.AddColumn("character_id", false);
                    questsTable.AddColumn("questid", true);
                    questsTable.AddColumn("data", true);

                    foreach (var quest in Quests.PartyQuestsRunning)
                    {
                        questsTable.AddRow(internalid, quest.Key, quest.Value);
                    }

                    questsTable.RunQuery();
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done_party WHERE character_id = " + internalid);
                using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done_party"))
                {
                    doneTable.AddColumn("character_id", false);
                    doneTable.AddColumn("questid", false);
                    doneTable.AddColumn("time", false);

                    foreach (var quest in Quests.PartyQuestsDone)
                    {
                        doneTable.AddRow(internalid, quest.Key, quest.Value);
                    }

                    doneTable.RunQuery();
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM skills WHERE character_id = " + internalid);
                using (InsertQueryBuilder skillTable = new InsertQueryBuilder("skills"))
                {
                    skillTable.OnDuplicateUpdate = true;
                    skillTable.AddColumn("character_id", false);
                    skillTable.AddColumn("skillid", false);
                    skillTable.AddColumn("level", true);
                    skillTable.AddColumn("maxlevel", true);
                    skillTable.AddColumn("expires", true);

                    foreach (var skill in Skills.SkillList)
                    {
                        skillTable.AddRow(internalid, skill.Key, skill.Value.Level, skill.Value.MasterLevel != -1 ? (object)skill.Value.MasterLevel : null, skill.Value.Expiration);
                    }

                    skillTable.RunQuery();
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM sp_data WHERE character_id = " + internalid);
                using (InsertQueryBuilder spTable = new InsertQueryBuilder("sp_data"))
                {
                    spTable.OnDuplicateUpdate = true;
                    spTable.AddColumn("character_id", false);
                    spTable.AddColumn("slot", false);
                    spTable.AddColumn("amount", true);

                    foreach (var kvp in Stats.SPData)
                    {
                        spTable.AddRow(internalid, kvp.Key, kvp.Value);
                    }

                    spTable.RunQuery();
                }

                using (InsertQueryBuilder teleportRocks = new InsertQueryBuilder("teleport_rock_locations"))
                {
                    teleportRocks.OnDuplicateUpdate = true;

                    teleportRocks.AddColumn("character_id");
                    for (int i = 0; i < 41; i++)
                        teleportRocks.AddColumn("map" + i, true);

                    teleportRocks.AddRowUnsafe(
                        pConnection.CharacterInternalID,
                        Inventory.TeleportRocks.ToList()
                        );

                    teleportRocks.RunQuery();
                }

                MySQL_Connection.Instance.RunQuery("DELETE FROM evolution_levels WHERE character_id = " + internalid);
                using (InsertQueryBuilder table = new InsertQueryBuilder("evolution_levels"))
                {
                    table.AddColumn("character_id");
                    table.AddColumn("block");
                    table.AddColumn("index");
                    table.AddColumn("card", true);
                    table.AddColumn("level", true);

                    foreach (var card in EvolutionCards)
                    {
                        table.AddRow(
                            pConnection.CharacterInternalID,
                            card.Block,
                            card.ID,
                            card.ItemID,
                            card.Level
                            );

                    }

                    table.RunQuery();
                }


                MySQL_Connection.Instance.RunQuery("DELETE FROM character_rings WHERE character_id = " + pConnection.CharacterInternalID);
                using (InsertQueryBuilder table = new InsertQueryBuilder("character_rings"))
                {
                    table.AddColumn("character_id");
                    table.AddColumn("friend_name");
                    table.AddColumn("cashid1");
                    table.AddColumn("cashid2");
                    table.AddColumn("type");

                    foreach (var ring in Rings)
                    {
                        string type = "";
                        switch (ring.RingType)
                        {
                            case Ring.Type.Couple: type = "couple"; break;
                            case Ring.Type.Marriage: type = "marriage"; break;
                            case Ring.Type.Friend: type = "friend"; break;
                        }

                        table.AddRow(
                            pConnection.CharacterInternalID,
                            ring.FriendName,
                            ring.RingCashID1,
                            ring.RingCashID1,
                            type
                            );

                    }

                    table.RunQuery();
                }


                MySQL_Connection.Instance.RunQuery("DELETE FROM character_abilities WHERE character_id = " + pConnection.CharacterInternalID);
                using (InsertQueryBuilder table = new InsertQueryBuilder("character_abilities"))
                {
                    table.AddColumn("character_id");
                    table.AddColumn("id");
                    table.AddColumn("skill_id");
                    table.AddColumn("level");

                    foreach (var stat in Abilities)
                    {
                        table.AddRow(
                            pConnection.CharacterInternalID,
                            stat.Item1,
                            stat.Item2,
                            stat.Item3
                            );
                    }

                    table.RunQuery();
                }

                return true;
            }
        }
Beispiel #42
0
        public void Decode(ClientConnection pConnection, MaplePacket pPacket)
        {
            if (pPacket.ReadBool())
            {
                for (short i = pPacket.ReadShort(); i > 0; i--)
                {
                    Skill skill = new Skill();
                    skill.ID = pPacket.ReadInt();
                    skill.Level = pPacket.ReadInt();
                    skill.Expiration = pPacket.ReadLong();

                    if (GameHelper.is_skill_need_master_level(skill.ID))
                        skill.MasterLevel = pPacket.ReadInt();
                    else
                        skill.MasterLevel = -1;

                    if (SkillList.ContainsKey(skill.ID)) // NEXON
                        pConnection.Logger_WriteLine("Found duplicate skill {0}", skill.ID);
                    else
                        SkillList.Add(skill.ID, skill);
                }

                // Link skills
                for (int i = pPacket.ReadShort(); i > 0; i--)
                {
                    pPacket.ReadInt();
                    pPacket.ReadShort();
                }
            }
            else
            {
                pConnection.Logger_WriteLine("Character has 'new' skilllist!");
                // 0.0
                for (short i = pPacket.ReadShort(); i > 0; i--)
                {
                    pPacket.ReadInt();
                    pPacket.ReadInt();
                }

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

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

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

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

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

            }

            short amnt = pPacket.ReadShort();

            for (short i = 0; i < amnt; i++)
            {
                Cooldowns.Add(pPacket.ReadInt(), pPacket.ReadInt());
            }
        }