Skip to content

Commit

Permalink
Move GetCDNAuthToken to SteamContent
Browse files Browse the repository at this point in the history
Fixes #1447
  • Loading branch information
oureveryday authored and xPaw committed Oct 13, 2024
1 parent 76163ad commit 453aa39
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 57 deletions.
4 changes: 2 additions & 2 deletions SteamKit2/SteamKit2/Steam/CDN/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Dispose()
/// This is used for decrypting filenames (if needed) in depot manifests.
/// </param>
/// <param name="proxyServer">Optional content server marked as UseAsProxy which transforms the request.</param>
/// <param name="cdnAuthToken">CDN auth token for CDN content server endpoints if necessary. Get one with <see cref="SteamApps.GetCDNAuthToken"/>.</param>
/// <param name="cdnAuthToken">CDN auth token for CDN content server endpoints if necessary. Get one with <see cref="SteamContent.GetCDNAuthToken"/>.</param>
/// <returns>A <see cref="DepotManifest"/> instance that contains information about the files present within a depot.</returns>
/// <exception cref="System.ArgumentNullException"><see ref="server"/> was null.</exception>
/// <exception cref="HttpRequestException">An network error occurred when performing the request.</exception>
Expand Down Expand Up @@ -196,7 +196,7 @@ public async Task<DepotManifest> DownloadManifestAsync( uint depotId, ulong mani
/// This is used to process the chunk data.
/// </param>
/// <param name="proxyServer">Optional content server marked as UseAsProxy which transforms the request.</param>
/// <param name="cdnAuthToken">CDN auth token for CDN content server endpoints if necessary. Get one with <see cref="SteamApps.GetCDNAuthToken"/>.</param>
/// <param name="cdnAuthToken">CDN auth token for CDN content server endpoints if necessary. Get one with <see cref="SteamContent.GetCDNAuthToken"/>.</param>
/// <exception cref="System.ArgumentNullException">chunk's <see cref="DepotManifest.ChunkData.ChunkID"/> was null.</exception>
/// <exception cref="System.IO.InvalidDataException">Thrown if the downloaded data does not match the expected length.</exception>
/// <exception cref="HttpRequestException">An network error occurred when performing the request.</exception>
Expand Down
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

0 comments on commit 453aa39

Please sign in to comment.