@quenty/gameproductservice 14.56.0 → 14.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/package.json +6 -5
- package/src/Client/Cmdr/GameProductCmdrServiceClient.lua +50 -0
- package/src/Client/GameProductServiceClient.lua +7 -0
- package/src/Server/Cmdr/GameProductCmdrService.lua +104 -0
- package/src/Server/GameProductService.lua +54 -0
- package/src/Shared/Cmdr/GameProductCmdrTypeUtils.lua +131 -0
- package/src/Shared/GameProductDataService.lua +61 -0
- package/src/Shared/GameProductDataService.spec.lua +168 -0
- package/src/Shared/Ownership/PlayerAssetOwnershipTracker.lua +172 -22
- package/src/Shared/Ownership/PlayerAssetOwnershipTracker.spec.lua +576 -0
- package/src/Shared/Ownership/PlayerProductOwnershipOverrideUtils.lua +56 -0
- package/src/Shared/Ownership/PlayerProductOwnershipOverrideUtils.spec.lua +65 -0
- package/src/Shared/Trackers/PlayerAssetMarketTracker.lua +25 -1
- package/src/Shared/Trackers/PlayerAssetMarketTracker.spec.lua +366 -0
- package/src/Shared/Trackers/PlayerProductManagerBase.lua +13 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,27 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [14.58.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.57.0...@quenty/gameproductservice@14.58.0) (2026-07-21)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- Resolve luau-lsp and moonwave lint failures ([286e352](https://github.com/Quenty/NevermoreEngine/commit/286e3527b52a86639fc0485359141d7805b3fefa))
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- Add kinda risky ownership override method + cmdr commands ([b0aaa68](https://github.com/Quenty/NevermoreEngine/commit/b0aaa68ebfab7f34da05b57bca77b35bf7890c3b))
|
|
15
|
+
- Game ownership works ([c09bdc3](https://github.com/Quenty/NevermoreEngine/commit/c09bdc32174fc17cfac7aeb6c7849b556be9cec4))
|
|
16
|
+
|
|
17
|
+
# [14.57.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.56.0...@quenty/gameproductservice@14.57.0) (2026-07-20)
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
- Strict typing on tests ([efbc458](https://github.com/Quenty/NevermoreEngine/commit/efbc45882fac95755ea4ff4e007c5f71bedebf6f))
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
- **gameproductservice:** add paid-access game ownership tracking ([581a595](https://github.com/Quenty/NevermoreEngine/commit/581a5950d433ea4d6dfbcc33e88f254f9f13e14c))
|
|
26
|
+
|
|
6
27
|
# [14.56.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.55.0...@quenty/gameproductservice@14.56.0) (2026-07-18)
|
|
7
28
|
|
|
8
29
|
**Note:** Version bump only for package @quenty/gameproductservice
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/gameproductservice",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.58.0",
|
|
4
4
|
"description": "Generalized monetization system for handling products and purchases correctly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"@quenty/brio": "14.32.0",
|
|
38
38
|
"@quenty/cmdrservice": "13.49.0",
|
|
39
39
|
"@quenty/enumutils": "3.4.6",
|
|
40
|
-
"@quenty/gameconfig": "12.
|
|
40
|
+
"@quenty/gameconfig": "12.54.0",
|
|
41
41
|
"@quenty/instanceutils": "13.32.0",
|
|
42
42
|
"@quenty/loader": "10.11.0",
|
|
43
43
|
"@quenty/maid": "3.10.0",
|
|
44
|
-
"@quenty/marketplaceutils": "11.
|
|
44
|
+
"@quenty/marketplaceutils": "11.24.0",
|
|
45
45
|
"@quenty/nevermore-test-runner": "1.4.0",
|
|
46
46
|
"@quenty/observablecollection": "12.41.0",
|
|
47
47
|
"@quenty/playerbinder": "14.39.0",
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"@quenty/string": "3.3.7",
|
|
59
59
|
"@quenty/table": "3.9.2",
|
|
60
60
|
"@quenty/tie": "10.43.0",
|
|
61
|
-
"@quenty/valueobject": "13.33.0"
|
|
61
|
+
"@quenty/valueobject": "13.33.0",
|
|
62
|
+
"@quentystudios/jest-lua": "3.10.0-quenty.2"
|
|
62
63
|
},
|
|
63
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "b7e59984e586064ea3cec6176e79b3f7451ecdc5"
|
|
64
65
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[=[
|
|
3
|
+
Registers the game product cmdr types on the client so cmdr can autocomplete the
|
|
4
|
+
`set-ownership` command's arguments. The commands themselves are registered on the server by
|
|
5
|
+
[GameProductCmdrService]; only the shared types need to exist on the client for autocomplete.
|
|
6
|
+
|
|
7
|
+
@client
|
|
8
|
+
@class GameProductCmdrServiceClient
|
|
9
|
+
]=]
|
|
10
|
+
|
|
11
|
+
local require = require(script.Parent.loader).load(script)
|
|
12
|
+
|
|
13
|
+
local GameProductCmdrTypeUtils = require("GameProductCmdrTypeUtils")
|
|
14
|
+
local Maid = require("Maid")
|
|
15
|
+
local ServiceBag = require("ServiceBag")
|
|
16
|
+
|
|
17
|
+
local GameProductCmdrServiceClient = {}
|
|
18
|
+
GameProductCmdrServiceClient.ServiceName = "GameProductCmdrServiceClient"
|
|
19
|
+
|
|
20
|
+
export type GameProductCmdrServiceClient = typeof(setmetatable(
|
|
21
|
+
{} :: {
|
|
22
|
+
_serviceBag: ServiceBag.ServiceBag,
|
|
23
|
+
_maid: Maid.Maid,
|
|
24
|
+
_cmdrService: any,
|
|
25
|
+
_gameConfigServiceClient: any,
|
|
26
|
+
},
|
|
27
|
+
{} :: typeof({ __index = GameProductCmdrServiceClient })
|
|
28
|
+
))
|
|
29
|
+
|
|
30
|
+
function GameProductCmdrServiceClient.Init(self: GameProductCmdrServiceClient, serviceBag: ServiceBag.ServiceBag): ()
|
|
31
|
+
assert(not (self :: any)._serviceBag, "Already initialized")
|
|
32
|
+
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
33
|
+
self._maid = Maid.new()
|
|
34
|
+
|
|
35
|
+
self._cmdrService = self._serviceBag:GetService(require("CmdrServiceClient"))
|
|
36
|
+
self._gameConfigServiceClient = self._serviceBag:GetService(require("GameConfigServiceClient"))
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
function GameProductCmdrServiceClient.Start(self: GameProductCmdrServiceClient): ()
|
|
40
|
+
local configPicker = self._gameConfigServiceClient:GetConfigPicker()
|
|
41
|
+
self._maid:GivePromise(self._cmdrService:PromiseCmdr()):Then(function(cmdr)
|
|
42
|
+
GameProductCmdrTypeUtils.registerTypes(cmdr, configPicker)
|
|
43
|
+
end)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
function GameProductCmdrServiceClient.Destroy(self: GameProductCmdrServiceClient): ()
|
|
47
|
+
self._maid:DoCleaning()
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
return GameProductCmdrServiceClient
|
|
@@ -60,6 +60,7 @@ function GameProductServiceClient.Init(self: GameProductServiceClient, serviceBa
|
|
|
60
60
|
-- Internal
|
|
61
61
|
self._gameProductDataService = self._serviceBag:GetService(require("GameProductDataService"))
|
|
62
62
|
self._serviceBag:GetService(require("PlayerProductManagerClient"))
|
|
63
|
+
self._serviceBag:GetService((require :: any)("GameProductCmdrServiceClient"))
|
|
63
64
|
|
|
64
65
|
-- Additional API for ergonomics
|
|
65
66
|
self.GamePassPurchased = self._maid:Add(Signal.new() :: any) -- :Fire(gamePassId)
|
|
@@ -200,6 +201,12 @@ function GameProductServiceClient.PromisePlayerOwnership(
|
|
|
200
201
|
return self._gameProductDataService:PromisePlayerOwnership(player, assetType, idOrKey)
|
|
201
202
|
end
|
|
202
203
|
|
|
204
|
+
--[=[
|
|
205
|
+
Ownership overrides are intentionally not settable from the client. They are server-authoritative
|
|
206
|
+
and replicated read-only (see [GameProductService.SetPlayerOwnershipOverride]), so a player can
|
|
207
|
+
never grant themselves ownership. Read ownership with [GameProductServiceClient.ObservePlayerOwnership].
|
|
208
|
+
]=]
|
|
209
|
+
|
|
203
210
|
--[=[
|
|
204
211
|
Observes if the player owns this cloud asset or not
|
|
205
212
|
|
|
@@ -5,18 +5,32 @@
|
|
|
5
5
|
|
|
6
6
|
local require = require(script.Parent.loader).load(script)
|
|
7
7
|
|
|
8
|
+
local GameConfigAssetTypeUtils = require("GameConfigAssetTypeUtils")
|
|
8
9
|
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
10
|
+
local GameProductCmdrTypeUtils = require("GameProductCmdrTypeUtils")
|
|
9
11
|
local PlayerUtils = require("PlayerUtils")
|
|
10
12
|
local ServiceBag = require("ServiceBag")
|
|
11
13
|
|
|
12
14
|
local GameProductCmdrService = {}
|
|
13
15
|
GameProductCmdrService.ServiceName = "GameProductCmdrService"
|
|
14
16
|
|
|
17
|
+
-- Asset types that have an ownership tracker (see PlayerProductManagerBase). Only these can
|
|
18
|
+
-- have their ownership overridden.
|
|
19
|
+
local OWNABLE_ASSET_TYPES: { [string]: boolean } = {
|
|
20
|
+
[GameConfigAssetTypes.PASS] = true,
|
|
21
|
+
[GameConfigAssetTypes.ASSET] = true,
|
|
22
|
+
[GameConfigAssetTypes.BUNDLE] = true,
|
|
23
|
+
[GameConfigAssetTypes.SUBSCRIPTION] = true,
|
|
24
|
+
[GameConfigAssetTypes.MEMBERSHIP] = true,
|
|
25
|
+
[GameConfigAssetTypes.GAME] = true,
|
|
26
|
+
}
|
|
27
|
+
|
|
15
28
|
export type GameProductCmdrService = typeof(setmetatable(
|
|
16
29
|
{} :: {
|
|
17
30
|
_serviceBag: ServiceBag.ServiceBag,
|
|
18
31
|
_cmdrService: any,
|
|
19
32
|
_gameProductService: any,
|
|
33
|
+
_gameConfigDataService: any,
|
|
20
34
|
},
|
|
21
35
|
{} :: typeof({ __index = GameProductCmdrService })
|
|
22
36
|
))
|
|
@@ -27,9 +41,17 @@ function GameProductCmdrService.Init(self: GameProductCmdrService, serviceBag: S
|
|
|
27
41
|
|
|
28
42
|
self._cmdrService = self._serviceBag:GetService(require("CmdrService"))
|
|
29
43
|
self._gameProductService = self._serviceBag:GetService(require("GameProductService"))
|
|
44
|
+
self._gameConfigDataService = self._serviceBag:GetService(require("GameConfigDataService"))
|
|
30
45
|
end
|
|
31
46
|
|
|
32
47
|
function GameProductCmdrService.Start(self: GameProductCmdrService): ()
|
|
48
|
+
-- Register the shared cmdr types before the commands that reference them. The client
|
|
49
|
+
-- registers the same types via GameProductCmdrServiceClient so cmdr can autocomplete.
|
|
50
|
+
local configPicker = self._gameConfigDataService:GetConfigPicker()
|
|
51
|
+
self._cmdrService:PromiseCmdr():Then(function(cmdr)
|
|
52
|
+
GameProductCmdrTypeUtils.registerTypes(cmdr, configPicker)
|
|
53
|
+
end)
|
|
54
|
+
|
|
33
55
|
self:_registerCommands()
|
|
34
56
|
end
|
|
35
57
|
|
|
@@ -190,6 +212,88 @@ function GameProductCmdrService._registerCommands(self: GameProductCmdrService):
|
|
|
190
212
|
|
|
191
213
|
return string.format("Prompted: %s", table.concat(givenTo, ", "))
|
|
192
214
|
end)
|
|
215
|
+
|
|
216
|
+
self._cmdrService:RegisterCommand({
|
|
217
|
+
Name = "set-ownership",
|
|
218
|
+
Description = "Overrides a player's local ownership of an asset. Useful for testing ownership-gated "
|
|
219
|
+
.. "behavior, including paid-access games which cannot be prompted in-experience.",
|
|
220
|
+
Group = "GameConfig",
|
|
221
|
+
Args = {
|
|
222
|
+
{
|
|
223
|
+
Name = "Player",
|
|
224
|
+
Type = "players",
|
|
225
|
+
Description = "The player(s) to override ownership for.",
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
Name = "AssetType",
|
|
229
|
+
Type = GameProductCmdrTypeUtils.OwnableAssetTypeName,
|
|
230
|
+
Description = "Ownable asset type: game, pass, asset, bundle, subscription, or membership.",
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
Name = "AssetIdOrKey",
|
|
234
|
+
Type = GameProductCmdrTypeUtils.OwnableAssetIdOrKeyName,
|
|
235
|
+
Description = "The asset id (number) or GameConfig asset key.",
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
Name = "State",
|
|
239
|
+
Type = GameProductCmdrTypeUtils.OwnershipStateName,
|
|
240
|
+
Description = "own (force owned), disown (force not owned), or clear (remove the override).",
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
}, function(_context, players, assetType, assetIdOrKey, state)
|
|
244
|
+
assetType = string.lower(assetType)
|
|
245
|
+
if not GameConfigAssetTypeUtils.isAssetType(assetType) then
|
|
246
|
+
return string.format("Unknown asset type %q", tostring(assetType))
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
if not OWNABLE_ASSET_TYPES[assetType] then
|
|
250
|
+
return string.format("Asset type %q is not ownable", tostring(assetType))
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
state = string.lower(state)
|
|
254
|
+
local ownsAsset: boolean?
|
|
255
|
+
if state == "own" then
|
|
256
|
+
ownsAsset = true
|
|
257
|
+
elseif state == "disown" then
|
|
258
|
+
ownsAsset = false
|
|
259
|
+
elseif state == "clear" then
|
|
260
|
+
ownsAsset = nil
|
|
261
|
+
else
|
|
262
|
+
return string.format("Unknown state %q (expected own, disown, or clear)", tostring(state))
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
-- Numeric ids arrive as strings from cmdr; coerce so raw asset ids resolve directly,
|
|
266
|
+
-- while GameConfig keys pass through as strings.
|
|
267
|
+
local idOrKey = tonumber(assetIdOrKey) or assetIdOrKey
|
|
268
|
+
|
|
269
|
+
local ownableAssetType = assetType :: GameConfigAssetTypes.GameConfigAssetType
|
|
270
|
+
|
|
271
|
+
local appliedTo = {}
|
|
272
|
+
for _, player in players do
|
|
273
|
+
self._gameProductService
|
|
274
|
+
:SetPlayerOwnershipOverride(player, ownableAssetType, idOrKey, ownsAsset)
|
|
275
|
+
:Catch(function(err)
|
|
276
|
+
warn(
|
|
277
|
+
string.format(
|
|
278
|
+
"[set-ownership] - Failed for %s: %s",
|
|
279
|
+
PlayerUtils.formatName(player),
|
|
280
|
+
tostring(err)
|
|
281
|
+
)
|
|
282
|
+
)
|
|
283
|
+
end)
|
|
284
|
+
|
|
285
|
+
table.insert(appliedTo, PlayerUtils.formatName(player))
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
local verb = if ownsAsset == nil then "Cleared" elseif ownsAsset then "Granted" else "Revoked"
|
|
289
|
+
return string.format(
|
|
290
|
+
"%s %s ownership of %s for %s",
|
|
291
|
+
verb,
|
|
292
|
+
assetType,
|
|
293
|
+
tostring(idOrKey),
|
|
294
|
+
table.concat(appliedTo, ", ")
|
|
295
|
+
)
|
|
296
|
+
end)
|
|
193
297
|
end
|
|
194
298
|
|
|
195
299
|
return GameProductCmdrService
|
|
@@ -204,6 +204,60 @@ function GameProductService.PromisePlayerOwnership(
|
|
|
204
204
|
return self._gameProductDataService:PromisePlayerOwnership(player, assetType, idOrKey)
|
|
205
205
|
end
|
|
206
206
|
|
|
207
|
+
--[=[
|
|
208
|
+
Sets a server-authoritative override for the player's ownership of the asset. When set, the
|
|
209
|
+
override wins over the cloud query and any session purchase, forcing ownership on (`true`) or off
|
|
210
|
+
(`false`). Passing `nil` clears the override.
|
|
211
|
+
|
|
212
|
+
The override is replicated read-only to the client and applied to every realm's ownership
|
|
213
|
+
tracker, so it drives client-side ownership-gated UI. Useful for testing ownership-gated behavior
|
|
214
|
+
(including paid-access games, which cannot be prompted in-experience) or granting access from a
|
|
215
|
+
non-Roblox condition. Only the server may set it; the client has no setter, so a player can never
|
|
216
|
+
grant themselves ownership.
|
|
217
|
+
|
|
218
|
+
@param player Player
|
|
219
|
+
@param assetType GameConfigAssetType
|
|
220
|
+
@param idOrKey string | number
|
|
221
|
+
@param ownsAsset boolean?
|
|
222
|
+
@return Promise
|
|
223
|
+
]=]
|
|
224
|
+
function GameProductService.SetPlayerOwnershipOverride(
|
|
225
|
+
self: GameProductService,
|
|
226
|
+
player: Player,
|
|
227
|
+
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
228
|
+
idOrKey: string | number,
|
|
229
|
+
ownsAsset: boolean?
|
|
230
|
+
): Promise.Promise<()>
|
|
231
|
+
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
232
|
+
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
233
|
+
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
234
|
+
assert(type(ownsAsset) == "boolean" or ownsAsset == nil, "Bad ownsAsset")
|
|
235
|
+
|
|
236
|
+
return self._gameProductDataService:SetPlayerOwnershipOverride(player, assetType, idOrKey, ownsAsset)
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
--[=[
|
|
240
|
+
Clears any local ownership override for the asset, so ownership falls back to the cloud
|
|
241
|
+
query. Equivalent to `SetPlayerOwnershipOverride(player, assetType, idOrKey, nil)`.
|
|
242
|
+
|
|
243
|
+
@param player Player
|
|
244
|
+
@param assetType GameConfigAssetType
|
|
245
|
+
@param idOrKey string | number
|
|
246
|
+
@return Promise
|
|
247
|
+
]=]
|
|
248
|
+
function GameProductService.ClearPlayerOwnershipOverride(
|
|
249
|
+
self: GameProductService,
|
|
250
|
+
player: Player,
|
|
251
|
+
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
252
|
+
idOrKey: string | number
|
|
253
|
+
): Promise.Promise<()>
|
|
254
|
+
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
255
|
+
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
256
|
+
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
257
|
+
|
|
258
|
+
return self._gameProductDataService:ClearPlayerOwnershipOverride(player, assetType, idOrKey)
|
|
259
|
+
end
|
|
260
|
+
|
|
207
261
|
--[=[
|
|
208
262
|
Checks if the asset is ownable and if it is, checks player ownership. Otherwise, it checks if the asset
|
|
209
263
|
has been purchased this session. If the asset has not been purchased this session it prompts the user to
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[=[
|
|
3
|
+
Registers the shared cmdr enum types used by the game product commands. These must be
|
|
4
|
+
registered on both the server (so commands validate and parse) and the client (so cmdr can
|
|
5
|
+
autocomplete them), mirroring how [GameConfigCmdrUtils] registers the asset id types.
|
|
6
|
+
|
|
7
|
+
@class GameProductCmdrTypeUtils
|
|
8
|
+
]=]
|
|
9
|
+
|
|
10
|
+
local require = require(script.Parent.loader).load(script)
|
|
11
|
+
|
|
12
|
+
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
13
|
+
|
|
14
|
+
local GameProductCmdrTypeUtils = {}
|
|
15
|
+
|
|
16
|
+
--[=[
|
|
17
|
+
The name of the ownable-asset-type enum cmdr type.
|
|
18
|
+
@prop OwnableAssetTypeName "ownableAssetType"
|
|
19
|
+
@within GameProductCmdrTypeUtils
|
|
20
|
+
]=]
|
|
21
|
+
GameProductCmdrTypeUtils.OwnableAssetTypeName = "ownableAssetType"
|
|
22
|
+
|
|
23
|
+
--[=[
|
|
24
|
+
The name of the ownership-state enum cmdr type.
|
|
25
|
+
@prop OwnershipStateName "ownershipState"
|
|
26
|
+
@within GameProductCmdrTypeUtils
|
|
27
|
+
]=]
|
|
28
|
+
GameProductCmdrTypeUtils.OwnershipStateName = "ownershipState"
|
|
29
|
+
|
|
30
|
+
--[=[
|
|
31
|
+
The name of the ownable-asset id/key cmdr type. Autocompletes asset keys across all ownable
|
|
32
|
+
asset types (a union -- it is not filtered by the command's chosen AssetType, since cmdr
|
|
33
|
+
types cannot read sibling arguments) and also accepts raw numeric ids.
|
|
34
|
+
@prop OwnableAssetIdOrKeyName "ownableAssetIdOrKey"
|
|
35
|
+
@within GameProductCmdrTypeUtils
|
|
36
|
+
]=]
|
|
37
|
+
GameProductCmdrTypeUtils.OwnableAssetIdOrKeyName = "ownableAssetIdOrKey"
|
|
38
|
+
|
|
39
|
+
-- Asset types that have an ownership tracker (see PlayerProductManagerBase), and so can have
|
|
40
|
+
-- their ownership overridden.
|
|
41
|
+
local OWNABLE_ASSET_TYPES: { GameConfigAssetTypes.GameConfigAssetType } = {
|
|
42
|
+
GameConfigAssetTypes.GAME,
|
|
43
|
+
GameConfigAssetTypes.PASS,
|
|
44
|
+
GameConfigAssetTypes.ASSET,
|
|
45
|
+
GameConfigAssetTypes.BUNDLE,
|
|
46
|
+
GameConfigAssetTypes.SUBSCRIPTION,
|
|
47
|
+
GameConfigAssetTypes.MEMBERSHIP,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
--[=[
|
|
51
|
+
Ownership override states accepted by the `set-ownership` command.
|
|
52
|
+
@prop OwnershipStates { "own", "disown", "clear" }
|
|
53
|
+
@within GameProductCmdrTypeUtils
|
|
54
|
+
]=]
|
|
55
|
+
GameProductCmdrTypeUtils.OwnershipStates = { "own", "disown", "clear" }
|
|
56
|
+
|
|
57
|
+
-- Builds the ownable-asset id/key type. Autocompletes keys across every ownable asset type
|
|
58
|
+
-- (a union) and accepts raw numbers. Parse returns the raw key string or number; the command
|
|
59
|
+
-- resolves it against its chosen AssetType via the config picker.
|
|
60
|
+
local function makeOwnableAssetIdOrKeyType(cmdr: any, configPicker: any)
|
|
61
|
+
--stylua: ignore
|
|
62
|
+
return {
|
|
63
|
+
Transform = function(text)
|
|
64
|
+
local keys = {}
|
|
65
|
+
local seen = {}
|
|
66
|
+
|
|
67
|
+
for _, assetType in OWNABLE_ASSET_TYPES do
|
|
68
|
+
for _, assetConfig in configPicker:GetAllActiveAssetsOfType(assetType) do
|
|
69
|
+
local key = assetConfig:GetAssetKey()
|
|
70
|
+
if not seen[key] then
|
|
71
|
+
seen[key] = true
|
|
72
|
+
table.insert(keys, key)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
local find = cmdr.Util.MakeFuzzyFinder(keys)
|
|
78
|
+
local found = find(text)
|
|
79
|
+
|
|
80
|
+
-- Allow raw numeric ids too
|
|
81
|
+
if tonumber(text) then
|
|
82
|
+
table.insert(found, tonumber(text))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
return found
|
|
86
|
+
end;
|
|
87
|
+
Validate = function(found)
|
|
88
|
+
return #found > 0, "No ownable asset with that key or id could be found."
|
|
89
|
+
end;
|
|
90
|
+
Autocomplete = function(found)
|
|
91
|
+
local strings = {}
|
|
92
|
+
for _, item in found do
|
|
93
|
+
table.insert(strings, tostring(item))
|
|
94
|
+
end
|
|
95
|
+
return strings
|
|
96
|
+
end;
|
|
97
|
+
Parse = function(found)
|
|
98
|
+
return found[1]
|
|
99
|
+
end;
|
|
100
|
+
}
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
--[=[
|
|
104
|
+
Registers the game product cmdr types. Safe to call once per cmdr registry (server and each
|
|
105
|
+
client). Registering a duplicate type name throws, so this should only be called from a
|
|
106
|
+
single service on each realm.
|
|
107
|
+
|
|
108
|
+
@param cmdr Cmdr
|
|
109
|
+
@param configPicker GameConfigPicker
|
|
110
|
+
]=]
|
|
111
|
+
function GameProductCmdrTypeUtils.registerTypes(cmdr: any, configPicker: any): ()
|
|
112
|
+
assert(cmdr, "Bad cmdr")
|
|
113
|
+
assert(configPicker, "Bad configPicker")
|
|
114
|
+
|
|
115
|
+
cmdr.Registry:RegisterType(
|
|
116
|
+
GameProductCmdrTypeUtils.OwnableAssetTypeName,
|
|
117
|
+
cmdr.Util.MakeEnumType(GameProductCmdrTypeUtils.OwnableAssetTypeName, OWNABLE_ASSET_TYPES)
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
cmdr.Registry:RegisterType(
|
|
121
|
+
GameProductCmdrTypeUtils.OwnershipStateName,
|
|
122
|
+
cmdr.Util.MakeEnumType(GameProductCmdrTypeUtils.OwnershipStateName, GameProductCmdrTypeUtils.OwnershipStates)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
cmdr.Registry:RegisterType(
|
|
126
|
+
GameProductCmdrTypeUtils.OwnableAssetIdOrKeyName,
|
|
127
|
+
makeOwnableAssetIdOrKeyType(cmdr, configPicker)
|
|
128
|
+
)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
return GameProductCmdrTypeUtils
|
|
@@ -277,6 +277,67 @@ function GameProductDataService.PromisePlayerOwnership(
|
|
|
277
277
|
end)
|
|
278
278
|
end
|
|
279
279
|
|
|
280
|
+
--[=[
|
|
281
|
+
Sets a server-authoritative override for the player's ownership of the asset. When set, the
|
|
282
|
+
override wins over the cloud query and any session purchase, forcing ownership on (`true`) or off
|
|
283
|
+
(`false`). Passing `nil` clears the override.
|
|
284
|
+
|
|
285
|
+
The override is stored in a replicated attribute and applied to every realm's ownership tracker,
|
|
286
|
+
so it drives client-side ownership-gated UI. It can only be set from the server: this rejects on
|
|
287
|
+
the client realm, and [GameProductServiceClient] deliberately exposes no setter, so a player can
|
|
288
|
+
never grant themselves ownership.
|
|
289
|
+
|
|
290
|
+
@server
|
|
291
|
+
@param player Player
|
|
292
|
+
@param assetType GameConfigAssetType
|
|
293
|
+
@param idOrKey string | number
|
|
294
|
+
@param ownsAsset boolean?
|
|
295
|
+
@return Promise
|
|
296
|
+
]=]
|
|
297
|
+
function GameProductDataService.SetPlayerOwnershipOverride(
|
|
298
|
+
self: GameProductDataService,
|
|
299
|
+
player: Player,
|
|
300
|
+
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
301
|
+
idOrKey: string | number,
|
|
302
|
+
ownsAsset: boolean?
|
|
303
|
+
): Promise.Promise<()>
|
|
304
|
+
-- Server authority: ownership overrides are never assignable from a client (otherwise a player
|
|
305
|
+
-- could grant themselves ownership of paid assets).
|
|
306
|
+
assert(
|
|
307
|
+
self._tieRealmService:GetTieRealm() ~= TieRealms.CLIENT,
|
|
308
|
+
"[GameProductDataService] - Ownership overrides can only be set from the server"
|
|
309
|
+
)
|
|
310
|
+
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
311
|
+
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
312
|
+
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
313
|
+
assert(type(ownsAsset) == "boolean" or ownsAsset == nil, "Bad ownsAsset")
|
|
314
|
+
|
|
315
|
+
return self:_promisePlayerProductManager(player):Then(function(playerProductManager)
|
|
316
|
+
local ownershipTracker = playerProductManager:GetOwnershipTrackerOrError(assetType)
|
|
317
|
+
ownershipTracker:SetOwnershipOverride(idOrKey, ownsAsset)
|
|
318
|
+
end)
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
--[=[
|
|
322
|
+
Clears any ownership override for the asset, so ownership falls back to the cloud query.
|
|
323
|
+
Equivalent to `SetPlayerOwnershipOverride(player, assetType, idOrKey, nil)`, and likewise
|
|
324
|
+
server-only.
|
|
325
|
+
|
|
326
|
+
@server
|
|
327
|
+
@param player Player
|
|
328
|
+
@param assetType GameConfigAssetType
|
|
329
|
+
@param idOrKey string | number
|
|
330
|
+
@return Promise
|
|
331
|
+
]=]
|
|
332
|
+
function GameProductDataService.ClearPlayerOwnershipOverride(
|
|
333
|
+
self: GameProductDataService,
|
|
334
|
+
player: Player,
|
|
335
|
+
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
336
|
+
idOrKey: string | number
|
|
337
|
+
): Promise.Promise<()>
|
|
338
|
+
return self:SetPlayerOwnershipOverride(player, assetType, idOrKey, nil)
|
|
339
|
+
end
|
|
340
|
+
|
|
280
341
|
--[=[
|
|
281
342
|
Returns true if item has been purchased this session
|
|
282
343
|
|