Пример #1
0
        public PacketIn ProcessPacket(TCPConnection con, byte[] buf, int start, int size)
        {
            PacketIn packet = new PacketIn(buf, start, size);

            switch (packet.ID)
            {
            case 72:     // TS_AC_AES_KEY_IV
                var pAES = new AUTH_PACKETS.AES_KEY_IV(packet);
                m_pAES_KEY = m_cRSA.PrivateDecrypt(pAES.nKey, OpenSSL.Crypto.RSA.Padding.PKCS1);
                GenerateLoginPacket(m_pAES_KEY, con);
                break;

            case 10000:     // TS_AC_RESULT
                var pResult = new AUTH_PACKETS.RESULT(packet.ReadUInt16(), packet.ReadUInt16(), packet.ReadInt32());
                if (pResult.nLoginFlag == 1)
                {
                    PacketOut o = new PacketOut(10021);
                    con.SendTCP(o);
                }
                else
                {
                    m_cAuthConnection.Disconnect();
                    XLog.Log("Login failed. Result: {0} - Disconnecting...", pResult.nResult);
                }
                m_szPassword = string.Empty;
                break;

            case 10022:     // TS_AC_SERVER_LIST
                m_iAuthServerList = new AUTH_PACKETS.SERVER_LIST(packet);
                XLog.Log("Server selection. Please use /select ID to connect to one of the listed servers below.");
                for (int i = 0; i < m_iAuthServerList.count; i++)
                {
                    XLog.Log(string.Format("-> Server {0}: {1}", i + 1, m_iAuthServerList.list[i].server_name));
                }
                break;

            case 10024:     // TS_AC_SELECT_SERVER
                con.Disconnect();

                var pSelectServer = new AUTH_PACKETS.SELECT_SERVER(packet, ref m_pAES_KEY);

                Config.ConfigNet conf = new Config.ConfigNet();
                conf.Port     = m_iAuthServerList.list[m_nSelectedServerIdx].server_port;
                conf.ListenIp = System.Net.IPAddress.Parse(m_iAuthServerList.list[m_nSelectedServerIdx].server_ip);

                PacketOut oEncrypt = new PacketOut(2005);
                oEncrypt.FillString(m_szName, 61);
                oEncrypt.Write(pSelectServer.encrypted_data, 0, pSelectServer.encrypted_data.Length);
                oEncrypt.FinalizeLengthAndChecksum();
                con.Close();
                m_cClientBase.CreateGameServerSession(oEncrypt, conf, m_szName);
                break;

            default:
                break;
            }
            return(packet);
        }
Пример #2
0
 public SERVER_LIST(PacketIn p)
 {
     last_login_idx = p.ReadUInt16();
     count          = p.ReadUInt16();
     list           = new SERVER_INFO[count];
     for (int i = 0; i < count; i++)
     {
         list[i] = new SERVER_INFO(p.ReadUInt16(), p.ReadString(21), p.ReadByte() == 1 ? true : false, p.ReadString(256), p.ReadString(16), p.ReadInt32(), p.ReadUInt16());
     }
 }
Пример #3
0
 private ClientInformation(PacketIn packet)
 {
     try
     {
         this.ProtocolVersion = packet.ReadByte();
         ushort num = packet.ReadUInt16();
         if (packet.RemainingLength != (int)num)
         {
             ClientInformation.Log.Warn(WCell_Core.Auth_Logon_with_invalid_length, (object)num,
                                        (object)packet.RemainingLength);
         }
         this._clientInstallationType = ClientTypeUtility.Lookup(packet.ReadFourCC());
         this.Version      = new ClientVersion(packet.ReadBytes(5));
         this.Architecture = packet.ReadFourCC().TrimEnd(new char[1]);
         this.OS           = packet.ReadFourCC().TrimEnd(new char[1]);
         this._locale      = ClientLocaleUtility.Lookup(packet.ReadFourCC());
         this.TimeZone     = BitConverter.ToUInt32(packet.ReadBytes(4), 0);
         this.IPAddress    = new XmlIPAddress(packet.ReadBytes(4));
         ClientInformation.Log.Info(WCell_Core.ClientInformationFourCCs, (object)this.ProtocolVersion,
                                    (object)this.ClientInstallationType, (object)this.Version, (object)this.Architecture,
                                    (object)this.OS, (object)this.Locale, (object)this.TimeZone, (object)this.IPAddress);
     }
     catch
     {
     }
 }
