Skip to content

Commit 63f2e78

Browse files
committed
Allow awaiting LogOn
1 parent 9d25ce3 commit 63f2e78

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

SteamKit2/SteamKit2/Steam/Handlers/SteamUser/Callbacks.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ internal LoggedOnCallback( IPacketMsg packetMsg )
120120
var logonResp = new ClientMsgProtobuf<CMsgClientLogonResponse>( packetMsg );
121121
var resp = logonResp.Body;
122122

123+
this.JobID = logonResp.TargetJobID;
123124
this.Result = ( EResult )resp.eresult;
124125
this.ExtendedResult = ( EResult )resp.eresult_extended;
125126

@@ -161,6 +162,7 @@ private void HandleNonProtoLogon( IPacketMsg packetMsg )
161162
var logonResp = new ClientMsg<MsgClientLogOnResponse>( packetMsg );
162163
var resp = logonResp.Body;
163164

165+
this.JobID = logonResp.TargetJobID;
164166
this.Result = resp.Result;
165167

166168
this.OutOfGameSecsPerHeartbeat = resp.OutOfGameHeartbeatRateSec;
@@ -197,11 +199,13 @@ internal LoggedOffCallback( IPacketMsg packetMsg )
197199
if ( packetMsg.IsProto )
198200
{
199201
var loggedOff = new ClientMsgProtobuf<CMsgClientLoggedOff>( packetMsg );
202+
this.JobID = loggedOff.TargetJobID;
200203
this.Result = ( EResult )loggedOff.Body.eresult;
201204
}
202205
else
203206
{
204207
var loggedOff = new ClientMsg<MsgClientLoggedOff>( packetMsg );
208+
this.JobID = loggedOff.TargetJobID;
205209
this.Result = loggedOff.Body.Result;
206210
}
207211
}

SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ public SteamID? SteamID
222222
/// <param name="details">The details to use for logging on.</param>
223223
/// <exception cref="ArgumentNullException">No logon details were provided.</exception>
224224
/// <exception cref="ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
225-
public void LogOn( LogOnDetails details )
225+
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="LoggedOnCallback"/>.</returns>
226+
public AsyncJob<LoggedOnCallback> LogOn( LogOnDetails details )
226227
{
227228
ArgumentNullException.ThrowIfNull( details );
228229

@@ -231,14 +232,14 @@ public void LogOn( LogOnDetails details )
231232
throw new ArgumentException( "LogOn requires a username and password or access token to be set in 'details'." );
232233
}
233234

235+
var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );
236+
234237
if ( !this.Client.IsConnected )
235238
{
236239
this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) );
237-
return;
240+
return new AsyncJob<LoggedOnCallback>( this.Client, logon.SourceJobID );
238241
}
239242

240-
var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );
241-
242243
SteamID steamId = new SteamID( details.AccountID, details.AccountInstance, Client.Universe, EAccountType.Individual );
243244

244245
if ( details.LoginID.HasValue )
@@ -302,34 +303,39 @@ public void LogOn( LogOnDetails details )
302303
logon.Body.access_token = details.AccessToken;
303304

304305
this.Client.Send( logon );
306+
307+
return new AsyncJob<LoggedOnCallback>( this.Client, logon.SourceJobID );
305308
}
306309

307310
/// <summary>
308311
/// Logs the client into the Steam3 network as an anonymous user.
309312
/// The client should already have been connected at this point.
310313
/// Results are returned in a <see cref="LoggedOnCallback"/>.
311314
/// </summary>
312-
public void LogOnAnonymous()
315+
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="LoggedOnCallback"/>.</returns>
316+
public AsyncJob<LoggedOnCallback> LogOnAnonymous()
313317
{
314-
LogOnAnonymous( new AnonymousLogOnDetails() );
318+
return LogOnAnonymous( new AnonymousLogOnDetails() );
315319
}
316320
/// <summary>
317321
/// Logs the client into the Steam3 network as an anonymous user.
318322
/// The client should already have been connected at this point.
319323
/// Results are returned in a <see cref="LoggedOnCallback"/>.
320324
/// </summary>
321325
/// <param name="details">The details to use for logging on.</param>
322-
public void LogOnAnonymous( AnonymousLogOnDetails details )
326+
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="LoggedOnCallback"/>.</returns>
327+
public AsyncJob<LoggedOnCallback> LogOnAnonymous( AnonymousLogOnDetails details )
323328
{
324329
ArgumentNullException.ThrowIfNull( details );
325330

331+
var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );
332+
326333
if ( !this.Client.IsConnected )
327334
{
328335
this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) );
329-
return;
330-
}
331336

332-
var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );
337+
return new AsyncJob<LoggedOnCallback>( this.Client, logon.SourceJobID );
338+
}
333339

334340
SteamID auId = new SteamID( 0, 0, Client.Universe, EAccountType.AnonUser );
335341

@@ -344,6 +350,8 @@ public void LogOnAnonymous( AnonymousLogOnDetails details )
344350
logon.Body.machine_id = HardwareUtils.GetMachineID( Client.Configuration.MachineInfoProvider );
345351

346352
this.Client.Send( logon );
353+
354+
return new AsyncJob<LoggedOnCallback>( this.Client, logon.SourceJobID );
347355
}
348356

349357
/// <summary>

0 commit comments

Comments
 (0)