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.
- package/README.md +101 -504
- package/index.js +26 -19
- package/lib/loader.js +787 -0
- package/lib/os.js +369 -0
- package/package.json +55 -84
- package/LICENSE +0 -21
- package/README_EN.md +0 -505
- package/adapter/adapter.js +0 -484
- package/adapter/custom_persistence.js +0 -661
- package/adapter/mqtt.js +0 -254
- package/adapter/socket.js +0 -244
- package/adapter/web.js +0 -92
- package/adapter/websocket.js +0 -43
- package/ai.js +0 -130
- package/com/api/README.md +0 -3
- package/com/api/com.json +0 -5
- package/com/api/config.tpl.json +0 -41
- package/com/api/drive.js +0 -732
- package/com/api/index.js +0 -201
- package/com/api/oauth.js +0 -200
- package/com/api/script.tpl.js +0 -32
- package/com/cmd/README.md +0 -11
- package/com/cmd/com.json +0 -5
- package/com/cmd/config.tpl.json +0 -48
- package/com/cmd/drive.js +0 -176
- package/com/cmd/index.js +0 -287
- package/com/cmd/job/config.json +0 -66
- package/com/cmd/job/index.js +0 -241
- package/com/cmd/job/test.js +0 -188
- package/com/cmd/msg.json +0 -48
- package/com/cmd/script.tpl.js +0 -12
- package/com/db/README.md +0 -3
- package/com/db/com.json +0 -5
- package/com/db/drive.js +0 -2206
- package/com/db/index.js +0 -241
- package/com/event/README.md +0 -4
- package/com/event/com.json +0 -5
- package/com/event/config.tpl.json +0 -20
- package/com/event/drive.js +0 -61
- package/com/event/index.js +0 -438
- package/com/event/script.tpl.js +0 -23
- package/com/mqtt/README.md +0 -47
- package/com/mqtt/com.json +0 -5
- package/com/mqtt/config.tpl.json +0 -42
- package/com/mqtt/drive.js +0 -704
- package/com/mqtt/index.js +0 -1052
- package/com/mqtt/index.test.js +0 -503
- package/com/mqtt/script.tpl.js +0 -719
- package/com/nav/README.md +0 -2
- package/com/nav/com.json +0 -5
- package/com/nav/config.tpl.json +0 -84
- package/com/nav/drive.js +0 -702
- package/com/nav/index.js +0 -228
- package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
- package/com/nav/tpl/admin_pc/page_config.vue +0 -280
- package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
- package/com/nav/tpl/admin_pc/page_default.vue +0 -247
- package/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
- package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
- package/com/nav/tpl/admin_pc/page_table.vue +0 -296
- package/com/nav/tpl/admin_pc/page_type.vue +0 -321
- package/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
- package/com/nav/tpl/dev_pc/page_config.vue +0 -253
- package/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/com/nav/tpl/dev_pc/page_form.vue +0 -162
- package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
- package/com/nav/tpl/dev_pc/page_table.vue +0 -247
- package/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/com/nav/tpl/home_pc/page_channel.vue +0 -234
- package/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/com/nav/tpl/home_phone/page_list.vue +0 -234
- package/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/com/nav/viewmodel.js +0 -446
- package/com/param/README.md +0 -2
- package/com/param/com.json +0 -5
- package/com/param/config.tpl.json +0 -136
- package/com/param/drive.js +0 -502
- package/com/param/index.js +0 -158
- package/com/param/script.tpl.js +0 -12
- package/com/pendant/README.md +0 -3
- package/com/pendant/com.json +0 -5
- package/com/pendant/config.tpl.json +0 -32
- package/com/pendant/drive.js +0 -204
- package/com/pendant/index.js +0 -467
- package/com/pendant/pendant.html +0 -16
- package/com/pendant/script.tpl.js +0 -18
- package/com/socket/README.md +0 -47
- package/com/socket/com.json +0 -5
- package/com/socket/config.tpl.json +0 -12
- package/com/socket/drive.js +0 -679
- package/com/socket/index.js +0 -402
- package/com/socket/script.tpl.js +0 -41
- package/com/sql/README.md +0 -3
- package/com/sql/com.json +0 -5
- package/com/sql/config.tpl.json +0 -74
- package/com/sql/drive.js +0 -1328
- package/com/sql/index.js +0 -152
- package/com/sql/script.tpl.js +0 -47
- package/com/static/README.md +0 -2
- package/com/static/com.json +0 -5
- package/com/static/config.tpl.json +0 -24
- package/com/static/drive.js +0 -194
- package/com/static/index.js +0 -237
- package/com/static/script.tpl.js +0 -28
- package/com/task/README.md +0 -3
- package/com/task/com.json +0 -5
- package/com/task/config.tpl.json +0 -24
- package/com/task/drive.js +0 -428
- package/com/task/index.js +0 -159
- package/com/task/script.tpl.js +0 -40
- package/com/template/com.json +0 -5
- package/com/template/config.tpl.json +0 -16
- package/com/template/drive.js +0 -81
- package/com/template/index.js +0 -141
- package/com.js +0 -237
- package/common/README.md +0 -2
- package/common/middleware/web_after/index.js +0 -26
- package/common/middleware/web_after/middleware.json +0 -9
- package/common/middleware/web_base/index.js +0 -113
- package/common/middleware/web_base/middleware.json +0 -19
- package/common/middleware/web_before/index.js +0 -33
- package/common/middleware/web_before/middleware.json +0 -9
- package/common/middleware/web_cors/index.js +0 -87
- package/common/middleware/web_cors/middleware.json +0 -24
- package/common/middleware/web_error/index.js +0 -131
- package/common/middleware/web_error/middleware.json +0 -19
- package/common/middleware/web_ip/index.js +0 -15
- package/common/middleware/web_ip/middleware.json +0 -14
- package/common/middleware/web_logger/index.js +0 -156
- package/common/middleware/web_logger/middleware.json +0 -14
- package/common/middleware/web_main/index.js +0 -26
- package/common/middleware/web_main/middleware.json +0 -9
- package/common/middleware/web_static/index.js +0 -73
- package/common/middleware/web_static/middleware.json +0 -54
- package/common/middleware/web_waf/index.js +0 -395
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -711
- package/core/app/script.tpl.js +0 -52
- package/core/channel/index.js +0 -899
- package/core/channel/matcher.js +0 -585
- package/core/com/config.tpl.json +0 -16
- package/core/com/index.js +0 -77
- package/core/com/script.tpl.js +0 -5
- package/core/component/component.js +0 -42
- package/core/component/config.tpl.json +0 -63
- package/core/component/index.js +0 -273
- package/core/component/script.tpl.js +0 -19
- package/core/controller/config.tpl.json +0 -14
- package/core/controller/index.js +0 -371
- package/core/controller/script.tpl.js +0 -27
- package/core/factory/config.tpl.json +0 -14
- package/core/factory/entity.js +0 -275
- package/core/factory/index.js +0 -241
- package/core/factory/script.tpl.js +0 -16
- package/core/game/bat/index.js +0 -137
- package/core/game/bat/world.js +0 -622
- package/core/game/config.tpl.json +0 -16
- package/core/game/entity_admin.js +0 -230
- package/core/game/index.js +0 -186
- package/core/handler/config.tpl.json +0 -22
- package/core/handler/index.js +0 -181
- package/core/handler/script.tpl.js +0 -23
- package/core/logic/config.tpl.json +0 -14
- package/core/logic/index.js +0 -59
- package/core/logic/script.tpl.js +0 -19
- package/core/middleware/config.tpl.json +0 -16
- package/core/middleware/index.js +0 -117
- package/core/middleware/script.tpl.js +0 -37
- package/core/mod/config.tpl.json +0 -22
- package/core/mod/index.js +0 -136
- package/core/mod/script.tpl.js +0 -34
- package/core/model/config.tpl.json +0 -219
- package/core/model/index.js +0 -272
- package/core/model/model.js +0 -27
- package/core/model/script.tpl.js +0 -20
- package/core/notifier/config.tpl.json +0 -14
- package/core/notifier/index.js +0 -77
- package/core/notifier/script.tpl.js +0 -20
- package/core/plugin/config.tpl.json +0 -36
- package/core/plugin/index.js +0 -267
- package/core/plugin/script.tpl.js +0 -51
- package/core/pusher/config.tpl.json +0 -14
- package/core/pusher/index.js +0 -158
- package/core/pusher/script.tpl.js +0 -20
- package/core/room/bat/index.js +0 -170
- package/core/room/bat/room.js +0 -524
- package/core/room/config.tpl.json +0 -20
- package/core/room/index.js +0 -249
- package/core/room/room.js +0 -61
- package/core/scene/config.tpl.json +0 -14
- package/core/scene/index.js +0 -467
- package/core/scene/loop.js +0 -1306
- package/core/scene/map.js +0 -28
- package/core/scene/script.tpl.js +0 -22
- package/core/sender/config.tpl.json +0 -14
- package/core/sender/index.js +0 -79
- package/core/sender/script.tpl.js +0 -20
- package/core/service/config.tpl.json +0 -14
- package/core/service/index.js +0 -100
- package/core/service/script.tpl.js +0 -25
- package/core/store/config.tpl.json +0 -26
- package/core/store/index.js +0 -1794
- package/core/store/script.tpl.js +0 -22
- package/core/system/config.tpl.json +0 -18
- package/core/system/index.js +0 -312
- package/core/system/script.tpl.js +0 -77
- package/core/view/config.tpl.json +0 -14
- package/core/view/index.js +0 -91
- package/core/view/script.tpl.js +0 -20
- package/core/zone/bat/index.js +0 -744
- package/core/zone/config.tpl.json +0 -54
- package/core/zone/index.js +0 -655
- package/core/zone/script.tpl.js +0 -10
- package/core/zone/zone_bat.js +0 -136
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
- package/os.js +0 -53
- package/server.js +0 -602
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
package/core/zone/zone_bat.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* 玩家进入频道
|
|
4
|
-
* @param {string} player_id 玩家ID
|
|
5
|
-
* @param {number} channel_id 频道ID
|
|
6
|
-
* @returns {boolean} 是否进入成功
|
|
7
|
-
*/
|
|
8
|
-
Zone.prototype.enterChannel = async function (player_id, channel_id) {
|
|
9
|
-
// 参数校验
|
|
10
|
-
if (!player_id || typeof player_id !== 'string') {
|
|
11
|
-
throw new TypeError('玩家ID必须是有效字符串');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!channel_id || typeof channel_id !== 'number') {
|
|
15
|
-
throw new TypeError('频道ID必须是有效数字');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// 获取玩家对象
|
|
19
|
-
var player = this.getPlayer(player_id);
|
|
20
|
-
|
|
21
|
-
// 检查频道是否存在
|
|
22
|
-
if (!this.channel.has(channel_id)) {
|
|
23
|
-
throw new Error(`频道 ${channel_id} 不存在`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 如果玩家已在其他频道,先退出
|
|
27
|
-
if (player.channel_id && this.channel.get(player.channel_id)) {
|
|
28
|
-
await this.channel.get(player.channel_id).leave(player_id);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 玩家进入频道
|
|
32
|
-
await this.channel.get(channel_id).enter(player_id);
|
|
33
|
-
|
|
34
|
-
// 更新玩家频道ID
|
|
35
|
-
player.channel_id = channel_id;
|
|
36
|
-
|
|
37
|
-
return true;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 切换频道
|
|
42
|
-
* @param {string} player_id 玩家ID
|
|
43
|
-
* @param {number} channel_id 频道ID
|
|
44
|
-
* @returns {boolean} 是否切换成功
|
|
45
|
-
*/
|
|
46
|
-
Zone.prototype.switchChannel = async function (player_id, channel_id) {
|
|
47
|
-
// 参数校验
|
|
48
|
-
if (!player_id || typeof player_id !== 'string') {
|
|
49
|
-
throw new TypeError('玩家ID必须是有效字符串');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!channel_id || typeof channel_id !== 'number') {
|
|
53
|
-
throw new TypeError('频道ID必须是有效数字');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 获取玩家对象
|
|
57
|
-
var player = this.getPlayer(player_id);
|
|
58
|
-
|
|
59
|
-
// 检查目标频道是否存在
|
|
60
|
-
if (!this.channel[channel_id]) {
|
|
61
|
-
throw new Error(`频道 ${channel_id} 不存在`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 如果玩家已在目标频道,直接返回
|
|
65
|
-
if (player.channel_id === channel_id) {
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 退出当前频道
|
|
70
|
-
if (player.channel_id && this.channel.get(player.channel_id)) {
|
|
71
|
-
await this.channel.get(player.channel_id).leave(player_id);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 进入目标频道
|
|
75
|
-
await this.channel.get(channel_id).enter(player_id);
|
|
76
|
-
|
|
77
|
-
// 更新玩家频道ID
|
|
78
|
-
player.channel_id = channel_id;
|
|
79
|
-
|
|
80
|
-
return true;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 频道数据发送
|
|
85
|
-
* @param {number} channel_id 频道ID
|
|
86
|
-
* @param {object} data 发送数据
|
|
87
|
-
* @param {string} msg_type 消息类型
|
|
88
|
-
* @param {string} msg_group 消息范围
|
|
89
|
-
* @param {string} sender_id 发送者ID
|
|
90
|
-
* @returns {object} 发送结果
|
|
91
|
-
*/
|
|
92
|
-
Zone.prototype.sendToChannel = async function (channel_id, data, msg_type = 'text', msg_group = 'channel', sender_id = 'system') {
|
|
93
|
-
// 参数校验
|
|
94
|
-
if (!channel_id || typeof channel_id !== 'number') {
|
|
95
|
-
throw new TypeError('频道ID必须是有效数字');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!data || typeof data !== 'object') {
|
|
99
|
-
throw new TypeError('发送数据必须是有效对象');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
// 检查频道是否存在
|
|
104
|
-
var channel = this.channel.get(channel_id);
|
|
105
|
-
if (!channel) {
|
|
106
|
-
throw new Error(`频道 ${channel_id} 不存在`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// 创建发送对象
|
|
110
|
-
var send_obj = {
|
|
111
|
-
data: data,
|
|
112
|
-
msg_type: msg_type,
|
|
113
|
-
msg_group: msg_group,
|
|
114
|
-
sender_id: sender_id,
|
|
115
|
-
timestamp: Date.now(),
|
|
116
|
-
channel_id: channel_id,
|
|
117
|
-
zone_name: this.config.name,
|
|
118
|
-
msg_id: this._generateMsgId()
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// 触发频道数据发送事件,由业务层处理具体的发送逻辑
|
|
122
|
-
this.emitEvent('channel_send', {
|
|
123
|
-
...send_obj
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
players: channel.getPlayerNum(),
|
|
128
|
-
success: 0,
|
|
129
|
-
fail: 0,
|
|
130
|
-
failed_players: []
|
|
131
|
-
};
|
|
132
|
-
} catch (error) {
|
|
133
|
-
this.log('error', `频道数据发送失败: `, error);
|
|
134
|
-
throw error;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# 基类模块清单
|
|
2
|
-
1. 中间件middleware,如身份验证、日志记录等,调用控制器controller
|
|
3
|
-
2. 控制器controller,如用户控制器、订单控制器等,调用处理器handler,视图view
|
|
4
|
-
3. 视图view,渲染器renderer、渲染上下文context等
|
|
5
|
-
4. 静态资源static,如图片、音频、视频等
|
|
6
|
-
5. 应用处理器handler(主要是命令处理器、事件处理器等),如用户注册处理器、订单支付处理器等,调用服务service、模型model、仓储store,订阅事件总线eventer,发布事件到事件总线eventer
|
|
7
|
-
6. 领域服务service,如订单服务、用户服务等,调用模型model、其他领域服务service、复杂业务逻辑logic
|
|
8
|
-
7. 富血模型model,如用户、订单等
|
|
9
|
-
8. 仓储store,如数据库、缓存等,调用db、cache、第三方API等
|
|
10
|
-
9. 事件总线eventer,如事件监听、事件发布等
|
|
11
|
-
10. 游戏循环gameLoop,如帧循环、时间循环等,调用系统system的update方法
|
|
12
|
-
11. 游戏系统system,如物理系统、渲染系统、AI系统等,调用游戏实体entity、游戏组件component、游戏逻辑logic
|
|
13
|
-
12. 游戏逻辑logic,如游戏规则、游戏状态等
|
|
14
|
-
13. 游戏实体entity,如玩家、NPC、怪物等
|
|
15
|
-
14. 游戏组件component,如位置组件、动画组件、状态组件等
|
|
16
|
-
15. 游戏场景scene,如主菜单、游戏关卡等,调用系统system
|
|
17
|
-
16. 任务task,定时任务、异步任务等,发布事件到事件总线eventer
|
|
18
|
-
17. 通知器notifier,邮箱email、短信sms通知等,订阅事件总线eventer
|
|
19
|
-
18. 消息发送器sender,转发消息到外部服务器,订阅事件总线eventer
|
|
20
|
-
19. 广播器pusher,广播到websocket、socket等,订阅事件总线eventer
|
|
21
|
-
20. 应用app,如内容管理系统cms、游戏game、商城mail,引入模组mod、应用处理器handler、模型model、仓储store、游戏循环gameLoop、游戏场景scene、游戏系统system、游戏实体entity、游戏组件component、任务task,引用上级server等
|
|
22
|
-
21. 插件plugin,如支付插件pay、邮件插件mail、短信插件sms
|
|
23
|
-
22. 模组mod,如游戏道具模块、游戏装备模块等
|
|
24
|
-
23. 服务端server,程序唯一,引入适配器adapter(web/socket/mqtt),通知器notifier、消息发送器sender、广播器pusher、日志管理器logger、管理器manager、应用app、插件plugin、事件总线eventer、缓存cache、数据库操作db等
|
package/os.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const cluster = require('cluster');
|
|
2
|
-
const os = require('os');
|
|
3
|
-
const { Server } = require('./server.js');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 操作系统核心类
|
|
7
|
-
*/
|
|
8
|
-
class MM_os {
|
|
9
|
-
/**
|
|
10
|
-
* 构造函数
|
|
11
|
-
* @param {object} config 配置对象
|
|
12
|
-
*/
|
|
13
|
-
constructor(config) {
|
|
14
|
-
this.config = config;
|
|
15
|
-
this.server = null;
|
|
16
|
-
this.num_cpus = os.cpus().length;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 初始化方法
|
|
21
|
-
* @returns {Promise<void>}
|
|
22
|
-
*/
|
|
23
|
-
async init() {
|
|
24
|
-
if (cluster.isPrimary) {
|
|
25
|
-
for (let i = 0; i < this.num_cpus; i++) {
|
|
26
|
-
cluster.fork();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
cluster.on('exit', (worker) => {
|
|
30
|
-
cluster.fork();
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
this.server = new Server(this.config);
|
|
34
|
-
await this.server.init();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 启动方法
|
|
40
|
-
* @returns {Promise<void>}
|
|
41
|
-
*/
|
|
42
|
-
async start() {
|
|
43
|
-
if (cluster.isPrimary) {
|
|
44
|
-
} else {
|
|
45
|
-
if (!this.server) {
|
|
46
|
-
throw new Error('请先调用 init() 方法初始化');
|
|
47
|
-
}
|
|
48
|
-
await this.server.start();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = { MM_os };
|