Games 🥳

This commit is contained in:
I-Have-An-Issue 2023-01-23 00:38:34 -05:00
parent 1412f534c7
commit 350ef70cee
No known key found for this signature in database
GPG Key ID: E55435DEA0825091
8 changed files with 35 additions and 15 deletions

View File

@ -6,7 +6,7 @@ const logger = require("../logger.js")
class GameJob extends Job {
constructor() {
super()
super({ expirationInSeconds: 360 })
}
StartGame(id) {
@ -45,4 +45,3 @@ class GameJob extends Job {
}
module.exports = GameJob
// a http://crapblox.cf/ -t 1 -j http://crapblox.cf//Game/JoinServer?Token=jRCfrKmwFfLBAvjNOQqNuOB210rjIvz4UfMhwIaY7teYGxXniECENL2vh8rvhSU2&PlaceId=10052

View File

@ -2,6 +2,7 @@ const soap = require("soap")
const { randomUUID } = require("crypto")
const RCCService = require("./RCCService.js")
const logger = require("../logger.js")
class Job extends RCCService {
constructor({ id = randomUUID(), expirationInSeconds = 10, category = 0, cores = 1 } = {}) {
@ -37,6 +38,7 @@ class Job extends RCCService {
async RenewLease(expirationInSeconds) {
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 })
}

View File

@ -115,6 +115,11 @@ class RenderJob extends Job {
}
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()
if (!started) throw new Error("RCCService failed to start")
if (!this.client) await this.CreateClient()

View File

@ -31,7 +31,7 @@ function update(LeavingPlayer)
end
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,
["PlaceId"] = game.PlaceId,
["PlayerCount"] = #game:GetService("Players"):GetPlayers(),
@ -114,8 +114,9 @@ end
------------------------------ RENEW GAME JOB SERVICE -------------------------------
coroutine.resume(coroutine.create((function()
while wait(30) do
spawn(function()
while true do
wait(10)
if #game.Players:GetPlayers() == 0 then
pcall(function() game:HttpGet(baseUrl .. "/arbiter/" .. jobId .. "/kill") end)
else
@ -123,7 +124,7 @@ coroutine.resume(coroutine.create((function()
keepAlive()
end
end
end)))
end)
------------------------------END START GAME SHARED SCRIPT--------------------------

View File

@ -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))
@ -11,7 +11,7 @@ game:GetService("ContentProvider"):SetBaseUrl(baseUrl)
game:GetService("ScriptContext").ScriptsDisabled = true
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("StarterGui").ShowDevelopmentGui = false

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,14 @@
const express = require("express")
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