Пример #4
0
 private ClientInformation(PacketIn packet)
 {
     try
     {
         ProtocolVersion = packet.ReadByte();
         ushort num = packet.ReadUInt16();
         if (packet.RemainingLength != num)
         {
             Log.Warn(WCell_Core.Auth_Logon_with_invalid_length, num,
                      packet.RemainingLength);
         }
         _clientInstallationType = ClientTypeUtility.Lookup(packet.ReadFourCC());
         Version      = new ClientVersion(packet.ReadBytes(5));
         Architecture = packet.ReadFourCC().TrimEnd(new char[1]);
         OS           = packet.ReadFourCC().TrimEnd(new char[1]);
         _locale      = ClientLocaleUtility.Lookup(packet.ReadFourCC());
         TimeZone     = BitConverter.ToUInt32(packet.ReadBytes(4), 0);
         IPAddress    = new XmlIPAddress(packet.ReadBytes(4));
         Log.Info(WCell_Core.ClientInformationFourCCs, (object)ProtocolVersion,
                  (object)ClientInstallationType, (object)Version, (object)Architecture,
                  (object)OS, (object)Locale, (object)TimeZone, (object)IPAddress);
     }
     catch
     {
     }
 }
Пример #5
0
        private ClientInformation(PacketIn packet)
        {
            try
            {
                ProtocolVersion = packet.ReadByte();
                var claimedRemainingLength = packet.ReadUInt16();
                if (packet.RemainingLength != claimedRemainingLength)
                {
                    Log.Warn(WCell_Core.Auth_Logon_with_invalid_length, claimedRemainingLength, packet.RemainingLength);
                }

                var clientInstallationType = packet.ReadFourCC();
                _clientInstallationType = ClientTypeUtility.Lookup(clientInstallationType);

                Version      = new ClientVersion(packet.ReadBytes(5));
                Architecture = packet.ReadFourCC().TrimEnd('\0');
                OS           = packet.ReadFourCC().TrimEnd('\0');

                var locale = packet.ReadFourCC();
                _locale = ClientLocaleUtility.Lookup(locale);

                TimeZone  = BitConverter.ToUInt32(packet.ReadBytes(4), 0);
                IPAddress = new XmlIPAddress(packet.ReadBytes(4));

                Log.Info(WCell_Core.ClientInformationFourCCs, ProtocolVersion, ClientInstallationType, Version, Architecture, OS, Locale, TimeZone, IPAddress);
            }
            catch
            {
            }
        }
Пример #6
0
 public SELECT_SERVER(PacketIn p, ref byte[] pAESKey)
 {
     result = p.ReadUInt16();
     encrypted_data_size = p.ReadInt32();
     encrypted_data      = new byte[encrypted_data_size];
     p.Read(encrypted_data, 0, encrypted_data_size);
     encrypted_data = XClientAuthEmulator.DecryptAES(pAESKey, encrypted_data);
     pending_time   = p.ReadUInt32();
     unknown        = p.ReadUInt32();
     unknown2       = p.ReadUInt32();
 }
Пример #7
0
        /// <summary>
        /// Checks if the client's proof matches our proof.
        /// </summary>
        /// <param name="packet">the packet to read from</param>
        /// <returns>true if the client proof matches; false otherwise</returns>
        public bool IsClientProofValid(PacketIn packet)
        {
            m_srp.PublicEphemeralValueA = packet.ReadBigInteger(32);

            BigInteger proof = packet.ReadBigInteger(20);

            // SHA1 of PublicEphemeralValueA and the 16 random bytes sent in
            // AUTH_LOGON_CHALLENGE from the server
            byte[] arr = packet.ReadBytes(20);

            byte keyCount = packet.ReadByte();

            for (int i = 0; i < keyCount; i++)
            {
                ushort keyUnk1     = packet.ReadUInt16();
                uint   keyUnk2     = packet.ReadUInt32();
                byte[] keyUnkArray = packet.ReadBytes(4);
                // sha of the SRP's PublicEphemeralValueA, PublicEphemeralValueB,
                // and 20 unknown bytes
                byte[] keyUnkSha = packet.ReadBytes(20);
            }

            byte securityFlags = packet.ReadByte();

            if ((securityFlags & 1) != 0)
            {
                // PIN
                byte[] pinRandom = packet.ReadBytes(16);
                byte[] pinSha    = packet.ReadBytes(20);
            }
            if ((securityFlags & 2) != 0)
            {
                byte[] security2Buf = packet.ReadBytes(20);
            }
            if ((securityFlags & 4) != 0)
            {
                byte   arrLen       = packet.ReadByte();
                byte[] security4Buf = packet.ReadBytes(arrLen);
            }

            return(m_srp.IsClientProofValid(proof));
        }
