local function endSession(gameSessionId, playDurationSec) local requestBody = { game_session_id = gameSessionId, } if playDurationSec then requestBody.play_duration_sec = playDurationSec end local success, response = pcall(function() return HttpService:RequestAsync({ Url = API_URL .. "/game/session/end", Method = "DELETE", Headers = { ["X-Api-Key"] = API_KEY, ["Content-Type"] = "application/json", }, Body = HttpService:JSONEncode(requestBody), }) end) if not success then warn("[Playwave] End session failed:", response) return end -- 404/409는 이미 정리된 상태 — 무시 if response.StatusCode == 404 or response.StatusCode == 409 then return end local body = HttpService:JSONDecode(response.Body) return body.dataend
Players.PlayerRemoving:Connect(function(player) local session = activeSessions[player.UserId] if not session then return end activeSessions[player.UserId] = nil endSession(session.gameSessionId)end)
game:BindToClose(function() for userId, session in pairs(activeSessions) do activeSessions[userId] = nil pcall(function() endSession(session.gameSessionId) end) endend)
BindToClose는 30초 제한이 있습니다. HTTP 호출이 실패하더라도 만료로 4분 후 자동 정리됩니다.