修复手牌问题

master
zhouwei 2026-02-04 22:09:03 +08:00
parent f6b9e7c875
commit 74d0d4c989
13 changed files with 153 additions and 22 deletions

View File

@ -239,8 +239,14 @@ public class EXGameController extends GameController {
//机器人房间映射关系
RobotUser robotUser = getRobotRoomInfo(String.valueOf(robotId));
Thread.sleep(5000);
if (robotUser.getRoomId() == null) {
robotUser.setCurrentRoomId(Integer.parseInt(roomId));
robotUser.setClient(client);
}
System.out.println(roomId);
System.out.println(Integer.parseInt(roomId));
System.out.println(robotUser.getCurrentRoomId());
Thread.sleep(2000);
params.putString("session","{user}:"+robotId+ "," + robotSession);
//发送加入房间请求到game_mj_cs
client.send(Config.JOIN_ROOM_CS, params, response -> {
@ -265,6 +271,17 @@ public class EXGameController extends GameController {
* ID
*/
public static RobotUser getRobotRoomInfo(String robotId) {
RobotUser robotUser = robotRoomMapping.get(robotId);
if (robotUser ==null && robotUser.getRoomId() == null) {
RobotUser robotUserCopy = new RobotUser();
robotUserCopy.setRobotId(robotId);
robotUserCopy.setPassword("123456");
robotUserCopy.setGameHost("8.138.242.190");
robotUserCopy.setGamePort("6311");
robotUserCopy.setRobotGroupid("330800");
robotUserCopy.setRobotPid("10");
return robotUserCopy;
}
return robotRoomMapping.get(robotId);
}
@ -282,7 +299,7 @@ public class EXGameController extends GameController {
public static TaurusClient getCsMjGameServerConnection(String connecId) {
TaurusClient taurusClient = robotConnectionManager.getGameClient(connecId);
System.out.println("根据机器人ID和连接ID获取长沙麻将游戏服务器连接 client: = "+taurusClient);
if (taurusClient != null) {
if (taurusClient != null && taurusClient.isConnected()) {
log.debug("成功获取游戏服务器连接connecId: {}", connecId);
return taurusClient;
}

View File

@ -40,10 +40,9 @@ public class EXMainServer extends MainServer{
startNetEventThread();
// 2. 启动连接检查定时任务
startConnectionCheckScheduler();
//startConnectionCheckScheduler();
//测试
Jedis jedis2 = Redis.use("group1_db2").getJedis();
/*Jedis jedis2 = Redis.use("group1_db2").getJedis();
String robotskey = "g{"+330800+"}:play:"+10;
Map<String, String> maprobot = jedis2.hgetAll(robotskey);
for(Map.Entry<String, String> entry : maprobot.entrySet()) {
@ -100,8 +99,7 @@ public class EXMainServer extends MainServer{
}
}
}, 0, 5 ,TimeUnit.SECONDS);
}, 0, 5 ,TimeUnit.SECONDS);*/
//5、干活
log.info("长沙麻将机器人服务器已启动");
log.info("服务器将监听端口 {} 用于接收robot_mgr管理协议", gameSetting.port);
@ -120,7 +118,7 @@ public class EXMainServer extends MainServer{
robotConnectionManager.checkIsConnect(robotUser);
}
Thread.sleep(2000);
Thread.sleep(8000);
} catch (InterruptedException e) {
break;
} catch (Exception e) {

View File

@ -1834,6 +1834,7 @@ public class HuNanChangSha {
* @return
*/
public String shanchuchuguopai(ITObject param) {
System.out.println("对面吃碰删除出过的牌组");
if (param == null) {
return null;
}
@ -1846,23 +1847,25 @@ public class HuNanChangSha {
Integer playerid = param.getInt("playerid");
String sql2 = String.format("SELECT id FROM `account` WHERE jiqiren=9998");
try {
ITArray robotId2 = DataBase.use().executeQueryByTArray(sql2);
List<Integer> robotIdsList = new ArrayList<>();
//Redis中获取机器人ID列表
List<Integer> robotIdsList = new ArrayList<>();
for (int j = 0; j < robotId2.size(); j++) {
robotIdsList.add(robotId2.getTObject(j).getInt("id"));
//Redis中获取当前活跃的机器人连接信息
try (Jedis jedis = Redis.use("group1_db2").getJedis()) {
//从Redis中获取所有在线的机器人ID
java.util.Set<String> allKeys = jedis.keys("{robot}:*");
for (String key : allKeys) {
robotIdsList.add(Integer.valueOf(key.replace("{robot}:","")));
}
}
if (!robotIdsList.contains(playerid)) {
if (type == 2 || type == 3 || type == 5 || type == 1) { // 碰,杠
getChuGuoCardInhand().remove(Integer.valueOf(card));
}
if (!robotIdsList.contains(playerid)) {
System.out.println("playerid "+playerid);
System.out.println("type "+type);
if (type == 2 || type == 3 || type == 5 || type == 1) { // 碰,杠
System.out.println("进入对面吃牌 机器人出的牌需要删除这张牌");
getChuGuoCardInhand().remove(Integer.valueOf(card));
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;

View File

@ -0,0 +1,113 @@
package robot.mj.network;
import com.robot.MainServer;
import com.taurus.core.entity.ITObject;
import com.taurus.core.entity.TObject;
import com.taurus.core.util.Logger;
import com.taurus.permanent.data.Session;
import java.util.concurrent.atomic.AtomicInteger;
/**
* TCP
*/
public class TaurusTcpListener {
private static final Logger log = Logger.getLogger(TaurusTcpListener.class);
private AtomicInteger connectionCount = new AtomicInteger(0);
private volatile boolean running = false;
/**
* TCP
*/
public void start() {
if (running) {
log.warn("TCP监听已在运行中");
return;
}
try {
running = true;
log.info("基于Taurus框架的TCP监听已启动");
} catch (Exception e) {
log.error("启动Taurus TCP监听失败", e);
}
}
/**
* TCP
*/
public void stop() {
if (!running) {
return;
}
try {
running = false;
log.info("Taurus TCP监听已停止");
} catch (Exception e) {
log.error("停止Taurus TCP监听时发生错误", e);
}
}
/**
*
*/
public void sendWelcomeMessage(Session session) {
try {
ITObject welcomeMsg = TObject.newInstance();
welcomeMsg.putString("type", "welcome");
welcomeMsg.putString("message", "连接到长沙麻将机器人服务器");
welcomeMsg.putInt("server_id", 7701);
welcomeMsg.putLong("timestamp", System.currentTimeMillis());
MainServer.instance.sendResponse(0, 0, welcomeMsg, session);
log.debug("已发送欢迎消息 - SessionId: {}", session.getId());
} catch (Exception e) {
log.error("发送欢迎消息失败", e);
}
}
/**
*
*/
public void processAndRespond(Session session, ITObject requestData, int gid) {
try {
ITObject response = TObject.newInstance();
response.putString("type", "response");
response.putTObject("original_data", requestData);
response.putBoolean("processed", true);
response.putLong("timestamp", System.currentTimeMillis());
//发送响应
MainServer.instance.sendResponse(gid, 0, response, session);
log.info("已发送响应 - SessionId: {}", session.getId());
} catch (Exception e) {
log.error("处理客户端消息时发生错误", e);
//发送错误响应
ITObject errorResponse = TObject.newInstance();
errorResponse.putString("type", "error");
errorResponse.putString("message", "处理请求时发生错误: " + e.getMessage());
errorResponse.putLong("timestamp", System.currentTimeMillis());
MainServer.instance.sendResponse(gid, 1, errorResponse, session);
}
}
public boolean isRunning() {
return running;
}
public int getConnectionCount() {
return connectionCount.get();
}
}