BattleNet.Bncs.AuthInfoRequest C# (CSharp) Метод

AuthInfoRequest() защищенный Метод

protected AuthInfoRequest ( byte type, List data ) : void
type byte
data List
Результат void
        protected void AuthInfoRequest(byte type, List<byte> data)
        {
            if (ClientlessBot.debugging)
                Console.WriteLine("{0}: [BNCS] Received Auth Info Packet", m_owner.Account);

            m_owner.ServerToken = BitConverter.ToUInt32(data.ToArray(), 8);
            List<byte> temp = data.GetRange(16, 8);
            byte[] tbytes = new byte[temp.Count];
            temp.CopyTo(tbytes);

            String mpq_file_time = System.Text.Encoding.ASCII.GetString(tbytes);

            int offset;
            if (data.ToArray()[24] == 0x76)
                offset = 24;
            else
                offset = 24;
            //Console.WriteLine((char)data.ToArray()[24]);

            String mpq_file_name = Utils.readNullTerminatedString(System.Text.Encoding.ASCII.GetString(data.ToArray()), ref offset);
            //Console.WriteLine(mpq_file_name[0]);
            String formula_string = Utils.readNullTerminatedString(System.Text.Encoding.ASCII.GetString(data.ToArray()), ref offset);
            //Console.WriteLine(formula_string[0]);

            if (ClientlessBot.debugging)
            {
                Console.WriteLine("\tServer Token: {0}",  m_owner.ServerToken);
                Console.WriteLine("\tMPQ File Time: {0}", mpq_file_time);
                Console.WriteLine("\tMPQ File Name: {0}", mpq_file_name);
                Console.WriteLine("\tFormula String: {0}", formula_string);
            }

            TcpClient bnftp = new TcpClient();
            bnftp.Connect(m_owner.BattleNetServer, s_bncsPort);
            NetworkStream ftpstream = bnftp.GetStream();
            if (ftpstream.CanWrite)
            {
                //Console.WriteLine(" Connected");
                ftpstream.WriteByte(0x02);
                List<byte> bytes = new List<byte>();
                byte[] tempftp = { 0x2f, 0x00, 0x00, 0x01 };

                bytes.AddRange(tempftp);
                bytes.AddRange(System.Text.Encoding.ASCII.GetBytes(platform));
                bytes.AddRange(System.Text.Encoding.ASCII.GetBytes(classic_id));
                bytes.AddRange(nulls);
                bytes.AddRange(nulls);
                bytes.AddRange(nulls);
                bytes.AddRange(System.Text.Encoding.ASCII.GetBytes(mpq_file_time));
                bytes.AddRange(System.Text.Encoding.ASCII.GetBytes(mpq_file_name));
                bytes.AddRange(zero);

                ftpstream.Write(bytes.ToArray(), 0, bytes.Count);

                List<byte> buffer = new List<byte>();

                do
                {
                    buffer.Add((byte)ftpstream.ReadByte());
                } while (buffer.Count < 8);
                byte[] bufferBytes = buffer.ToArray();
                UInt16 headerSize = BitConverter.ToUInt16(bufferBytes, 0);
                UInt32 fileSize = BitConverter.ToUInt32(bufferBytes, 4);
                UInt32 totalSize = fileSize + headerSize;
                if (ClientlessBot.debugging)
                    Console.WriteLine("{0}: [BNCS] Starting BNFTP download",m_owner.Account);

                do
                {
                    if (ftpstream.DataAvailable)
                        buffer.Add((byte)ftpstream.ReadByte());
                    else
                        break;

                } while (buffer.Count < totalSize);
                if (ClientlessBot.debugging)
                    Console.WriteLine("{0}: [BNCS] Finished BNFTP download",m_owner.Account);

                ftpstream.Close();
                bnftp.Close();

            }
            else
            {
            }

            uint exe_checksum = AdvancedCheckRevision.FastComputeHash(formula_string, mpq_file_name,
                                                            System.IO.Path.Combine(m_owner.BinaryDirectory, "Game.exe"),
                                                            System.IO.Path.Combine(m_owner.BinaryDirectory, "Bnclient.dll"),
                                                            System.IO.Path.Combine(m_owner.BinaryDirectory, "D2Client.dll"));
            /*
            switch (CheckRevision.DoCheck(formula_string, mpq_file_name,  m_owner.BinaryDirectory, ref exe_checksum))
            {
                case CheckRevision.CheckRevisionResult.CHECK_REVISION_SUCCESS:
                    if (ClientlessBot.debugging)
                        Console.WriteLine("\t\tCheck Revision SUCCESS");
                    break;
                default:
                    if (ClientlessBot.debugging)
                        Console.WriteLine("\t\tCheck Revision Failed");
                    break;
            }
            */
            uint client_token = (uint)System.Environment.TickCount;

            List<byte> classic_hash = new List<byte>(), lod_hash = new List<byte>(), classic_public = new List<byte>(), lod_public = new List<byte>();

            if (CdKey.GetD2KeyHash(m_owner.ClassicKey, ref  client_token, m_owner.ServerToken, ref classic_hash, ref classic_public))
            {
                if (ClientlessBot.debugging)
                    Console.WriteLine("{0}: [BNCS] Successfully generated the classic CD key hash", m_owner.Account);
            }
            else
            {
                Console.WriteLine("{0}: [BNCS] CD key is invalid", m_owner.Account);
                m_owner.Status = ClientlessBot.ClientStatus.STATUS_INVALID_CD_KEY;
            }

            if (CdKey.GetD2KeyHash(m_owner.ExpansionKey, ref client_token, m_owner.ServerToken, ref  lod_hash, ref lod_public))
            {
                if (ClientlessBot.debugging)
                    Console.WriteLine("{0}: [BNCS] Successfully generated the lod CD key hash", m_owner.Account);
            }
            else
            {
                Console.WriteLine("{0}: [BNCS] Expansion CD key is invalid", m_owner.Account);
                m_owner.Status = ClientlessBot.ClientStatus.STATUS_INVALID_EXP_CD_KEY;
            }

            byte[] packet =  BuildPacket((byte)0x51, BitConverter.GetBytes(client_token), BitConverter.GetBytes(0x01000001), BitConverter.GetBytes(exe_checksum),
                            BitConverter.GetBytes(0x00000002), nulls, ten, six, classic_public, nulls, classic_hash, ten, BitConverter.GetBytes((UInt32)10),
                            lod_public, nulls, lod_hash, System.Text.Encoding.UTF8.GetBytes(m_owner.GameExeInformation), zero, System.Text.Encoding.ASCII.GetBytes(m_owner.KeyOwner),zero);

            PrintPacket(packet);

            m_stream.Write(packet, 0, packet.Length);
        }