gamesd
This commit is contained in:
parent
87a96a7595
commit
34102c9f47
19
.env.example
19
.env.example
|
|
@ -1,15 +1,16 @@
|
||||||
RCCSERVICE=
|
RCCSERVICE=
|
||||||
|
ARBITER_TOKEN=
|
||||||
|
|
||||||
BASE_URL=
|
BASE_URL=https://crapblox.cf
|
||||||
|
|
||||||
RENDER_FORMAT=
|
RENDER_FORMAT=PNG
|
||||||
RENDER_BASE64=
|
RENDER_BASE64=true
|
||||||
|
|
||||||
RENDER_USER_WIDTH=
|
RENDER_USER_WIDTH=420
|
||||||
RENDER_USER_HEIGHT=
|
RENDER_USER_HEIGHT=420
|
||||||
|
|
||||||
RENDER_ASSET_WIDTH=
|
RENDER_ASSET_WIDTH=420
|
||||||
RENDER_ASSET_HEIGHT=
|
RENDER_ASSET_HEIGHT=420
|
||||||
|
|
||||||
RENDER_PLACE_WIDTH=
|
RENDER_PLACE_WIDTH=720
|
||||||
RENDER_PLACE_HEIGHT=
|
RENDER_PLACE_HEIGHT=480
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"version": "0.1",
|
"version": "0.1",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^1.2.3",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
|
@ -66,13 +67,13 @@
|
||||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "0.27.2",
|
"version": "1.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.2.3.tgz",
|
||||||
"integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
|
"integrity": "sha512-pdDkMYJeuXLZ6Xj/Q5J3Phpe+jbGdsSzlQaFVkMQzRUL05+6+tetX8TV3p4HrU4kzuO9bt+io/yGQxuyxA/xcw==",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.14.9",
|
"follow-redirects": "^1.15.0",
|
||||||
"form-data": "^4.0.0"
|
"form-data": "^4.0.0",
|
||||||
|
"proxy-from-env": "^1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios-ntlm": {
|
"node_modules/axios-ntlm": {
|
||||||
|
|
@ -84,16 +85,6 @@
|
||||||
"dev-null": "^0.1.1"
|
"dev-null": "^0.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios-ntlm/node_modules/axios": {
|
|
||||||
"version": "1.2.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.2.3.tgz",
|
|
||||||
"integrity": "sha512-pdDkMYJeuXLZ6Xj/Q5J3Phpe+jbGdsSzlQaFVkMQzRUL05+6+tetX8TV3p4HrU4kzuO9bt+io/yGQxuyxA/xcw==",
|
|
||||||
"dependencies": {
|
|
||||||
"follow-redirects": "^1.15.0",
|
|
||||||
"form-data": "^4.0.0",
|
|
||||||
"proxy-from-env": "^1.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/body-parser": {
|
"node_modules/body-parser": {
|
||||||
"version": "1.20.1",
|
"version": "1.20.1",
|
||||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
|
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^1.2.3",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
|
|
||||||
11
src/index.js
11
src/index.js
|
|
@ -5,14 +5,15 @@ const app = express()
|
||||||
const logger = require("./lib/logger.js")
|
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("/place/start", require("./routes/place/start.js"))
|
app.use("/game/start", require("./routes/game/start.js"))
|
||||||
app.use("/place/stop", require("./routes/place/stop.js"))
|
app.use("/game/stop", require("./routes/game/stop.js"))
|
||||||
app.use("/place/execute", require("./routes/place/execute.js"))
|
app.use("/game/execute", require("./routes/game/execute.js"))
|
||||||
app.use("/place/renew", require("./routes/place/renew.js"))
|
app.use("/game/renew", require("./routes/game/renew.js"))
|
||||||
|
|
||||||
app.use("/render/asset", require("./routes/render/asset.js"))
|
app.use("/render/asset", require("./routes/render/asset.js"))
|
||||||
app.use("/render/place", require("./routes/render/place.js"))
|
app.use("/render/game", require("./routes/render/game.js"))
|
||||||
app.use("/render/headshot", require("./routes/render/headshot.js"))
|
app.use("/render/headshot", require("./routes/render/headshot.js"))
|
||||||
app.use("/render/bodyshot", require("./routes/render/bodyshot.js"))
|
app.use("/render/bodyshot", require("./routes/render/bodyshot.js"))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,49 @@
|
||||||
|
const axios = require("axios")
|
||||||
|
const { readFileSync } = require("fs")
|
||||||
|
|
||||||
const Job = require("./Job.js")
|
const Job = require("./Job.js")
|
||||||
|
const logger = require("../logger.js")
|
||||||
|
|
||||||
class GameJob extends Job {
|
class GameJob extends Job {
|
||||||
constructor({ placeId }) {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StartGame(id) {
|
||||||
|
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
|
||||||
|
|
||||||
|
const started = await this.Start()
|
||||||
|
if (!started) throw new Error("RCCService failed to start")
|
||||||
|
if (!this.client) await this.CreateClient()
|
||||||
|
|
||||||
|
logger.info(`[${this.id}] GameJob started for ${id}`)
|
||||||
|
|
||||||
|
this.OpenJobEx({
|
||||||
|
name: this.id,
|
||||||
|
script: readFileSync(__dirname + "/../../lua/gameserver.lua", { encoding: "utf-8" }),
|
||||||
|
arguments: {
|
||||||
|
LuaValue: [
|
||||||
|
{ type: "LUA_TSTRING", value: this.id },
|
||||||
|
{ type: "LUA_TSTRING", value: "Place" },
|
||||||
|
|
||||||
|
{ type: "LUA_TSTRING", value: process.env.BASE_URL },
|
||||||
|
|
||||||
|
{ type: "LUA_TNUMBER", value: id },
|
||||||
|
{ type: "LUA_TNUMBER", value: 53640 },
|
||||||
|
// { type: "LUA_TNUMBER", value: server_port },
|
||||||
|
{ type: "LUA_TNUMBER", value: server_owner_id },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}).catch((e) => reject(e))
|
||||||
|
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = GameJob
|
module.exports = GameJob
|
||||||
|
// a http://crapblox.cf/ -t 1 -j http://crapblox.cf//Game/JoinServer?Token=jRCfrKmwFfLBAvjNOQqNuOB210rjIvz4UfMhwIaY7teYGxXniECENL2vh8rvhSU2&PlaceId=10052
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
const express = require("express")
|
||||||
|
const app = express.Router()
|
||||||
|
|
||||||
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
|
app.get("/:token/:expire", async (request, response) => {
|
||||||
|
const game = global.games.get(request.params.token)
|
||||||
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
|
await game.RenewLease(request.params.expire)
|
||||||
|
return response.json({ success: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = app
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
const express = require("express")
|
||||||
|
const app = express.Router()
|
||||||
|
|
||||||
|
const GameJob = require("../../lib/classes/GameJob.js")
|
||||||
|
|
||||||
|
app.get("/:id", async (request, response) => {
|
||||||
|
const job = new GameJob()
|
||||||
|
const result = await job.StartGame(request.params.id).catch((_) => _)
|
||||||
|
|
||||||
|
global.games.set(job.id, job)
|
||||||
|
job.proc.once("exit", () => {
|
||||||
|
global.games.delete(job.id)
|
||||||
|
})
|
||||||
|
|
||||||
|
return response.json({ success: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = app
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
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)
|
||||||
|
if (!game) return response.status(404).json({ error: "Game is not running" })
|
||||||
|
|
||||||
|
game.Stop()
|
||||||
|
return response.json({ success: true })
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = app
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
@ -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
|
|
||||||
Loading…
Reference in New Issue