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