Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        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();
            }
        }
Exemplo n.º 7
0
        internal bool BufferTCPPacket(TcpPacket pTCPPacket, bool pInbound)
        {
            if (pTCPPacket.Syn && pTCPPacket.Ack)
            {
                mInboundSequence = (uint)(pTCPPacket.SequenceNumber + 1); 
                return true;
            }
            if (pTCPPacket.PayloadData.Length == 0) return true;
            if (_mapleVersion == 0)
            {
                if (pTCPPacket.PayloadData.Length < 13) return false;
                byte[] tcpData = pTCPPacket.PayloadData;

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

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

                pr.Dispose();
                pr = null;

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

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

            return true;
        }
        public void Decode(MaplePacket pPacket)
        {
            Stats = new GW_CharacterStat();
            Stats.Decode(pPacket);

            this.BuddylistSize = pPacket.ReadByte();

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

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

            // Unknown stuff here

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


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

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

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

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


                while (true)
                {

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


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

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

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

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

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

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

            Inventory.DecodeTeleportRocks(pPacket);


        }