修复手牌问题
parent
f6b9e7c875
commit
74d0d4c989
|
|
@ -239,8 +239,14 @@ public class EXGameController extends GameController {
|
||||||
|
|
||||||
//机器人房间映射关系
|
//机器人房间映射关系
|
||||||
RobotUser robotUser = getRobotRoomInfo(String.valueOf(robotId));
|
RobotUser robotUser = getRobotRoomInfo(String.valueOf(robotId));
|
||||||
|
if (robotUser.getRoomId() == null) {
|
||||||
Thread.sleep(5000);
|
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);
|
params.putString("session","{user}:"+robotId+ "," + robotSession);
|
||||||
//发送加入房间请求到game_mj_cs
|
//发送加入房间请求到game_mj_cs
|
||||||
client.send(Config.JOIN_ROOM_CS, params, response -> {
|
client.send(Config.JOIN_ROOM_CS, params, response -> {
|
||||||
|
|
@ -265,6 +271,17 @@ public class EXGameController extends GameController {
|
||||||
* 根据机器人ID获取其所在的房间信息
|
* 根据机器人ID获取其所在的房间信息
|
||||||
*/
|
*/
|
||||||
public static RobotUser getRobotRoomInfo(String robotId) {
|
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);
|
return robotRoomMapping.get(robotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -282,7 +299,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);
|
System.out.println("根据机器人ID和连接ID获取长沙麻将游戏服务器连接 client: = "+taurusClient);
|
||||||
if (taurusClient != null) {
|
if (taurusClient != null && taurusClient.isConnected()) {
|
||||||
log.debug("成功获取游戏服务器连接,connecId: {}", connecId);
|
log.debug("成功获取游戏服务器连接,connecId: {}", connecId);
|
||||||
return taurusClient;
|
return taurusClient;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,9 @@ public class EXMainServer extends MainServer{
|
||||||
startNetEventThread();
|
startNetEventThread();
|
||||||
|
|
||||||
// 2. 启动连接检查定时任务
|
// 2. 启动连接检查定时任务
|
||||||
startConnectionCheckScheduler();
|
//startConnectionCheckScheduler();
|
||||||
|
|
||||||
//测试
|
//测试
|
||||||
Jedis jedis2 = Redis.use("group1_db2").getJedis();
|
/*Jedis jedis2 = Redis.use("group1_db2").getJedis();
|
||||||
String robotskey = "g{"+330800+"}:play:"+10;
|
String robotskey = "g{"+330800+"}:play:"+10;
|
||||||
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()) {
|
||||||
|
|
@ -100,8 +99,7 @@ public class EXMainServer extends MainServer{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0, 5 ,TimeUnit.SECONDS);
|
}, 0, 5 ,TimeUnit.SECONDS);*/
|
||||||
|
|
||||||
//5、干活
|
//5、干活
|
||||||
log.info("长沙麻将机器人服务器已启动");
|
log.info("长沙麻将机器人服务器已启动");
|
||||||
log.info("服务器将监听端口 {} 用于接收robot_mgr管理协议", gameSetting.port);
|
log.info("服务器将监听端口 {} 用于接收robot_mgr管理协议", gameSetting.port);
|
||||||
|
|
@ -120,7 +118,7 @@ public class EXMainServer extends MainServer{
|
||||||
robotConnectionManager.checkIsConnect(robotUser);
|
robotConnectionManager.checkIsConnect(robotUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(2000);
|
Thread.sleep(8000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
break;
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
|
|
@ -1834,6 +1834,7 @@ public class HuNanChangSha {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String shanchuchuguopai(ITObject param) {
|
public String shanchuchuguopai(ITObject param) {
|
||||||
|
System.out.println("对面吃碰删除出过的牌组");
|
||||||
if (param == null) {
|
if (param == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -1846,25 +1847,27 @@ public class HuNanChangSha {
|
||||||
Integer playerid = param.getInt("playerid");
|
Integer playerid = param.getInt("playerid");
|
||||||
|
|
||||||
|
|
||||||
String sql2 = String.format("SELECT id FROM `account` WHERE jiqiren=9998");
|
//Redis中获取机器人ID列表
|
||||||
try {
|
|
||||||
ITArray robotId2 = DataBase.use().executeQueryByTArray(sql2);
|
|
||||||
List<Integer> robotIdsList = new ArrayList<>();
|
List<Integer> robotIdsList = new ArrayList<>();
|
||||||
|
|
||||||
for (int j = 0; j < robotId2.size(); j++) {
|
//Redis中获取当前活跃的机器人连接信息
|
||||||
robotIdsList.add(robotId2.getTObject(j).getInt("id"));
|
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 (!robotIdsList.contains(playerid)) {
|
||||||
|
System.out.println("playerid "+playerid);
|
||||||
|
System.out.println("type "+type);
|
||||||
if (type == 2 || type == 3 || type == 5 || type == 1) { // 碰,杠
|
if (type == 2 || type == 3 || type == 5 || type == 1) { // 碰,杠
|
||||||
|
System.out.println("进入对面吃牌 机器人出的牌需要删除这张牌");
|
||||||
getChuGuoCardInhand().remove(Integer.valueOf(card));
|
getChuGuoCardInhand().remove(Integer.valueOf(card));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue