Guest User

Untitled

a guest
Mar 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. "use strict";
  2.  
  3. const { readdirSync, existsSync, renameSync } = require("fs");
  4. const { basename, resolve } = require("path");
  5. const sysmsg = require("tera-data-parser").sysmsg,
  6. migration = require("./lib/migration"),
  7. childModules = [
  8. require("./lib/core"),
  9. require("./lib/cooldowns")
  10. ],
  11. childModulesLength = childModules.length;
  12.  
  13. const currentDir = basename(__dirname);
  14. const blockedModules = new Set(["cooldowns", "lockons", "lockons", "fastfire",
  15. "fast-fire", "fast-fire", "fast-block","skill-prediction", "pinkie-sp",
  16. "skill-prediction", "skill-prediction-exp", "fast-block", "skillprediction",
  17. "skill-prediction-experimental", "cooldowns", "sp-pinkie", "sp"]);
  18.  
  19. let errorState = false;
  20. checkBlockedModulesAndCorrectNames: {
  21. const arr = readdirSync(resolve(__dirname, "../"));
  22. const len = arr.length;
  23. const masterRegex = /-master/gi;
  24. let i = 0, foundCommand = false;
  25. do {
  26. const origName = arr[i];
  27. if (origName === currentDir) { continue; }
  28. const name = origName.replace(masterRegex, "");
  29. if (name !== origName) {
  30. try { renameSync(origName, name); }
  31. catch(_) {
  32. console.error(`[${currentDir}] ERROR! Delete either ${origName} or ${name}, whichever is older. You shouldn't have more than one of them.`);
  33. process.exit(1);
  34. }
  35. }
  36. switch(name.charAt(0)) { case ".": case "_": continue; }
  37. if (blockedModules.has(name)) {
  38. console.error(`[${currentDir}] ERROR! Blocked module ${name} installed.`);
  39. errorState = true;
  40. break checkBlockedModulesAndCorrectNames;
  41. }
  42. if (!foundCommand) {
  43. switch(name) {
  44. case "command": case "command-master": foundCommand = true;
  45. }
  46. }
  47. } while(++i < len);
  48. if (!foundCommand) {
  49. console.error(`[${currentDir}] ERROR! Missing module "command". Close tera-proxy and install it.`);
  50. errorState = true;
  51. }
  52. }
  53.  
  54.  
  55. migrateOldConfig: {
  56. const migrationConfigPath = resolve(__dirname, "./migration/partial-config.json");
  57. const originalConfigPath = resolve(__dirname, "./config/config.json");
  58.  
  59. if (existsSync(migrationConfigPath)) {
  60. const migrationHelper = new migration.ConfigMigrationHelper(migrationConfigPath, originalConfigPath);
  61. if (!migrationHelper.compareJsons()) {
  62. migrationHelper.applyMigration();
  63. }
  64. }
  65. }
  66.  
  67. const ctxSymbol = Symbol("context");
  68. function checkVersion() {
  69. const dispatch = this[ctxSymbol];
  70. if (!sysmsg.maps.get(dispatch.base.protocolVersion) || sysmsg.maps.get(dispatch.base.protocolVersion).name.size === 0) {
  71. console.error("ERROR: Your version of tera-proxy is too old to run Skill Prediction");
  72. process.exit(1);
  73. }
  74. }
  75.  
  76. function SkillPredictionCore(dispatch) {
  77. if (errorState) {
  78. console.error(`[${currentDir}] Start cancelled!`);
  79. process.exit(1);
  80. }
  81.  
  82. dispatch.hookOnce("C_CHECK_VERSION", 1, checkVersion)[ctxSymbol] = dispatch;
  83.  
  84. for (let i = 0; i < childModulesLength; ++i) {
  85. childModules[i](dispatch);
  86. }
  87. }
  88.  
  89. module.exports = SkillPredictionCore;
Add Comment
Please, Sign In to add comment