@baipiaodajun/mcbots 1.2.4 → 1.2.6

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 (3) hide show
  1. package/README.md +4 -3
  2. package/package.json +2 -2
  3. package/server.js +39 -11
package/README.md CHANGED
@@ -52,7 +52,7 @@ npm install && npm run start
52
52
  ```
53
53
  docker run -d \
54
54
  --name mcbot \
55
- -e SERVERS_JSON='[{"host":"mc-yy.io","port":25565,"minBots":1,"maxBots":3,"version":"1.20.1"},{"host":"mc-xx.io","port":25565,"minBots":1,"maxBots":3,"version":"1.20.1"}]' \
55
+ -e SERVERS_JSON='[{"host":"mc-yy.io","port":25565,"minBots":1,"maxBots":3},{"host":"mc-xx.io","port":25565,"minBots":1,"maxBots":3}]' \
56
56
  -p 3000:3000 \
57
57
  mingli2038/mcbot:latest
58
58
  ```
@@ -61,9 +61,10 @@ docker run -d \
61
61
 
62
62
  - 新版本引入了 **热更新功能:`SERVER_JSON`**
63
63
  - 目前该功能处于 **实验状态**,可能会导致一些 **意料之外的问题**
64
- - 如果需要稳定使用,推荐继续使用 **1.1 版本**
64
+ - ~~如果需要稳定使用,推荐继续使用 **1.1 版本**~~
65
65
  - **1.2.4** 优化机器人断开逻辑,避免幽灵机器人出现。
66
-
66
+ - **1.2.5** 根据群友建议加入服务备注,以便能够区分是哪一家服务器,因为一些服务器没有域名。
67
+ - **1.2.6** mineflayer更新到4.35,得益于此,现在可以直连1.21.8-1.21.11的MC离线模式服务器而不需要通过兼容版本插件,mc版本|最大机器人数|最小机器人数变成可选项,有默认值,mc版本使用上游自动识别功能。
67
68
  ---
68
69
 
69
70
  ### 页面更新
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baipiaodajun/mcbots",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "Minecraft bot and status dashboard for multi-server management",
5
5
  "main": "server.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "cookie-parser": "^1.4.7",
18
18
  "express": "^4.18.2",
19
- "mineflayer": "^4.33.0",
19
+ "mineflayer": "4.35",
20
20
  "node-fetch": "^2.7.0"
21
21
  },
22
22
  "files": [
package/server.js CHANGED
@@ -42,6 +42,7 @@ if (fs.existsSync(CONFIG_FILE)) {
42
42
  SERVERS.length = 0;
43
43
  SERVERS.push(...fileConfig);
44
44
  console.log(`从 ${CONFIG_FILE} 加载服务器配置成功,数量: ${SERVERS.length} 项`);
45
+ debugPrint(`配置为:${JSON.stringify(SERVERS, null, 2)}`);
45
46
  loaded = true;
46
47
  } else {
47
48
  console.warn('配置文件内容不是数组,已忽略');
@@ -206,12 +207,13 @@ class HotUpdateAuth {
206
207
  const hotUpdateAuth =new HotUpdateAuth();
207
208
  // Minecraft机器人管理器
208
209
  class MinecraftBotManager {
209
- constructor(host, port, minBots, maxBots, version) {
210
+ constructor(host, port, minBots, maxBots, version,note) {
210
211
  this.host = host;
211
212
  this.port = port;
212
- this.minBots = minBots;
213
- this.maxBots = maxBots;
214
- this.version = version || "1.20.1";
213
+ this.minBots = minBots || 1;
214
+ this.maxBots = maxBots || 3;
215
+ this.note=note;
216
+ this.version = version || false;
215
217
  this.currentBots = 0;
216
218
  this.activeBots = new Map();
217
219
  this.pendingReconnect = new Set(); // 等待重连的机器人名字(已断开但优先重用名字)
@@ -231,8 +233,9 @@ class MinecraftBotManager {
231
233
  globalServerStatus.servers.set(`${host}:${port}`, {
232
234
  host: host,
233
235
  port: port,
234
- minBots: minBots,
235
- maxBots: maxBots,
236
+ minBots: this.minBots,
237
+ maxBots: this.maxBots,
238
+ note:note,
236
239
  currentBots: 0,
237
240
  activeBots: [],
238
241
  lastUpdate: Date.now(),
@@ -825,14 +828,28 @@ class StatusServer {
825
828
  .server-header {
826
829
  display: flex;
827
830
  justify-content: space-between;
828
- align-items: center;
829
831
  margin-bottom: 15px;
832
+ gap: 8px;
833
+ }
834
+ .server-note {
835
+ font-size: 0.85rem;
836
+ font-weight: 600;
837
+ display: inline-block;
838
+ padding: 6px 12px;
839
+ background: #e6f0ff;
840
+ color: #1e40af;
841
+ border-radius: 20px;
842
+ border: 1px solid #93c5fd;
843
+ flex-shrink: 0;
844
+ white-space: nowrap;
845
+ margin-right: 8px;
830
846
  }
831
-
832
847
  .server-title {
833
848
  font-size: 1.2rem;
834
849
  font-weight: 600;
835
850
  color: #2d3748;
851
+ min-width: 0;
852
+ flex: 1;
836
853
  }
837
854
 
838
855
  .status-badge {
@@ -841,6 +858,7 @@ class StatusServer {
841
858
  font-size: 0.85rem;
842
859
  font-weight: 600;
843
860
  text-transform: uppercase;
861
+ flex-shrink: 0;
844
862
  }
845
863
 
846
864
  .status-healthy {
@@ -1030,9 +1048,9 @@ class StatusServer {
1030
1048
  <div class="server-card ${server.status}">
1031
1049
  <div class="server-header">
1032
1050
  <div class="server-title">${server.host}:${server.port}</div>
1051
+ ${server.note ? `<div class="server-note">${server.note}</div>` : "" }
1033
1052
  <div class="status-badge ${statusClass}">${statusText}</div>
1034
1053
  </div>
1035
-
1036
1054
  <div class="server-info">
1037
1055
  <div class="info-item">
1038
1056
  <div class="info-label">机器人数量</div>
@@ -1584,7 +1602,8 @@ async function initialize() {
1584
1602
  server.port,
1585
1603
  server.minBots,
1586
1604
  server.maxBots,
1587
- server.version
1605
+ server.version,
1606
+ server.note ?? ""
1588
1607
  )
1589
1608
  );
1590
1609
 
@@ -1639,6 +1658,14 @@ async function hotUpdateServers() {
1639
1658
  // 完全一致:保留,并从 newServerMap 删除(避免重复创建)
1640
1659
  newServerMap.delete(key);
1641
1660
  // 状态保持最新(可选:刷新 lastUpdate)
1661
+
1662
+ //备注处理,不重建机器人,只是更新备注
1663
+ if (manager.note !== newConfig.note) {
1664
+ manager.note = newConfig.note;
1665
+ const status = globalServerStatus.servers.get(key);
1666
+ if (status) status.note = newConfig.note;
1667
+ }
1668
+
1642
1669
  const status = globalServerStatus.servers.get(key);
1643
1670
  if (status) status.lastUpdate = Date.now();
1644
1671
  } else {
@@ -1675,7 +1702,8 @@ async function hotUpdateServers() {
1675
1702
  config.port,
1676
1703
  config.minBots,
1677
1704
  config.maxBots,
1678
- config.version
1705
+ config.version,
1706
+ config.note
1679
1707
  );
1680
1708
  newManager.startMonitoring();
1681
1709
  botManagers.push(newManager);