This commit is contained in:
commit
88135b551b
96
README.md
96
README.md
|
|
@ -7,3 +7,99 @@ It comes preloaded with some Lua scripts made by kinery and jackd900.
|
||||||
You **will** have to replace/modify these scripts when implementing for your own projects.
|
You **will** have to replace/modify these scripts when implementing for your own projects.
|
||||||
|
|
||||||
Set your desired settings in `.env.example`, then rename it to `.env`.
|
Set your desired settings in `.env.example`, then rename it to `.env`.
|
||||||
|
|
||||||
|
## Routes
|
||||||
|
|
||||||
|
### GET /render/asset/:id
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>200 OK</summary>
|
||||||
|
|
||||||
|
```
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC...
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### GET /render/asset/3d/:id
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>200 OK</summary>
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"camera": {
|
||||||
|
"position": { "x": 0, "y": 0, "z": 0 },
|
||||||
|
"direction": { "x": 0, "y": 0, "z": 0 }
|
||||||
|
},
|
||||||
|
"AABB": {
|
||||||
|
"min": { "x": 0, "y": 0, "z": 0 },
|
||||||
|
"max": { "x": 0, "y": 0, "z": 0 }
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"scene.obj": { "content": "..." },
|
||||||
|
"scene.mtl": { "content": "..." },
|
||||||
|
"Handle1Tex.png": { "content": "..." }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### GET /render/texture/:id
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>200 OK</summary>
|
||||||
|
|
||||||
|
```
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC...
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### GET /render/user/headshot/:id
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>200 OK</summary>
|
||||||
|
|
||||||
|
```
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC...
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### GET /render/user/bodyshot/:id
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>200 OK</summary>
|
||||||
|
|
||||||
|
```
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC...
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
### GET /render/user/3d/:id
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>200 OK</summary>
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"camera": {
|
||||||
|
"position": { "x": 0, "y": 0, "z": 0 },
|
||||||
|
"direction": { "x": 0, "y": 0, "z": 0 }
|
||||||
|
},
|
||||||
|
"AABB": {
|
||||||
|
"min": { "x": 0, "y": 0, "z": 0 },
|
||||||
|
"max": { "x": 0, "y": 0, "z": 0 }
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"scene.obj": { "content": "..." },
|
||||||
|
"scene.mtl": { "content": "..." },
|
||||||
|
"Handle1Tex.png": { "content": "..." }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
|
PORT=
|
||||||
RCCSERVICE=
|
RCCSERVICE=
|
||||||
ARBITER_TOKEN=
|
ARBITER_TOKEN=
|
||||||
|
|
||||||
BASE_URL=https://crapblox.cf
|
BASE_URL=https://crapblox.cf
|
||||||
|
|
||||||
RENDER_FORMAT=PNG
|
ARBITER_TOKEN=
|
||||||
|
ARBITER_KEY=
|
||||||
|
|
||||||
RENDER_USER_WIDTH=420
|
RENDER_USER_WIDTH=420
|
||||||
RENDER_USER_HEIGHT=420
|
RENDER_USER_HEIGHT=420
|
||||||
|
|
|
||||||
30
src/index.js
30
src/index.js
|
|
@ -6,13 +6,11 @@ const logger = require("./lib/logger.js")
|
||||||
|
|
||||||
if (process.platform == "linux") logger.warn("Game hosting might not be fully compatible with Linux")
|
if (process.platform == "linux") logger.warn("Game hosting might not be fully compatible with Linux")
|
||||||
|
|
||||||
global.games = new Map()
|
app.use(({ query }, response, next) => {
|
||||||
|
if (!query.key) return response.status(400).json({ error: "Missing key in query" })
|
||||||
setInterval(() => {
|
if (query.key !== process.env.ARBITER_KEY) return response.status(403).json({ error: "Incorrect key in query" })
|
||||||
global.games.forEach(async (value, key) => {
|
next()
|
||||||
if (!(await value.Running())) value.Stop()
|
})
|
||||||
})
|
|
||||||
}, 15000)
|
|
||||||
|
|
||||||
app.use("/game/start", require("./routes/game/start.js"))
|
app.use("/game/start", require("./routes/game/start.js"))
|
||||||
app.use("/game/stop", require("./routes/game/stop.js"))
|
app.use("/game/stop", require("./routes/game/stop.js"))
|
||||||
|
|
@ -22,17 +20,19 @@ app.use("/game/status", require("./routes/game/status.js"))
|
||||||
app.use("/game/execute", require("./routes/game/execute.js"))
|
app.use("/game/execute", require("./routes/game/execute.js"))
|
||||||
|
|
||||||
app.use("/render/asset", require("./routes/render/asset.js"))
|
app.use("/render/asset", require("./routes/render/asset.js"))
|
||||||
//app.use("/render/game", require("./routes/render/game.js"))
|
app.use("/render/game", require("./routes/render/game.js"))
|
||||||
//app.use("/render/texture", require("./routes/render/texture.js"))
|
app.use("/render/texture", require("./routes/render/texture.js"))
|
||||||
app.use("/render/user", require("./routes/render/user.js"))
|
app.use("/render/user", require("./routes/render/user.js"))
|
||||||
app.use("/render/texture", require("./routes/render/texture.js"))
|
app.use("/render/texture", require("./routes/render/texture.js"))
|
||||||
|
|
||||||
app.use("*", require("./routes/index.js"))
|
app.use("*", require("./routes/index.js"))
|
||||||
|
|
||||||
app.listen(process.env.PORT || 64989, () => {
|
process.on("uncaughtException", (err) => logger.error(err.message))
|
||||||
logger.boot(`Listening on http://127.0.0.1:${process.env.PORT || 64989}/`)
|
global.games = new Map()
|
||||||
})
|
setInterval(() => {
|
||||||
|
global.games.forEach(async (value, key) => {
|
||||||
|
if (!(await value.Running())) value.Stop()
|
||||||
|
})
|
||||||
|
}, 15000)
|
||||||
|
|
||||||
process.on("uncaughtException", (err) => {
|
app.listen(process.env.PORT, () => logger.boot(`Listening on http://127.0.0.1:${process.env.PORT}/`))
|
||||||
logger.error(err.message)
|
|
||||||
})
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ const { readFile } = require("fs/promises")
|
||||||
|
|
||||||
const Job = require("./Job.js")
|
const Job = require("./Job.js")
|
||||||
const logger = require("../logger.js")
|
const logger = require("../logger.js")
|
||||||
|
const randport = require("../randport.js")
|
||||||
|
|
||||||
class GameJob extends Job {
|
class GameJob extends Job {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -11,10 +12,6 @@ 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, server_owner_id } = response.data
|
|
||||||
|
|
||||||
this.id = server_token
|
|
||||||
this.placeId = id
|
this.placeId = id
|
||||||
|
|
||||||
const started = await this.Start()
|
const started = await this.Start()
|
||||||
|
|
@ -23,6 +20,8 @@ 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" }),
|
||||||
|
|
@ -34,13 +33,12 @@ 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: server_port },
|
{ type: "LUA_TNUMBER", value: port },
|
||||||
{ type: "LUA_TNUMBER", value: server_owner_id },
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}).catch((e) => reject(e))
|
}).catch((e) => reject(e))
|
||||||
|
|
||||||
resolve()
|
resolve(port)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ const RCCService = require("./RCCService.js")
|
||||||
const logger = require("../logger.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 = 60, category = 0, cores = 1 } = {}) {
|
||||||
super()
|
super()
|
||||||
this.id = id
|
this.id = id
|
||||||
this.expirationInSeconds = expirationInSeconds
|
this.expirationInSeconds = expirationInSeconds
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const { readFile } = require("fs/promises")
|
const { readFile } = require("fs/promises")
|
||||||
const chalk = require('chalk')
|
const chalk = require("chalk")
|
||||||
|
|
||||||
const Job = require("./Job.js")
|
const Job = require("./Job.js")
|
||||||
const logger = require("../logger.js")
|
const logger = require("../logger.js")
|
||||||
|
|
@ -31,7 +31,7 @@ class RenderJob extends Job {
|
||||||
{ type: "LUA_TSTRING", value: this.id },
|
{ type: "LUA_TSTRING", value: this.id },
|
||||||
|
|
||||||
{ type: "LUA_TSTRING", value: "Headshot" },
|
{ type: "LUA_TSTRING", value: "Headshot" },
|
||||||
{ type: "LUA_TSTRING", value: process.env.RENDER_FORMAT },
|
{ type: "LUA_TSTRING", value: "PNG" },
|
||||||
|
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH },
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT },
|
||||||
|
|
@ -44,6 +44,8 @@ class RenderJob extends Job {
|
||||||
|
|
||||||
logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Headshot RenderJob finished for ${id}`)
|
logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Headshot RenderJob finished for ${id}`)
|
||||||
|
|
||||||
|
this.Stop()
|
||||||
|
|
||||||
if (!result) return false
|
if (!result) return false
|
||||||
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +72,7 @@ class RenderJob extends Job {
|
||||||
{ type: "LUA_TSTRING", value: this.id },
|
{ type: "LUA_TSTRING", value: this.id },
|
||||||
|
|
||||||
{ type: "LUA_TSTRING", value: "Bodyshot" },
|
{ type: "LUA_TSTRING", value: "Bodyshot" },
|
||||||
{ type: "LUA_TSTRING", value: three_d ? "OBJ" : process.env.RENDER_FORMAT },
|
{ type: "LUA_TSTRING", value: three_d ? "OBJ" : "PNG" },
|
||||||
|
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH },
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT },
|
||||||
|
|
@ -84,6 +86,8 @@ class RenderJob extends Job {
|
||||||
if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Bodyshot RenderJob finished for ${id}`)
|
if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Bodyshot RenderJob finished for ${id}`)
|
||||||
else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Bodyshot RenderJob finished for ${id}`)
|
else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Bodyshot RenderJob finished for ${id}`)
|
||||||
|
|
||||||
|
this.Stop()
|
||||||
|
|
||||||
if (!result) return false
|
if (!result) return false
|
||||||
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +114,7 @@ class RenderJob extends Job {
|
||||||
{ type: "LUA_TSTRING", value: this.id },
|
{ type: "LUA_TSTRING", value: this.id },
|
||||||
|
|
||||||
{ type: "LUA_TSTRING", value: "Asset" },
|
{ type: "LUA_TSTRING", value: "Asset" },
|
||||||
{ type: "LUA_TSTRING", value: three_d ? "OBJ" : process.env.RENDER_FORMAT },
|
{ type: "LUA_TSTRING", value: three_d ? "OBJ" : "PNG" },
|
||||||
|
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_ASSET_WIDTH },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_ASSET_WIDTH },
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_ASSET_HEIGHT },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_ASSET_HEIGHT },
|
||||||
|
|
@ -125,16 +129,13 @@ class RenderJob extends Job {
|
||||||
if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Asset RenderJob finished for ${id}`)
|
if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Asset RenderJob finished for ${id}`)
|
||||||
else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Asset RenderJob finished for ${id}`)
|
else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Asset RenderJob finished for ${id}`)
|
||||||
|
|
||||||
|
this.Stop()
|
||||||
|
|
||||||
if (!result) return false
|
if (!result) return false
|
||||||
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
||||||
}
|
}
|
||||||
|
|
||||||
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, server_port, server_owner_id } = response.data
|
|
||||||
|
|
||||||
this.id = server_token
|
|
||||||
|
|
||||||
const running = this.started
|
const running = this.started
|
||||||
if (!running) {
|
if (!running) {
|
||||||
const started = await this.Start()
|
const started = await this.Start()
|
||||||
|
|
@ -153,19 +154,22 @@ class RenderJob extends Job {
|
||||||
{ type: "LUA_TSTRING", value: this.id },
|
{ type: "LUA_TSTRING", value: this.id },
|
||||||
|
|
||||||
{ type: "LUA_TSTRING", value: "Place" },
|
{ type: "LUA_TSTRING", value: "Place" },
|
||||||
{ type: "LUA_TSTRING", value: process.env.RENDER_FORMAT },
|
{ type: "LUA_TSTRING", value: "PNG" },
|
||||||
|
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_PLACE_WIDTH },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_PLACE_WIDTH },
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_PLACE_HEIGHT },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_PLACE_HEIGHT },
|
||||||
|
|
||||||
{ 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 },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}).catch((e) => false)
|
}).catch((e) => false)
|
||||||
|
|
||||||
logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Place RenderJob finished for ${id}`)
|
logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Place RenderJob finished for ${id}`)
|
||||||
|
|
||||||
|
this.Stop()
|
||||||
|
|
||||||
if (!result) return false
|
if (!result) return false
|
||||||
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +195,7 @@ class RenderJob extends Job {
|
||||||
{ type: "LUA_TSTRING", value: this.id },
|
{ type: "LUA_TSTRING", value: this.id },
|
||||||
|
|
||||||
{ type: "LUA_TSTRING", value: "Texture" },
|
{ type: "LUA_TSTRING", value: "Texture" },
|
||||||
{ type: "LUA_TSTRING", value: process.env.RENDER_FORMAT },
|
{ type: "LUA_TSTRING", value: "PNG" },
|
||||||
|
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH },
|
||||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT },
|
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT },
|
||||||
|
|
@ -204,6 +208,8 @@ class RenderJob extends Job {
|
||||||
|
|
||||||
logger.info(`[${this.id}] Headshot RenderJob finished for ${id}`)
|
logger.info(`[${this.id}] Headshot RenderJob finished for ${id}`)
|
||||||
|
|
||||||
|
this.Stop()
|
||||||
|
|
||||||
if (!result) return false
|
if (!result) return false
|
||||||
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ exports.tcp = () => {
|
||||||
|
|
||||||
exports.udp = () => {
|
exports.udp = () => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const server = dgram.createSocket()
|
const server = dgram.createSocket("udp4")
|
||||||
server.bind(0, () => {
|
server.bind(Math.random() * (60_000 - 50_000) + 50_000, () => {
|
||||||
const port = server.address().port
|
const port = server.address().port
|
||||||
server.close((err) => resolve(port))
|
server.close((err) => resolve(port))
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
local jobId, type, baseUrl, placeId, port, owner = ...
|
local jobId, type, baseUrl, placeId, port = ...
|
||||||
|
|
||||||
------------------- 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)
|
||||||
if child then
|
if child then return child end
|
||||||
return child
|
|
||||||
end
|
|
||||||
parent.ChildAdded:wait()
|
parent.ChildAdded:wait()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -66,20 +63,16 @@ 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(assetId, false)
|
game:SetPlaceID(placeId, false)
|
||||||
game:GetService("ChangeHistoryService"):SetEnabled(false)
|
game:GetService("ChangeHistoryService"):SetEnabled(false)
|
||||||
game:SetCreatorId(owner, Enum.CreatorType.User)
|
|
||||||
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)
|
||||||
|
|
@ -99,29 +92,16 @@ 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 .. "/thumbs/staticimage?r=" .. jobId)
|
game:Load(baseUrl .. "/asset/?id=" .. placeId)
|
||||||
end
|
end
|
||||||
|
|
||||||
------------------------------ RENEW GAME JOB SERVICE -------------------------------
|
------------------------------ RENEW GAME JOB SERVICE -------------------------------
|
||||||
|
|
@ -144,4 +124,6 @@ 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()
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
|
|
||||||
app.post("/:token", async (request, response) => {
|
app.post("/:id", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.status(404).json({ error: "Game is not running" })
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
const { script } = request.body
|
const { script } = request.body
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.get("/:token/:expire", async (request, response) => {
|
app.get("/:id/:expire", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.status(404).json({ error: "Game is not running" })
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
await game.RenewLease(request.params.expire)
|
await game.RenewLease(request.params.expire)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.get("/:token", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.json(false)
|
if (!game) return response.json(false)
|
||||||
|
|
||||||
const running = await game.Running()
|
const running = await game.Running()
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,16 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
function getGameById(id) {
|
|
||||||
let game
|
|
||||||
|
|
||||||
global.games.forEach((value, key) => {
|
|
||||||
if (value.placeId == id) game = value
|
|
||||||
})
|
|
||||||
|
|
||||||
return game
|
|
||||||
}
|
|
||||||
|
|
||||||
app.get("/:id", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
const game = global.games.get(getGameById(request.params.id)?.id)
|
const game = global.games.get(request.params.id)
|
||||||
if (game) return response.status(400).json({ error: "Game is running" })
|
if (game) return response.status(400).json({ error: "Game is running" })
|
||||||
|
|
||||||
const job = new GameJob()
|
const job = new GameJob()
|
||||||
const result = await job.StartGame(request.params.id).catch((_) => _)
|
const result = await job.StartGame(request.params.id).catch((_) => _)
|
||||||
|
|
||||||
global.games.set(job.id, job)
|
global.games.set(request.params.id, job)
|
||||||
job.proc.once("exit", () => {
|
job.proc.once("exit", () => {
|
||||||
global.games.delete(job.id)
|
global.games.delete(request.params.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
return response.json({ success: true })
|
return response.json({ success: true })
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.get("/:token", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.status(404).json({ error: "Game is not running" })
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
const status = await game.GetStatus()
|
const status = await game.GetStatus()
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ const app = express.Router()
|
||||||
|
|
||||||
const GameJob = require("../../lib/classes/GameJob.js")
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
app.get("/:token", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
const game = global.games.get(request.params.token)
|
const game = global.games.get(request.params.id)
|
||||||
if (!game) return response.status(404).json({ error: "Game is not running" })
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
game.Stop()
|
game.Stop()
|
||||||
|
|
|
||||||
|
|
@ -6,27 +6,21 @@ const RenderJob = require("../../lib/classes/RenderJob.js")
|
||||||
app.get("/:id", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
const { params, query } = request
|
const { params, query } = request
|
||||||
const job = new RenderJob()
|
const job = new RenderJob()
|
||||||
let body = {}
|
|
||||||
|
|
||||||
const asset = await job.RenderAsset(params.id).catch((_) => _)
|
const asset = await job.RenderAsset(params.id).catch((_) => _)
|
||||||
if (asset?.message) {
|
if (asset?.message) return response.status(500).json({ error: asset.message })
|
||||||
job.Stop()
|
|
||||||
return response.status(500).json({ error: asset.message })
|
|
||||||
}
|
|
||||||
body.asset = asset
|
|
||||||
|
|
||||||
if (query.three_d) {
|
return response.end(asset)
|
||||||
const three_d = await job.RenderAsset(params.id, true).catch((_) => _)
|
})
|
||||||
if (three_d?.message) {
|
|
||||||
job.Stop()
|
|
||||||
return response.status(500).json({ error: three_d.message })
|
|
||||||
}
|
|
||||||
body.three_d = three_d
|
|
||||||
}
|
|
||||||
|
|
||||||
job.Stop()
|
app.get("/:id/3d", async (request, response) => {
|
||||||
|
const { params, query } = request
|
||||||
|
const job = new RenderJob()
|
||||||
|
|
||||||
return response.json(body)
|
const three_d = await job.RenderAsset(params.id, true).catch((_) => _)
|
||||||
|
if (three_d?.message) return response.status(500).json({ error: three_d.message })
|
||||||
|
|
||||||
|
return response.json(JSON.parse(three_d))
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = app
|
module.exports = app
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@ const app = express.Router()
|
||||||
const RenderJob = require("../../lib/classes/RenderJob.js")
|
const RenderJob = require("../../lib/classes/RenderJob.js")
|
||||||
|
|
||||||
app.get("/:id", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
|
const { params, query } = request
|
||||||
const job = new RenderJob()
|
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 })
|
const game = await job.RenderPlace(params.id).catch((_) => _)
|
||||||
else return response.end(result)
|
if (game?.message) return response.status(500).json({ error: game.message })
|
||||||
|
|
||||||
|
return response.end(game)
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = app
|
module.exports = app
|
||||||
|
|
|
||||||
|
|
@ -6,18 +6,11 @@ const RenderJob = require("../../lib/classes/RenderJob.js")
|
||||||
app.get("/:id", async (request, response) => {
|
app.get("/:id", async (request, response) => {
|
||||||
const { params, query } = request
|
const { params, query } = request
|
||||||
const job = new RenderJob()
|
const job = new RenderJob()
|
||||||
let body = {}
|
|
||||||
|
|
||||||
const texture = await job.RenderTexture(params.id).catch((_) => _)
|
const texture = await job.RenderTexture(params.id).catch((_) => _)
|
||||||
if (texture?.message) {
|
if (texture?.message) return response.status(500).json({ error: texture.message })
|
||||||
job.Stop()
|
|
||||||
return response.status(500).json({ error: texture.message })
|
|
||||||
}
|
|
||||||
body.texture = texture
|
|
||||||
|
|
||||||
job.Stop()
|
return response.end(texture)
|
||||||
|
|
||||||
return response.json(body)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = app
|
module.exports = app
|
||||||
|
|
|
||||||
|
|
@ -3,37 +3,34 @@ const app = express.Router()
|
||||||
|
|
||||||
const RenderJob = require("../../lib/classes/RenderJob.js")
|
const RenderJob = require("../../lib/classes/RenderJob.js")
|
||||||
|
|
||||||
app.get("/:id", async (request, response) => {
|
app.get("/:id/bodyshot", async (request, response) => {
|
||||||
const { params, query } = request
|
const { params } = request
|
||||||
const job = new RenderJob()
|
const job = new RenderJob()
|
||||||
let body = {}
|
|
||||||
|
|
||||||
const headshot = await job.RenderHeadshot(params.id).catch((_) => _)
|
|
||||||
if (headshot?.message) {
|
|
||||||
job.Stop()
|
|
||||||
return response.status(500).json({ error: headshot.message })
|
|
||||||
}
|
|
||||||
body.headshot = headshot
|
|
||||||
|
|
||||||
const bodyshot = await job.RenderBodyshot(params.id).catch((_) => _)
|
const bodyshot = await job.RenderBodyshot(params.id).catch((_) => _)
|
||||||
if (bodyshot?.message) {
|
if (bodyshot?.message) return response.status(500).json({ error: bodyshot.message })
|
||||||
job.Stop()
|
|
||||||
return response.status(500).json({ error: bodyshot.message })
|
|
||||||
}
|
|
||||||
body.bodyshot = bodyshot
|
|
||||||
|
|
||||||
if (query.three_d) {
|
return response.end(bodyshot)
|
||||||
const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _)
|
})
|
||||||
if (three_d?.message) {
|
|
||||||
job.Stop()
|
|
||||||
return response.status(500).json({ error: three_d.message })
|
|
||||||
}
|
|
||||||
body.three_d = three_d
|
|
||||||
}
|
|
||||||
|
|
||||||
job.Stop()
|
app.get("/:id/headshot", async (request, response) => {
|
||||||
|
const { params } = request
|
||||||
|
const job = new RenderJob()
|
||||||
|
|
||||||
return response.json(body)
|
const headshot = await job.RenderHeadshot(params.id).catch((_) => _)
|
||||||
|
if (headshot?.message) return response.status(500).json({ error: headshot.message })
|
||||||
|
|
||||||
|
return response.end(headshot)
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get("/:id/3d", async (request, response) => {
|
||||||
|
const { params, query } = request
|
||||||
|
const job = new RenderJob()
|
||||||
|
|
||||||
|
const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _)
|
||||||
|
if (three_d?.message) return response.status(500).json({ error: three_d.message })
|
||||||
|
|
||||||
|
return response.json(JSON.parse(three_d))
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = app
|
module.exports = app
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue