public void Decode(MaplePacket pPacket)
        {
            pPacket.ReadByte(); // ?


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

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

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

            pPacket.ReadByte(); // ?

            for (int i = pPacket.ReadShort(); i > 0; i--)
            {
                Done.Add(pPacket.ReadUShort(), pPacket.ReadLong());
            }
        }
        public 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();
            }

        }
Example #3
0
        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());
                }
            }
        }
Example #4
0
            public DumpPacket(MaplePacket pPacket)
            {
                pPacket.Reset();
                MaplePacket.CommunicationType type = (MaplePacket.CommunicationType)pPacket.ReadByte();
                Outboud = type == MaplePacket.CommunicationType.ClientPacket;
                Opcode = pPacket.ReadUShort();

                Data = new byte[pPacket.Length - 3];
                Buffer.BlockCopy(pPacket.ToArray(), 3, Data, 0, Data.Length); // byte + short (header)
                ArrivalTime = MasterThread.CurrentDate;
                pPacket.Reset();
            }
Example #5
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);
            }
        }
Example #6
0
 private static ushort FlaggedValue(ClientConnection pConnection, int pItemID, uint pValue, uint pFlag, MaplePacket pPacket, ushort pTypeValue, bool pLogIfFound = false)
 {
     if (pValue.HasFlag(pFlag))
     {
         var val = pPacket.ReadUShort();
         if (pLogIfFound)
             pConnection.Logger_WriteLine("Found flag {3} {0:X8}: {1} | ItemID: {2}", pFlag, val, pItemID, pTypeValue.GetType().Name);
         return val;
     }
     else
         return 0;
 }
Example #7
0
        public override void Decode(ClientConnection pConnection, MaplePacket pPacket)
        {
            base.Decode(pConnection, pPacket);


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

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

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

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


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

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

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

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

            this.Name = pPacket.ReadString();

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

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

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

            this.DisplayID = pPacket.ReadUShort();

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

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

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


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

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

#endif

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

            this.SetFlags = string.Join(",", flagsList);
        }
Example #8
0
        public override void OnPacket(MaplePacket pPacket)
        {
            MasterThread.Instance.AddCallback((a) =>
            {
                try
                {
                    if (Disconnected) return; // Just to be sure...

                    if (_exporter != null)
                        _exporter.AddPacket(pPacket);

                    MaplePacket.CommunicationType type = (MaplePacket.CommunicationType)pPacket.ReadByte();
                    ushort opcode = pPacket.ReadUShort();

                    if (IsFake)
                    {
                        Logger.WriteLine("Emulating {0:X4} (Len: {1})", opcode, pPacket.Length);
                    }

                    if ((byte)type < Program.ValidHeaders.Length)
                    {
                        // Check if packet is accepted
                        var list = Program.ValidHeaders[(byte)type];
                        if (list.ContainsKey(opcode))
                        {
                            var action = list[opcode];
                            if (action != null)
                            {
                                try
                                {
                                    if (action.CanHandle == null || action.CanHandle(this))
                                        action.Handle(this, pPacket);
                                }
                                catch (Exception ex)
                                {
                                    Logger_ErrorLog("Failed parsing {0:X4} for {1}", opcode, type);
                                    Logger_WriteLine(ex.ToString());
                                    if (!IsFake)
                                    {
                                        LogFilename += "ERROR";
                                        SendInfoText("An error occurred on the Mapler.me server! Please report this :)");

                                        // Save exception to packet
                                        using (MaplePacket mp = new MaplePacket(MaplePacket.CommunicationType.ServerPacket, 0x9999))
                                        {
                                            mp.WriteString(ex.ToString());
                                            if (ex.ToString().Contains("MySql.Data.MySqlClient.MySqlException"))
                                            {
                                                Logger_ErrorLog("MySQL exception!");
                                                var queries = MySQL_Connection.Instance.GetRanQueries();
                                                mp.WriteInt(queries.Count);
                                                foreach (var kvp in queries)
                                                {
                                                    mp.WriteString(kvp.Key);
                                                    mp.WriteString(kvp.Value);
                                                }

                                            }
                                            mp.SwitchOver(); // Make read packet
                                            _exporter.AddPacket(mp);
                                        }

                                        Save(false, false);
                                    }
                                }
                            }
                            else
                            {
                                if (!IsFake)
                                    Logger_WriteLine("No action for {0:X4}", opcode);
                            }
                        }
                        else
                        {
                            if (!IsFake)
                                Logger_WriteLine("Client sent packet {0:X4} for {1} but this one is not handled!", opcode, type);
                        }
                    }
                    else
                    {
                        Logger_ErrorLog("Packet Type not accepted!!! {0:X4} {1}", opcode, (byte)type);
                    }
                }
                catch (Exception ex)
                {
                    Logger.ErrorLog("Failed handling packet: {0}", ex.ToString());
                    SendInfoText("An error occurred on the Mapler.me server! Please report this :)");
                }
                pPacket.Dispose();
                pPacket = null;
            });
        }
