Пример #1
0
        public static AuthTicket GetInfos(byte[] ticket)
        {
            MemoryStream stream        = new MemoryStream(ticket);
            BinaryReader binaryReader  = new BinaryReader(stream);
            HttpClient   client        = new HttpClient();
            int          initiallenght = binaryReader.ReadInt32();

            if (initiallenght == 20)
            {
                AuthTicket authTicket = new AuthTicket();
                authTicket.gctoken = binaryReader.ReadUInt64().ToString();
                binaryReader.ReadBytes(8);
                double tokengeneratednotday = (double)binaryReader.ReadUInt32() * 1000;
                authTicket.tokenGenerated = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(tokengeneratednotday).ToLocalTime();
                if (binaryReader.ReadUInt32() != 24)
                {
                    return(new AuthTicket());
                }
                binaryReader.ReadBytes(8);
                uint p = binaryReader.ReadUInt32();
                binaryReader.ReadBytes(4);
                authTicket.clientConnectionTime  = binaryReader.ReadUInt32();
                authTicket.clientConnectionCount = (int)binaryReader.ReadUInt32();
                long ownershipTicketOffset = binaryReader.BaseStream.Position;
                uint ownershipTicketLength = binaryReader.ReadUInt32();

                binaryReader.ReadBytes(4);
                authTicket.version   = (int)binaryReader.ReadUInt32();
                authTicket.AccountID = (int)binaryReader.ReadUInt32();
                binaryReader.ReadBytes(4);
                authTicket.appID = (int)binaryReader.ReadUInt32();
                uint   ownershipTicketExternalIP      = binaryReader.ReadUInt32();
                uint   ownershipTicketInternalIP      = binaryReader.ReadUInt32();
                uint   ownershipFlags                 = binaryReader.ReadUInt32();
                double ownershipTicketGeneratednotday = (double)binaryReader.ReadUInt32() * 1000;
                authTicket.ownershipTicketGenerated = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ownershipTicketGeneratednotday).ToLocalTime();
                double ownershipTicketExpiresnotday = (double)binaryReader.ReadUInt32() * 1000;
                authTicket.ownershipTicketExpires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ownershipTicketExpiresnotday).ToLocalTime();

                ushort licenseCount = binaryReader.ReadUInt16();
                int[]  license      = new int[licenseCount];
                for (int i = 0; i < licenseCount; i++)
                {
                    license[i] = (int)binaryReader.ReadUInt32();
                }
                authTicket.licences = license;
                ushort          dlcCount       = binaryReader.ReadUInt16();
                AuthTicketDlc[] authTicketDlcs = new AuthTicketDlc[dlcCount];
                for (int i = 0; i < dlcCount; i++)
                {
                    authTicketDlcs[i].appID = (int)binaryReader.ReadUInt32();
                    licenseCount            = binaryReader.ReadUInt16();
                    int[] dlclicenses = new int[licenseCount];
                    for (int h = 0; h < licenseCount; h++)
                    {
                        dlclicenses[h] = (int)binaryReader.ReadUInt32();
                    }
                    authTicketDlcs[i].licenses = dlclicenses;
                }
                authTicket.dlcs = authTicketDlcs;
                binaryReader.ReadBytes(2);
                if (binaryReader.BaseStream.Position + 128 == binaryReader.BaseStream.Length)
                {
                    authTicket.signature = binaryReader.ReadBytes((int)(binaryReader.BaseStream.Position + 128));
                }

                String             Ticketresponse = client.GetAsync("https://api.steampowered.com/ISteamUserAuth/AuthenticateUserTicket/v1/?key=BB147E811A8CEA5DFEFEA578D7105230&appid=700330&ticket=" + GetSteamAuthTicket(ticket)).Result.Content.ReadAsStringAsync().Result;
                AuthenticateTicket ticketjson     = AuthenticateTicket.FromJson(Ticketresponse);
                bool hasValidSignature            = true;
                if (ticketjson.Response.Params != null)
                {
                    hasValidSignature    = ticketjson.Response.Params.Result == "OK";
                    authTicket.SteamID64 = long.Parse(ticketjson.Response.Params.Ownersteamid);
                }
                else
                {
                    return(new AuthTicket());
                }

                String   userInfoResponse = client.GetAsync("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=BB147E811A8CEA5DFEFEA578D7105230&steamids=" + ticketjson.Response.Params.Ownersteamid).Result.Content.ReadAsStringAsync().Result;
                UserInfo info             = UserInfo.FromJson(userInfoResponse);
                authTicket.nickname  = info.Response.Players[0].Personaname;
                authTicket.isExpired = authTicket.ownershipTicketExpires < DateTime.Now;
                authTicket.isValid   = !authTicket.isExpired & hasValidSignature;



                return(authTicket);
            }
            return(new AuthTicket());
        }