@rbxts/scribe 2.7.0 → 2.8.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/README.md +1 -1
- package/Scribe-source-map.json +1 -1
- package/package.json +1 -1
- package/src/Client/init.luau +46 -18
- package/src/Internal/Store/ProfileStore.luau +20 -0
- package/src/Internal/Template.luau +2 -1
- package/src/Internal/Version.luau +1 -1
- package/src/Server/Monetization.luau +249 -87
- package/src/Server/Persistence.luau +3 -1
- package/src/Server/init.luau +6 -2
- package/src/Types.luau +8 -0
- package/src/init.luau +285 -116
- package/types/api.d.ts +10 -5
- package/types/common.d.ts +6 -0
- package/types/index.d.ts +1 -0
|
@@ -139,6 +139,18 @@ function Monetization.new(ctx: any)
|
|
|
139
139
|
or function(userId: number, passId: number): boolean
|
|
140
140
|
return MarketplaceService:UserOwnsGamePassAsync(userId, passId)
|
|
141
141
|
end
|
|
142
|
+
-- An injected legacy reader overrides engine detection.
|
|
143
|
+
local getPassOwnership: ((player: Player, passId: number) -> any)? = options.GetPassOwnershipAsync
|
|
144
|
+
if getPassOwnership == nil and options.UserOwnsGamePassAsync == nil then
|
|
145
|
+
local found, method = pcall(function()
|
|
146
|
+
return (MarketplaceService :: any).GetPassOwnershipAsync
|
|
147
|
+
end)
|
|
148
|
+
if found and type(method) == "function" then
|
|
149
|
+
getPassOwnership = function(player: Player, passId: number): any
|
|
150
|
+
return (MarketplaceService :: any):GetPassOwnershipAsync(player, passId)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
142
154
|
local getPolicyInfo: (player: Player) -> any = options.GetPolicyInfoAsync
|
|
143
155
|
or function(player: Player): any
|
|
144
156
|
return (game:GetService("PolicyService") :: any):GetPolicyInfoForPlayerAsync(player)
|
|
@@ -823,22 +835,31 @@ function Monetization.new(ctx: any)
|
|
|
823
835
|
-- The ownership predicate: perk flag, cached pass ownership, or Roblox Plus. No DevMode
|
|
824
836
|
-- warning and no entry lookup, because internal scans legitimately walk keys that were
|
|
825
837
|
-- never registered.
|
|
826
|
-
local function
|
|
838
|
+
local function ownership(player: Player, entry: any, key: string): (boolean, boolean, number?)
|
|
827
839
|
local reserved = reservedRaw(entry.LiveData)
|
|
828
840
|
if reserved.Perks[key] == true then
|
|
829
|
-
return true
|
|
841
|
+
return true, false, nil
|
|
830
842
|
end
|
|
831
843
|
local ownsCache = entry.SessionStore[Template.SESSION_ROOT]
|
|
832
844
|
ownsCache = if type(ownsCache) == "table" then ownsCache.OwnsCache else nil
|
|
833
|
-
if type(ownsCache) == "table"
|
|
834
|
-
|
|
845
|
+
local cached = if type(ownsCache) == "table" then ownsCache[key] else nil
|
|
846
|
+
if cached == true then
|
|
847
|
+
return true, false, nil
|
|
835
848
|
end
|
|
836
849
|
if key == "RobloxPlus" then
|
|
837
850
|
-- Coerce: the property is nil on a player object that predates it, and a nil
|
|
838
851
|
-- would read as "changed" against a false baseline on every ownership scan.
|
|
839
|
-
return player.HasRobloxSubscription == true
|
|
852
|
+
return player.HasRobloxSubscription == true, false, nil
|
|
840
853
|
end
|
|
841
|
-
|
|
854
|
+
if type(cached) == "number" then
|
|
855
|
+
return true, true, if cached > 0 then cached else nil
|
|
856
|
+
end
|
|
857
|
+
return false, false, nil
|
|
858
|
+
end
|
|
859
|
+
|
|
860
|
+
local function ownsOutright(entry: any, key: string): boolean
|
|
861
|
+
local owned, trial = ownership(entry.Player, entry, key)
|
|
862
|
+
return owned and not trial
|
|
842
863
|
end
|
|
843
864
|
|
|
844
865
|
-- Paid random items. The policy is per session, read once off the join path;
|
|
@@ -911,7 +932,17 @@ function Monetization.new(ctx: any)
|
|
|
911
932
|
if not entry or entry.State ~= "Ready" or not entry.LiveData then
|
|
912
933
|
return false
|
|
913
934
|
end
|
|
914
|
-
return
|
|
935
|
+
return (ownership(player, entry, key))
|
|
936
|
+
end
|
|
937
|
+
|
|
938
|
+
function self.GetTrial(player: Player, key: string): { EndsAt: number? }?
|
|
939
|
+
checkOwnsKey(key, "GetTrial")
|
|
940
|
+
local entry = ctx.Persistence.EntryFor(player)
|
|
941
|
+
if not entry or entry.State ~= "Ready" or not entry.LiveData then
|
|
942
|
+
return nil
|
|
943
|
+
end
|
|
944
|
+
local _, trial, trialEnds = ownership(player, entry, key)
|
|
945
|
+
return if trial then { EndsAt = trialEnds } else nil
|
|
915
946
|
end
|
|
916
947
|
|
|
917
948
|
-- One function behind both the query and the prompt, so they cannot disagree.
|
|
@@ -926,7 +957,7 @@ function Monetization.new(ctx: any)
|
|
|
926
957
|
end
|
|
927
958
|
end
|
|
928
959
|
local ownedKey = if pass then name else product.Grants
|
|
929
|
-
if ownedKey ~= nil and
|
|
960
|
+
if ownedKey ~= nil and ownsOutright(entry, ownedKey) then
|
|
930
961
|
return "owned"
|
|
931
962
|
end
|
|
932
963
|
return "purchasable"
|
|
@@ -947,14 +978,179 @@ function Monetization.new(ctx: any)
|
|
|
947
978
|
end
|
|
948
979
|
end
|
|
949
980
|
|
|
950
|
-
--
|
|
951
|
-
|
|
981
|
+
-- Pass ownership ----------------------------------------------------------------
|
|
982
|
+
|
|
983
|
+
-- Poll unknown ends every minute and recheck known ends within five minutes.
|
|
984
|
+
local TRIAL_POLL = 60
|
|
985
|
+
local TRIAL_RECHECK = 300
|
|
986
|
+
|
|
987
|
+
-- Normalize reported ends to Unix seconds. Zero means unknown.
|
|
988
|
+
local function trialEnd(value: any): number
|
|
989
|
+
if type(value) == "string" then
|
|
990
|
+
local parsed, at = pcall(DateTime.fromIsoDate, value)
|
|
991
|
+
value = if parsed then at else nil
|
|
992
|
+
end
|
|
993
|
+
if typeof(value) == "DateTime" then
|
|
994
|
+
value = value.UnixTimestamp
|
|
995
|
+
end
|
|
996
|
+
if type(value) ~= "number" or value ~= value or value <= 0 or value == math.huge then
|
|
997
|
+
return 0
|
|
998
|
+
end
|
|
999
|
+
-- Current Unix millisecond timestamps exceed 1e11.
|
|
1000
|
+
return if value > 1e11 then value / 1000 else value
|
|
1001
|
+
end
|
|
1002
|
+
|
|
1003
|
+
local passOwnershipAnswered = false
|
|
1004
|
+
local passOwnershipWarned = false
|
|
1005
|
+
|
|
1006
|
+
-- Returns (purchased, trialEnd). A trial with an unknown end uses 0.
|
|
1007
|
+
local function readPass(player: Player, userId: number, passId: number): (boolean, number?)
|
|
1008
|
+
if getPassOwnership == nil then
|
|
1009
|
+
return userOwnsGamePass(userId, passId) == true, nil
|
|
1010
|
+
end
|
|
1011
|
+
local ok, info = pcall(getPassOwnership, player, passId)
|
|
1012
|
+
if ok and type(info) == "table" and (type(info.Owned) == "boolean" or type(info.Active) == "boolean") then
|
|
1013
|
+
passOwnershipAnswered = true
|
|
1014
|
+
if info.Owned == true then
|
|
1015
|
+
return true, nil
|
|
1016
|
+
end
|
|
1017
|
+
return false, if info.Active == true then trialEnd(info.EndTime) else nil
|
|
1018
|
+
end
|
|
1019
|
+
if passOwnershipAnswered then
|
|
1020
|
+
error(if ok then "GetPassOwnershipAsync returned no ownership" else info, 0)
|
|
1021
|
+
end
|
|
1022
|
+
-- Fall back only until the first detailed response. Legacy reads conflate trials and purchases.
|
|
1023
|
+
local owned = userOwnsGamePass(userId, passId) == true
|
|
1024
|
+
if owned and not passOwnershipWarned then
|
|
1025
|
+
passOwnershipWarned = true
|
|
1026
|
+
Log.Warn(
|
|
1027
|
+
"Monetization",
|
|
1028
|
+
"PASS_TRIAL_READ_FAIL",
|
|
1029
|
+
`GetPassOwnershipAsync has not answered ({tostring(info)}), so pass ownership is read without `
|
|
1030
|
+
.. "free-trial detail and a trial counts as a purchase",
|
|
1031
|
+
{ Player = player, PassId = passId }
|
|
1032
|
+
)
|
|
1033
|
+
end
|
|
1034
|
+
return owned, nil
|
|
1035
|
+
end
|
|
1036
|
+
|
|
1037
|
+
local passAsked = 0
|
|
1038
|
+
|
|
1039
|
+
local function passState(entry: any, name: string): { Seen: number, Watch: number? }
|
|
1040
|
+
local states = entry.PassStates
|
|
1041
|
+
if states == nil then
|
|
1042
|
+
states = {}
|
|
1043
|
+
entry.PassStates = states
|
|
1044
|
+
end
|
|
1045
|
+
local state = states[name]
|
|
1046
|
+
if state == nil then
|
|
1047
|
+
state = { Seen = 0 }
|
|
1048
|
+
states[name] = state
|
|
1049
|
+
end
|
|
1050
|
+
return state
|
|
1051
|
+
end
|
|
1052
|
+
|
|
1053
|
+
local resolvePass: (entry: any, name: string, quiet: boolean?) -> (boolean, boolean)
|
|
1054
|
+
|
|
1055
|
+
-- Roblox sends no expiry event. Recheck even if the reported end is still far away.
|
|
1056
|
+
local function watchTrial(entry: any, name: string, trialEnds: number)
|
|
1057
|
+
local state = passState(entry, name)
|
|
1058
|
+
local left = trialEnds - Clock.Now()
|
|
1059
|
+
local delay = if trialEnds > 0 and left > 0 then math.min(left + 1, TRIAL_RECHECK) else TRIAL_POLL
|
|
1060
|
+
passAsked += 1
|
|
1061
|
+
local token = passAsked
|
|
1062
|
+
state.Watch = token
|
|
1063
|
+
local function onTrial(): boolean
|
|
1064
|
+
return not promptStopped
|
|
1065
|
+
and not entry.TornDown
|
|
1066
|
+
and entry.Tree ~= nil
|
|
1067
|
+
and not entry.Tree.Dead
|
|
1068
|
+
and type(sessionAcc(entry).OwnsCache.Child(name).Get()) == "number"
|
|
1069
|
+
end
|
|
1070
|
+
Clock.Delay(delay, function()
|
|
1071
|
+
-- A superseded Clock.Delay still runs.
|
|
1072
|
+
if state.Watch ~= token then
|
|
1073
|
+
return
|
|
1074
|
+
end
|
|
1075
|
+
state.Watch = nil
|
|
1076
|
+
if not onTrial() then
|
|
1077
|
+
return
|
|
1078
|
+
end
|
|
1079
|
+
-- Keep trial access on failure and retry.
|
|
1080
|
+
if not resolvePass(entry, name) and state.Watch == nil and onTrial() then
|
|
1081
|
+
watchTrial(entry, name, 0)
|
|
1082
|
+
end
|
|
1083
|
+
end)
|
|
1084
|
+
end
|
|
1085
|
+
|
|
1086
|
+
-- A confirmed purchase wins for the session. For trials, the latest request wins.
|
|
1087
|
+
local function applyPass(entry: any, name: string, asked: number, owned: boolean, trialEnds: number?): boolean
|
|
952
1088
|
if not entry.Tree or entry.Tree.Dead then
|
|
953
|
-
return owned
|
|
1089
|
+
return owned or trialEnds ~= nil
|
|
1090
|
+
end
|
|
1091
|
+
local cache = sessionAcc(entry).OwnsCache.Child(name)
|
|
1092
|
+
local held = cache.Get()
|
|
1093
|
+
if owned or held == true then
|
|
1094
|
+
cache.Set(true)
|
|
1095
|
+
return true
|
|
1096
|
+
end
|
|
1097
|
+
local state = passState(entry, name)
|
|
1098
|
+
if asked < state.Seen then
|
|
1099
|
+
return held ~= nil
|
|
1100
|
+
end
|
|
1101
|
+
state.Seen = asked
|
|
1102
|
+
if trialEnds ~= nil and (trialEnds ~= held or state.Watch == nil) then
|
|
1103
|
+
watchTrial(entry, name, trialEnds)
|
|
1104
|
+
end
|
|
1105
|
+
if trialEnds ~= held then
|
|
1106
|
+
if held == nil then
|
|
1107
|
+
Metrics.Add("PassTrialsStarted")
|
|
1108
|
+
Log.Info("Monetization", "PASS_TRIAL_STARTED", `pass "{name}" is on free trial`, {
|
|
1109
|
+
Player = entry.Player,
|
|
1110
|
+
Pass = name,
|
|
1111
|
+
EndsAt = trialEnds,
|
|
1112
|
+
})
|
|
1113
|
+
elseif trialEnds == nil then
|
|
1114
|
+
Metrics.Add("PassTrialsEnded")
|
|
1115
|
+
Log.Info("Monetization", "PASS_TRIAL_ENDED", `the free trial of pass "{name}" ended`, {
|
|
1116
|
+
Player = entry.Player,
|
|
1117
|
+
Pass = name,
|
|
1118
|
+
})
|
|
1119
|
+
end
|
|
1120
|
+
-- Write last because listeners can recheck ownership.
|
|
1121
|
+
cache.Set(trialEnds)
|
|
1122
|
+
end
|
|
1123
|
+
return trialEnds ~= nil
|
|
1124
|
+
end
|
|
1125
|
+
|
|
1126
|
+
-- Returns (ok, hasAccess). A failed check leaves the cache intact.
|
|
1127
|
+
function resolvePass(entry: any, name: string, quiet: boolean?): (boolean, boolean)
|
|
1128
|
+
local pass = passesByName[name]
|
|
1129
|
+
passAsked += 1
|
|
1130
|
+
local asked = passAsked
|
|
1131
|
+
local ok, owned, trialEnds = pcall(readPass, entry.Player, entry.UserId, pass.Id)
|
|
1132
|
+
if not ok then
|
|
1133
|
+
Metrics.Add("OwnershipCheckFailures")
|
|
1134
|
+
Log.Warn(
|
|
1135
|
+
"Monetization",
|
|
1136
|
+
"OWNERSHIP_CHECK_FAIL",
|
|
1137
|
+
tostring(owned),
|
|
1138
|
+
{ Player = entry.Player, Pass = name, PassId = pass.Id }
|
|
1139
|
+
)
|
|
1140
|
+
return false, false
|
|
954
1141
|
end
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
1142
|
+
if entry.TornDown then
|
|
1143
|
+
return true, owned or trialEnds ~= nil
|
|
1144
|
+
end
|
|
1145
|
+
-- Include a late join read in the silent baseline for this pass only.
|
|
1146
|
+
if quiet then
|
|
1147
|
+
entry.OwnsQuiet = name
|
|
1148
|
+
end
|
|
1149
|
+
local owns = applyPass(entry, name, asked, owned, trialEnds)
|
|
1150
|
+
if quiet then
|
|
1151
|
+
entry.OwnsQuiet = nil
|
|
1152
|
+
end
|
|
1153
|
+
return true, owns
|
|
958
1154
|
end
|
|
959
1155
|
|
|
960
1156
|
-- Every key whose ownership is worth tracking: everything registered, plus whatever
|
|
@@ -992,20 +1188,18 @@ function Monetization.new(ctx: any)
|
|
|
992
1188
|
entry.OwnsLast = last
|
|
993
1189
|
end
|
|
994
1190
|
local candidates = ownershipCandidates(entry)
|
|
995
|
-
--
|
|
996
|
-
--
|
|
997
|
-
-- nowhere and its false would never fire. The baseline records what was last
|
|
998
|
-
-- reported, so unioning it in is exactly the set that could still owe a transition,
|
|
999
|
-
-- and it cannot grow without bound: a false fired here never fires again.
|
|
1191
|
+
-- Revoked unregistered perks disappear from the candidates. Scan their last
|
|
1192
|
+
-- reported state once more to deliver the loss of access.
|
|
1000
1193
|
for key in last do
|
|
1001
1194
|
candidates[key] = true
|
|
1002
1195
|
end
|
|
1003
1196
|
for key in candidates do
|
|
1004
|
-
local owned =
|
|
1005
|
-
if
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1197
|
+
local owned, trial = ownership(player, entry, key)
|
|
1198
|
+
local state = if trial then "trial" elseif owned then "owned" else nil
|
|
1199
|
+
if state ~= last[key] then
|
|
1200
|
+
last[key] = state
|
|
1201
|
+
if not silent and key ~= entry.OwnsQuiet then
|
|
1202
|
+
ctx.Signals.OnOwnershipChanged:Fire(player, key, owned, trial)
|
|
1009
1203
|
end
|
|
1010
1204
|
end
|
|
1011
1205
|
end
|
|
@@ -1031,21 +1225,22 @@ function Monetization.new(ctx: any)
|
|
|
1031
1225
|
-- only real transitions fire. Returns a disconnect. The public doc-comment lives on
|
|
1032
1226
|
-- Data.ObserveOwned (Server/init.luau); keep this a plain comment so docgen does not
|
|
1033
1227
|
-- emit a duplicate entry.
|
|
1034
|
-
function self.ObserveOwned(player: Player, key: string, callback: (owned: boolean) -> ()): () -> ()
|
|
1228
|
+
function self.ObserveOwned(player: Player, key: string, callback: (owned: boolean, trial: boolean) -> ()): () -> ()
|
|
1035
1229
|
checkOwnsKey(key, "ObserveOwned")
|
|
1036
1230
|
local entry = ctx.Persistence.EntryFor(player)
|
|
1037
1231
|
if not entry or entry.State ~= "Ready" or not entry.Tree or entry.Tree.Dead then
|
|
1038
1232
|
error("Scribe: ObserveOwned requires a Ready player (use Data.WaitForData)", 3)
|
|
1039
1233
|
end
|
|
1040
|
-
local
|
|
1234
|
+
local lastOwned: boolean? = nil
|
|
1235
|
+
local lastTrial = false
|
|
1041
1236
|
local function push()
|
|
1042
1237
|
if entry.TornDown or not entry.LiveData then
|
|
1043
1238
|
return
|
|
1044
1239
|
end
|
|
1045
|
-
local owned =
|
|
1046
|
-
if owned ~=
|
|
1047
|
-
|
|
1048
|
-
Sched.Spawn(callback, owned)
|
|
1240
|
+
local owned, trial = ownership(player, entry, key)
|
|
1241
|
+
if owned ~= lastOwned or trial ~= lastTrial then
|
|
1242
|
+
lastOwned, lastTrial = owned, trial
|
|
1243
|
+
Sched.Spawn(callback, owned, trial)
|
|
1049
1244
|
end
|
|
1050
1245
|
end
|
|
1051
1246
|
-- Avoid public-read copies, as in watchOwnership.
|
|
@@ -1084,34 +1279,9 @@ function Monetization.new(ctx: any)
|
|
|
1084
1279
|
markOwnershipReady(entry)
|
|
1085
1280
|
return
|
|
1086
1281
|
end
|
|
1087
|
-
for name
|
|
1282
|
+
for name in passesByName do
|
|
1088
1283
|
Sched.Spawn(function()
|
|
1089
|
-
|
|
1090
|
-
return userOwnsGamePass(entry.UserId, pass.Id)
|
|
1091
|
-
end)
|
|
1092
|
-
if ok and not entry.TornDown then
|
|
1093
|
-
-- Fold this resolution into the join baseline before writing it.
|
|
1094
|
-
-- watchOwnership takes its silent baseline while this network round trip
|
|
1095
|
-
-- is still out, so without this every player who already owned a pass got
|
|
1096
|
-
-- a spurious owned=true. OR, never assign: ownership is the union of
|
|
1097
|
-
-- Perks, OwnsCache and RobloxPlus. A nil OwnsLast means the baseline has
|
|
1098
|
-
-- not been taken yet and that scan absorbs this by itself.
|
|
1099
|
-
local last = entry.OwnsLast
|
|
1100
|
-
if last ~= nil and entry.Tree and not entry.Tree.Dead then
|
|
1101
|
-
last[name] = last[name] == true or owned == true
|
|
1102
|
-
end
|
|
1103
|
-
foldOwnsCache(entry, name, owned == true)
|
|
1104
|
-
elseif not ok then
|
|
1105
|
-
-- A throw or throttle leaves this pass unresolved and the cache not-owned.
|
|
1106
|
-
-- Surface it rather than treating a failed check as a confirmed not-owned.
|
|
1107
|
-
Metrics.Add("OwnershipCheckFailures")
|
|
1108
|
-
Log.Warn(
|
|
1109
|
-
"Monetization",
|
|
1110
|
-
"OWNERSHIP_CHECK_FAIL",
|
|
1111
|
-
tostring(owned),
|
|
1112
|
-
{ Player = entry.Player, Pass = name, PassId = pass.Id }
|
|
1113
|
-
)
|
|
1114
|
-
end
|
|
1284
|
+
resolvePass(entry, name, true)
|
|
1115
1285
|
pending -= 1
|
|
1116
1286
|
if pending <= 0 and not entry.TornDown then
|
|
1117
1287
|
markOwnershipReady(entry)
|
|
@@ -1131,32 +1301,15 @@ function Monetization.new(ctx: any)
|
|
|
1131
1301
|
if not entry or entry.State ~= "Ready" or not entry.LiveData then
|
|
1132
1302
|
return false
|
|
1133
1303
|
end
|
|
1134
|
-
--
|
|
1135
|
-
|
|
1136
|
-
if self.Owns(player, key) then
|
|
1304
|
+
-- Confirmed purchases stay cached. Trial access can expire.
|
|
1305
|
+
if ownsOutright(entry, key) then
|
|
1137
1306
|
return true
|
|
1138
1307
|
end
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
-- are mirror reads that must never gate one. Refresh the cache while we are here.
|
|
1142
|
-
local pass = passesByName[key]
|
|
1143
|
-
if pass and not entry.TornDown then
|
|
1144
|
-
local ok, owned = pcall(function()
|
|
1145
|
-
return userOwnsGamePass(entry.UserId, pass.Id)
|
|
1146
|
-
end)
|
|
1308
|
+
if passesByName[key] and not entry.TornDown then
|
|
1309
|
+
local ok, owns = resolvePass(entry, key)
|
|
1147
1310
|
if ok then
|
|
1148
|
-
|
|
1149
|
-
return foldOwnsCache(entry, key, owned == true)
|
|
1150
|
-
end
|
|
1151
|
-
return owned == true
|
|
1311
|
+
return owns
|
|
1152
1312
|
end
|
|
1153
|
-
Metrics.Add("OwnershipCheckFailures")
|
|
1154
|
-
Log.Warn(
|
|
1155
|
-
"Monetization",
|
|
1156
|
-
"OWNERSHIP_CHECK_FAIL",
|
|
1157
|
-
tostring(owned),
|
|
1158
|
-
{ Player = entry.Player, Pass = key, PassId = pass.Id }
|
|
1159
|
-
)
|
|
1160
1313
|
end
|
|
1161
1314
|
return self.Owns(player, key)
|
|
1162
1315
|
end
|
|
@@ -1536,8 +1689,9 @@ function Monetization.new(ctx: any)
|
|
|
1536
1689
|
|
|
1537
1690
|
local function recipientAlreadyOwns(recipientUserId: number, perkKey: string): boolean
|
|
1538
1691
|
local recipientEntry = ctx.Persistence.EntryForUserId(recipientUserId)
|
|
1539
|
-
|
|
1540
|
-
|
|
1692
|
+
local present = recipientEntry ~= nil and recipientEntry.State == "Ready"
|
|
1693
|
+
if present then
|
|
1694
|
+
if ownsOutright(recipientEntry, perkKey) then
|
|
1541
1695
|
return true
|
|
1542
1696
|
end
|
|
1543
1697
|
else
|
|
@@ -1556,6 +1710,10 @@ function Monetization.new(ctx: any)
|
|
|
1556
1710
|
local pass = passesByName[perkKey]
|
|
1557
1711
|
if pass then
|
|
1558
1712
|
local ok, owned = pcall(function()
|
|
1713
|
+
-- The trial-aware read requires a local Player.
|
|
1714
|
+
if present then
|
|
1715
|
+
return (readPass(recipientEntry.Player, recipientUserId, pass.Id))
|
|
1716
|
+
end
|
|
1559
1717
|
return MarketplaceService:UserOwnsGamePassAsync(recipientUserId, pass.Id)
|
|
1560
1718
|
end)
|
|
1561
1719
|
if not ok then
|
|
@@ -1811,7 +1969,7 @@ function Monetization.new(ctx: any)
|
|
|
1811
1969
|
|
|
1812
1970
|
-- No matching intent: NoGiftIntentPolicy. A product with a consumable Grant still
|
|
1813
1971
|
-- delivers real value, so the credit path only covers pure perk products.
|
|
1814
|
-
if product.Grants and not product.Grant and
|
|
1972
|
+
if product.Grants and not product.Grant and ownsOutright(entry, product.Grants) then
|
|
1815
1973
|
-- Hold further credits until the existing paid credit is spent. Roblox may retry later.
|
|
1816
1974
|
if (tonumber(reservedRaw(entry.LiveData).GiftCredits[product.Name]) or 0) > 0 then
|
|
1817
1975
|
Log.Warn(
|
|
@@ -2429,13 +2587,13 @@ function Monetization.new(ctx: any)
|
|
|
2429
2587
|
-- session cache would heal on the next join, but robuxLog writes the PERSISTED
|
|
2430
2588
|
-- purchase history, so an unconfirmed event falsifies it.
|
|
2431
2589
|
Sched.Spawn(function()
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2590
|
+
passAsked += 1
|
|
2591
|
+
local asked = passAsked
|
|
2592
|
+
local ok, owned, trialEnds = pcall(readPass, player, entry.UserId, passId)
|
|
2435
2593
|
if entry.TornDown then
|
|
2436
2594
|
return
|
|
2437
2595
|
end
|
|
2438
|
-
if not ok or owned ~= true then
|
|
2596
|
+
if not ok or (owned ~= true and trialEnds == nil) then
|
|
2439
2597
|
-- Self-heals: the join scan re-resolves every declared pass, so a real
|
|
2440
2598
|
-- purchase the API had not caught up with is credited on the next load.
|
|
2441
2599
|
Metrics.Add("PassPurchasesUnconfirmed")
|
|
@@ -2447,7 +2605,11 @@ function Monetization.new(ctx: any)
|
|
|
2447
2605
|
)
|
|
2448
2606
|
return
|
|
2449
2607
|
end
|
|
2450
|
-
|
|
2608
|
+
applyPass(entry, passName, asked, owned, trialEnds)
|
|
2609
|
+
if not owned then
|
|
2610
|
+
-- Trial starts also fire the prompt event. Only purchases enter the paid history.
|
|
2611
|
+
return
|
|
2612
|
+
end
|
|
2451
2613
|
robuxLog(entry, {
|
|
2452
2614
|
PurchaseId = `pass:{passId}:{Clock.Now()}`,
|
|
2453
2615
|
Product = passName,
|
|
@@ -135,8 +135,10 @@ export type Entry = {
|
|
|
135
135
|
StopLoadWatchdog: (() -> ())?,
|
|
136
136
|
-- Monetization state
|
|
137
137
|
GiftLastAt: number,
|
|
138
|
-
OwnsLast: { [string]:
|
|
138
|
+
OwnsLast: { [string]: string }?, -- last reported state ("owned" or "trial")
|
|
139
|
+
OwnsQuiet: string?, -- pass being added to the join baseline
|
|
139
140
|
OwnsWatchers: { () -> () }?, -- Perks/OwnsCache listeners driving OnOwnershipChanged
|
|
141
|
+
PassStates: { [string]: { Seen: number, Watch: number? } }?, -- latest applied request and pending trial check
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
local SIZE_WARN_BYTES = 3.5 * 1024 * 1024 -- warn approaching the ~4 MB DataStore ceiling
|
package/src/Server/init.luau
CHANGED
|
@@ -59,7 +59,7 @@ function Server.build(options: any, compiled: Template.Compiled): (any, any)
|
|
|
59
59
|
OnGiftReceived = Signal.new(), -- (player, { FromUserId, Product, GiftId })
|
|
60
60
|
OnGiftCredit = Signal.new(), -- (player, productName)
|
|
61
61
|
OnMessage = Signal.new(), -- (player, message)
|
|
62
|
-
OnOwnershipChanged = Signal.new(), -- (player, key, owned)
|
|
62
|
+
OnOwnershipChanged = Signal.new(), -- (player, key, owned, trial)
|
|
63
63
|
OnCooldownEnded = Signal.new(), -- (player, key)
|
|
64
64
|
OnLeaderboard = Signal.new(), -- (boardName, entries)
|
|
65
65
|
}
|
|
@@ -320,8 +320,12 @@ function Server.build(options: any, compiled: Template.Compiled): (any, any)
|
|
|
320
320
|
function Data.OwnsAsync(player: Player, key: string, timeout: number?)
|
|
321
321
|
return ctx.Monetization.OwnsAsync(player, key, timeout)
|
|
322
322
|
end
|
|
323
|
+
-- Returns the cached trial if it alone grants access, otherwise nil.
|
|
324
|
+
function Data.GetTrial(player: Player, key: string)
|
|
325
|
+
return ctx.Monetization.GetTrial(player, key)
|
|
326
|
+
end
|
|
323
327
|
-- Reports current ownership and later changes; returns a disconnect.
|
|
324
|
-
function Data.ObserveOwned(player: Player, key: string, callback: (owned: boolean) -> ())
|
|
328
|
+
function Data.ObserveOwned(player: Player, key: string, callback: (owned: boolean, trial: boolean) -> ())
|
|
325
329
|
return ctx.Monetization.ObserveOwned(player, key, callback)
|
|
326
330
|
end
|
|
327
331
|
-- Grants a perk through Scribe's ownership state.
|
package/src/Types.luau
CHANGED
|
@@ -170,6 +170,9 @@ export type LogCode =
|
|
|
170
170
|
| "RECEIPT_HISTORY_FULL"
|
|
171
171
|
| "OWNERSHIP_CHECK_FAIL"
|
|
172
172
|
| "PASS_PURCHASE_UNCONFIRMED"
|
|
173
|
+
| "PASS_TRIAL_STARTED"
|
|
174
|
+
| "PASS_TRIAL_ENDED"
|
|
175
|
+
| "PASS_TRIAL_READ_FAIL"
|
|
173
176
|
| "PERK_GRANTED"
|
|
174
177
|
| "PERK_REVOKED"
|
|
175
178
|
| "PRODUCT_INFO_FAIL"
|
|
@@ -447,6 +450,11 @@ export type PurchaseFilter = {
|
|
|
447
450
|
Limit: number?,
|
|
448
451
|
}
|
|
449
452
|
|
|
453
|
+
-- Expected trial end in Unix seconds, nil if unknown.
|
|
454
|
+
export type PassTrial = {
|
|
455
|
+
EndsAt: number?,
|
|
456
|
+
}
|
|
457
|
+
|
|
450
458
|
-- Economy analytics -----------------------------------------------------------
|
|
451
459
|
|
|
452
460
|
-- The tag passed to Increment/Decrement to auto-emit LogEconomyEvent. All
|