Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. const path = require('path')
  2. const fs = require('fs-extra')
  3. const homepath = process.argv[2]
  4. const gameTypes = ["oracle", "opticstrike", "battleboats", "skyrush"]
  5. var screen = require('screen-init')()
  6. const Hapi = require('hapi')
  7.  
  8. const server = Hapi.Server({
  9. port: 3001,
  10. })
  11.  
  12.  
  13. server.ext('onRequest', (request, h) => {
  14. // do something
  15. const authorization = request.headers.authorization;
  16. if(!authorization || authorization !== "thisisprivatecubed!"){
  17. let response = h.response({error: "Not authorized"});
  18. response.code(401)
  19. return response.takeover()
  20. }
  21. return h.continue;
  22. });
  23.  
  24. server.route({
  25. method: 'GET',
  26. path: '/setup/{game}/{amount}',
  27. handler: (request, h) => {
  28. let game = request.params.game
  29. let amount = request.params.amount
  30. fs.mkdirSync(path.join(homepath, game))
  31. for(var i = 0; i < amount; i++){
  32. fs.copySync(path.join(homepath, "templates", game), path.join(homepath, game, game + "-" + i))
  33. screen.newScreen()
  34. screen.title(game + "-" + i)
  35. screen.exec("cd " + path.join(homepath, game, game + "-" + i))
  36. screen.exec("./start.sh")
  37. }
  38. return {success: true}
  39. }
  40. })
  41. server.route({
  42. method: 'GET',
  43. path: '/start/{game}/{amount}',
  44. handler: (request, h) => {
  45. let game = request.params.game
  46. let amount = request.params.amount
  47. for(var i = 0; i < amount; i++){
  48. screen.newScreen()
  49. screen.title(game + "-" + i)
  50. screen.exec("cd " + path.join(homepath, game, game + "-" + i))
  51. screen.exec("./start.sh")
  52. }
  53. return {success: true}
  54. }
  55. })
  56.  
  57. server.route({
  58. method: 'GET',
  59. path: '/stop/{game}/{amount}',
  60. handler: (request, h) => {
  61. let game = request.params.game
  62. let amount = request.params.amount
  63. for(var i = 0; i < amount; i++){
  64. screen.exec("stop", game + "-" + i)
  65. }
  66. return {success: true}
  67. }
  68. })
  69. const init = async () => {
  70. await server.start()
  71. console.log(`Server running at ${server.info.uri}`)
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement