From 63f2e78b3377e4b364b2361ddcd4439078d140f8 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 16 Oct 2024 10:50:12 +0300 Subject: [PATCH] Allow awaiting LogOn --- .../Steam/Handlers/SteamUser/Callbacks.cs | 4 +++ .../Steam/Handlers/SteamUser/SteamUser.cs | 28 ++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/Callbacks.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/Callbacks.cs index 3c0745877..f3f2e75ba 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/Callbacks.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/Callbacks.cs @@ -120,6 +120,7 @@ internal LoggedOnCallback( IPacketMsg packetMsg ) var logonResp = new ClientMsgProtobuf( packetMsg ); var resp = logonResp.Body; + this.JobID = logonResp.TargetJobID; this.Result = ( EResult )resp.eresult; this.ExtendedResult = ( EResult )resp.eresult_extended; @@ -161,6 +162,7 @@ private void HandleNonProtoLogon( IPacketMsg packetMsg ) var logonResp = new ClientMsg( packetMsg ); var resp = logonResp.Body; + this.JobID = logonResp.TargetJobID; this.Result = resp.Result; this.OutOfGameSecsPerHeartbeat = resp.OutOfGameHeartbeatRateSec; @@ -197,11 +199,13 @@ internal LoggedOffCallback( IPacketMsg packetMsg ) if ( packetMsg.IsProto ) { var loggedOff = new ClientMsgProtobuf( packetMsg ); + this.JobID = loggedOff.TargetJobID; this.Result = ( EResult )loggedOff.Body.eresult; } else { var loggedOff = new ClientMsg( packetMsg ); + this.JobID = loggedOff.TargetJobID; this.Result = loggedOff.Body.Result; } } diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs index f073dd837..b35d67c62 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs @@ -222,7 +222,8 @@ public SteamID? SteamID /// The details to use for logging on. /// No logon details were provided. /// Username or password are not set within . - public void LogOn( LogOnDetails details ) + /// The Job ID of the request. This can be used to find the appropriate . + public AsyncJob LogOn( LogOnDetails details ) { ArgumentNullException.ThrowIfNull( details ); @@ -231,14 +232,14 @@ public void LogOn( LogOnDetails details ) throw new ArgumentException( "LogOn requires a username and password or access token to be set in 'details'." ); } + var logon = new ClientMsgProtobuf( EMsg.ClientLogon ); + if ( !this.Client.IsConnected ) { this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) ); - return; + return new AsyncJob( this.Client, logon.SourceJobID ); } - var logon = new ClientMsgProtobuf( EMsg.ClientLogon ); - SteamID steamId = new SteamID( details.AccountID, details.AccountInstance, Client.Universe, EAccountType.Individual ); if ( details.LoginID.HasValue ) @@ -302,6 +303,8 @@ public void LogOn( LogOnDetails details ) logon.Body.access_token = details.AccessToken; this.Client.Send( logon ); + + return new AsyncJob( this.Client, logon.SourceJobID ); } /// @@ -309,9 +312,10 @@ public void LogOn( LogOnDetails details ) /// The client should already have been connected at this point. /// Results are returned in a . /// - public void LogOnAnonymous() + /// The Job ID of the request. This can be used to find the appropriate . + public AsyncJob LogOnAnonymous() { - LogOnAnonymous( new AnonymousLogOnDetails() ); + return LogOnAnonymous( new AnonymousLogOnDetails() ); } /// /// Logs the client into the Steam3 network as an anonymous user. @@ -319,17 +323,19 @@ public void LogOnAnonymous() /// Results are returned in a . /// /// The details to use for logging on. - public void LogOnAnonymous( AnonymousLogOnDetails details ) + /// The Job ID of the request. This can be used to find the appropriate . + public AsyncJob LogOnAnonymous( AnonymousLogOnDetails details ) { ArgumentNullException.ThrowIfNull( details ); + var logon = new ClientMsgProtobuf( EMsg.ClientLogon ); + if ( !this.Client.IsConnected ) { this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) ); - return; - } - var logon = new ClientMsgProtobuf( EMsg.ClientLogon ); + return new AsyncJob( this.Client, logon.SourceJobID ); + } SteamID auId = new SteamID( 0, 0, Client.Universe, EAccountType.AnonUser ); @@ -344,6 +350,8 @@ public void LogOnAnonymous( AnonymousLogOnDetails details ) logon.Body.machine_id = HardwareUtils.GetMachineID( Client.Configuration.MachineInfoProvider ); this.Client.Send( logon ); + + return new AsyncJob( this.Client, logon.SourceJobID ); } ///