Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,24 @@ public sealed class StatusDetails
/// <param name="details">The details to use for logging on.</param>
/// <exception cref="System.ArgumentNullException">No logon details were provided.</exception>
/// <exception cref="System.ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
public void LogOn( LogOnDetails details )
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="SteamUser.LoggedOnCallback"/>.</returns>
public AsyncJob<SteamUser.LoggedOnCallback> LogOn( LogOnDetails details )
{
ArgumentNullException.ThrowIfNull( details );

if ( string.IsNullOrEmpty( details.Token ) )
{
throw new ArgumentException( "LogOn requires a game server token to be set in 'details'." );
}


var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogonGameServer );

if ( !this.Client.IsConnected )
{
this.Client.PostCallback( new SteamUser.LoggedOnCallback( EResult.NoConnection ) );
return;
this.Client.PostCallback( new SteamUser.LoggedOnCallback( EResult.NoConnection, logon.SourceJobID ) );
return new AsyncJob<SteamUser.LoggedOnCallback>( this.Client, logon.SourceJobID );
}

var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogonGameServer );

SteamID gsId = new SteamID( 0, 0, Client.Universe, EAccountType.GameServer );

logon.ProtoHeader.client_sessionid = 0;
Expand All @@ -121,6 +122,8 @@ public void LogOn( LogOnDetails details )
logon.Body.game_server_token = details.Token;

this.Client.Send( logon );

return new AsyncJob<SteamUser.LoggedOnCallback>( this.Client, logon.SourceJobID );
}

/// <summary>
Expand All @@ -129,16 +132,17 @@ public void LogOn( LogOnDetails details )
/// Results are returned in a <see cref="SteamUser.LoggedOnCallback"/>.
/// </summary>
/// <param name="appId">The AppID served by this game server, or 0 for the default.</param>
public void LogOnAnonymous( uint appId = 0 )
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="SteamUser.LoggedOnCallback"/>.</returns>
public AsyncJob<SteamUser.LoggedOnCallback> LogOnAnonymous( uint appId = 0 )
{
var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );

if ( !this.Client.IsConnected )
{
this.Client.PostCallback( new SteamUser.LoggedOnCallback( EResult.NoConnection ) );
return;
this.Client.PostCallback( new SteamUser.LoggedOnCallback( EResult.NoConnection, logon.SourceJobID ) );
return new AsyncJob<SteamUser.LoggedOnCallback>( this.Client, logon.SourceJobID );
}

var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );

SteamID gsId = new SteamID( 0, 0, Client.Universe, EAccountType.AnonGameServer );

logon.ProtoHeader.client_sessionid = 0;
Expand All @@ -153,6 +157,8 @@ public void LogOnAnonymous( uint appId = 0 )
logon.Body.machine_id = HardwareUtils.GetMachineID( Client.Configuration.MachineInfoProvider );

this.Client.Send( logon );

return new AsyncJob<SteamUser.LoggedOnCallback>( this.Client, logon.SourceJobID );
}

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion SteamKit2/SteamKit2/Steam/Handlers/SteamUser/Callbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ internal LoggedOnCallback( IPacketMsg packetMsg )
var logonResp = new ClientMsgProtobuf<CMsgClientLogonResponse>( packetMsg );
var resp = logonResp.Body;

this.JobID = logonResp.TargetJobID;
this.Result = ( EResult )resp.eresult;
this.ExtendedResult = ( EResult )resp.eresult_extended;

Expand Down Expand Up @@ -167,6 +168,7 @@ private void HandleNonProtoLogon( IPacketMsg packetMsg )
var logonResp = new ClientMsg<MsgClientLogOnResponse>( packetMsg );
var resp = logonResp.Body;

this.JobID = logonResp.TargetJobID;
this.Result = resp.Result;

this.OutOfGameSecsPerHeartbeat = resp.OutOfGameHeartbeatRateSec;
Expand All @@ -180,8 +182,9 @@ private void HandleNonProtoLogon( IPacketMsg packetMsg )
}


internal LoggedOnCallback( EResult result )
internal LoggedOnCallback( EResult result, JobID jobId )
{
this.JobID = jobId;
this.Result = result;
}
}
Expand All @@ -203,11 +206,13 @@ internal LoggedOffCallback( IPacketMsg packetMsg )
if ( packetMsg.IsProto )
{
var loggedOff = new ClientMsgProtobuf<CMsgClientLoggedOff>( packetMsg );
this.JobID = loggedOff.TargetJobID;
this.Result = ( EResult )loggedOff.Body.eresult;
}
else
{
var loggedOff = new ClientMsg<MsgClientLoggedOff>( packetMsg );
this.JobID = loggedOff.TargetJobID;
this.Result = loggedOff.Body.Result;
}
}
Expand Down
31 changes: 19 additions & 12 deletions SteamKit2/SteamKit2/Steam/Handlers/SteamUser/SteamUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ public SteamID? SteamID
/// <param name="details">The details to use for logging on.</param>
/// <exception cref="ArgumentNullException">No logon details were provided.</exception>
/// <exception cref="ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
public void LogOn( LogOnDetails details )
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="LoggedOnCallback"/>.</returns>
public AsyncJob<LoggedOnCallback> LogOn( LogOnDetails details )
{
ArgumentNullException.ThrowIfNull( details );

Expand All @@ -238,14 +239,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<CMsgClientLogon>( EMsg.ClientLogon );

if ( !this.Client.IsConnected )
{
this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) );
return;
this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection, logon.SourceJobID ) );
return new AsyncJob<LoggedOnCallback>( this.Client, logon.SourceJobID );
}

