diff --git a/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/SteamApps.java b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/SteamApps.java index cb29e624..46d4b042 100644 --- a/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/SteamApps.java +++ b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/SteamApps.java @@ -45,6 +45,18 @@ public void accept(IPacketMsg packetMsg) { handleFreeLicense(packetMsg); } }); + dispatchMap.put(EMsg.ClientPurchaseResponse, new Consumer() { + @Override + public void accept(IPacketMsg packetMsg) { + handlePurchaseResponse(packetMsg); + } + }); + dispatchMap.put(EMsg.ClientRedeemGuestPassResponse, new Consumer() { + @Override + public void accept(IPacketMsg packetMsg) { + handleRedeemGuestPassResponse(packetMsg); + } + }); dispatchMap.put(EMsg.ClientGameConnectTokens, new Consumer() { @Override public void accept(IPacketMsg packetMsg) { @@ -522,6 +534,20 @@ private void handleFreeLicense(IPacketMsg packetMsg) { client.postCallback(new FreeLicenseCallback(grantedLicenses.getTargetJobID(), grantedLicenses.getBody())); } + private void handlePurchaseResponse(IPacketMsg packetMsg) { + ClientMsgProtobuf callback = + new ClientMsgProtobuf<>(CMsgClientPurchaseResponse.class, packetMsg); + + client.postCallback(new PurchaseResponseCallback(callback.getTargetJobID(), callback.getBody())); + } + + private void handleRedeemGuestPassResponse(IPacketMsg packetMsg) { + ClientMsgProtobuf callback = + new ClientMsgProtobuf<>(CMsgClientRedeemGuestPassResponse.class, packetMsg); + + client.postCallback(new RedeemGuestPassResponseCallback(callback.getTargetJobID(), callback.getBody())); + } + private void handleVACBanStatus(IPacketMsg packetMsg) { ClientMsg vacStatus = new ClientMsg<>(MsgClientVACBanStatus.class, packetMsg); diff --git a/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/callback/PurchaseResponseCallback.java b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/callback/PurchaseResponseCallback.java new file mode 100644 index 00000000..5afca160 --- /dev/null +++ b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/callback/PurchaseResponseCallback.java @@ -0,0 +1,60 @@ +package in.dragonbra.javasteam.steam.handlers.steamapps.callback; + +import in.dragonbra.javasteam.enums.EPurchaseResultDetail; +import in.dragonbra.javasteam.enums.EResult; +import in.dragonbra.javasteam.protobufs.steamclient.SteammessagesClientserver2.CMsgClientPurchaseResponse; +import in.dragonbra.javasteam.steam.steamclient.callbackmgr.CallbackMsg; +import in.dragonbra.javasteam.types.JobID; +import in.dragonbra.javasteam.types.KeyValue; +import in.dragonbra.javasteam.util.stream.MemoryStream; + +import java.io.IOException; + +public class PurchaseResponseCallback extends CallbackMsg { + + private EResult result; + + private EPurchaseResultDetail purchaseResultDetail; + + private KeyValue purchaseReceiptInfo; + + public PurchaseResponseCallback(JobID jobID, CMsgClientPurchaseResponse.Builder msg) { + setJobID(jobID); + + this.result = EResult.from(msg.getEresult()); + this.purchaseResultDetail = EPurchaseResultDetail.from(msg.getPurchaseResultDetails()); + this.purchaseReceiptInfo = new KeyValue(); + + if (msg.getPurchaseReceiptInfo() == null) { + return; + } + + try { + MemoryStream ms = new MemoryStream(msg.getPurchaseReceiptInfo().toByteArray()); + this.purchaseReceiptInfo.tryReadAsBinary(ms); + } catch (IOException exception) { + throw new IllegalArgumentException("input stream is null"); + } + } + + /** + * @return Result of the operation + */ + public EResult getResult() { + return result; + } + + /** + * @return Purchase result of the operation + */ + public EPurchaseResultDetail getPurchaseResultDetail() { + return purchaseResultDetail; + } + + /** + * @return Purchase receipt of the operation + */ + public KeyValue getPurchaseReceiptInfo() { + return purchaseReceiptInfo; + } +} diff --git a/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/callback/RedeemGuestPassResponseCallback.java b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/callback/RedeemGuestPassResponseCallback.java new file mode 100644 index 00000000..f6c3859f --- /dev/null +++ b/src/main/java/in/dragonbra/javasteam/steam/handlers/steamapps/callback/RedeemGuestPassResponseCallback.java @@ -0,0 +1,44 @@ +package in.dragonbra.javasteam.steam.handlers.steamapps.callback; + +import in.dragonbra.javasteam.enums.EResult; +import in.dragonbra.javasteam.protobufs.steamclient.SteammessagesClientserver2.CMsgClientRedeemGuestPassResponse; +import in.dragonbra.javasteam.steam.steamclient.callbackmgr.CallbackMsg; +import in.dragonbra.javasteam.types.JobID; + +public class RedeemGuestPassResponseCallback extends CallbackMsg { + + private EResult result; + + private Integer packageID; + + private Integer mustOwnAppID; + + public RedeemGuestPassResponseCallback(JobID jobID, CMsgClientRedeemGuestPassResponse.Builder msg) { + setJobID(jobID); + + this.result = EResult.from(msg.getEresult()); + this.packageID = msg.getPackageId(); + this.mustOwnAppID = msg.getMustOwnAppid(); + } + + /** + * @return Result of the operation + */ + public EResult getResult() { + return result; + } + + /** + * @return Result of the operation + */ + public Integer getPackageID() { + return packageID; + } + + /** + * @return App ID which must be owned to activate this guest pass. + */ + public Integer getMustOwnAppID() { + return mustOwnAppID; + } +}