Example #9
0
        public void Decode(MaplePacket pPacket)
        {
            this.ID = pPacket.ReadInt();
            this.Name = pPacket.ReadString(13);

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

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

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

            this.Level = pPacket.ReadByte();


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

            this.AP = pPacket.ReadShort();

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

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

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

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


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

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

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

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

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


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

            pPacket.ReadInt();

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

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

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

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

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

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

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


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

                    SetKeys(sendkey, recvkey);

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


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

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

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

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

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

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

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

            pPacket.Dispose();
            pPacket = null;
        }
Example #11
0
        public void ForwardPacket(MaplePacket.CommunicationType pType, MaplePacket pPacket)
        {
            pPacket.Reset();

            ushort header = pPacket.ReadUShort();

            if (!_validHeaders[(byte)pType].Contains(header))
            {
                return;
            }

            using (MaplePacket packet = new MaplePacket(pType, header))
            {
                packet.WriteBytes(pPacket.ReadLeftoverBytes());
                SendPacket(packet);
            }
        }
        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 HandleMessage(ClientConnection pConnection, MaplePacket pPacket)
        {
            byte type = pPacket.ReadByte();
            if (type == 0x0C)
            {
                ushort id = pPacket.ReadUShort();
                string data = pPacket.ReadString();
                // Server data update
                using (InsertQueryBuilder iqb = new InsertQueryBuilder("quests_running_party"))
                {
                    iqb.OnDuplicateUpdate = true;
                    iqb.AddColumn("character_id");
                    iqb.AddColumn("questid");
                    iqb.AddColumn("data", true);

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

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

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

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

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

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

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

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

                }
            }
        }
Example #14
0
        internal bool BufferTCPPacket(TcpPacket pTCPPacket, bool pInbound)
        {
            if (pTCPPacket.Syn && pTCPPacket.Ack)
            {
                mInboundSequence = (uint)(pTCPPacket.SequenceNumber + 1); 
                return true;
            }
            if (pTCPPacket.PayloadData.Length == 0) return true;
            if (_mapleVersion == 0)
            {
                if (pTCPPacket.PayloadData.Length < 13) return false;
                byte[] tcpData = pTCPPacket.PayloadData;

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

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

                pr.Dispose();
                pr = null;

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

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

            return true;
        }
Example #15
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);
     }
 }
Example #16
0
        public void Decode(ClientConnection pConnection, MaplePacket pPacket)
        {
            pPacket.Skip(8); // Flag

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

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

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

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

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


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

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

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

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

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

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

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


            // Unknown stuff here

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

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

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


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

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

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


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

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

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

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

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


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


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


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

#endif

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

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

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


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

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


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

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


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


            {

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

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

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

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

                    MarriedWith = ring.FriendName;
                }
            }


            Inventory.DecodeTeleportRocks(pPacket);

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

            pPacket.ReadInt(); // -1?

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

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

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

            Quests.DecodePQ(pConnection, pPacket);

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

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

            Quests.DecodePQDone(pConnection, pPacket);

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

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

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

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

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

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

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

                pPacket.ReadByte();
            }
#endif

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

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

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

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

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

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


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


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

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

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

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

            }

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

#if LOCALE_EMS
            // No farm info

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

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

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

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

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

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

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

            pPacket.ReadByte();

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

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

                pPacket.Skip(32);
            }

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

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

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

            // Removed in V.141
            //pPacket.ReadInt(); // I DONT EVEN D:
#endif
        }
        public 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;
            }
        }