Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- const { readdirSync, existsSync, renameSync } = require("fs");
- const { basename, resolve } = require("path");
- const sysmsg = require("tera-data-parser").sysmsg,
- migration = require("./lib/migration"),
- childModules = [
- require("./lib/core"),
- require("./lib/cooldowns")
- ],
- childModulesLength = childModules.length;
- const currentDir = basename(__dirname);
- const blockedModules = new Set(["cooldowns", "lockons", "lockons", "fastfire",
- "fast-fire", "fast-fire", "fast-block","skill-prediction", "pinkie-sp",
- "skill-prediction", "skill-prediction-exp", "fast-block", "skillprediction",
- "skill-prediction-experimental", "cooldowns", "sp-pinkie", "sp"]);
- let errorState = false;
- checkBlockedModulesAndCorrectNames: {
- const arr = readdirSync(resolve(__dirname, "../"));
- const len = arr.length;
- const masterRegex = /-master/gi;
- let i = 0, foundCommand = false;
- do {
- const origName = arr[i];
- if (origName === currentDir) { continue; }
- const name = origName.replace(masterRegex, "");
- if (name !== origName) {
- try { renameSync(origName, name); }
- catch(_) {
- console.error(`[${currentDir}] ERROR! Delete either ${origName} or ${name}, whichever is older. You shouldn't have more than one of them.`);
- process.exit(1);
- }
- }
- switch(name.charAt(0)) { case ".": case "_": continue; }
- if (blockedModules.has(name)) {
- console.error(`[${currentDir}] ERROR! Blocked module ${name} installed.`);
- errorState = true;
- break checkBlockedModulesAndCorrectNames;
- }
- if (!foundCommand) {
- switch(name) {
- case "command": case "command-master": foundCommand = true;
- }
- }
- } while(++i < len);
- if (!foundCommand) {
- console.error(`[${currentDir}] ERROR! Missing module "command". Close tera-proxy and install it.`);
- errorState = true;
- }
- }
- migrateOldConfig: {
- const migrationConfigPath = resolve(__dirname, "./migration/partial-config.json");
- const originalConfigPath = resolve(__dirname, "./config/config.json");
- if (existsSync(migrationConfigPath)) {
- const migrationHelper = new migration.ConfigMigrationHelper(migrationConfigPath, originalConfigPath);
- if (!migrationHelper.compareJsons()) {
- migrationHelper.applyMigration();
- }
- }
- }
- const ctxSymbol = Symbol("context");
- function checkVersion() {
- const dispatch = this[ctxSymbol];
- if (!sysmsg.maps.get(dispatch.base.protocolVersion) || sysmsg.maps.get(dispatch.base.protocolVersion).name.size === 0) {
- console.error("ERROR: Your version of tera-proxy is too old to run Skill Prediction");
- process.exit(1);
- }
- }
- function SkillPredictionCore(dispatch) {
- if (errorState) {
- console.error(`[${currentDir}] Start cancelled!`);
- process.exit(1);
- }
- dispatch.hookOnce("C_CHECK_VERSION", 1, checkVersion)[ctxSymbol] = dispatch;
- for (let i = 0; i < childModulesLength; ++i) {
- childModules[i](dispatch);
- }
- }
- module.exports = SkillPredictionCore;
Add Comment
Please, Sign In to add comment