Пример #8
0
        public void RequestRealmlist()
        {
            PacketOut packet = new PacketOut(LogonServerOpCode.REALM_LIST);

            packet.Write(0x00);
            Send(packet);


            // Most tricky code ever. It's so because retail server sends a lot of data in this packet...
            byte[]   temp = pLoop.OnReceive(3);
            PacketIn p1   = new PacketIn(temp, true);

            byte[] temp2 = pLoop.OnReceive(p1.ReadUInt16());
            byte[] temp3 = new byte[temp.Length + temp2.Length];
            temp.CopyTo(temp3, 0);
            temp2.CopyTo(temp3, temp.Length);

            p1 = new PacketIn(temp3, false);
            HandlePacket(p1);
        }
Пример #9
0
        public void HandleRealmlist(PacketIn packetIn)
        {
            //packetIn.ReadByte();
            UInt16 Length      = packetIn.ReadUInt16();
            UInt32 Request     = packetIn.ReadUInt32();
            int    realmscount = packetIn.ReadInt16();

            //Console.Write(packetIn.ToHex());

            Log.WriteLine(LogType.Success, "Got information about {0} realms.", realmscount);
            Realm[] realms = new Realm[realmscount];
            try
            {
                for (int i = 0; i < realmscount; i++)
                {
                    realms[i].Type  = packetIn.ReadByte();
                    realms[i].Color = packetIn.ReadByte();
                    packetIn.ReadByte(); // unk
                    realms[i].Name       = packetIn.ReadString();
                    realms[i].Address    = packetIn.ReadString();
                    realms[i].Population = packetIn.ReadFloat();
                    realms[i].NumChars   = packetIn.ReadByte();
                    realms[i].Language   = packetIn.ReadByte();
                    packetIn.ReadByte();
                }

                Realmlist = realms;
                mCore.Event(new Event(EventType.EVENT_REALMLIST, "", new object[] { Realmlist }));
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogType.Error, "Exception Occured");
                Log.WriteLine(LogType.Error, "Message: {0}", ex.Message);
                Log.WriteLine(LogType.Error, "Stacktrace: {0}", ex.StackTrace);
                Disconnect();
            }
        }
Пример #10
0
        /// <summary>Checks if the client's proof matches our proof.</summary>
        /// <param name="packet">the packet to read from</param>
        /// <returns>true if the client proof matches; false otherwise</returns>
        public bool IsClientProofValid(PacketIn packet)
        {
            this.m_srp.PublicEphemeralValueA = packet.ReadBigInteger(32);
            BigInteger client_proof = packet.ReadBigInteger(20);

            packet.ReadBytes(20);
            byte num1 = packet.ReadByte();

            for (int index = 0; index < (int)num1; ++index)
            {
                packet.ReadUInt16();
                packet.ReadUInt32();
                packet.ReadBytes(4);
                packet.ReadBytes(20);
            }

            byte num2 = packet.ReadByte();

            if (((int)num2 & 1) != 0)
            {
                packet.ReadBytes(16);
                packet.ReadBytes(20);
            }

            if (((int)num2 & 2) != 0)
            {
                packet.ReadBytes(20);
            }
            if (((int)num2 & 4) != 0)
            {
                byte num3 = packet.ReadByte();
                packet.ReadBytes((int)num3);
            }

            return(this.m_srp.IsClientProofValid(client_proof));
        }
