Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path')
- const fs = require('fs-extra')
- const homepath = process.argv[2]
- const gameTypes = ["oracle", "opticstrike", "battleboats", "skyrush"]
- var screen = require('screen-init')()
- const Hapi = require('hapi')
- const server = Hapi.Server({
- port: 3001,
- })
- server.ext('onRequest', (request, h) => {
- // do something
- const authorization = request.headers.authorization;
- if(!authorization || authorization !== "thisisprivatecubed!"){
- let response = h.response({error: "Not authorized"});
- response.code(401)
- return response.takeover()
- }
- return h.continue;
- });
- server.route({
- method: 'GET',
- path: '/setup/{game}/{amount}',
- handler: (request, h) => {
- let game = request.params.game
- let amount = request.params.amount
- fs.mkdirSync(path.join(homepath, game))
- for(var i = 0; i < amount; i++){
- fs.copySync(path.join(homepath, "templates", game), path.join(homepath, game, game + "-" + i))
- screen.newScreen()
- screen.title(game + "-" + i)
- screen.exec("cd " + path.join(homepath, game, game + "-" + i))
- screen.exec("./start.sh")
- }
- return {success: true}
- }
- })
- server.route({
- method: 'GET',
- path: '/start/{game}/{amount}',
- handler: (request, h) => {
- let game = request.params.game
- let amount = request.params.amount
- for(var i = 0; i < amount; i++){
- screen.newScreen()
- screen.title(game + "-" + i)
- screen.exec("cd " + path.join(homepath, game, game + "-" + i))
- screen.exec("./start.sh")
- }
- return {success: true}
- }
- })
- server.route({
- method: 'GET',
- path: '/stop/{game}/{amount}',
- handler: (request, h) => {
- let game = request.params.game
- let amount = request.params.amount
- for(var i = 0; i < amount; i++){
- screen.exec("stop", game + "-" + i)
- }
- return {success: true}
- }
- })
- const init = async () => {
- await server.start()
- console.log(`Server running at ${server.info.uri}`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement