From 5dd3f1209b8d78a249b7c84f4722da289307a0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=94=E6=B0=91=E5=B0=8F=E9=95=87?= <262610965@qq.com> Date: Tue, 31 Dec 2024 10:38:32 +0800 Subject: [PATCH] refactor(core): broadcastMe Added Tip: Please bind UserId before using this method, see FlowContext.bindingUserId. --- .../skeleton/core/flow/InternalAboutFlowContext.java | 10 ++++++++-- .../iohao/game/action/skeleton/i18n/MessageKey.java | 3 +++ common/common-core/src/main/resources/iohao.properties | 4 +++- .../src/main/resources/iohao_zh_CN.properties | 3 +++ .../game/bolt/broker/client/kit/UserIdSettingKit.java | 6 +++--- .../bolt/broker/core/message/BroadcastMessage.java | 1 - 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/flow/InternalAboutFlowContext.java b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/flow/InternalAboutFlowContext.java index a7877a3f4..5d8e32796 100644 --- a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/flow/InternalAboutFlowContext.java +++ b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/flow/InternalAboutFlowContext.java @@ -24,6 +24,8 @@ import com.iohao.game.action.skeleton.core.flow.attr.FlowOptionDynamic; import com.iohao.game.action.skeleton.eventbus.EventBus; import com.iohao.game.action.skeleton.eventbus.EventBusMessage; +import com.iohao.game.action.skeleton.i18n.Bundle; +import com.iohao.game.action.skeleton.i18n.MessageKey; import com.iohao.game.action.skeleton.kit.ExecutorSelectKit; import com.iohao.game.action.skeleton.protocol.HeadMetadata; import com.iohao.game.action.skeleton.protocol.RequestMessage; @@ -598,6 +600,10 @@ default void broadcastMe(CmdInfo cmdInfo, Object bizData) { */ default void broadcastMe(ResponseMessage responseMessage) { var userId = this.getUserId(); + if (userId == 0) { + ThrowKit.ofRuntimeException(Bundle.getMessage(MessageKey.bindingUserId)); + } + this.broadcast(responseMessage, userId); } @@ -1712,7 +1718,7 @@ default SettingUserIdResult bindingUserIdAndGetResult(final long userId) { * @param userId userId * @return true:login success * @since 21.19 - * @deprecated see {@link this#bindingUserId(long)} + * @deprecated see {@link #bindingUserId(long)} */ @Deprecated default boolean setUserId(long userId) { @@ -1725,7 +1731,7 @@ default boolean setUserId(long userId) { * @param userId userId * @return result * @since 21.19 - * @deprecated see {@link this#bindingUserIdAndGetResult(long)} + * @deprecated see {@link #bindingUserIdAndGetResult(long)} */ @Deprecated default SettingUserIdResult setUserIdAndGetResult(final long userId) { diff --git a/common/common-core/src/main/java/com/iohao/game/action/skeleton/i18n/MessageKey.java b/common/common-core/src/main/java/com/iohao/game/action/skeleton/i18n/MessageKey.java index a551a85c6..b0012b71a 100644 --- a/common/common-core/src/main/java/com/iohao/game/action/skeleton/i18n/MessageKey.java +++ b/common/common-core/src/main/java/com/iohao/game/action/skeleton/i18n/MessageKey.java @@ -81,4 +81,7 @@ public interface MessageKey { /* see DefaultUserHook.java */ String userHookInto = "userHookInto"; String userHookQuit = "userHookQuit"; + + /* see InternalAboutFlowContext.java */ + String bindingUserId = "bindingUserId"; } diff --git a/common/common-core/src/main/resources/iohao.properties b/common/common-core/src/main/resources/iohao.properties index 0f36ad222..536023024 100644 --- a/common/common-core/src/main/resources/iohao.properties +++ b/common/common-core/src/main/resources/iohao.properties @@ -47,4 +47,6 @@ textDocumentBroadcast=Broadcast textDocumentErrorCodeTitle=Error Code # see DefaultUserHook userHookInto=[PlayerOnline] CountOnline -userHookQuit=[PlayerOffline] CountOnline \ No newline at end of file +userHookQuit=[PlayerOffline] CountOnline +# see InternalAboutFlowContext.java +bindingUserId=Please binding UserId before using this method. see FlowContext.bindingUserId. diff --git a/common/common-core/src/main/resources/iohao_zh_CN.properties b/common/common-core/src/main/resources/iohao_zh_CN.properties index f0a3cf4f3..4a0952522 100644 --- a/common/common-core/src/main/resources/iohao_zh_CN.properties +++ b/common/common-core/src/main/resources/iohao_zh_CN.properties @@ -48,3 +48,6 @@ textDocumentErrorCodeTitle=错误码 # see DefaultUserHook userHookInto=[玩家上线] 在线数量 userHookQuit=[玩家下线] 在线数量 +# see InternalAboutFlowContext.java +bindingUserId=请登录后使用该方法. see FlowContext.bindingUserId. + diff --git a/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/client/kit/UserIdSettingKit.java b/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/client/kit/UserIdSettingKit.java index a4285ac69..e2843eca4 100644 --- a/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/client/kit/UserIdSettingKit.java +++ b/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/client/kit/UserIdSettingKit.java @@ -43,17 +43,17 @@ public class UserIdSettingKit { * @param flowContext 业务框架 flow上下文 * @param userId 一般从数据库中获取 * @return true 变更成功 - * @deprecated Please use {@link FlowContext#setUserId(long)} or {@link FlowContext#setUserIdAndGetResult(long)} + * @deprecated see {@link FlowContext#bindingUserId(long)} */ @Deprecated public boolean settingUserId(FlowContext flowContext, long userId) { - var result = flowContext.setUserIdAndGetResult(userId); + var result = flowContext.bindingUserIdAndGetResult(userId); if (!result.success()) { Exception exception = result.exception(); log.error(exception.getMessage(), exception); } - + return result.success(); } } diff --git a/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/core/message/BroadcastMessage.java b/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/core/message/BroadcastMessage.java index 949873b1f..e160be338 100644 --- a/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/core/message/BroadcastMessage.java +++ b/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/core/message/BroadcastMessage.java @@ -49,5 +49,4 @@ public class BroadcastMessage implements Serializable { Collection userIdList; /** true 给全体广播 */ boolean broadcastAll; - }