UNPKG

maniajs

Version:

ManiaPlanet (Dedicated) Server Controller.

177 lines (138 loc) 5.08 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /** * App Public Interface. Facade to the class instances. */ var _facade = require('./database/facade'); var _facade2 = _interopRequireDefault(_facade); var _facade3 = require('./server/facade'); var _facade4 = _interopRequireDefault(_facade3); var _facade5 = require('./plugin/facade'); var _facade6 = _interopRequireDefault(_facade5); var _facade7 = require('./game/facade'); var _facade8 = _interopRequireDefault(_facade7); var _facade9 = require('./util/facade'); var _facade10 = _interopRequireDefault(_facade9); var _facade11 = require('./ui/facade'); var _facade12 = _interopRequireDefault(_facade11); var _package = require('./../package.json'); var _package2 = _interopRequireDefault(_package); var _configuration = require('./util/configuration'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * App Interface Class. * * @class App * @type {App} * * @property {{}} config * @property {{}} log * @property {string} version * @property {ServerClient} server * @property {{}} models * @property {Players} players * @property {Maps} maps * @property {UtilFacade} util * @property {UIFacade} ui */ var App = function () { function App(log) { _classCallCheck(this, App); this.log = log; this.version = _package2.default.version; this.config = _configuration.config; this.config.plugins = _configuration.raw.plugins; // Map plugin into config. /** * INTERNAL FACADE * Facade classes of components. */ this.serverFacade = new _facade4.default(this); this.databaseFacade = new _facade2.default(this); this.pluginFacade = new _facade6.default(this); this.gameFacade = new _facade8.default(this); this.uiFacade = new _facade12.default(this); this.utilFacade = new _facade10.default(this); /** * PUBLIC INTERFACE VARIABLES * Will be used for providing plugins features. Keep stable please. */ this.server = null; this.plugins = {}; this.models = {}; this.players = this.gameFacade.players; this.maps = this.gameFacade.maps; this.util = this.utilFacade; this.ui = this.uiFacade; } /** * Prepare by loading core's facade and managers. * Prepare the plugins by loading the info. * * @returns {Promise} */ _createClass(App, [{ key: 'prepare', value: function prepare() { var _this = this; return this.serverFacade.init().then(function () { return _this.databaseFacade.init(); }).then(function () { return _this.uiFacade.init(); }).then(function () { return _this.pluginFacade.init(); }).then(function () { return _this.gameFacade.init(); }).catch(function (err) { _this.log.fatal(err); process.exit(1); }); } /** * Run the Controller. * @returns {Promise} */ }, { key: 'run', value: function run() { var _this2 = this; return this.serverFacade.run().then(function () { return _this2.databaseFacade.run(); }).then(function () { return _this2.gameFacade.run(); }).then(function () { return _this2.uiFacade.run(); }).then(function () { return _this2.pluginFacade.run(); }).then(function () { _this2.log.info('Controller Ready!'); _this2.server.send().chat('$o$f90Mania$z$o$f90JS$z$fff: Controller ready! $n(' + _this2.version + ')').exec(); }).catch(function (err) { _this2.log.error(err); }); } /** * Exit Handler. * @returns {Promise} */ }, { key: 'exit', value: function exit() { var _this3 = this; return new Promise(function (resolve, reject) { _this3.server.send().chat('$o$f90Mania$z$o$f90JS$z$fff: Controller shutting down!').exec(); _this3.pluginFacade.stop(); _this3.uiFacade.stop(); _this3.gameFacade.stop(); _this3.serverFacade.stop(); _this3.databaseFacade.stop(); _this3.utilFacade.stop(); }); } }]); return App; }(); exports.default = App;