feat: 解耦认证逻辑
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.webgame.webgamebackend.ws;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.webgame.webgamebackend.common.auth.AuthenticationProvider;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.webgame.webgamebackend.service.GomokuGameService;
|
||||
@@ -35,6 +35,7 @@ public class RoomWebSocketHandler extends TextWebSocketHandler {
|
||||
private final RoomSessionManager sessionManager;
|
||||
private final GomokuGameService gomokuGameService;
|
||||
private final WsMessageRouter router;
|
||||
private final AuthenticationProvider authProvider;
|
||||
|
||||
/**
|
||||
* 注册所有消息类型与对应处理器
|
||||
@@ -109,12 +110,11 @@ public class RoomWebSocketHandler extends TextWebSocketHandler {
|
||||
}
|
||||
|
||||
// 通过 token 获取用户 ID
|
||||
Object loginId = StpUtil.getLoginIdByToken(token);
|
||||
if (loginId == null) {
|
||||
String userId = authProvider.getUserIdByToken(token);
|
||||
if (userId == null) {
|
||||
session.close(CloseStatus.POLICY_VIOLATION);
|
||||
return;
|
||||
}
|
||||
String userId = loginId.toString();
|
||||
|
||||
// 注册会话(内部会清理同用户的旧会话)
|
||||
sessionManager.addSession(roomId, userId, session);
|
||||
|
||||
Reference in New Issue
Block a user