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.
- 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 -80
- 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 -696
- package/com/mqtt/index.js +0 -1017
- package/com/mqtt/index.test.js +0 -503
- package/com/mqtt/mm_mqtt.js +0 -446
- 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 -1283
- 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 -385
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -710
- 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 -297
- 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/store/sql.js +0 -1488
- 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 -595
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
package/core/channel/matcher.js
DELETED
|
@@ -1,585 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
Drive
|
|
3
|
-
} = require('mm_machine');
|
|
4
|
-
const {
|
|
5
|
-
idGen
|
|
6
|
-
} = require('../../ulits/id_gen.js');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 匹配器
|
|
10
|
-
* 管理匹配池并实现基于等级和等待时间的匹配算法
|
|
11
|
-
*/
|
|
12
|
-
class Matcher extends Drive {
|
|
13
|
-
static config = {
|
|
14
|
-
name: 'matcher',
|
|
15
|
-
title: '匹配器',
|
|
16
|
-
wait_time: 120000,
|
|
17
|
-
lv_range_init: 5,
|
|
18
|
-
lv_range_max: 20,
|
|
19
|
-
lv_expand_int: 10000,
|
|
20
|
-
match_interval: 1000,
|
|
21
|
-
team_sizes: {
|
|
22
|
-
'1v1': 1,
|
|
23
|
-
'3v3': 3,
|
|
24
|
-
'5v5': 5
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 构造函数
|
|
30
|
-
* @param {object} config 配置参数
|
|
31
|
-
*/
|
|
32
|
-
constructor(config) {
|
|
33
|
-
super({
|
|
34
|
-
...Matcher.config,
|
|
35
|
-
...config
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
this._channel = null;
|
|
39
|
-
this._match_timer = null;
|
|
40
|
-
|
|
41
|
-
this._pools = new Map();
|
|
42
|
-
this._player_pool = new Map();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 获取模板目录
|
|
48
|
-
* @returns {string} 模板目录
|
|
49
|
-
*/
|
|
50
|
-
Matcher.prototype.getTplDir = function() {
|
|
51
|
-
return __dirname;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 初始化匹配器
|
|
56
|
-
* @param {object} channel 游戏频道
|
|
57
|
-
*/
|
|
58
|
-
Matcher.prototype._initCore = async function (channel) {
|
|
59
|
-
this._channel = channel;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 启动匹配定时器
|
|
64
|
-
*/
|
|
65
|
-
Matcher.prototype._start = function () {
|
|
66
|
-
this._match_timer = setInterval(() => {
|
|
67
|
-
this._doMatch();
|
|
68
|
-
}, this.config.match_interval);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 停止匹配定时器
|
|
73
|
-
*/
|
|
74
|
-
Matcher.prototype._stop = function () {
|
|
75
|
-
if (this._match_timer) {
|
|
76
|
-
clearInterval(this._match_timer);
|
|
77
|
-
this._match_timer = null;
|
|
78
|
-
this.log('debug', '匹配定时器已停止');
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 执行匹配
|
|
84
|
-
*/
|
|
85
|
-
Matcher.prototype._doMatch = function () {
|
|
86
|
-
this.updateLevelRanges();
|
|
87
|
-
this.cleanTimeout();
|
|
88
|
-
|
|
89
|
-
var modes = ['rank', 'casual'];
|
|
90
|
-
var formats = ['1v1', '3v3', '5v5'];
|
|
91
|
-
var team_sizes = [1, 2, 3, 5];
|
|
92
|
-
|
|
93
|
-
for (var m = 0; m < modes.length; m++) {
|
|
94
|
-
for (var f = 0; f < formats.length; f++) {
|
|
95
|
-
for (var t = 0; t < team_sizes.length; t++) {
|
|
96
|
-
this._matchPool(modes[m], formats[f], team_sizes[t]);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* 匹配指定池
|
|
104
|
-
* @param {string} mode 游戏模式
|
|
105
|
-
* @param {string} format 比赛格式
|
|
106
|
-
* @param {number} team_size 队伍人数
|
|
107
|
-
*/
|
|
108
|
-
Matcher.prototype._matchPool = function (mode, format, team_size) {
|
|
109
|
-
var pool = this.getPool(mode, format, team_size);
|
|
110
|
-
if (pool.length < 2) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
var required_count = this._getRequiredCount(format);
|
|
115
|
-
var matched_groups = this._findMatchGroups(pool, required_count);
|
|
116
|
-
|
|
117
|
-
for (var i = 0; i < matched_groups.length; i++) {
|
|
118
|
-
var group = matched_groups[i];
|
|
119
|
-
this._create(group, mode, format);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 获取需要的玩家数量
|
|
125
|
-
* @param {string} format 比赛格式
|
|
126
|
-
* @returns {number} 玩家数量
|
|
127
|
-
*/
|
|
128
|
-
Matcher.prototype._getRequiredCount = function (format) {
|
|
129
|
-
var counts = {
|
|
130
|
-
'1v1': 2,
|
|
131
|
-
'3v3': 6,
|
|
132
|
-
'5v5': 10
|
|
133
|
-
};
|
|
134
|
-
return counts[format] || 10;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* 查找匹配组
|
|
139
|
-
* @param {Array} pool 匹配池
|
|
140
|
-
* @param {number} required_count 需要的玩家数量
|
|
141
|
-
* @returns {Array} 匹配组列表
|
|
142
|
-
*/
|
|
143
|
-
Matcher.prototype._findMatchGroups = function (pool, required_count) {
|
|
144
|
-
var groups = [];
|
|
145
|
-
var used = new Set();
|
|
146
|
-
var sorted_pool = this._sortByWaitTime(pool);
|
|
147
|
-
|
|
148
|
-
for (var i = 0; i < sorted_pool.length; i++) {
|
|
149
|
-
var entry = sorted_pool[i];
|
|
150
|
-
if (used.has(entry.player_id)) {
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
var group = this._buildGroup(entry, sorted_pool, used, required_count);
|
|
155
|
-
if (group && group.length === required_count) {
|
|
156
|
-
groups.push(group);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return groups;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* 按等待时间排序(等待久的优先)
|
|
165
|
-
* @param {Array} pool 匹配池
|
|
166
|
-
* @returns {Array} 排序后的匹配池
|
|
167
|
-
*/
|
|
168
|
-
Matcher.prototype._sortByWaitTime = function (pool) {
|
|
169
|
-
return pool.slice().sort((a, b) => {
|
|
170
|
-
return a.join_time - b.join_time;
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 构建匹配组
|
|
176
|
-
* @param {object} first_entry 第一个玩家
|
|
177
|
-
* @param {Array} pool 匹配池
|
|
178
|
-
* @param {Set} used 已使用的玩家
|
|
179
|
-
* @param {number} required_count 需要的玩家数量
|
|
180
|
-
* @returns {Array|null} 匹配组
|
|
181
|
-
*/
|
|
182
|
-
Matcher.prototype._buildGroup = function (first_entry, pool, used, required_count) {
|
|
183
|
-
var group = [first_entry];
|
|
184
|
-
used.add(first_entry.player_id);
|
|
185
|
-
|
|
186
|
-
var member_count = first_entry.team_members.length;
|
|
187
|
-
|
|
188
|
-
for (var i = 0; i < pool.length && member_count < required_count; i++) {
|
|
189
|
-
var entry = pool[i];
|
|
190
|
-
if (used.has(entry.player_id)) {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (this._can(first_entry, entry)) {
|
|
195
|
-
if (member_count + entry.team_members.length <= required_count) {
|
|
196
|
-
group.push(entry);
|
|
197
|
-
used.add(entry.player_id);
|
|
198
|
-
member_count += entry.team_members.length;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (member_count === required_count) {
|
|
204
|
-
return group;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
for (var j = 0; j < group.length; j++) {
|
|
208
|
-
used.delete(group[j].player_id);
|
|
209
|
-
}
|
|
210
|
-
return null;
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* 判断两个玩家是否可以匹配
|
|
215
|
-
* @param {object} entry_a 玩家A
|
|
216
|
-
* @param {object} entry_b 玩家B
|
|
217
|
-
* @returns {boolean} 是否可以匹配
|
|
218
|
-
*/
|
|
219
|
-
Matcher.prototype._can = function (entry_a, entry_b) {
|
|
220
|
-
var level_diff = Math.abs(entry_a.level - entry_b.level);
|
|
221
|
-
var min_range = Math.min(entry_a.lv_range, entry_b.lv_range);
|
|
222
|
-
|
|
223
|
-
return level_diff <= min_range;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* 创建匹配
|
|
228
|
-
* @param {Array} group 匹配组
|
|
229
|
-
* @param {string} mode 游戏模式
|
|
230
|
-
* @param {string} format 比赛格式
|
|
231
|
-
* @returns {object} 匹配结果
|
|
232
|
-
*/
|
|
233
|
-
Matcher.prototype._create = function (group, mode, format) {
|
|
234
|
-
var match_id = idGen.genId('match');
|
|
235
|
-
var all_players = [];
|
|
236
|
-
|
|
237
|
-
for (var i = 0; i < group.length; i++) {
|
|
238
|
-
var entry = group[i];
|
|
239
|
-
all_players = all_players.concat(entry.team_members);
|
|
240
|
-
this.leave(entry.player_id);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
var teams = this._splitTeams(all_players, format);
|
|
244
|
-
|
|
245
|
-
var match_ret = {
|
|
246
|
-
match_id: match_id,
|
|
247
|
-
mode: mode,
|
|
248
|
-
format: format,
|
|
249
|
-
teams: teams,
|
|
250
|
-
players: all_players,
|
|
251
|
-
timestamp: Date.now()
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
this.emitEvent('match_success', match_ret);
|
|
255
|
-
|
|
256
|
-
this.log('info', `匹配成功: ${match_id}, 模式: ${mode}, 格式: ${format}, 玩家数: ${all_players.length}`);
|
|
257
|
-
|
|
258
|
-
return match_ret;
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* 分割队伍
|
|
263
|
-
* @param {Array} players 玩家列表
|
|
264
|
-
* @param {string} format 比赛格式
|
|
265
|
-
* @returns {object} 队伍配置
|
|
266
|
-
*/
|
|
267
|
-
Matcher.prototype._splitTeams = function (players, format) {
|
|
268
|
-
var counts = {
|
|
269
|
-
'1v1': 1,
|
|
270
|
-
'3v3': 3,
|
|
271
|
-
'5v5': 5
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
var team_size = counts[format] || 5;
|
|
275
|
-
|
|
276
|
-
return {
|
|
277
|
-
team_a: players.slice(0, team_size),
|
|
278
|
-
team_b: players.slice(team_size),
|
|
279
|
-
format: format
|
|
280
|
-
};
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* 玩家加入匹配池
|
|
285
|
-
* @param {string} player_id 玩家ID
|
|
286
|
-
* @param {object} options 匹配选项
|
|
287
|
-
* @returns {boolean} 是否成功加入
|
|
288
|
-
*/
|
|
289
|
-
Matcher.prototype.join = function (player_id, options = {}) {
|
|
290
|
-
if (typeof player_id !== 'string') {
|
|
291
|
-
throw new TypeError('玩家ID必须是字符串');
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
var mode = options.mode || 'rank';
|
|
295
|
-
var format = options.format || '5v5';
|
|
296
|
-
var team_size = options.team_size || 1;
|
|
297
|
-
var team_members = options.team_members || [player_id];
|
|
298
|
-
|
|
299
|
-
if (this._player_pool.has(player_id)) {
|
|
300
|
-
throw new Error(`玩家 ${player_id} 已在匹配池中`);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
var player = this._channel.getPlayer(player_id);
|
|
304
|
-
if (!player) {
|
|
305
|
-
throw new Error(`玩家 ${player_id} 不存在`);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
var pool_key = this._getPoolKey(mode, format, team_size);
|
|
309
|
-
var pool = this._getOrCreatePool(pool_key);
|
|
310
|
-
|
|
311
|
-
var entry = this._createEntry(player_id, player, team_members, team_size, mode, format);
|
|
312
|
-
|
|
313
|
-
pool.push(entry);
|
|
314
|
-
this._player_pool.set(player_id, pool_key);
|
|
315
|
-
|
|
316
|
-
this._emitJoinEvent(player_id, mode, format, team_size, entry.join_time);
|
|
317
|
-
|
|
318
|
-
this.log('debug', `玩家 ${player_id} 加入匹配池 ${pool_key}`);
|
|
319
|
-
return true;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* 玩家离开匹配池
|
|
324
|
-
* @param {string} player_id 玩家ID
|
|
325
|
-
* @returns {boolean} 是否成功离开
|
|
326
|
-
*/
|
|
327
|
-
Matcher.prototype.leave = function (player_id) {
|
|
328
|
-
if (typeof player_id !== 'string') {
|
|
329
|
-
throw new TypeError('玩家ID必须是字符串');
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
var pool_key = this._player_pool.get(player_id);
|
|
333
|
-
if (!pool_key) {
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
var pool = this._pools.get(pool_key);
|
|
338
|
-
if (!pool) {
|
|
339
|
-
this._player_pool.delete(player_id);
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
for (var i = pool.length - 1; i >= 0; i--) {
|
|
344
|
-
if (pool[i].player_id === player_id) {
|
|
345
|
-
pool.splice(i, 1);
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
this._player_pool.delete(player_id);
|
|
351
|
-
|
|
352
|
-
this.emitEvent('player_leave_pool', {
|
|
353
|
-
player_id: player_id,
|
|
354
|
-
timestamp: Date.now()
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
this.log('debug', `玩家 ${player_id} 离开匹配池`);
|
|
358
|
-
return true;
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* 检查玩家是否在匹配池中
|
|
363
|
-
* @param {string} player_id 玩家ID
|
|
364
|
-
* @returns {boolean} 是否在匹配池中
|
|
365
|
-
*/
|
|
366
|
-
Matcher.prototype.has = function (player_id) {
|
|
367
|
-
return this._player_pool.has(player_id);
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* 获取匹配池键
|
|
372
|
-
* @param {string} mode 游戏模式
|
|
373
|
-
* @param {string} format 比赛格式
|
|
374
|
-
* @param {number} team_size 队伍人数
|
|
375
|
-
* @returns {string} 匹配池键
|
|
376
|
-
*/
|
|
377
|
-
Matcher.prototype._getPoolKey = function (mode, format, team_size) {
|
|
378
|
-
return `${mode}_${format}_${team_size}`;
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* 获取或创建匹配池
|
|
383
|
-
* @param {string} pool_key 池键名
|
|
384
|
-
* @returns {Array} 匹配池
|
|
385
|
-
*/
|
|
386
|
-
Matcher.prototype._getOrCreatePool = function (pool_key) {
|
|
387
|
-
if (!this._pools.has(pool_key)) {
|
|
388
|
-
this._pools.set(pool_key, []);
|
|
389
|
-
}
|
|
390
|
-
return this._pools.get(pool_key);
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* 创建匹配条目
|
|
395
|
-
* @param {string} player_id 玩家ID
|
|
396
|
-
* @param {object} player 玩家对象
|
|
397
|
-
* @param {Array} members 队伍成员
|
|
398
|
-
* @param {number} team_size 队伍人数
|
|
399
|
-
* @param {string} mode 游戏模式
|
|
400
|
-
* @param {string} format 比赛格式
|
|
401
|
-
* @returns {object} 匹配条目
|
|
402
|
-
*/
|
|
403
|
-
Matcher.prototype._createEntry = function (player_id, player, members, team_size, mode, format) {
|
|
404
|
-
return {
|
|
405
|
-
player_id: player_id,
|
|
406
|
-
team_members: members,
|
|
407
|
-
team_size: team_size,
|
|
408
|
-
level: player.level || 0,
|
|
409
|
-
join_time: Date.now(),
|
|
410
|
-
lv_range: this.config.lv_range_init,
|
|
411
|
-
mode: mode,
|
|
412
|
-
format: format
|
|
413
|
-
};
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* 发送加入事件
|
|
418
|
-
* @param {string} player_id 玩家ID
|
|
419
|
-
* @param {string} mode 游戏模式
|
|
420
|
-
* @param {string} format 比赛格式
|
|
421
|
-
* @param {number} team_size 队伍人数
|
|
422
|
-
* @param {number} timestamp 时间戳
|
|
423
|
-
*/
|
|
424
|
-
Matcher.prototype._emitJoinEvent = function (player_id, mode, format, team_size, timestamp) {
|
|
425
|
-
this.emitEvent('player_join_pool', {
|
|
426
|
-
player_id: player_id,
|
|
427
|
-
mode: mode,
|
|
428
|
-
format: format,
|
|
429
|
-
team_size: team_size,
|
|
430
|
-
timestamp: timestamp
|
|
431
|
-
});
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
/**
|
|
435
|
-
* 获取指定匹配池
|
|
436
|
-
* @param {string} mode 游戏模式
|
|
437
|
-
* @param {string} format 比赛格式
|
|
438
|
-
* @param {number} team_size 队伍人数
|
|
439
|
-
* @returns {Array} 匹配池
|
|
440
|
-
*/
|
|
441
|
-
Matcher.prototype.getPool = function (mode, format, team_size) {
|
|
442
|
-
var pool_key = this._getPoolKey(mode, format, team_size);
|
|
443
|
-
return this._pools.get(pool_key) || [];
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* 获取匹配池大小
|
|
448
|
-
* @param {string} mode 游戏模式
|
|
449
|
-
* @param {string} format 比赛格式
|
|
450
|
-
* @param {number} team_size 队伍人数
|
|
451
|
-
* @returns {number} 匹配池大小
|
|
452
|
-
*/
|
|
453
|
-
Matcher.prototype.getPoolSize = function (mode, format, team_size) {
|
|
454
|
-
return this.getPool(mode, format, team_size).length;
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
* 获取总等待人数
|
|
459
|
-
* @returns {number} 总等待人数
|
|
460
|
-
*/
|
|
461
|
-
Matcher.prototype.getTotalWaiting = function () {
|
|
462
|
-
return this._player_pool.size;
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* 更新玩家等级范围
|
|
467
|
-
* 根据等待时间扩大匹配范围
|
|
468
|
-
*/
|
|
469
|
-
Matcher.prototype.updateLevelRanges = function () {
|
|
470
|
-
var now = Date.now();
|
|
471
|
-
var expand_int = this.config.lv_expand_int;
|
|
472
|
-
var max_range = this.config.lv_range_max;
|
|
473
|
-
var self = this;
|
|
474
|
-
|
|
475
|
-
this._pools.forEach((pool) => {
|
|
476
|
-
for (var i = 0; i < pool.length; i++) {
|
|
477
|
-
var entry = pool[i];
|
|
478
|
-
var wait_time = now - entry.join_time;
|
|
479
|
-
var expand_count = Math.floor(wait_time / expand_int);
|
|
480
|
-
var new_range = self.config.lv_range_init + expand_count;
|
|
481
|
-
|
|
482
|
-
if (new_range > max_range) {
|
|
483
|
-
entry.lv_range = max_range;
|
|
484
|
-
} else {
|
|
485
|
-
entry.lv_range = new_range;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* 清理超时玩家
|
|
493
|
-
*/
|
|
494
|
-
Matcher.prototype.cleanTimeout = function () {
|
|
495
|
-
var now = Date.now();
|
|
496
|
-
var max_wait = this.config.wait_time;
|
|
497
|
-
|
|
498
|
-
this._pools.forEach((pool, pool_key) => {
|
|
499
|
-
for (var i = pool.length - 1; i >= 0; i--) {
|
|
500
|
-
var entry = pool[i];
|
|
501
|
-
if (now - entry.join_time > max_wait) {
|
|
502
|
-
pool.splice(i, 1);
|
|
503
|
-
this._player_pool.delete(entry.player_id);
|
|
504
|
-
|
|
505
|
-
this.emitEvent('match_timeout', {
|
|
506
|
-
player_id: entry.player_id,
|
|
507
|
-
wait_time: max_wait,
|
|
508
|
-
timestamp: now
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
this.log('debug', `玩家 ${entry.player_id} 匹配超时`);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* 清空匹配池
|
|
519
|
-
*/
|
|
520
|
-
Matcher.prototype.clear = function () {
|
|
521
|
-
this._pools.clear();
|
|
522
|
-
this._player_pool.clear();
|
|
523
|
-
this.log('info', '匹配池已清空');
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* 获取匹配状态
|
|
528
|
-
* @param {string} player_id 玩家ID
|
|
529
|
-
* @returns {object|null} 匹配状态
|
|
530
|
-
*/
|
|
531
|
-
Matcher.prototype.getMatchStatus = function (player_id) {
|
|
532
|
-
if (!this.has(player_id)) {
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
var entry = this._findPlayerEntry(player_id);
|
|
537
|
-
if (!entry) {
|
|
538
|
-
return null;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
var now = Date.now();
|
|
542
|
-
var wait_time = now - entry.join_time;
|
|
543
|
-
|
|
544
|
-
return {
|
|
545
|
-
player_id: player_id,
|
|
546
|
-
mode: entry.mode,
|
|
547
|
-
format: entry.format,
|
|
548
|
-
team_size: entry.team_size,
|
|
549
|
-
level: entry.level,
|
|
550
|
-
lv_range: entry.lv_range,
|
|
551
|
-
wait_time: wait_time,
|
|
552
|
-
pool_size: this.getPoolSize(entry.mode, entry.format, entry.team_size)
|
|
553
|
-
};
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
/**
|
|
557
|
-
* 查找玩家匹配条目
|
|
558
|
-
* @param {string} player_id 玩家ID
|
|
559
|
-
* @returns {object|null} 匹配条目
|
|
560
|
-
*/
|
|
561
|
-
Matcher.prototype._findPlayerEntry = function (player_id) {
|
|
562
|
-
var found = null;
|
|
563
|
-
|
|
564
|
-
this._pools.forEach((pool) => {
|
|
565
|
-
for (var i = 0; i < pool.length; i++) {
|
|
566
|
-
if (pool[i].player_id === player_id) {
|
|
567
|
-
found = pool[i];
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
return found;
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* 停止匹配器
|
|
578
|
-
*/
|
|
579
|
-
Matcher.prototype.stop = function () {
|
|
580
|
-
this._stop();
|
|
581
|
-
this.clear();
|
|
582
|
-
this.log('info', '匹配器已停止');
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
exports.Matcher = Matcher;
|
package/core/com/config.tpl.json
DELETED
package/core/com/index.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
Drive
|
|
3
|
-
} = require('mm_machine');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 公共基类
|
|
7
|
-
* 负责管理公共的生命周期、资源加载和依赖管理
|
|
8
|
-
*/
|
|
9
|
-
class Com extends Drive {
|
|
10
|
-
static config = {
|
|
11
|
-
// 组件名称
|
|
12
|
-
name: 'default',
|
|
13
|
-
// 组件版本
|
|
14
|
-
version: '1.0.0',
|
|
15
|
-
// 组件标题
|
|
16
|
-
title: '公共',
|
|
17
|
-
// 组件描述
|
|
18
|
-
description: '公共基类',
|
|
19
|
-
// 作者
|
|
20
|
-
author: 'qww',
|
|
21
|
-
// 组件目录
|
|
22
|
-
dir: './com',
|
|
23
|
-
// 依赖的npm模块
|
|
24
|
-
dependencies: []
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* 构造函数
|
|
28
|
-
* @param {object} config 配置参数
|
|
29
|
-
* @param {object} parent 父对象
|
|
30
|
-
*/
|
|
31
|
-
constructor(config, parent) {
|
|
32
|
-
super({...Com.config, ...config || {}}, parent);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 获取模板目录
|
|
38
|
-
* @returns {string} 模板目录
|
|
39
|
-
*/
|
|
40
|
-
Com.prototype.getTplDir = function() {
|
|
41
|
-
return __dirname;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 初始化核心
|
|
46
|
-
* @param {object} server 服务器
|
|
47
|
-
* @param {object} eventer 事件总线
|
|
48
|
-
* @param {object} logger 日志管理器
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
Com.prototype._initCore = async function(server, eventer, logger) {
|
|
52
|
-
// 初始化依赖项
|
|
53
|
-
if (logger) {
|
|
54
|
-
this.setLogger(logger);
|
|
55
|
-
}
|
|
56
|
-
if (eventer) {
|
|
57
|
-
this.getEventer = function () {
|
|
58
|
-
return eventer;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (server) {
|
|
62
|
-
this.getServer = function () {
|
|
63
|
-
return server;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
// 初始化管理
|
|
67
|
-
await this._initManager();
|
|
68
|
-
// 加载资源
|
|
69
|
-
await this._loadSources();
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
Com.prototype._startCore = async function () {
|
|
73
|
-
// 初始化资源
|
|
74
|
-
await this._initSources();
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
exports.Com = Com;
|
package/core/com/script.tpl.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 组件基类
|
|
3
|
-
*/
|
|
4
|
-
class Component {
|
|
5
|
-
constructor() {
|
|
6
|
-
this._is_dirty = false;
|
|
7
|
-
// 使用 Proxy 代理对象,拦截属性设置操作
|
|
8
|
-
return new Proxy(this, {
|
|
9
|
-
set: function (target, prop, value) {
|
|
10
|
-
if (prop === '_is_dirty') {
|
|
11
|
-
target._is_dirty = value;
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
if (target[prop] !== value) {
|
|
15
|
-
target._is_dirty = true;
|
|
16
|
-
}
|
|
17
|
-
target[prop] = value;
|
|
18
|
-
return true;
|
|
19
|
-
},
|
|
20
|
-
get: function (target, prop) {
|
|
21
|
-
return target[prop];
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
isDirty(is_dirty) {
|
|
27
|
-
if (is_dirty !== undefined) {
|
|
28
|
-
this._is_dirty = is_dirty;
|
|
29
|
-
}
|
|
30
|
-
return this._is_dirty;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 转换为JSON字符串
|
|
36
|
-
* @returns {string} JSON字符串
|
|
37
|
-
*/
|
|
38
|
-
Component.prototype.toJson = function () {
|
|
39
|
-
return JSON.stringify(this);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
module.exports = Component;
|