修改长麻、红中已知问题
parent
f855be8d92
commit
38333c4be4
|
|
@ -131,8 +131,8 @@ public class EXGameController extends GameController {
|
||||||
try {
|
try {
|
||||||
String connecId = params.getString("connecId");
|
String connecId = params.getString("connecId");
|
||||||
TaurusClient client = getCsMjGameServerConnection(connecId);
|
TaurusClient client = getCsMjGameServerConnection(connecId);
|
||||||
System.out.println("接收来自robot_mgr的加入房间协议 connecId: = "+connecId);
|
log.info("接收来自robot_mgr的加入房间协议 connecId: {}", connecId);
|
||||||
System.out.println("接收来自robot_mgr的加入房间协议 client: = "+client);
|
log.info("接收来自robot_mgr的加入房间协议 client: {}", client);
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
ITObject errorResponse = TObject.newInstance();
|
ITObject errorResponse = TObject.newInstance();
|
||||||
errorResponse.putString("status", "failed");
|
errorResponse.putString("status", "failed");
|
||||||
|
|
@ -170,7 +170,7 @@ public class EXGameController extends GameController {
|
||||||
params.del("connecId");
|
params.del("connecId");
|
||||||
//发送加入房间请求到game_mj_cs
|
//发送加入房间请求到game_mj_cs
|
||||||
client.send(Config.JOIN_ROOM_CS, params, response -> {
|
client.send(Config.JOIN_ROOM_CS, params, response -> {
|
||||||
System.out.println("joinRoomController: " + response);
|
log.info("joinRoomController: {}", response);
|
||||||
RobotUser roomInfo = new RobotUser();
|
RobotUser roomInfo = new RobotUser();
|
||||||
roomInfo.setCurrentRoomId(Integer.parseInt(roomId));
|
roomInfo.setCurrentRoomId(Integer.parseInt(roomId));
|
||||||
roomInfo.setConnecId(connecId);
|
roomInfo.setConnecId(connecId);
|
||||||
|
|
@ -200,8 +200,8 @@ public class EXGameController extends GameController {
|
||||||
try {
|
try {
|
||||||
String connecId = params.getString("connecId");
|
String connecId = params.getString("connecId");
|
||||||
TaurusClient client = getCsMjGameServerConnection(connecId);
|
TaurusClient client = getCsMjGameServerConnection(connecId);
|
||||||
System.out.println("接收来自robot_mgr的机器人准备协议 connecId: = "+connecId);
|
log.info("接收来自robot_mgr的机器人准备协议 connecId: {}", connecId);
|
||||||
System.out.println("接收来自robot_mgr的机器人准备协议 client: = "+client);
|
log.info("接收来自robot_mgr的机器人准备协议 client: {}", client);
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
ITObject errorResponse = TObject.newInstance();
|
ITObject errorResponse = TObject.newInstance();
|
||||||
errorResponse.putString("status", "failed");
|
errorResponse.putString("status", "failed");
|
||||||
|
|
@ -214,7 +214,7 @@ public class EXGameController extends GameController {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
//发送准备请求到game_mj_cs
|
//发送准备请求到game_mj_cs
|
||||||
client.send(Config.GAME_READY_CS, params, response -> {
|
client.send(Config.GAME_READY_CS, params, response -> {
|
||||||
System.out.println("robotReadyRoom: " + response);
|
log.info("robotReadyRoom: {}", response);
|
||||||
});
|
});
|
||||||
|
|
||||||
ITObject paramsReq = TObject.newInstance();
|
ITObject paramsReq = TObject.newInstance();
|
||||||
|
|
@ -246,7 +246,7 @@ public class EXGameController extends GameController {
|
||||||
if (!robotUsers.isEmpty()) {
|
if (!robotUsers.isEmpty()) {
|
||||||
synchronized (robotUsers) {
|
synchronized (robotUsers) {
|
||||||
RobotUser robotUser = robotUsers.get(0);
|
RobotUser robotUser = robotUsers.get(0);
|
||||||
System.err.println("房间{"+ roomId +"}中Redis未找到机器人{"+robotId+"},但本地映射存在{"+robotUser.getRobotId()+"},清理本地映射");
|
log.warn("房间{}中Redis未找到机器人{},但本地映射存在{},清理本地映射", roomId, robotId, robotUser.getRobotId());
|
||||||
robotRoomMapping.remove(robotUser.getConnecId());
|
robotRoomMapping.remove(robotUser.getConnecId());
|
||||||
robotRoomMapping.remove(robotUser.getRobotId());
|
robotRoomMapping.remove(robotUser.getRobotId());
|
||||||
}
|
}
|
||||||
|
|
@ -261,16 +261,16 @@ public class EXGameController extends GameController {
|
||||||
|
|
||||||
if (robotId != existingRobotId) {
|
if (robotId != existingRobotId) {
|
||||||
//不同机器人的冲突
|
//不同机器人的冲突
|
||||||
System.err.println("房间{"+ roomId +"}中Redis已存在机器人{"+existingRobotId+"},当前机器人{"+robotId+"}不执行加入逻辑");
|
log.warn("房间{}中Redis已存在机器人{},当前机器人{}不执行加入逻辑", roomId, existingRobotId, robotId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.err.println("225开始进房间: "+"room:"+ roomId +"robot:"+robotId);
|
log.info("225开始进房间: room:{} robot:{}", roomId, robotId);
|
||||||
//加入房间
|
//加入房间
|
||||||
joinRoomCommon(robotId, roomId, groupId, params);
|
joinRoomCommon(robotId, roomId, groupId, params);
|
||||||
System.err.println("225已进入房间准备成功: "+"room:"+ roomId +"robot:"+robotId);
|
log.info("225已进入房间准备成功: room:{} robot:{}", roomId, robotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -280,10 +280,10 @@ public class EXGameController extends GameController {
|
||||||
public void webGroupActive(Session session, ITObject params, int gid) {
|
public void webGroupActive(Session session, ITObject params, int gid) {
|
||||||
int robotId = params.getInt("robotid");
|
int robotId = params.getInt("robotid");
|
||||||
String roomId = params.getString("roomid");
|
String roomId = params.getString("roomid");
|
||||||
System.err.println("226开始进房间: " + "room:" + roomId + "robot:" + robotId);
|
log.info("226开始进房间: room:{} robot:{}", roomId, robotId);
|
||||||
//加入房间
|
//加入房间
|
||||||
joinRoomCommon(params.getInt("robotid"), params.getString("roomid"), params.getInt("groupid"), params);
|
joinRoomCommon(params.getInt("robotid"), params.getString("roomid"), params.getInt("groupid"), params);
|
||||||
System.err.println("226已进入房间准备成功: " + "room:" + roomId + "robot:" + robotId);
|
log.info("226已进入房间准备成功: room:{} robot:{}", roomId, robotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -310,12 +310,12 @@ public class EXGameController extends GameController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.err.println("重启后开始进房间: " + "room:" + robotUser.getCurrentRoomId() + "robot:" + robotUser.getRobotId());
|
log.info("重启后开始进房间: room:{} robot:{}", robotUser.getCurrentRoomId(), robotUser.getRobotId());
|
||||||
ITObject params = new TObject();
|
ITObject params = new TObject();
|
||||||
params.putString("session", "{user}:" + robotUser.getRobotId() + "," + robotSession);
|
params.putString("session", "{user}:" + robotUser.getRobotId() + "," + robotSession);
|
||||||
//加入房间
|
//加入房间
|
||||||
joinRoomCommon(Integer.parseInt(robotUser.getRobotId()), String.valueOf(robotUser.getCurrentRoomId()), Integer.parseInt(robotUser.getRobotGroupid()), params);
|
joinRoomCommon(Integer.parseInt(robotUser.getRobotId()), String.valueOf(robotUser.getCurrentRoomId()), Integer.parseInt(robotUser.getRobotGroupid()), params);
|
||||||
System.err.println("重启后已进入房间准备成功: " + "room:" + robotUser.getCurrentRoomId() + "robot:" + robotUser.getRobotId());
|
log.info("重启后已进入房间准备成功: room:{} robot:{}", robotUser.getCurrentRoomId(), robotUser.getRobotId());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("重启服务断线重连时发生错误", e);
|
log.error("重启服务断线重连时发生错误", e);
|
||||||
|
|
@ -342,8 +342,8 @@ public class EXGameController extends GameController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.err.println("开始进房间: room:" + roomId);
|
log.info("开始进房间: room:{}", roomId);
|
||||||
System.err.println("开始进房间: {user}:" + robotId);
|
log.info("开始进房间: {user}:{}", robotId);
|
||||||
|
|
||||||
TaurusClient client = getCsMjGameServerConnection(roomId + "_" + robotId);
|
TaurusClient client = getCsMjGameServerConnection(roomId + "_" + robotId);
|
||||||
GroupRoomBusiness.joinRoom(groupId, "room:" + roomId, "{user}:" + robotId, null);
|
GroupRoomBusiness.joinRoom(groupId, "room:" + roomId, "{user}:" + robotId, null);
|
||||||
|
|
@ -373,11 +373,11 @@ public class EXGameController extends GameController {
|
||||||
robotConnectionManager.reconnectToGameServer(response, robotUser, client);
|
robotConnectionManager.reconnectToGameServer(response, robotUser, client);
|
||||||
});
|
});
|
||||||
|
|
||||||
System.err.println("已进入房间成功: " + robotUser.getConnecId());
|
log.info("已进入房间成功: {}", robotUser.getConnecId());
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
if (client.isConnected()) {
|
if (client.isConnected()) {
|
||||||
client.send(Config.GAME_READY_CS, params, response -> {
|
client.send(Config.GAME_READY_CS, params, response -> {
|
||||||
System.out.println("1003:" + response);
|
log.info("1003:{}", response);
|
||||||
});
|
});
|
||||||
jedis2.hset("gallrobot", String.valueOf(robotUser.getRobotId()), "1");
|
jedis2.hset("gallrobot", String.valueOf(robotUser.getRobotId()), "1");
|
||||||
|
|
||||||
|
|
@ -391,13 +391,13 @@ public class EXGameController extends GameController {
|
||||||
scheduleDelay(() -> {
|
scheduleDelay(() -> {
|
||||||
//15秒后还没有建立映射关系 加入可能失败
|
//15秒后还没有建立映射关系 加入可能失败
|
||||||
if (robotRoomMapping.get(robotUser.getConnecId()) == null) {
|
if (robotRoomMapping.get(robotUser.getConnecId()) == null) {
|
||||||
System.err.println("机器人{"+robotId+"}加入房间{"+roomId+"}超时,清理临时状态");
|
log.warn("机器人{}加入房间{}超时,清理临时状态", robotId, roomId);
|
||||||
robotConnectionManager.disconnectFromGameServer(connecId);
|
robotConnectionManager.disconnectFromGameServer(connecId);
|
||||||
}
|
}
|
||||||
}, 15, TimeUnit.SECONDS);
|
}, 15, TimeUnit.SECONDS);
|
||||||
//15秒后还没有建立映射关系 加入可能失败
|
//15秒后还没有建立映射关系 加入可能失败
|
||||||
if (robotRoomMapping.get(robotUser.getConnecId()) == null) {
|
if (robotRoomMapping.get(robotUser.getConnecId()) == null) {
|
||||||
System.err.println("机器人{"+robotId+"}加入房间{"+roomId+"}超时,清理临时状态");
|
log.warn("机器人{}加入房间{}超时,清理临时状态", robotId, roomId);
|
||||||
robotConnectionManager.disconnectFromGameServer(connecId);
|
robotConnectionManager.disconnectFromGameServer(connecId);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -405,7 +405,7 @@ public class EXGameController extends GameController {
|
||||||
}
|
}
|
||||||
}, ThreadPoolConfig.getBusinessThreadPool());//指定自定义线程池
|
}, ThreadPoolConfig.getBusinessThreadPool());//指定自定义线程池
|
||||||
robotUser.setIntoRoomTime(robotConnectionManager.getTime());
|
robotUser.setIntoRoomTime(robotConnectionManager.getTime());
|
||||||
System.err.println("已进入房间准备成功: " + robotUser.getConnecId());
|
log.info("已进入房间准备成功: {}", robotUser.getConnecId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("加入房间时发生错误", e);
|
log.error("加入房间时发生错误", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -460,7 +460,7 @@ public class EXGameController extends GameController {
|
||||||
lastAccessTime.remove(removedUser.getConnecId());
|
lastAccessTime.remove(removedUser.getConnecId());
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("清理机器人房间信息: " + robotId);
|
log.info("清理机器人房间信息: {}", robotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -486,7 +486,7 @@ public class EXGameController extends GameController {
|
||||||
for (String connecId : expiredConnections) {
|
for (String connecId : expiredConnections) {
|
||||||
RobotUser robotUser = robotRoomMapping.get(connecId);
|
RobotUser robotUser = robotRoomMapping.get(connecId);
|
||||||
if (robotUser != null) {
|
if (robotUser != null) {
|
||||||
System.out.println("清理超时连接: " + connecId + ", 机器人ID: " + robotUser.getRobotId());
|
log.info("清理超时连接: {}, 机器人ID: {}", connecId, robotUser.getRobotId());
|
||||||
robotConnectionManager.disconnectFromGameServer(connecId);
|
robotConnectionManager.disconnectFromGameServer(connecId);
|
||||||
}
|
}
|
||||||
robotRoomMapping.remove(connecId);
|
robotRoomMapping.remove(connecId);
|
||||||
|
|
@ -494,7 +494,7 @@ public class EXGameController extends GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expiredConnections.isEmpty()) {
|
if (!expiredConnections.isEmpty()) {
|
||||||
System.out.println("本次清理了 " + expiredConnections.size() + " 个超时连接");
|
log.info("本次清理了 {} 个超时连接", expiredConnections.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -539,7 +539,7 @@ public class EXGameController extends GameController {
|
||||||
*/
|
*/
|
||||||
public static TaurusClient getCsMjGameServerConnection(String connecId) {
|
public static TaurusClient getCsMjGameServerConnection(String connecId) {
|
||||||
TaurusClient taurusClient = robotConnectionManager.getGameClient(connecId);
|
TaurusClient taurusClient = robotConnectionManager.getGameClient(connecId);
|
||||||
System.out.println("根据机器人ID和连接ID获取长沙麻将游戏服务器连接 client: = "+taurusClient);
|
log.info("根据机器人ID和连接ID获取长沙麻将游戏服务器连接 client: {}", taurusClient);
|
||||||
if (taurusClient != null) {
|
if (taurusClient != null) {
|
||||||
log.debug("成功获取游戏服务器连接,connecId: {}", connecId);
|
log.debug("成功获取游戏服务器连接,connecId: {}", connecId);
|
||||||
return taurusClient;
|
return taurusClient;
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public class EXMainServer extends MainServer{
|
||||||
String robotskey = "g{"+Config.DEFAULT_GROUP_ID+"}:play:"+Config.DEFAULT_PID;
|
String robotskey = "g{"+Config.DEFAULT_GROUP_ID+"}:play:"+Config.DEFAULT_PID;
|
||||||
Map<String, String> maprobot = jedis2.hgetAll(robotskey);
|
Map<String, String> maprobot = jedis2.hgetAll(robotskey);
|
||||||
for(Map.Entry<String, String> entry : maprobot.entrySet()) {
|
for(Map.Entry<String, String> entry : maprobot.entrySet()) {
|
||||||
System.out.println(entry.getKey() + ":" + entry.getValue());
|
log.info("{}:{}", entry.getKey(), entry.getValue());
|
||||||
//是否创建
|
//是否创建
|
||||||
RobotUser robotUser = new RobotUser();
|
RobotUser robotUser = new RobotUser();
|
||||||
robotUser.setRobotId(entry.getKey());
|
robotUser.setRobotId(entry.getKey());
|
||||||
|
|
@ -88,7 +88,7 @@ public class EXMainServer extends MainServer{
|
||||||
|
|
||||||
log.info("长沙麻将机器人服务器已启动");
|
log.info("长沙麻将机器人服务器已启动");
|
||||||
log.info("服务器将监听端口 {} 用于接收robot_mgr管理协议", gameSetting.port);
|
log.info("服务器将监听端口 {} 用于接收robot_mgr管理协议", gameSetting.port);
|
||||||
System.out.println("当前线程池配置: " + ThreadPoolConfig.getThreadPoolStatus());
|
log.info("当前线程池配置: {}", ThreadPoolConfig.getThreadPoolStatus());
|
||||||
|
|
||||||
jedis2.close();
|
jedis2.close();
|
||||||
}
|
}
|
||||||
|
|
@ -123,16 +123,16 @@ public class EXMainServer extends MainServer{
|
||||||
//每30秒执行一次资源清理
|
//每30秒执行一次资源清理
|
||||||
Thread.sleep(30000);
|
Thread.sleep(30000);
|
||||||
ResourceCleanupUtil.performCleanup();
|
ResourceCleanupUtil.performCleanup();
|
||||||
System.out.println("线程池状态: " + ThreadPoolConfig.getThreadPoolStatus());
|
log.info("线程池状态: {}", ThreadPoolConfig.getThreadPoolStatus());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
break;
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("资源清理任务异常: " + e.getMessage());
|
log.error("资源清理任务异常: {}", e.getMessage(), e);
|
||||||
// 发生异常时尝试清理
|
// 发生异常时尝试清理
|
||||||
try {
|
try {
|
||||||
ResourceCleanupUtil.performCleanup();
|
ResourceCleanupUtil.performCleanup();
|
||||||
} catch (Exception cleanupEx) {
|
} catch (Exception cleanupEx) {
|
||||||
System.err.println("异常清理也失败: " + cleanupEx.getMessage());
|
log.error("异常清理也失败: {}", cleanupEx.getMessage(), cleanupEx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +140,7 @@ public class EXMainServer extends MainServer{
|
||||||
|
|
||||||
cleanupThread.setDaemon(true);
|
cleanupThread.setDaemon(true);
|
||||||
cleanupThread.start();
|
cleanupThread.start();
|
||||||
System.out.println("资源清理定时任务已启动");
|
log.info("资源清理定时任务已启动");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package robot.mj;
|
||||||
|
|
||||||
import com.robot.data.Player;
|
import com.robot.data.Player;
|
||||||
import com.robot.data.Room;
|
import com.robot.data.Room;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -10,10 +12,11 @@ import com.robot.data.Room;
|
||||||
public class EXPlayer extends Player {
|
public class EXPlayer extends Player {
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(EXPlayer.class);
|
||||||
|
|
||||||
public EXPlayer(int playerid, Room table, String session_id) {
|
public EXPlayer(int playerid, Room table, String session_id) {
|
||||||
super(playerid, table, session_id);
|
super(playerid, table, session_id);
|
||||||
System.out.println("new robot ");
|
log.info("new robot");
|
||||||
}
|
}
|
||||||
|
|
||||||
public EXRoom getRoom() {
|
public EXRoom getRoom() {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import static robot.mj.EXGameController.robotRoomMapping;
|
||||||
*/
|
*/
|
||||||
public class RobotConnectionManager {
|
public class RobotConnectionManager {
|
||||||
|
|
||||||
private Logger log = Logger.getLogger(RobotConnectionManager.class);
|
private final Logger log = Logger.getLogger(RobotConnectionManager.class);
|
||||||
private static final Map<String, HuNanChangSha> huNanChangShaInstances = new ConcurrentHashMap<>();
|
private static final Map<String, HuNanChangSha> huNanChangShaInstances = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
//记录活跃连接 用于资源清理判断
|
//记录活跃连接 用于资源清理判断
|
||||||
|
|
@ -103,13 +103,13 @@ public class RobotConnectionManager {
|
||||||
//从Redis恢复状态
|
//从Redis恢复状态
|
||||||
boolean restored = newInstance.restoreFromRedis(connecId);
|
boolean restored = newInstance.restoreFromRedis(connecId);
|
||||||
if (restored) {
|
if (restored) {
|
||||||
System.out.println("从Redis恢复HuNanChangSha实例: " + connecId);
|
log.info("从Redis恢复HuNanChangSha实例: {}", connecId);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("创建新的HuNanChangSha实例: " + connecId);
|
log.info("创建新的HuNanChangSha实例: {}", connecId);
|
||||||
}
|
}
|
||||||
|
|
||||||
huNanChangShaInstances.put(connecId, newInstance);
|
huNanChangShaInstances.put(connecId, newInstance);
|
||||||
System.out.println("当前HuNanChangSha实例总数: " + huNanChangShaInstances.size());
|
log.info("当前HuNanChangSha实例总数: {}", huNanChangShaInstances.size());
|
||||||
return newInstance;
|
return newInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,7 +146,7 @@ public class RobotConnectionManager {
|
||||||
* 断开与游戏服务器的连接(主动断开)
|
* 断开与游戏服务器的连接(主动断开)
|
||||||
*/
|
*/
|
||||||
public void disconnectFromGameServer(String connecId) {
|
public void disconnectFromGameServer(String connecId) {
|
||||||
System.out.println("开始主动断开连接: {"+connecId+"}");
|
log.info("开始主动断开连接: {}", connecId);
|
||||||
RobotUser robotUser = robotRoomMapping.remove(connecId);
|
RobotUser robotUser = robotRoomMapping.remove(connecId);
|
||||||
|
|
||||||
//标记连接为非活跃
|
//标记连接为非活跃
|
||||||
|
|
@ -167,7 +167,7 @@ public class RobotConnectionManager {
|
||||||
instance.getchowGroup().clear();
|
instance.getchowGroup().clear();
|
||||||
instance.getchangShaCardInhandgang().clear();
|
instance.getchangShaCardInhandgang().clear();
|
||||||
instance.getChuGuoPainum().clear();
|
instance.getChuGuoPainum().clear();
|
||||||
System.out.println("清空HuNanChangSha集合数据: " + connecId);
|
log.info("清空HuNanChangSha集合数据: {}", connecId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//移除实例和相关数据
|
//移除实例和相关数据
|
||||||
|
|
@ -178,7 +178,7 @@ public class RobotConnectionManager {
|
||||||
playermingsMapByConn.remove(connecId);
|
playermingsMapByConn.remove(connecId);
|
||||||
playerzisMapByConn.remove(connecId);
|
playerzisMapByConn.remove(connecId);
|
||||||
|
|
||||||
System.out.println("清理完成,当前活跃连接数: " + activeConnections.size() + ", 实例数: " + huNanChangShaInstances.size());
|
log.info("清理完成,当前活跃连接数: {}, 实例数: {}", activeConnections.size(), huNanChangShaInstances.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (robotUser != null) {
|
if (robotUser != null) {
|
||||||
|
|
@ -188,12 +188,12 @@ public class RobotConnectionManager {
|
||||||
if (client.isConnected()) {
|
if (client.isConnected()) {
|
||||||
client.killConnection();
|
client.killConnection();
|
||||||
}
|
}
|
||||||
System.out.println("客户端主动断开连接完成: {"+connecId+"}");
|
log.info("客户端主动断开连接完成: {}", connecId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("断开客户端连接时发生异常: " + connecId + ", 错误: " + e.getMessage());
|
log.error("断开客户端连接时发生异常: {}, 错误: {}", connecId, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("客户端连接不存在: {"+connecId+"}");
|
log.warn("客户端连接不存在: {}", connecId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//同时清理机器人房间映射
|
//同时清理机器人房间映射
|
||||||
|
|
@ -217,12 +217,12 @@ public class RobotConnectionManager {
|
||||||
|
|
||||||
//清理过期连接
|
//清理过期连接
|
||||||
for (String connecId : expiredConnections) {
|
for (String connecId : expiredConnections) {
|
||||||
System.out.println("清理过期连接实例: " + connecId);
|
log.info("清理过期连接实例: {}", connecId);
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expiredConnections.isEmpty()) {
|
if (!expiredConnections.isEmpty()) {
|
||||||
System.out.println("本次清理了 " + expiredConnections.size() + " 个过期连接实例");
|
log.info("本次清理了 {} 个过期连接实例", expiredConnections.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,7 +240,7 @@ public class RobotConnectionManager {
|
||||||
ITObject param = message.param;
|
ITObject param = message.param;
|
||||||
//回调协议号
|
//回调协议号
|
||||||
String command = message.command;
|
String command = message.command;
|
||||||
System.out.println("csmj OnEvent msg: " + command);
|
log.debug("csmj OnEvent msg: {}", command);
|
||||||
|
|
||||||
//根据玩法ID处理不同的回调
|
//根据玩法ID处理不同的回调
|
||||||
if (StringUtil.isNotEmpty(command)) {
|
if (StringUtil.isNotEmpty(command)) {
|
||||||
|
|
@ -287,10 +287,10 @@ public class RobotConnectionManager {
|
||||||
robotUser.setSeat(seat);
|
robotUser.setSeat(seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("playerData:" + playerData);
|
log.info("playerData: {}", playerData);
|
||||||
|
|
||||||
System.out.println("obj:" + obj);
|
log.info("obj: {}", obj);
|
||||||
System.out.println("reloadInfo:" + reloadInfo);
|
log.info("reloadInfo: {}", reloadInfo);
|
||||||
if (reloadInfo != null) {
|
if (reloadInfo != null) {
|
||||||
//重连回来的
|
//重连回来的
|
||||||
int curren_outcard_seat = reloadInfo.getInt("curren_outcard_seat");
|
int curren_outcard_seat = reloadInfo.getInt("curren_outcard_seat");
|
||||||
|
|
@ -316,7 +316,7 @@ public class RobotConnectionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("hcard>0" + hcard);
|
log.info("hcard>0{}", hcard);
|
||||||
if (hcard.size() > 0) {
|
if (hcard.size() > 0) {
|
||||||
//同步手牌
|
//同步手牌
|
||||||
HuNanChangSha currentInstance = getHuNanChangShaInstance(connecId);
|
HuNanChangSha currentInstance = getHuNanChangShaInstance(connecId);
|
||||||
|
|
@ -326,9 +326,9 @@ public class RobotConnectionManager {
|
||||||
if (currentHand.isEmpty() || hcard.size() > currentHand.size()) {
|
if (currentHand.isEmpty() || hcard.size() > currentHand.size()) {
|
||||||
//手牌集合为空 或者 玩家出牌了
|
//手牌集合为空 或者 玩家出牌了
|
||||||
currentInstance.updateHandCard(hcard);
|
currentInstance.updateHandCard(hcard);
|
||||||
System.out.println("断线重连:同步手牌数据,服务器手牌:" + hcard);
|
log.info("断线重连:同步手牌数据,服务器手牌:{}", hcard);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("断线重连:使用Redis恢复的手牌数据,数量:" + currentHand.size());
|
log.info("断线重连:使用Redis恢复的手牌数据,数量:{}", currentHand.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outcard_list.size() > 0) {
|
if (outcard_list.size() > 0) {
|
||||||
|
|
@ -341,9 +341,9 @@ public class RobotConnectionManager {
|
||||||
List<Integer> currentOutCards = currentInstance.getChuGuoCardInhand();
|
List<Integer> currentOutCards = currentInstance.getChuGuoCardInhand();
|
||||||
if (currentOutCards.isEmpty() || outcards.size() > currentOutCards.size()) {
|
if (currentOutCards.isEmpty() || outcards.size() > currentOutCards.size()) {
|
||||||
currentInstance.updateOutCard(outcards);
|
currentInstance.updateOutCard(outcards);
|
||||||
System.out.println("断线重连:同步出牌数据,服务器出牌:" + outcards);
|
log.info("断线重连:同步出牌数据,服务器出牌:{}", outcards);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("断线重连:使用Redis恢复的出牌数据,数量:" + currentOutCards.size());
|
log.info("断线重连:使用Redis恢复的出牌数据,数量:{}", currentOutCards.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -359,7 +359,7 @@ public class RobotConnectionManager {
|
||||||
Map<Integer, List<Integer>> currentPlayerzisMap = getPlayerzisMap(connecId);
|
Map<Integer, List<Integer>> currentPlayerzisMap = getPlayerzisMap(connecId);
|
||||||
|
|
||||||
reconnectedInstance.outCard(client, currentPlayerOutcardsMap, currentPlayerchisMap, currentPlayerpengsMap, currentPlayermingsMap, currentPlayerzisMap);
|
reconnectedInstance.outCard(client, currentPlayerOutcardsMap, currentPlayerchisMap, currentPlayerpengsMap, currentPlayermingsMap, currentPlayerzisMap);
|
||||||
System.out.println("断线重连后成功执行出牌操作");
|
log.info("断线重连后成功执行出牌操作");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("断线重连后执行出牌操作时发生异常", e);
|
log.error("断线重连后执行出牌操作时发生异常", e);
|
||||||
//即使出牌失败,也要确保连接状态正确
|
//即使出牌失败,也要确保连接状态正确
|
||||||
|
|
@ -373,7 +373,7 @@ public class RobotConnectionManager {
|
||||||
}
|
}
|
||||||
}, 2, TimeUnit.SECONDS);
|
}, 2, TimeUnit.SECONDS);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("警告:重连时未获取到手牌数据");
|
log.warn("警告:重连时未获取到手牌数据");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -396,7 +396,7 @@ public class RobotConnectionManager {
|
||||||
EXGameController.updateLastAccessTime(connecId);
|
EXGameController.updateLastAccessTime(connecId);
|
||||||
|
|
||||||
if (robotUser == null) {
|
if (robotUser == null) {
|
||||||
System.err.println("未找到机器人用户信息,连接ID: " + connecId);
|
log.error("未找到机器人用户信息,连接ID: {}", connecId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -585,7 +585,7 @@ public class RobotConnectionManager {
|
||||||
//更新机器人剩余数量
|
//更新机器人剩余数量
|
||||||
updateLeftoverRobot(robotId);
|
updateLeftoverRobot(robotId);
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
System.out.println("2001发送退出房间协议1005,robotId: {"+robotId+"}");
|
log.info("2001发送退出房间协议1005,robotId: {}", robotId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -599,7 +599,7 @@ public class RobotConnectionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 6, TimeUnit.SECONDS);
|
}, 6, TimeUnit.SECONDS);
|
||||||
System.out.println("玩家{"+ robotUser.getCurrentRoomId()+"}加入房间:"+ param);
|
log.info("玩家{}加入房间:{}", robotUser.getCurrentRoomId(), param);
|
||||||
}
|
}
|
||||||
//2026.02.03修改 玩家退出房间也要检查
|
//2026.02.03修改 玩家退出房间也要检查
|
||||||
else if ("2002".equalsIgnoreCase(command)) {
|
else if ("2002".equalsIgnoreCase(command)) {
|
||||||
|
|
@ -626,7 +626,7 @@ public class RobotConnectionManager {
|
||||||
//更新机器人剩余数量
|
//更新机器人剩余数量
|
||||||
updateLeftoverRobot(robotId);
|
updateLeftoverRobot(robotId);
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
System.out.println("2002发送退出房间协议1005,robotId: {"+robotId+"}");
|
log.info("2002发送退出房间协议1005,robotId: {}", robotId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -646,7 +646,7 @@ public class RobotConnectionManager {
|
||||||
//更新机器人剩余数量
|
//更新机器人剩余数量
|
||||||
updateLeftoverRobot(robotId);
|
updateLeftoverRobot(robotId);
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
System.out.println("2005玩家发送解散房间协议,robotId: {"+robotId+"}");
|
log.info("2005玩家发送解散房间协议,robotId: {}", robotId);
|
||||||
}
|
}
|
||||||
//2026.02.03修改 解散房间时候恢复机器人账号可以使用
|
//2026.02.03修改 解散房间时候恢复机器人账号可以使用
|
||||||
else if ("2008".equalsIgnoreCase(command)) {
|
else if ("2008".equalsIgnoreCase(command)) {
|
||||||
|
|
@ -692,18 +692,18 @@ public class RobotConnectionManager {
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
//更新机器人剩余数量
|
//更新机器人剩余数量
|
||||||
updateLeftoverRobot(paramRobotId);
|
updateLeftoverRobot(paramRobotId);
|
||||||
System.out.println("2009发送退出房间协议1005,robotId: {"+paramRobotId+"}");
|
log.info("2009发送退出房间协议1005,robotId: {}", paramRobotId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
System.err.println("2009协议数字格式异常,robotId: " + param.get("aid") + ", connecId: " + connecId);
|
log.error("2009协议数字格式异常,robotId: {}, connecId: {}", param.get("aid"), connecId);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
System.err.println("2009协议空指针异常,connecId: " + connecId);
|
log.error("2009协议空指针异常,connecId: {}", connecId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("2009协议处理异常: " + e.getMessage() + ", connecId: " + connecId);
|
log.error("2009协议处理异常: {}, connecId: {}", e.getMessage(), connecId, e);
|
||||||
} finally {
|
} finally {
|
||||||
if (jedis != null) {
|
if (jedis != null) {
|
||||||
jedis.close();
|
jedis.close();
|
||||||
|
|
@ -796,7 +796,7 @@ public class RobotConnectionManager {
|
||||||
|
|
||||||
jedis2.hset("{grobot}:" + robotId, "start", "0");
|
jedis2.hset("{grobot}:" + robotId, "start", "0");
|
||||||
|
|
||||||
System.out.println("机器人 {"+robotId+"} 退出房间,修改gallrobot为0");
|
log.info("机器人 {} 退出房间,修改gallrobot为0", robotId);
|
||||||
} finally {
|
} finally {
|
||||||
jedis2.close();
|
jedis2.close();
|
||||||
}
|
}
|
||||||
|
|
@ -806,14 +806,14 @@ public class RobotConnectionManager {
|
||||||
* 机器人登录
|
* 机器人登录
|
||||||
*/
|
*/
|
||||||
public void login(RobotUser robotUser){
|
public void login(RobotUser robotUser){
|
||||||
System.out.println("login:"+robotUser.getRobotId());
|
log.info("login:{}", robotUser.getRobotId());
|
||||||
ITObject object = null;
|
ITObject object = null;
|
||||||
AccountBusiness accountBusiness = null;
|
AccountBusiness accountBusiness = null;
|
||||||
accountBusiness = new AccountBusiness();
|
accountBusiness = new AccountBusiness();
|
||||||
try {
|
try {
|
||||||
//先快速登录
|
//先快速登录
|
||||||
object = accountBusiness.fastLogin(Integer.parseInt(robotUser.getRobotId()));
|
object = accountBusiness.fastLogin(Integer.parseInt(robotUser.getRobotId()));
|
||||||
System.out.println("object:"+object);
|
log.info("object:{}", object);
|
||||||
if(object==null){
|
if(object==null){
|
||||||
object = accountBusiness.idPasswordLogin(Integer.parseInt(robotUser.getRobotId()), robotUser.getPassword());
|
object = accountBusiness.idPasswordLogin(Integer.parseInt(robotUser.getRobotId()), robotUser.getPassword());
|
||||||
}
|
}
|
||||||
|
|
@ -835,7 +835,7 @@ public class RobotConnectionManager {
|
||||||
connectGame(robotUser);
|
connectGame(robotUser);
|
||||||
|
|
||||||
robotUser.setConnecId(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId());
|
robotUser.setConnecId(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId());
|
||||||
System.err.println("重启获取的机器人还有当前房间,准备加入: "+robotUser.getConnecId());
|
log.info("重启获取的机器人还有当前房间,准备加入: {}", robotUser.getConnecId());
|
||||||
exGameController.webGroupJoinRoom(robotUser);
|
exGameController.webGroupJoinRoom(robotUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -862,12 +862,12 @@ public class RobotConnectionManager {
|
||||||
robotUser.setClient(client);
|
robotUser.setClient(client);
|
||||||
EXGameController.robotRoomMapping.put(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId(), robotUser);
|
EXGameController.robotRoomMapping.put(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId(), robotUser);
|
||||||
}else{
|
}else{
|
||||||
System.out.println("reconnect");
|
log.info("reconnect");
|
||||||
System.out.println("client.isConnected()"+robotUser.getClient().isConnected());
|
log.info("client.isConnected(){}", robotUser.getClient().isConnected());
|
||||||
if(robotUser.getClient().isConnected()){
|
if(robotUser.getClient().isConnected()){
|
||||||
robotUser.setIsconnect(true);
|
robotUser.setIsconnect(true);
|
||||||
}else{
|
}else{
|
||||||
System.out.println("reconnect"+robotUser.getClient().getGameID());
|
log.info("reconnect{}", robotUser.getClient().getGameID());
|
||||||
TaurusClient client = new TaurusClient(robotUser.getGameHost()+":"+robotUser.getGamePort(), "cm"+robotUser.getRobotId(), TaurusClient.ConnectionProtocol.Tcp);
|
TaurusClient client = new TaurusClient(robotUser.getGameHost()+":"+robotUser.getGamePort(), "cm"+robotUser.getRobotId(), TaurusClient.ConnectionProtocol.Tcp);
|
||||||
client.setSession(robotUser.getLoginsession());
|
client.setSession(robotUser.getLoginsession());
|
||||||
client.connect();
|
client.connect();
|
||||||
|
|
@ -914,7 +914,6 @@ public class RobotConnectionManager {
|
||||||
//添加延迟
|
//添加延迟
|
||||||
Thread.sleep(time);
|
Thread.sleep(time);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
System.out.println(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,11 +145,11 @@ public class AccountBusiness extends Controller {
|
||||||
|
|
||||||
String idPwdBan = Redis.use("group1_db0").get(id + "_login_ban");
|
String idPwdBan = Redis.use("group1_db0").get(id + "_login_ban");
|
||||||
if (StringUtil.isNotEmpty(idPwdBan)) {
|
if (StringUtil.isNotEmpty(idPwdBan)) {
|
||||||
System.out.println("进入了77777777777777777777");
|
logger.info("进入了77777777777777777777");
|
||||||
logger.error("id:" + id + " ban login");
|
logger.error("id:" + id + " ban login");
|
||||||
//throw new WebException(ErrorCode.BAN_LOGIN);
|
//throw new WebException(ErrorCode.BAN_LOGIN);
|
||||||
}
|
}
|
||||||
System.out.println("进入了9999999999999");
|
logger.info("进入了9999999999999");
|
||||||
|
|
||||||
ITArray resultArray = null;
|
ITArray resultArray = null;
|
||||||
try {
|
try {
|
||||||
|
|
@ -172,13 +172,13 @@ public class AccountBusiness extends Controller {
|
||||||
Redis.use("group1_db0").set(id + "_login_ban", "1");
|
Redis.use("group1_db0").set(id + "_login_ban", "1");
|
||||||
Redis.use("group1_db0").expire(id + "_login_ban", 1800);
|
Redis.use("group1_db0").expire(id + "_login_ban", 1800);
|
||||||
logger.error("pwd error count:" + count + " not login");
|
logger.error("pwd error count:" + count + " not login");
|
||||||
System.out.println("进入了00000000000");
|
logger.info("进入了00000000000");
|
||||||
|
|
||||||
//throw new WebException(ErrorCode._NO_SESSION);
|
//throw new WebException(ErrorCode._NO_SESSION);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("进入了111111111111");
|
logger.info("进入了111111111111");
|
||||||
|
|
||||||
//throw new WebException(ErrorCode._FAILED);
|
//throw new WebException(ErrorCode._FAILED);
|
||||||
}
|
}
|
||||||
|
|
@ -204,13 +204,13 @@ public class AccountBusiness extends Controller {
|
||||||
Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000);
|
Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000);
|
||||||
Redis.use("group1_db0").expire(token, 172800);
|
Redis.use("group1_db0").expire(token, 172800);
|
||||||
|
|
||||||
System.out.println("进入了2222222222222");
|
logger.info("进入了2222222222222");
|
||||||
|
|
||||||
long tokenNum = Redis.use("group1_db0").scard(session + "_token");
|
long tokenNum = Redis.use("group1_db0").scard(session + "_token");
|
||||||
if (tokenNum >= 10) {
|
if (tokenNum >= 10) {
|
||||||
logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum);
|
logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum);
|
||||||
}
|
}
|
||||||
System.out.println("进入了33333333333333333332");
|
logger.info("进入了33333333333333333332");
|
||||||
|
|
||||||
resData.putString("token", token);
|
resData.putString("token", token);
|
||||||
return resData;
|
return resData;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import com.taurus.core.entity.TArray;
|
||||||
import com.taurus.core.entity.TObject;
|
import com.taurus.core.entity.TObject;
|
||||||
import com.taurus.core.plugin.redis.Redis;
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
import com.taurus.core.util.StringUtil;
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import taurus.client.Message;
|
import taurus.client.Message;
|
||||||
import taurus.client.TaurusClient;
|
import taurus.client.TaurusClient;
|
||||||
|
|
@ -20,7 +22,7 @@ import com.google.gson.reflect.TypeToken;
|
||||||
import static robot.mj.thread.ThreadPoolConfig.getBusinessThreadPool;
|
import static robot.mj.thread.ThreadPoolConfig.getBusinessThreadPool;
|
||||||
|
|
||||||
public class HuNanChangSha {
|
public class HuNanChangSha {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(HuNanChangSha.class);
|
||||||
public int changShaCard = 0;
|
public int changShaCard = 0;
|
||||||
public static boolean isTinPeng = false;
|
public static boolean isTinPeng = false;
|
||||||
private final List<Integer> changShaCardInhandgang = new ArrayList<>();
|
private final List<Integer> changShaCardInhandgang = new ArrayList<>();
|
||||||
|
|
@ -108,9 +110,9 @@ public class HuNanChangSha {
|
||||||
//1小时过期时间
|
//1小时过期时间
|
||||||
jedis.expire(redisKey, 3600);
|
jedis.expire(redisKey, 3600);
|
||||||
|
|
||||||
System.out.println("保存HuNanChangSha状态到Redis: " + connecId);
|
log.info("保存HuNanChangSha状态到Redis: {}", connecId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("保存HuNanChangSha状态到Redis失败: " + e.getMessage());
|
log.error("保存HuNanChangSha状态到Redis失败: {}", e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
jedis.close();
|
jedis.close();
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +130,7 @@ public class HuNanChangSha {
|
||||||
Map<String, String> stateMap = jedis.hgetAll(redisKey);
|
Map<String, String> stateMap = jedis.hgetAll(redisKey);
|
||||||
|
|
||||||
if (stateMap == null || stateMap.isEmpty()) {
|
if (stateMap == null || stateMap.isEmpty()) {
|
||||||
System.out.println("Redis中没有找到HuNanChangSha状态数据: " + connecId);
|
log.info("Redis中没有找到HuNanChangSha状态数据{}", connecId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,11 +191,10 @@ public class HuNanChangSha {
|
||||||
|
|
||||||
session = stateMap.getOrDefault("session", "");
|
session = stateMap.getOrDefault("session", "");
|
||||||
token = stateMap.getOrDefault("token", "");
|
token = stateMap.getOrDefault("token", "");
|
||||||
|
log.info("从Redis恢复HuNanChangSha状态成功: {}, 手牌数量: {}", connecId, changShaCardInhand.size());
|
||||||
System.out.println("从Redis恢复HuNanChangSha状态成功: " + connecId + ", 手牌数量: " + changShaCardInhand.size());
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("从Redis恢复HuNanChangSha状态失败: " + e.getMessage());
|
log.error("从Redis恢复HuNanChangSha状态失败: {}", e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
jedis.close();
|
jedis.close();
|
||||||
|
|
@ -209,9 +210,9 @@ public class HuNanChangSha {
|
||||||
try {
|
try {
|
||||||
String redisKey = "{csmj}:" + connecId;
|
String redisKey = "{csmj}:" + connecId;
|
||||||
jedis.del(redisKey);
|
jedis.del(redisKey);
|
||||||
System.out.println("从Redis删除HuNanChangSha状态: " + connecId);
|
log.info("从Redis删除HuNanChangSha状态: {}", connecId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("从Redis删除HuNanChangSha状态失败: " + e.getMessage());
|
log.error("从Redis删除HuNanChangSha状态失败: {}", e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
jedis.close();
|
jedis.close();
|
||||||
}
|
}
|
||||||
|
|
@ -228,8 +229,7 @@ public class HuNanChangSha {
|
||||||
chowGroup.clear();
|
chowGroup.clear();
|
||||||
changShaCardInhandgang.clear();
|
changShaCardInhandgang.clear();
|
||||||
chuGuoPainum.clear();
|
chuGuoPainum.clear();
|
||||||
|
log.info("已清空HuNanChangSha所有集合数据");
|
||||||
System.out.println("已清空HuNanChangSha所有集合数据");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -270,8 +270,8 @@ public class HuNanChangSha {
|
||||||
int drawnCard = param.getInt("card");
|
int drawnCard = param.getInt("card");
|
||||||
changShaSuanFaTest.drawnCards = drawnCard;//存储摸到的牌
|
changShaSuanFaTest.drawnCards = drawnCard;//存储摸到的牌
|
||||||
changShaCardInhand.add(drawnCard);
|
changShaCardInhand.add(drawnCard);
|
||||||
System.out.println("param.getInt(player)" + param.getInt("player") );
|
log.info("param.getInt(player): {}",param.getInt("player"));
|
||||||
System.out.println("摸到的牌 +++++++++ " + drawnCard);
|
log.info("摸到的牌 +++++++++ : {}",drawnCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
jedis222.close();
|
jedis222.close();
|
||||||
|
|
@ -304,7 +304,7 @@ public class HuNanChangSha {
|
||||||
changShaCardInhand.add(cardList.getInt(i));
|
changShaCardInhand.add(cardList.getInt(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("changShaCardInhand" + changShaCardInhand);
|
log.info("changShaCardInhand: {}", changShaCardInhand);
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -315,11 +315,13 @@ public class HuNanChangSha {
|
||||||
* @param handCard
|
* @param handCard
|
||||||
*/
|
*/
|
||||||
public void updateHandCard(List<Integer> handCard) {
|
public void updateHandCard(List<Integer> handCard) {
|
||||||
System.out.println("updateHandCard同步手牌:"+ handCard);
|
log.info("updateHandCard同步手牌:{}", handCard);
|
||||||
|
|
||||||
|
log.info("changShaCardInhand: {}", changShaCardInhand);
|
||||||
changShaCardInhand.clear();
|
changShaCardInhand.clear();
|
||||||
System.out.println("updateHandCard同步手牌changShaCardInhand:"+ changShaCardInhand);
|
log.info("updateHandCard同步手牌changShaCardInhand:{}", changShaCardInhand);
|
||||||
changShaCardInhand.addAll(handCard);
|
changShaCardInhand.addAll(handCard);
|
||||||
System.out.println("updateHandCard同步手牌add:"+ changShaCardInhand);
|
log.info("updateHandCard同步手牌add:{}", changShaCardInhand);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateOutCard(List<Integer> outCard) {
|
public void updateOutCard(List<Integer> outCard) {
|
||||||
|
|
@ -337,14 +339,14 @@ public class HuNanChangSha {
|
||||||
getBusinessThreadPool().execute(() -> {
|
getBusinessThreadPool().execute(() -> {
|
||||||
try {
|
try {
|
||||||
int delaySeconds = 1 + new Random().nextInt(2);
|
int delaySeconds = 1 + new Random().nextInt(2);
|
||||||
System.out.println("执行" + actionName + "动作,延迟" + delaySeconds + "秒");
|
log.info("执行{}动作,延迟{}秒", actionName, delaySeconds);
|
||||||
Thread.sleep(delaySeconds * 1000);
|
Thread.sleep(delaySeconds * 1000);
|
||||||
|
|
||||||
client.send("612", params, response -> {
|
client.send("612", params, response -> {
|
||||||
System.out.println(actionName + "动作发送完成");
|
log.info("{}动作发送完成", actionName);
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("执行" + actionName + "动作时发生异常: " + e.getMessage());
|
log.error("执行{}动作时发生异常: {}", actionName, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -413,12 +415,12 @@ public class HuNanChangSha {
|
||||||
|
|
||||||
List<Integer> shifoutingpai = changShaSuanFaTest.handscardshifoutingpai(changShaCardInhand, chowGroup, pongGroup, gangdepai);
|
List<Integer> shifoutingpai = changShaSuanFaTest.handscardshifoutingpai(changShaCardInhand, chowGroup, pongGroup, gangdepai);
|
||||||
boolean beforelisten = false;//记录操作之前的下听状态
|
boolean beforelisten = false;//记录操作之前的下听状态
|
||||||
System.out.println("shifoutingpai" + shifoutingpai);
|
log.info("shifoutingpai{}", shifoutingpai);
|
||||||
if (shifoutingpai.size() > 0) {
|
if (shifoutingpai.size() > 0) {
|
||||||
beforelisten = true;
|
beforelisten = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("beforelisten" + beforelisten);
|
log.info("beforelisten{}", beforelisten);
|
||||||
//如果杠了之后还能继续听牌则杠
|
//如果杠了之后还能继续听牌则杠
|
||||||
|
|
||||||
//优先处理胡牌
|
//优先处理胡牌
|
||||||
|
|
@ -453,7 +455,7 @@ public class HuNanChangSha {
|
||||||
if (type == 3) {
|
if (type == 3) {
|
||||||
Util.removeCard(gangusecars, card, 3);
|
Util.removeCard(gangusecars, card, 3);
|
||||||
List<Integer> shifoutingpai3 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
|
List<Integer> shifoutingpai3 = changShaSuanFaTest.handscardshifoutingpai(gangusecars, chowGroup, pongGroup, gangdepai);
|
||||||
System.out.println(shifoutingpai3);
|
log.info("shifoutingpai3: {}", shifoutingpai3);
|
||||||
|
|
||||||
if (shifoutingpai3.size() > 0) {
|
if (shifoutingpai3.size() > 0) {
|
||||||
//开杠
|
//开杠
|
||||||
|
|
@ -564,7 +566,7 @@ public class HuNanChangSha {
|
||||||
int beforeIsDahu = 0;
|
int beforeIsDahu = 0;
|
||||||
|
|
||||||
beforeIsDahu = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
|
beforeIsDahu = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
|
||||||
System.out.println("bef:" + beforeIsDahu);
|
log.info("bef:{}", beforeIsDahu);
|
||||||
//5、门清
|
//5、门清
|
||||||
if (yupanhandcard.size() == 13 && beforelisten) {
|
if (yupanhandcard.size() == 13 && beforelisten) {
|
||||||
beforeIsDahu = 5;//门清
|
beforeIsDahu = 5;//门清
|
||||||
|
|
@ -619,10 +621,10 @@ public class HuNanChangSha {
|
||||||
idObject.put(id, sj);
|
idObject.put(id, sj);
|
||||||
}
|
}
|
||||||
//计算分数
|
//计算分数
|
||||||
System.out.println(pingfenResult);
|
log.info("pingfenResult: {}", pingfenResult);
|
||||||
if (pingfenResult.size() > 0) {
|
if (pingfenResult.size() > 0) {
|
||||||
int changeid = changShaSuanFaTest.suanfen(pingfenResult);
|
int changeid = changShaSuanFaTest.suanfen(pingfenResult);
|
||||||
System.out.println("changeid:" + changeid);
|
log.info("changeid:{}", changeid);
|
||||||
//选择最优的分数
|
//选择最优的分数
|
||||||
if (changeid == 0) {
|
if (changeid == 0) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
|
|
@ -636,7 +638,7 @@ public class HuNanChangSha {
|
||||||
for (Map.Entry<Integer, ITObject> entry : idObject.entrySet()) {
|
for (Map.Entry<Integer, ITObject> entry : idObject.entrySet()) {
|
||||||
if (entry.getKey() == changeid) {
|
if (entry.getKey() == changeid) {
|
||||||
tmp = entry.getValue();
|
tmp = entry.getValue();
|
||||||
System.out.println("tmp ++++++++++= " + tmp);
|
log.debug("tmp ++++++++++= {}", tmp);
|
||||||
if (tmp.getInt("type") == 2) {
|
if (tmp.getInt("type") == 2) {
|
||||||
//碰
|
//碰
|
||||||
ITArray outcards = tmp.getTArray("opcard");
|
ITArray outcards = tmp.getTArray("opcard");
|
||||||
|
|
@ -653,8 +655,8 @@ public class HuNanChangSha {
|
||||||
for (int i = 0; i < outcards.size(); i++) {
|
for (int i = 0; i < outcards.size(); i++) {
|
||||||
Util.removeCard(changShaCardInhand, outcards.getInt(i), 1);
|
Util.removeCard(changShaCardInhand, outcards.getInt(i), 1);
|
||||||
}
|
}
|
||||||
System.out.println("判断吃 +++++++++" + card);
|
log.debug("判断吃 +++++++++{}", card);
|
||||||
System.out.println("判断吃 ==========" + outcards);
|
log.debug("判断吃 ========== {}", outcards);
|
||||||
chowGroup.add(card);
|
chowGroup.add(card);
|
||||||
chowGroup.add(outcards.getInt(0));
|
chowGroup.add(outcards.getInt(0));
|
||||||
chowGroup.add(outcards.getInt(1));
|
chowGroup.add(outcards.getInt(1));
|
||||||
|
|
@ -686,7 +688,7 @@ public class HuNanChangSha {
|
||||||
List<Integer> tmpChangSch = new ArrayList<>();
|
List<Integer> tmpChangSch = new ArrayList<>();
|
||||||
tmpChangSch.addAll(yupanhandcard);
|
tmpChangSch.addAll(yupanhandcard);
|
||||||
ChangshaWinSplitCard.checkNormalHu(tmpChangSch, map);
|
ChangshaWinSplitCard.checkNormalHu(tmpChangSch, map);
|
||||||
System.out.println("要不要补map:" + map);
|
log.info("要不要补map:{}", map);
|
||||||
|
|
||||||
Map<String, Object> map2 = new HashMap<>();
|
Map<String, Object> map2 = new HashMap<>();
|
||||||
List<Integer> tmpChangSch2 = new ArrayList<>();
|
List<Integer> tmpChangSch2 = new ArrayList<>();
|
||||||
|
|
@ -700,12 +702,12 @@ public class HuNanChangSha {
|
||||||
}
|
}
|
||||||
|
|
||||||
ChangshaWinSplitCard.checkNormalHu(tmpChangSch2, map2);
|
ChangshaWinSplitCard.checkNormalHu(tmpChangSch2, map2);
|
||||||
System.out.println("要不要补map2:" + map2);
|
log.info("要不要补map2:{}", map2);
|
||||||
System.out.println(yupanhandcard);
|
log.info("yupanhandcard: {}", yupanhandcard);
|
||||||
//假设补牌
|
//假设补牌
|
||||||
//如果下听不能不能补牌
|
//如果下听不能不能补牌
|
||||||
if (beforelisten) {
|
if (beforelisten) {
|
||||||
System.out.println("b补");
|
log.info("b补");
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -717,7 +719,7 @@ public class HuNanChangSha {
|
||||||
Map<Integer, List<Integer>> afterOpbg = changShaSuanFaTest.quyizhangTingPai(yupanhandcard);
|
Map<Integer, List<Integer>> afterOpbg = changShaSuanFaTest.quyizhangTingPai(yupanhandcard);
|
||||||
if (type == 4) {
|
if (type == 4) {
|
||||||
if (afterDahuOpbg.size() > 0 || afterOpbg.size() > 0) {
|
if (afterDahuOpbg.size() > 0 || afterOpbg.size() > 0) {
|
||||||
System.out.println("bs补");
|
log.info("bs补");
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -731,7 +733,7 @@ public class HuNanChangSha {
|
||||||
if (map2.size() > 0) {
|
if (map2.size() > 0) {
|
||||||
//判断补牌后
|
//判断补牌后
|
||||||
if (Integer.parseInt(map2.get("remainingMelds").toString()) > Integer.parseInt(map.get("remainingMelds").toString()) && Integer.parseInt(map.get("remainingMelds").toString()) <= 2) {
|
if (Integer.parseInt(map2.get("remainingMelds").toString()) > Integer.parseInt(map.get("remainingMelds").toString()) && Integer.parseInt(map.get("remainingMelds").toString()) <= 2) {
|
||||||
System.out.println("b补");
|
log.info("b补");
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -742,7 +744,7 @@ public class HuNanChangSha {
|
||||||
//判断七对
|
//判断七对
|
||||||
int dh = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
|
int dh = changShaSuanFaTest.checkDahu(yupanhandcard, chowGroup, pongGroup, gangdepai);
|
||||||
if (dh > 0) {
|
if (dh > 0) {
|
||||||
System.out.println("不补");
|
log.info("不补");
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -750,7 +752,7 @@ public class HuNanChangSha {
|
||||||
return "不开杠";
|
return "不开杠";
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("补");
|
log.info("补");
|
||||||
|
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
|
|
@ -812,7 +814,7 @@ public class HuNanChangSha {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("actchangShaCardInhand"+changShaCardInhand);
|
log.info("actchangShaCardInhand{}", changShaCardInhand);
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
|
|
@ -865,10 +867,10 @@ public class HuNanChangSha {
|
||||||
resultList.addAll(zigang);
|
resultList.addAll(zigang);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("长沙麻将出牌" + changShaCardInhand);
|
log.info("长沙麻将出牌{}", changShaCardInhand);
|
||||||
// 长沙麻将出牌
|
// 长沙麻将出牌
|
||||||
String changShaOutCard = changShaSuanFaTest.outCardSuanFa(changShaCardInhand, pongGroup, chowGroup, gangdepai, resultList);
|
String changShaOutCard = changShaSuanFaTest.outCardSuanFa(changShaCardInhand, pongGroup, chowGroup, gangdepai, resultList);
|
||||||
System.out.println("长沙麻将出牌" + changShaCardInhand);
|
log.info("长沙麻将出牌{}", changShaCardInhand);
|
||||||
|
|
||||||
ITObject params = TObject.newInstance();
|
ITObject params = TObject.newInstance();
|
||||||
int cardToOut;
|
int cardToOut;
|
||||||
|
|
@ -891,10 +893,10 @@ public class HuNanChangSha {
|
||||||
|
|
||||||
// 将当前出的牌添加到历史出牌列表
|
// 将当前出的牌添加到历史出牌列表
|
||||||
changShachuguopai.add(cardToOut);
|
changShachuguopai.add(cardToOut);
|
||||||
System.out.println("changShachuguopai ++++ :" + changShachuguopai);
|
log.info("changShachuguopai ++++ :{}", changShachuguopai);
|
||||||
// 从手牌中移除
|
// 从手牌中移除
|
||||||
changShaCardInhand.remove(Integer.valueOf(cardToOut));
|
changShaCardInhand.remove(Integer.valueOf(cardToOut));
|
||||||
System.out.println("打过后的手牌 +++ " + changShaCardInhand);
|
log.info("打过后的手牌 +++ {}", changShaCardInhand);
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
|
|
||||||
//使用线程池替代CompletableFuture.runAsync + Thread.sleep
|
//使用线程池替代CompletableFuture.runAsync + Thread.sleep
|
||||||
|
|
@ -906,7 +908,7 @@ public class HuNanChangSha {
|
||||||
|
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Thread error");
|
log.error("线程执行错误", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -925,7 +927,7 @@ public class HuNanChangSha {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String shanchuchuguopai(ITObject param) {
|
public String shanchuchuguopai(ITObject param) {
|
||||||
System.out.println("对面吃碰删除出过的牌组");
|
log.info("对面吃碰删除出过的牌组");
|
||||||
if (param == null) {
|
if (param == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -953,10 +955,10 @@ public class HuNanChangSha {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!robotIdsList.contains(playerid)) {
|
if (!robotIdsList.contains(playerid)) {
|
||||||
System.out.println("playerid "+playerid);
|
log.info("playerid {}", playerid);
|
||||||
System.out.println("type "+type);
|
log.info("type {}", type);
|
||||||
if (type == 2 || type == 3 || type == 5 || type == 1) { // 碰,杠
|
if (type == 2 || type == 3 || type == 5 || type == 1) { // 碰,杠
|
||||||
System.out.println("进入对面吃牌 机器人出的牌需要删除这张牌");
|
log.info("进入对面吃牌 机器人出的牌需要删除这张牌");
|
||||||
getChuGuoCardInhand().remove(Integer.valueOf(card));
|
getChuGuoCardInhand().remove(Integer.valueOf(card));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package robot.mj.thread;
|
package robot.mj.thread;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import robot.mj.EXGameController;
|
import robot.mj.EXGameController;
|
||||||
import robot.mj.RobotConnectionManager;
|
import robot.mj.RobotConnectionManager;
|
||||||
|
|
||||||
|
|
@ -11,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
* 用于管理和清理不再使用的资源 防止内存泄漏
|
* 用于管理和清理不再使用的资源 防止内存泄漏
|
||||||
*/
|
*/
|
||||||
public class ResourceCleanupUtil {
|
public class ResourceCleanupUtil {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ResourceCleanupUtil.class);
|
||||||
|
|
||||||
//需要清理的资源
|
//需要清理的资源
|
||||||
private static final Set<String> pendingCleanupResources = ConcurrentHashMap.newKeySet();
|
private static final Set<String> pendingCleanupResources = ConcurrentHashMap.newKeySet();
|
||||||
|
|
@ -26,7 +29,7 @@ public class ResourceCleanupUtil {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("开始执行资源清理,待清理资源数: " + pendingCleanupResources.size());
|
log.info("开始执行资源清理,待清理资源数: {}", pendingCleanupResources.size());
|
||||||
int cleanedCount = 0;
|
int cleanedCount = 0;
|
||||||
|
|
||||||
Set<String> resourcesToClean = ConcurrentHashMap.newKeySet();
|
Set<String> resourcesToClean = ConcurrentHashMap.newKeySet();
|
||||||
|
|
@ -41,13 +44,13 @@ public class ResourceCleanupUtil {
|
||||||
pendingCleanupResources.remove(resourceId);
|
pendingCleanupResources.remove(resourceId);
|
||||||
cleanedCount++;
|
cleanedCount++;
|
||||||
|
|
||||||
System.out.println("已清理资源: " + resourceId);
|
log.info("已清理资源: {}", resourceId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("清理资源时发生异常: " + resourceId + ", 错误: " + e.getMessage());
|
log.error("清理资源时发生异常: {}, 错误: {}", resourceId, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("资源清理完成,共清理: " + cleanedCount + " 个资源");
|
log.info("资源清理完成,共清理: {} 个资源", cleanedCount);
|
||||||
|
|
||||||
//执行常规清理
|
//执行常规清理
|
||||||
performRegularCleanup();
|
performRegularCleanup();
|
||||||
|
|
@ -62,11 +65,11 @@ public class ResourceCleanupUtil {
|
||||||
EXGameController.cleanupExpiredConnections();
|
EXGameController.cleanupExpiredConnections();
|
||||||
|
|
||||||
//输出当前系统状态
|
//输出当前系统状态
|
||||||
System.out.println("=== 系统资源状态 ===");
|
log.info("=== 系统资源状态 ===");
|
||||||
System.out.println(ThreadPoolConfig.getThreadPoolStatus());
|
log.info("{}", ThreadPoolConfig.getThreadPoolStatus());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("执行常规清理时发生异常: " + e.getMessage());
|
log.error("执行常规清理时发生异常: {}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package robot.mj.thread;
|
package robot.mj.thread;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
|
@ -8,6 +11,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
*/
|
*/
|
||||||
public class ThreadPoolConfig {
|
public class ThreadPoolConfig {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ThreadPoolConfig.class);
|
||||||
//线程池配置
|
//线程池配置
|
||||||
private static final ExecutorService BUSINESS_THREAD_POOL =
|
private static final ExecutorService BUSINESS_THREAD_POOL =
|
||||||
new ThreadPoolExecutor(
|
new ThreadPoolExecutor(
|
||||||
|
|
@ -54,14 +58,14 @@ public class ThreadPoolConfig {
|
||||||
* 执行延迟任务,替代Thread.sleep
|
* 执行延迟任务,替代Thread.sleep
|
||||||
*/
|
*/
|
||||||
public static void scheduleDelay(Runnable task, long delay, TimeUnit unit) {
|
public static void scheduleDelay(Runnable task, long delay, TimeUnit unit) {
|
||||||
System.out.println("提交延迟任务: 延迟" + delay + " " + unit + ", 当前时间: " + System.currentTimeMillis());
|
log.debug("提交延迟任务: 延迟{} {}, 当前时间: {}", delay, unit, System.currentTimeMillis());
|
||||||
SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
|
SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
|
||||||
try {
|
try {
|
||||||
System.out.println("执行延迟任务开始: 当前时间: " + System.currentTimeMillis());
|
log.debug("执行延迟任务开始: 当前时间: {}", System.currentTimeMillis());
|
||||||
task.run();
|
task.run();
|
||||||
System.out.println("执行延迟任务完成: 当前时间: " + System.currentTimeMillis());
|
log.debug("执行延迟任务完成: 当前时间: {}", System.currentTimeMillis());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("延迟任务执行异常: " + e.getMessage());
|
log.error("延迟任务执行异常: {}", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}, delay, unit);
|
}, delay, unit);
|
||||||
}
|
}
|
||||||
|
|
@ -70,13 +74,13 @@ public class ThreadPoolConfig {
|
||||||
* 关闭线程池 释放资源
|
* 关闭线程池 释放资源
|
||||||
*/
|
*/
|
||||||
public static void shutdown() {
|
public static void shutdown() {
|
||||||
System.out.println("开始关闭线程池...");
|
log.info("开始关闭线程池...");
|
||||||
|
|
||||||
//关闭定时任务线程池
|
//关闭定时任务线程池
|
||||||
SCHEDULED_EXECUTOR_SERVICE.shutdown();
|
SCHEDULED_EXECUTOR_SERVICE.shutdown();
|
||||||
try {
|
try {
|
||||||
if (!SCHEDULED_EXECUTOR_SERVICE.awaitTermination(3, TimeUnit.SECONDS)) {
|
if (!SCHEDULED_EXECUTOR_SERVICE.awaitTermination(3, TimeUnit.SECONDS)) {
|
||||||
System.out.println("定时任务线程池强制关闭");
|
log.info("定时任务线程池强制关闭");
|
||||||
SCHEDULED_EXECUTOR_SERVICE.shutdownNow();
|
SCHEDULED_EXECUTOR_SERVICE.shutdownNow();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
@ -88,7 +92,7 @@ public class ThreadPoolConfig {
|
||||||
BUSINESS_THREAD_POOL.shutdown();
|
BUSINESS_THREAD_POOL.shutdown();
|
||||||
try {
|
try {
|
||||||
if (!BUSINESS_THREAD_POOL.awaitTermination(5, TimeUnit.SECONDS)) {
|
if (!BUSINESS_THREAD_POOL.awaitTermination(5, TimeUnit.SECONDS)) {
|
||||||
System.out.println("业务线程池强制关闭");
|
log.info("业务线程池强制关闭");
|
||||||
BUSINESS_THREAD_POOL.shutdownNow();
|
BUSINESS_THREAD_POOL.shutdownNow();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
@ -96,7 +100,7 @@ public class ThreadPoolConfig {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("线程池关闭完成");
|
log.info("线程池关闭完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class ChangShaSuanFaTest {
|
||||||
*/
|
*/
|
||||||
private void logInfo(String message) {
|
private void logInfo(String message) {
|
||||||
// 注释掉日志输出,减少测试时的信息干扰
|
// 注释掉日志输出,减少测试时的信息干扰
|
||||||
// System.out.println(message);
|
// log.info(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Logger log;
|
private final static Logger log;
|
||||||
|
|
@ -179,21 +179,21 @@ public class ChangShaSuanFaTest {
|
||||||
// boolean hasBigSuit = isAllSameSuit(handCards, pengCard); // 分析是否有可能的清一色花色
|
// boolean hasBigSuit = isAllSameSuit(handCards, pengCard); // 分析是否有可能的清一色花色
|
||||||
int hasBigSuit = checkDahu(handCards,chowGroup,pengCard,gangdepai);
|
int hasBigSuit = checkDahu(handCards,chowGroup,pengCard,gangdepai);
|
||||||
|
|
||||||
System.out.println("resultList22 +++++++++++++++++++++++================" + hasBigSuit);
|
log.info("resultList22 +++++++++++++++++++++++================ {}", hasBigSuit);
|
||||||
|
|
||||||
|
|
||||||
//特殊牌型处理
|
//特殊牌型处理
|
||||||
|
|
||||||
String tscard = teshuXuanPai(cardInhand, pengCard, chowGroup, gangdepai);
|
String tscard = teshuXuanPai(cardInhand, pengCard, chowGroup, gangdepai);
|
||||||
if (tscard!=null){
|
if (tscard!=null){
|
||||||
System.out.printf("特殊牌型处理111 +++++++++++++++++++++++++++++++++++");
|
log.info("特殊牌型处理111 +++++++++++++++++++++++++++++++++++");
|
||||||
return tscard;
|
return tscard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//循环去一张是否能大胡听牌
|
//循环去一张是否能大胡听牌
|
||||||
Map<Integer,List<Integer>> afterDahuOp = quyizhangDahuTingPai(cardInhand,chowGroup,pengCard,gangdepai);
|
Map<Integer,List<Integer>> afterDahuOp = quyizhangDahuTingPai(cardInhand,chowGroup,pengCard,gangdepai);
|
||||||
System.out.println("afterDahuOp:"+afterDahuOp);
|
log.info("afterDahuOp:{}", afterDahuOp);
|
||||||
|
|
||||||
if (afterDahuOp.size()>0){
|
if (afterDahuOp.size()>0){
|
||||||
//执行
|
//执行
|
||||||
|
|
@ -204,8 +204,8 @@ public class ChangShaSuanFaTest {
|
||||||
tmpres.addAll(cardInhand);
|
tmpres.addAll(cardInhand);
|
||||||
|
|
||||||
for (Map.Entry<Integer, List<Integer>> entry : afterDahuOp.entrySet()) {
|
for (Map.Entry<Integer, List<Integer>> entry : afterDahuOp.entrySet()) {
|
||||||
System.out.println(entry.getKey());
|
log.debug("{}", entry.getKey());
|
||||||
System.out.println("num:"+getTingPainum(entry.getValue(),tmpres));
|
log.debug("num:{}", getTingPainum(entry.getValue(),tmpres));
|
||||||
if (caozuonum1==0){
|
if (caozuonum1==0){
|
||||||
caozuonum1 = getTingPainum(entry.getValue(),tmpres);
|
caozuonum1 = getTingPainum(entry.getValue(),tmpres);
|
||||||
xuanzecard1 = entry.getKey();
|
xuanzecard1 = entry.getKey();
|
||||||
|
|
@ -225,7 +225,7 @@ public class ChangShaSuanFaTest {
|
||||||
|
|
||||||
//循环去一张还能听多牌
|
//循环去一张还能听多牌
|
||||||
Map<Integer,List<Integer>> afterOp = quyizhangTingPai(cardInhand);
|
Map<Integer,List<Integer>> afterOp = quyizhangTingPai(cardInhand);
|
||||||
System.out.println("afterOp:"+afterOp);
|
log.debug("afterOp:{}", afterOp);
|
||||||
|
|
||||||
if (afterOp.size()>0){
|
if (afterOp.size()>0){
|
||||||
//执行
|
//执行
|
||||||
|
|
@ -255,7 +255,7 @@ public class ChangShaSuanFaTest {
|
||||||
//六对
|
//六对
|
||||||
if (pisCardsCount >= 6 && pengCard.size() == 0 && chowGroup.size() == 0) {
|
if (pisCardsCount >= 6 && pengCard.size() == 0 && chowGroup.size() == 0) {
|
||||||
|
|
||||||
System.out.println("七小对数量大于等于6+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
|
log.info("七小对数量大于等于6+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
|
||||||
//单张牌
|
//单张牌
|
||||||
List<Integer> danzhang = danzhang(handCards);
|
List<Integer> danzhang = danzhang(handCards);
|
||||||
isTin = true;
|
isTin = true;
|
||||||
|
|
@ -299,21 +299,21 @@ public class ChangShaSuanFaTest {
|
||||||
List<Integer> zeroCountCards = threeCardsFromMax.stream()
|
List<Integer> zeroCountCards = threeCardsFromMax.stream()
|
||||||
.filter(card3 -> danzhangCountMap.getOrDefault(card3, 0) == 0)
|
.filter(card3 -> danzhangCountMap.getOrDefault(card3, 0) == 0)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
System.out.println("出现次数为0的牌: " + zeroCountCards);
|
log.debug("出现次数为0的牌: {}", zeroCountCards);
|
||||||
// 从maxCards中移除
|
// 从maxCards中移除
|
||||||
if (!zeroCountCards.isEmpty()) {
|
if (!zeroCountCards.isEmpty()) {
|
||||||
maxCards.removeAll(zeroCountCards);
|
maxCards.removeAll(zeroCountCards);
|
||||||
System.out.println("移除后maxCards: " + maxCards);
|
log.debug("移除后maxCards: {}", maxCards);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("maxCards中出现3次的牌: " + threeCardsFromMax);
|
log.debug("maxCards中出现3次的牌: {}", threeCardsFromMax);
|
||||||
if (threeCardsFromMax.size() > 0) {
|
if (threeCardsFromMax.size() > 0) {
|
||||||
return String.valueOf(threeCardsFromMax.get(0));
|
return String.valueOf(threeCardsFromMax.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer maxCard = maxCards.isEmpty() ? null : maxCards.get(0);
|
Integer maxCard = maxCards.isEmpty() ? null : maxCards.get(0);
|
||||||
System.out.println("maxCard++++++++++++++++++++++++++++++" + maxCard);
|
log.debug("maxCard++++++++++++++++++++++++++++++{}", maxCard);
|
||||||
System.out.printf("特殊牌型处理333 +++++++++++++++++++++++++++++++++++");
|
System.out.printf("特殊牌型处理333 +++++++++++++++++++++++++++++++++++");
|
||||||
|
|
||||||
return String.valueOf(maxCard);
|
return String.valueOf(maxCard);
|
||||||
|
|
@ -348,7 +348,7 @@ public class ChangShaSuanFaTest {
|
||||||
return String.valueOf(outcard);
|
return String.valueOf(outcard);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("hasBigSuit:"+hasBigSuit);
|
log.debug("hasBigSuit:{}", hasBigSuit);
|
||||||
if (hasBigSuit>0) {
|
if (hasBigSuit>0) {
|
||||||
logInfo("执行清一色策略,尝试优化花色分布");
|
logInfo("执行清一色策略,尝试优化花色分布");
|
||||||
// 调用清一色特定出牌策略
|
// 调用清一色特定出牌策略
|
||||||
|
|
@ -435,7 +435,7 @@ public class ChangShaSuanFaTest {
|
||||||
|
|
||||||
//调平胡递归
|
//调平胡递归
|
||||||
List<Integer> integers = ChangshaWinSplitCard.analyzeBestDiscard(pinghuhandCards);
|
List<Integer> integers = ChangshaWinSplitCard.analyzeBestDiscard(pinghuhandCards);
|
||||||
System.out.println("integers:"+integers);
|
log.debug("integers:{}", integers);
|
||||||
if(integers.size()>0) {
|
if(integers.size()>0) {
|
||||||
int integer = 0;
|
int integer = 0;
|
||||||
|
|
||||||
|
|
@ -456,7 +456,7 @@ public class ChangShaSuanFaTest {
|
||||||
|
|
||||||
|
|
||||||
if (integers.size() > 0 && cardnum < 4) {
|
if (integers.size() > 0 && cardnum < 4) {
|
||||||
System.out.println("平胡最新出牌策略=============================================== 666 " + integer);
|
log.debug("平胡最新出牌策略=============================================== 666 {}", integer);
|
||||||
|
|
||||||
List<Integer> guzhangc = new ArrayList<>();
|
List<Integer> guzhangc = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -494,7 +494,7 @@ public class ChangShaSuanFaTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("chaiduizi:" + chaiduizi);
|
log.debug("chaiduizi:{}", chaiduizi);
|
||||||
List<Integer> kydongduizi = new ArrayList<>();
|
List<Integer> kydongduizi = new ArrayList<>();
|
||||||
|
|
||||||
List<Integer> tmps = new ArrayList<>();
|
List<Integer> tmps = new ArrayList<>();
|
||||||
|
|
@ -512,7 +512,7 @@ public class ChangShaSuanFaTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
chaiduizi.removeAll(kydongduizi);
|
chaiduizi.removeAll(kydongduizi);
|
||||||
System.out.println("kydongduizi:" + chaiduizi);
|
log.debug("kydongduizi:{}", chaiduizi);
|
||||||
|
|
||||||
if(chaiduizi.size()>0) {
|
if(chaiduizi.size()>0) {
|
||||||
return String.valueOf(chaiduizi.get(0));
|
return String.valueOf(chaiduizi.get(0));
|
||||||
|
|
@ -544,7 +544,7 @@ public class ChangShaSuanFaTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("jiangcards:" + jiangcards);
|
log.debug("jiangcards:{}", jiangcards);
|
||||||
if (jiangcards > 0&&chaiduizi.size()<2) {
|
if (jiangcards > 0&&chaiduizi.size()<2) {
|
||||||
//
|
//
|
||||||
//去掉将判断孤章
|
//去掉将判断孤章
|
||||||
|
|
@ -619,7 +619,7 @@ public class ChangShaSuanFaTest {
|
||||||
|
|
||||||
//如果已经是听牌状态的情况
|
//如果已经是听牌状态的情况
|
||||||
if (analysis.isTingPai) {
|
if (analysis.isTingPai) {
|
||||||
System.out.println("已经是听牌状态----" + drawnCards);
|
log.info("已经是听牌状态----{}", drawnCards);
|
||||||
return String.valueOf(drawnCards);
|
return String.valueOf(drawnCards);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -627,7 +627,7 @@ public class ChangShaSuanFaTest {
|
||||||
if (isJiangPai(outcard)&&integers.size()>0){
|
if (isJiangPai(outcard)&&integers.size()>0){
|
||||||
return String.valueOf(integers.get(0));
|
return String.valueOf(integers.get(0));
|
||||||
}
|
}
|
||||||
System.out.println("最终出的牌------" + outcard);
|
log.info("最终出的牌------{}", outcard);
|
||||||
return String.valueOf(outcard);
|
return String.valueOf(outcard);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -657,8 +657,8 @@ public class ChangShaSuanFaTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("258将牌: " + is258Cards);
|
log.debug("258将牌: {}", is258Cards);
|
||||||
System.out.println("非258牌: " + non258Cards);
|
log.debug("非258牌: {}", non258Cards);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -763,7 +763,7 @@ public class ChangShaSuanFaTest {
|
||||||
cardCountMap.put(card, cardCountMap.getOrDefault(card, 0) + 1);
|
cardCountMap.put(card, cardCountMap.getOrDefault(card, 0) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("统计结果: " + cardCountMap);
|
log.debug("统计结果: {}", cardCountMap);
|
||||||
|
|
||||||
List<Integer> singleCards = new ArrayList<>();
|
List<Integer> singleCards = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -951,7 +951,7 @@ public class ChangShaSuanFaTest {
|
||||||
List<Integer> handCards2 = new ArrayList<>();
|
List<Integer> handCards2 = new ArrayList<>();
|
||||||
handCards2.addAll(handCards);
|
handCards2.addAll(handCards);
|
||||||
// handCards2.addAll(pengCard);
|
// handCards2.addAll(pengCard);
|
||||||
System.out.println("碰碰胡 handCards2 ++++++++++++++++" + handCards2);
|
log.debug("碰碰胡 handCards2 ++++++++++++++++{}", handCards2);
|
||||||
|
|
||||||
// 按花色分组
|
// 按花色分组
|
||||||
Map<Integer, List<Integer>> suitGroupMap = new HashMap<>();
|
Map<Integer, List<Integer>> suitGroupMap = new HashMap<>();
|
||||||
|
|
@ -2745,7 +2745,7 @@ public class ChangShaSuanFaTest {
|
||||||
for (Integer item : cardInHand) {
|
for (Integer item : cardInHand) {
|
||||||
countMap.put(item, countMap.getOrDefault(item, 0) + 1);
|
countMap.put(item, countMap.getOrDefault(item, 0) + 1);
|
||||||
}
|
}
|
||||||
System.out.println("countMap: " + countMap);
|
log.debug("countMap: {}", countMap);
|
||||||
int jiangnum = 0;
|
int jiangnum = 0;
|
||||||
for (int key : countMap.keySet()) {
|
for (int key : countMap.keySet()) {
|
||||||
if (isJiangPai(key) && countMap.get(key) == 2) {
|
if (isJiangPai(key) && countMap.get(key) == 2) {
|
||||||
|
|
@ -2868,7 +2868,7 @@ public class ChangShaSuanFaTest {
|
||||||
int suit = entry.getKey();
|
int suit = entry.getKey();
|
||||||
|
|
||||||
int count = entry.getValue();
|
int count = entry.getValue();
|
||||||
System.out.println("count:"+count);
|
log.debug("count:{}", count);
|
||||||
|
|
||||||
if (handcards.size()==13||handcards.size()==14){
|
if (handcards.size()==13||handcards.size()==14){
|
||||||
if (count >= 10) {
|
if (count >= 10) {
|
||||||
|
|
@ -2926,7 +2926,7 @@ public class ChangShaSuanFaTest {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static int suanfen(Map<Integer,ITObject>map){
|
public static int suanfen(Map<Integer,ITObject>map){
|
||||||
System.out.println("suanfen"+map);
|
log.debug("suanfen{}", map);
|
||||||
if (map.size()==0){
|
if (map.size()==0){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -2965,7 +2965,7 @@ public class ChangShaSuanFaTest {
|
||||||
if (entry.getValue().getInt("guzhang")>0){
|
if (entry.getValue().getInt("guzhang")>0){
|
||||||
tmp= tmp+entry.getValue().getInt("guzhang")*1;
|
tmp= tmp+entry.getValue().getInt("guzhang")*1;
|
||||||
}
|
}
|
||||||
System.out.println("tmp:"+tmp);
|
log.debug("tmp:{}", tmp);
|
||||||
fell.put(entry.getKey(), tmp);
|
fell.put(entry.getKey(), tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3028,7 +3028,7 @@ public class ChangShaSuanFaTest {
|
||||||
chiob.putInt("isDaHu",beforeIsDahu);
|
chiob.putInt("isDaHu",beforeIsDahu);
|
||||||
List checkCards = new ArrayList();
|
List checkCards = new ArrayList();
|
||||||
checkCards.addAll(yupanhandcard);
|
checkCards.addAll(yupanhandcard);
|
||||||
System.out.println("checkCards"+checkCards);
|
log.debug("checkCards{}", checkCards);
|
||||||
//去掉三张牌是否还能听牌
|
//去掉三张牌是否还能听牌
|
||||||
List<Integer> npeng = new ArrayList<>();
|
List<Integer> npeng = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -3228,7 +3228,7 @@ public class ChangShaSuanFaTest {
|
||||||
}
|
}
|
||||||
//检测是否有4对
|
//检测是否有4对
|
||||||
int duizi = countPairs(yupanhandcard);
|
int duizi = countPairs(yupanhandcard);
|
||||||
System.out.println("duizi:"+duizi);
|
log.debug("duizi:{}", duizi);
|
||||||
System.out.println(pengGrop);
|
System.out.println(pengGrop);
|
||||||
|
|
||||||
if (duizi==4&&pengGrop.size()>=0){
|
if (duizi==4&&pengGrop.size()>=0){
|
||||||
|
|
|
||||||
|
|
@ -131,8 +131,8 @@ public class EXGameController extends GameController {
|
||||||
try {
|
try {
|
||||||
String connecId = params.getString("connecId");
|
String connecId = params.getString("connecId");
|
||||||
TaurusClient client = getCsMjGameServerConnection(connecId);
|
TaurusClient client = getCsMjGameServerConnection(connecId);
|
||||||
System.out.println("接收来自robot_mgr的加入房间协议 connecId: = "+connecId);
|
log.info("接收来自robot_mgr的加入房间协议 connecId: {}", connecId);
|
||||||
System.out.println("接收来自robot_mgr的加入房间协议 client: = "+client);
|
log.info("接收来自robot_mgr的加入房间协议 client: {}", client);
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
ITObject errorResponse = TObject.newInstance();
|
ITObject errorResponse = TObject.newInstance();
|
||||||
errorResponse.putString("status", "failed");
|
errorResponse.putString("status", "failed");
|
||||||
|
|
@ -170,7 +170,7 @@ public class EXGameController extends GameController {
|
||||||
params.del("connecId");
|
params.del("connecId");
|
||||||
//发送加入房间请求到game_mj_cs
|
//发送加入房间请求到game_mj_cs
|
||||||
client.send(Config.JOIN_ROOM_CS, params, response -> {
|
client.send(Config.JOIN_ROOM_CS, params, response -> {
|
||||||
System.out.println("joinRoomController: " + response);
|
log.info("joinRoomController: {}", response);
|
||||||
RobotUser roomInfo = new RobotUser();
|
RobotUser roomInfo = new RobotUser();
|
||||||
roomInfo.setCurrentRoomId(Integer.parseInt(roomId));
|
roomInfo.setCurrentRoomId(Integer.parseInt(roomId));
|
||||||
roomInfo.setConnecId(connecId);
|
roomInfo.setConnecId(connecId);
|
||||||
|
|
@ -200,8 +200,8 @@ public class EXGameController extends GameController {
|
||||||
try {
|
try {
|
||||||
String connecId = params.getString("connecId");
|
String connecId = params.getString("connecId");
|
||||||
TaurusClient client = getCsMjGameServerConnection(connecId);
|
TaurusClient client = getCsMjGameServerConnection(connecId);
|
||||||
System.out.println("接收来自robot_mgr的机器人准备协议 connecId: = "+connecId);
|
log.info("接收来自robot_mgr的加入房间协议 connecId: {}", connecId);
|
||||||
System.out.println("接收来自robot_mgr的机器人准备协议 client: = "+client);
|
log.info("接收来自robot_mgr的加入房间协议 client: {}", client);
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
ITObject errorResponse = TObject.newInstance();
|
ITObject errorResponse = TObject.newInstance();
|
||||||
errorResponse.putString("status", "failed");
|
errorResponse.putString("status", "failed");
|
||||||
|
|
@ -214,7 +214,7 @@ public class EXGameController extends GameController {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
//发送准备请求到game_mj_cs
|
//发送准备请求到game_mj_cs
|
||||||
client.send(Config.GAME_READY_CS, params, response -> {
|
client.send(Config.GAME_READY_CS, params, response -> {
|
||||||
System.out.println("robotReadyRoom: " + response);
|
log.info("robotReadyRoom: {}", response);
|
||||||
});
|
});
|
||||||
|
|
||||||
ITObject paramsReq = TObject.newInstance();
|
ITObject paramsReq = TObject.newInstance();
|
||||||
|
|
@ -246,7 +246,7 @@ public class EXGameController extends GameController {
|
||||||
if (!robotUsers.isEmpty()) {
|
if (!robotUsers.isEmpty()) {
|
||||||
synchronized (robotUsers) {
|
synchronized (robotUsers) {
|
||||||
RobotUser robotUser = robotUsers.get(0);
|
RobotUser robotUser = robotUsers.get(0);
|
||||||
System.err.println("房间{"+ roomId +"}中Redis未找到机器人{"+robotId+"},但本地映射存在{"+robotUser.getRobotId()+"},清理本地映射");
|
log.error("房间{}中Redis未找到机器人{},但本地映射存在{}", roomId, robotId, robotId);
|
||||||
robotRoomMapping.remove(robotUser.getConnecId());
|
robotRoomMapping.remove(robotUser.getConnecId());
|
||||||
robotRoomMapping.remove(robotUser.getRobotId());
|
robotRoomMapping.remove(robotUser.getRobotId());
|
||||||
}
|
}
|
||||||
|
|
@ -261,16 +261,16 @@ public class EXGameController extends GameController {
|
||||||
|
|
||||||
if (robotId != existingRobotId) {
|
if (robotId != existingRobotId) {
|
||||||
//不同机器人的冲突
|
//不同机器人的冲突
|
||||||
System.err.println("房间{"+ roomId +"}中Redis已存在机器人{"+existingRobotId+"},当前机器人{"+robotId+"}不执行加入逻辑");
|
log.error("房间{}中Redis已存在机器人{},当前机器人{}不执行加入逻辑", roomId, existingRobotId, robotId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.err.println("225开始进房间: "+"room:"+ roomId +"robot:"+robotId);
|
log.info("225开始进房间: room:{} robot:{}", roomId, robotId);
|
||||||
//加入房间
|
//加入房间
|
||||||
joinRoomCommon(robotId, roomId, groupId, params);
|
joinRoomCommon(robotId, roomId, groupId, params);
|
||||||
System.err.println("225已进入房间准备成功: "+"room:"+ roomId +"robot:"+robotId);
|
log.info("225已进入房间准备成功: room:{} robot:{}", roomId, robotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -280,10 +280,10 @@ public class EXGameController extends GameController {
|
||||||
public void webGroupActive(Session session, ITObject params, int gid) {
|
public void webGroupActive(Session session, ITObject params, int gid) {
|
||||||
int robotId = params.getInt("robotid");
|
int robotId = params.getInt("robotid");
|
||||||
String roomId = params.getString("roomid");
|
String roomId = params.getString("roomid");
|
||||||
System.err.println("226开始进房间: " + "room:" + roomId + "robot:" + robotId);
|
log.info("226开始进房间 room: {} robot: {}", roomId, robotId);
|
||||||
//加入房间
|
//加入房间
|
||||||
joinRoomCommon(params.getInt("robotid"), params.getString("roomid"), params.getInt("groupid"), params);
|
joinRoomCommon(params.getInt("robotid"), params.getString("roomid"), params.getInt("groupid"), params);
|
||||||
System.err.println("226已进入房间准备成功: " + "room:" + roomId + "robot:" + robotId);
|
log.info("226已进入房间准备成功: room:{} robot:{}", roomId, robotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -310,15 +310,14 @@ public class EXGameController extends GameController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.err.println("重启后开始进房间: " + "room:" + robotUser.getCurrentRoomId() + "robot:" + robotUser.getRobotId());
|
log.info("重启后开始进房间: room:{}robot:{}", robotUser.getCurrentRoomId(), robotUser.getRobotId());
|
||||||
ITObject params = new TObject();
|
ITObject params = new TObject();
|
||||||
params.putString("session", "{user}:" + robotUser.getRobotId() + "," + robotSession);
|
params.putString("session", "{user}:" + robotUser.getRobotId() + "," + robotSession);
|
||||||
//加入房间
|
//加入房间
|
||||||
joinRoomCommon(Integer.parseInt(robotUser.getRobotId()), String.valueOf(robotUser.getCurrentRoomId()), Integer.parseInt(robotUser.getRobotGroupid()), params);
|
joinRoomCommon(Integer.parseInt(robotUser.getRobotId()), String.valueOf(robotUser.getCurrentRoomId()), Integer.parseInt(robotUser.getRobotGroupid()), params);
|
||||||
System.err.println("重启后已进入房间准备成功: " + "room:" + robotUser.getCurrentRoomId() + "robot:" + robotUser.getRobotId());
|
log.info("重启后已进入房间准备成功: room:{} robot:{}", robotUser.getCurrentRoomId(), robotUser.getRobotId());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// throw new RuntimeException(e);
|
log.error("重启后进房间时发生错误", e);
|
||||||
} finally {
|
} finally {
|
||||||
jedis0.close();
|
jedis0.close();
|
||||||
jedis2.close();
|
jedis2.close();
|
||||||
|
|
@ -342,8 +341,8 @@ public class EXGameController extends GameController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.err.println("开始进房间: room:" + roomId);
|
log.info("开始进房间: room:{}robot:{}", roomId, robotId);
|
||||||
System.err.println("开始进房间: {user}:" + robotId);
|
log.info("开始进房间: {user}:{}", robotId);
|
||||||
|
|
||||||
TaurusClient client = getCsMjGameServerConnection(roomId + "_" + robotId);
|
TaurusClient client = getCsMjGameServerConnection(roomId + "_" + robotId);
|
||||||
GroupRoomBusiness.joinRoom(groupId, "room:" + roomId, "{user}:" + robotId, null);
|
GroupRoomBusiness.joinRoom(groupId, "room:" + roomId, "{user}:" + robotId, null);
|
||||||
|
|
@ -371,11 +370,11 @@ public class EXGameController extends GameController {
|
||||||
robotRoomMapping.put(robotUser.getConnecId(), robotUser);
|
robotRoomMapping.put(robotUser.getConnecId(), robotUser);
|
||||||
robotConnectionManager.reconnectToGameServer(response, robotUser, client);
|
robotConnectionManager.reconnectToGameServer(response, robotUser, client);
|
||||||
});
|
});
|
||||||
System.err.println("已进入房间成功: " + robotUser.getConnecId());
|
log.info("已进入房间成功: {}", connecId);
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
if (client.isConnected()) {
|
if (client.isConnected()) {
|
||||||
client.send(Config.GAME_READY_CS, params, response -> {
|
client.send(Config.GAME_READY_CS, params, response -> {
|
||||||
System.out.println("1003:" + response);
|
log.info("1003: {}", response);
|
||||||
});
|
});
|
||||||
jedis2.hset("gallrobot", String.valueOf(robotUser.getRobotId()), "1");
|
jedis2.hset("gallrobot", String.valueOf(robotUser.getRobotId()), "1");
|
||||||
|
|
||||||
|
|
@ -389,13 +388,13 @@ public class EXGameController extends GameController {
|
||||||
scheduleDelay(() -> {
|
scheduleDelay(() -> {
|
||||||
//15秒后还没有建立映射关系 加入可能失败
|
//15秒后还没有建立映射关系 加入可能失败
|
||||||
if (robotRoomMapping.get(robotUser.getConnecId()) == null) {
|
if (robotRoomMapping.get(robotUser.getConnecId()) == null) {
|
||||||
System.err.println("机器人{"+robotId+"}加入房间{"+roomId+"}超时,清理临时状态");
|
log.info("机器人{{}}加入房间{{}}超时,清理临时状态", robotId, roomId);
|
||||||
robotConnectionManager.disconnectFromGameServer(connecId);
|
robotConnectionManager.disconnectFromGameServer(connecId);
|
||||||
}
|
}
|
||||||
}, 15, TimeUnit.SECONDS);
|
}, 15, TimeUnit.SECONDS);
|
||||||
//15秒后还没有建立映射关系 加入可能失败
|
//15秒后还没有建立映射关系 加入可能失败
|
||||||
if (robotRoomMapping.get(robotUser.getConnecId()) == null) {
|
if (robotRoomMapping.get(robotUser.getConnecId()) == null) {
|
||||||
System.err.println("机器人{"+robotId+"}加入房间{"+roomId+"}超时,清理临时状态");
|
log.info("机器人{}加入房间{}超时,清理临时状态", robotId, roomId);
|
||||||
robotConnectionManager.disconnectFromGameServer(connecId);
|
robotConnectionManager.disconnectFromGameServer(connecId);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -403,9 +402,9 @@ public class EXGameController extends GameController {
|
||||||
}
|
}
|
||||||
}, ThreadPoolConfig.getBusinessThreadPool());//指定自定义线程池
|
}, ThreadPoolConfig.getBusinessThreadPool());//指定自定义线程池
|
||||||
robotUser.setIntoRoomTime(robotConnectionManager.getTime());
|
robotUser.setIntoRoomTime(robotConnectionManager.getTime());
|
||||||
System.err.println("已进入房间准备成功: " + robotUser.getConnecId());
|
log.info("已进入房间成功: {}", robotUser.getConnecId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// throw new RuntimeException(e);
|
log.error("机器人加入房间失败", e);
|
||||||
} finally {
|
} finally {
|
||||||
jedis0.close();
|
jedis0.close();
|
||||||
jedis2.close();
|
jedis2.close();
|
||||||
|
|
@ -452,13 +451,13 @@ public class EXGameController extends GameController {
|
||||||
RobotUser removedUser = robotRoomMapping.remove(robotId);
|
RobotUser removedUser = robotRoomMapping.remove(robotId);
|
||||||
lastAccessTime.remove(robotId);
|
lastAccessTime.remove(robotId);
|
||||||
|
|
||||||
// 如果有连接ID,也一并清理
|
//如果有连接ID 也一并清理
|
||||||
if (removedUser != null && removedUser.getConnecId() != null) {
|
if (removedUser != null && removedUser.getConnecId() != null) {
|
||||||
robotRoomMapping.remove(removedUser.getConnecId());
|
robotRoomMapping.remove(removedUser.getConnecId());
|
||||||
lastAccessTime.remove(removedUser.getConnecId());
|
lastAccessTime.remove(removedUser.getConnecId());
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("清理机器人房间信息: " + robotId);
|
log.info("已删除机器人房间信息: {}", robotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -484,7 +483,7 @@ public class EXGameController extends GameController {
|
||||||
for (String connecId : expiredConnections) {
|
for (String connecId : expiredConnections) {
|
||||||
RobotUser robotUser = robotRoomMapping.get(connecId);
|
RobotUser robotUser = robotRoomMapping.get(connecId);
|
||||||
if (robotUser != null) {
|
if (robotUser != null) {
|
||||||
System.out.println("清理超时连接: " + connecId + ", 机器人ID: " + robotUser.getRobotId());
|
log.info("清理超时连接{}已超时,, 机器人ID: {}", connecId, robotUser.getRobotId());
|
||||||
robotConnectionManager.disconnectFromGameServer(connecId);
|
robotConnectionManager.disconnectFromGameServer(connecId);
|
||||||
}
|
}
|
||||||
robotRoomMapping.remove(connecId);
|
robotRoomMapping.remove(connecId);
|
||||||
|
|
@ -492,7 +491,7 @@ public class EXGameController extends GameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expiredConnections.isEmpty()) {
|
if (!expiredConnections.isEmpty()) {
|
||||||
System.out.println("本次清理了 " + expiredConnections.size() + " 个超时连接");
|
log.info("本次清理了 {} 个超时连接", expiredConnections.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -502,9 +501,9 @@ public class EXGameController extends GameController {
|
||||||
*/
|
*/
|
||||||
public static TaurusClient getCsMjGameServerConnection(String connecId) {
|
public static TaurusClient getCsMjGameServerConnection(String connecId) {
|
||||||
TaurusClient taurusClient = robotConnectionManager.getGameClient(connecId);
|
TaurusClient taurusClient = robotConnectionManager.getGameClient(connecId);
|
||||||
System.out.println("根据机器人ID和连接ID获取红中麻将游戏服务器连接 client: = "+taurusClient);
|
log.info("根据机器人ID和连接ID获取红中麻将游戏服务器连接 connecId: {}", connecId);
|
||||||
if (taurusClient != null) {
|
if (taurusClient != null) {
|
||||||
log.debug("成功获取游戏服务器连接,connecId: {}", connecId);
|
log.info("成功获取游戏服务器连接,connecId: {}", connecId);
|
||||||
return taurusClient;
|
return taurusClient;
|
||||||
}
|
}
|
||||||
taurusClient = robotConnectionManager.connectToGameServer(connecId);
|
taurusClient = robotConnectionManager.connectToGameServer(connecId);
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public class EXMainServer extends MainServer{
|
||||||
String robotskey = "g{"+Config.DEFAULT_GROUP_ID+"}:play:"+Config.DEFAULT_PID;
|
String robotskey = "g{"+Config.DEFAULT_GROUP_ID+"}:play:"+Config.DEFAULT_PID;
|
||||||
Map<String, String> maprobot = jedis2.hgetAll(robotskey);
|
Map<String, String> maprobot = jedis2.hgetAll(robotskey);
|
||||||
for(Map.Entry<String, String> entry : maprobot.entrySet()) {
|
for(Map.Entry<String, String> entry : maprobot.entrySet()) {
|
||||||
System.out.println(entry.getKey() + ":" + entry.getValue());
|
log.info("机器人配置 - {}: {}", entry.getKey(), entry.getValue());
|
||||||
//是否创建
|
//是否创建
|
||||||
RobotUser robotUser = new RobotUser();
|
RobotUser robotUser = new RobotUser();
|
||||||
robotUser.setRobotId(entry.getKey());
|
robotUser.setRobotId(entry.getKey());
|
||||||
|
|
@ -89,7 +89,7 @@ public class EXMainServer extends MainServer{
|
||||||
//5、干活
|
//5、干活
|
||||||
log.info("红中麻将机器人服务器已启动");
|
log.info("红中麻将机器人服务器已启动");
|
||||||
log.info("服务器将监听端口 {} 用于接收robot_mgr管理协议", gameSetting.port);
|
log.info("服务器将监听端口 {} 用于接收robot_mgr管理协议", gameSetting.port);
|
||||||
System.out.println("当前线程池配置: " + ThreadPoolConfig.getThreadPoolStatus());
|
log.info("当前线程池配置: {}", ThreadPoolConfig.getThreadPoolStatus());
|
||||||
|
|
||||||
jedis2.close();
|
jedis2.close();
|
||||||
}
|
}
|
||||||
|
|
@ -124,16 +124,16 @@ public class EXMainServer extends MainServer{
|
||||||
//每30秒执行一次资源清理
|
//每30秒执行一次资源清理
|
||||||
Thread.sleep(30000);
|
Thread.sleep(30000);
|
||||||
ResourceCleanupUtil.performCleanup();
|
ResourceCleanupUtil.performCleanup();
|
||||||
System.out.println("线程池状态: " + ThreadPoolConfig.getThreadPoolStatus());
|
log.info("线程池状态: {}", ThreadPoolConfig.getThreadPoolStatus());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
break;
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("资源清理任务异常: " + e.getMessage());
|
log.error("资源清理任务异常: {}", e.getMessage());
|
||||||
// 发生异常时尝试清理
|
// 发生异常时尝试清理
|
||||||
try {
|
try {
|
||||||
ResourceCleanupUtil.performCleanup();
|
ResourceCleanupUtil.performCleanup();
|
||||||
} catch (Exception cleanupEx) {
|
} catch (Exception cleanupEx) {
|
||||||
System.err.println("异常清理也失败: " + cleanupEx.getMessage());
|
log.error("异常清理也失败: {}", cleanupEx.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -141,7 +141,7 @@ public class EXMainServer extends MainServer{
|
||||||
|
|
||||||
cleanupThread.setDaemon(true);
|
cleanupThread.setDaemon(true);
|
||||||
cleanupThread.start();
|
cleanupThread.start();
|
||||||
System.out.println("资源清理定时任务已启动");
|
log.info("资源清理定时任务已启动");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,19 @@ package robot.mj;
|
||||||
|
|
||||||
import com.robot.data.Player;
|
import com.robot.data.Player;
|
||||||
import com.robot.data.Room;
|
import com.robot.data.Room;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EXPlayer extends Player {
|
public class EXPlayer extends Player {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(EXPlayer.class);
|
||||||
|
|
||||||
public EXPlayer(int playerid, Room table, String session_id) {
|
public EXPlayer(int playerid, Room table, String session_id) {
|
||||||
super(playerid, table, session_id);
|
super(playerid, table, session_id);
|
||||||
System.out.println("new robot ");
|
log.info("创建新的机器人玩家");
|
||||||
}
|
}
|
||||||
|
|
||||||
public EXRoom getRoom() {
|
public EXRoom getRoom() {
|
||||||
|
|
|
||||||
|
|
@ -72,13 +72,13 @@ public class RobotConnectionManager {
|
||||||
//从Redis恢复状态
|
//从Redis恢复状态
|
||||||
boolean restored = newInstance.restoreFromRedis(connecId);
|
boolean restored = newInstance.restoreFromRedis(connecId);
|
||||||
if (restored) {
|
if (restored) {
|
||||||
System.out.println("从Redis恢复HuNanHongZhong实例: " + connecId);
|
log.info("从Redis恢复HuNanHongZhong实例: " + connecId);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("创建新的HuNanHongZhong实例: " + connecId);
|
log.info("创建新的HuNanHongZhong实例: " + connecId);
|
||||||
}
|
}
|
||||||
|
|
||||||
huNanHongZhongInstances.put(connecId, newInstance);
|
huNanHongZhongInstances.put(connecId, newInstance);
|
||||||
System.out.println("当前HuNanHongZhong实例总数: " + huNanHongZhongInstances.size());
|
log.info("当前HuNanHongZhong实例总数: " + huNanHongZhongInstances.size());
|
||||||
return newInstance;
|
return newInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ public class RobotConnectionManager {
|
||||||
* 断开与游戏服务器的连接(主动断开)
|
* 断开与游戏服务器的连接(主动断开)
|
||||||
*/
|
*/
|
||||||
public void disconnectFromGameServer(String connecId) {
|
public void disconnectFromGameServer(String connecId) {
|
||||||
System.out.println("开始主动断开连接: {"+connecId+"}");
|
log.info("开始主动断开连接: {"+connecId+"}");
|
||||||
RobotUser robotUser = robotRoomMapping.remove(connecId);
|
RobotUser robotUser = robotRoomMapping.remove(connecId);
|
||||||
|
|
||||||
//标记连接为非活跃
|
//标记连接为非活跃
|
||||||
|
|
@ -130,13 +130,13 @@ public class RobotConnectionManager {
|
||||||
//清理所有集合数据以释放内存
|
//清理所有集合数据以释放内存
|
||||||
instance.getHongZhongCardInhand().clear();
|
instance.getHongZhongCardInhand().clear();
|
||||||
instance.getChuGuoCardInhand().clear();
|
instance.getChuGuoCardInhand().clear();
|
||||||
System.out.println("清空HuNanHongZhong集合数据: " + connecId);
|
log.info("清理HuNanHongZhong集合数据: " + connecId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//移除实例
|
//移除实例
|
||||||
huNanHongZhongInstances.remove(connecId);
|
huNanHongZhongInstances.remove(connecId);
|
||||||
|
|
||||||
System.out.println("清理完成,当前活跃连接数: " + activeConnections.size() + ", 实例数: " + huNanHongZhongInstances.size());
|
log.info("清理完成,当前活跃连接数: " + activeConnections.size() + ", 实例数: " + huNanHongZhongInstances.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (robotUser != null) {
|
if (robotUser != null) {
|
||||||
|
|
@ -146,12 +146,12 @@ public class RobotConnectionManager {
|
||||||
if (client.isConnected()) {
|
if (client.isConnected()) {
|
||||||
client.killConnection();
|
client.killConnection();
|
||||||
}
|
}
|
||||||
System.out.println("客户端主动断开连接完成: {"+connecId+"}");
|
log.info("客户端主动断开连接完成: {"+connecId+"}");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("断开客户端连接时发生异常: " + connecId + ", 错误: " + e.getMessage());
|
log.error("断开客户端连接时发生异常: " + connecId + ", 错误: " + e.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out.println("客户端连接不存在: {"+connecId+"}");
|
log.info("客户端连接不存在: {"+connecId+"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
//同时清理机器人房间映射
|
//同时清理机器人房间映射
|
||||||
|
|
@ -175,12 +175,12 @@ public class RobotConnectionManager {
|
||||||
|
|
||||||
//清理过期连接
|
//清理过期连接
|
||||||
for (String connecId : expiredConnections) {
|
for (String connecId : expiredConnections) {
|
||||||
System.out.println("清理过期连接实例: " + connecId);
|
log.info("清理过期连接实例: " + connecId);
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!expiredConnections.isEmpty()) {
|
if (!expiredConnections.isEmpty()) {
|
||||||
System.out.println("本次清理了 " + expiredConnections.size() + " 个过期连接实例");
|
log.info("本次清理了 " + expiredConnections.size() + " 个过期连接实例");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,7 +198,6 @@ public class RobotConnectionManager {
|
||||||
ITObject param = message.param;
|
ITObject param = message.param;
|
||||||
//回调协议号
|
//回调协议号
|
||||||
String command = message.command;
|
String command = message.command;
|
||||||
System.out.println("csmj OnEvent msg: " + command);
|
|
||||||
|
|
||||||
//根据玩法ID处理不同的回调
|
//根据玩法ID处理不同的回调
|
||||||
if (StringUtil.isNotEmpty(command)) {
|
if (StringUtil.isNotEmpty(command)) {
|
||||||
|
|
@ -245,10 +244,10 @@ public class RobotConnectionManager {
|
||||||
robotUser.setSeat(seat);
|
robotUser.setSeat(seat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("playerData:" + playerData);
|
log.info("playerData:" + playerData);
|
||||||
|
|
||||||
System.out.println("obj:" + obj);
|
log.info("obj:" + obj);
|
||||||
System.out.println("reloadInfo:" + reloadInfo);
|
log.info("reloadInfo:" + reloadInfo);
|
||||||
if (reloadInfo != null) {
|
if (reloadInfo != null) {
|
||||||
//重连回来的
|
//重连回来的
|
||||||
int curren_outcard_seat = reloadInfo.getInt("curren_outcard_seat");
|
int curren_outcard_seat = reloadInfo.getInt("curren_outcard_seat");
|
||||||
|
|
@ -274,7 +273,7 @@ public class RobotConnectionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("hcard>0" + hcard);
|
log.info("hcard>0" + hcard);
|
||||||
if (hcard.size() > 0) {
|
if (hcard.size() > 0) {
|
||||||
//同步手牌
|
//同步手牌
|
||||||
HuNanHongZhong currentInstance = getHuNanHongZhongInstance(connecId);
|
HuNanHongZhong currentInstance = getHuNanHongZhongInstance(connecId);
|
||||||
|
|
@ -284,9 +283,9 @@ public class RobotConnectionManager {
|
||||||
if (currentHand.isEmpty() || hcard.size() > currentHand.size()) {
|
if (currentHand.isEmpty() || hcard.size() > currentHand.size()) {
|
||||||
//手牌集合为空 或者 玩家出牌了
|
//手牌集合为空 或者 玩家出牌了
|
||||||
currentInstance.updateHandCard(hcard);
|
currentInstance.updateHandCard(hcard);
|
||||||
System.out.println("断线重连:同步手牌数据,服务器手牌:" + hcard);
|
log.info("断线重连:同步手牌数据,服务器手牌:" + hcard);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("断线重连:使用Redis恢复的手牌数据,数量:" + currentHand.size());
|
log.info("断线重连:使用Redis恢复的手牌数据,数量:" + currentHand.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outcard_list.size() > 0) {
|
if (outcard_list.size() > 0) {
|
||||||
|
|
@ -299,9 +298,9 @@ public class RobotConnectionManager {
|
||||||
List<Integer> currentOutCards = currentInstance.getChuGuoCardInhand();
|
List<Integer> currentOutCards = currentInstance.getChuGuoCardInhand();
|
||||||
if (currentOutCards.isEmpty() || outcards.size() > currentOutCards.size()) {
|
if (currentOutCards.isEmpty() || outcards.size() > currentOutCards.size()) {
|
||||||
currentInstance.updateOutCard(outcards);
|
currentInstance.updateOutCard(outcards);
|
||||||
System.out.println("断线重连:同步出牌数据,服务器出牌:" + outcards);
|
log.info("断线重连:同步出牌数据,服务器出牌:" + outcards);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("断线重连:使用Redis恢复的出牌数据,数量:" + currentOutCards.size());
|
log.info("断线重连:使用Redis恢复的出牌数据,数量:" + currentOutCards.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -311,7 +310,7 @@ public class RobotConnectionManager {
|
||||||
scheduleDelay(() -> {
|
scheduleDelay(() -> {
|
||||||
try {
|
try {
|
||||||
currentInstance.outCard(client);
|
currentInstance.outCard(client);
|
||||||
System.out.println("断线重连后成功执行出牌操作");
|
log.info("断线重连后成功执行出牌操作");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("断线重连后执行出牌操作时发生异常", e);
|
log.error("断线重连后执行出牌操作时发生异常", e);
|
||||||
//即使出牌失败,也要确保连接状态正确
|
//即使出牌失败,也要确保连接状态正确
|
||||||
|
|
@ -325,7 +324,7 @@ public class RobotConnectionManager {
|
||||||
}
|
}
|
||||||
}, 2, TimeUnit.SECONDS);
|
}, 2, TimeUnit.SECONDS);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("警告:重连时未获取到手牌数据");
|
log.info("警告:重连时未获取到手牌数据");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -348,7 +347,7 @@ public class RobotConnectionManager {
|
||||||
EXGameController.updateLastAccessTime(connecId);
|
EXGameController.updateLastAccessTime(connecId);
|
||||||
|
|
||||||
if (robotUser == null) {
|
if (robotUser == null) {
|
||||||
System.err.println("未找到机器人用户信息,连接ID: " + connecId);
|
log.info("未找到机器人用户信息,连接ID: " + connecId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -392,7 +391,7 @@ public class RobotConnectionManager {
|
||||||
else if ("817".equalsIgnoreCase(command)) {
|
else if ("817".equalsIgnoreCase(command)) {
|
||||||
huNanHongZhong.getHongZhongCardInhand().clear();
|
huNanHongZhong.getHongZhongCardInhand().clear();
|
||||||
huNanHongZhong.getChuGuoCardInhand().clear();
|
huNanHongZhong.getChuGuoCardInhand().clear();
|
||||||
System.out.println("红中结算");
|
log.info("红中结算");
|
||||||
Integer type = param.getInt("type");
|
Integer type = param.getInt("type");
|
||||||
if (type == 1 || type == 2) { //为1 为大结算 为2为解散,都需要恢复数据
|
if (type == 1 || type == 2) { //为1 为大结算 为2为解散,都需要恢复数据
|
||||||
//更新机器人剩余数量
|
//更新机器人剩余数量
|
||||||
|
|
@ -453,7 +452,7 @@ public class RobotConnectionManager {
|
||||||
//更新机器人剩余数量
|
//更新机器人剩余数量
|
||||||
updateLeftoverRobot(robotId);
|
updateLeftoverRobot(robotId);
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
System.out.println("2002发送退出房间协议1005,robotId: {"+robotId+"}");
|
log.info("2002发送退出房间协议1005,robotId: {"+robotId+"}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -462,7 +461,7 @@ public class RobotConnectionManager {
|
||||||
log.error("处理玩家加入房间检查时发生异常", e);
|
log.error("处理玩家加入房间检查时发生异常", e);
|
||||||
}
|
}
|
||||||
}, 6, TimeUnit.SECONDS);
|
}, 6, TimeUnit.SECONDS);
|
||||||
System.out.println("玩家{"+ robotUser.getCurrentRoomId()+"}加入房间:"+ param);
|
log.info("玩家{"+ robotUser.getCurrentRoomId()+"}加入房间:"+ param);
|
||||||
}
|
}
|
||||||
//玩家退出房间也要检查
|
//玩家退出房间也要检查
|
||||||
else if ("2002".equalsIgnoreCase(command)) {
|
else if ("2002".equalsIgnoreCase(command)) {
|
||||||
|
|
@ -490,7 +489,7 @@ public class RobotConnectionManager {
|
||||||
//更新机器人剩余数量
|
//更新机器人剩余数量
|
||||||
updateLeftoverRobot(robotId);
|
updateLeftoverRobot(robotId);
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
System.out.println("2002发送退出房间协议1005,robotId: {"+robotId+"}");
|
log.info("2002发送退出房间协议1005,robotId: {"+robotId+"}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -510,7 +509,7 @@ public class RobotConnectionManager {
|
||||||
//更新机器人剩余数量
|
//更新机器人剩余数量
|
||||||
updateLeftoverRobot(robotId);
|
updateLeftoverRobot(robotId);
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
System.out.println("2005玩家发送解散房间协议,robotId: {"+robotId+"}");
|
log.info("2005玩家发送解散房间协议,robotId: {"+robotId+"}");
|
||||||
}
|
}
|
||||||
//解散房间时候恢复机器人账号可以使用
|
//解散房间时候恢复机器人账号可以使用
|
||||||
else if ("2008".equalsIgnoreCase(command)) {
|
else if ("2008".equalsIgnoreCase(command)) {
|
||||||
|
|
@ -528,7 +527,7 @@ public class RobotConnectionManager {
|
||||||
|
|
||||||
//查询该房间的玩家信息
|
//查询该房间的玩家信息
|
||||||
String playersStr = jedis.hget(roomKey, "players");
|
String playersStr = jedis.hget(roomKey, "players");
|
||||||
if (!playersStr.equals("[]")) {
|
if (playersStr != null && !playersStr.equals("[]")) {
|
||||||
String players = playersStr.substring(1, playersStr.length() - 1);
|
String players = playersStr.substring(1, playersStr.length() - 1);
|
||||||
String[] playerIds = players.split(",");
|
String[] playerIds = players.split(",");
|
||||||
|
|
||||||
|
|
@ -544,18 +543,18 @@ public class RobotConnectionManager {
|
||||||
disconnectFromGameServer(connecId);
|
disconnectFromGameServer(connecId);
|
||||||
//更新机器人剩余数量
|
//更新机器人剩余数量
|
||||||
updateLeftoverRobot(paramRobotId);
|
updateLeftoverRobot(paramRobotId);
|
||||||
System.out.println("2009发送退出房间协议1005,robotId: {"+paramRobotId+"}");
|
log.info("2009发送退出房间协议1005,robotId: {"+paramRobotId+"}");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
System.err.println("2009协议数字格式异常,robotId: " + param.get("aid") + ", connecId: " + connecId);
|
log.error("2009协议数字格式异常,robotId: " + param.get("aid") + ", connecId: " + connecId);
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
System.err.println("2009协议空指针异常,connecId: " + connecId);
|
log.error("2009协议空指针异常,connecId: " + connecId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("2009协议处理异常: " + e.getMessage() + ", connecId: " + connecId);
|
log.error("2009协议处理异常: " + e.getMessage() + ", connecId: " + connecId);
|
||||||
} finally {
|
} finally {
|
||||||
if (jedis != null) {
|
if (jedis != null) {
|
||||||
jedis.close();
|
jedis.close();
|
||||||
|
|
@ -582,7 +581,7 @@ public class RobotConnectionManager {
|
||||||
|
|
||||||
jedis2.hset("{grobot}:" + robotId, "start", "0");
|
jedis2.hset("{grobot}:" + robotId, "start", "0");
|
||||||
|
|
||||||
System.out.println("机器人 {"+robotId+"} 退出房间,修改gallrobot为0");
|
log.info("机器人 {"+robotId+"} 退出房间,修改gallrobot为0");
|
||||||
} finally {
|
} finally {
|
||||||
jedis2.close();
|
jedis2.close();
|
||||||
}
|
}
|
||||||
|
|
@ -592,14 +591,14 @@ public class RobotConnectionManager {
|
||||||
* 机器人登录
|
* 机器人登录
|
||||||
*/
|
*/
|
||||||
public void login(RobotUser robotUser){
|
public void login(RobotUser robotUser){
|
||||||
System.out.println("login:"+robotUser.getRobotId());
|
log.info("开始机器人登录,robotId: {"+robotUser.getRobotId()+"}");
|
||||||
ITObject object = null;
|
ITObject object = null;
|
||||||
AccountBusiness accountBusiness = null;
|
AccountBusiness accountBusiness = null;
|
||||||
accountBusiness = new AccountBusiness();
|
accountBusiness = new AccountBusiness();
|
||||||
try {
|
try {
|
||||||
//先快速登录
|
//先快速登录
|
||||||
object = accountBusiness.fastLogin(Integer.parseInt(robotUser.getRobotId()));
|
object = accountBusiness.fastLogin(Integer.parseInt(robotUser.getRobotId()));
|
||||||
System.out.println("object:"+object);
|
log.info("机器人登录成功,robotId: {"+robotUser.getRobotId()+"}");
|
||||||
if(object==null){
|
if(object==null){
|
||||||
object = accountBusiness.idPasswordLogin(Integer.parseInt(robotUser.getRobotId()), robotUser.getPassword());
|
object = accountBusiness.idPasswordLogin(Integer.parseInt(robotUser.getRobotId()), robotUser.getPassword());
|
||||||
}
|
}
|
||||||
|
|
@ -621,7 +620,7 @@ public class RobotConnectionManager {
|
||||||
connectGame(robotUser);
|
connectGame(robotUser);
|
||||||
|
|
||||||
robotUser.setConnecId(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId());
|
robotUser.setConnecId(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId());
|
||||||
System.err.println("重启获取的机器人还有当前房间,准备加入: "+robotUser.getConnecId());
|
log.info("重启获取的机器人还有当前房间,准备加入: "+robotUser.getConnecId());
|
||||||
exGameController.webGroupJoinRoom(robotUser);
|
exGameController.webGroupJoinRoom(robotUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -648,12 +647,12 @@ public class RobotConnectionManager {
|
||||||
robotUser.setClient(client);
|
robotUser.setClient(client);
|
||||||
EXGameController.robotRoomMapping.put(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId(), robotUser);
|
EXGameController.robotRoomMapping.put(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId(), robotUser);
|
||||||
}else{
|
}else{
|
||||||
System.out.println("reconnect");
|
log.info("机器人已连接,准备加入房间");
|
||||||
System.out.println("client.isConnected()"+robotUser.getClient().isConnected());
|
log.info("client.isConnected()"+robotUser.getClient().isConnected());
|
||||||
if(robotUser.getClient().isConnected()){
|
if(robotUser.getClient().isConnected()){
|
||||||
robotUser.setIsconnect(true);
|
robotUser.setIsconnect(true);
|
||||||
}else{
|
}else{
|
||||||
System.out.println("reconnect"+robotUser.getClient().getGameID());
|
log.info("reconnect"+robotUser.getClient().getGameID());
|
||||||
TaurusClient client = new TaurusClient(robotUser.getGameHost()+":"+robotUser.getGamePort(), "hz"+robotUser.getRobotId(), TaurusClient.ConnectionProtocol.Tcp);
|
TaurusClient client = new TaurusClient(robotUser.getGameHost()+":"+robotUser.getGamePort(), "hz"+robotUser.getRobotId(), TaurusClient.ConnectionProtocol.Tcp);
|
||||||
client.setSession(robotUser.getLoginsession());
|
client.setSession(robotUser.getLoginsession());
|
||||||
client.connect();
|
client.connect();
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,7 @@ import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class AccountBusiness extends Controller {
|
public class AccountBusiness extends Controller {
|
||||||
private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(AccountBusiness.class);
|
private static final Logger log = Logger.getLogger(AccountBusiness.class);
|
||||||
private static Logger logger = Logger.getLogger(AccountBusiness.class);
|
|
||||||
|
|
||||||
private final ITObject fillLoginData(String session, int accountid) {
|
private final ITObject fillLoginData(String session, int accountid) {
|
||||||
ITObject resData = TObject.newInstance();
|
ITObject resData = TObject.newInstance();
|
||||||
|
|
@ -149,11 +148,11 @@ public class AccountBusiness extends Controller {
|
||||||
|
|
||||||
String idPwdBan = Redis.use("group1_db0").get(id + "_login_ban");
|
String idPwdBan = Redis.use("group1_db0").get(id + "_login_ban");
|
||||||
if (StringUtil.isNotEmpty(idPwdBan)) {
|
if (StringUtil.isNotEmpty(idPwdBan)) {
|
||||||
System.out.println("进入了77777777777777777777");
|
log.info("用户登录被禁止进入了77777777777777777777: {}", id);
|
||||||
logger.error("id:" + id + " ban login");
|
logger.error("id:" + id + " ban login");
|
||||||
//throw new WebException(ErrorCode.BAN_LOGIN);
|
//throw new WebException(ErrorCode.BAN_LOGIN);
|
||||||
}
|
}
|
||||||
System.out.println("进入了9999999999999");
|
log.debug("执行密码登录流程进入了9999999999999");
|
||||||
|
|
||||||
ITArray resultArray = null;
|
ITArray resultArray = null;
|
||||||
try {
|
try {
|
||||||
|
|
@ -176,13 +175,13 @@ public class AccountBusiness extends Controller {
|
||||||
Redis.use("group1_db0").set(id + "_login_ban", "1");
|
Redis.use("group1_db0").set(id + "_login_ban", "1");
|
||||||
Redis.use("group1_db0").expire(id + "_login_ban", 1800);
|
Redis.use("group1_db0").expire(id + "_login_ban", 1800);
|
||||||
logger.error("pwd error count:" + count + " not login");
|
logger.error("pwd error count:" + count + " not login");
|
||||||
System.out.println("进入了00000000000");
|
log.warn("密码错误次数过多,禁止登录: {}进入了00000000000", id);
|
||||||
|
|
||||||
//throw new WebException(ErrorCode._NO_SESSION);
|
//throw new WebException(ErrorCode._NO_SESSION);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("进入了111111111111");
|
log.debug("密码验证完成进入了111111111111");
|
||||||
|
|
||||||
//throw new WebException(ErrorCode._FAILED);
|
//throw new WebException(ErrorCode._FAILED);
|
||||||
}
|
}
|
||||||
|
|
@ -226,13 +225,13 @@ public class AccountBusiness extends Controller {
|
||||||
// logger.info("delte timeout token:" + temp);
|
// logger.info("delte timeout token:" + temp);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
System.out.println("进入了2222222222222");
|
log.debug("生成登录token完成进入了2222222222222");
|
||||||
|
|
||||||
long tokenNum = Redis.use("group1_db0").scard(session + "_token");
|
long tokenNum = Redis.use("group1_db0").scard(session + "_token");
|
||||||
if (tokenNum >= 10) {
|
if (tokenNum >= 10) {
|
||||||
logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum);
|
logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum);
|
||||||
}
|
}
|
||||||
System.out.println("进入了33333333333333333332");
|
log.debug("登录流程结束进入了33333333333333333332");
|
||||||
|
|
||||||
resData.putString("token", token);
|
resData.putString("token", token);
|
||||||
return resData;
|
return resData;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import com.taurus.core.entity.ITObject;
|
||||||
import com.taurus.core.entity.TObject;
|
import com.taurus.core.entity.TObject;
|
||||||
import com.taurus.core.plugin.redis.Redis;
|
import com.taurus.core.plugin.redis.Redis;
|
||||||
import com.taurus.core.util.StringUtil;
|
import com.taurus.core.util.StringUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import taurus.client.Message;
|
import taurus.client.Message;
|
||||||
import taurus.client.TaurusClient;
|
import taurus.client.TaurusClient;
|
||||||
|
|
@ -15,11 +17,11 @@ import taurus.util.HongZhongSuanFaTest;
|
||||||
import taurus.util.Util;
|
import taurus.util.Util;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
import static robot.mj.thread.ThreadPoolConfig.getBusinessThreadPool;
|
import static robot.mj.thread.ThreadPoolConfig.getBusinessThreadPool;
|
||||||
|
|
||||||
public class HuNanHongZhong {
|
public class HuNanHongZhong {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(HuNanHongZhong.class);
|
||||||
|
|
||||||
public static int hongZhongCard = 0;
|
public static int hongZhongCard = 0;
|
||||||
|
|
||||||
|
|
@ -74,9 +76,9 @@ public class HuNanHongZhong {
|
||||||
//1小时过期时间
|
//1小时过期时间
|
||||||
jedis.expire(redisKey, 3600);
|
jedis.expire(redisKey, 3600);
|
||||||
|
|
||||||
System.out.println("保存HuNanHongZhong状态到Redis: " + connecId);
|
log.info("保存HuNanHongZhong状态到Redis: {}", connecId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("保存HuNanHongZhong状态到Redis失败: " + e.getMessage());
|
log.error("保存HuNanHongZhong状态到Redis失败: {}", e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
jedis.close();
|
jedis.close();
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +96,7 @@ public class HuNanHongZhong {
|
||||||
Map<String, String> stateMap = jedis.hgetAll(redisKey);
|
Map<String, String> stateMap = jedis.hgetAll(redisKey);
|
||||||
|
|
||||||
if (stateMap == null || stateMap.isEmpty()) {
|
if (stateMap == null || stateMap.isEmpty()) {
|
||||||
System.out.println("Redis中没有找到HuNanHongZhong状态数据: " + connecId);
|
log.warn("Redis中没有找到HuNanHongZhong状态数据: {}", connecId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,10 +119,10 @@ public class HuNanHongZhong {
|
||||||
session = stateMap.getOrDefault("session", "");
|
session = stateMap.getOrDefault("session", "");
|
||||||
token = stateMap.getOrDefault("token", "");
|
token = stateMap.getOrDefault("token", "");
|
||||||
|
|
||||||
System.out.println("从Redis恢复HuNanHongZhong状态成功: " + connecId + ", 手牌数量: " + hongZhongchuguopai.size());
|
log.info("从Redis恢复HuNanHongZhong状态成功: {}, 手牌数量: {}", connecId, hongZhongchuguopai.size());
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("从Redis恢复HuNanHongZhong状态失败: " + e.getMessage());
|
log.error("从Redis恢复HuNanHongZhong状态失败: {}", e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
jedis.close();
|
jedis.close();
|
||||||
|
|
@ -136,9 +138,9 @@ public class HuNanHongZhong {
|
||||||
try {
|
try {
|
||||||
String redisKey = "{hzmj}:" + connecId;
|
String redisKey = "{hzmj}:" + connecId;
|
||||||
jedis.del(redisKey);
|
jedis.del(redisKey);
|
||||||
System.out.println("从Redis删除HuNanHongZhong状态: " + connecId);
|
log.info("从Redis删除HuNanHongZhong状态: {}", connecId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("从Redis删除HuNanHongZhong状态失败: " + e.getMessage());
|
log.error("从Redis删除HuNanHongZhong状态失败: {}", e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
jedis.close();
|
jedis.close();
|
||||||
}
|
}
|
||||||
|
|
@ -149,11 +151,11 @@ public class HuNanHongZhong {
|
||||||
* @param handCard
|
* @param handCard
|
||||||
*/
|
*/
|
||||||
public void updateHandCard(List<Integer> handCard) {
|
public void updateHandCard(List<Integer> handCard) {
|
||||||
System.out.println("updateHandCard同步手牌:"+ handCard);
|
log.info("updateHandCard同步手牌: {}", handCard);
|
||||||
hongZhongCardInhand.clear();
|
hongZhongCardInhand.clear();
|
||||||
System.out.println("updateHandCard同步手牌hongZhongCardInhand:"+ hongZhongCardInhand);
|
log.debug("updateHandCard同步手牌hongZhongCardInhand: {}", hongZhongCardInhand);
|
||||||
hongZhongCardInhand.addAll(handCard);
|
hongZhongCardInhand.addAll(handCard);
|
||||||
System.out.println("updateHandCard同步手牌add:"+ hongZhongCardInhand);
|
log.info("updateHandCard同步手牌add: {}", hongZhongCardInhand);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateOutCard(List<Integer> outCard) {
|
public void updateOutCard(List<Integer> outCard) {
|
||||||
|
|
@ -175,8 +177,8 @@ public class HuNanHongZhong {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
hongZhongCard = param.getInt("card");
|
hongZhongCard = param.getInt("card");
|
||||||
System.out.println("出牌广播" + hongZhongCard);
|
log.info("出牌广播: {}", hongZhongCard);
|
||||||
System.out.println("座位号:" + param.getInt("seat") + "的用户出牌:" + param.getInt("card"));
|
log.info("座位号:{}的用户出牌:{}", param.getInt("seat"), param.getInt("card"));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -190,28 +192,28 @@ public class HuNanHongZhong {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getCard(String command, Message message) {
|
public String getCard(String command, Message message) {
|
||||||
System.out.println("摸牌协议-----" + command + "message---" + message);
|
log.info("摸牌协议-----{} message---{}", command, message);
|
||||||
if (command.equalsIgnoreCase("819")) {
|
if (command.equalsIgnoreCase("819")) {
|
||||||
ITObject param = message.param;
|
ITObject param = message.param;
|
||||||
if (param == null) {
|
if (param == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// {seat=2, Ishupai=0, isBaoTing=-1, tingcard=0, isgang=0, card=101, left_count=106}
|
// {seat=2, Ishupai=0, isBaoTing=-1, tingcard=0, isgang=0, card=101, left_count=106}
|
||||||
System.out.println("轮到用户:" + param.getInt("player") + "的用户摸牌" + ",牌为:" + param.getInt("card"));
|
log.info("轮到用户:{}的用户摸牌, 牌为:{}", param.getInt("player"), param.getInt("card"));
|
||||||
System.out.println("用户id" + playerId);
|
log.debug("用户id: {}", playerId);
|
||||||
System.out.println("座位号" + param.getInt("seat"));
|
log.debug("座位号: {}", param.getInt("seat"));
|
||||||
if (param.getInt("player") != null) {
|
if (param.getInt("player") != null) {
|
||||||
int drawnCard = param.getInt("card");
|
int drawnCard = param.getInt("card");
|
||||||
|
|
||||||
hongZhongSuanFaTest.drawnCards = drawnCard;
|
hongZhongSuanFaTest.drawnCards = drawnCard;
|
||||||
hongZhongCardInhand.add(drawnCard);
|
hongZhongCardInhand.add(drawnCard);
|
||||||
System.out.println("摸牌后手牌" + hongZhongCardInhand);
|
log.info("摸牌后手牌: {}", hongZhongCardInhand);
|
||||||
|
|
||||||
// 创建包含摸牌后的完整手牌
|
// 创建包含摸牌后的完整手牌
|
||||||
List<Integer> newHand = new ArrayList<>(hongZhongCardInhand);
|
List<Integer> newHand = new ArrayList<>(hongZhongCardInhand);
|
||||||
|
|
||||||
// 调用分离分析方法,将刻子、顺子、红中单独拎出后分析剩余牌
|
// 调用分离分析方法,将刻子、顺子、红中单独拎出后分析剩余牌
|
||||||
System.out.println("[HuNanHongZhong] 开始分离分析手牌结构...");
|
log.info("[HuNanHongZhong] 开始分离分析手牌结构...");
|
||||||
hongZhongSuanFaTest.separateAndAnalyzeHand(newHand);
|
hongZhongSuanFaTest.separateAndAnalyzeHand(newHand);
|
||||||
|
|
||||||
// 直接调用hongZhongSuanFaTest中的analyzeDrawCard方法分析摸牌后是否可听牌
|
// 直接调用hongZhongSuanFaTest中的analyzeDrawCard方法分析摸牌后是否可听牌
|
||||||
|
|
@ -219,15 +221,15 @@ public class HuNanHongZhong {
|
||||||
|
|
||||||
|
|
||||||
// 调用新添加的findDiscardToTing方法,分析打出哪张牌可以听牌
|
// 调用新添加的findDiscardToTing方法,分析打出哪张牌可以听牌
|
||||||
System.out.println("[HuNanHongZhong] 开始分析打出哪张牌可以听牌...");
|
log.info("[HuNanHongZhong] 开始分析打出哪张牌可以听牌...");
|
||||||
Map<Integer, Set<Integer>> discardOptions = hongZhongSuanFaTest.findDiscardToTing(newHand);
|
Map<Integer, Set<Integer>> discardOptions = hongZhongSuanFaTest.findDiscardToTing(newHand);
|
||||||
|
|
||||||
// 如果有可打出后听牌的选项,记录信息
|
// 如果有可打出后听牌的选项,记录信息
|
||||||
if (!discardOptions.isEmpty()) {
|
if (!discardOptions.isEmpty()) {
|
||||||
System.out.println("[HuNanHongZhong] 发现" + discardOptions.size() + "个可打出后听牌的选项");
|
log.info("[HuNanHongZhong] 发现{}个可打出后听牌的选项", discardOptions.size());
|
||||||
// 这些信息将在出牌决策时被考虑
|
// 这些信息将在出牌决策时被考虑
|
||||||
} else {
|
} else {
|
||||||
System.out.println("[HuNanHongZhong] 当前没有可以打出后听牌的牌");
|
log.info("[HuNanHongZhong] 当前没有可以打出后听牌的牌");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -241,7 +243,7 @@ public class HuNanHongZhong {
|
||||||
* @return 是否应该碰牌
|
* @return 是否应该碰牌
|
||||||
*/
|
*/
|
||||||
public boolean shouldPong(int proposedCard) {
|
public boolean shouldPong(int proposedCard) {
|
||||||
System.out.println("判断是否应该碰牌: " + proposedCard);
|
log.debug("判断是否应该碰牌: {}", proposedCard);
|
||||||
|
|
||||||
// 直接调用hongZhongSuanFaTest中的shouldPong方法,它已经包含了所有需要的规则
|
// 直接调用hongZhongSuanFaTest中的shouldPong方法,它已经包含了所有需要的规则
|
||||||
return hongZhongSuanFaTest.shouldPong(proposedCard, hongZhongCardInhand);
|
return hongZhongSuanFaTest.shouldPong(proposedCard, hongZhongCardInhand);
|
||||||
|
|
@ -267,9 +269,9 @@ public class HuNanHongZhong {
|
||||||
}
|
}
|
||||||
if (hongZhongCardInhand.size() > 13) {
|
if (hongZhongCardInhand.size() > 13) {
|
||||||
outCard(client);
|
outCard(client);
|
||||||
System.out.println("机器人:" + param.getInt("seat") + "为庄家,需要出牌" + ",牌为:" + hongZhongCardInhand.get(0));
|
log.info("机器人:{}为庄家,需要出牌, 牌为:{}", param.getInt("seat"), hongZhongCardInhand.get(0));
|
||||||
}
|
}
|
||||||
System.out.println("机器人:" + param.getInt("seat") + "初始化手牌" + ",牌为:" + hongZhongCardInhand.toString());
|
log.info("机器人:{}初始化手牌, 牌为:{}", param.getInt("seat"), hongZhongCardInhand.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -293,8 +295,8 @@ public class HuNanHongZhong {
|
||||||
id = firstTip.getInt("id");
|
id = firstTip.getInt("id");
|
||||||
type = firstTip.getInt("type");
|
type = firstTip.getInt("type");
|
||||||
opcard = firstTip.getTArray("opcard").getInt(0);
|
opcard = firstTip.getTArray("opcard").getInt(0);
|
||||||
System.out.println("id ++ " + id);
|
log.debug("id ++ {}", id);
|
||||||
System.out.println("type ++ " + type);
|
log.debug("type ++ {}", type);
|
||||||
}
|
}
|
||||||
//弃 是根据算法选择是否要弃掉 不进行碰杠胡
|
//弃 是根据算法选择是否要弃掉 不进行碰杠胡
|
||||||
//params.putInt("qi", 0);
|
//params.putInt("qi", 0);
|
||||||
|
|
@ -308,12 +310,12 @@ public class HuNanHongZhong {
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 1);
|
params.putInt("id", 1);
|
||||||
Util.removeCard(hongZhongCardInhand, opcard, 2);
|
Util.removeCard(hongZhongCardInhand, opcard, 2);
|
||||||
System.out.println("执行碰牌并删除碰的牌");
|
log.info("执行碰牌并删除碰的牌");
|
||||||
} else {
|
} else {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 1); // 放弃碰牌
|
params.putInt("qi", 1); // 放弃碰牌
|
||||||
params.putInt("id", 0);
|
params.putInt("id", 0);
|
||||||
System.out.println("根据规则,决定不碰牌: " + opcard);
|
log.info("根据规则,决定不碰牌: {}", opcard);
|
||||||
}
|
}
|
||||||
// Global.logger.info("删除碰的牌");
|
// Global.logger.info("删除碰的牌");
|
||||||
//执行胡牌
|
//执行胡牌
|
||||||
|
|
@ -321,46 +323,46 @@ public class HuNanHongZhong {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 1);
|
params.putInt("id", 1);
|
||||||
System.out.println("执行胡牌");
|
log.info("执行胡牌");
|
||||||
//执行吃杠
|
//执行吃杠
|
||||||
} else if (type == 3) {
|
} else if (type == 3) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 1);
|
params.putInt("id", 1);
|
||||||
Util.removeCard(hongZhongCardInhand, opcard, 3);
|
Util.removeCard(hongZhongCardInhand, opcard, 3);
|
||||||
System.out.println("执行吃杠");
|
log.info("执行吃杠");
|
||||||
//执行自杠
|
//执行自杠
|
||||||
} else if (type == 4) {
|
} else if (type == 4) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 1);
|
params.putInt("id", 1);
|
||||||
Util.removeCard(hongZhongCardInhand, opcard, 4);
|
Util.removeCard(hongZhongCardInhand, opcard, 4);
|
||||||
System.out.println("执行自杠");
|
log.info("执行自杠");
|
||||||
// 碰后补杠
|
// 碰后补杠
|
||||||
} else if (type == 5) {
|
} else if (type == 5) {
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
params.putInt("qi", 0);
|
params.putInt("qi", 0);
|
||||||
params.putInt("id", 1);
|
params.putInt("id", 1);
|
||||||
Util.removeCard(hongZhongCardInhand, opcard, 1);
|
Util.removeCard(hongZhongCardInhand, opcard, 1);
|
||||||
System.out.println("执行碰后补杠");
|
log.info("执行碰后补杠");
|
||||||
}
|
}
|
||||||
|
|
||||||
// cardInhand.remove(0);
|
// cardInhand.remove(0);
|
||||||
// cardInhand.remove(1);
|
// cardInhand.remove(1);
|
||||||
System.out.println("执行id为:" + 0 + "的操作");
|
log.info("执行id为:{}的操作", 0);
|
||||||
|
|
||||||
//使用线程池执行延迟动作
|
//使用线程池执行延迟动作
|
||||||
getBusinessThreadPool().execute(() -> {
|
getBusinessThreadPool().execute(() -> {
|
||||||
try {
|
try {
|
||||||
int delaySeconds = 1 + new Random().nextInt(2);
|
int delaySeconds = 1 + new Random().nextInt(2);
|
||||||
System.out.println("执行延迟" + delaySeconds + "秒");
|
log.debug("执行延迟{}秒", delaySeconds);
|
||||||
Thread.sleep(delaySeconds * 1000);
|
Thread.sleep(delaySeconds * 1000);
|
||||||
|
|
||||||
client.send("612", params, response -> {
|
client.send("612", params, response -> {
|
||||||
|
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("执行动作时发生异常: " + e.getMessage());
|
log.error("执行动作时发生异常: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -373,7 +375,7 @@ public class HuNanHongZhong {
|
||||||
if (param == null) {
|
if (param == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
System.out.println("出牌权转移到座位号:" + param.getInt("seat") + "的用户");
|
log.info("出牌权转移到座位号:{}的用户", param.getInt("seat"));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -385,7 +387,7 @@ public class HuNanHongZhong {
|
||||||
public String outCard(TaurusClient client) {
|
public String outCard(TaurusClient client) {
|
||||||
// 调用分离分析方法,将刻子、顺子、红中单独拎出后分析剩余牌
|
// 调用分离分析方法,将刻子、顺子、红中单独拎出后分析剩余牌
|
||||||
try {
|
try {
|
||||||
System.out.println("[HuNanHongZhong] 出牌前分离分析手牌结构...");
|
log.info("[HuNanHongZhong] 出牌前分离分析手牌结构...");
|
||||||
hongZhongSuanFaTest.separateAndAnalyzeHand(hongZhongCardInhand);
|
hongZhongSuanFaTest.separateAndAnalyzeHand(hongZhongCardInhand);
|
||||||
|
|
||||||
// 红中麻将出牌
|
// 红中麻将出牌
|
||||||
|
|
@ -409,13 +411,13 @@ public class HuNanHongZhong {
|
||||||
params.putTArray("outcard_list", CardUtil.maJiangToTArray(cardsToSend));
|
params.putTArray("outcard_list", CardUtil.maJiangToTArray(cardsToSend));
|
||||||
}
|
}
|
||||||
params.putTArray("card_list", CardUtil.maJiangToTArray(hongZhongCardInhand));
|
params.putTArray("card_list", CardUtil.maJiangToTArray(hongZhongCardInhand));
|
||||||
System.out.println("机器人牌============" + params);
|
log.info("机器人牌============{}", params);
|
||||||
// 将当前出的牌添加到历史出牌列表
|
// 将当前出的牌添加到历史出牌列表
|
||||||
hongZhongchuguopai.add(cardToOut);
|
hongZhongchuguopai.add(cardToOut);
|
||||||
// 从手牌中移除
|
// 从手牌中移除
|
||||||
hongZhongCardInhand.remove(Integer.valueOf(cardToOut));
|
hongZhongCardInhand.remove(Integer.valueOf(cardToOut));
|
||||||
System.out.println("出牌: " + cardToOut);
|
log.info("出牌: {}", cardToOut);
|
||||||
System.out.println("目前机器人剩余手牌:" + hongZhongCardInhand.toString());
|
log.info("目前机器人剩余手牌:{}", hongZhongCardInhand.toString());
|
||||||
params.putString("session", session + "," + token);
|
params.putString("session", session + "," + token);
|
||||||
|
|
||||||
//使用线程池替代CompletableFuture.runAsync + Thread.sleep
|
//使用线程池替代CompletableFuture.runAsync + Thread.sleep
|
||||||
|
|
@ -427,7 +429,7 @@ public class HuNanHongZhong {
|
||||||
|
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Thread error");
|
log.error("线程执行错误");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -451,14 +453,14 @@ public class HuNanHongZhong {
|
||||||
Integer card = param.getInt("card"); // 操作牌值
|
Integer card = param.getInt("card"); // 操作牌值
|
||||||
Integer type = param.getInt("type"); // 操作类型
|
Integer type = param.getInt("type"); // 操作类型
|
||||||
Integer from_seat = param.getInt("from_seat"); // 牌来源座位
|
Integer from_seat = param.getInt("from_seat"); // 牌来源座位
|
||||||
System.out.println("删除出过的牌组 card " + card);
|
log.debug("删除出过的牌组 card: {}", card);
|
||||||
System.out.println("删除出过的牌组 type " + type);
|
log.debug("删除出过的牌组 type: {}", type);
|
||||||
System.out.println("删除出过的牌组 from_seat " + from_seat);
|
log.debug("删除出过的牌组 from_seat: {}", from_seat);
|
||||||
System.out.println("机器人 seat " + seat);
|
log.debug("机器人 seat: {}", seat);
|
||||||
|
|
||||||
if (type == 2 || type == 3 || type == 5) { // 碰,杠
|
if (type == 2 || type == 3 || type == 5) { // 碰,杠
|
||||||
getChuGuoCardInhand().remove(Integer.valueOf(card));
|
getChuGuoCardInhand().remove(Integer.valueOf(card));
|
||||||
System.out.println("删除出过的牌组 成功");
|
log.info("删除出过的牌组 成功");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package robot.mj.thread;
|
||||||
|
|
||||||
|
|
||||||
import robot.mj.EXGameController;
|
import robot.mj.EXGameController;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
@ -11,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
* 用于管理和清理不再使用的资源 防止内存泄漏
|
* 用于管理和清理不再使用的资源 防止内存泄漏
|
||||||
*/
|
*/
|
||||||
public class ResourceCleanupUtil {
|
public class ResourceCleanupUtil {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ResourceCleanupUtil.class);
|
||||||
|
|
||||||
//需要清理的资源
|
//需要清理的资源
|
||||||
private static final Set<String> pendingCleanupResources = ConcurrentHashMap.newKeySet();
|
private static final Set<String> pendingCleanupResources = ConcurrentHashMap.newKeySet();
|
||||||
|
|
@ -26,7 +29,7 @@ public class ResourceCleanupUtil {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("开始执行资源清理,待清理资源数: " + pendingCleanupResources.size());
|
log.info("开始执行资源清理,待清理资源数: {}", pendingCleanupResources.size());
|
||||||
int cleanedCount = 0;
|
int cleanedCount = 0;
|
||||||
|
|
||||||
Set<String> resourcesToClean = ConcurrentHashMap.newKeySet();
|
Set<String> resourcesToClean = ConcurrentHashMap.newKeySet();
|
||||||
|
|
@ -41,13 +44,13 @@ public class ResourceCleanupUtil {
|
||||||
pendingCleanupResources.remove(resourceId);
|
pendingCleanupResources.remove(resourceId);
|
||||||
cleanedCount++;
|
cleanedCount++;
|
||||||
|
|
||||||
System.out.println("已清理资源: " + resourceId);
|
log.info("已清理资源: {}", resourceId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("清理资源时发生异常: " + resourceId + ", 错误: " + e.getMessage());
|
log.error("清理资源时发生异常: {}, 错误: {}", resourceId, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("资源清理完成,共清理: " + cleanedCount + " 个资源");
|
log.info("资源清理完成,共清理: {} 个资源", cleanedCount);
|
||||||
|
|
||||||
//执行常规清理
|
//执行常规清理
|
||||||
performRegularCleanup();
|
performRegularCleanup();
|
||||||
|
|
@ -62,11 +65,11 @@ public class ResourceCleanupUtil {
|
||||||
EXGameController.cleanupExpiredConnections();
|
EXGameController.cleanupExpiredConnections();
|
||||||
|
|
||||||
//输出当前系统状态
|
//输出当前系统状态
|
||||||
System.out.println("=== 系统资源状态 ===");
|
log.info("=== 系统资源状态 ===");
|
||||||
System.out.println(ThreadPoolConfig.getThreadPoolStatus());
|
log.info("{}", ThreadPoolConfig.getThreadPoolStatus());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("执行常规清理时发生异常: " + e.getMessage());
|
log.error("执行常规清理时发生异常: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package robot.mj.thread;
|
package robot.mj.thread;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
|
@ -7,6 +10,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
* 线程池配置类
|
* 线程池配置类
|
||||||
*/
|
*/
|
||||||
public class ThreadPoolConfig {
|
public class ThreadPoolConfig {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ThreadPoolConfig.class);
|
||||||
|
|
||||||
//线程池配置
|
//线程池配置
|
||||||
private static final ExecutorService BUSINESS_THREAD_POOL =
|
private static final ExecutorService BUSINESS_THREAD_POOL =
|
||||||
|
|
@ -54,14 +58,14 @@ public class ThreadPoolConfig {
|
||||||
* 执行延迟任务,替代Thread.sleep
|
* 执行延迟任务,替代Thread.sleep
|
||||||
*/
|
*/
|
||||||
public static void scheduleDelay(Runnable task, long delay, TimeUnit unit) {
|
public static void scheduleDelay(Runnable task, long delay, TimeUnit unit) {
|
||||||
System.out.println("提交延迟任务: 延迟" + delay + " " + unit + ", 当前时间: " + System.currentTimeMillis());
|
log.debug("提交延迟任务: 延迟{} {}, 当前时间: {}", delay, unit, System.currentTimeMillis());
|
||||||
SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
|
SCHEDULED_EXECUTOR_SERVICE.schedule(() -> {
|
||||||
try {
|
try {
|
||||||
System.out.println("执行延迟任务开始: 当前时间: " + System.currentTimeMillis());
|
log.debug("执行延迟任务开始: 当前时间: {}", System.currentTimeMillis());
|
||||||
task.run();
|
task.run();
|
||||||
System.out.println("执行延迟任务完成: 当前时间: " + System.currentTimeMillis());
|
log.debug("执行延迟任务完成: 当前时间: {}", System.currentTimeMillis());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("延迟任务执行异常: " + e.getMessage());
|
log.error("延迟任务执行异常: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
}, delay, unit);
|
}, delay, unit);
|
||||||
}
|
}
|
||||||
|
|
@ -70,13 +74,13 @@ public class ThreadPoolConfig {
|
||||||
* 关闭线程池 释放资源
|
* 关闭线程池 释放资源
|
||||||
*/
|
*/
|
||||||
public static void shutdown() {
|
public static void shutdown() {
|
||||||
System.out.println("开始关闭线程池...");
|
log.info("开始关闭线程池...");
|
||||||
|
|
||||||
//关闭定时任务线程池
|
//关闭定时任务线程池
|
||||||
SCHEDULED_EXECUTOR_SERVICE.shutdown();
|
SCHEDULED_EXECUTOR_SERVICE.shutdown();
|
||||||
try {
|
try {
|
||||||
if (!SCHEDULED_EXECUTOR_SERVICE.awaitTermination(3, TimeUnit.SECONDS)) {
|
if (!SCHEDULED_EXECUTOR_SERVICE.awaitTermination(3, TimeUnit.SECONDS)) {
|
||||||
System.out.println("定时任务线程池强制关闭");
|
log.warn("定时任务线程池强制关闭");
|
||||||
SCHEDULED_EXECUTOR_SERVICE.shutdownNow();
|
SCHEDULED_EXECUTOR_SERVICE.shutdownNow();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
@ -88,7 +92,7 @@ public class ThreadPoolConfig {
|
||||||
BUSINESS_THREAD_POOL.shutdown();
|
BUSINESS_THREAD_POOL.shutdown();
|
||||||
try {
|
try {
|
||||||
if (!BUSINESS_THREAD_POOL.awaitTermination(5, TimeUnit.SECONDS)) {
|
if (!BUSINESS_THREAD_POOL.awaitTermination(5, TimeUnit.SECONDS)) {
|
||||||
System.out.println("业务线程池强制关闭");
|
log.warn("业务线程池强制关闭");
|
||||||
BUSINESS_THREAD_POOL.shutdownNow();
|
BUSINESS_THREAD_POOL.shutdownNow();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
@ -96,7 +100,7 @@ public class ThreadPoolConfig {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("线程池关闭完成");
|
log.info("线程池关闭完成");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
package taurus.util;
|
package taurus.util;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class HongZhongSuanFaTest {
|
public class HongZhongSuanFaTest {
|
||||||
private static final int HONG_ZHONG = 412;
|
private static final int HONG_ZHONG = 412;
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(HongZhongSuanFaTest.class);
|
||||||
|
|
||||||
public int drawnCards;
|
public int drawnCards;
|
||||||
// 权重配置 -
|
// 权重配置 -
|
||||||
|
|
@ -57,7 +61,7 @@ public class HongZhongSuanFaTest {
|
||||||
// 关键步骤1:摸牌分析 - 检测是否已经听牌或可听牌
|
// 关键步骤1:摸牌分析 - 检测是否已经听牌或可听牌
|
||||||
boolean isTingAfterDraw = analyzeDrawCard(cardInhand,drawnCards);
|
boolean isTingAfterDraw = analyzeDrawCard(cardInhand,drawnCards);
|
||||||
|
|
||||||
System.out.println("是否听牌: " + isTingAfterDraw);
|
log.info("是否听牌: " + isTingAfterDraw);
|
||||||
// 分析手牌结构 - 获取完整的手牌分析结果
|
// 分析手牌结构 - 获取完整的手牌分析结果
|
||||||
HandAnalysis analysis = analyzeHand(handCards);
|
HandAnalysis analysis = analyzeHand(handCards);
|
||||||
|
|
||||||
|
|
@ -103,9 +107,9 @@ public class HongZhongSuanFaTest {
|
||||||
// 执行时间统计
|
// 执行时间统计
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
// logInfo("算法执行时间: " + (endTime - startTime) + "ms");
|
// logInfo("算法执行时间: " + (endTime - startTime) + "ms");
|
||||||
System.out.println("听的牌----"+analysis.tingCards);
|
log.info("听的牌----"+analysis.tingCards);
|
||||||
if (isTingAfterDraw && drawnCards!=412 ) {
|
if (isTingAfterDraw && drawnCards!=412 ) {
|
||||||
System.out.println("1111");
|
log.info("1111");
|
||||||
return String.valueOf(drawnCards);
|
return String.valueOf(drawnCards);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -626,7 +630,7 @@ public class HongZhongSuanFaTest {
|
||||||
* 统一日志输出方法
|
* 统一日志输出方法
|
||||||
*/
|
*/
|
||||||
private void logInfo(String message) {
|
private void logInfo(String message) {
|
||||||
System.out.println(message);
|
log.info(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1881,13 +1885,13 @@ public class HongZhongSuanFaTest {
|
||||||
* @return 当前手牌是否已经听牌
|
* @return 当前手牌是否已经听牌
|
||||||
*/
|
*/
|
||||||
public boolean analyzeDrawCard(List<Integer> currentHand, int drawnCard) {
|
public boolean analyzeDrawCard(List<Integer> currentHand, int drawnCard) {
|
||||||
System.out.println("机器人手牌" + currentHand);
|
log.info("机器人手牌" + currentHand);
|
||||||
// 创建包含摸牌后的手牌
|
// 创建包含摸牌后的手牌
|
||||||
List<Integer> newHand = new ArrayList<>(currentHand);
|
List<Integer> newHand = new ArrayList<>(currentHand);
|
||||||
// newHand.add(drawnCard);
|
// newHand.add(drawnCard);
|
||||||
newHand.sort(Integer::compareTo);
|
newHand.sort(Integer::compareTo);
|
||||||
drawnCard = drawnCards;
|
drawnCard = drawnCards;
|
||||||
System.out.println("drawnCards ======= " + drawnCards);
|
log.info("drawnCards ======= " + drawnCards);
|
||||||
logInfo("\n===== 开始摸牌分析 =====");
|
logInfo("\n===== 开始摸牌分析 =====");
|
||||||
logInfo("摸牌: " + drawnCard + ",摸牌后手牌: " + newHand);
|
logInfo("摸牌: " + drawnCard + ",摸牌后手牌: " + newHand);
|
||||||
|
|
||||||
|
|
@ -2130,8 +2134,7 @@ public class HongZhongSuanFaTest {
|
||||||
* @param hand 当前手牌
|
* @param hand 当前手牌
|
||||||
*/
|
*/
|
||||||
public void separateAndAnalyzeHand(List<Integer> hand) {
|
public void separateAndAnalyzeHand(List<Integer> hand) {
|
||||||
System.out.println("\n开始分离分析手牌...");
|
log.info("开始分离分析手牌");
|
||||||
|
|
||||||
// 分析手牌
|
// 分析手牌
|
||||||
HandAnalysis analysis = analyzeHand(hand);
|
HandAnalysis analysis = analyzeHand(hand);
|
||||||
|
|
||||||
|
|
@ -2195,12 +2198,11 @@ public class HongZhongSuanFaTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 输出分离结果
|
// 输出分离结果
|
||||||
System.out.println("分离结果:");
|
log.info("分离结果:");
|
||||||
System.out.println("- 刻子: " + kziCards);
|
log.info("刻子: " + kziCards);
|
||||||
System.out.println("- 顺子: " + shunziCards);
|
log.info("顺子: " + shunziCards);
|
||||||
System.out.println("- 红中: " + hongzhongCards);
|
log.info("红中: " + hongzhongCards);
|
||||||
System.out.println("- 剩余待分析的牌: " + remainingCards);
|
log.info("剩余待分析的牌: " + remainingCards);
|
||||||
|
|
||||||
// 更新analysis中的剩余牌
|
// 更新analysis中的剩余牌
|
||||||
analysis.remainingCards = remainingCards;
|
analysis.remainingCards = remainingCards;
|
||||||
|
|
||||||
|
|
@ -2215,7 +2217,7 @@ public class HongZhongSuanFaTest {
|
||||||
*/
|
*/
|
||||||
private void analyzeRemainingCards(List<Integer> remainingCards, HandAnalysis analysis) {
|
private void analyzeRemainingCards(List<Integer> remainingCards, HandAnalysis analysis) {
|
||||||
if (remainingCards.isEmpty()) {
|
if (remainingCards.isEmpty()) {
|
||||||
System.out.println("没有剩余需要分析的牌,手牌结构完整");
|
log.info("没有剩余需要分析的牌,手牌结构完整");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2339,21 +2341,21 @@ public class HongZhongSuanFaTest {
|
||||||
// 更新analysis中的孤张牌信息,确保顺子中多余的牌被正确识别为孤张
|
// 更新analysis中的孤张牌信息,确保顺子中多余的牌被正确识别为孤张
|
||||||
analysis.isolatedCards = isolatedCards;
|
analysis.isolatedCards = isolatedCards;
|
||||||
|
|
||||||
System.out.println("剩余牌分析:");
|
log.info("剩余牌分析结果: ");
|
||||||
System.out.println("- 三张: " + triples);
|
log.info("三张: {}", triples);
|
||||||
System.out.println("- 对子: " + pairs);
|
log.info("对子: {}", pairs);
|
||||||
System.out.println("- 搭子: " + 搭子);
|
log.info("搭子: {}", 搭子);
|
||||||
System.out.println("- 孤张: " + isolatedCards);
|
log.info("孤张: {}", isolatedCards);
|
||||||
|
|
||||||
// 计算剩余牌需要的张数来完成牌型
|
// 计算剩余牌需要的张数来完成牌型
|
||||||
int neededMelds = 4 - analysis.meldCount;
|
int neededMelds = 4 - analysis.meldCount;
|
||||||
int neededPairs = (analysis.pairCount > 0) ? 0 : 1;
|
int neededPairs = (analysis.pairCount > 0) ? 0 : 1;
|
||||||
System.out.println("还需要完成的面子数: " + neededMelds);
|
log.info("剩余牌需要完成的面子数: " + neededMelds);
|
||||||
System.out.println("还需要的对子数: " + neededPairs);
|
log.info("还需要的对子数: " + neededPairs);
|
||||||
|
|
||||||
// 分析牌的冗余情况
|
// 分析牌的冗余情况
|
||||||
if (!isolatedCards.isEmpty()) {
|
if (!isolatedCards.isEmpty()) {
|
||||||
System.out.println("存在孤张牌,建议考虑打出:" + isolatedCards);
|
log.info("存在孤张牌,建议考虑打出:{}", isolatedCards);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2423,28 +2425,28 @@ public class HongZhongSuanFaTest {
|
||||||
public boolean shouldPong(int proposedCard, List<Integer> currentHand) {
|
public boolean shouldPong(int proposedCard, List<Integer> currentHand) {
|
||||||
// 分析当前手牌
|
// 分析当前手牌
|
||||||
HandAnalysis analysis = analyzeHand(currentHand);
|
HandAnalysis analysis = analyzeHand(currentHand);
|
||||||
System.out.println("----"+analysis.pairCount);
|
log.info("当前手牌分析结果: "+analysis.pairCount);
|
||||||
|
|
||||||
// 不能碰听牌组中的牌
|
// 不能碰听牌组中的牌
|
||||||
if (analysis.tingCards.contains(proposedCard)) {
|
if (analysis.tingCards.contains(proposedCard)) {
|
||||||
System.out.println("不能碰: 不能碰听牌组中的牌 " + proposedCard);
|
log.info("不能碰: 不能碰听牌组中的牌 " + proposedCard);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (analysis.isTingPai){
|
if (analysis.isTingPai){
|
||||||
System.out.println("听牌中不能碰" + proposedCard);
|
log.info("听牌中不能碰" + proposedCard);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 规则2: 有5个对子时不能碰已成对子的牌
|
// 规则2: 有5个对子时不能碰已成对子的牌
|
||||||
if (analysis.hasLongQiDuiPotential==true && analysis.pairs.contains(proposedCard)) {
|
if (analysis.hasLongQiDuiPotential==true && analysis.pairs.contains(proposedCard)) {
|
||||||
System.out.println("不能碰: 已有5个或更多对子时不能碰已成对子的牌 " + proposedCard);
|
log.info("不能碰: 已有5个或更多对子时不能碰已成对子的牌 " + proposedCard);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 规则3: 顺子的情况下不能碰
|
// 规则3: 顺子的情况下不能碰
|
||||||
if (isCardInSequence(proposedCard, analysis)) {
|
if (isCardInSequence(proposedCard, analysis)) {
|
||||||
System.out.println("不能碰: 牌在顺子中的情况下不能碰 " + proposedCard);
|
log.info("不能碰: 牌在顺子中的情况下不能碰 " + proposedCard);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2457,7 +2459,7 @@ public class HongZhongSuanFaTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean canPong = cardCount >= 2;
|
boolean canPong = cardCount >= 2;
|
||||||
System.out.println("是否可以碰牌 " + proposedCard + ": " + canPong);
|
log.info("是否可以碰牌 " + proposedCard + ": "+ canPong);
|
||||||
|
|
||||||
return canPong;
|
return canPong;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue