Skip to content

Commit

Permalink
refactor(core): broadcastMe Added Tip: Please bind UserId before usin…
Browse files Browse the repository at this point in the history
…g this method, see FlowContext.bindingUserId.
  • Loading branch information
iohao committed Dec 31, 2024
1 parent 591ead7 commit 5dd3f12
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@ public interface MessageKey {
/* see DefaultUserHook.java */
String userHookInto = "userHookInto";
String userHookQuit = "userHookQuit";

/* see InternalAboutFlowContext.java */
String bindingUserId = "bindingUserId";
}
4 changes: 3 additions & 1 deletion common/common-core/src/main/resources/iohao.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ textDocumentBroadcast=Broadcast
textDocumentErrorCodeTitle=Error Code
# see DefaultUserHook
userHookInto=[PlayerOnline] CountOnline
userHookQuit=[PlayerOffline] CountOnline
userHookQuit=[PlayerOffline] CountOnline
# see InternalAboutFlowContext.java
bindingUserId=Please binding UserId before using this method. see FlowContext.bindingUserId.
3 changes: 3 additions & 0 deletions common/common-core/src/main/resources/iohao_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ textDocumentErrorCodeTitle=错误码
# see DefaultUserHook
userHookInto=[玩家上线] 在线数量
userHookQuit=[玩家下线] 在线数量
# see InternalAboutFlowContext.java
bindingUserId=请登录后使用该方法. see FlowContext.bindingUserId.

Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ public class BroadcastMessage implements Serializable {
Collection<Long> userIdList;
/** true 给全体广播 */
boolean broadcastAll;

}

0 comments on commit 5dd3f12

Please sign in to comment.