@quenty/gameproductservice 14.51.2 → 14.53.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 +26 -0
- package/package.json +11 -11
- package/src/Client/GameProductServiceClient.lua +68 -25
- package/src/Client/Manager/PlayerProductManagerClient.lua +70 -32
- package/src/Server/Cmdr/GameProductCmdrService.lua +6 -8
- package/src/Server/GameProductService.lua +28 -6
- package/src/Server/Manager/PlayerProductManager.lua +36 -22
- package/src/Shared/GameProductDataService.lua +124 -7
- package/src/Shared/Interfaces/PlayerAssetMarketTrackerInterface.lua +1 -1
- package/src/Shared/Interfaces/PlayerProductManagerInterface.lua +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
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.53.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.52.0...@quenty/gameproductservice@14.53.0) (2026-07-14)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- add [@within](https://github.com/within) for moonwave on SettingDefinitionProvider \_\_index; cast Tie :Implement receiver ([388e3f8](https://github.com/Quenty/NevermoreEngine/commit/388e3f8c658b14d991b2328776d6cac5b11501c0))
|
|
11
|
+
- cast Tie interface at :Implement sites to dodge flaky symlink-nominal analyze errors ([17f54f8](https://github.com/Quenty/NevermoreEngine/commit/17f54f87c6d449386570b8a409175dc2d6d02016))
|
|
12
|
+
- **gameproductservice:** annotate manager to avoid strict avatareditorutils inference blowup ([f80ea4a](https://github.com/Quenty/NevermoreEngine/commit/f80ea4a66ae7300790cad9427e1f22783005de14))
|
|
13
|
+
- **gameproductservice:** drop PlayerProductManager to --!nonstrict (luau-lsp V1 symlink-nominal flake, unreproducible locally) ([a854eec](https://github.com/Quenty/NevermoreEngine/commit/a854eecbc9619ba59e01b8d2c92d1399a1604e28))
|
|
14
|
+
- **gameproductservice:** pass selfAny to Tie :Implement to dodge symlink-nominal error ([f3b9c7d](https://github.com/Quenty/NevermoreEngine/commit/f3b9c7deaa7a7a381beced2dfd39d1a001649701))
|
|
15
|
+
- **gameproductservice:** route PlayerProductManager :Implement line through selfAny (any) to kill nominal flake ([64832ab](https://github.com/Quenty/NevermoreEngine/commit/64832ab9ee9c433ad832298455530783d9cde18d))
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
- **gameproductservice:** convert package to --!strict ([c27613b](https://github.com/Quenty/NevermoreEngine/commit/c27613b12776c983a1c3c2a2df80cd2c1b93ac4d))
|
|
20
|
+
|
|
21
|
+
# [14.52.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.51.2...@quenty/gameproductservice@14.52.0) (2026-07-02)
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
- Fix lint ([c9c1ed7](https://github.com/Quenty/NevermoreEngine/commit/c9c1ed7ee47bd464225c64baffbabbdeee6ddafe))
|
|
26
|
+
- Fix property replication ([cbdf092](https://github.com/Quenty/NevermoreEngine/commit/cbdf092195a1f11f402aa22f53ce29d4f93eb00d))
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
- Add server-only purchasing mode to GameProductService ([af6551b](https://github.com/Quenty/NevermoreEngine/commit/af6551b2f8d3bf202cb8dfa98f10fd1885b31668))
|
|
31
|
+
|
|
6
32
|
## [14.51.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/gameproductservice@14.51.1...@quenty/gameproductservice@14.51.2) (2026-06-03)
|
|
7
33
|
|
|
8
34
|
**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.53.0",
|
|
4
4
|
"description": "Generalized monetization system for handling products and purchases correctly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -31,34 +31,34 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@quenty/attributeutils": "14.30.1",
|
|
34
|
-
"@quenty/avatareditorutils": "7.
|
|
34
|
+
"@quenty/avatareditorutils": "7.40.0",
|
|
35
35
|
"@quenty/baseobject": "10.13.0",
|
|
36
|
-
"@quenty/binder": "14.
|
|
36
|
+
"@quenty/binder": "14.37.0",
|
|
37
37
|
"@quenty/brio": "14.30.1",
|
|
38
|
-
"@quenty/cmdrservice": "13.
|
|
38
|
+
"@quenty/cmdrservice": "13.46.0",
|
|
39
39
|
"@quenty/enumutils": "3.4.6",
|
|
40
|
-
"@quenty/gameconfig": "12.
|
|
40
|
+
"@quenty/gameconfig": "12.50.0",
|
|
41
41
|
"@quenty/instanceutils": "13.30.1",
|
|
42
42
|
"@quenty/loader": "10.11.0",
|
|
43
43
|
"@quenty/maid": "3.9.0",
|
|
44
|
-
"@quenty/marketplaceutils": "11.
|
|
44
|
+
"@quenty/marketplaceutils": "11.21.0",
|
|
45
45
|
"@quenty/nevermore-test-runner": "1.4.0",
|
|
46
|
-
"@quenty/observablecollection": "12.
|
|
47
|
-
"@quenty/playerbinder": "14.
|
|
46
|
+
"@quenty/observablecollection": "12.39.0",
|
|
47
|
+
"@quenty/playerbinder": "14.37.0",
|
|
48
48
|
"@quenty/playerutils": "8.32.1",
|
|
49
49
|
"@quenty/promise": "10.18.1",
|
|
50
50
|
"@quenty/promisemaid": "5.18.1",
|
|
51
51
|
"@quenty/receiptprocessing": "7.34.1",
|
|
52
52
|
"@quenty/remoting": "12.32.1",
|
|
53
53
|
"@quenty/rx": "13.28.3",
|
|
54
|
-
"@quenty/rxbinderutils": "14.
|
|
54
|
+
"@quenty/rxbinderutils": "14.37.0",
|
|
55
55
|
"@quenty/servicebag": "11.18.1",
|
|
56
56
|
"@quenty/signal": "7.13.1",
|
|
57
57
|
"@quenty/statestack": "14.32.1",
|
|
58
58
|
"@quenty/string": "3.3.7",
|
|
59
59
|
"@quenty/table": "3.9.2",
|
|
60
|
-
"@quenty/tie": "10.
|
|
60
|
+
"@quenty/tie": "10.41.0",
|
|
61
61
|
"@quenty/valueobject": "13.31.1"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "13f0162f4971a77378e55e9b7236aea94f0dd3a8"
|
|
64
64
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
--!
|
|
1
|
+
--!strict
|
|
2
2
|
--[=[
|
|
3
3
|
This service provides an interface to purchase produces, assets, and other
|
|
4
4
|
marketplace items. This listens to events, handles requests between server and
|
|
@@ -27,12 +27,27 @@ local Signal = require("Signal")
|
|
|
27
27
|
local GameProductServiceClient = {}
|
|
28
28
|
GameProductServiceClient.ServiceName = "GameProductServiceClient"
|
|
29
29
|
|
|
30
|
+
export type GameProductServiceClient = typeof(setmetatable(
|
|
31
|
+
{} :: {
|
|
32
|
+
_serviceBag: ServiceBag.ServiceBag,
|
|
33
|
+
_maid: Maid.Maid,
|
|
34
|
+
_gameProductDataService: any,
|
|
35
|
+
GamePassPurchased: Signal.Signal<number>,
|
|
36
|
+
ProductPurchased: Signal.Signal<number>,
|
|
37
|
+
AssetPurchased: Signal.Signal<number>,
|
|
38
|
+
BundlePurchased: Signal.Signal<number>,
|
|
39
|
+
SubscriptionPurchased: Signal.Signal<string>,
|
|
40
|
+
MembershipPurchased: Signal.Signal<number>,
|
|
41
|
+
},
|
|
42
|
+
{} :: typeof({ __index = GameProductServiceClient })
|
|
43
|
+
))
|
|
44
|
+
|
|
30
45
|
--[=[
|
|
31
46
|
Initializes the service. Should be done via [ServiceBag]
|
|
32
47
|
@param serviceBag ServiceBag
|
|
33
48
|
]=]
|
|
34
|
-
function GameProductServiceClient
|
|
35
|
-
assert(not self._serviceBag, "Already initialized")
|
|
49
|
+
function GameProductServiceClient.Init(self: GameProductServiceClient, serviceBag: ServiceBag.ServiceBag): ()
|
|
50
|
+
assert(not (self :: any)._serviceBag, "Already initialized")
|
|
36
51
|
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
37
52
|
self._maid = Maid.new()
|
|
38
53
|
|
|
@@ -47,19 +62,19 @@ function GameProductServiceClient:Init(serviceBag: ServiceBag.ServiceBag)
|
|
|
47
62
|
self._serviceBag:GetService(require("PlayerProductManagerClient"))
|
|
48
63
|
|
|
49
64
|
-- Additional API for ergonomics
|
|
50
|
-
self.GamePassPurchased = self._maid:Add(Signal.new()) -- :Fire(gamePassId)
|
|
51
|
-
self.ProductPurchased = self._maid:Add(Signal.new()) -- :Fire(productId)
|
|
52
|
-
self.AssetPurchased = self._maid:Add(Signal.new()) -- :Fire(assetId)
|
|
53
|
-
self.BundlePurchased = self._maid:Add(Signal.new()) -- :Fire(bundleId)
|
|
54
|
-
self.SubscriptionPurchased = self._maid:Add(Signal.new()) -- :Fire(subscriptionId)
|
|
55
|
-
self.MembershipPurchased = self._maid:Add(Signal.new()) -- :Fire(membershipId)
|
|
65
|
+
self.GamePassPurchased = self._maid:Add(Signal.new() :: any) -- :Fire(gamePassId)
|
|
66
|
+
self.ProductPurchased = self._maid:Add(Signal.new() :: any) -- :Fire(productId)
|
|
67
|
+
self.AssetPurchased = self._maid:Add(Signal.new() :: any) -- :Fire(assetId)
|
|
68
|
+
self.BundlePurchased = self._maid:Add(Signal.new() :: any) -- :Fire(bundleId)
|
|
69
|
+
self.SubscriptionPurchased = self._maid:Add(Signal.new() :: any) -- :Fire(subscriptionId)
|
|
70
|
+
self.MembershipPurchased = self._maid:Add(Signal.new() :: any) -- :Fire(membershipId)
|
|
56
71
|
end
|
|
57
72
|
|
|
58
73
|
--[=[
|
|
59
74
|
Starts the service. Should be done via [ServiceBag]
|
|
60
75
|
]=]
|
|
61
|
-
function GameProductServiceClient
|
|
62
|
-
local function forwardSignal(origSignal, signal)
|
|
76
|
+
function GameProductServiceClient.Start(self: GameProductServiceClient): ()
|
|
77
|
+
local function forwardSignal(origSignal: any, signal: any)
|
|
63
78
|
self._maid:GiveTask(origSignal:Connect(function(player, ...)
|
|
64
79
|
if player == Players.LocalPlayer then
|
|
65
80
|
signal:Fire(...)
|
|
@@ -82,7 +97,11 @@ end
|
|
|
82
97
|
@param idOrKey string | number
|
|
83
98
|
@return Observable<>
|
|
84
99
|
]=]
|
|
85
|
-
function GameProductServiceClient
|
|
100
|
+
function GameProductServiceClient.ObservePlayerAssetPurchased(
|
|
101
|
+
self: GameProductServiceClient,
|
|
102
|
+
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
103
|
+
idOrKey: string | number
|
|
104
|
+
): Observable.Observable<()>
|
|
86
105
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
87
106
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
88
107
|
|
|
@@ -96,7 +115,8 @@ end
|
|
|
96
115
|
@param idOrKey string | number
|
|
97
116
|
@return Observable<boolean>
|
|
98
117
|
]=]
|
|
99
|
-
function GameProductServiceClient
|
|
118
|
+
function GameProductServiceClient.ObserveAssetPurchased(
|
|
119
|
+
self: GameProductServiceClient,
|
|
100
120
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
101
121
|
idOrKey: string | number
|
|
102
122
|
): Observable.Observable<boolean>
|
|
@@ -114,7 +134,8 @@ end
|
|
|
114
134
|
@param idOrKey string | number
|
|
115
135
|
@return boolean
|
|
116
136
|
]=]
|
|
117
|
-
function GameProductServiceClient
|
|
137
|
+
function GameProductServiceClient.HasPlayerPurchasedThisSession(
|
|
138
|
+
self: GameProductServiceClient,
|
|
118
139
|
player: Player,
|
|
119
140
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
120
141
|
idOrKey: string | number
|
|
@@ -134,7 +155,8 @@ end
|
|
|
134
155
|
@param idOrKey string | number
|
|
135
156
|
@return Promise<boolean>
|
|
136
157
|
]=]
|
|
137
|
-
function GameProductServiceClient
|
|
158
|
+
function GameProductServiceClient.PromisePromptPurchase(
|
|
159
|
+
self: GameProductServiceClient,
|
|
138
160
|
player: Player,
|
|
139
161
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
140
162
|
idOrKey: string | number
|
|
@@ -146,6 +168,17 @@ function GameProductServiceClient:PromisePromptPurchase(
|
|
|
146
168
|
return self._gameProductDataService:PromisePromptPurchase(player, assetType, idOrKey)
|
|
147
169
|
end
|
|
148
170
|
|
|
171
|
+
--[=[
|
|
172
|
+
Observes whether server-only prompting is enabled. When enabled,
|
|
173
|
+
[GameProductServiceClient:PromisePromptPurchase] rejects and prompts must be
|
|
174
|
+
initiated from the server. Useful for hiding or disabling buy buttons on the client.
|
|
175
|
+
|
|
176
|
+
@return Observable<boolean>
|
|
177
|
+
]=]
|
|
178
|
+
function GameProductServiceClient:ObserveServerOnlyPromptingEnabled(): Observable.Observable<boolean>
|
|
179
|
+
return self._gameProductDataService:ObserveServerOnlyPrompting(Players.LocalPlayer)
|
|
180
|
+
end
|
|
181
|
+
|
|
149
182
|
--[=[
|
|
150
183
|
Returns true if item has been purchased this session
|
|
151
184
|
|
|
@@ -154,7 +187,8 @@ end
|
|
|
154
187
|
@param idOrKey string | number
|
|
155
188
|
@return Promise<boolean>
|
|
156
189
|
]=]
|
|
157
|
-
function GameProductServiceClient
|
|
190
|
+
function GameProductServiceClient.PromisePlayerOwnership(
|
|
191
|
+
self: GameProductServiceClient,
|
|
158
192
|
player: Player,
|
|
159
193
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
160
194
|
idOrKey: string | number
|
|
@@ -174,9 +208,10 @@ end
|
|
|
174
208
|
@param idOrKey string | number
|
|
175
209
|
@return Observable<boolean>
|
|
176
210
|
]=]
|
|
177
|
-
function GameProductServiceClient
|
|
211
|
+
function GameProductServiceClient.ObservePlayerOwnership(
|
|
212
|
+
self: GameProductServiceClient,
|
|
178
213
|
player: Player,
|
|
179
|
-
assetType,
|
|
214
|
+
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
180
215
|
idOrKey: string | number
|
|
181
216
|
): Observable.Observable<boolean>
|
|
182
217
|
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
@@ -192,9 +227,12 @@ end
|
|
|
192
227
|
@param player Player
|
|
193
228
|
@return Promise<boolean>
|
|
194
229
|
]=]
|
|
195
|
-
function GameProductServiceClient
|
|
230
|
+
function GameProductServiceClient.PromisePlayerIsPromptOpen(
|
|
231
|
+
self: GameProductServiceClient,
|
|
232
|
+
player: Player
|
|
233
|
+
): Promise.Promise<boolean>
|
|
196
234
|
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
197
|
-
assert(self ~= GameProductServiceClient, "Use serviceBag")
|
|
235
|
+
assert(self ~= (GameProductServiceClient :: any), "Use serviceBag")
|
|
198
236
|
assert(self._serviceBag, "Not initialized")
|
|
199
237
|
|
|
200
238
|
return self._gameProductDataService:PromisePlayerIsPromptOpen(player)
|
|
@@ -206,9 +244,12 @@ end
|
|
|
206
244
|
@param player Player
|
|
207
245
|
@return Promise
|
|
208
246
|
]=]
|
|
209
|
-
function GameProductServiceClient
|
|
247
|
+
function GameProductServiceClient.PromisePlayerPromptClosed(
|
|
248
|
+
self: GameProductServiceClient,
|
|
249
|
+
player: Player
|
|
250
|
+
): Promise.Promise<boolean>
|
|
210
251
|
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
211
|
-
assert(self ~= GameProductServiceClient, "Use serviceBag")
|
|
252
|
+
assert(self ~= (GameProductServiceClient :: any), "Use serviceBag")
|
|
212
253
|
assert(self._serviceBag, "Not initialized")
|
|
213
254
|
|
|
214
255
|
return self._gameProductDataService:PromisePlayerPromptClosed(player)
|
|
@@ -224,7 +265,8 @@ end
|
|
|
224
265
|
@param idOrKey string | number
|
|
225
266
|
@return Promise<boolean>
|
|
226
267
|
]=]
|
|
227
|
-
function GameProductServiceClient
|
|
268
|
+
function GameProductServiceClient.PromisePlayerOwnershipOrPrompt(
|
|
269
|
+
self: GameProductServiceClient,
|
|
228
270
|
player: Player,
|
|
229
271
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
230
272
|
idOrKey: string | number
|
|
@@ -243,7 +285,8 @@ end
|
|
|
243
285
|
@param productIdOrKey string | number
|
|
244
286
|
@return Promise<boolean>
|
|
245
287
|
]=]
|
|
246
|
-
function GameProductServiceClient
|
|
288
|
+
function GameProductServiceClient.PromiseGamePassOrProductUnlockOrPrompt(
|
|
289
|
+
self: GameProductServiceClient,
|
|
247
290
|
gamePassIdOrKey: string | number,
|
|
248
291
|
productIdOrKey: string | number
|
|
249
292
|
): Promise.Promise<boolean>
|
|
@@ -264,7 +307,7 @@ function GameProductServiceClient:PromiseGamePassOrProductUnlockOrPrompt(
|
|
|
264
307
|
end)
|
|
265
308
|
end
|
|
266
309
|
|
|
267
|
-
function GameProductServiceClient
|
|
310
|
+
function GameProductServiceClient.Destroy(self: GameProductServiceClient): ()
|
|
268
311
|
self._maid:DoCleaning()
|
|
269
312
|
end
|
|
270
313
|
|
|
@@ -25,16 +25,46 @@ local PlayerProductManagerClient = setmetatable({}, PlayerProductManagerBase)
|
|
|
25
25
|
PlayerProductManagerClient.ClassName = "PlayerProductManagerClient"
|
|
26
26
|
PlayerProductManagerClient.__index = PlayerProductManagerClient
|
|
27
27
|
|
|
28
|
+
-- Structural subset of AvatarEditorInventoryServiceClient covering only the methods this
|
|
29
|
+
-- manager calls. Naming the full exported type here makes the Luau solver's normalization of
|
|
30
|
+
-- the PlayerProductManagerClient intersection blow up ("Code is too complex to typecheck") --
|
|
31
|
+
-- AvatarEditorInventoryServiceClient and AvatarEditorInventory are both metatable/BaseObject
|
|
32
|
+
-- intersection types, and nesting them inside this manager's own intersection explodes the
|
|
33
|
+
-- solver. We keep call-site precision with these minimal interfaces instead.
|
|
34
|
+
type AvatarEditorInventoryEntry = {
|
|
35
|
+
IsAssetIdInInventory: (self: AvatarEditorInventoryEntry, assetId: number) -> boolean,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type AvatarEditorInventoryQuerier = {
|
|
39
|
+
IsInventoryAccessAllowed: (self: AvatarEditorInventoryQuerier) -> boolean,
|
|
40
|
+
PromiseInventoryForAvatarAssetType: (
|
|
41
|
+
self: AvatarEditorInventoryQuerier,
|
|
42
|
+
avatarAssetType: Enum.AvatarAssetType
|
|
43
|
+
) -> Promise.Promise<AvatarEditorInventoryEntry>,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
-- Structural subset of CatalogSearchServiceCache covering only PromiseItemDetails. Naming the
|
|
47
|
+
-- full exported type here reintroduces the "Code is too complex to typecheck" blow-up --
|
|
48
|
+
-- CatalogSearchServiceCache is a heavy metatable type (generic Aggregator fields), and nesting
|
|
49
|
+
-- it inside this manager's own intersection explodes the solver.
|
|
50
|
+
type CatalogSearchServiceCacheQuerier = {
|
|
51
|
+
PromiseItemDetails: (
|
|
52
|
+
self: CatalogSearchServiceCacheQuerier,
|
|
53
|
+
assetId: number,
|
|
54
|
+
avatarItemType: Enum.AvatarItemType
|
|
55
|
+
) -> Promise.Promise<any>,
|
|
56
|
+
}
|
|
57
|
+
|
|
28
58
|
export type PlayerProductManagerClient =
|
|
29
59
|
typeof(setmetatable(
|
|
30
60
|
{} :: {
|
|
31
61
|
_obj: Player,
|
|
32
62
|
_player: Player,
|
|
33
63
|
_serviceBag: ServiceBag.ServiceBag,
|
|
34
|
-
_remoting: Remoting.Remoting
|
|
64
|
+
_remoting: any, -- Remoting.Remoting (naming the full type here explodes the class-intersection normalization)
|
|
35
65
|
|
|
36
|
-
_avatarEditorInventoryServiceClient:
|
|
37
|
-
_catalogSearchServiceCache:
|
|
66
|
+
_avatarEditorInventoryServiceClient: AvatarEditorInventoryQuerier,
|
|
67
|
+
_catalogSearchServiceCache: CatalogSearchServiceCacheQuerier,
|
|
38
68
|
},
|
|
39
69
|
{} :: typeof({ __index = PlayerProductManagerClient })
|
|
40
70
|
))
|
|
@@ -60,7 +90,7 @@ function PlayerProductManagerClient.new(player: Player, serviceBag: ServiceBag.S
|
|
|
60
90
|
self:_connectBulkPurchaseMarketplace()
|
|
61
91
|
end
|
|
62
92
|
|
|
63
|
-
local impl = self._maid:Add(PlayerProductManagerInterface.Client:Implement(self._obj, self))
|
|
93
|
+
local impl = self._maid:Add((PlayerProductManagerInterface :: any).Client:Implement(self._obj, self))
|
|
64
94
|
self:ExportMarketTrackers(impl:GetImplParent())
|
|
65
95
|
|
|
66
96
|
return self
|
|
@@ -74,11 +104,15 @@ function PlayerProductManagerClient.GetPlayer(self: PlayerProductManagerClient):
|
|
|
74
104
|
return self._obj
|
|
75
105
|
end
|
|
76
106
|
|
|
77
|
-
|
|
107
|
+
-- The private setup/query helpers below take `self: any` on purpose. Typing them
|
|
108
|
+
-- `self: PlayerProductManagerClient` makes the solver renormalize the full class-&-base
|
|
109
|
+
-- intersection at every `self:...` call inside them (and at the constructor call sites),
|
|
110
|
+
-- which trips "Code is too complex to typecheck". `self: any` breaks that inference chain.
|
|
111
|
+
function PlayerProductManagerClient._setupAssetTracker(self: any): ()
|
|
78
112
|
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.ASSET)
|
|
79
113
|
local assetOwnership = assert(tracker:GetOwnershipTracker(), "Missing ownershipTracker on client")
|
|
80
114
|
|
|
81
|
-
assetOwnership:SetQueryOwnershipCallback(function(assetId)
|
|
115
|
+
assetOwnership:SetQueryOwnershipCallback(function(assetId: number): Promise.Promise<boolean>
|
|
82
116
|
return self:_promiseBulkOwnsAssetQuery(assetId)
|
|
83
117
|
end)
|
|
84
118
|
|
|
@@ -91,7 +125,7 @@ function PlayerProductManagerClient._setupAssetTracker(self: PlayerProductManage
|
|
|
91
125
|
end))
|
|
92
126
|
end
|
|
93
127
|
|
|
94
|
-
function PlayerProductManagerClient._setupMembershipTracker(self:
|
|
128
|
+
function PlayerProductManagerClient._setupMembershipTracker(self: any): ()
|
|
95
129
|
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.MEMBERSHIP)
|
|
96
130
|
|
|
97
131
|
self._maid:GiveTask(MarketplaceService.PromptPremiumPurchaseFinished:Connect(function()
|
|
@@ -115,7 +149,7 @@ function PlayerProductManagerClient._setupMembershipTracker(self: PlayerProductM
|
|
|
115
149
|
end))
|
|
116
150
|
end
|
|
117
151
|
|
|
118
|
-
function PlayerProductManagerClient._setupSubscriptionTracker(self:
|
|
152
|
+
function PlayerProductManagerClient._setupSubscriptionTracker(self: any): ()
|
|
119
153
|
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.SUBSCRIPTION)
|
|
120
154
|
|
|
121
155
|
-- Main event
|
|
@@ -148,7 +182,7 @@ function PlayerProductManagerClient._setupSubscriptionTracker(self: PlayerProduc
|
|
|
148
182
|
end))
|
|
149
183
|
end
|
|
150
184
|
|
|
151
|
-
function PlayerProductManagerClient._connectBulkPurchaseMarketplace(self:
|
|
185
|
+
function PlayerProductManagerClient._connectBulkPurchaseMarketplace(self: any): ()
|
|
152
186
|
self._maid:GiveTask(MarketplaceService.PromptBulkPurchaseFinished:Connect(function(player, status, results)
|
|
153
187
|
if player ~= self._obj then
|
|
154
188
|
return
|
|
@@ -182,7 +216,7 @@ function PlayerProductManagerClient._connectBulkPurchaseMarketplace(self: Player
|
|
|
182
216
|
end))
|
|
183
217
|
end
|
|
184
218
|
|
|
185
|
-
function PlayerProductManagerClient._setupProductTracker(self:
|
|
219
|
+
function PlayerProductManagerClient._setupProductTracker(self: any): ()
|
|
186
220
|
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.PRODUCT)
|
|
187
221
|
|
|
188
222
|
self._maid:GiveTask(
|
|
@@ -206,7 +240,7 @@ function PlayerProductManagerClient._setupProductTracker(self: PlayerProductMana
|
|
|
206
240
|
end))
|
|
207
241
|
end
|
|
208
242
|
|
|
209
|
-
function PlayerProductManagerClient._connectGamePassTracker(self:
|
|
243
|
+
function PlayerProductManagerClient._connectGamePassTracker(self: any): ()
|
|
210
244
|
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.PASS)
|
|
211
245
|
|
|
212
246
|
self._maid:GiveTask(
|
|
@@ -223,12 +257,12 @@ function PlayerProductManagerClient._connectGamePassTracker(self: PlayerProductM
|
|
|
223
257
|
)
|
|
224
258
|
end
|
|
225
259
|
|
|
226
|
-
function PlayerProductManagerClient._setupBundleTracker(self:
|
|
260
|
+
function PlayerProductManagerClient._setupBundleTracker(self: any): ()
|
|
227
261
|
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.BUNDLE)
|
|
228
262
|
|
|
229
263
|
local bundleOwnership = assert(tracker:GetOwnershipTracker(), "Missing ownershipTracker on client")
|
|
230
264
|
|
|
231
|
-
bundleOwnership:SetQueryOwnershipCallback(function(assetId)
|
|
265
|
+
bundleOwnership:SetQueryOwnershipCallback(function(assetId: number): Promise.Promise<boolean>
|
|
232
266
|
return self:_promiseBulkOwnsBundleQuery(assetId)
|
|
233
267
|
end)
|
|
234
268
|
|
|
@@ -242,34 +276,38 @@ function PlayerProductManagerClient._setupBundleTracker(self: PlayerProductManag
|
|
|
242
276
|
end))
|
|
243
277
|
end
|
|
244
278
|
|
|
245
|
-
function PlayerProductManagerClient._promiseBulkOwnsAssetQuery(self:
|
|
279
|
+
function PlayerProductManagerClient._promiseBulkOwnsAssetQuery(self: any, assetId: number): Promise.Promise<boolean>
|
|
246
280
|
if self._avatarEditorInventoryServiceClient:IsInventoryAccessAllowed() then
|
|
247
281
|
-- When scrolling through a ton of entries in the avatar editor we want to query
|
|
248
282
|
-- this is typically faster. We really hope we aren't the Roblox account.
|
|
249
|
-
|
|
250
|
-
:PromiseItemDetails(assetId, Enum.AvatarItemType.Asset)
|
|
251
|
-
:Then(function(itemDetails)
|
|
252
|
-
-- https://devforum.roblox.com/t/avatareditorservicegetitemdetails-returns-ownership-where-as-avatareditorservicegetbatchitemdetails-does-not/3257431
|
|
253
|
-
|
|
254
|
-
local assetType: Enum.AvatarAssetType? =
|
|
255
|
-
EnumUtils.toEnum(Enum.AvatarAssetType, itemDetails.AssetType) :: any
|
|
256
|
-
if not assetType then
|
|
257
|
-
-- TODO: Fallback to standard query?
|
|
258
|
-
return Promise.rejected("Failed to get assetType")
|
|
259
|
-
end
|
|
283
|
+
local detailsPromise: Promise.Promise<any> =
|
|
284
|
+
self._catalogSearchServiceCache:PromiseItemDetails(assetId, Enum.AvatarItemType.Asset)
|
|
260
285
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
286
|
+
return detailsPromise:Then(function(itemDetails: any): Promise.Promise<boolean>
|
|
287
|
+
-- https://devforum.roblox.com/t/avatareditorservicegetitemdetails-returns-ownership-where-as-avatareditorservicegetbatchitemdetails-does-not/3257431
|
|
288
|
+
|
|
289
|
+
local assetType: Enum.AvatarAssetType? =
|
|
290
|
+
EnumUtils.toEnum(Enum.AvatarAssetType, itemDetails.AssetType) :: any
|
|
291
|
+
if not assetType then
|
|
292
|
+
-- TODO: Fallback to standard query?
|
|
293
|
+
return Promise.rejected("Failed to get assetType") :: any
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
local inventoryPromise: Promise.Promise<AvatarEditorInventoryEntry> =
|
|
297
|
+
self._avatarEditorInventoryServiceClient:PromiseInventoryForAvatarAssetType(assetType)
|
|
298
|
+
|
|
299
|
+
return inventoryPromise:Then(
|
|
300
|
+
function(inventory: AvatarEditorInventoryEntry): boolean
|
|
264
301
|
return inventory:IsAssetIdInInventory(assetId)
|
|
265
|
-
end
|
|
266
|
-
|
|
302
|
+
end
|
|
303
|
+
) :: Promise.Promise<boolean>
|
|
304
|
+
end)
|
|
267
305
|
end
|
|
268
306
|
|
|
269
|
-
return MarketplaceUtils.promisePlayerOwnsAsset(self._player, assetId)
|
|
307
|
+
return MarketplaceUtils.promisePlayerOwnsAsset(self._player, assetId) :: Promise.Promise<boolean>
|
|
270
308
|
end
|
|
271
309
|
|
|
272
|
-
function PlayerProductManagerClient._promiseBulkOwnsBundleQuery(self:
|
|
310
|
+
function PlayerProductManagerClient._promiseBulkOwnsBundleQuery(self: any, bundleId: number): Promise.Promise<boolean>
|
|
273
311
|
return MarketplaceUtils.promisePlayerOwnsBundle(self._player, bundleId)
|
|
274
312
|
end
|
|
275
313
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
--!
|
|
1
|
+
--!strict
|
|
2
2
|
--[=[
|
|
3
3
|
@class GameProductCmdrService
|
|
4
4
|
]=]
|
|
5
5
|
|
|
6
6
|
local require = require(script.Parent.loader).load(script)
|
|
7
7
|
|
|
8
|
-
local CmdrService = require("CmdrService")
|
|
9
8
|
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
10
|
-
local GameProductService = require("GameProductService")
|
|
11
9
|
local PlayerUtils = require("PlayerUtils")
|
|
12
10
|
local ServiceBag = require("ServiceBag")
|
|
13
11
|
|
|
@@ -17,13 +15,13 @@ GameProductCmdrService.ServiceName = "GameProductCmdrService"
|
|
|
17
15
|
export type GameProductCmdrService = typeof(setmetatable(
|
|
18
16
|
{} :: {
|
|
19
17
|
_serviceBag: ServiceBag.ServiceBag,
|
|
20
|
-
_cmdrService:
|
|
21
|
-
_gameProductService:
|
|
18
|
+
_cmdrService: any,
|
|
19
|
+
_gameProductService: any,
|
|
22
20
|
},
|
|
23
21
|
{} :: typeof({ __index = GameProductCmdrService })
|
|
24
22
|
))
|
|
25
23
|
|
|
26
|
-
function GameProductCmdrService.Init(self: GameProductCmdrService, serviceBag: ServiceBag.ServiceBag)
|
|
24
|
+
function GameProductCmdrService.Init(self: GameProductCmdrService, serviceBag: ServiceBag.ServiceBag): ()
|
|
27
25
|
assert(not (self :: any)._serviceBag, "Already initialized")
|
|
28
26
|
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
29
27
|
|
|
@@ -31,11 +29,11 @@ function GameProductCmdrService.Init(self: GameProductCmdrService, serviceBag: S
|
|
|
31
29
|
self._gameProductService = self._serviceBag:GetService(require("GameProductService"))
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
function GameProductCmdrService.Start(self: GameProductCmdrService)
|
|
32
|
+
function GameProductCmdrService.Start(self: GameProductCmdrService): ()
|
|
35
33
|
self:_registerCommands()
|
|
36
34
|
end
|
|
37
35
|
|
|
38
|
-
function GameProductCmdrService._registerCommands(self: GameProductCmdrService)
|
|
36
|
+
function GameProductCmdrService._registerCommands(self: GameProductCmdrService): ()
|
|
39
37
|
self._cmdrService:RegisterCommand({
|
|
40
38
|
Name = "prompt-product",
|
|
41
39
|
Description = "Prompts the player to make a product purchase game-product-service.",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
--!
|
|
1
|
+
--!strict
|
|
2
2
|
--[=[
|
|
3
3
|
This service provides an interface to purchase produces, assets, and other
|
|
4
4
|
marketplace items. This listens to events, handles requests between server and
|
|
@@ -16,7 +16,6 @@ local require = require(script.Parent.loader).load(script)
|
|
|
16
16
|
|
|
17
17
|
local GameConfigAssetTypeUtils = require("GameConfigAssetTypeUtils")
|
|
18
18
|
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
19
|
-
local GameProductDataService = require("GameProductDataService")
|
|
20
19
|
local Maid = require("Maid")
|
|
21
20
|
local Observable = require("Observable")
|
|
22
21
|
local Promise = require("Promise")
|
|
@@ -30,7 +29,7 @@ export type GameProductService = typeof(setmetatable(
|
|
|
30
29
|
{} :: {
|
|
31
30
|
_serviceBag: ServiceBag.ServiceBag,
|
|
32
31
|
_maid: Maid.Maid,
|
|
33
|
-
_gameProductDataService:
|
|
32
|
+
_gameProductDataService: any,
|
|
34
33
|
|
|
35
34
|
GamePassPurchased: Signal.Signal<Player, number>,
|
|
36
35
|
ProductPurchased: Signal.Signal<Player, number>,
|
|
@@ -46,7 +45,7 @@ export type GameProductService = typeof(setmetatable(
|
|
|
46
45
|
Initializes the service. Should be done via [ServiceBag]
|
|
47
46
|
@param serviceBag ServiceBag
|
|
48
47
|
]=]
|
|
49
|
-
function GameProductService.Init(self: GameProductService, serviceBag: ServiceBag.ServiceBag)
|
|
48
|
+
function GameProductService.Init(self: GameProductService, serviceBag: ServiceBag.ServiceBag): ()
|
|
50
49
|
assert(not (self :: any)._serviceBag, "Already initialized")
|
|
51
50
|
|
|
52
51
|
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
@@ -102,7 +101,7 @@ end
|
|
|
102
101
|
function GameProductService.ObserveAssetPurchased(
|
|
103
102
|
self: GameProductService,
|
|
104
103
|
assetType: GameConfigAssetTypes.GameConfigAssetType,
|
|
105
|
-
idOrKey
|
|
104
|
+
idOrKey: string | number
|
|
106
105
|
): Observable.Observable<Player>
|
|
107
106
|
assert(GameConfigAssetTypeUtils.isAssetType(assetType), "Bad assetType")
|
|
108
107
|
assert(type(idOrKey) == "number" or type(idOrKey) == "string", "Bad idOrKey")
|
|
@@ -249,10 +248,33 @@ function GameProductService.ObservePlayerOwnership(
|
|
|
249
248
|
return self._gameProductDataService:ObservePlayerOwnership(player, assetType, idOrKey)
|
|
250
249
|
end
|
|
251
250
|
|
|
251
|
+
--[=[
|
|
252
|
+
Restricts purchase prompting to the server. When enabled, clients can no longer
|
|
253
|
+
prompt purchases directly via [GameProductServiceClient:PromisePromptPurchase] (it
|
|
254
|
+
rejects); prompts must be initiated from the server, where the developer can validate
|
|
255
|
+
the asset id. Defaults to disabled.
|
|
256
|
+
|
|
257
|
+
@param enabled boolean
|
|
258
|
+
]=]
|
|
259
|
+
function GameProductService.SetServerOnlyPromptingEnabled(self: GameProductService, enabled: boolean)
|
|
260
|
+
assert(type(enabled) == "boolean", "Bad enabled")
|
|
261
|
+
|
|
262
|
+
self._gameProductDataService:SetServerOnlyPrompting(enabled)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
--[=[
|
|
266
|
+
Returns true if server-only prompting is enabled.
|
|
267
|
+
|
|
268
|
+
@return boolean
|
|
269
|
+
]=]
|
|
270
|
+
function GameProductService.IsServerOnlyPromptingEnabled(self: GameProductService): boolean
|
|
271
|
+
return self._gameProductDataService:GetServerOnlyPromptingValue().Value
|
|
272
|
+
end
|
|
273
|
+
|
|
252
274
|
--[=[
|
|
253
275
|
Cleans up the game product service
|
|
254
276
|
]=]
|
|
255
|
-
function GameProductService.Destroy(self: GameProductService)
|
|
277
|
+
function GameProductService.Destroy(self: GameProductService): ()
|
|
256
278
|
self._maid:DoCleaning()
|
|
257
279
|
end
|
|
258
280
|
|
|
@@ -13,6 +13,7 @@ local Players = game:GetService("Players")
|
|
|
13
13
|
|
|
14
14
|
local EnumUtils = require("EnumUtils")
|
|
15
15
|
local GameConfigAssetTypes = require("GameConfigAssetTypes")
|
|
16
|
+
local GameProductDataService = require("GameProductDataService")
|
|
16
17
|
local PlayerBinder = require("PlayerBinder")
|
|
17
18
|
local PlayerProductManagerBase = require("PlayerProductManagerBase")
|
|
18
19
|
local PlayerProductManagerInterface = require("PlayerProductManagerInterface")
|
|
@@ -28,7 +29,8 @@ export type PlayerProductManager =
|
|
|
28
29
|
typeof(setmetatable(
|
|
29
30
|
{} :: {
|
|
30
31
|
_serviceBag: ServiceBag.ServiceBag,
|
|
31
|
-
_receiptProcessingService: ReceiptProcessingService.ReceiptProcessingService
|
|
32
|
+
_receiptProcessingService: any, -- ReceiptProcessingService.ReceiptProcessingService
|
|
33
|
+
_remoting: any,
|
|
32
34
|
},
|
|
33
35
|
{} :: typeof({ __index = PlayerProductManager })
|
|
34
36
|
))
|
|
@@ -46,33 +48,42 @@ function PlayerProductManager.new(player: Player, serviceBag: ServiceBag.Service
|
|
|
46
48
|
setmetatable(PlayerProductManagerBase.new(player, serviceBag) :: any, PlayerProductManager)
|
|
47
49
|
|
|
48
50
|
self._serviceBag = assert(serviceBag, "No serviceBag")
|
|
49
|
-
self._receiptProcessingService = self._serviceBag:GetService(ReceiptProcessingService)
|
|
51
|
+
self._receiptProcessingService = self._serviceBag:GetService(ReceiptProcessingService) :: any
|
|
50
52
|
|
|
51
|
-
self
|
|
53
|
+
-- Route internal setup through an `any` view: resolving these heavy-`self` method
|
|
54
|
+
-- calls against the intersected type otherwise overwhelms the old solver.
|
|
55
|
+
local selfAny = self :: any
|
|
56
|
+
selfAny:_setupRemoting()
|
|
52
57
|
|
|
53
58
|
-- Setup each ownership tracker
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
selfAny:_setupAssetTracker()
|
|
60
|
+
selfAny:_setupMembershipTracker()
|
|
61
|
+
selfAny:_setupSubscriptionTracker()
|
|
62
|
+
selfAny:_setupProductTracker()
|
|
63
|
+
selfAny:_setupPassTracker()
|
|
64
|
+
selfAny:_setupBundleTracker()
|
|
60
65
|
|
|
61
66
|
-- Initialize attributes
|
|
62
67
|
|
|
68
|
+
local serverOnlyPrompting = self._serviceBag:GetService(GameProductDataService):GetServerOnlyPromptingValue()
|
|
69
|
+
self._maid:GiveTask(serverOnlyPrompting:Observe():Subscribe(function(value)
|
|
70
|
+
self._obj:SetAttribute(GameProductDataService.ServerOnlyPromptingAttribute, value)
|
|
71
|
+
end))
|
|
72
|
+
|
|
63
73
|
-- Implement
|
|
64
74
|
local impl = self._maid:Add(PlayerProductManagerInterface.Server:Implement(self._obj, self))
|
|
65
|
-
|
|
75
|
+
selfAny:ExportMarketTrackers(impl:GetImplParent())
|
|
66
76
|
|
|
67
77
|
return self
|
|
68
78
|
end
|
|
69
79
|
|
|
70
80
|
function PlayerProductManager._setupRemoting(self: PlayerProductManager): ()
|
|
71
|
-
self._remoting =
|
|
81
|
+
self._remoting =
|
|
82
|
+
self._maid:Add((Remoting.Server :: any).new(self._obj, "PlayerProductManager", Remoting.Realms.SERVER))
|
|
72
83
|
end
|
|
73
84
|
|
|
74
85
|
function PlayerProductManager._setupAssetTracker(self: PlayerProductManager): ()
|
|
75
|
-
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.ASSET)
|
|
86
|
+
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.ASSET) :: any
|
|
76
87
|
|
|
77
88
|
self._maid:GiveTask(self._remoting.AssetPromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
|
|
78
89
|
assert(self._obj == player, "Bad player")
|
|
@@ -86,7 +97,7 @@ function PlayerProductManager._setupAssetTracker(self: PlayerProductManager): ()
|
|
|
86
97
|
end
|
|
87
98
|
|
|
88
99
|
function PlayerProductManager._setupProductTracker(self: PlayerProductManager): ()
|
|
89
|
-
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.PRODUCT)
|
|
100
|
+
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.PRODUCT) :: any
|
|
90
101
|
|
|
91
102
|
-- Source of truth for purchase is here
|
|
92
103
|
self._remoting.DeveloperProductPurchased:DeclareEvent()
|
|
@@ -103,9 +114,8 @@ function PlayerProductManager._setupProductTracker(self: PlayerProductManager):
|
|
|
103
114
|
end))
|
|
104
115
|
|
|
105
116
|
self._maid:GiveTask(
|
|
106
|
-
self._receiptProcessingService
|
|
107
|
-
|
|
108
|
-
:Subscribe(function(receiptInfo, productPurchaseDecision)
|
|
117
|
+
(self._receiptProcessingService:ObserveReceiptProcessedForPlayer(self._obj) :: any):Subscribe(
|
|
118
|
+
function(receiptInfo, productPurchaseDecision)
|
|
109
119
|
assert(type(receiptInfo) == "table", "Bad receiptInfo")
|
|
110
120
|
assert(EnumUtils.isOfType(Enum.ProductPurchaseDecision, productPurchaseDecision), "Bad decision")
|
|
111
121
|
|
|
@@ -113,12 +123,13 @@ function PlayerProductManager._setupProductTracker(self: PlayerProductManager):
|
|
|
113
123
|
tracker:HandlePurchaseEvent(productId, true)
|
|
114
124
|
|
|
115
125
|
self._remoting.DeveloperProductPurchased:FireClient(self._obj, productId)
|
|
116
|
-
end
|
|
126
|
+
end
|
|
127
|
+
)
|
|
117
128
|
)
|
|
118
129
|
end
|
|
119
130
|
|
|
120
131
|
function PlayerProductManager._setupPassTracker(self: PlayerProductManager): ()
|
|
121
|
-
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.PASS)
|
|
132
|
+
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.PASS) :: any
|
|
122
133
|
|
|
123
134
|
self._maid:GiveTask(self._remoting.PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, isPurchased)
|
|
124
135
|
assert(player == self._obj, "Bad player")
|
|
@@ -132,7 +143,7 @@ function PlayerProductManager._setupPassTracker(self: PlayerProductManager): ()
|
|
|
132
143
|
end
|
|
133
144
|
|
|
134
145
|
function PlayerProductManager._setupMembershipTracker(self: PlayerProductManager): ()
|
|
135
|
-
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.MEMBERSHIP)
|
|
146
|
+
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.MEMBERSHIP) :: any
|
|
136
147
|
|
|
137
148
|
self._maid:GiveTask(Players.PlayerMembershipChanged:Connect(function(player)
|
|
138
149
|
if player == self._obj then
|
|
@@ -146,7 +157,7 @@ end
|
|
|
146
157
|
function PlayerProductManager._setupSubscriptionTracker(self: PlayerProductManager): ()
|
|
147
158
|
self._remoting.UserSubscriptionStatusChanged:DeclareEvent()
|
|
148
159
|
|
|
149
|
-
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.SUBSCRIPTION)
|
|
160
|
+
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.SUBSCRIPTION) :: any
|
|
150
161
|
|
|
151
162
|
self._maid:GiveTask(self._remoting.PromptSubscriptionPurchaseFinished:Connect(function(player, subscriptionId)
|
|
152
163
|
assert(player == self._obj, "Bad player")
|
|
@@ -177,7 +188,7 @@ function PlayerProductManager._setupSubscriptionTracker(self: PlayerProductManag
|
|
|
177
188
|
end
|
|
178
189
|
|
|
179
190
|
function PlayerProductManager._setupBundleTracker(self: PlayerProductManager): ()
|
|
180
|
-
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.BUNDLE)
|
|
191
|
+
local tracker = self:GetAssetTrackerOrError(GameConfigAssetTypes.BUNDLE) :: any
|
|
181
192
|
|
|
182
193
|
self._maid:GiveTask(MarketplaceService.PromptBundlePurchaseFinished:Connect(function(player, bundleId, isPurchased)
|
|
183
194
|
if player == self._obj then
|
|
@@ -196,4 +207,7 @@ function PlayerProductManager._setupBundleTracker(self: PlayerProductManager): (
|
|
|
196
207
|
end))
|
|
197
208
|
end
|
|
198
209
|
|
|
199
|
-
return PlayerBinder.new(
|
|
210
|
+
return PlayerBinder.new(
|
|
211
|
+
"PlayerProductManager",
|
|
212
|
+
PlayerProductManager :: any
|
|
213
|
+
) :: PlayerBinder.PlayerBinder<PlayerProductManager>
|
|
@@ -13,19 +13,25 @@ local Observable = require("Observable")
|
|
|
13
13
|
local PlayerProductManagerInterface = require("PlayerProductManagerInterface")
|
|
14
14
|
local Promise = require("Promise")
|
|
15
15
|
local Rx = require("Rx")
|
|
16
|
+
local RxAttributeUtils = require("RxAttributeUtils")
|
|
16
17
|
local RxBrioUtils = require("RxBrioUtils")
|
|
17
18
|
local ServiceBag = require("ServiceBag")
|
|
18
19
|
local Signal = require("Signal")
|
|
19
20
|
local TieRealmService = require("TieRealmService")
|
|
21
|
+
local TieRealms = require("TieRealms")
|
|
22
|
+
local ValueObject = require("ValueObject")
|
|
20
23
|
|
|
21
24
|
local GameProductDataService = {}
|
|
22
25
|
GameProductDataService.ServiceName = "GameProductDataService"
|
|
23
26
|
|
|
27
|
+
GameProductDataService.ServerOnlyPromptingAttribute = "GameProductServerOnlyPrompting"
|
|
28
|
+
|
|
24
29
|
export type GameProductDataService = typeof(setmetatable(
|
|
25
30
|
{} :: {
|
|
26
31
|
_serviceBag: ServiceBag.ServiceBag,
|
|
27
32
|
_tieRealmService: TieRealmService.TieRealmService,
|
|
28
33
|
_maid: Maid.Maid,
|
|
34
|
+
_serverOnlyPrompting: ValueObject.ValueObject<boolean>,
|
|
29
35
|
|
|
30
36
|
GamePassPurchased: Signal.Signal<Player, number>,
|
|
31
37
|
ProductPurchased: Signal.Signal<Player, number>,
|
|
@@ -46,6 +52,12 @@ function GameProductDataService.Init(self: GameProductDataService, serviceBag: S
|
|
|
46
52
|
|
|
47
53
|
self._maid = Maid.new()
|
|
48
54
|
|
|
55
|
+
-- Source of truth for server-only prompting. On the server this is set via
|
|
56
|
+
-- [GameProductService:SetServerOnlyPromptingEnabled] and replicated to clients
|
|
57
|
+
-- through the PlayerProductManager tie. On the client we read the replicated
|
|
58
|
+
-- value to decide whether to refuse local prompts.
|
|
59
|
+
self._serverOnlyPrompting = self._maid:Add(ValueObject.new(false, "boolean"))
|
|
60
|
+
|
|
49
61
|
-- Configure
|
|
50
62
|
self.GamePassPurchased = self._maid:Add(Signal.new() :: any) -- :Fire(player, gamePassId)
|
|
51
63
|
self.ProductPurchased = self._maid:Add(Signal.new() :: any) -- :Fire(player, productId)
|
|
@@ -84,6 +96,111 @@ function GameProductDataService.Start(self: GameProductDataService)
|
|
|
84
96
|
)
|
|
85
97
|
end
|
|
86
98
|
|
|
99
|
+
--[=[
|
|
100
|
+
Sets whether prompting is restricted to the server. When enabled, clients can no
|
|
101
|
+
longer prompt purchases directly via [GameProductDataService:PromisePromptPurchase];
|
|
102
|
+
prompts must be initiated from the server. Can only be set from the server.
|
|
103
|
+
|
|
104
|
+
@param serverOnly boolean
|
|
105
|
+
]=]
|
|
106
|
+
function GameProductDataService.SetServerOnlyPrompting(self: GameProductDataService, serverOnly: boolean): ()
|
|
107
|
+
assert(type(serverOnly) == "boolean", "Bad serverOnly")
|
|
108
|
+
assert(
|
|
109
|
+
self._tieRealmService:GetTieRealm() ~= TieRealms.CLIENT,
|
|
110
|
+
"[GameProductDataService] - Server-only prompting can only be configured from the server"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
self._serverOnlyPrompting.Value = serverOnly
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
--[=[
|
|
117
|
+
Returns the server-authoritative server-only prompting [ValueObject]. This is
|
|
118
|
+
exported through the PlayerProductManager tie so it replicates to clients.
|
|
119
|
+
|
|
120
|
+
@return ValueObject<boolean>
|
|
121
|
+
]=]
|
|
122
|
+
function GameProductDataService.GetServerOnlyPromptingValue(
|
|
123
|
+
self: GameProductDataService
|
|
124
|
+
): ValueObject.ValueObject<boolean>
|
|
125
|
+
return self._serverOnlyPrompting
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
--[=[
|
|
129
|
+
Returns true if server-only prompting is currently enabled. On the client this
|
|
130
|
+
reads the value replicated from the server for the local player.
|
|
131
|
+
|
|
132
|
+
@param player Player
|
|
133
|
+
@return Observable<boolean>
|
|
134
|
+
]=]
|
|
135
|
+
function GameProductDataService.ObserveServerOnlyPrompting(
|
|
136
|
+
_self: GameProductDataService,
|
|
137
|
+
player: Player
|
|
138
|
+
): Observable.Observable<boolean>
|
|
139
|
+
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
140
|
+
|
|
141
|
+
-- Always read the server-authoritative value (the server implementation), which
|
|
142
|
+
-- replicates down to clients as an attribute on the PlayerProductManager folder.
|
|
143
|
+
return RxAttributeUtils.observeAttribute(
|
|
144
|
+
player,
|
|
145
|
+
GameProductDataService.ServerOnlyPromptingAttribute,
|
|
146
|
+
false
|
|
147
|
+
)
|
|
148
|
+
:Pipe({
|
|
149
|
+
Rx.map(function(value: any)
|
|
150
|
+
return value == true
|
|
151
|
+
end) :: any,
|
|
152
|
+
Rx.distinct() :: any,
|
|
153
|
+
}) :: any
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
--[=[
|
|
157
|
+
Resolves if the caller is allowed to prompt a purchase, rejecting if server-only
|
|
158
|
+
prompting is enabled and we are on the client. The server is always authorized.
|
|
159
|
+
|
|
160
|
+
@param player Player
|
|
161
|
+
@return Promise
|
|
162
|
+
]=]
|
|
163
|
+
function GameProductDataService._promiseServerOnlyPromptingGuard(
|
|
164
|
+
self: GameProductDataService,
|
|
165
|
+
player: Player
|
|
166
|
+
): Promise.Promise<()>
|
|
167
|
+
-- The server (and a single shared realm) is the authority and may always prompt.
|
|
168
|
+
if self._tieRealmService:GetTieRealm() ~= TieRealms.CLIENT then
|
|
169
|
+
return Promise.resolved()
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
return Rx.toPromise(self:ObserveServerOnlyPrompting(player) :: any):Then(function(serverOnly)
|
|
173
|
+
if serverOnly then
|
|
174
|
+
return Promise.rejected(
|
|
175
|
+
"[GameProductDataService] - Server-only prompting is enabled. The client cannot prompt purchases "
|
|
176
|
+
.. "directly; prompts must be initiated from the server."
|
|
177
|
+
)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
return nil
|
|
181
|
+
end)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
--[=[
|
|
185
|
+
Applies the server-only prompting guard and then prompts the purchase. Used by all
|
|
186
|
+
prompt entry points so the guard is enforced consistently.
|
|
187
|
+
|
|
188
|
+
@param player Player
|
|
189
|
+
@param assetTracker PlayerAssetMarketTracker
|
|
190
|
+
@param idOrKey string | number
|
|
191
|
+
@return Promise<boolean>
|
|
192
|
+
]=]
|
|
193
|
+
function GameProductDataService._promiseGuardedPromptPurchase(
|
|
194
|
+
self: GameProductDataService,
|
|
195
|
+
player: Player,
|
|
196
|
+
assetTracker: any,
|
|
197
|
+
idOrKey: string | number
|
|
198
|
+
): Promise.Promise<boolean>
|
|
199
|
+
return self:_promiseServerOnlyPromptingGuard(player):Then(function()
|
|
200
|
+
return assetTracker:PromisePromptPurchase(idOrKey)
|
|
201
|
+
end)
|
|
202
|
+
end
|
|
203
|
+
|
|
87
204
|
--[=[
|
|
88
205
|
Returns true if item has been purchased this session
|
|
89
206
|
|
|
@@ -132,7 +249,7 @@ function GameProductDataService.PromisePromptPurchase(
|
|
|
132
249
|
|
|
133
250
|
return self:_promisePlayerProductManager(player):Then(function(playerProductManager)
|
|
134
251
|
local assetTracker = playerProductManager:GetAssetTrackerOrError(assetType)
|
|
135
|
-
return
|
|
252
|
+
return self:_promiseGuardedPromptPurchase(player, assetTracker, idOrKey)
|
|
136
253
|
end)
|
|
137
254
|
end
|
|
138
255
|
|
|
@@ -305,7 +422,7 @@ function GameProductDataService.ObserveAssetPurchased(
|
|
|
305
422
|
return playerProductManager:GetPlayer()
|
|
306
423
|
end),
|
|
307
424
|
})
|
|
308
|
-
end),
|
|
425
|
+
end) :: any,
|
|
309
426
|
Rx.map(function(brio)
|
|
310
427
|
-- I THINK THIS LEAKS
|
|
311
428
|
if brio:IsDead() then
|
|
@@ -313,10 +430,10 @@ function GameProductDataService.ObserveAssetPurchased(
|
|
|
313
430
|
end
|
|
314
431
|
|
|
315
432
|
return brio:GetValue()
|
|
316
|
-
end),
|
|
433
|
+
end) :: any,
|
|
317
434
|
Rx.where(function(value)
|
|
318
435
|
return value ~= nil
|
|
319
|
-
end),
|
|
436
|
+
end) :: any,
|
|
320
437
|
})
|
|
321
438
|
end
|
|
322
439
|
|
|
@@ -350,7 +467,7 @@ function GameProductDataService.PromisePlayerOwnershipOrPrompt(
|
|
|
350
467
|
if ownsAsset then
|
|
351
468
|
return true
|
|
352
469
|
else
|
|
353
|
-
return
|
|
470
|
+
return self:_promiseGuardedPromptPurchase(player, assetTracker, idOrKey) :: any
|
|
354
471
|
end
|
|
355
472
|
end)
|
|
356
473
|
else
|
|
@@ -359,7 +476,7 @@ function GameProductDataService.PromisePlayerOwnershipOrPrompt(
|
|
|
359
476
|
return Promise.resolved(true)
|
|
360
477
|
end
|
|
361
478
|
|
|
362
|
-
return
|
|
479
|
+
return self:_promiseGuardedPromptPurchase(player, assetTracker, idOrKey)
|
|
363
480
|
end
|
|
364
481
|
end)
|
|
365
482
|
end
|
|
@@ -382,7 +499,7 @@ function GameProductDataService._promisePlayerProductManager(
|
|
|
382
499
|
return PlayerProductManagerInterface:Promise(player, self._tieRealmService:GetTieRealm())
|
|
383
500
|
end
|
|
384
501
|
|
|
385
|
-
function GameProductDataService._getPlayerProductManager(self: GameProductDataService, player: Player)
|
|
502
|
+
function GameProductDataService._getPlayerProductManager(self: GameProductDataService, player: Player): any
|
|
386
503
|
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
387
504
|
|
|
388
505
|
return PlayerProductManagerInterface:Find(player, self._tieRealmService:GetTieRealm())
|