mm_os 4.0.9 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/app/index.js CHANGED
@@ -37,11 +37,11 @@ class App extends Drive {
37
37
  'author': 'qww',
38
38
  'scope': 'server',
39
39
  'dir': '',
40
- // 游戏配置,非游戏模块不需要配置
41
- 'game': {
42
- // 游戏类型
43
- 'type': 'card_game'
44
- },
40
+ // // 游戏配置,非游戏模块不需要配置
41
+ // 'game': {
42
+ // // 游戏类型
43
+ // 'type': 'card_game'
44
+ // },
45
45
  'dependencies': [],
46
46
  // // 压缩目录
47
47
  // 'zip_dir': './static/file/zip',
@@ -142,7 +142,7 @@ App.prototype._preset = function () {
142
142
  * @returns {object} 管理器实例
143
143
  */
144
144
  App.prototype._createManager = function (name, title, cls) {
145
- let dir = this._getDir();
145
+ let dir = this.getDir();
146
146
  var manager = new Manager({
147
147
  name: name,
148
148
  title: title,
@@ -160,6 +160,7 @@ App.prototype._createManager = function (name, title, cls) {
160
160
  * @returns {Promise<void>} 初始化完成
161
161
  */
162
162
  App.prototype._initManager = async function () {
163
+ // console.time('[TIMING] App._initManager');
163
164
  // 管理器配置列表
164
165
  var mgr_configs = [
165
166
  { name: 'store', title: '仓储', Module: Store },
@@ -182,12 +183,13 @@ App.prototype._initManager = async function () {
182
183
  }
183
184
 
184
185
  // 并行执行所有管理器的初始化操作
185
- var init_promises = [];
186
+ var list = [];
186
187
  for (var j = 0; j < managers.length; j++) {
187
- init_promises.push(managers[j].do('init'));
188
+ list.push(managers[j].do('init'));
188
189
  }
189
190
 
190
- await Promise.all(init_promises);
191
+ await Promise.all(list);
192
+ // console.timeEnd('[TIMING] App._initManager');
191
193
  };
192
194
 
193
195
  /**
@@ -195,6 +197,7 @@ App.prototype._initManager = async function () {
195
197
  * @returns {Promise<void>} 加载完成
196
198
  */
197
199
  App.prototype._loadSources = async function () {
200
+ // console.time('[TIMING] App._loadSources');
198
201
  // 加载无需依赖关系,所以可以同时加载,内部并行执行
199
202
  let loadPromises = [
200
203
  this.manager.store.runAll('load'),
@@ -206,21 +209,23 @@ App.prototype._loadSources = async function () {
206
209
  this.manager.plugin.runAll('load')
207
210
  ];
208
211
  await Promise.all(loadPromises);
212
+ // console.timeEnd('[TIMING] App._loadSources');
209
213
  };
210
214
 
211
215
  /**
212
216
  * 初始化路由相关模块
213
217
  */
214
218
  App.prototype._initRouteMod = async function () {
215
- Promise.all([
219
+ await Promise.all([
216
220
  this.manager.store.runAll('init', this.sql, this.cache, this.getLogger()),
217
221
  this.manager.view.runAll('init', this.getLogger()),
218
222
  this.manager.model.runAll('init', this.getEventer(), this.getLogger())
219
223
  ]);
220
-
221
224
  await this.manager.service.runAll('init', this.model, this.getEventer(), this.getLogger());
222
- this.manager.controller.runAll('init', this.model, this.service, this.view, this.getEventer(), this.getLogger());
223
- this.manager.handler.runAll('init', this, this.getEventer(), this.getLogger());
225
+ await Promise.all([
226
+ this.manager.controller.runAll('init', this.model, this.service, this.view, this.getEventer(), this.getLogger()),
227
+ this.manager.handler.runAll('init', this, this.getEventer(), this.getLogger())
228
+ ]);
224
229
  };
225
230
 
226
231
  /**
@@ -228,10 +233,8 @@ App.prototype._initRouteMod = async function () {
228
233
  * @returns {Promise<void>} 初始化完成
229
234
  */
230
235
  App.prototype._initSources = async function () {
231
- // 验证依赖关系
232
- this._validateDep();
236
+ await this._initRouteMod();
233
237
  await this.manager.plugin.runWait('init', this, this.getEventer(), this.getLogger());
234
- this._initRouteMod();
235
238
  };
236
239
 
237
240
  /**
@@ -242,7 +245,7 @@ App.prototype._initSources = async function () {
242
245
  * @private
243
246
  */
244
247
  App.prototype._initCore = async function (server, eventer, logger) {
245
- if (logger) {
248
+ if (logger) {
246
249
  this.setLogger(logger);
247
250
  }
248
251
  if (eventer) {
@@ -261,8 +264,8 @@ App.prototype._initCore = async function (server, eventer, logger) {
261
264
  await this._initManager();
262
265
  // 加载资源
263
266
  await this._loadSources();
264
- // 初始化资源
265
- await this._initSources();
267
+ // 验证依赖关系
268
+ this._validateDep();
266
269
  };
267
270
 
268
271
  /**
@@ -315,6 +318,8 @@ App.prototype._startSources = async function () {
315
318
  * @private
316
319
  */
317
320
  App.prototype._startCore = async function () {
321
+ // 初始化资源
322
+ await this._initSources();
318
323
  // 启动资源
319
324
  await this._startSources();
320
325
  };
@@ -333,32 +338,6 @@ App.prototype._validateDep = function () {
333
338
  }
334
339
  };
335
340
 
336
- /**
337
- * 记录初始化结果
338
- * @param {Array} results 初始化结果数组
339
- * @private
340
- */
341
- App.prototype._logInitResults = function (results) {
342
- var success = 0;
343
- var error = 0;
344
- var error_modules = [];
345
-
346
- for (var result of results) {
347
- if (result.result && result.result.error_count > 0) {
348
- error += result.result.error_count;
349
- error_modules.push(result.name);
350
- } else {
351
- success++;
352
- }
353
- }
354
-
355
- if (error > 0) {
356
- this.log('warn', `资源初始化完成,成功: ${success}, 失败: ${error}, 失败模块: ${error_modules.join(', ')}`);
357
- } else {
358
- this.log('info', `所有资源初始化成功,共 ${success} 个模块`);
359
- }
360
- };
361
-
362
341
  /**
363
342
  * 压缩插件
364
343
  * @param {string} name 插件名称
@@ -102,15 +102,6 @@ Channel.prototype._initCore = async function (zone, eventer, logger) {
102
102
 
103
103
  await this._initManager();
104
104
  await this._loadSources();
105
- await this._initSources();
106
-
107
- await this._loadWorlds();
108
-
109
- await this._initRoomAdmin();
110
-
111
- await this._loadRooms();
112
-
113
- await this._initMatcher();
114
105
  };
115
106
 
116
107
  /**
@@ -160,7 +151,7 @@ Channel.prototype._initMatcher = async function () {
160
151
  * 初始化管理器
161
152
  */
162
153
  Channel.prototype._initManager = async function () {
163
- // var dir = this._getDir().dirname().dirname();
154
+ // var dir = this.getDir().dirname().dirname();
164
155
  // var game = new Manager({
165
156
  // name: 'game',
166
157
  // title: '游戏',
@@ -178,8 +169,8 @@ Channel.prototype._initManager = async function () {
178
169
  * 获取游戏管理器目录
179
170
  * @returns {string} 游戏管理器目录
180
171
  */
181
- Channel.prototype._getDir = function () {
182
- return this.getZone()._getDir();
172
+ Channel.prototype.getDir = function () {
173
+ return this.getZone().getDir();
183
174
  };
184
175
 
185
176
  /**
@@ -245,6 +236,16 @@ Channel.prototype._loadRooms = async function () {
245
236
  * 启动核心
246
237
  */
247
238
  Channel.prototype._startCore = async function () {
239
+ await this._initSources();
240
+
241
+ await this._loadWorlds();
242
+
243
+ await this._initRoomAdmin();
244
+
245
+ await this._loadRooms();
246
+
247
+ await this._initMatcher();
248
+
248
249
  await this.manager.game.runAll('start');
249
250
  await this.matcher.do('start');
250
251
  this._startMonitor();
package/core/com/index.js CHANGED
@@ -67,6 +67,9 @@ Com.prototype._initCore = async function(server, eventer, logger) {
67
67
  await this._initManager();
68
68
  // 加载资源
69
69
  await this._loadSources();
70
+ };
71
+
72
+ Com.prototype._startCore = async function () {
70
73
  // 初始化资源
71
74
  await this._initSources();
72
75
  };
@@ -98,7 +98,7 @@ GameWorld.prototype.getTplDir = function () {
98
98
  * 获取游戏管理器目录
99
99
  * @returns {string} 游戏管理器目录
100
100
  */
101
- GameWorld.prototype._getDir = function () {
101
+ GameWorld.prototype.getDir = function () {
102
102
  return this.getGame()._
103
103
  };
104
104
 
@@ -118,7 +118,7 @@ GameWorld.prototype.genId = function () {
118
118
  * @returns {object} 管理器实例
119
119
  */
120
120
  GameWorld.prototype._createManager = function (name, title, cls) {
121
- var dir = this._getDir();
121
+ var dir = this.getDir();
122
122
  var manager = new Manager({
123
123
  name,
124
124
  title,
@@ -85,8 +85,6 @@ Game.prototype._initCore = async function (server, eventer, logger) {
85
85
  await this._initManager();
86
86
  // 加载资源
87
87
  await this._loadSources();
88
- // 初始化资源
89
- await this._initSources();
90
88
  };
91
89
 
92
90
  /**
@@ -121,7 +119,7 @@ Game.prototype._initManager = async function () {
121
119
  * @returns {object} 管理器实例
122
120
  */
123
121
  Game.prototype._createManager = function (name, title, cls) {
124
- let dir = this._getDir();
122
+ let dir = this.getDir();
125
123
  var manager = new Manager({
126
124
  name: name,
127
125
  title: title,
@@ -164,6 +162,8 @@ Game.prototype._initSources = async function () {
164
162
  * 启动核心
165
163
  */
166
164
  Game.prototype._startCore = async function () {
165
+ // 初始化资源
166
+ await this._initSources();
167
167
  // 启动资源
168
168
  await this._startSources();
169
169
  };
package/core/mod/index.js CHANGED
@@ -75,6 +75,12 @@ Mod.prototype._initCore = async function (server, eventer, logger) {
75
75
  await this._initManager();
76
76
  // 加载资源
77
77
  await this._loadSources();
78
+ };
79
+
80
+ /**
81
+ * 启动核心
82
+ */
83
+ Mod.prototype._startCore = async function () {
78
84
  // 初始化资源
79
85
  await this._initSources();
80
86
  };
@@ -226,7 +226,7 @@ Plugin.prototype._getCacheOptionsFile = function () {
226
226
  */
227
227
  Drive.prototype.getModel = function (type) {
228
228
  let model = { ...this.config };
229
- let dir = this._getDir();
229
+ let dir = this.getDir();
230
230
  let l = $.slash;
231
231
  let app_name = dir.between('app' + l, l);
232
232
  let plugin_name = dir.between('plugin' + l, l);
@@ -214,15 +214,13 @@ Zone.prototype._initCore = async function (app, eventer, logger) {
214
214
  return app;
215
215
  };
216
216
  }
217
+ // // 初始化基础组件
218
+ // await this._initBase();
219
+ // // 初始化管理器
220
+ // await this._initManager();
221
+ // // 加载资源
222
+ // await this._loadSources();
217
223
  return this;
218
- // 初始化基础组件
219
- await this._initBase();
220
- // 初始化管理器
221
- await this._initManager();
222
- // 加载资源
223
- await this._loadSources();
224
- // 初始化资源
225
- await this._initSources();
226
224
  };
227
225
 
228
226
  /**
@@ -243,6 +241,9 @@ Zone.prototype._startSources = async function () {
243
241
  * @private
244
242
  */
245
243
  Zone.prototype._startCore = async function () {
244
+ // // 初始化资源
245
+ // await this._initSources();
246
+
246
247
  // 加载所有登录玩家
247
248
  await this._loadPlayers();
248
249
 
@@ -157,8 +157,6 @@ Zone.prototype._initCore = async function (server, eventer, logger) {
157
157
  await this._initManager();
158
158
  // 加载资源
159
159
  await this._loadSources();
160
- // 初始化资源
161
- await this._initSources();
162
160
  };
163
161
 
164
162
  /**
@@ -193,7 +191,7 @@ Zone.prototype._initBase = async function () {
193
191
  * @returns {object} 管理器实例
194
192
  */
195
193
  Zone.prototype._createManager = function (name, title, cls) {
196
- let dir = this._getDir();
194
+ let dir = this.getDir();
197
195
  var manager = new Manager({
198
196
  name: name,
199
197
  title: title,
@@ -282,6 +280,9 @@ App.prototype._startSources = async function () {
282
280
  * @private
283
281
  */
284
282
  Zone.prototype._startCore = async function () {
283
+ // 初始化资源
284
+ await this._initSources();
285
+
285
286
  // 加载所有登录玩家
286
287
  await this._loadPlayers();
287
288
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mm_os",
3
3
  "description": "MM_OS服务端架构,用于快速构建应用程序,支持网站建设、小程序后台、AI应用、物联网(IOT/AIOT)、游戏服务端等多种场景。",
4
- "version": "4.0.9",
4
+ "version": "4.1.0",
5
5
  "main": "index.js",
6
6
  "keywords": [
7
7
  "AI",
@@ -22,8 +22,8 @@
22
22
  "author": "qww",
23
23
  "license": "ISC",
24
24
  "scripts": {
25
- "dev": "cross-env NODE_ENV=development nodemon ./example/index.js",
26
- "test": "cross-env NODE_ENV=test node ./example/index.js"
25
+ "dev": "cross-env NODE_ENV=development nodemon ./example/demo.js",
26
+ "test": "cross-env NODE_ENV=test node ./example/demo.js"
27
27
  },
28
28
  "dependencies": {
29
29
  "aedes": "^1.0.2",
@@ -44,7 +44,7 @@
44
44
  "mm_https": "^1.6.6",
45
45
  "mm_ip": "^1.0.4",
46
46
  "mm_logs": "^1.6.9",
47
- "mm_machine": "^2.7.4",
47
+ "mm_machine": "^2.7.6",
48
48
  "mm_matchs": "^1.1.9",
49
49
  "mm_queue": "^1.0.3",
50
50
  "mm_session": "^1.5.8",
@@ -57,7 +57,7 @@
57
57
  "devDependencies": {
58
58
  "@types/jest": "^30.0.0",
59
59
  "eslint-formatter-table": "^7.32.1",
60
- "eslint-plugin-jsdoc": "^63.0.1",
60
+ "eslint-plugin-jsdoc": "^63.0.2",
61
61
  "jest": "^30.4.2",
62
62
  "mm_eslint": "^1.7.1"
63
63
  },