Skip to content

Commit

Permalink
Fix BillingService checks when buying items
Browse files Browse the repository at this point in the history
  • Loading branch information
Crypto137 committed Feb 17, 2024
1 parent 5c08ff9 commit 55edf4d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/MHServerEmu/Billing/BillingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,16 @@ private void OnBuyItemFromCatalog(FrontendClient client, NetMessageBuyItemFromCa
DBAvatar currentAvatar = client.Session.Account.CurrentAvatar;

CatalogEntry entry = _catalog.GetEntry(buyItemFromCatalog.SkuId);
if (entry == null && entry.GuidItems.Length == 0) return;
if (entry == null || entry.GuidItems.Length == 0)
{
SendBuyItemResponse(client, false, BuyItemResultErrorCodes.BUY_RESULT_ERROR_UNKNOWN, buyItemFromCatalog.SkuId);
return;
}

var costumePrototype = entry.GuidItems[0].ItemPrototypeRuntimeIdForClient.As<CostumePrototype>();
if (costumePrototype == null || costumePrototype.UsableBy != (PrototypeId)currentAvatar.Prototype)
{
client.SendMessage(MuxChannel, new(NetMessageBuyItemFromCatalogResponse.CreateBuilder()
.SetDidSucceed(false)
.SetCurrentCurrencyBalance(ConfigManager.Billing.CurrencyBalance)
.SetErrorcode(BuyItemResultErrorCodes.BUY_RESULT_ERROR_UNKNOWN)
.SetSkuId(buyItemFromCatalog.SkuId)
.Build()));
SendBuyItemResponse(client, false, BuyItemResultErrorCodes.BUY_RESULT_ERROR_UNKNOWN, buyItemFromCatalog.SkuId);
return;
}

Expand All @@ -137,11 +136,16 @@ private void OnBuyItemFromCatalog(FrontendClient client, NetMessageBuyItemFromCa
client.SendMessage(MuxChannel, new(
Property.ToNetMessageSetProperty(9078332, new(PropertyEnum.AvatarLibraryCostume, 0, enumValue), costumePrototype.DataRef)));

SendBuyItemResponse(client, true, BuyItemResultErrorCodes.BUY_RESULT_ERROR_SUCCESS, buyItemFromCatalog.SkuId);
}

private void SendBuyItemResponse(FrontendClient client, bool didSucceed, BuyItemResultErrorCodes errorCode, long skuId)
{
client.SendMessage(MuxChannel, new(NetMessageBuyItemFromCatalogResponse.CreateBuilder()
.SetDidSucceed(true)
.SetDidSucceed(didSucceed)
.SetCurrentCurrencyBalance(ConfigManager.Billing.CurrencyBalance)
.SetErrorcode(BuyItemResultErrorCodes.BUY_RESULT_ERROR_SUCCESS)
.SetSkuId(buyItemFromCatalog.SkuId)
.SetErrorcode(errorCode)
.SetSkuId(skuId)
.Build()));
}
}
Expand Down

0 comments on commit 55edf4d

Please sign in to comment.