Exemplo n.º 1
0
        public HandlePin(Client client, byte[] packet)
        {
            PacketReader Reader = new PacketReader(packet);

            byte type = Reader.ReadByte();

            if (type == 0)
            {
                PacketWriter Writer = new PacketWriter();

                Writer.WriteShort((short)PacketOpcodes.sWorldInfoRequest);
                client.SendPacket(Writer);
            }
            else if (type == 1)
            {
                MessageBox.Show("Please set a pin.");
                client.MapleConnect.Close();
                client.LoginThread.Abort();
                client.Account.LoggingIn = false;
                client.MForm.ChangedAccount();
            }
            else if (type == 2)
            {
                MessageBox.Show("Incorrect pin");
                client.MapleConnect.Close();
                client.LoginThread.Abort();
                client.Account.LoggingIn = false;
                client.MForm.ChangedAccount();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles received character login information and confirms CharacterID
        /// </summary>
        /// <param name="client">Client from which packet was received</param>
        /// <param name="packet"></param>
        public HandleLoggedIn(Client client, byte[] packet)
        {
            PacketReader Reader = new PacketReader(packet);
            int CharacterID = Reader.ReadInt();

            for (int i = 0; i < client.Account.CharacterCount; i++)
            {
                if (client.Account.Characters[i].ID == CharacterID)
                    client.Account.Characters[i].LoggedIn = true;
            }
        }
Exemplo n.º 3
0
        public HandleLoginInfo(Client client, byte[] packet)
        {
            PacketReader Reader = new PacketReader(packet);

            byte Type = Reader.ReadByte();

            if (Type == 4)
            {
                MessageBox.Show("Incorrect password.");
                client.MapleConnect.Close();
                client.LoginThread.Abort();
                client.Account.LoggingIn = false;
                client.MForm.ChangedAccount();
            }
            else if (Type == 5)
            {
                MessageBox.Show("Username does not exist.");
                client.MapleConnect.Close();
                client.LoginThread.Abort();
                client.Account.LoggingIn = false;
                client.MForm.ChangedAccount();
            }
            else if (Type == 7)
            {
                MessageBox.Show("Account already logged in.");
                client.MapleConnect.Close();
                client.LoginThread.Abort();
                client.Account.LoggingIn = false;
                client.MForm.ChangedAccount();
            }
            else
            {
                client.Account.AccountID = Reader.ReadInt();
                Reader.ReadByte();
                Reader.ReadByte();
                Reader.ReadByte();
                client.Account.Username = Reader.ReadMapleString();
                Reader.ReadMapleString();
                Reader.ReadInt();
                //MessageBox.Show("Actual username: "******"; Account id: " + client.Account.Account_id);

                PacketWriter Writer = new PacketWriter();
                Writer.WriteShort((short)PacketOpcodes.sPin);
                Writer.WriteByte(1);
                Writer.WriteByte(0);
                Writer.WriteInt(client.Account.AccountID);
                Writer.WriteMapleString(client.Account.Pin);

                client.SendPacket(Writer);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles account login.
        /// Encrypts password and send login packet.
        /// </summary>
        /// <param name="client">Client from which packet was received</param>
        /// <param name="packet">Packet to be handled</param>>
        public HandleLogin(Client client, byte[] packet)
        {
            PacketReader Reader = new PacketReader(packet);

            int Length = Reader.ReadShort();
            byte[] Key = Reader.ReadBytes(Length);
            string PwEncrypted = Encoding.ASCII.GetString(Crypto.WzRSAEncrypt.Encrypt(Key, Length, client.Account.Password));

            byte[] Buffer = { 0x00, 0xE0, 0x4D, 0xA6, 0xA5, 0xCF, 0xB4, 0x68, 0xCB, 0xE4, 0x00, 0x00, 0x00, 0x00, 0x32, 0xFD, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00 };

            PacketWriter Writer = new PacketWriter();
            Writer.WriteShort((short)PacketOpcodes.sLogin);
            Writer.WriteMapleString(client.Account.Username);
            Writer.WriteMapleString(PwEncrypted);
            Writer.WriteMapleString("00E04DA6A5CF_B468CBE4");
            Writer.WriteBytes(Buffer);
            client.SendPacket(Writer);
        }
Exemplo n.º 5
0
        public HandleWorldInfo(Client client, byte[] packet)
        {
            PacketReader Reader = new PacketReader(packet);

            byte WorldID = Reader.ReadByte();

            if (WorldID != 0xFF)
            {
                string WorldName = Reader.ReadMapleString();
                byte EventType = Reader.ReadByte();
                string EventInfo = Reader.ReadMapleString();
                Reader.ReadShort();
                Reader.ReadShort();
                byte ChannelCount = Reader.ReadByte();

                //byte WorldID = # player["worlds"];
                client.Account.Worlds[WorldID] = new Account.World();

                client.Account.Worlds[WorldID].ID = WorldID;
                client.Account.Worlds[WorldID].Name = WorldName;
                client.Account.Worlds[WorldID].EventType = EventType;
                client.Account.Worlds[WorldID].EventInfo = EventInfo;
                client.Account.Worlds[WorldID].ChannelCount = ChannelCount;

                for (int i = 0; i < ChannelCount; i++)
                {
                    string ChannelName = Reader.ReadMapleString();
                    int ChannelPopulation = Reader.ReadInt();
                    byte ChannelWorld = Reader.ReadByte();
                    byte ChannelID = Reader.ReadByte();
                    byte ChannelLanguage = Reader.ReadByte();

                    client.Account.Worlds[WorldID].Channels[i] = new Account.Channel();

                    client.Account.Worlds[WorldID].Channels[i].Name = ChannelName;
                    client.Account.Worlds[WorldID].Channels[i].Population = ChannelPopulation;
                    client.Account.Worlds[WorldID].Channels[i].World = ChannelWorld;
                    client.Account.Worlds[WorldID].Channels[i].ID = ChannelID;
                    client.Account.Worlds[WorldID].Channels[i].Language = ChannelLanguage;
                }
            }
        }
Exemplo n.º 6
0
        public HandleServerConnect(Client client, byte[] packet)
        {
            PacketReader Reader = new PacketReader(packet);

            Reader.ReadByte();                       // unknown
            Reader.ReadByte();                       // unknown
            int Host = Reader.ReadInt();
            int Port = Reader.ReadShort();
            int CharacterID = Reader.ReadInt();
            Reader.ReadByte();                       // unknown
            Reader.ReadInt();                      // unknown

            client.ChangeIntConnection(Host, Port);

            byte[] Buffer = { 0x00, 0xE0, 0x4D, 0xA6, 0xA5, 0xCF, 0xB4, 0x68, 0xCB, 0xE4, 0x00, 0x00, 0x00, 0x00, 0x32, 0xFD, 0x00, 0x00 };

            PacketWriter Writer = new PacketWriter();
            Writer.WriteShort((short)PacketOpcodes.sChannelConnect);
            Writer.WriteInt(CharacterID);
            Writer.WriteBytes(Buffer);
            Writer.WriteBytes(client.Account.SessionID);

            client.SendPacket(Writer);
        }
Exemplo n.º 7
0
        /// <summary>
        /// A loop to check for received packets
        /// </summary>
        private void ReceiveLoop()
        {
            if (this.TcpConnection.Connected)
            {
                while (this.TcpConnection.Available < 0x10)
                {
                    Thread.Sleep(50);
                }
                byte[] buffer = new byte[0x10];
                this.TcpConnection.GetStream().Read(buffer, 0, 0x10);

                PacketReader Reader = new PacketReader(buffer);
                Reader.ReadShort();
                this.MapleVersion = Reader.ReadShort();
                Reader.ReadMapleString();
                this.SendCrypto = new MapleCrypto(Reader.ReadBytes(4), (short)this.MapleVersion);
                this.ReceiveCrypto = new MapleCrypto(Reader.ReadBytes(4), (short)this.MapleVersion);

                this.Ready = true;
                while (this.TcpConnection.Connected)
                {
                    if (this.TcpConnection.Available >= 4)
                    {
                        byte[] buffer2 = new byte[4];
                        this.TcpConnection.GetStream().Read(buffer2, 0, 4);
                        int packetLength = MapleCrypto.GetPacketLength(buffer2);
                        while (this.TcpConnection.Available < packetLength)
                        {
                            Thread.Sleep(20);
                        }
                        byte[] buffer3 = new byte[packetLength];
                        this.TcpConnection.GetStream().Read(buffer3, 0, packetLength);
                        this.ReceiveCrypto.Crypt(buffer3);
                        MapleCustomEncryption.Decrypt(buffer3);
                        Client.HandlePacket(buffer3);
                    }
                    Thread.Sleep(5);
                }
                this.Ready = false;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// HandlePacket
        /// Switches packet header and runs the appropriate scripts
        /// </summary>
        /// <param name="packet">Packet to be Handled</param>
        public void HandlePacket(byte[] packet)
        {
            PacketReader Reader = new PacketReader(packet);
            short header = Reader.ReadShort();
            byte[] Packet = Reader.ReadBytes(packet.Length - 2);
            switch (header)
            {
                case (short)PacketOpcodes.rPing:
                    new HandlePing(this);
                    break;

                case (short)PacketOpcodes.rLogin:
                    new HandleLoginInfo(this, Packet);
                    break;

                case (short)PacketOpcodes.rPwKey:
                    new HandleLogin(this, Packet);
                    break;

                case (short)PacketOpcodes.rPin:
                    new HandlePin(this, Packet);
                    break;

                case (short)PacketOpcodes.rWorldInfo:
                    new HandleWorldInfo(this, Packet);
                    break;

                case (short)PacketOpcodes.rWorldSelectAllClear:
                    new HandleSelectWorld(this);
                    break;

                case (short)PacketOpcodes.rChannelSelectAllClear:
                    new HandleSelectChannel(this);
                    break;

                case (short)PacketOpcodes.rCharInfo:
                    new HandleCharList(this, Packet);
                    break;

                case (short)PacketOpcodes.rServerInfo:
                    new HandleServerConnect(this, Packet);
                    break;

                case (short)PacketOpcodes.rLoggedIn:
                    new HandleLoggedIn(this, Packet);
                    break;

                default:
                    break;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Handles received information about the character list.
        /// Stores character variables for later access.
        /// </summary>
        /// <param name="client">Client from which packet was received</param>
        /// <param name="packet">Packet to be handled</param>
        public HandleCharList(Client client, byte[] packet)
        {
            PacketReader Reader = new PacketReader(packet);

            byte Error = Reader.ReadByte();
            if(Error!=0)
            {
                MessageBox.Show("Error selecting channel");
            }
            else
            {
                client.Account.CharacterCount = Reader.ReadByte();

                for(int i=0; i<client.Account.CharacterCount; i++)
                {
                    client.Account.Characters[i] = new Account.Character();

                    client.Account.Characters[i].ID = Reader.ReadInt();
                    PacketReader SubReader = new PacketReader(Reader.ReadBytes(13));
                    client.Account.Characters[i].Name = SubReader.ReadNullTerminatedString();
                    client.Account.Characters[i].Gender = Reader.ReadByte();
                    client.Account.Characters[i].Skin = Reader.ReadByte();
                    client.Account.Characters[i].Face = Reader.ReadInt();
                    client.Account.Characters[i].Hair = Reader.ReadInt();
                    client.Account.Characters[i].Level = Reader.ReadByte();
                    client.Account.Characters[i].Job = Reader.ReadShort();
                    client.Account.Characters[i].Str = Reader.ReadShort();
                    client.Account.Characters[i].Dex = Reader.ReadShort();
                    client.Account.Characters[i].Int = Reader.ReadShort();
                    client.Account.Characters[i].Luk = Reader.ReadShort();
                    client.Account.Characters[i].HP = Reader.ReadShort();
                    client.Account.Characters[i].MaxHp = Reader.ReadShort();
                    client.Account.Characters[i].MP = Reader.ReadShort();
                    client.Account.Characters[i].MaxMp = Reader.ReadShort();
                    client.Account.Characters[i].AP = Reader.ReadShort();
                    if (client.Account.Characters[i].Job / 1000 == 3 || client.Account.Characters[i].Job / 100 == 22 || client.Account.Characters[i].Job == 2001)
                    {
                        byte spCount = Reader.ReadByte();
                        Reader.Skip(spCount * 2);//sp for each job level
                    }
                    else
                        client.Account.Characters[i].SP = Reader.ReadShort();
                    //Reader.Skip(Reader.ReadByte() * 2);
                    client.Account.Characters[i].XP = Reader.ReadInt();
                    client.Account.Characters[i].Fame = Reader.ReadShort();
                    client.Account.Characters[i].Map = Reader.ReadInt();
                    client.Account.Characters[i].SpawnPoint = Reader.ReadByte();
                    Reader.ReadInt();  // unknown
                    Reader.ReadShort();  // unknown
                    Reader.ReadInt();  // unknown
                    Reader.ReadInt();  // unknown
                    Reader.ReadBytes(8); // unknown
                    Reader.ReadByte();   // gender (again)
                    Reader.ReadByte();   // skin (again)
                    Reader.ReadInt();  // face (again)
                    Reader.ReadByte();   // unknown
                    Reader.ReadInt();  // hair (again)

                    byte Position = Reader.ReadByte();

                    while(Position != 0xFF)
                    {
                        client.Account.Equips.Visible[Position] = Reader.ReadInt();
                        Position = Reader.ReadByte();
                    }

                    Position = Reader.ReadByte();

                    while(Position != 0xFF)
                    {
                        client.Account.Equips.Masked[Position] = Reader.ReadInt();
                        Position = Reader.ReadByte();
                    }

                    client.Account.Equips.CashWeapon = Reader.ReadInt();

                    Reader.ReadBytes(12);    // pet info
                    Reader.ReadByte();       // unknown
                    if(Reader.ReadByte()!=0)
                        Reader.Skip(16);       // ranking
                }

                Reader.ReadShort();          // unknown
                Reader.ReadShort();          // unknown
                Reader.ReadBytes(6);         // unknown
                client.Account.SessionID = Reader.ReadBytes(8);

                client.Account.LoggedIn = true;
                // Program.mFrm.LoggedIn(client.Account.id);
                // Program.mFrm.AddCharacters(client.Account.character_count);
            }
        }