mm_os 4.3.6 → 5.0.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.
Files changed (234) hide show
  1. package/README.md +101 -504
  2. package/index.js +26 -19
  3. package/lib/loader.js +787 -0
  4. package/lib/os.js +369 -0
  5. package/package.json +55 -80
  6. package/LICENSE +0 -21
  7. package/README_EN.md +0 -505
  8. package/adapter/adapter.js +0 -484
  9. package/adapter/custom_persistence.js +0 -661
  10. package/adapter/mqtt.js +0 -254
  11. package/adapter/socket.js +0 -244
  12. package/adapter/web.js +0 -92
  13. package/adapter/websocket.js +0 -43
  14. package/ai.js +0 -130
  15. package/com/api/README.md +0 -3
  16. package/com/api/com.json +0 -5
  17. package/com/api/config.tpl.json +0 -41
  18. package/com/api/drive.js +0 -732
  19. package/com/api/index.js +0 -201
  20. package/com/api/oauth.js +0 -200
  21. package/com/api/script.tpl.js +0 -32
  22. package/com/cmd/README.md +0 -11
  23. package/com/cmd/com.json +0 -5
  24. package/com/cmd/config.tpl.json +0 -48
  25. package/com/cmd/drive.js +0 -176
  26. package/com/cmd/index.js +0 -287
  27. package/com/cmd/job/config.json +0 -66
  28. package/com/cmd/job/index.js +0 -241
  29. package/com/cmd/job/test.js +0 -188
  30. package/com/cmd/msg.json +0 -48
  31. package/com/cmd/script.tpl.js +0 -12
  32. package/com/db/README.md +0 -3
  33. package/com/db/com.json +0 -5
  34. package/com/db/drive.js +0 -2206
  35. package/com/db/index.js +0 -241
  36. package/com/event/README.md +0 -4
  37. package/com/event/com.json +0 -5
  38. package/com/event/config.tpl.json +0 -20
  39. package/com/event/drive.js +0 -61
  40. package/com/event/index.js +0 -438
  41. package/com/event/script.tpl.js +0 -23
  42. package/com/mqtt/README.md +0 -47
  43. package/com/mqtt/com.json +0 -5
  44. package/com/mqtt/config.tpl.json +0 -42
  45. package/com/mqtt/drive.js +0 -696
  46. package/com/mqtt/index.js +0 -1017
  47. package/com/mqtt/index.test.js +0 -503
  48. package/com/mqtt/mm_mqtt.js +0 -446
  49. package/com/mqtt/script.tpl.js +0 -719
  50. package/com/nav/README.md +0 -2
  51. package/com/nav/com.json +0 -5
  52. package/com/nav/config.tpl.json +0 -84
  53. package/com/nav/drive.js +0 -702
  54. package/com/nav/index.js +0 -228
  55. package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
  56. package/com/nav/tpl/admin_pc/page_config.vue +0 -280
  57. package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
  58. package/com/nav/tpl/admin_pc/page_default.vue +0 -247
  59. package/com/nav/tpl/admin_pc/page_form.vue +0 -180
  60. package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
  61. package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
  62. package/com/nav/tpl/admin_pc/page_table.vue +0 -296
  63. package/com/nav/tpl/admin_pc/page_type.vue +0 -321
  64. package/com/nav/tpl/admin_pc/page_view.vue +0 -124
  65. package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
  66. package/com/nav/tpl/dev_pc/page_config.vue +0 -253
  67. package/com/nav/tpl/dev_pc/page_default.vue +0 -247
  68. package/com/nav/tpl/dev_pc/page_form.vue +0 -162
  69. package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
  70. package/com/nav/tpl/dev_pc/page_table.vue +0 -247
  71. package/com/nav/tpl/dev_pc/page_type.vue +0 -313
  72. package/com/nav/tpl/home_pc/page_channel.vue +0 -234
  73. package/com/nav/tpl/home_pc/page_default.vue +0 -234
  74. package/com/nav/tpl/home_pc/page_form.vue +0 -137
  75. package/com/nav/tpl/home_pc/page_list.vue +0 -234
  76. package/com/nav/tpl/home_pc/page_nav.vue +0 -221
  77. package/com/nav/tpl/home_pc/page_type.vue +0 -234
  78. package/com/nav/tpl/home_pc/page_view.vue +0 -125
  79. package/com/nav/tpl/home_phone/page_channel.vue +0 -234
  80. package/com/nav/tpl/home_phone/page_default.vue +0 -234
  81. package/com/nav/tpl/home_phone/page_form.vue +0 -137
  82. package/com/nav/tpl/home_phone/page_list.vue +0 -234
  83. package/com/nav/tpl/home_phone/page_nav.vue +0 -237
  84. package/com/nav/tpl/home_phone/page_type.vue +0 -234
  85. package/com/nav/tpl/home_phone/page_view.vue +0 -125
  86. package/com/nav/viewmodel.js +0 -446
  87. package/com/param/README.md +0 -2
  88. package/com/param/com.json +0 -5
  89. package/com/param/config.tpl.json +0 -136
  90. package/com/param/drive.js +0 -502
  91. package/com/param/index.js +0 -158
  92. package/com/param/script.tpl.js +0 -12
  93. package/com/pendant/README.md +0 -3
  94. package/com/pendant/com.json +0 -5
  95. package/com/pendant/config.tpl.json +0 -32
  96. package/com/pendant/drive.js +0 -204
  97. package/com/pendant/index.js +0 -467
  98. package/com/pendant/pendant.html +0 -16
  99. package/com/pendant/script.tpl.js +0 -18
  100. package/com/socket/README.md +0 -47
  101. package/com/socket/com.json +0 -5
  102. package/com/socket/config.tpl.json +0 -12
  103. package/com/socket/drive.js +0 -679
  104. package/com/socket/index.js +0 -402
  105. package/com/socket/script.tpl.js +0 -41
  106. package/com/sql/README.md +0 -3
  107. package/com/sql/com.json +0 -5
  108. package/com/sql/config.tpl.json +0 -74
  109. package/com/sql/drive.js +0 -1283
  110. package/com/sql/index.js +0 -152
  111. package/com/sql/script.tpl.js +0 -47
  112. package/com/static/README.md +0 -2
  113. package/com/static/com.json +0 -5
  114. package/com/static/config.tpl.json +0 -24
  115. package/com/static/drive.js +0 -194
  116. package/com/static/index.js +0 -237
  117. package/com/static/script.tpl.js +0 -28
  118. package/com/task/README.md +0 -3
  119. package/com/task/com.json +0 -5
  120. package/com/task/config.tpl.json +0 -24
  121. package/com/task/drive.js +0 -428
  122. package/com/task/index.js +0 -159
  123. package/com/task/script.tpl.js +0 -40
  124. package/com/template/com.json +0 -5
  125. package/com/template/config.tpl.json +0 -16
  126. package/com/template/drive.js +0 -81
  127. package/com/template/index.js +0 -141
  128. package/com.js +0 -237
  129. package/common/README.md +0 -2
  130. package/common/middleware/web_after/index.js +0 -26
  131. package/common/middleware/web_after/middleware.json +0 -9
  132. package/common/middleware/web_base/index.js +0 -113
  133. package/common/middleware/web_base/middleware.json +0 -19
  134. package/common/middleware/web_before/index.js +0 -33
  135. package/common/middleware/web_before/middleware.json +0 -9
  136. package/common/middleware/web_cors/index.js +0 -87
  137. package/common/middleware/web_cors/middleware.json +0 -24
  138. package/common/middleware/web_error/index.js +0 -131
  139. package/common/middleware/web_error/middleware.json +0 -19
  140. package/common/middleware/web_ip/index.js +0 -15
  141. package/common/middleware/web_ip/middleware.json +0 -14
  142. package/common/middleware/web_logger/index.js +0 -156
  143. package/common/middleware/web_logger/middleware.json +0 -14
  144. package/common/middleware/web_main/index.js +0 -26
  145. package/common/middleware/web_main/middleware.json +0 -9
  146. package/common/middleware/web_static/index.js +0 -73
  147. package/common/middleware/web_static/middleware.json +0 -54
  148. package/common/middleware/web_waf/index.js +0 -385
  149. package/common/middleware/web_waf/middleware.json +0 -13
  150. package/core/app/config.tpl.json +0 -67
  151. package/core/app/index.js +0 -710
  152. package/core/app/script.tpl.js +0 -52
  153. package/core/channel/index.js +0 -899
  154. package/core/channel/matcher.js +0 -585
  155. package/core/com/config.tpl.json +0 -16
  156. package/core/com/index.js +0 -77
  157. package/core/com/script.tpl.js +0 -5
  158. package/core/component/component.js +0 -42
  159. package/core/component/config.tpl.json +0 -63
  160. package/core/component/index.js +0 -273
  161. package/core/component/script.tpl.js +0 -19
  162. package/core/controller/config.tpl.json +0 -14
  163. package/core/controller/index.js +0 -371
  164. package/core/controller/script.tpl.js +0 -27
  165. package/core/factory/config.tpl.json +0 -14
  166. package/core/factory/entity.js +0 -275
  167. package/core/factory/index.js +0 -241
  168. package/core/factory/script.tpl.js +0 -16
  169. package/core/game/bat/index.js +0 -137
  170. package/core/game/bat/world.js +0 -622
  171. package/core/game/config.tpl.json +0 -16
  172. package/core/game/entity_admin.js +0 -230
  173. package/core/game/index.js +0 -186
  174. package/core/handler/config.tpl.json +0 -22
  175. package/core/handler/index.js +0 -181
  176. package/core/handler/script.tpl.js +0 -23
  177. package/core/logic/config.tpl.json +0 -14
  178. package/core/logic/index.js +0 -59
  179. package/core/logic/script.tpl.js +0 -19
  180. package/core/middleware/config.tpl.json +0 -16
  181. package/core/middleware/index.js +0 -117
  182. package/core/middleware/script.tpl.js +0 -37
  183. package/core/mod/config.tpl.json +0 -22
  184. package/core/mod/index.js +0 -136
  185. package/core/mod/script.tpl.js +0 -34
  186. package/core/model/config.tpl.json +0 -219
  187. package/core/model/index.js +0 -272
  188. package/core/model/model.js +0 -27
  189. package/core/model/script.tpl.js +0 -20
  190. package/core/notifier/config.tpl.json +0 -14
  191. package/core/notifier/index.js +0 -77
  192. package/core/notifier/script.tpl.js +0 -20
  193. package/core/plugin/config.tpl.json +0 -36
  194. package/core/plugin/index.js +0 -297
  195. package/core/plugin/script.tpl.js +0 -51
  196. package/core/pusher/config.tpl.json +0 -14
  197. package/core/pusher/index.js +0 -158
  198. package/core/pusher/script.tpl.js +0 -20
  199. package/core/room/bat/index.js +0 -170
  200. package/core/room/bat/room.js +0 -524
  201. package/core/room/config.tpl.json +0 -20
  202. package/core/room/index.js +0 -249
  203. package/core/room/room.js +0 -61
  204. package/core/scene/config.tpl.json +0 -14
  205. package/core/scene/index.js +0 -467
  206. package/core/scene/loop.js +0 -1306
  207. package/core/scene/map.js +0 -28
  208. package/core/scene/script.tpl.js +0 -22
  209. package/core/sender/config.tpl.json +0 -14
  210. package/core/sender/index.js +0 -79
  211. package/core/sender/script.tpl.js +0 -20
  212. package/core/service/config.tpl.json +0 -14
  213. package/core/service/index.js +0 -100
  214. package/core/service/script.tpl.js +0 -25
  215. package/core/store/config.tpl.json +0 -26
  216. package/core/store/index.js +0 -1794
  217. package/core/store/script.tpl.js +0 -22
  218. package/core/store/sql.js +0 -1488
  219. package/core/system/config.tpl.json +0 -18
  220. package/core/system/index.js +0 -312
  221. package/core/system/script.tpl.js +0 -77
  222. package/core/view/config.tpl.json +0 -14
  223. package/core/view/index.js +0 -91
  224. package/core/view/script.tpl.js +0 -20
  225. package/core/zone/bat/index.js +0 -744
  226. package/core/zone/config.tpl.json +0 -54
  227. package/core/zone/index.js +0 -655
  228. package/core/zone/script.tpl.js +0 -10
  229. package/core/zone/zone_bat.js +0 -136
  230. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
  231. package/os.js +0 -53
  232. package/server.js +0 -595
  233. package/ulits/id_gen.js +0 -134
  234. package/ulits/word.js +0 -206