Пример #11
0
        /*
         *      [PacketHandlerAtribute(WorldServerOpCode.SMSG_COMPRESSED_UPDATE_OBJECT)]
         *      public void HandleCompressedObjectUpdate(PacketIn packet)
         *      {
         *              try
         *              {
         *                      Int32 size = packet.ReadInt32();
         *                      byte[] decomped = mClient.Shared.Compression.Decompress(size, packet.ReadRemaining());
         *                      packet = new PacketIn(decomped, 1);
         *                      HandleObjectUpdate(packet);
         *              }
         *              catch(Exception ex)
         *              {
         *                      Log.WriteLine(LogType.Error, "{1} \n {0}", ex.StackTrace, ex.Message);
         *              }
         *      }
         *
         *      [PacketHandlerAtribute(WorldServerOpCode.SMSG_UPDATE_OBJECT)]
         *      public void HandleObjectUpdate(PacketIn packet)
         *      {
         *      UInt32 UpdateBlocks = packet.ReadUInt32();
         *
         *      for(int allBlocks = 0; allBlocks < UpdateBlocks; allBlocks++)
         *      {
         *          UpdateType type = (UpdateType)packet.ReadByte();
         *
         *          WoWGuid updateGuid;
         *          uint updateId;
         *          uint fCount;
         *
         *          switch(type)
         *          {
         *              case UpdateType.Values:
         *                  Object getObject;
         *                  updateGuid = new WoWGuid(packet.ReadUInt64());
         *                  if (objectMgr.objectExists(updateGuid))
         *                  {
         *                      getObject = objectMgr.getObject(updateGuid);
         *                  }
         *                  else
         *                  {
         *                      getObject = new Object(updateGuid);
         *                      objectMgr.addObject(getObject);
         *                  }
         *                  Log.WriteLine(LogType.Normal, "Handling Fields Update for object: {0}", getObject.Guid.ToString());
         *                  HandleUpdateObjectFieldBlock(packet, getObject);
         *                  objectMgr.updateObject(getObject);
         *                  break;
         *
         *              case UpdateType.Create:
         *              case UpdateType.CreateSelf:
         *                  updateGuid = new WoWGuid(packet.ReadUInt64());
         *                  updateId = packet.ReadByte();
         *                  fCount = GeUpdateFieldsCount(updateId);
         *
         *                  if (objectMgr.objectExists(updateGuid))
         *                      objectMgr.delObject(updateGuid);
         *
         *                  Object newObject = new Object(updateGuid);
         *                  newObject.Fields = new UInt32[2000];
         *                  objectMgr.addObject(newObject);
         *                  HandleUpdateMovementBlock(packet, newObject);
         *                  HandleUpdateObjectFieldBlock(packet, newObject);
         *                  objectMgr.updateObject(newObject);
         *                  Log.WriteLine(LogType.Normal, "Handling Creation of object: {0}", newObject.Guid.ToString());
         *                  break;
         *
         *              case UpdateType.OutOfRange:
         *                  fCount = packet.ReadByte();
         *                  for (int j = 0; j < fCount; j++)
         *                  {
         *                      WoWGuid guid = new WoWGuid(packet.ReadUInt64());
         *                      Log.WriteLine(LogType.Normal, "Handling delete for object: {0}", guid.ToString());
         *                      if (objectMgr.objectExists(guid))
         *                          objectMgr.delObject(guid);
         *                  }
         *                  break;
         *          }
         *      }
         *
         * }
         */

        public void HandleUpdateMovementBlock(PacketIn packet, Object newObject)
        {
            UInt16 flags = packet.ReadUInt16();


            if ((flags & 0x20) >= 1)
            {
                UInt32 flags2 = packet.ReadUInt32();
                UInt16 unk1   = packet.ReadUInt16();
                UInt32 unk2   = packet.ReadUInt32();
                newObject.Position = new Coordinate(packet.ReadFloat(), packet.ReadFloat(), packet.ReadFloat(), packet.ReadFloat());

                if ((flags2 & 0x200) >= 1)
                {
                    packet.ReadBytes(21); //transporter
                }

                if (((flags2 & 0x2200000) >= 1) || ((unk1 & 0x20) >= 1))
                {
                    packet.ReadBytes(4); // pitch
                }

                packet.ReadBytes(4); //lastfalltime

                if ((flags2 & 0x1000) >= 1)
                {
                    packet.ReadBytes(16); // skip 4 floats
                }

                if ((flags2 & 0x4000000) >= 1)
                {
                    packet.ReadBytes(4); // skip 1 float
                }

                packet.ReadBytes(32);          // all of speeds

                if ((flags2 & 0x8000000) >= 1) //spline ;/
                {
                    UInt32 splineFlags = packet.ReadUInt32();

                    if ((splineFlags & 0x00020000) >= 1)
                    {
                        packet.ReadBytes(4); // skip 1 float
                    }
                    else
                    {
                        if ((splineFlags & 0x00010000) >= 1)
                        {
                            packet.ReadBytes(4); // skip 1 float
                        }
                        else if ((splineFlags & 0x00008000) >= 1)
                        {
                            packet.ReadBytes(12); // skip 3 float
                        }
                    }

                    packet.ReadBytes(28); // skip 8 float

                    UInt32 splineCount = packet.ReadUInt32();

                    for (UInt32 j = 0; j < splineCount; j++)
                    {
                        packet.ReadBytes(12); // skip 3 float
                    }

                    packet.ReadBytes(13);
                }
            }

            else if ((flags & 0x100) >= 1)
            {
                packet.ReadBytes(40);
            }
            else if ((flags & 0x40) >= 1)
            {
                newObject.Position = new Coordinate(packet.ReadFloat(), packet.ReadFloat(), packet.ReadFloat(), packet.ReadFloat());
            }

            if ((flags & 0x8) >= 1)
            {
                packet.ReadBytes(4);
            }

            if ((flags & 0x10) >= 1)
            {
                packet.ReadBytes(4);
            }

            if ((flags & 0x04) >= 1)
            {
                packet.ReadBytes(8);
            }

            if ((flags & 0x2) >= 1)
            {
                packet.ReadBytes(4);
            }

            if ((flags & 0x80) >= 1)
            {
                packet.ReadBytes(8);
            }

            if ((flags & 0x200) >= 1)
            {
                packet.ReadBytes(8);
            }
        }
