Games 🥳
This commit is contained in:
parent
1412f534c7
commit
350ef70cee
|
|
@ -6,7 +6,7 @@ const logger = require("../logger.js")
|
||||||
|
|
||||||
class GameJob extends Job {
|
class GameJob extends Job {
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super({ expirationInSeconds: 360 })
|
||||||
}
|
}
|
||||||
|
|
||||||
StartGame(id) {
|
StartGame(id) {
|
||||||
|
|
@ -45,4 +45,3 @@ class GameJob extends Job {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = GameJob
|
module.exports = GameJob
|
||||||
// a http://crapblox.cf/ -t 1 -j http://crapblox.cf//Game/JoinServer?Token=jRCfrKmwFfLBAvjNOQqNuOB210rjIvz4UfMhwIaY7teYGxXniECENL2vh8rvhSU2&PlaceId=10052
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ const soap = require("soap")
|
||||||
const { randomUUID } = require("crypto")
|
const { randomUUID } = require("crypto")
|
||||||
|
|
||||||
const RCCService = require("./RCCService.js")
|
const RCCService = require("./RCCService.js")
|
||||||
|
const logger = require("../logger.js")
|
||||||
|
|
||||||
class Job extends RCCService {
|
class Job extends RCCService {
|
||||||
constructor({ id = randomUUID(), expirationInSeconds = 10, category = 0, cores = 1 } = {}) {
|
constructor({ id = randomUUID(), expirationInSeconds = 10, category = 0, cores = 1 } = {}) {
|
||||||
|
|
@ -37,6 +38,7 @@ class Job extends RCCService {
|
||||||
|
|
||||||
async RenewLease(expirationInSeconds) {
|
async RenewLease(expirationInSeconds) {
|
||||||
if (!this.client) throw new Error("There is no client")
|
if (!this.client) throw new Error("There is no client")
|
||||||
|
logger.info(`[${this.id}] Job renewed to ${expirationInSeconds} seconds`)
|
||||||
return await this.client.RenewLeaseAsync({ jobID: this.id, expirationInSeconds })
|
return await this.client.RenewLeaseAsync({ jobID: this.id, expirationInSeconds })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,11 @@ class RenderJob extends Job {
|
||||||
}
|
}
|
||||||
|
|
||||||
async RenderPlace(id, base64 = false) {
|
async RenderPlace(id, base64 = false) {
|
||||||
|
const response = await axios(`${process.env.BASE_URL}/API/Game/${id}?t=${process.env.ARBITER_TOKEN}`).catch((_) => reject(_))
|
||||||
|
const { server_token, server_port, server_owner_id } = response.data
|
||||||
|
|
||||||
|
this.id = server_token
|
||||||
|
|
||||||
const started = await this.Start()
|
const started = await this.Start()
|
||||||
if (!started) throw new Error("RCCService failed to start")
|
if (!started) throw new Error("RCCService failed to start")
|
||||||
if (!this.client) await this.CreateClient()
|
if (!this.client) await this.CreateClient()
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ function update(LeavingPlayer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function keepAlive(LeavingPlayer)
|
function keepAlive(LeavingPlayer)
|
||||||
game:GetService("HttpService"):PostAsync(baseUrl .. "/API/KeepAlive", game:GetService("HttpService"):JSONEncode({
|
game:GetService("HttpService"):PostAsync("https://dungblx.cf/API/KeepAlive", game:GetService("HttpService"):JSONEncode({
|
||||||
["ServerIP"] = jobId,
|
["ServerIP"] = jobId,
|
||||||
["PlaceId"] = game.PlaceId,
|
["PlaceId"] = game.PlaceId,
|
||||||
["PlayerCount"] = #game:GetService("Players"):GetPlayers(),
|
["PlayerCount"] = #game:GetService("Players"):GetPlayers(),
|
||||||
|
|
@ -114,8 +114,9 @@ end
|
||||||
|
|
||||||
------------------------------ RENEW GAME JOB SERVICE -------------------------------
|
------------------------------ RENEW GAME JOB SERVICE -------------------------------
|
||||||
|
|
||||||
coroutine.resume(coroutine.create((function()
|
spawn(function()
|
||||||
while wait(30) do
|
while true do
|
||||||
|
wait(10)
|
||||||
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/" .. jobId .. "/kill") end)
|
||||||
else
|
else
|
||||||
|
|
@ -123,7 +124,7 @@ coroutine.resume(coroutine.create((function()
|
||||||
keepAlive()
|
keepAlive()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)))
|
end)
|
||||||
|
|
||||||
------------------------------END START GAME SHARED SCRIPT--------------------------
|
------------------------------END START GAME SHARED SCRIPT--------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
local jobId, type, format, x, y, baseUrl, assetId, key = ...
|
local jobId, type, format, x, y, baseUrl, assetId = ...
|
||||||
|
|
||||||
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 +11,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/server/%d/place?key=%s"):format(baseUrl, assetId, key))
|
game:Load(baseUrl .. "/thumbs/staticimage?r=" .. jobId)
|
||||||
|
|
||||||
game:GetService("ScriptContext").ScriptsDisabled = true
|
game:GetService("ScriptContext").ScriptsDisabled = true
|
||||||
game:GetService("StarterGui").ShowDevelopmentGui = false
|
game:GetService("StarterGui").ShowDevelopmentGui = false
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
const express = require("express")
|
|
||||||
const app = express.Router()
|
|
||||||
|
|
||||||
app.all("*", (request, response) => response.status(404).json({ status: 404 }))
|
|
||||||
|
|
||||||
module.exports = app
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
const express = require("express")
|
||||||
|
const app = express.Router()
|
||||||
|
|
||||||
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
|
app.get("/:token", async (request, response) => {
|
||||||
|
const game = global.games.get(request.params.token)
|
||||||
|
return response.end(!!game)
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = app
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
const express = require("express")
|
const express = require("express")
|
||||||
const app = express.Router()
|
const app = express.Router()
|
||||||
|
|
||||||
app.all("*", (request, response) => response.status(404).json({ status: 404 }))
|
const RenderJob = require("../../lib/classes/RenderJob.js")
|
||||||
|
|
||||||
|
app.get("/:id", async (request, response) => {
|
||||||
|
const job = new RenderJob()
|
||||||
|
const result = await job.RenderPlace(request.params.id, process.env.RENDER_BASE64).catch((_) => _)
|
||||||
|
|
||||||
|
if (result?.message) return response.status(500).json({ error: result.message })
|
||||||
|
else return response.end(result)
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = app
|
module.exports = app
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue