Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetCDNAuthToken after Steam change #1447

Closed
wants to merge 4 commits into from
Closed
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
31 changes: 0 additions & 31 deletions SteamKit2/SteamKit2/Steam/Handlers/SteamApps/Callbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,37 +764,6 @@ internal PurchaseResponseCallback( IPacketMsg packetMsg )
}
}

/// <summary>
/// This callback is received when a CDN auth token is received
/// </summary>
public sealed class CDNAuthTokenCallback : CallbackMsg
{
/// <summary>
/// Result of the operation
/// </summary>
public EResult Result { get; set; }
/// <summary>
/// CDN auth token
/// </summary>
public string Token { get; set; }
/// <summary>
/// Token expiration date
/// </summary>
public DateTime Expiration { get; set; }

internal CDNAuthTokenCallback( IPacketMsg packetMsg )
{
var response = new ClientMsgProtobuf<CMsgClientGetCDNAuthTokenResponse>( packetMsg );
var msg = response.Body;

JobID = response.TargetJobID;

Result = ( EResult )msg.eresult;
Token = msg.token;
Expiration = DateUtils.DateTimeFromUnixTime( msg.expiration_time );
}
}

/// <summary>
/// This callback is received when a beta password check has been completed
/// </summary>
Expand Down
24 changes: 0 additions & 24 deletions SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public PICSRequest( uint id = 0, ulong access_token = 0 )
EMsg.ClientPICSChangesSinceResponse => new PICSChangesCallback( packetMsg ),
EMsg.ClientPICSProductInfoResponse => new PICSProductInfoCallback( packetMsg ),
EMsg.ClientUpdateGuestPassesList => new GuestPassListCallback( packetMsg ),
EMsg.ClientGetCDNAuthTokenResponse => new CDNAuthTokenCallback( packetMsg ),
EMsg.ClientCheckAppBetaPasswordResponse => new CheckAppBetaPasswordCallback( packetMsg ),
_ => null,
};
Expand Down Expand Up @@ -231,29 +230,6 @@ public AsyncJobMultiple<PICSProductInfoCallback> PICSGetProductInfo( IEnumerable
}


/// <summary>
/// Request product information for an app or package
/// Results are returned in a <see cref="CDNAuthTokenCallback"/> callback.
/// The returned <see cref="AsyncJob{T}"/> can also be awaited to retrieve the callback result.
/// </summary>
/// <param name="app">App id requested.</param>
/// <param name="depot">Depot id requested.</param>
/// <param name="host_name">CDN host name being requested.</param>
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="CDNAuthTokenCallback"/>.</returns>
public AsyncJob<CDNAuthTokenCallback> GetCDNAuthToken( uint app, uint depot, string host_name )
{
var request = new ClientMsgProtobuf<CMsgClientGetCDNAuthToken>( EMsg.ClientGetCDNAuthToken );
request.SourceJobID = Client.GetNextJobID();

request.Body.app_id = app;
request.Body.depot_id = depot;
request.Body.host_name = host_name;

this.Client.Send( request );

return new AsyncJob<CDNAuthTokenCallback>( this.Client, request.SourceJobID );
}

/// <summary>
/// Request a free license for given appid, can be used for free on demand apps
/// Results are returned in a <see cref="FreeLicenseCallback"/> callback.
Expand Down
54 changes: 54 additions & 0 deletions SteamKit2/SteamKit2/Steam/Handlers/SteamContent/SteamContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ namespace SteamKit2
/// </summary>
public sealed class SteamContent : ClientMsgHandler
{
/// <summary>
/// This is received when a CDN auth token is received
/// </summary>
public sealed class CDNAuthToken
{
/// <summary>
/// Result of the operation
/// </summary>
public EResult Result { get; set; }
/// <summary>
/// CDN auth token
/// </summary>
public string Token { get; set; }
/// <summary>
/// Token expiration date
/// </summary>
public DateTime Expiration { get; set; }

internal CDNAuthToken( SteamUnifiedMessages.ServiceMethodResponse message )
{
var response = message.GetDeserializedResponse<CContentServerDirectory_GetCDNAuthToken_Response>();
Result = message.Result;
Token = response.token;
Expiration = DateUtils.DateTimeFromUnixTime( response.expiration_time );
}
}

/// <summary>
/// Load a list of servers from the Content Server Directory Service.
/// This is an alternative to <see cref="o:ContentServerDirectoryService.LoadAsync"></see>.
Expand Down Expand Up @@ -91,6 +118,33 @@ public async Task<ulong> GetManifestRequestCode( uint depotId, uint appId, ulong
return response.manifest_request_code;
}

/// <summary>
/// Request product information for an app or package
/// Results are returned in a <see cref="CDNAuthToken"/>.
/// The returned <see cref="AsyncJob{T}"/> can also be awaited to retrieve the result.
/// </summary>
/// <param name="app">App id requested.</param>
/// <param name="depot">Depot id requested.</param>
/// <param name="host_name">CDN host name being requested.</param>
/// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="CDNAuthToken"/>.</returns>
public async Task<CDNAuthToken> GetCDNAuthToken(uint app, uint depot, string host_name)
{
var request = new CContentServerDirectory_GetCDNAuthToken_Request
{
app_id = app,
depot_id = depot,
host_name = host_name,
};

// SendMessage is an AsyncJob, but we want to deserialize it
// can't really do HandleMsg because it requires parsing the service like its done in HandleServiceMethod
var unifiedMessages = Client.GetHandler<SteamUnifiedMessages>()!;
var contentService = unifiedMessages.CreateService<IContentServerDirectory>();
var message = await contentService.SendMessage(api => api.GetCDNAuthToken(request));

return new CDNAuthToken( message );
}

/// <summary>
/// Handles a client message. This should not be called directly.
/// </summary>
Expand Down
Loading