From 5c913fa2dbf0bd3ea233a032db6dc748c7320ffb Mon Sep 17 00:00:00 2001 From: MiniDay <372403923@qq.com> Date: Wed, 24 Apr 2024 14:12:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20singleton-server-i?= =?UTF-8?q?d=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ball-bukkit/src/main/resources/config.yml | 7 +++++++ ball-bungee/src/main/resources/config.yml | 4 ++++ .../cn/hamster3/mc/plugin/ball/common/api/BallAPI.java | 2 +- .../hamster3/mc/plugin/ball/common/config/BallConfig.java | 3 +++ ball-velocity/src/main/resources/config.yml | 4 ++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ball-bukkit/src/main/resources/config.yml b/ball-bukkit/src/main/resources/config.yml index 780aedb..61c4411 100644 --- a/ball-bukkit/src/main/resources/config.yml +++ b/ball-bukkit/src/main/resources/config.yml @@ -1,6 +1,13 @@ # 是否允许在控制台输出调试信息 debug: false +# 是否启用服务器 ID 单例模式 +# 启用后,当一个服务器启动后将会占用 服务器唯一识别码 +# 其他使用相同 服务器唯一识别码 的服务器将无法启动 +# 测试端中可关闭该功能 +# 推荐在正式服中开启该功能以防止服务器 ID 重复 +singleton-server-id: false + # 频道名前缀 # 使用这个配置选项可以划分子服消息通信分组 # 只有在同一个频道名的子服才能互相通信 diff --git a/ball-bungee/src/main/resources/config.yml b/ball-bungee/src/main/resources/config.yml index cdee594..907f391 100644 --- a/ball-bungee/src/main/resources/config.yml +++ b/ball-bungee/src/main/resources/config.yml @@ -1,6 +1,10 @@ # 是否允许在控制台输出调试信息 debug: false +# 是否启用服务器 ID 单例模式 +# 启用后,服务器唯一识别码 相同的服务器将无法启动 +singleton-server-id: false + # 频道名前缀 # 使用这个配置选项可以划分子服消息通信分组 # 只有在同一个频道名的子服才能互相通信 diff --git a/ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java b/ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java index 6924d39..df2c5af 100644 --- a/ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java +++ b/ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java @@ -108,7 +108,7 @@ public abstract class BallAPI { protected void enable() throws SQLException, InterruptedException { try (Jedis jedis = CoreAPI.getInstance().getJedisPool().getResource()) { String key = "HamsterBall:ServerInfo:" + localServerInfo.getId(); - if (jedis.exists(key)) { + if (jedis.exists(key) && ballConfig.isSingletonServerID()) { throw new IllegalStateException("已经有一个服务器占用了该 ID"); } jedis.hset(key, "id", localServerInfo.getId()); diff --git a/ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/config/BallConfig.java b/ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/config/BallConfig.java index da31e33..7e61829 100644 --- a/ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/config/BallConfig.java +++ b/ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/config/BallConfig.java @@ -11,13 +11,16 @@ import java.util.List; @AllArgsConstructor public class BallConfig { private boolean debug; + private boolean singletonServerID; @NotNull private String channelPrefix; private boolean gameServerUpdatePlayerInfo; + @NotNull private List loadPlayerInfoFilter; public BallConfig(@NotNull ConfigSection config) { debug = config.getBoolean("debug", false); + singletonServerID = config.getBoolean("singleton-server-id", false); channelPrefix = config.getString("channel-prefix", ""); channelPrefix = channelPrefix.isEmpty() ? channelPrefix : channelPrefix + ":"; gameServerUpdatePlayerInfo = config.getBoolean("game-server-update-player-info", false); diff --git a/ball-velocity/src/main/resources/config.yml b/ball-velocity/src/main/resources/config.yml index ac69770..2f15707 100644 --- a/ball-velocity/src/main/resources/config.yml +++ b/ball-velocity/src/main/resources/config.yml @@ -1,6 +1,10 @@ # 是否允许在控制台输出调试信息 debug: false +# 是否启用服务器 ID 单例模式 +# 启用后,服务器唯一识别码 相同的服务器将无法启动 +singleton-server-id: false + # 频道名前缀 # 使用这个配置选项可以划分子服消息通信分组 # 只有在同一个频道名的子服才能互相通信