Better game management
This commit is contained in:
parent
88135b551b
commit
32a2748d17
|
|
@ -12,6 +12,10 @@ class GameJob extends Job {
|
|||
|
||||
StartGame(id) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const response = await axios(`${process.env.BASE_URL}/API/Game/${id}?t=${process.env.ARBITER_TOKEN}`).catch((_) => reject(_))
|
||||
const { server_token, server_port } = response.data
|
||||
|
||||
this.serverToken = server_token
|
||||
this.placeId = id
|
||||
|
||||
const started = await this.Start()
|
||||
|
|
@ -20,8 +24,6 @@ class GameJob extends Job {
|
|||
|
||||
logger.info(`[${this.id}] GameJob started for ${id}`)
|
||||
|
||||
const port = await randport.udp()
|
||||
|
||||
this.OpenJobEx({
|
||||
name: this.id,
|
||||
script: await readFile(__dirname + "/../../lua/gameserver.lua", { encoding: "utf-8" }),
|
||||
|
|
@ -33,12 +35,13 @@ class GameJob extends Job {
|
|||
{ type: "LUA_TSTRING", value: process.env.BASE_URL },
|
||||
|
||||
{ type: "LUA_TNUMBER", value: id },
|
||||
{ type: "LUA_TNUMBER", value: port },
|
||||
{ type: "LUA_TNUMBER", value: server_port },
|
||||
{ type: "LUA_TSTRING", value: this.serverToken },
|
||||
],
|
||||
},
|
||||
}).catch((e) => reject(e))
|
||||
|
||||
resolve(port)
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
const { readFile } = require("fs/promises")
|
||||
const chalk = require("chalk")
|
||||
const axios = require("axios")
|
||||
|
||||
const Job = require("./Job.js")
|
||||
const logger = require("../logger.js")
|
||||
|
|
@ -136,6 +137,12 @@ class RenderJob extends Job {
|
|||
}
|
||||
|
||||
async RenderPlace(id) {
|
||||
const response = await axios(`${process.env.BASE_URL}/API/Game/${id}?t=${process.env.ARBITER_TOKEN}`).catch((_) => reject(_))
|
||||
const { server_token } = response.data
|
||||
|
||||
this.serverToken = server_token
|
||||
console.log(`${process.env.BASE_URL}/API/Game/${id}?t=${process.env.ARBITER_TOKEN}`, server_token)
|
||||
|
||||
const running = this.started
|
||||
if (!running) {
|
||||
const started = await this.Start()
|
||||
|
|
@ -161,7 +168,7 @@ class RenderJob extends Job {
|
|||
|
||||
{ type: "LUA_TSTRING", value: process.env.BASE_URL },
|
||||
{ type: "LUA_TNUMBER", value: id },
|
||||
{ type: "LUA_TSTRING", value: process.env.ARBITER_TOKEN },
|
||||
{ type: "LUA_TSTRING", value: this.serverToken },
|
||||
],
|
||||
},
|
||||
}).catch((e) => false)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
local jobId, type, baseUrl, placeId, port = ...
|
||||
local jobId, type, baseUrl, placeId, port, token = ...
|
||||
|
||||
------------------- UTILITY FUNCTIONS --------------------------
|
||||
|
||||
function waitForChild(parent, childName)
|
||||
while true do
|
||||
local child = parent:findFirstChild(childName)
|
||||
|
|
@ -63,16 +64,19 @@ pcall(function() settings().Diagnostics:LegacyScriptMode() end)
|
|||
|
||||
-----------------------------------START GAME SHARED SCRIPT------------------------------
|
||||
|
||||
local assetId = placeId
|
||||
|
||||
local scriptContext = game:GetService("ScriptContext")
|
||||
pcall(function() scriptContext:AddStarterScript(37801172) end)
|
||||
scriptContext.ScriptsDisabled = true
|
||||
|
||||
game:SetPlaceID(placeId, false)
|
||||
game:SetPlaceID(assetId, false)
|
||||
game:GetService("ChangeHistoryService"):SetEnabled(false)
|
||||
game:GetService("HttpService").HttpEnabled = true
|
||||
|
||||
local ns = game:GetService("NetworkServer")
|
||||
|
||||
if baseUrl ~= nil then
|
||||
if baseUrl~=nil then
|
||||
pcall(function() game:GetService("Players"):SetAbuseReportUrl(baseUrl .. "/AbuseReport/InGameChatHandler.ashx") end)
|
||||
pcall(function() game:GetService("ScriptInformationProvider"):SetAssetUrl(baseUrl .. "/Asset/") end)
|
||||
pcall(function() game:GetService("ContentProvider"):SetBaseUrl(baseUrl .. "/") end)
|
||||
|
|
@ -92,16 +96,29 @@ end
|
|||
settings().Diagnostics.LuaRamLimit = 0
|
||||
|
||||
game:GetService("Players").PlayerAdded:connect(function(player)
|
||||
keepAlive()
|
||||
print("Player " .. player.userId .. " added")
|
||||
|
||||
player.CharacterAdded:connect(function(c)
|
||||
game:GetObjects("rbxasset://fonts/characterCameraScript.rbxmx")[1].Parent = c
|
||||
game:GetObjects("rbxasset://fonts/characterControlScript.rbxmx")[1].Parent = c
|
||||
|
||||
for i,v in pairs(c:GetChildren()) do
|
||||
print(v.Name)
|
||||
end
|
||||
|
||||
print(c.Animate.Source)
|
||||
end)
|
||||
end)
|
||||
|
||||
game:GetService("Players").PlayerRemoving:connect(function(player)
|
||||
keepAlive(player)
|
||||
print("Player " .. player.userId .. " leaving")
|
||||
end)
|
||||
|
||||
if placeId ~= nil and baseUrl ~= nil then
|
||||
if placeId~=nil and baseUrl~=nil then
|
||||
wait()
|
||||
game:Load(baseUrl .. "/asset/?id=" .. placeId)
|
||||
game:Load(baseUrl .. "/thumbs/staticimage?r=" .. token)
|
||||
end
|
||||
|
||||
------------------------------ RENEW GAME JOB SERVICE -------------------------------
|
||||
|
|
@ -109,9 +126,9 @@ end
|
|||
spawn(function()
|
||||
while wait(30) do
|
||||
if #game.Players:GetPlayers() == 0 then
|
||||
pcall(function() game:HttpGet(baseUrl .. "/arbiter/" .. jobId .. "/kill") end)
|
||||
pcall(function() game:HttpGet(baseUrl .. "/arbiter/" .. token .. "/kill") end)
|
||||
else
|
||||
pcall(function() game:HttpGet(baseUrl .. "/arbiter/" .. jobId .. "/renew?s=360") end)
|
||||
pcall(function() game:HttpGet(baseUrl .. "/arbiter/" .. token .. "/renew?s=360") end)
|
||||
keepAlive()
|
||||
end
|
||||
end
|
||||
|
|
@ -124,6 +141,4 @@ ns:Start(port)
|
|||
scriptContext:SetTimeout(10)
|
||||
scriptContext.ScriptsDisabled = false
|
||||
|
||||
------------------------------END START GAME SHARED SCRIPT--------------------------
|
||||
|
||||
game:GetService("RunService"):Run()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
local jobId, type, format, x, y, baseUrl, assetId = ...
|
||||
local jobId, type, format, x, y, baseUrl, assetId, token = ...
|
||||
print(token)
|
||||
|
||||
print(("[%s] Started RenderJob for type '%s' with assetId %d ..."):format(jobId, type, assetId))
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ game:GetService("ContentProvider"):SetBaseUrl(baseUrl)
|
|||
game:GetService("ScriptContext").ScriptsDisabled = true
|
||||
game:GetService("StarterGui").ShowDevelopmentGui = false
|
||||
|
||||
game:Load(("%s/asset/?id=%d"):format(baseUrl, assetId))
|
||||
game:Load(("%s/thumbs/staticimage?r=%s"):format(baseUrl, token))
|
||||
|
||||
game:GetService("ScriptContext").ScriptsDisabled = true
|
||||
game:GetService("StarterGui").ShowDevelopmentGui = false
|
||||
|
|
|
|||
Loading…
Reference in New Issue