diff --git a/game_web/robot_mgr/src/main/java/com/group/robot/matcher/RoomWanfaMatcher.java b/game_web/robot_mgr/src/main/java/com/group/robot/matcher/RoomWanfaMatcher.java index 5649356..b5dc82b 100644 --- a/game_web/robot_mgr/src/main/java/com/group/robot/matcher/RoomWanfaMatcher.java +++ b/game_web/robot_mgr/src/main/java/com/group/robot/matcher/RoomWanfaMatcher.java @@ -171,8 +171,9 @@ public class RoomWanfaMatcher { //检查调度器是否可用 if (!scheduler.isShutdown()) { CompletableFuture.runAsync(() -> { + RobotInfo robot = null; try { - RobotInfo robot = robotManager.getLoggedInRobotForWanfa(wanfaId); + robot = robotManager.getLoggedInRobotForWanfa(wanfaId); //加入房间 GroupRoomBusiness.joinRoom(group, roomId, robot.getSession(), null); @@ -185,6 +186,9 @@ public class RoomWanfaMatcher { robotConnectionHandler.readyTimeRobotExit(robot); } } catch (Exception e) { + if (robot != null) { + robotConnectionHandler.disconnectRobot(robot.getRobotId()); + } log.error("机器人加入房间时发生错误: groupId={}, roomId={}, wanfaId={}, isRobot={}", group, roomId, wanfaId, isRobot, e); } });