Skip to content

Commit

Permalink
Use SteamContent GetCDNAuthToken
Browse files Browse the repository at this point in the history
  • Loading branch information
oureveryday committed Oct 12, 2024
1 parent 4ec75fb commit 651d08c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
9 changes: 8 additions & 1 deletion SteamKit2/SteamKit2/Steam/Handlers/SteamApps/Callbacks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This file is subject to the terms and conditions defined in
* file 'license.txt', which is part of this source code package.
*/
Expand Down Expand Up @@ -793,6 +793,13 @@ internal CDNAuthTokenCallback( IPacketMsg packetMsg )
Token = msg.token;
Expiration = DateUtils.DateTimeFromUnixTime( msg.expiration_time );
}

internal CDNAuthTokenCallback(CContentServerDirectory_GetCDNAuthToken_Response response)
{
Result = EResult.OK;
Token = response.token;
Expiration = DateUtils.DateTimeFromUnixTime(response.expiration_time);
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This file is subject to the terms and conditions defined in
* file 'license.txt', which is part of this source code package.
*/
Expand Down
31 changes: 30 additions & 1 deletion SteamKit2/SteamKit2/Steam/Handlers/SteamContent/SteamContent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This file is subject to the terms and conditions defined in
* file 'license.txt', which is part of this source code package.
*/
Expand All @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using SteamKit2.Internal;
using static SteamKit2.SteamApps;

namespace SteamKit2
{
Expand Down Expand Up @@ -91,6 +92,34 @@ 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="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 async Task<CDNAuthTokenCallback> 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));
var response = message.GetDeserializedResponse<CContentServerDirectory_GetCDNAuthToken_Response>();

return new CDNAuthTokenCallback(response);
}

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

0 comments on commit 651d08c

Please sign in to comment.