mm_os 3.3.1 → 4.0.1
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/LICENSE +21 -201
- package/README.md +498 -99
- package/README_EN.md +505 -0
- package/adapter/adapter.js +431 -0
- package/adapter/custom_persistence.js +660 -0
- package/adapter/mqtt.js +273 -0
- package/adapter/socket.js +113 -0
- package/adapter/web.js +67 -0
- package/adapter/websocket.js +146 -0
- package/com/api/com.json +5 -0
- package/{core/com → com}/api/config.tpl.json +8 -8
- package/com/api/drive.js +708 -0
- package/com/api/index.js +198 -0
- package/com/api/oauth.js +200 -0
- package/com/api/script.tpl.js +32 -0
- package/com/cmd/README.md +11 -0
- package/com/cmd/com.json +5 -0
- package/com/cmd/config.tpl.json +122 -0
- package/com/cmd/drive.js +1548 -0
- package/com/cmd/index.js +1066 -0
- package/com/cmd/msg.json +48 -0
- package/com/cmd/nlp.js +525 -0
- package/com/cmd/script.tpl.js +32 -0
- package/com/db/com.json +5 -0
- package/com/db/drive.js +1999 -0
- package/com/db/index.js +242 -0
- package/{core/com → com}/event/README.md +4 -4
- package/com/event/com.json +5 -0
- package/{core/com → com}/event/config.tpl.json +18 -18
- package/com/event/drive.js +59 -0
- package/com/event/index.js +409 -0
- package/com/event/script.tpl.js +23 -0
- package/com/mqtt/com.json +5 -0
- package/{core/com → com}/mqtt/config.tpl.json +3 -5
- package/com/mqtt/drive.js +676 -0
- package/com/mqtt/index.js +822 -0
- package/com/mqtt/mm_mqtt.js +425 -0
- package/com/mqtt/script.tpl.js +723 -0
- package/com/nav/com.json +5 -0
- package/com/nav/config.tpl.json +84 -0
- package/com/nav/drive.js +702 -0
- package/com/nav/index.js +231 -0
- package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
- package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
- package/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/com/nav/tpl/admin_pc/page_view.vue +124 -0
- package/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/com/nav/tpl/dev_pc/page_type.vue +313 -0
- package/com/nav/tpl/home_pc/page_default.vue +234 -0
- package/com/nav/tpl/home_pc/page_form.vue +137 -0
- package/com/nav/tpl/home_pc/page_list.vue +234 -0
- package/com/nav/tpl/home_pc/page_nav.vue +221 -0
- package/com/nav/tpl/home_pc/page_type.vue +234 -0
- package/com/nav/tpl/home_pc/page_view.vue +125 -0
- package/com/nav/tpl/home_phone/page_channel.vue +234 -0
- package/com/nav/tpl/home_phone/page_default.vue +234 -0
- package/com/nav/tpl/home_phone/page_form.vue +137 -0
- package/com/nav/tpl/home_phone/page_nav.vue +237 -0
- package/com/nav/tpl/home_phone/page_type.vue +234 -0
- package/com/nav/tpl/home_phone/page_view.vue +125 -0
- package/com/nav/viewmodel.js +446 -0
- package/com/param/com.json +5 -0
- package/{core/com → com}/param/config.tpl.json +7 -1
- package/com/param/drive.js +502 -0
- package/com/param/index.js +155 -0
- package/com/param/script.tpl.js +12 -0
- package/com/pendant/com.json +5 -0
- package/{core/com/component → com/pendant}/config.tpl.json +15 -13
- package/com/pendant/drive.js +204 -0
- package/com/pendant/index.js +441 -0
- package/com/pendant/pendant.html +16 -0
- package/com/pendant/script.tpl.js +18 -0
- package/com/socket/com.json +5 -0
- package/com/socket/config.tpl.json +12 -0
- package/com/socket/drive.js +651 -0
- package/com/socket/index.js +351 -0
- package/com/socket/script.tpl.js +41 -0
- package/com/sql/com.json +5 -0
- package/{core/com → com}/sql/config.tpl.json +13 -9
- package/com/sql/drive.js +1259 -0
- package/com/sql/index.js +150 -0
- package/com/sql/script.tpl.js +47 -0
- package/com/static/com.json +5 -0
- package/{core/com → com}/static/config.tpl.json +10 -6
- package/com/static/drive.js +194 -0
- package/com/static/index.js +226 -0
- package/com/static/script.tpl.js +28 -0
- package/com/task/com.json +5 -0
- package/{core/com → com}/task/config.tpl.json +4 -6
- package/com/task/drive.js +405 -0
- package/com/task/index.js +148 -0
- package/com/task/script.tpl.js +37 -0
- package/com/template/com.json +5 -0
- package/com/template/config.tpl.json +16 -0
- package/com/template/drive.js +80 -0
- package/com/template/index.js +141 -0
- package/com.js +156 -0
- package/common/README.md +2 -0
- package/common/handler/msg/handler.json +22 -0
- package/common/handler/msg/index.js +23 -0
- package/common/handler/player/handler.json +22 -0
- package/common/handler/player/index.js +287 -0
- package/common/handler/user/handler.json +22 -0
- package/common/handler/user/index.js +23 -0
- package/common/middleware/web_after/index.js +29 -0
- package/common/middleware/web_after/middleware.json +9 -0
- package/common/middleware/web_base/index.js +113 -0
- package/common/middleware/web_base/middleware.json +19 -0
- package/common/middleware/web_before/index.js +33 -0
- package/common/middleware/web_before/middleware.json +9 -0
- package/common/middleware/web_cors/index.js +87 -0
- package/common/middleware/web_cors/middleware.json +24 -0
- package/common/middleware/web_error/index.js +119 -0
- package/common/middleware/web_error/middleware.json +18 -0
- package/common/middleware/web_ip/index.js +15 -0
- package/common/middleware/web_ip/middleware.json +14 -0
- package/common/middleware/web_logger/index.js +156 -0
- package/common/middleware/web_logger/middleware.json +14 -0
- package/common/middleware/web_main/index.js +24 -0
- package/common/middleware/web_main/middleware.json +9 -0
- package/common/middleware/web_static/index.js +73 -0
- package/common/middleware/web_static/middleware.json +54 -0
- package/common/middleware/web_waf/index.js +385 -0
- package/common/middleware/web_waf/middleware.json +13 -0
- package/common/model/msg/index.js +88 -0
- package/common/model/msg/model.json +401 -0
- package/common/model/player/index.js +63 -0
- package/common/model/player/model.json +185 -0
- package/common/model/user/index.js +11 -0
- package/common/model/user/model.json +219 -0
- package/core/app/config.tpl.json +67 -0
- package/core/app/index.js +632 -0
- package/core/app/script.tpl.js +52 -0
- package/core/channel/index.js +899 -0
- package/core/channel/matcher.js +585 -0
- package/core/com/config.tpl.json +16 -0
- package/core/com/index.js +74 -0
- package/core/com/script.tpl.js +5 -0
- package/core/component/component.js +42 -0
- package/core/component/config.tpl.json +63 -0
- package/core/component/index.js +273 -0
- package/core/component/script.tpl.js +19 -0
- package/core/controller/config.tpl.json +14 -0
- package/core/controller/index.js +373 -0
- package/core/controller/script.tpl.js +27 -0
- package/core/factory/config.tpl.json +14 -0
- package/core/factory/entity.js +275 -0
- package/core/factory/index.js +241 -0
- package/core/factory/script.tpl.js +16 -0
- package/core/game/bat/index.js +137 -0
- package/core/game/bat/world.js +622 -0
- package/core/game/config.tpl.json +16 -0
- package/core/game/entity_admin.js +230 -0
- package/core/game/index.js +186 -0
- package/core/handler/config.tpl.json +22 -0
- package/core/handler/index.js +181 -0
- package/core/handler/script.tpl.js +23 -0
- package/core/logic/config.tpl.json +14 -0
- package/core/logic/index.js +59 -0
- package/core/logic/script.tpl.js +19 -0
- package/core/middleware/config.tpl.json +16 -0
- package/core/middleware/index.js +125 -0
- package/core/middleware/script.tpl.js +37 -0
- package/core/mod/config.tpl.json +22 -0
- package/core/mod/index.js +130 -0
- package/core/mod/script.tpl.js +34 -0
- package/core/model/config.tpl.json +219 -0
- package/core/model/index.js +272 -0
- package/core/model/model.js +27 -0
- package/core/model/script.tpl.js +20 -0
- package/core/notifier/config.tpl.json +14 -0
- package/core/notifier/index.js +77 -0
- package/core/notifier/script.tpl.js +20 -0
- package/core/plugin/config.tpl.json +24 -0
- package/core/plugin/index.js +232 -0
- package/core/plugin/script.tpl.js +51 -0
- package/core/pusher/config.tpl.json +14 -0
- package/core/pusher/index.js +161 -0
- package/core/pusher/script.tpl.js +20 -0
- package/core/room/bat/index.js +170 -0
- package/core/room/bat/room.js +524 -0
- package/core/room/config.tpl.json +20 -0
- package/core/room/index.js +249 -0
- package/core/room/room.js +61 -0
- package/core/scene/config.tpl.json +14 -0
- package/core/scene/index.js +466 -0
- package/core/scene/loop.js +1255 -0
- package/core/scene/map.js +28 -0
- package/core/scene/script.tpl.js +22 -0
- package/core/sender/config.tpl.json +14 -0
- package/core/sender/index.js +79 -0
- package/core/sender/script.tpl.js +20 -0
- package/core/service/config.tpl.json +14 -0
- package/core/service/index.js +100 -0
- package/core/service/script.tpl.js +25 -0
- package/core/store/config.tpl.json +26 -0
- package/core/store/index.js +1755 -0
- package/core/store/script.tpl.js +22 -0
- package/core/store/sql.js +1464 -0
- package/core/system/config.tpl.json +18 -0
- package/core/system/index.js +312 -0
- package/core/system/script.tpl.js +77 -0
- package/core/view/config.tpl.json +14 -0
- package/core/view/index.js +91 -0
- package/core/view/script.tpl.js +20 -0
- package/core/zone/bat/index.js +725 -0
- package/core/zone/config.tpl.json +54 -0
- package/core/zone/index.js +614 -0
- package/core/zone/script.tpl.js +10 -0
- package/core/zone/zone_bat.js +136 -0
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
- package/index.js +17 -333
- package/os.js +57 -0
- package/package.json +65 -55
- package/server.js +598 -0
- package/README.en.md +0 -36
- package/conf.json +0 -3
- package/core/base/mqtt/index.js +0 -1110
- package/core/base/mqtt/lib.js +0 -40
- package/core/base/web/index.js +0 -245
- package/core/com/api/com.json +0 -4
- package/core/com/api/drive.js +0 -668
- package/core/com/api/index.js +0 -108
- package/core/com/api/oauth.js +0 -158
- package/core/com/api/script.js +0 -32
- package/core/com/app/README.md +0 -3
- package/core/com/app/com.json +0 -4
- package/core/com/app/config.tpl.json +0 -16
- package/core/com/app/drive.js +0 -309
- package/core/com/app/index.js +0 -211
- package/core/com/app/script.js +0 -155
- package/core/com/cmd/com.json +0 -4
- package/core/com/cmd/config.tpl.json +0 -66
- package/core/com/cmd/drive.js +0 -513
- package/core/com/cmd/index.js +0 -354
- package/core/com/cmd/old/5w2h.js +0 -54
- package/core/com/cmd/old/drive.js +0 -423
- package/core/com/cmd/script.js +0 -11
- package/core/com/component/README.md +0 -3
- package/core/com/component/com.json +0 -4
- package/core/com/component/component.html +0 -16
- package/core/com/component/drive.js +0 -197
- package/core/com/component/index.js +0 -312
- package/core/com/component/script.js +0 -18
- package/core/com/db/com.json +0 -4
- package/core/com/db/drive.js +0 -1160
- package/core/com/db/index.js +0 -176
- package/core/com/event/com.json +0 -4
- package/core/com/event/drive.js +0 -133
- package/core/com/event/index.js +0 -345
- package/core/com/event/script.js +0 -26
- package/core/com/eventer/com.js +0 -477
- package/core/com/eventer/com.json +0 -4
- package/core/com/middleware/com.js +0 -154
- package/core/com/middleware/com.json +0 -4
- package/core/com/middleware/config.tpl.json +0 -8
- package/core/com/middleware/script.js +0 -9
- package/core/com/mqtt/com.json +0 -4
- package/core/com/mqtt/drive.js +0 -600
- package/core/com/mqtt/index.js +0 -572
- package/core/com/mqtt/mm_mqtt.js +0 -330
- package/core/com/mqtt/script.js +0 -604
- package/core/com/msg/com.js +0 -296
- package/core/com/msg/com.json +0 -4
- package/core/com/nav/com.json +0 -4
- package/core/com/nav/config.tpl.json +0 -75
- package/core/com/nav/drive.js +0 -549
- package/core/com/nav/index.js +0 -182
- package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/core/com/nav/viewmodel.js +0 -296
- package/core/com/param/drive.js +0 -366
- package/core/com/param/index.js +0 -80
- package/core/com/param/script.js +0 -12
- package/core/com/param/test.js +0 -98
- package/core/com/plugin/README.md +0 -3
- package/core/com/plugin/com.json +0 -4
- package/core/com/plugin/config.tpl.json +0 -26
- package/core/com/plugin/drive.js +0 -536
- package/core/com/plugin/index.js +0 -259
- package/core/com/plugin/script.js +0 -213
- package/core/com/rpc/com.json +0 -4
- package/core/com/rpc/drive.js +0 -160
- package/core/com/rpc/index.js +0 -87
- package/core/com/rpc/rpc.js +0 -118
- package/core/com/socket/com.json +0 -4
- package/core/com/socket/config.tpl.json +0 -14
- package/core/com/socket/drive.js +0 -403
- package/core/com/socket/index.js +0 -62
- package/core/com/socket/script.js +0 -42
- package/core/com/sql/drive.js +0 -1087
- package/core/com/sql/index.js +0 -83
- package/core/com/sql/script.js +0 -48
- package/core/com/static/com.json +0 -4
- package/core/com/static/drive.js +0 -220
- package/core/com/static/index.js +0 -149
- package/core/com/static/script.js +0 -28
- package/core/com/task/com.json +0 -4
- package/core/com/task/drive.js +0 -403
- package/core/com/task/index.js +0 -110
- package/core/com/task/script.js +0 -37
- package/core/com/timer/com.js +0 -217
- package/core/com/timer/com.json +0 -4
- package/core/com/tpl/com.js +0 -19
- package/core/com/tpl/com.json +0 -4
- package/lib/actions.js +0 -50
- package/lib/base.js +0 -361
- package/lib/com.js +0 -29
- package/lib/ref.js +0 -121
- package/middleware/cors/index.js +0 -119
- package/middleware/cors/middleware.json +0 -20
- package/middleware/csrf/index.js +0 -202
- package/middleware/csrf/middleware.json +0 -24
- package/middleware/ip_firewall/index.js +0 -476
- package/middleware/ip_firewall/middleware.json +0 -109
- package/middleware/mqtt_base/index.js +0 -10
- package/middleware/mqtt_base/middleware.json +0 -11
- package/middleware/security_audit/index.js +0 -543
- package/middleware/security_audit/middleware.json +0 -48
- package/middleware/waf/index.js +0 -343
- package/middleware/waf/middleware.json +0 -10
- package/middleware/waf_ddos/index.js +0 -520
- package/middleware/waf_ddos/middleware.json +0 -38
- package/middleware/waf_xss/index.js +0 -269
- package/middleware/waf_xss/middleware.json +0 -18
- package/middleware/web_after/index.js +0 -33
- package/middleware/web_after/middleware.json +0 -10
- package/middleware/web_base/index.js +0 -90
- package/middleware/web_base/middleware.json +0 -10
- package/middleware/web_before/index.js +0 -27
- package/middleware/web_before/middleware.json +0 -10
- package/middleware/web_check/index.js +0 -28
- package/middleware/web_check/middleware.json +0 -10
- package/middleware/web_main/index.js +0 -28
- package/middleware/web_main/middleware.json +0 -10
- package/middleware/web_proxy/index.js +0 -37
- package/middleware/web_proxy/middleware.json +0 -10
- package/middleware/web_render/index.js +0 -87
- package/middleware/web_render/middleware.json +0 -10
- package/middleware/web_socket/index.js +0 -34
- package/middleware/web_socket/middleware.json +0 -10
- package/middleware/web_static/index.js +0 -115
- package/middleware/web_static/middleware.json +0 -10
- /package/{core/com → com}/api/README.md +0 -0
- /package/{core/com → com}/db/README.md +0 -0
- /package/{core/com → com}/mqtt/README.md +0 -0
- /package/{core/com → com}/nav/README.md +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
- /package/{core/com → com}/param/README.md +0 -0
- /package/{core/com/cmd → com/pendant}/README.md +0 -0
- /package/{core/com → com}/socket/README.md +0 -0
- /package/{core/com → com}/sql/README.md +0 -0
- /package/{core/com → com}/static/README.md +0 -0
- /package/{core/com → com}/task/README.md +0 -0
package/server.js
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
require('mm_expand');
|
|
2
|
+
const {
|
|
3
|
+
Log
|
|
4
|
+
} = require('mm_logs');
|
|
5
|
+
const {
|
|
6
|
+
cacheAdmin
|
|
7
|
+
} = require('mm_cache');
|
|
8
|
+
const {
|
|
9
|
+
sqlAdmin
|
|
10
|
+
} = require('mm_sql');
|
|
11
|
+
const {
|
|
12
|
+
Config
|
|
13
|
+
} = require('mm_config');
|
|
14
|
+
const {
|
|
15
|
+
Manager,
|
|
16
|
+
Drive
|
|
17
|
+
} = require('mm_machine');
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
App
|
|
21
|
+
} = require('./core/app/index.js');
|
|
22
|
+
const {
|
|
23
|
+
Game
|
|
24
|
+
} = require('./core/game/index.js');
|
|
25
|
+
// const {
|
|
26
|
+
// Zone
|
|
27
|
+
// } = require('./core/zone/index.js');
|
|
28
|
+
const {
|
|
29
|
+
Mod
|
|
30
|
+
} = require('./core/mod/index.js');
|
|
31
|
+
const {
|
|
32
|
+
Middleware
|
|
33
|
+
} = require('./core/middleware/index.js');
|
|
34
|
+
const {
|
|
35
|
+
Notifier
|
|
36
|
+
} = require('./core/notifier/index.js');
|
|
37
|
+
const {
|
|
38
|
+
Pusher
|
|
39
|
+
} = require('./core/pusher/index.js');
|
|
40
|
+
const {
|
|
41
|
+
Sender
|
|
42
|
+
} = require('./core/sender/index.js');
|
|
43
|
+
const {
|
|
44
|
+
Web
|
|
45
|
+
} = require('./adapter/web.js');
|
|
46
|
+
const {
|
|
47
|
+
Mqtt
|
|
48
|
+
} = require('./adapter/mqtt.js');
|
|
49
|
+
const {
|
|
50
|
+
Socket
|
|
51
|
+
} = require('./adapter/socket.js');
|
|
52
|
+
const {
|
|
53
|
+
WebSocket
|
|
54
|
+
} = require('./adapter/websocket.js');
|
|
55
|
+
const {
|
|
56
|
+
Com
|
|
57
|
+
} = require('./com.js');
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 服务器类
|
|
61
|
+
* 负责管理整个应用的服务端架构
|
|
62
|
+
*/
|
|
63
|
+
class Server extends Drive {
|
|
64
|
+
static config = {
|
|
65
|
+
name: 'mos',
|
|
66
|
+
title: 'mm服务端系统',
|
|
67
|
+
log: {
|
|
68
|
+
level: 'debug',
|
|
69
|
+
file: false
|
|
70
|
+
},
|
|
71
|
+
mqtt: {
|
|
72
|
+
host: '127.0.0.1',
|
|
73
|
+
port: 1883,
|
|
74
|
+
state: 0
|
|
75
|
+
},
|
|
76
|
+
socket: {
|
|
77
|
+
host: '0.0.0.0',
|
|
78
|
+
port: 8200,
|
|
79
|
+
state: 0
|
|
80
|
+
},
|
|
81
|
+
sql: {
|
|
82
|
+
// mysql、sqlite
|
|
83
|
+
way: 'mysql'
|
|
84
|
+
},
|
|
85
|
+
sqlite: {
|
|
86
|
+
dir: './db/'.fullname(),
|
|
87
|
+
user: 'root',
|
|
88
|
+
password: '',
|
|
89
|
+
database: 'mm',
|
|
90
|
+
charset: 'utf8mb4',
|
|
91
|
+
connect_timeout: 20000,
|
|
92
|
+
connection_limit: 500
|
|
93
|
+
},
|
|
94
|
+
mysql: {
|
|
95
|
+
host: '127.0.0.1',
|
|
96
|
+
port: 3306,
|
|
97
|
+
user: 'root',
|
|
98
|
+
password: 'Asd159357',
|
|
99
|
+
database: '',
|
|
100
|
+
charset: 'utf8mb4',
|
|
101
|
+
timezone: '+08:00',
|
|
102
|
+
connect_timeout: 20000,
|
|
103
|
+
connection_limit: 500
|
|
104
|
+
},
|
|
105
|
+
cache: {
|
|
106
|
+
// 缓存方式memory、redis、mongodb
|
|
107
|
+
way: 'redis'
|
|
108
|
+
},
|
|
109
|
+
// 缓存基础配置
|
|
110
|
+
cachebase: {
|
|
111
|
+
dir: './cache/'.fullname(),
|
|
112
|
+
expire: 0,
|
|
113
|
+
max: 0,
|
|
114
|
+
persist: false, // 是否启用持久化
|
|
115
|
+
saveInterval: 60000 // 保存间隔(毫秒)
|
|
116
|
+
},
|
|
117
|
+
// 缓存配置
|
|
118
|
+
redis: {
|
|
119
|
+
// 服务器地址
|
|
120
|
+
host: 'localhost',
|
|
121
|
+
// 端口号
|
|
122
|
+
port: 6379,
|
|
123
|
+
// 密码
|
|
124
|
+
password: 'asd159357',
|
|
125
|
+
// 数据库
|
|
126
|
+
database: 0,
|
|
127
|
+
// 前缀
|
|
128
|
+
prefix: "mm_",
|
|
129
|
+
// 连接超时时间(ms)
|
|
130
|
+
connect_timeout: 10000,
|
|
131
|
+
// 重试次数
|
|
132
|
+
retry_count: 3,
|
|
133
|
+
// 重试间隔(ms)
|
|
134
|
+
retry_delay: 1000
|
|
135
|
+
},
|
|
136
|
+
// 数据库配置
|
|
137
|
+
mongodb: {
|
|
138
|
+
// 服务器地址
|
|
139
|
+
host: 'localhost',
|
|
140
|
+
// 端口号
|
|
141
|
+
port: 27017,
|
|
142
|
+
// 数据库名
|
|
143
|
+
database: "mm",
|
|
144
|
+
// 用户名
|
|
145
|
+
user: '',
|
|
146
|
+
// 密码
|
|
147
|
+
password: '',
|
|
148
|
+
// 连接选项 (MongoDB驱动7.x版本支持的参数)
|
|
149
|
+
min_pool_size: 10,
|
|
150
|
+
max_pool_size: 100,
|
|
151
|
+
connect_timeout_ms: 10000,
|
|
152
|
+
server_selection_timeout_ms: 5000,
|
|
153
|
+
retry_writes: true
|
|
154
|
+
},
|
|
155
|
+
web: {
|
|
156
|
+
state: 1,
|
|
157
|
+
// 访问地址
|
|
158
|
+
host: '127.0.0.1',
|
|
159
|
+
// 访问端口号
|
|
160
|
+
port: 8000,
|
|
161
|
+
// 是否启用websocket
|
|
162
|
+
socket: false,
|
|
163
|
+
// 是否启用压缩
|
|
164
|
+
compress: false,
|
|
165
|
+
// 是否启用事件
|
|
166
|
+
event: true,
|
|
167
|
+
// 是否启用事件
|
|
168
|
+
log: true,
|
|
169
|
+
// 跨域
|
|
170
|
+
cos: {
|
|
171
|
+
status: true,
|
|
172
|
+
origin: '*',
|
|
173
|
+
// "headers": "Content-Type,Content-Length,Authorization,Accept,X-Requested-With,x-auth-token,token,client_id,appid,apikey,user_id,x-forwarded-for,x-real-ip,User-Agent,cache-control,pragma,accept-encoding,connection,host"
|
|
174
|
+
},
|
|
175
|
+
// 代理转发
|
|
176
|
+
proxy: {},
|
|
177
|
+
// static 配置
|
|
178
|
+
static: {
|
|
179
|
+
// 是否开启静态文件处理
|
|
180
|
+
state: 1,
|
|
181
|
+
// 前端缓存时间,单位秒
|
|
182
|
+
max_age: 7200,
|
|
183
|
+
// 是否开启缓存
|
|
184
|
+
cache: true,
|
|
185
|
+
// 后端缓存时间,单位秒
|
|
186
|
+
cache_age: 0,
|
|
187
|
+
// 是否开启immutable缓存
|
|
188
|
+
immutable: true,
|
|
189
|
+
// 是否开启隐藏文件处理
|
|
190
|
+
hidden: false,
|
|
191
|
+
// 是否格式化文件
|
|
192
|
+
format: true,
|
|
193
|
+
// 是否指定文件扩展名
|
|
194
|
+
extensions: false,
|
|
195
|
+
// 是否开启brotli压缩
|
|
196
|
+
brotli: false,
|
|
197
|
+
// 是否开启gzip压缩
|
|
198
|
+
gzip: false,
|
|
199
|
+
// 静态文件根目录
|
|
200
|
+
root: "./static",
|
|
201
|
+
// 编译vue文件,启动后会将vue转为js,可让前端通过 import xxx from './xxx.vue' 引入
|
|
202
|
+
compile_vue: true,
|
|
203
|
+
// 编译markdown文件,启动后会将markdown转为html
|
|
204
|
+
compile_md: true,
|
|
205
|
+
// 是否将files中的文件的js转换为amd格式
|
|
206
|
+
convert_amd: false,
|
|
207
|
+
// 指定路径文件需要转换
|
|
208
|
+
src_path: '/src',
|
|
209
|
+
// 需要转换的文件扩展名
|
|
210
|
+
files: [
|
|
211
|
+
'.js',
|
|
212
|
+
'.vue',
|
|
213
|
+
'.html'
|
|
214
|
+
],
|
|
215
|
+
// 是否启用文件修改监听(实时检测文件修改)
|
|
216
|
+
watch: true
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 构造函数
|
|
223
|
+
* @param {object} config 配置参数
|
|
224
|
+
*/
|
|
225
|
+
constructor(config) {
|
|
226
|
+
super({ ...Server.config, ...config });
|
|
227
|
+
/** == 管理层 == */
|
|
228
|
+
// 管理器
|
|
229
|
+
this.manager = {};
|
|
230
|
+
// 通知器
|
|
231
|
+
this.notifier = {};
|
|
232
|
+
// 消息发送器
|
|
233
|
+
this.sender = {};
|
|
234
|
+
// 广播器
|
|
235
|
+
this.pusher = {};
|
|
236
|
+
|
|
237
|
+
/** == 应用层 == */
|
|
238
|
+
// 中间件
|
|
239
|
+
this.middleware = {};
|
|
240
|
+
// 应用
|
|
241
|
+
this.app = {};
|
|
242
|
+
// 模组,用于功能/玩法扩展
|
|
243
|
+
this.mod = {};
|
|
244
|
+
// 游戏
|
|
245
|
+
this.game = {};
|
|
246
|
+
// 事件总线
|
|
247
|
+
this.eventer = $.eventer;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 预置
|
|
253
|
+
*/
|
|
254
|
+
Server.prototype._preset = function () {
|
|
255
|
+
// 适配器
|
|
256
|
+
this.adapter = {};
|
|
257
|
+
|
|
258
|
+
/** == 基础设施 == */
|
|
259
|
+
// 日志
|
|
260
|
+
this.setLogger($.log || console);
|
|
261
|
+
// 数据库
|
|
262
|
+
this.sql = null;
|
|
263
|
+
// 缓存
|
|
264
|
+
this.cache = null;
|
|
265
|
+
// 文件管理
|
|
266
|
+
this.filer = null;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* 深度合并对象
|
|
271
|
+
* @param {object} target 目标对象
|
|
272
|
+
* @param {object} source 源对象
|
|
273
|
+
* @returns {object} 合并后的对象
|
|
274
|
+
*/
|
|
275
|
+
Server.prototype.deepMerge = function (target, source) {
|
|
276
|
+
for (let key of Object.keys(source)) {
|
|
277
|
+
if (source[key] instanceof Object && key in target) {
|
|
278
|
+
Object.assign(source[key], this.deepMerge(target[key], source[key]));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
...target,
|
|
283
|
+
...source
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* 设置配置
|
|
289
|
+
* @param {object} config 配置参数
|
|
290
|
+
*/
|
|
291
|
+
Server.prototype.setConfig = function (config) {
|
|
292
|
+
if (config) {
|
|
293
|
+
this.config = this.deepMerge(this.config, config);
|
|
294
|
+
this._preset();
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 初始化基础设施
|
|
300
|
+
*/
|
|
301
|
+
Server.prototype._initModules = function () {
|
|
302
|
+
// 模板引擎
|
|
303
|
+
require('mm_tpl');
|
|
304
|
+
const Http = require('mm_https').Http;
|
|
305
|
+
$.Http = Http;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 初始化基础设施
|
|
310
|
+
*/
|
|
311
|
+
Server.prototype._initBase = function () {
|
|
312
|
+
// 获取数据库配置
|
|
313
|
+
var sql = { type: 'mysql', ...this.config.sql };
|
|
314
|
+
if (this.config.mysql) {
|
|
315
|
+
sql.mysql = this.config.mysql;
|
|
316
|
+
}
|
|
317
|
+
if (this.config.sqlite) {
|
|
318
|
+
sql.sqlite = this.config.sqlite;
|
|
319
|
+
}
|
|
320
|
+
$.sqlAdmin = sqlAdmin;
|
|
321
|
+
this.sql = sqlAdmin('sys', sql);
|
|
322
|
+
$.sql = this.sql;
|
|
323
|
+
|
|
324
|
+
// 获取缓存配置
|
|
325
|
+
var cache = { type: 'memory', ...this.config.cache };
|
|
326
|
+
if (this.config.cachebase) {
|
|
327
|
+
cache.cachebase = this.config.cachebase;
|
|
328
|
+
}
|
|
329
|
+
if (this.config.redis) {
|
|
330
|
+
cache = { ...cache, ...this.config.redis };
|
|
331
|
+
}
|
|
332
|
+
if (this.config.mongodb) {
|
|
333
|
+
cache.mongodb = this.config.mongodb;
|
|
334
|
+
}
|
|
335
|
+
this.cache = cacheAdmin('sys', cache);
|
|
336
|
+
$.cache = this.cache;
|
|
337
|
+
|
|
338
|
+
this.filer = $.file;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* 初始化工具
|
|
343
|
+
*/
|
|
344
|
+
Server.prototype._initTool = function () {
|
|
345
|
+
this.logger = new Log(this.config.log);
|
|
346
|
+
$.log = this.logger;
|
|
347
|
+
$.config = new Config({
|
|
348
|
+
file: '/config.json'.fullname()
|
|
349
|
+
});
|
|
350
|
+
$.config.load();
|
|
351
|
+
$.config.setOptions(this.config);
|
|
352
|
+
$.config.saveAsync();
|
|
353
|
+
$.com = new Com();
|
|
354
|
+
$.com.loads();
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* 初始化适配器
|
|
359
|
+
*/
|
|
360
|
+
Server.prototype._initAdapter = async function () {
|
|
361
|
+
// http服务器
|
|
362
|
+
var web = new Web(this.config.web);
|
|
363
|
+
web.init(this);
|
|
364
|
+
this.adapter.web = web;
|
|
365
|
+
if (this.config.web.socket) {
|
|
366
|
+
// websocket服务器 - 与web服务器共享同一个端口
|
|
367
|
+
this.adapter.ws = await new WebSocket(this.config.web).init(web);
|
|
368
|
+
}
|
|
369
|
+
if (this.config.mqtt && this.config.mqtt.state) {
|
|
370
|
+
// mqtt服务器
|
|
371
|
+
this.adapter.mqtt = await new Mqtt(this.config.mqtt).init(this.cache);
|
|
372
|
+
}
|
|
373
|
+
if (this.config.socket && this.config.socket.state) {
|
|
374
|
+
// socket服务器
|
|
375
|
+
this.adapter.socket = await new Socket(this.config.socket || {}).init();
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* 创建管理器实例
|
|
382
|
+
* @param {string} name 管理器名称
|
|
383
|
+
* @param {string} title 管理器标题
|
|
384
|
+
* @param {Function} cls 管理器类
|
|
385
|
+
* @returns {object} 管理器实例
|
|
386
|
+
*/
|
|
387
|
+
Server.prototype._createManager = function (name, title, cls) {
|
|
388
|
+
var manager = new Manager(
|
|
389
|
+
{
|
|
390
|
+
name: name,
|
|
391
|
+
title: title,
|
|
392
|
+
filename: name + '.json',
|
|
393
|
+
tpl_dir: `./core/${name}/`.fullname(__dirname),
|
|
394
|
+
base_dir: `./common/${name}/`.fullname(__dirname),
|
|
395
|
+
dir: `./${name}`.fullname()
|
|
396
|
+
},
|
|
397
|
+
this,
|
|
398
|
+
this[name],
|
|
399
|
+
cls
|
|
400
|
+
);
|
|
401
|
+
// 设置到对应的管理器属性
|
|
402
|
+
this.manager[name] = manager;
|
|
403
|
+
return manager;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* 初始化管理
|
|
408
|
+
*/
|
|
409
|
+
Server.prototype._initManager = async function () {
|
|
410
|
+
// 管理器配置列表
|
|
411
|
+
var mgrConfigs = [
|
|
412
|
+
{ name: 'game', title: '游戏', Module: Game },
|
|
413
|
+
// { name: 'zone', title: '分区', Module: Zone },
|
|
414
|
+
{ name: 'app', title: '应用', Module: App },
|
|
415
|
+
{ name: 'mod', title: '模组', Module: Mod },
|
|
416
|
+
{ name: 'middleware', title: '中间件', Module: Middleware },
|
|
417
|
+
{ name: 'notifier', title: '通知器', Module: Notifier },
|
|
418
|
+
{ name: 'sender', title: '消息发送器', Module: Sender },
|
|
419
|
+
{ name: 'pusher', title: '广播器', Module: Pusher }
|
|
420
|
+
];
|
|
421
|
+
|
|
422
|
+
// 管理器实例集合
|
|
423
|
+
var managers = [];
|
|
424
|
+
|
|
425
|
+
// 使用for循环初始化所有管理器
|
|
426
|
+
for (var i = 0; i < mgrConfigs.length; i++) {
|
|
427
|
+
var config = mgrConfigs[i];
|
|
428
|
+
var manager = this._createManager(config.name, config.title, config.Module);
|
|
429
|
+
managers.push(manager);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// 并行执行所有管理器的初始化操作
|
|
433
|
+
var init_promises = [];
|
|
434
|
+
for (var j = 0; j < managers.length; j++) {
|
|
435
|
+
init_promises.push(managers[j].do('init'));
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
await Promise.all(init_promises);
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* 初始化模块
|
|
443
|
+
*/
|
|
444
|
+
Server.prototype._initAsyncMod = async function () {
|
|
445
|
+
await Promise.all([
|
|
446
|
+
this.manager.notifier.runAll('init', this.adapter, this.eventer, this.logger),
|
|
447
|
+
this.manager.sender.runAll('init', this.adapter, this.eventer, this.logger),
|
|
448
|
+
this.manager.pusher.runAll('init', this.adapter, this.eventer, this.logger)
|
|
449
|
+
]);
|
|
450
|
+
this.manager.middleware.runWait('init', this.adapter, this.eventer, this.logger);
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* 初始化资源
|
|
455
|
+
*/
|
|
456
|
+
Server.prototype._initSources = async function () {
|
|
457
|
+
// 初始化顺序 game > app > mod > middleware > notifier > sender > pusher,根据依赖关系自下而上初始化,内部并行执行
|
|
458
|
+
await this.manager.game.runAll('init', this, this.eventer, this.logger);
|
|
459
|
+
await this.manager.app.runAll('init', this, this.eventer, this.logger);
|
|
460
|
+
await this.manager.mod.runAll('init', this, this.eventer, this.logger);
|
|
461
|
+
await this._initAsyncMod();
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* 初始化
|
|
466
|
+
* @private
|
|
467
|
+
*/
|
|
468
|
+
Server.prototype._init = async function () {
|
|
469
|
+
try {
|
|
470
|
+
// 初始化工具
|
|
471
|
+
this._initTool();
|
|
472
|
+
// 初始化模块
|
|
473
|
+
this._initModules();
|
|
474
|
+
// 初始化基础设施
|
|
475
|
+
this._initBase();
|
|
476
|
+
// 初始化适配器
|
|
477
|
+
this._initAdapter();
|
|
478
|
+
// 初始化管理器
|
|
479
|
+
await this._initManager();
|
|
480
|
+
// 加载资源
|
|
481
|
+
await this._loadSources();
|
|
482
|
+
// 初始化资源
|
|
483
|
+
await this._initSources();
|
|
484
|
+
// 统一处理错误
|
|
485
|
+
this._initErrorRun();
|
|
486
|
+
} catch (error) {
|
|
487
|
+
this.log('error', '初始化过程失败:', error);
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* 启动资源
|
|
494
|
+
*/
|
|
495
|
+
Server.prototype._startSources = async function () {
|
|
496
|
+
// 启动无顺序,但需要等待所有启动完成,内部依次执行
|
|
497
|
+
await Promise.all([
|
|
498
|
+
this.manager.middleware.runAll('start'),
|
|
499
|
+
this.manager.game.runAll('start'),
|
|
500
|
+
// this.manager.zone.runAll('start'),
|
|
501
|
+
this.manager.app.runAll('start'),
|
|
502
|
+
this.manager.mod.runAll('start')
|
|
503
|
+
]);
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* 启动适配器
|
|
508
|
+
*/
|
|
509
|
+
Server.prototype._startAdapter = async function () {
|
|
510
|
+
for (var k in this.adapter) {
|
|
511
|
+
try {
|
|
512
|
+
await this.adapter[k].start();
|
|
513
|
+
} catch (error) {
|
|
514
|
+
this.log('error', '启动适配器失败:', error);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* 停止适配器
|
|
521
|
+
*/
|
|
522
|
+
Server.prototype._stopAdapter = async function () {
|
|
523
|
+
for (var k in this.adapter) {
|
|
524
|
+
try {
|
|
525
|
+
await this.adapter[k].stop();
|
|
526
|
+
} catch (error) {
|
|
527
|
+
this.log('error', '停止适配器失败:', error);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* 停止
|
|
534
|
+
*/
|
|
535
|
+
Server.prototype._stop = async function () {
|
|
536
|
+
await this._stopAdapter();
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* 启动
|
|
541
|
+
*/
|
|
542
|
+
Server.prototype._start = async function () {
|
|
543
|
+
$.sql.open();
|
|
544
|
+
$.cache.connect();
|
|
545
|
+
|
|
546
|
+
// 启动资源
|
|
547
|
+
await this._startSources();
|
|
548
|
+
|
|
549
|
+
// 启动适配器
|
|
550
|
+
await this._startAdapter();
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* 加载资源
|
|
555
|
+
*/
|
|
556
|
+
Server.prototype._loadSources = async function () {
|
|
557
|
+
// 加载无需依赖关系,所以可以同时加载,内部并行执行
|
|
558
|
+
await Promise.all([
|
|
559
|
+
this.manager.game.runAll('load'),
|
|
560
|
+
// this.manager.zone.runAll('load'),
|
|
561
|
+
this.manager.app.runAll('load'),
|
|
562
|
+
this.manager.middleware.runAll('load'),
|
|
563
|
+
this.manager.mod.runAll('load')
|
|
564
|
+
]);
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* 启动服务器
|
|
569
|
+
*/
|
|
570
|
+
Server.prototype.start = async function () {
|
|
571
|
+
try {
|
|
572
|
+
if (this.status === 'created') {
|
|
573
|
+
await this.init();
|
|
574
|
+
}
|
|
575
|
+
await this._start();
|
|
576
|
+
this.log('info', '服务器启动成功');
|
|
577
|
+
} catch (error) {
|
|
578
|
+
this.log('error', '服务器启动失败:', error);
|
|
579
|
+
throw error;
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* 初始化全局错误处理机制
|
|
585
|
+
*/
|
|
586
|
+
Server.prototype._initErrorRun = function () {
|
|
587
|
+
// 全局未捕获异常处理
|
|
588
|
+
process.on('uncaughtException', (error) => {
|
|
589
|
+
this.log('error', '全局未捕获异常:', error);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
// 全局未处理Promise拒绝处理
|
|
593
|
+
process.on('unhandledRejection', (reason) => {
|
|
594
|
+
this.log('error', '全局未处理Promise拒绝:', reason);
|
|
595
|
+
});
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
exports.Server = Server;
|
package/README.en.md
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# 服务端框架
|
|
2
|
-
|
|
3
|
-
#### Description
|
|
4
|
-
这是服务端框架,网站、游戏、小程序服务端可基于该框架进行二次开发
|
|
5
|
-
|
|
6
|
-
#### Software Architecture
|
|
7
|
-
Software architecture description
|
|
8
|
-
|
|
9
|
-
#### Installation
|
|
10
|
-
|
|
11
|
-
1. xxxx
|
|
12
|
-
2. xxxx
|
|
13
|
-
3. xxxx
|
|
14
|
-
|
|
15
|
-
#### Instructions
|
|
16
|
-
|
|
17
|
-
1. xxxx
|
|
18
|
-
2. xxxx
|
|
19
|
-
3. xxxx
|
|
20
|
-
|
|
21
|
-
#### Contribution
|
|
22
|
-
|
|
23
|
-
1. Fork the repository
|
|
24
|
-
2. Create Feat_xxx branch
|
|
25
|
-
3. Commit your code
|
|
26
|
-
4. Create Pull Request
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#### Gitee Feature
|
|
30
|
-
|
|
31
|
-
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
|
32
|
-
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
|
33
|
-
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
|
34
|
-
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
|
35
|
-
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
|
36
|
-
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
package/conf.json
DELETED