var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );

SteamID steamId = new SteamID( details.AccountID, details.AccountInstance, Client.Universe, EAccountType.Individual );

if ( details.LoginID.HasValue )
Expand Down Expand Up @@ -316,35 +317,39 @@ public void LogOn( LogOnDetails details )
logon.Body.access_token = details.AccessToken;

this.Client.Send( logon );

return new AsyncJob<LoggedOnCallback>( this.Client, logon.SourceJobID );
}

/// <summary>
/// Logs the client into the Steam3 network as an anonymous user.
/// The client should already have been connected at this point.
/// Results are returned in a <see cref="LoggedOnCallback"/>.
/// </summary>
public void LogOnAnonymous()
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="LoggedOnCallback"/>.</returns>
public AsyncJob<LoggedOnCallback> LogOnAnonymous()
{
LogOnAnonymous( new AnonymousLogOnDetails() );
return LogOnAnonymous( new AnonymousLogOnDetails() );
}
/// <summary>
/// Logs the client into the Steam3 network as an anonymous user.
/// The client should already have been connected at this point.
/// Results are returned in a <see cref="LoggedOnCallback"/>.
/// </summary>
/// <param name="details">The details to use for logging on.</param>
public void LogOnAnonymous( AnonymousLogOnDetails details )
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="LoggedOnCallback"/>.</returns>
public AsyncJob<LoggedOnCallback> LogOnAnonymous( AnonymousLogOnDetails details )
{
ArgumentNullException.ThrowIfNull( details );

var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );

if ( !this.Client.IsConnected )
{
this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) );
return;
this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection, logon.SourceJobID ) );
return new AsyncJob<LoggedOnCallback>( this.Client, logon.SourceJobID );
}

var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );

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

logon.ProtoHeader.client_sessionid = 0;
Expand All @@ -358,6 +363,8 @@ public void LogOnAnonymous( AnonymousLogOnDetails details )
logon.Body.machine_id = HardwareUtils.GetMachineID( Client.Configuration.MachineInfoProvider );

this.Client.Send( logon );

return new AsyncJob<LoggedOnCallback>( this.Client, logon.SourceJobID );
}

/// <summary>
Expand Down
8 changes: 5 additions & 3 deletions SteamKit2/Tests/SteamGameServerFacts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SteamKit2;
using SteamKit2;
using Xunit;

namespace Tests
Expand All @@ -8,7 +8,7 @@ public class SteamGameServerFacts : HandlerTestBase<SteamGameServer>
[Fact]
public void LogOnPostsLoggedOnCallbackWhenNoConnection()
{
Handler.LogOn(new SteamGameServer.LogOnDetails
var asyncJob = Handler.LogOn(new SteamGameServer.LogOnDetails
{
Token = "SuperSecretToken"
});
Expand All @@ -19,19 +19,21 @@ public void LogOnPostsLoggedOnCallbackWhenNoConnection()

var loc = (SteamUser.LoggedOnCallback)callback;
Assert.Equal( EResult.NoConnection, loc.Result );
Assert.Equal( asyncJob.JobID, loc.JobID );
}

[Fact]
public void LogOnAnonymousPostsLoggedOnCallbackWhenNoConnection()
{
Handler.LogOnAnonymous();
var asyncJob = Handler.LogOnAnonymous();

var callback = SteamClient.GetCallback( );
Assert.NotNull( callback );
Assert.IsType<SteamUser.LoggedOnCallback>( callback );

var loc = (SteamUser.LoggedOnCallback)callback;
Assert.Equal( EResult.NoConnection, loc.Result );
Assert.Equal( asyncJob.JobID, loc.JobID );
}
}
}
10 changes: 6 additions & 4 deletions SteamKit2/Tests/SteamUserFacts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using SteamKit2;
using Xunit;

Expand All @@ -9,7 +9,7 @@ public class SteamUserFacts : HandlerTestBase<SteamUser>
[Fact]
public void LogOnPostsLoggedOnCallbackWhenNoConnection()
{
Handler.LogOn(new SteamUser.LogOnDetails
var asyncJob = Handler.LogOn(new SteamUser.LogOnDetails
{
Username = "iamauser",
Password = "lamepassword"
Expand All @@ -21,6 +21,7 @@ public void LogOnPostsLoggedOnCallbackWhenNoConnection()

var loc = (SteamUser.LoggedOnCallback)callback;
Assert.Equal( EResult.NoConnection, loc.Result );
Assert.Equal( asyncJob.JobID, loc.JobID );
}

[Fact]
Expand Down Expand Up @@ -82,7 +83,7 @@ public void LogOnDoesNotThrowExceptionIfUserNameAndPasswordProvided()

Assert.Null( ex );
}

[Fact]
public void LogOnDoesNotThrowExceptionIfUserNameAndAccessTokenProvided()
{
Expand All @@ -102,14 +103,15 @@ public void LogOnDoesNotThrowExceptionIfUserNameAndAccessTokenProvided()
[Fact]
public void LogOnAnonymousPostsLoggedOnCallbackWhenNoConnection()
{
Handler.LogOnAnonymous();
var asyncJob = Handler.LogOnAnonymous();

var callback = SteamClient.GetCallback( );
Assert.NotNull( callback );
Assert.IsType<SteamUser.LoggedOnCallback>( callback );

var loc = (SteamUser.LoggedOnCallback)callback;
Assert.Equal( EResult.NoConnection, loc.Result );
Assert.Equal( asyncJob.JobID, loc.JobID );
}
}
}
Loading