Merge crapblox and tadah

This commit is contained in:
cirroskais 2023-08-27 03:49:00 -04:00
commit 72e40b3083
No known key found for this signature in database
GPG Key ID: E55435DEA0825091
5 changed files with 63 additions and 11 deletions

View File

@ -11,8 +11,13 @@ class GameJob extends Job {
StartGame(id, port) {
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.port = port
this.id = id
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")

View File

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

View File

@ -12,6 +12,39 @@ function waitForChild(parent, childName)
end
end
function update(LeavingPlayer)
local names = {}
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
if (player ~= LeavingPlayer) then
table.insert(names, player.Name)
end
end
local str = (#names > 0) and (#names > 1) and (names[1] .. ",") or names[1] or ""
for i = 2, #names -1, 1 do
str = str .. names[i] .. ","
end
str = (#names > 0) and (#names > 1) and (str .. names[#names]) or names[1] or ""
return str
end
function keepAlive(LeavingPlayer)
pcall(function()
game:GetService("HttpService").HttpEnabled = true
local body = game:GetService("HttpService"):JSONEncode({
["ServerIP"] = jobId,
["PlaceId"] = game.PlaceId,
["PlayerCount"] = #game:GetService("Players"):GetPlayers(),
["PlayerList"] = update(LeavingPlayer),
})
return game:GetService("HttpService"):PostAsync("https://dungblx.cf/API/KeepAlive", body)
end)
end
-----------------------------------END UTILITY FUNCTIONS -------------------------
-----------------------------------"CUSTOM" SHARED CODE----------------------------------
@ -34,6 +67,7 @@ pcall(function() scriptContext:AddStarterScript(37801172) end)
game:SetPlaceID(assetId, false)
game:GetService("ChangeHistoryService"):SetEnabled(false)
game:GetService("HttpService").HttpEnabled = true
local ns = game:GetService("NetworkServer")
@ -54,7 +88,8 @@ if baseUrl ~= nil then
game:GetService("InsertService"):SetAssetUrl(baseUrl .. "/Asset/?id=%d")
game:GetService("InsertService"):SetAssetVersionUrl(baseUrl .. "/Asset/?assetversionid=%d")
pcall(function() loadfile(baseUrl .. "/Game/LoadPlaceInfo.ashx?PlaceId=" .. placeId)() end)
pcall(function() loadfile(baseUrl .. "/Game/LoadPlaceInfo.ashx?PlaceId=" .. placeId)() end)
pcall(function() game:GetService("NetworkServer"):SetIsPlayerAuthenticationRequired(true) end)
end
pcall(function() game:GetService("NetworkServer"):SetIsPlayerAuthenticationRequired(true) end)
@ -106,6 +141,4 @@ spawn(function()
end
end)
------------------------------END START GAME SHARED SCRIPT--------------------------
game:GetService("RunService"):Run()

View File

@ -8,16 +8,23 @@ game:GetService("InsertService"):SetAssetVersionUrl(baseUrl .. "/Asset/?assetver
game:GetService("ContentProvider"):SetBaseUrl(baseUrl)
game:GetService("ScriptContext").ScriptsDisabled = true
local asset = game:GetObjects(("%s/asset/?id=%d"):format(baseUrl, assetId))[1]
asset.Parent = workspace
local Player = game.Players:CreateLocalPlayer(0)
Player.CharacterAppearance = ("%s/v1.1/asset-render/%d"):format(baseUrl, assetId)
Player:LoadCharacter(false)
local thumbnailCamera = asset:FindFirstChild("ThumbnailCamera")
if thumbnailCamera ~= nil and thumbnailCamera.ClassName == "Camera" then
workspace.CurrentCamera = thumbnailCamera
game:GetService("RunService"):Run()
Player.Character.Animate.Disabled = true
Player.Character.Torso.Anchored = true
local gear = Player.Backpack:GetChildren()[1]
if gear then
gear.Parent = Player.Character
Player.Character.Torso["Right Shoulder"].CurrentAngle = math.rad(90)
end
print(("[%s] Rendering ..."):format(jobId))
local result = game:GetService("ThumbnailGenerator"):Click(format, x, y, true)
print(("[%s] Done!"):format(jobId))
return result
return result

View File

@ -11,7 +11,7 @@ app.post("/:id", async (request, response) => {
if (!game) return response.status(404).json({ error: "Game is not running" })
const { script } = request.body
const jobResponse = await game.Execute(randomUUID(), script)
const jobResponse = await game.Execute(randomUUID(), script).catch((_) => _)
return response.json({ response: jobResponse })
})