mm_os 4.3.7 → 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 (232) 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 -84
  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 -704
  46. package/com/mqtt/index.js +0 -1052
  47. package/com/mqtt/index.test.js +0 -503
  48. package/com/mqtt/script.tpl.js +0 -719
  49. package/com/nav/README.md +0 -2
  50. package/com/nav/com.json +0 -5
  51. package/com/nav/config.tpl.json +0 -84
  52. package/com/nav/drive.js +0 -702
  53. package/com/nav/index.js +0 -228
  54. package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
  55. package/com/nav/tpl/admin_pc/page_config.vue +0 -280
  56. package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
  57. package/com/nav/tpl/admin_pc/page_default.vue +0 -247
  58. package/com/nav/tpl/admin_pc/page_form.vue +0 -180
  59. package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
  60. package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
  61. package/com/nav/tpl/admin_pc/page_table.vue +0 -296
  62. package/com/nav/tpl/admin_pc/page_type.vue +0 -321
  63. package/com/nav/tpl/admin_pc/page_view.vue +0 -124
  64. package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
  65. package/com/nav/tpl/dev_pc/page_config.vue +0 -253
  66. package/com/nav/tpl/dev_pc/page_default.vue +0 -247
  67. package/com/nav/tpl/dev_pc/page_form.vue +0 -162
  68. package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
  69. package/com/nav/tpl/dev_pc/page_table.vue +0 -247
  70. package/com/nav/tpl/dev_pc/page_type.vue +0 -313
  71. package/com/nav/tpl/home_pc/page_channel.vue +0 -234
  72. package/com/nav/tpl/home_pc/page_default.vue +0 -234
  73. package/com/nav/tpl/home_pc/page_form.vue +0 -137
  74. package/com/nav/tpl/home_pc/page_list.vue +0 -234
  75. package/com/nav/tpl/home_pc/page_nav.vue +0 -221
  76. package/com/nav/tpl/home_pc/page_type.vue +0 -234
  77. package/com/nav/tpl/home_pc/page_view.vue +0 -125
  78. package/com/nav/tpl/home_phone/page_channel.vue +0 -234
  79. package/com/nav/tpl/home_phone/page_default.vue +0 -234
  80. package/com/nav/tpl/home_phone/page_form.vue +0 -137
  81. package/com/nav/tpl/home_phone/page_list.vue +0 -234
  82. package/com/nav/tpl/home_phone/page_nav.vue +0 -237
  83. package/com/nav/tpl/home_phone/page_type.vue +0 -234
  84. package/com/nav/tpl/home_phone/page_view.vue +0 -125
  85. package/com/nav/viewmodel.js +0 -446
  86. package/com/param/README.md +0 -2
  87. package/com/param/com.json +0 -5
  88. package/com/param/config.tpl.json +0 -136
  89. package/com/param/drive.js +0 -502
  90. package/com/param/index.js +0 -158
  91. package/com/param/script.tpl.js +0 -12
  92. package/com/pendant/README.md +0 -3
  93. package/com/pendant/com.json +0 -5
  94. package/com/pendant/config.tpl.json +0 -32
  95. package/com/pendant/drive.js +0 -204
  96. package/com/pendant/index.js +0 -467
  97. package/com/pendant/pendant.html +0 -16
  98. package/com/pendant/script.tpl.js +0 -18
  99. package/com/socket/README.md +0 -47
  100. package/com/socket/com.json +0 -5
  101. package/com/socket/config.tpl.json +0 -12
  102. package/com/socket/drive.js +0 -679
  103. package/com/socket/index.js +0 -402
  104. package/com/socket/script.tpl.js +0 -41
  105. package/com/sql/README.md +0 -3
  106. package/com/sql/com.json +0 -5
  107. package/com/sql/config.tpl.json +0 -74
  108. package/com/sql/drive.js +0 -1328
  109. package/com/sql/index.js +0 -152
  110. package/com/sql/script.tpl.js +0 -47
  111. package/com/static/README.md +0 -2
  112. package/com/static/com.json +0 -5
  113. package/com/static/config.tpl.json +0 -24
  114. package/com/static/drive.js +0 -194
  115. package/com/static/index.js +0 -237
  116. package/com/static/script.tpl.js +0 -28
  117. package/com/task/README.md +0 -3
  118. package/com/task/com.json +0 -5
  119. package/com/task/config.tpl.json +0 -24
  120. package/com/task/drive.js +0 -428
  121. package/com/task/index.js +0 -159
  122. package/com/task/script.tpl.js +0 -40
  123. package/com/template/com.json +0 -5
  124. package/com/template/config.tpl.json +0 -16
  125. package/com/template/drive.js +0 -81
  126. package/com/template/index.js +0 -141
  127. package/com.js +0 -237
  128. package/common/README.md +0 -2
  129. package/common/middleware/web_after/index.js +0 -26
  130. package/common/middleware/web_after/middleware.json +0 -9
  131. package/common/middleware/web_base/index.js +0 -113
  132. package/common/middleware/web_base/middleware.json +0 -19
  133. package/common/middleware/web_before/index.js +0 -33
  134. package/common/middleware/web_before/middleware.json +0 -9
  135. package/common/middleware/web_cors/index.js +0 -87
  136. package/common/middleware/web_cors/middleware.json +0 -24
  137. package/common/middleware/web_error/index.js +0 -131
  138. package/common/middleware/web_error/middleware.json +0 -19
  139. package/common/middleware/web_ip/index.js +0 -15
  140. package/common/middleware/web_ip/middleware.json +0 -14
  141. package/common/middleware/web_logger/index.js +0 -156
  142. package/common/middleware/web_logger/middleware.json +0 -14
  143. package/common/middleware/web_main/index.js +0 -26
  144. package/common/middleware/web_main/middleware.json +0 -9
  145. package/common/middleware/web_static/index.js +0 -73
  146. package/common/middleware/web_static/middleware.json +0 -54
  147. package/common/middleware/web_waf/index.js +0 -395
  148. package/common/middleware/web_waf/middleware.json +0 -13
  149. package/core/app/config.tpl.json +0 -67
  150. package/core/app/index.js +0 -711
  151. package/core/app/script.tpl.js +0 -52
  152. package/core/channel/index.js +0 -899
  153. package/core/channel/matcher.js +0 -585
  154. package/core/com/config.tpl.json +0 -16
  155. package/core/com/index.js +0 -77
  156. package/core/com/script.tpl.js +0 -5
  157. package/core/component/component.js +0 -42
  158. package/core/component/config.tpl.json +0 -63
  159. package/core/component/index.js +0 -273
  160. package/core/component/script.tpl.js +0 -19
  161. package/core/controller/config.tpl.json +0 -14
  162. package/core/controller/index.js +0 -371
  163. package/core/controller/script.tpl.js +0 -27
  164. package/core/factory/config.tpl.json +0 -14
  165. package/core/factory/entity.js +0 -275
  166. package/core/factory/index.js +0 -241
  167. package/core/factory/script.tpl.js +0 -16
  168. package/core/game/bat/index.js +0 -137
  169. package/core/game/bat/world.js +0 -622
  170. package/core/game/config.tpl.json +0 -16
  171. package/core/game/entity_admin.js +0 -230
  172. package/core/game/index.js +0 -186
  173. package/core/handler/config.tpl.json +0 -22
  174. package/core/handler/index.js +0 -181
  175. package/core/handler/script.tpl.js +0 -23
  176. package/core/logic/config.tpl.json +0 -14
  177. package/core/logic/index.js +0 -59
  178. package/core/logic/script.tpl.js +0 -19
  179. package/core/middleware/config.tpl.json +0 -16
  180. package/core/middleware/index.js +0 -117
  181. package/core/middleware/script.tpl.js +0 -37
  182. package/core/mod/config.tpl.json +0 -22
  183. package/core/mod/index.js +0 -136
  184. package/core/mod/script.tpl.js +0 -34
  185. package/core/model/config.tpl.json +0 -219
  186. package/core/model/index.js +0 -272
  187. package/core/model/model.js +0 -27
  188. package/core/model/script.tpl.js +0 -20
  189. package/core/notifier/config.tpl.json +0 -14
  190. package/core/notifier/index.js +0 -77
  191. package/core/notifier/script.tpl.js +0 -20
  192. package/core/plugin/config.tpl.json +0 -36
  193. package/core/plugin/index.js +0 -267
  194. package/core/plugin/script.tpl.js +0 -51
  195. package/core/pusher/config.tpl.json +0 -14
  196. package/core/pusher/index.js +0 -158
  197. package/core/pusher/script.tpl.js +0 -20
  198. package/core/room/bat/index.js +0 -170
  199. package/core/room/bat/room.js +0 -524
  200. package/core/room/config.tpl.json +0 -20
  201. package/core/room/index.js +0 -249
  202. package/core/room/room.js +0 -61
  203. package/core/scene/config.tpl.json +0 -14
  204. package/core/scene/index.js +0 -467
  205. package/core/scene/loop.js +0 -1306
  206. package/core/scene/map.js +0 -28
  207. package/core/scene/script.tpl.js +0 -22
  208. package/core/sender/config.tpl.json +0 -14
  209. package/core/sender/index.js +0 -79
  210. package/core/sender/script.tpl.js +0 -20
  211. package/core/service/config.tpl.json +0 -14
  212. package/core/service/index.js +0 -100
  213. package/core/service/script.tpl.js +0 -25
  214. package/core/store/config.tpl.json +0 -26
  215. package/core/store/index.js +0 -1794
  216. package/core/store/script.tpl.js +0 -22
  217. package/core/system/config.tpl.json +0 -18
  218. package/core/system/index.js +0 -312
  219. package/core/system/script.tpl.js +0 -77
  220. package/core/view/config.tpl.json +0 -14
  221. package/core/view/index.js +0 -91
  222. package/core/view/script.tpl.js +0 -20
  223. package/core/zone/bat/index.js +0 -744
  224. package/core/zone/config.tpl.json +0 -54
  225. package/core/zone/index.js +0 -655
  226. package/core/zone/script.tpl.js +0 -10
  227. package/core/zone/zone_bat.js +0 -136
  228. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
  229. package/os.js +0 -53
  230. package/server.js +0 -602
  231. package/ulits/id_gen.js +0 -134
  232. package/ulits/word.js +0 -206