Пример #12
0
        /// <summary>
        /// The function which is used to proceed an incoming packet to the active TCPConnection
        /// </summary>
        /// <param name="con">The connection which received the packet</param>
        /// <param name="buf">byte[] array containing the raw content of the received packet</param>
        /// <param name="start">Start of the content in buf, usually 0</param>
        /// <param name="size">Size of the packet (minus start)</param>
        /// <returns>PacketIn -> Converted raw package to MemoryStream based PacketIn</returns>
        public PacketIn ProcessPacket(TCPConnection con, byte[] buf, int start, int size)
        {
            PacketIn packet = new PacketIn(buf, start, size);

            switch (packet.ID)
            {
            case 0:     // ResultMsg
                var res = new AUTH_PACKETS.RESULT(packet.ReadUInt16(), packet.ReadUInt16(), packet.ReadInt32());
                if (res.nRequestPacket == 2005)
                {
                    if (res.nResult == 0)
                    {
                        con.SendTCP(CreateReportPacket());
                        con.SendTCP(CreateCharacterListPacket());
                    }
                    else
                    {
                        con.Disconnect();
                        XLog.Log("Can't connect to game server. Result: {0} - disconnecting...", res.nResult);
                    }
                }
                break;

            case 2004:     // CharacterList
                m_iGameCharacterList = new GAME_PACKETS.CharacterList(packet);
                XLog.Log("Character selection. Please use /use ID to select a character.");
                for (int i = 0; i < m_iGameCharacterList.nCount; i++)
                {
                    XLog.Log("-> Character {0}: {1}", i + 1, m_iGameCharacterList.nList[i].szName);
                }
                break;

            case 21:     // ChatLocal
                var    tmp      = packet.ReadInt32();
                string szSource = m_dHandles.ContainsKey(tmp) ? m_dHandles[tmp] : "INVALID-HANDLE:" + tmp;
                int    nLen     = packet.ReadByte();
                int    nType    = packet.ReadByte();
                XLog.AddMessage(szSource, packet.ReadString(nLen), nType);
                break;

            case 22:     // ChatMsg
                var pMessage = new GAME_PACKETS.ChatMessage(packet);
                XLog.AddMessage(pMessage.szName, pMessage.szMessage, pMessage.nType);
                break;

            case 3:     // Enter: Handle -> Name, small hack so we don't have to read the full packet (which is f*****g large)
                if (packet.ReadByte() == 0)
                {
                    int key = packet.ReadInt32();
                    if (m_dHandles.ContainsKey(key))
                    {
                        m_dHandles.Remove(key);
                    }
                    packet.Seek(77, System.IO.SeekOrigin.Current);
                    string value = packet.ReadString(19);
                    m_dHandles.Add(key, value);
                }
                break;

            case 507:     // Property: Own Name -> Handle
                if (m_dHandles.ContainsKey(0) && m_tPingThread == null)
                {
                    var szName = m_dHandles[0];
                    m_dHandles.Remove(0);
                    m_dHandles.Add(packet.ReadInt32(), szName);
                    m_tPingThread = new System.Threading.Thread(new System.Threading.ThreadStart(SendPingPacket));
                    m_tPingThread.IsBackground = true;
                    m_tPingThread.Start();
                }
                break;

            default:
                break;
            }
            return(packet);
        }