77--
88-- Requests (HttpService:RequestAsync, POST, JSON, `Authorization: Bearer <token>`); contract in plans/01 "Fleet API":
99-- /v1/fleet/heartbeat the fleet status { t, b, c?, a?, n, m, s, u, p, pv, x?, xh?, xd?, cv?, v, q, g, h, e?, sv = 2 } plus j = JobId
10+ -- and region? (0.5.8, game.ServerRegion)
1011-- (never `k`, the reserved access code), every FLEET_HEARTBEAT_SECONDS and right after a change
1112-- /v1/fleet/report each deploy report { s, b, a, j, r, e?, d?, t, g, k, p }, at once
1213-- /v1/fleet/alert { level = "critical" | "warning", code, message (<= 300 bytes), j, b, a, s, t, g, k }, at once
3839-- the first after a change, and the next one after a reply asked (`xq = 1`). Fleet.heartbeat("columns") (the game's
3940-- values changed, the declarations changed, or `xq`) is coalesced: at most one per FLEET_COLUMNS_GAP s. The closing
4041-- request carries none of them.
42+ -- 0.5.8: every heartbeat (and the closing request) carries `region` at the top level: the Roblox data center this
43+ -- server runs in, game.ServerRegion (an uppercase 3-letter IATA airport code such as "IAD", "SYD", "LHR"; open-ended,
44+ -- so not checked against a list). Read through deps.serverRegion in a pcall (an engine without the property must not
45+ -- break a heartbeat), trimmed, sent only when it matches ^[A-Z]{3}$ (else the field is left out: "" in Studio, before
46+ -- the engine filled it in, or on an older engine). Re-read on every heartbeat until a valid code was seen, then kept.
47+ -- The backend prefers it over its IP geolocation of the heartbeat.
4148
4249local Constants = require (game :GetService ("ReplicatedStorage" ):WaitForChild ("TypeTorchKernelShared" ):WaitForChild ("Constants" ))
4350
@@ -70,6 +77,10 @@ local deps = {
7077 columnValues = function ()
7178 return nil
7279 end ,
80+ -- 0.5.8: () -> any: game.ServerRegion (may error: an older engine without the property).
81+ serverRegion = function ()
82+ return nil
83+ end ,
7384 encode = nil , -- (table) -> string
7485 decode = nil , -- (string) -> any
7586 warn = warn ,
@@ -91,6 +102,7 @@ local heartbeat = { due = false, urgent = false, attempts = 0, nextAt = 0, lastA
91102local declarationsSent : string ? = nil
92103local declarationsAsked = false
93104local started = false
105+ local regionCode : string ? = nil -- 0.5.8: the first valid game.ServerRegion read (it never changes for a server)
94106local closed = false
95107local tokens , tokensAt = 10 , os.clock ()
96108local stats = { sent = 0 , failed = 0 , dropped = 0 , lastOkAt = nil , lastError = nil , lastErrorAt = nil , lastStatus = nil , alerts = 0 }
@@ -333,13 +345,37 @@ local function post(path: string, body): (boolean, boolean, number?, string?, st
333345 return false , retry , if typeof (code ) == "number" then code else nil , stats .lastError
334346end
335347
348+ -- 0.5.8: a game.ServerRegion value as the heartbeat's `region`: trimmed, and only an uppercase 3-letter code; else nil.
349+ function Fleet .regionCode (raw : any ): string ?
350+ if typeof (raw ) ~= "string" or # raw > 64 then
351+ return nil
352+ end
353+ local trimmed = string.match (raw , "^%s*(.-)%s*$" )
354+ if trimmed and string.match (trimmed , "^[A-Z][A-Z][A-Z]$" ) then
355+ return trimmed
356+ end
357+ return nil
358+ end
359+
360+ -- 0.5.8: this server's region code, or nil (read again next time until one is valid).
361+ local function serverRegion (): string ?
362+ if regionCode == nil then
363+ local ok , raw = pcall (deps .serverRegion )
364+ if ok then
365+ regionCode = Fleet .regionCode (raw )
366+ end
367+ end
368+ return regionCode
369+ end
370+
336371-- The heartbeat body: the fleet status without `k` (a reserved server's access code stays in the universe), plus j.
337372-- 0.5.7: plus the live debug fields (xh, xd?, cv?) unless `closing`.
338373local function heartbeatBody (closing : boolean ? )
339374 local ok , status = pcall (deps .status )
340375 local body = if ok and typeof (status ) == "table" then table.clone (status ) else { sv = 2 }
341376 body .k = nil
342377 body .j = deps .jobId
378+ body .region = serverRegion () -- 0.5.8: nil (left out) until game.ServerRegion holds a valid code
343379 -- 0.4.0: the budget summary (`bu`) and anything else the kernel adds; only on what goes to the backend (the roll
344380 -- call and the analytics engine use api:fleetStatus() without it).
345381 local extraOk , extra = pcall (deps .heartbeatExtra )
@@ -639,6 +675,8 @@ function Fleet.info()
639675 source = settingsSource ,
640676 -- 0.5.7: the declarations' hash the backend acknowledged (nil: none declared, or not sent yet).
641677 declarationsSent = declarationsSent ,
678+ -- 0.5.8: the `region` heartbeats carry (game.ServerRegion), nil while unknown.
679+ region = regionCode ,
642680 }
643681end
644682
0 commit comments