GetAuthSessionTicket() public static method

Retrieve ticket to be sent to the entity who wishes to authenticate you.

pcbTicket retrieves the length of the actual ticket.

public static GetAuthSessionTicket ( byte pTicket, int cbMaxTicket, uint &pcbTicket ) : HAuthTicket
pTicket byte
cbMaxTicket int
pcbTicket uint
return HAuthTicket
Exemplo n.º 1
0
        public void AuthSession()
        {
            var ticket = SteamUser.GetAuthSessionTicket();

            Assert.AreNotEqual(0, ticket.Handle);
            Assert.AreNotEqual(0, ticket.Data.Length);
            Console.WriteLine($"ticket.Handle: {ticket.Handle}");
            Console.WriteLine($"ticket.Data: { string.Join( "", ticket.Data.Select( x => x.ToString( "x" ) ) ) }");

            var result = SteamUser.BeginAuthSession(ticket.Data, SteamClient.SteamId);

            Console.WriteLine($"result: { result }");
            Assert.AreEqual(result, BeginAuthResult.OK);

            SteamUser.EndAuthSession(SteamClient.SteamId);
        }
Exemplo n.º 2
0
        public override byte[] OpenTicket()
        {
            uint size;

            if (_ticketHandle != HAuthTicket.Invalid)
            {
                return(null);
            }
            byte[] pTicket = new byte[1024];
            _ticketHandle = SteamUser.GetAuthSessionTicket(pTicket, pTicket.Length, out size);
            if (size == 0)
            {
                return(null);
            }
            byte[] dst = new byte[size];
            System.Buffer.BlockCopy(pTicket, 0, dst, 0, (int)size);
            _ticketOpened = true;
            return(dst);
        }
        public async Task BeginAuthSession()
        {
            var          stopwatch = System.Diagnostics.Stopwatch.StartNew();
            bool         finished  = false;
            string       failed    = null;
            AuthResponse response  = AuthResponse.AuthTicketInvalidAlreadyUsed;

            //
            // Clientside calls this function, gets ticket
            //
            var clientTicket = SteamUser.GetAuthSessionTicket();

            //
            // The client sends this data to the server along with their steamid
            //
            var ticketData    = clientTicket.Data;
            var clientSteamId = SteamClient.SteamId;

            //
            // Server listens to auth responses from Gabe
            //
            SteamServer.OnValidateAuthTicketResponse += (steamid, ownerid, rsponse) =>
            {
                finished = true;
                response = rsponse;

                if (steamid == 0)
                {
                    failed = $"steamid is 0! {steamid} != {ownerid} ({rsponse})";
                }

                if (ownerid == 0)
                {
                    failed = $"ownerid is 0! {steamid} != {ownerid} ({rsponse})";
                }

                if (steamid != ownerid)
                {
                    failed = $"Steamid and Ownerid are different! {steamid} != {ownerid} ({rsponse})";
                }
            };

            //
            // Server gets the ticket, starts authing
            //
            if (!SteamServer.BeginAuthSession(ticketData, clientSteamId))
            {
                Assert.Fail("BeginAuthSession returned false, called bullshit without even having to check with Gabe");
            }

            //
            // Wait for that to go through steam
            //
            while (!finished)
            {
                if (stopwatch.Elapsed.TotalSeconds > 5)
                {
                    throw new System.Exception("Took too long waiting for AuthSessionResponse.OK");
                }

                await Task.Delay(10);
            }

            Assert.AreEqual(response, AuthResponse.OK);

            if (failed != null)
            {
                Assert.Fail(failed);
            }

            finished  = false;
            stopwatch = System.Diagnostics.Stopwatch.StartNew();

            //
            // The client is leaving, and now wants to cancel the ticket
            //

            Assert.AreNotEqual(0, clientTicket.Handle);
            clientTicket.Cancel();

            //
            // We should get another callback
            //
            while (!finished)
            {
                if (stopwatch.Elapsed.TotalSeconds > 5)
                {
                    throw new System.Exception("Took too long waiting for AuthSessionResponse.AuthTicketCanceled");
                }

                await Task.Delay(10);
            }

            if (failed != null)
            {
                Assert.Fail(failed);
            }

            //Assert.AreEqual( response, AuthResponse.AuthTicketCanceled );
        }