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

Add PurchaseResponseCallback and RedeemGuestPassResponseCallback #1033

Merged
merged 1 commit into from
Oct 24, 2021
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
80 changes: 72 additions & 8 deletions SteamKit2/SteamKit2/Steam/Handlers/SteamApps/Callbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ internal VACStatusCallback( MsgClientVACBanStatus msg, byte[] payload )
using ( var ms = new MemoryStream( payload ) )
using ( var br = new BinaryReader( ms ) )
{
for ( int x = 0 ; x < msg.NumBans ; x++ )
for ( int x = 0; x < msg.NumBans; x++ )
{
tempList.Add( br.ReadUInt32() );
}
Expand Down Expand Up @@ -481,7 +481,7 @@ public sealed class PICSProductInfo
/// </summary>
public Uri? HttpUri { get; private set; }

internal PICSProductInfo( CMsgClientPICSProductInfoResponse parentResponse, CMsgClientPICSProductInfoResponse.AppInfo app_info)
internal PICSProductInfo( CMsgClientPICSProductInfoResponse parentResponse, CMsgClientPICSProductInfoResponse.AppInfo app_info )
{
this.ID = app_info.appid;
this.ChangeNumber = app_info.change_number;
Expand All @@ -502,13 +502,13 @@ internal PICSProductInfo( CMsgClientPICSProductInfoResponse parentResponse, CMsg
this.OnlyPublic = app_info.only_public;

// We should have all these fields set for the response to a metadata-only request, but guard here just in case.
if (this.SHAHash != null && this.SHAHash.Length > 0 && !string.IsNullOrEmpty(parentResponse.http_host))
if ( this.SHAHash != null && this.SHAHash.Length > 0 && !string.IsNullOrEmpty( parentResponse.http_host ) )
{
var shaString = BitConverter.ToString(this.SHAHash)
.Replace("-", string.Empty)
var shaString = BitConverter.ToString( this.SHAHash )
.Replace( "-", string.Empty )
.ToLower();
var uriString = string.Format("http://{0}/appinfo/{1}/sha/{2}.txt.gz", parentResponse.http_host, this.ID, shaString);
this.HttpUri = new Uri(uriString);
var uriString = string.Format( "http://{0}/appinfo/{1}/sha/{2}.txt.gz", parentResponse.http_host, this.ID, shaString );
this.HttpUri = new Uri( uriString );
}

this.UseHttp = this.HttpUri != null && app_info.size >= parentResponse.http_min_size;
Expand All @@ -532,7 +532,7 @@ internal PICSProductInfo( CMsgClientPICSProductInfoResponse.PackageInfo package_
// see: CPackageInfo::UpdateFromBuffer(CSHA const&,uint,CUtlBuffer &)
// todo: we've apparently ignored this with zero ill effects, but perhaps we want to respect it?
br.ReadUInt32();

this.KeyValues.TryReadAsBinary( ms );
}
}
Expand Down Expand Up @@ -627,6 +627,70 @@ internal GuestPassListCallback( MsgClientUpdateGuestPassesList msg, Stream paylo
}
}

/// <summary>
/// This callback is received in response to activating a guest pass or a gift.
/// </summary>
public sealed class RedeemGuestPassResponseCallback : CallbackMsg
{
/// <summary>
/// Result of the operation
/// </summary>
public EResult Result { get; set; }
/// <summary>
/// Package ID which was activated.
/// </summary>
public uint PackageID { get; set; }
/// <summary>
/// App ID which must be owned to activate this guest pass.
/// </summary>
public uint MustOwnAppID { get; set; }


internal RedeemGuestPassResponseCallback( JobID jobID, CMsgClientRedeemGuestPassResponse msg )
{
JobID = jobID;
Result = ( EResult )msg.eresult;
PackageID = msg.package_id;
MustOwnAppID = msg.must_own_appid;
}
}

/// <summary>
/// This callback is received in a response to activating a Steam key.
/// </summary>
public sealed class PurchaseResponseCallback : CallbackMsg
{
/// <summary>
/// Result of the operation
/// </summary>
public EResult Result { get; set; }
/// <summary>
/// Purchase result of the operation
/// </summary>
public EPurchaseResultDetail PurchaseResultDetail { get; set; }
/// <summary>
/// Purchase receipt of the operation
/// </summary>
public KeyValue PurchaseReceiptInfo { get; set; }


internal PurchaseResponseCallback( JobID jobID, CMsgClientPurchaseResponse msg )
{
JobID = jobID;
Result = ( EResult )msg.eresult;
PurchaseResultDetail = ( EPurchaseResultDetail )msg.purchase_result_details;
PurchaseReceiptInfo = new KeyValue();

if ( msg.purchase_receipt_info == null )
{
return;
}

using var ms = new MemoryStream( msg.purchase_receipt_info );
PurchaseReceiptInfo.TryReadAsBinary( ms );
yaakov-h marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// <summary>
/// This callback is received when a CDN auth token is received
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ internal SteamApps()
{
{ EMsg.ClientLicenseList, HandleLicenseList },
{ EMsg.ClientRequestFreeLicenseResponse, HandleFreeLicense },
{ EMsg.ClientPurchaseResponse, HandlePurchaseResponse },
{ EMsg.ClientRedeemGuestPassResponse, HandleRedeemGuestPassResponse },
{ EMsg.ClientGameConnectTokens, HandleGameConnectTokens },
{ EMsg.ClientVACBanStatus, HandleVACBanStatus },
{ EMsg.ClientGetAppOwnershipTicketResponse, HandleAppOwnershipTicketResponse },
Expand Down Expand Up @@ -379,6 +381,20 @@ void HandleFreeLicense( IPacketMsg packetMsg )
var callback = new FreeLicenseCallback( grantedLicenses.TargetJobID, grantedLicenses.Body );
this.Client.PostCallback( callback );
}
void HandlePurchaseResponse( IPacketMsg packetMsg )
{
var purchaseResponse = new ClientMsgProtobuf<CMsgClientPurchaseResponse>( packetMsg );

var callback = new PurchaseResponseCallback( purchaseResponse.TargetJobID, purchaseResponse.Body );
this.Client.PostCallback( callback );
}
void HandleRedeemGuestPassResponse( IPacketMsg packetMsg )
{
var redeemedGuestPass = new ClientMsgProtobuf<CMsgClientRedeemGuestPassResponse>( packetMsg );

var callback = new RedeemGuestPassResponseCallback( redeemedGuestPass.TargetJobID, redeemedGuestPass.Body );
this.Client.PostCallback( callback );
}
void HandleVACBanStatus( IPacketMsg packetMsg )
{
var vacStatus = new ClientMsg<MsgClientVACBanStatus>( packetMsg );
Expand Down