@@ -1,297 +0,0 @@
1
- const { Drive } = require('mm_machine');
2
-
3
- /**
4
- * 插件基类
5
- * 负责管理插件的生命周期、资源加载和依赖管理
6
- */
7
- class Plugin extends Drive {
8
- static config = {
9
- // 插件名称
10
- name: '',
11
- // 插件标题
12
- title: '插件',
13
- // 插件描述
14
- description: '介绍插件的作用',
15
- // 插件版本
16
- version: '1.0.0',
17
- // 用于什么应用
18
- app: 'tool',
19
- // 作者
20
- author: 'qww',
21
- // 主文件
22
- main: './index.js',
23
- // git仓库地址
24
- git: '',
25
- // 依赖的npm模块
26
- dependencies: [],
27
- };
28
- /**
29
- * 构造函数
30
- * @param {object} config 配置参数
31
- * @param {object} parent 父对象
32
- */
33
- constructor(config, parent) {
34
- super({ ...Plugin.config, ...(config || {}) }, parent);
35
- this.options = {};
36
- }
37
- }
38
-
39
- /**
40
- * 获取模板目录
41
- * @returns {string} 模板目录
42
- */
43
- Plugin.prototype.getTplDir = function () {
44
- return __dirname;
45
- };
46
-
47
- /**
48
- * 初始化核心
49
- * @param {object} app 应用实例
50
- * @param {object} eventer 事件管理器
51
- * @param {object} logger 日志管理器
52
- * @private
53
- */
54
- Plugin.prototype._initCore = async function (app, eventer, logger) {
55
- // 初始化依赖项
56
- if (logger) {
57
- this.setLogger(logger);
58
- }
59
- if (eventer) {
60
- this.getEventer = function () {
61
- return eventer;
62
- };
63
- }
64
- if (app) {
65
- this.getApp = function () {
66
- return app;
67
- };
68
- this._db = app.db;
69
- this._cache = app.cache;
70
- this._filer = app.filer;
71
- }
72
- // // 初始化管理
73
- // await this._initManager();
74
- // // 加载资源
75
- // await this._loadSources();
76
- // // 初始化资源
77
- // await this._initSources();
78
- // 初始化配置
79
- this._initOptions();
80
- };
81
-
82
- /**
83
- * 获取应用实例
84
- * @returns {object} 应用实例
85
- */
86
- Plugin.prototype.getApp = function () {
87
- // 初始化资源
88
- return this.getParent();
89
- };
90
-
91
- /**
92
- * 获取插件配置
93
- * @returns {object} 插件配置
94
- */
95
- Plugin.prototype.getOptions = function () {
96
- return this.options;
97
- };
98
-
99
- /**
100
- * 初始化插件选项
101
- * 从config.options中提取默认值,mm_machine的save/load机制负责持久化
102
- */
103
- Plugin.prototype._initOptions = function () {
104
- this.options = this.getConfigOptions();
105
- };
106
-
107
- /**
108
- * 转换数字类型值
109
- * @param {*} value 原始值
110
- * @returns {number} 转换后的值
111
- * @private
112
- */
113
- Plugin.prototype._convertNumber = function (value) {
114
- if (value === 'null') return 0;
115
- return Number(value || '0');
116
- };
117
-
118
- /**
119
- * 转换布尔类型值
120
- * @param {*} value 原始值
121
- * @returns {boolean} 转换后的值
122
- * @private
123
- */
124
- Plugin.prototype._convertBoolean = function (value) {
125
- if (!value) return false;
126
- if (typeof value === 'boolean') return value;
127
- if (typeof value === 'string') {
128
- return value === '1' || value === 'true';
129
- }
130
- return false;
131
- };
132
-
133
- /**
134
- * 转换对象类型值
135
- * @param {*} value 原始值
136
- * @returns {object} 转换后的值
137
- * @private
138
- */
139
- Plugin.prototype._convertObject = function (value) {
140
- if (value === 'null') return {};
141
- return value.toJSON ? value.toJSON() : {};
142
- };
143
-
144
- /**
145
- * 转换数组类型值
146
- * @param {*} value 原始值
147
- * @returns {Array} 转换后的值
148
- * @private
149
- */
150
- Plugin.prototype._convertArray = function (value) {
151
- if (value === 'null') return [];
152
- return value.toJSON ? value.toJSON() : [];
153
- };
154
-
155
- /**
156
- * 转换字符串类型值
157
- * @param {*} value 原始值
158
- * @returns {string} 转换后的值
159
- * @private
160
- */
161
- Plugin.prototype._convertString = function (value) {
162
- if (value === 'null') return null;
163
- return value || '';
164
- };
165
-
166
- /**
167
- * 转换单个配置项的值
168
- * @param {object} option 配置项
169
- * @returns {*} 转换后的值
170
- * @private
171
- */
172
- Plugin.prototype._convertOptionValue = function (option) {
173
- var val = option.value;
174
- if (val === 'null') return null;
175
-
176
- var type = option.type;
177
- switch (type) {
178
- case 'number':
179
- return this._convertNumber(val);
180
- case 'boolean':
181
- return this._convertBoolean(val);
182
- case 'object':
183
- return this._convertObject(val);
184
- case 'array':
185
- return this._convertArray(val);
186
- case 'string':
187
- return this._convertString(val);
188
- default:
189
- return val;
190
- }
191
- };
192
-
193
- /**
194
- * 获取配置参数
195
- * @returns {object} 返回配置参数
196
- */
197
- Plugin.prototype.getConfigOptions = function () {
198
- var op = this.config.options || [];
199
- var dict = {};
200
- for (var i = 0; i < op.length; i++) {
201
- var o = op[i];
202
- dict[o.name] = this._convertOptionValue(o);
203
- }
204
- return dict;
205
- };
206
-
207
- /**
208
- * 设计配置
209
- * @param {object} body 配置参数
210
- */
211
- Plugin.prototype.designOptions = function (body) {
212
- var cg = this.config;
213
- if (Array.isArray(body)) {
214
- cg.options = body;
215
- } else {
216
- var options = cg.options || [];
217
- var option = options.getObj({
218
- name: body.name,
219
- });
220
- if (option) {
221
- Object.assign(option, body);
222
- } else {
223
- options.push(body);
224
- }
225
- cg.options = options;
226
- }
227
- };
228
-
229
- /**
230
- * 保存配置
231
- * 更新options字典和config.options数组中的值,并通过mm_machine的save()持久化
232
- * @param {object} options 配置参数
233
- */
234
- Plugin.prototype.saveOptions = function (options) {
235
- this.options = options;
236
- var config_options = this.config.options;
237
- if (config_options) {
238
- for (var i = 0; i < config_options.length; i++) {
239
- var o = config_options[i];
240
- if (o.name in options) {
241
- o.value = options[o.name];
242
- }
243
- }
244
- }
245
- this.save();
246
- };
247
-
248
- /**
249
- * 获取模型
250
- * @param {string} type 模型类型
251
- * @returns {object} 返回获取到的模型
252
- */
253
- Drive.prototype.getModel = function (type) {
254
- let model = { ...this.config };
255
- let dir = this.getDir();
256
- let l = $.slash;
257
- let app_name = dir.between('app' + l, l);
258
- let plugin_name = dir.between('plugin' + l, l);
259
- let name = dir.basename();
260
- model.app = app_name;
261
- model.plugin = plugin_name;
262
- model.name = model.name || name;
263
- model.path = '/' + app_name + '/' + name;
264
- return model;
265
- };
266
-
267
- /**
268
- * 安装插件
269
- * @private
270
- */
271
- Plugin.prototype._install = async function () {
272
- return this;
273
- };
274
-
275
- /**
276
- * 安装插件
277
- */
278
- Plugin.prototype.install = async function () {
279
- return this._install();
280
- };
281
-
282
- /**
283
- * 卸载插件
284
- * @private
285
- */
286
- Plugin.prototype._uninstall = async function () {
287
- return this;
288
- };
289
-
290
- /**
291
- * 卸载插件
292
- */
293
- Plugin.prototype.uninstall = async function () {
294
- return this._uninstall();
295
- };
296
-
297
- exports.Plugin = Plugin;
@@ -1,51 +0,0 @@
1
- /**
2
- * 插件,用于拓展功能
3
- */
4
- module.exports = {
5
- /**
6
- * 安装
7
- */
8
- async _install() {
9
- this.log('info', `插件安装`);
10
- },
11
- /**
12
- * 卸载
13
- */
14
- async _uninstall() {
15
- this.log('info', `插件卸载`);
16
- },
17
- /**
18
- * 初始化
19
- * @param {object} app 应用实例
20
- */
21
- async _init(app) {
22
- // this.log('debug', `初始化!`);
23
- },
24
- /**
25
- * 启动
26
- */
27
- async _start() {
28
- // this.log('debug', `启动!`);
29
- },
30
- /**
31
- * 停止
32
- */
33
- async _stop() {
34
- this.log('debug', `停止!`);
35
- },
36
- /**
37
- * 销毁
38
- * @param {...any} args 参数列表
39
- */
40
- async _destroy(...args) {
41
- this.log('debug', `销毁!`, { args });
42
- },
43
- /**
44
- * 主要逻辑
45
- * @param {...any} args 参数列表
46
- */
47
- async main(...args) {
48
- // 主要代码写在这
49
- this.log('debug', `主要逻辑被调用`, { args });
50
- }
51
- };
@@ -1,14 +0,0 @@
1
- {
2
- // 名称
3
- "name": "${name}",
4
- // 标题
5
- "title": "${title || '推送'}",
6
- // 描述
7
- "description": "${description || '推送器'}",
8
- // 主文件
9
- "main": "${main || 'index.js'}",
10
- // 状态 0:禁用 1:启用
11
- "state": 1,
12
- // 排序,越小越靠前
13
- "sort": 100
14
- }
@@ -1,158 +0,0 @@
1
- const { Drive } = require("mm_machine");
2
-
3
- /**
4
- * 广播器
5
- * 进行websocket、socket、mqtt广播
6
- */
7
- class Pusher extends Drive {
8
- static config = {
9
- // 广播器名称
10
- name: "default",
11
- // 推送配置
12
- // 推送类型: websocket, mqtt、socket
13
- type: "websocket",
14
- // 推送策略: realtime(实时), batch(批量)
15
- strategy: "realtime",
16
- // 批量推送间隔(毫秒)
17
- batch_interval: 100,
18
- // 推送队列大小
19
- queue_size: 1000,
20
- // 最大重试次数
21
- max_retry: 3,
22
- // 重试间隔(毫秒)
23
- retry_interval: 500,
24
- // 是否启用压缩
25
- compression: false,
26
- };
27
- /**
28
- * 构造函数
29
- * @param {object} config 配置参数
30
- * @param {object} parent 父对象
31
- */
32
- constructor(config, parent) {
33
- super({ ...Pusher.config, ...(config || {}) }, parent);
34
- // 推送队列
35
- this._push_queue = [];
36
- // 推送计时器
37
- this._batch_timer = null;
38
- }
39
- }
40
-
41
- /**
42
- * 获取模板目录
43
- * @returns {string} 模板目录
44
- */
45
- Pusher.prototype.getTplDir = function () {
46
- return __dirname;
47
- };
48
-
49
- /**
50
- * 初始化核心
51
- * @param {object} adapter 适配器
52
- * @param {object} eventer 事件总线
53
- * @param {object} logger 日志管理器
54
- */
55
- Pusher.prototype._initCore = async function (adapter, eventer, logger) {
56
- // 初始化依赖项
57
- if (logger) {
58
- this.setLogger(logger);
59
- }
60
- if (eventer) {
61
- this.getEventer = function () {
62
- return eventer;
63
- };
64
- }
65
- if (adapter) {
66
- this.getAdapter = function () {
67
- return adapter[this.config.type];
68
- };
69
- }
70
-
71
- // 初始化批量推送计时器
72
- if (this.config.strategy === "batch") {
73
- this._startBatchTimer();
74
- }
75
-
76
- // 注册事件监听
77
- this._registerEvents();
78
- };
79
-
80
- /**
81
- * 注册事件监听
82
- * @private
83
- */
84
- Pusher.prototype._registerEvents = function () {
85
- var eventer = this.getEventer();
86
- this._ev_changed = (data) => {
87
- this.log("info", "entity_changed", data);
88
- };
89
- this._ev_created = (data) => {
90
- this.log("info", "entity_created", data);
91
- };
92
- this._ev_deleted = (data) => {
93
- this.log("info", "entity_deleted", data);
94
- };
95
- eventer.on("entity_changed", this._ev_changed);
96
- eventer.on("entity_created", this._ev_created);
97
- eventer.on("entity_deleted", this._ev_deleted);
98
- };
99
-
100
- /**
101
- * 广播消息给所有连接的客户端
102
- * @param {string} method 方法名
103
- * @param {object} params 参数
104
- */
105
- Pusher.prototype.broadcast = function (method, params) {};
106
-
107
- /**
108
- * 启动
109
- */
110
- Pusher.prototype._start = async function () {
111
- this.log("info", "启动");
112
-
113
- // 启动批量推送计时器
114
- if (this.config.strategy === "batch") {
115
- this._startBatchTimer();
116
- }
117
- };
118
-
119
- /**
120
- * 停止
121
- */
122
- Pusher.prototype._stop = async function () {
123
- // 停止批量推送计时器
124
- if (this._batch_timer) {
125
- clearInterval(this._batch_timer);
126
- this._batch_timer = null;
127
- }
128
-
129
- // 清空推送队列
130
- this._push_queue = [];
131
-
132
- this.log("info", "stopped");
133
- };
134
-
135
- /**
136
- * 销毁
137
- */
138
- Pusher.prototype._destroy = function () {
139
- try {
140
- // 停止批量推送计时器
141
- if (this._batch_timer) {
142
- clearInterval(this._batch_timer);
143
- this._batch_timer = null;
144
- }
145
-
146
- // 清空存储引用
147
- this._push_queue = [];
148
-
149
- this.log("info", "destroyed");
150
-
151
- // 移除所有监听器
152
- this.removeAllListeners();
153
- } catch (error) {
154
- this.log("error", `销毁失败`, error);
155
- }
156
- };
157
-
158
- exports.Pusher = Pusher;
@@ -1,20 +0,0 @@
1
- /**
2
- * 广播器
3
- */
4
- module.exports = {
5
- /**
6
- * 初始化
7
- * @param {object} eventer 事件总线
8
- */
9
- async _init(eventer) {
10
- // this.log('debug', '初始化');
11
- },
12
- /**
13
- * 主要逻辑
14
- * @param {...any} args 参数列表
15
- */
16
- async main(...args) {
17
- // 主要代码写在这
18
- this.log('debug', 'pusher main 被调用', { args });
19
- }
20
- };
@@ -1,170 +0,0 @@
1
- const {
2
- Drive
3
- } = require('mm_machine');
4
-
5
- /**
6
- * 游戏房间
7
- */
8
- class Room extends Drive {
9
- static config = {
10
- // 房间名称
11
- 'name': '5v5',
12
- // 房间标题
13
- 'title': '',
14
- // 房间等级上限
15
- 'max_level': 1000,
16
- // 房间最大人数
17
- 'max_players': 5,
18
- // 游戏类型 rpg、card
19
- 'type': 'card',
20
- // 游戏类型 排位赛rank、娱乐局casual
21
- 'mode': 'rank',
22
- // 房间主程序
23
- 'main': ''
24
- };
25
-
26
- /**
27
- * 构造函数
28
- * @param {object} config 配置参数
29
- */
30
- constructor(config) {
31
- super({
32
- ...Room.config,
33
- ...config
34
- });
35
-
36
- // 房间列表
37
- this.list = new Map();
38
- }
39
- };
40
-
41
- /**
42
- * 获取模板目录
43
- * @returns {string} 模板目录
44
- */
45
- Room.prototype.getTplDir = function() {
46
- return __dirname;
47
- };
48
-
49
- /**
50
- * 初始化核心
51
- * @param {object} zone 游戏世界分区
52
- * @param {object} eventer 事件管理器
53
- * @param {object} logger 日志管理器
54
- */
55
- Room.prototype._initCore = async function (zone, eventer, logger) {
56
- if (!zone) {
57
- throw new TypeError('游戏世界分区不能为空');
58
- }
59
- // 游戏世界分区
60
- this.getZone = function () {
61
- return zone;
62
- };
63
- if (logger) {
64
- this.setLogger(logger);
65
- }
66
- if (eventer) {
67
- this.getEventer = function () {
68
- return eventer;
69
- };
70
- }
71
- };
72
-
73
- /**
74
- * 开始匹配
75
- */
76
- Room.prototype.startMatch = function () {
77
- // 检查所有玩家是否已准备
78
- if (!this.isAllPlayersReady()) {
79
- throw new Error('房间内玩家未全部准备');
80
- }
81
- // 检查房间是否已开始匹配
82
- if (this.state === 2) {
83
- throw new Error('房间已开始匹配');
84
- }
85
- // 检查房间是否已开始游戏
86
- else if (this.state === 3) {
87
- throw new Error('房间已开始游戏');
88
- }
89
-
90
- this.state = 2;
91
- // 记录匹配开始时间
92
- this._match_time = Date.now();
93
-
94
- // 触发开始匹配事件
95
- this.emitEvent('room_start_match', {
96
- room_id: this.room_id,
97
- room_name: this.config.name,
98
- timestamp: this._match_time
99
- });
100
- };
101
-
102
- /**
103
- * 匹配玩家
104
- * 根据房间配置进行玩家匹配
105
- * @returns {object} 匹配结果
106
- */
107
- Room.prototype._matchPlayers = function () {
108
- var config = this.config;
109
- var format = config.format || '5v5';
110
- var mode = config.mode || 'rank';
111
- var player_ids = this.getAllPlayerIds();
112
- var player_count = player_ids.length;
113
-
114
- var ret = this._checkMatch(player_count, config.max_players || 6);
115
- if (!ret.valid) {
116
- return { success: false, reason: ret.reason };
117
- }
118
-
119
- var teams = this._splitTeams(player_ids, format);
120
- if (!teams) {
121
- return { success: false, reason: '玩家数量不符合比赛格式要求' };
122
- }
123
-
124
- return this._buildMatch(mode, format, teams, player_count);
125
- };
126
-
127
- /**
128
- * 检查匹配条件
129
- * @param {number} player_count 玩家数量
130
- * @param {number} max_players 最大玩家数
131
- * @returns {object} 检查结果
132
- */
133
- Room.prototype._checkMatch = function (player_count, max_players) {
134
- if (player_count === 0) {
135
- return { valid: false, reason: '房间内没有玩家' };
136
- }
137
- if (player_count > max_players) {
138
- return { valid: false, reason: '房间内玩家数量超过上限' };
139
- }
140
- return { valid: true };
141
- };
142
-
143
- /**
144
- * 构建匹配结果
145
- * @param {string} mode 游戏模式
146
- * @param {string} format 比赛格式
147
- * @param {object} teams 队伍配置
148
- * @param {number} player_count 玩家数量
149
- * @returns {object} 匹配结果
150
- */
151
- Room.prototype._buildMatch = function (mode, format, teams, player_count) {
152
- var ret = {
153
- success: true,
154
- room_id: this.room_id,
155
- mode: mode,
156
- format: format,
157
- teams: teams,
158
- player_count: player_count,
159
- timestamp: Date.now()
160
- };
161
-
162
- this.emitEvent('room_match_success', {
163
- room_id: this.room_id,
164
- ret: ret
165
- });
166
-
167
- return ret;
168
- };
169
-
170
- exports.Room = Room;