UNPKG

@ccms/api

Version:

MiaoScript api package

304 lines 12.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.server = void 0; var tslib_1 = require("tslib"); var reflect = require("@ccms/common/dist/reflect"); var container_1 = require("@ccms/container"); var constants_1 = require("./constants"); var server; (function (server) { /** * Runtime ServerType */ server.ServerType = Symbol("ServerType"); /** * Runtime Console */ server.Console = Symbol("Console"); /** * Runtime Server Instance */ server.ServerInstance = Symbol("ServerInstance"); var NativePluginManager = /** @class */ (function () { function NativePluginManager() { } NativePluginManager.prototype.list = function () { throw new Error("Method not implemented."); }; NativePluginManager.prototype.has = function (name) { return true; }; NativePluginManager.prototype.get = function (name) { throw new Error("Method not implemented."); }; NativePluginManager.prototype.enable = function (name) { throw new Error("Method not implemented."); }; NativePluginManager.prototype.disable = function (name) { throw new Error("Method not implemented."); }; NativePluginManager.prototype.reload = function (name) { throw new Error("Method not implemented."); }; NativePluginManager.prototype.delete = function (name) { throw new Error("Method not implemented."); }; NativePluginManager = tslib_1.__decorate([ (0, container_1.injectable)() ], NativePluginManager); return NativePluginManager; }()); server.NativePluginManager = NativePluginManager; /** * MiaoScript Server */ var Server = /** @class */ (function () { function Server() { } Server.prototype.getVersion = function () { throw new Error("Method not implemented."); }; Server.prototype.getPlayer = function (name) { throw new Error("Method not implemented."); }; Server.prototype.getOnlinePlayers = function () { throw new Error("Method not implemented."); }; Server.prototype.getConsoleSender = function () { throw new Error("Method not implemented."); }; Server.prototype.getService = function (service) { throw new Error("Method not implemented."); }; Server.prototype.broadcast = function (message, permission) { throw new Error("Method not implemented."); }; Server.prototype.broadcastMessage = function (message) { throw new Error("Method not implemented."); }; Server.prototype.dispatchCommand = function (sender, command) { throw new Error("Method not implemented."); }; Server.prototype.dispatchConsoleCommand = function (command) { throw new Error("Method not implemented."); }; Server.prototype.getPluginsFolder = function () { throw new Error("Method not implemented."); }; Server.prototype.getDedicatedServer = function () { throw new Error("Method not implemented."); }; Server.prototype.getNettyPipeline = function () { throw new Error("Method not implemented."); }; Server.prototype.getRootLogger = function () { throw new Error("Method not implemented."); }; Server = tslib_1.__decorate([ (0, container_1.injectable)() ], Server); return Server; }()); server.Server = Server; var ServerChecker = /** @class */ (function () { function ServerChecker() { } ServerChecker.prototype.check = function (servers) { // Not set servers -> allow if (!servers || !servers.length) return true; // include !type -> deny var denyServers = servers.filter(function (svr) { return svr.startsWith("!"); }); if (denyServers.length !== 0) { return !denyServers.includes("!".concat(this.serverType)); } else { // only include -> allow return servers.includes(this.serverType); } }; tslib_1.__decorate([ (0, container_1.Autowired)(server.ServerType), tslib_1.__metadata("design:type", String) ], ServerChecker.prototype, "serverType", void 0); ServerChecker = tslib_1.__decorate([ (0, container_1.injectable)() ], ServerChecker); return ServerChecker; }()); server.ServerChecker = ServerChecker; var NativePluginChecker = /** @class */ (function () { function NativePluginChecker() { } NativePluginChecker.prototype.check = function (plugins) { var e_1, _a; // Not set plugins -> allow if (!plugins || !plugins.length) return true; try { for (var plugins_1 = tslib_1.__values(plugins), plugins_1_1 = plugins_1.next(); !plugins_1_1.done; plugins_1_1 = plugins_1.next()) { var plugin = plugins_1_1.value; if (!this.nativePluginManager.has(plugin)) { return false; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (plugins_1_1 && !plugins_1_1.done && (_a = plugins_1.return)) _a.call(plugins_1); } finally { if (e_1) throw e_1.error; } } return true; }; tslib_1.__decorate([ (0, container_1.Autowired)(NativePluginManager), tslib_1.__metadata("design:type", NativePluginManager) ], NativePluginChecker.prototype, "nativePluginManager", void 0); NativePluginChecker = tslib_1.__decorate([ (0, container_1.injectable)() ], NativePluginChecker); return NativePluginChecker; }()); server.NativePluginChecker = NativePluginChecker; var ReflectServer = /** @class */ (function (_super) { tslib_1.__extends(ReflectServer, _super); function ReflectServer() { return _super.call(this) || this; } ReflectServer.prototype.reflect = function () { try { var consoleServer = this.getDedicatedServer(); this.reflectPipeline(consoleServer); this.reflectRootLogger(consoleServer); } catch (error) { console.error('Error When Reflect MinecraftServer!', error); console.ex(error); } }; ReflectServer.prototype.reflectPipeline = function (consoleServer) { var e_2, _a, e_3, _b; var connection; var promise; try { for (var _c = tslib_1.__values(constants_1.constants.Reflect.Method.getServerConnection), _d = _c.next(); !_d.done; _d = _c.next()) { var method = _d.value; try { connection = reflect.on(consoleServer).call(method).get(); if (connection.class.name.indexOf('ServerConnection') !== -1 || connection.class.name.indexOf('NetworkSystem') !== -1) { break; } connection = undefined; } catch (error) { if (global.debug) { console.ex(error); } } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_d && !_d.done && (_a = _c.return)) _a.call(_c); } finally { if (e_2) throw e_2.error; } } if (!connection) { console.error("Can't found ServerConnection!"); return; } try { for (var _e = tslib_1.__values(constants_1.constants.Reflect.Field.listeningChannels), _f = _e.next(); !_f.done; _f = _e.next()) { var field = _f.value; try { promise = reflect.on(connection).get(field).get().get(0); if (promise.class.name.indexOf('Promise') !== -1) { break; } promise = undefined; } catch (error) { if (global.debug) { console.ex(error); } } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_f && !_f.done && (_b = _e.return)) _b.call(_e); } finally { if (e_3) throw e_3.error; } } if (!promise) { console.error("Can't found listeningChannels!"); return; } this.pipeline = reflect.on(promise).get('channel').get().pipeline(); this.container.bind(constants_1.constants.ServiceIdentifier.NettyPipeline).toConstantValue(this.pipeline); }; ReflectServer.prototype.reflectRootLogger = function (consoleServer) { try { this.rootLogger = reflect.on(consoleServer).get('LOGGER').get(); } catch (error) { if (global.debug) { console.ex(error); } try { this.rootLogger = reflect.on(consoleServer).get(0).get(); } catch (error) { if (global.debug) { console.ex(error); } } } if (this.rootLogger.class.name.indexOf('slf4j') !== -1) { try { var LogManager = Java.type('org.apache.logging.log4j.LogManager'); this.rootLogger = LogManager.getLogger('ROOT'); } catch (error) { if (global.debug) { console.ex(error); } } } if (this.rootLogger && this.rootLogger.class.name.indexOf('Logger') === -1) { console.error('Error Logger Class: ' + this.rootLogger.class.name); this.rootLogger = undefined; } if (!this.rootLogger) { console.error("Can't found rootLogger!"); } // get root logger for (var index = 0; index < 5 && this.rootLogger.parent; index++) { this.rootLogger = this.rootLogger.parent; } this.container.bind(constants_1.constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger); }; tslib_1.__decorate([ (0, container_1.Autowired)(container_1.ContainerInstance), tslib_1.__metadata("design:type", container_1.Container) ], ReflectServer.prototype, "container", void 0); tslib_1.__decorate([ (0, container_1.postConstruct)(), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", []), tslib_1.__metadata("design:returntype", void 0) ], ReflectServer.prototype, "reflect", null); ReflectServer = tslib_1.__decorate([ (0, container_1.injectable)(), tslib_1.__metadata("design:paramtypes", []) ], ReflectServer); return ReflectServer; }(server.Server)); server.ReflectServer = ReflectServer; })(server = exports.server || (exports.server = {})); //# sourceMappingURL=server.js.map