@@ -1,267 +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
- }
36
- }
37
-
38
- /**
39
- * 获取模板目录
40
- * @returns {string} 模板目录
41
- */
42
- Plugin.prototype.getTplDir = function () {
43
- return __dirname;
44
- };
45
-
46
- /**
47
- * 初始化核心
48
- * @param {object} app 应用实例
49
- * @param {object} eventer 事件管理器
50
- * @param {object} logger 日志管理器
51
- * @private
52
- */
53
- Plugin.prototype._initCore = async function (app, eventer, logger) {
54
- // 初始化依赖项
55
- if (logger) {
56
- this.setLogger(logger);
57
- }
58
- if (eventer) {
59
- this.getEventer = function () {
60
- return eventer;
61
- };
62
- }
63
- if (app) {
64
- this.getApp = function () {
65
- return app;
66
- };
67
- this._db = app.db;
68
- this._cache = app.cache;
69
- this._filer = app.filer;
70
- }
71
- // // 初始化管理
72
- // await this._initManager();
73
- // // 加载资源
74
- // await this._loadSources();
75
- // // 初始化资源
76
- // await this._initSources();
77
- this._preset();
78
- };
79
-
80
- /**
81
- * 获取应用实例
82
- * @returns {object} 应用实例
83
- */
84
- Plugin.prototype.getApp = function () {
85
- // 初始化资源
86
- return this.getParent();
87
- };
88
-
89
- /**
90
- * 转换数字类型值
91
- * @param {*} value 原始值
92
- * @returns {number} 转换后的值
93
- * @private
94
- */
95
- Plugin.prototype._convertNumber = function (value) {
96
- if (value === 'null') return 0;
97
- return Number(value || '0');
98
- };
99
-
100
- /**
101
- * 转换布尔类型值
102
- * @param {*} value 原始值
103
- * @returns {boolean} 转换后的值
104
- * @private
105
- */
106
- Plugin.prototype._convertBoolean = function (value) {
107
- if (!value) return false;
108
- if (typeof value === 'boolean') return value;
109
- if (typeof value === 'string') {
110
- return value === '1' || value === 'true';
111
- }
112
- return false;
113
- };
114
-
115
- /**
116
- * 转换对象类型值
117
- * @param {*} value 原始值
118
- * @returns {object} 转换后的值
119
- * @private
120
- */
121
- Plugin.prototype._convertObject = function (value) {
122
- if (value === 'null') return {};
123
- return value.toJSON ? value.toJSON() : {};
124
- };
125
-
126
- /**
127
- * 转换数组类型值
128
- * @param {*} value 原始值
129
- * @returns {Array} 转换后的值
130
- * @private
131
- */
132
- Plugin.prototype._convertArray = function (value) {
133
- if (value === 'null') return [];
134
- return value.toJSON ? value.toJSON() : [];
135
- };
136
-
137
- /**
138
- * 转换字符串类型值
139
- * @param {*} value 原始值
140
- * @returns {string} 转换后的值
141
- * @private
142
- */
143
- Plugin.prototype._convertString = function (value) {
144
- if (value === 'null') return null;
145
- return value || '';
146
- };
147
-
148
- /**
149
- * 转换单个配置项的值
150
- * @param {object} option 配置项
151
- * @returns {*} 转换后的值
152
- * @private
153
- */
154
- Plugin.prototype._convertOptionValue = function (option) {
155
- var val = option.value;
156
- if (val === 'null') return null;
157
-
158
- var type = option.type;
159
- switch (type) {
160
- case 'number':
161
- return this._convertNumber(val);
162
- case 'boolean':
163
- return this._convertBoolean(val);
164
- case 'object':
165
- return this._convertObject(val);
166
- case 'array':
167
- return this._convertArray(val);
168
- case 'string':
169
- return this._convertString(val);
170
- default:
171
- return val;
172
- }
173
- };
174
-
175
- /**
176
- * 设计配置
177
- * @param {object} body 配置参数
178
- */
179
- Plugin.prototype.designOptions = function (body) {
180
- var cg = this.config;
181
- if (Array.isArray(body)) {
182
- cg.options = body;
183
- } else {
184
- var options = cg.options || [];
185
- var option = options.getObj({
186
- name: body.name,
187
- });
188
- if (option) {
189
- Object.assign(option, body);
190
- } else {
191
- options.push(body);
192
- }
193
- cg.options = options;
194
- }
195
- };
196
-
197
- /**
198
- * 保存配置
199
- * 更新options字典并通过mm_machine的setOptionsToFile()持久化到缓存文件
200
- * @param {object} options 配置参数
201
- * @throws {TypeError} 参数类型错误时抛出
202
- */
203
- Plugin.prototype.saveOptions = function (options) {
204
- if (!options || typeof options !== 'object') {
205
- throw new TypeError('配置参数必须是对象');
206
- }
207
- if (!this._options) {
208
- this._options = {};
209
- }
210
- for (var key in options) {
211
- if (options.hasOwnProperty(key)) {
212
- this._options[key] = options[key];
213
- }
214
- }
215
- this.setOptionsToFile();
216
- };
217
-
218
- /**
219
- * 获取模型
220
- * @param {string} type 模型类型
221
- * @returns {object} 返回获取到的模型
222
- */
223
- Drive.prototype.getModel = function (type) {
224
- let model = { ...this.config };
225
- let dir = this.getDir();
226
- let l = $.slash;
227
- let app_name = dir.between('app' + l, l);
228
- let plugin_name = dir.between('plugin' + l, l);
229
- let name = dir.basename();
230
- model.app = app_name;
231
- model.plugin = plugin_name;
232
- model.name = model.name || name;
233
- model.path = '/' + app_name + '/' + name;
234
- return model;
235
- };
236
-
237
- /**
238
- * 安装插件
239
- * @private
240
- */
241
- Plugin.prototype._install = async function () {
242
- return this;
243
- };
244
-
245
- /**
246
- * 安装插件
247
- */
248
- Plugin.prototype.install = async function () {
249
- return this._install();
250
- };
251
-
252
- /**
253
- * 卸载插件
254
- * @private
255
- */
256
- Plugin.prototype._uninstall = async function () {
257
- return this;
258
- };
259
-
260
- /**
261
- * 卸载插件
262
- */
263
- Plugin.prototype.uninstall = async function () {
264
- return this._uninstall();
265
- };
266
-
267
- 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;