server-tools.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict';
  2. // process.exit(1);
  3. var usage = function () {
  4. var text = `
  5. USAGE : npm run tools <option>
  6. with <option> :
  7. - players : get authorized players
  8. - add-player <username> : Add a new authorized player
  9. - remove-player <username> : Remove an authorized player
  10. - syncdb : Force server to sync with db
  11. - add-game <json>: Add new game into DB
  12. '{"player1":"","player2":"","deck":"","advRules":[],"status":"","data":"{}"}'
  13. deck : faction tournament draft (one of these)
  14. advRules : popularity discard (0 or any of these)
  15. status : CREATED ONGOING FINISHED (one of these)
  16. - remove-game <method> <filter> : Remove game(s) from DB
  17. <method> / <filter>
  18. byId gameId
  19. byPlayer1 username
  20. byPlayerAny username
  21. byStatus CREATED ONGOING FINISHED (one of these)
  22. byDays number of days old is last connection
  23. finishedByDays number of days old is last connection(only finished)
  24. `;
  25. console.log(text);
  26. };
  27. var args = process.argv.slice(2);
  28. if (args.length === 0) {
  29. usage();
  30. process.exit(0);
  31. }
  32. var command = "";
  33. var option = "";
  34. switch (args[0]) {
  35. case "players":
  36. case "syncdb":
  37. command = args[0];
  38. break;
  39. case "add-player":
  40. case "remove-player":
  41. case "add-game":
  42. case "remove-game":
  43. if (args[0] === "remove-game" && args.length < 3) {
  44. usage();
  45. process.exit(0);
  46. }
  47. if (args[1] && args[1] !== "") {
  48. command = args[0];
  49. if (args[0] === "add-game") {
  50. try {
  51. option = [JSON.parse(args[1])];
  52. } catch (error) {
  53. console.log(error);
  54. process.exit(0);
  55. }
  56. } else {
  57. args.shift();
  58. option = args;
  59. }
  60. } else {
  61. console.log('error ; specify a username');
  62. usage();
  63. }
  64. break;
  65. default:
  66. usage();
  67. break;
  68. }
  69. if (command !== "") {
  70. console.log('Connecting to server...');
  71. var socket = require('socket.io-client')("http://localhost:1664");
  72. socket.emit(command, option,function (response) {
  73. console.log('Done, response from server : ', response);
  74. });
  75. }