修改已知问题
parent
1c5d453fb6
commit
5a3ab7efda
|
|
@ -16,6 +16,8 @@ import taurus.client.TaurusClient;
|
|||
import taurus.client.business.GroupRoomBusiness;
|
||||
import taurus.util.ROBOTEventType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -156,7 +158,7 @@ public class EXGameController extends GameController {
|
|||
client.send(Config.JOIN_ROOM_CS, params, response -> {
|
||||
System.out.println("joinRoomController: " + response);
|
||||
RobotUser roomInfo = new RobotUser();
|
||||
roomInfo.setRoomId(roomId);
|
||||
roomInfo.setCurrentRoomId(Integer.parseInt(roomId));
|
||||
roomInfo.setConnecId(connecId);
|
||||
roomInfo.setUserId(0);
|
||||
//机器人房间映射关系
|
||||
|
|
@ -214,69 +216,52 @@ public class EXGameController extends GameController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收来自web_group的加入房间协议
|
||||
*/
|
||||
@ActionKey(value = "225", validate = GameInterceptor.NOT_PLAYER)
|
||||
public void webGroup(Session session, ITObject params, int gid) {
|
||||
int robotId = params.getInt("robotid");
|
||||
String roomId = params.getString("roomid");
|
||||
int groupId = params.getInt("groupid");
|
||||
try (Jedis jedis0 = Redis.use("group1_db0").getJedis();Jedis jedis2 = Redis.use("group1_db2").getJedis()){
|
||||
Set<String> robotTokens = jedis0.smembers("{user}:"+robotId+"_token");
|
||||
String robotSession = null;
|
||||
|
||||
for (String token : robotTokens) {
|
||||
if (jedis0.exists(token)) {
|
||||
robotSession = token;
|
||||
break;
|
||||
//防止玩家操作同一房间 导致其他机器人加入
|
||||
List<RobotUser> robotUsers = getRobotUsersByRoomId(Integer.parseInt(roomId));
|
||||
if (!robotUsers.isEmpty()) {
|
||||
synchronized (robotUsers) {
|
||||
RobotUser robotUser = robotUsers.get(0);
|
||||
if (robotId != Integer.parseInt(robotUser.getRobotId())) {
|
||||
System.err.println("房间{"+ roomId +"}中已有机器人{"+robotUser.getRobotId()+"},当前机器人{"+robotId+"}不执行加入逻辑");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("进房间: "+robotId);
|
||||
System.out.println("进房间: "+roomId);
|
||||
System.out.println("进房间: "+"room:"+ roomId);
|
||||
System.out.println("进房间: "+"{user}:"+robotId);
|
||||
|
||||
TaurusClient client = getCsMjGameServerConnection(roomId+"_"+robotId);
|
||||
GroupRoomBusiness.joinRoom(groupId, "room:"+ roomId, "{user}:"+robotId, null);
|
||||
|
||||
//机器人房间映射关系
|
||||
RobotUser robotUser = getRobotRoomInfo(String.valueOf(robotId));
|
||||
if (robotUser.getCurrentRoomId() == 0) {
|
||||
robotUser.setCurrentRoomId(Integer.parseInt(roomId));
|
||||
robotUser.setClient(client);
|
||||
robotUser.setConnecId(roomId+ "_"+ robotId);
|
||||
}
|
||||
robotRoomMapping.put(robotUser.getConnecId(), robotUser);
|
||||
robotRoomMapping.remove(robotUser.getRobotId());
|
||||
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 -> {
|
||||
System.out.println("joinRoomController: " + response);
|
||||
robotConnectionManager.reconnectToGameServer(response, robotUser, client);
|
||||
});
|
||||
|
||||
Thread.sleep(1000);
|
||||
if(client.isConnected()){
|
||||
client.send(Config.GAME_READY_CS, params, response -> {
|
||||
System.out.println("1003:"+response);
|
||||
});
|
||||
jedis2.hset("gallrobot", String.valueOf(robotUser.getRobotId()), "1");
|
||||
|
||||
robotUser.setStatus(ROBOTEventType.ROBOT_INTOROOM_READY);
|
||||
robotConnectionManager.setSessionAndToken("{user}:"+robotId, robotSession, robotUser.getConnecId());
|
||||
}
|
||||
robotUser.setIntoRoomTime(robotConnectionManager.getTime());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.err.println("225开始进房间: "+"room:"+ roomId +"robot:"+robotId);
|
||||
//加入房间
|
||||
joinRoomCommon(robotId, roomId, groupId, params);
|
||||
System.err.println("225已进入房间准备成功: "+"room:"+ roomId +"robot:"+robotId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收来自web_group的主动重连协议
|
||||
*/
|
||||
@ActionKey(value = "226", validate = GameInterceptor.NOT_PLAYER)
|
||||
public void webGroupActive(Session session, ITObject params, int gid) {
|
||||
int robotId = params.getInt("robotid");
|
||||
String roomId = params.getString("roomid");
|
||||
System.err.println("226开始进房间: " + "room:" + roomId + "robot:" + robotId);
|
||||
//加入房间
|
||||
joinRoomCommon(params.getInt("robotid"), params.getString("roomid"), params.getInt("groupid"), params);
|
||||
System.err.println("226已进入房间准备成功: " + "room:" + roomId + "robot:" + robotId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启服务断线重连
|
||||
* */
|
||||
public void webGroupJoinRoom(RobotUser robotUser) {
|
||||
String connecId = robotUser.getConnecId();
|
||||
TaurusClient client = getCsMjGameServerConnection(connecId);
|
||||
|
||||
//重启检查
|
||||
try (Jedis jedis0 = Redis.use("group1_db0").getJedis();Jedis jedis2 = Redis.use("group1_db2").getJedis()){
|
||||
Set<String> robotTokens = jedis0.smembers("{user}:"+robotUser.getRobotId()+"_token");
|
||||
String robotSession = null;
|
||||
|
|
@ -292,40 +277,70 @@ public class EXGameController extends GameController {
|
|||
robotRoomMapping.remove(connecId);
|
||||
return;
|
||||
}
|
||||
System.out.println("重连进房间: "+robotUser.getRobotId());
|
||||
System.out.println("重连进房间: "+robotUser.getCurrentRoomId());
|
||||
System.out.println("重连进房间: "+"room:"+ robotUser.getCurrentRoomId());
|
||||
System.out.println("重连进房间: "+"{user}:"+robotUser.getRobotId());
|
||||
GroupRoomBusiness.joinRoom(Integer.parseInt(robotUser.getRobotGroupid()), "room:"+ robotUser.getCurrentRoomId(), "{user}:"+robotUser.getRobotId(), null);
|
||||
|
||||
System.err.println("重启后开始进房间: " + "room:" + robotUser.getCurrentRoomId() + "robot:" + robotUser.getRobotId());
|
||||
ITObject params = new TObject();
|
||||
params.putString("session", "{user}:" + robotUser.getRobotId() + "," + robotSession);
|
||||
//加入房间
|
||||
joinRoomCommon(Integer.parseInt(robotUser.getRobotId()), String.valueOf(robotUser.getCurrentRoomId()), Integer.parseInt(robotUser.getRobotGroupid()), params);
|
||||
System.err.println("重启后已进入房间准备成功: " + "room:" + robotUser.getCurrentRoomId() + "robot:" + robotUser.getRobotId());
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入房间逻辑
|
||||
*/
|
||||
private void joinRoomCommon(int robotId, String roomId, int groupId, ITObject params) {
|
||||
try (Jedis jedis0 = Redis.use("group1_db0").getJedis();Jedis jedis2 = Redis.use("group1_db2").getJedis()) {
|
||||
Set<String> robotTokens = jedis0.smembers("{user}:" + robotId + "_token");
|
||||
String robotSession = null;
|
||||
|
||||
for (String token : robotTokens) {
|
||||
if (jedis0.exists(token)) {
|
||||
robotSession = token;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.err.println("开始进房间: room:" + roomId);
|
||||
System.err.println("开始进房间: {user}:" + robotId);
|
||||
|
||||
TaurusClient client = getCsMjGameServerConnection(roomId + "_" + robotId);
|
||||
GroupRoomBusiness.joinRoom(groupId, "room:" + roomId, "{user}:" + robotId, null);
|
||||
|
||||
//机器人房间映射关系
|
||||
if (robotUser.getRoomId() == null) {
|
||||
robotUser.setCurrentRoomId(robotUser.getCurrentRoomId());
|
||||
RobotUser robotUser = getRobotRoomInfo(String.valueOf(robotId));
|
||||
String connecId = roomId + "_" + robotId;
|
||||
if (robotUser.getCurrentRoomId() == 0) {
|
||||
robotUser.setCurrentRoomId(Integer.parseInt(roomId));
|
||||
robotUser.setClient(client);
|
||||
robotUser.setConnecId(connecId);
|
||||
}
|
||||
robotRoomMapping.put(robotUser.getConnecId(), robotUser);
|
||||
robotRoomMapping.remove(robotUser.getRobotId());
|
||||
|
||||
Thread.sleep(2000);
|
||||
ITObject params = new TObject();
|
||||
params.putString("session","{user}:"+robotUser.getRobotId()+ "," + robotSession);
|
||||
params.putString("session", "{user}:" + robotId + "," + robotSession);
|
||||
|
||||
//发送加入房间请求到game_mj_cs
|
||||
client.send(Config.JOIN_ROOM_CS, params, response -> {
|
||||
System.out.println("joinRoomController: " + response);
|
||||
robotConnectionManager.reconnectToGameServer(response, robotUser, client);
|
||||
});
|
||||
|
||||
System.err.println("已进入房间成功: " + robotUser.getConnecId());
|
||||
Thread.sleep(1000);
|
||||
if(client.isConnected()){
|
||||
if (client.isConnected()) {
|
||||
client.send(Config.GAME_READY_CS, params, response -> {
|
||||
System.out.println("1003:"+response);
|
||||
System.out.println("1003:" + response);
|
||||
});
|
||||
|
||||
jedis2.hset("gallrobot", String.valueOf(robotUser.getRobotId()), "1");
|
||||
|
||||
robotUser.setStatus(ROBOTEventType.ROBOT_INTOROOM_READY);
|
||||
robotConnectionManager.setSessionAndToken("{user}:" + robotId, robotSession, robotUser.getConnecId());
|
||||
}
|
||||
robotUser.setIntoRoomTime(robotConnectionManager.getTime());
|
||||
System.err.println("已进入房间准备成功: " + robotUser.getConnecId());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -349,6 +364,21 @@ public class EXGameController extends GameController {
|
|||
return robotRoomMapping.get(robotId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据房间ID获取所有对应的RobotUser
|
||||
*/
|
||||
public List<RobotUser> getRobotUsersByRoomId(int roomId) {
|
||||
String prefix = roomId + "_";
|
||||
List<RobotUser> result = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, RobotUser> entry : robotRoomMapping.entrySet()) {
|
||||
if (entry.getKey().startsWith(prefix)) {
|
||||
result.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据机器人ID删除其所在的房间信息
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -59,10 +59,6 @@ public class EXMainServer extends MainServer{
|
|||
robotRoomMapping.put(entry.getKey(), robotUser);
|
||||
}
|
||||
|
||||
TPServer.me().getTimerPool().scheduleAtFixedRate(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
for(Map.Entry<String, RobotUser> entry : robotRoomMapping.entrySet()) {
|
||||
RobotUser robotUser = entry.getValue();
|
||||
//1、登录
|
||||
|
|
@ -70,67 +66,54 @@ public class EXMainServer extends MainServer{
|
|||
if(!robotUser.isLogin){
|
||||
robotConnectionManager.login(robotUser);
|
||||
}
|
||||
/*//2、链接
|
||||
//判断是否链接
|
||||
System.out.println("robotUser.isconnect"+robotUser.getIsconnect());
|
||||
if(!robotUser.getIsconnect()){
|
||||
robotConnectionManager.connectGame(robotUser);
|
||||
}else{
|
||||
robotConnectionManager.renconnect(robotUser);
|
||||
}
|
||||
|
||||
|
||||
//4、加入房间
|
||||
if(robotUser.getStatus()==0){
|
||||
//没状态时候进入加入房间
|
||||
ITObject params = new TObject();
|
||||
params.putString("connecId", robotUser.getRoomId()+"_"+robotUser.getRobotId());
|
||||
params.putString("roomId", robotUser.getRoomId());
|
||||
params.putString("groupId", robotUser.getRobotGroupid());
|
||||
params.putString("session", "{user}:"+robotUser.getRobotId());
|
||||
exGameController.joinRoom(null, params, robotUser.getClient().getId());
|
||||
}
|
||||
System.out.println("robotUser.getIntoRoomTime()"+robotUser.getIntoRoomTime());
|
||||
System.out.println("robGetTiem"+robotConnectionManager.getTime());
|
||||
if(robotUser.getIntoRoomTime()+6<=robotConnectionManager.getTime()){
|
||||
//5、退出房间
|
||||
robotConnectionManager.outoRoom(robotUser);
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
}, 0, 5 ,TimeUnit.SECONDS);
|
||||
// TPServer.me().getTimerPool().scheduleAtFixedRate(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
//
|
||||
// for(Map.Entry<String, RobotUser> entry : robotRoomMapping.entrySet()) {
|
||||
// RobotUser robotUser = entry.getValue();
|
||||
// //1、登录
|
||||
// //判断是否登录
|
||||
// if(!robotUser.isLogin){
|
||||
// robotConnectionManager.login(robotUser);
|
||||
// }
|
||||
// /*//2、链接
|
||||
// //判断是否链接
|
||||
// System.out.println("robotUser.isconnect"+robotUser.getIsconnect());
|
||||
// if(!robotUser.getIsconnect()){
|
||||
// robotConnectionManager.connectGame(robotUser);
|
||||
// }else{
|
||||
// robotConnectionManager.renconnect(robotUser);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //4、加入房间
|
||||
// if(robotUser.getStatus()==0){
|
||||
// //没状态时候进入加入房间
|
||||
// ITObject params = new TObject();
|
||||
// params.putString("connecId", robotUser.getRoomId()+"_"+robotUser.getRobotId());
|
||||
// params.putString("roomId", robotUser.getRoomId());
|
||||
// params.putString("groupId", robotUser.getRobotGroupid());
|
||||
// params.putString("session", "{user}:"+robotUser.getRobotId());
|
||||
// exGameController.joinRoom(null, params, robotUser.getClient().getId());
|
||||
// }
|
||||
// System.out.println("robotUser.getIntoRoomTime()"+robotUser.getIntoRoomTime());
|
||||
// System.out.println("robGetTiem"+robotConnectionManager.getTime());
|
||||
// if(robotUser.getIntoRoomTime()+6<=robotConnectionManager.getTime()){
|
||||
// //5、退出房间
|
||||
// robotConnectionManager.outoRoom(robotUser);
|
||||
// }*/
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }, 0, 5 ,TimeUnit.SECONDS);
|
||||
//5、干活
|
||||
log.info("长沙麻将机器人服务器已启动");
|
||||
log.info("服务器将监听端口 {} 用于接收robot_mgr管理协议", gameSetting.port);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启动连接检查定时任务
|
||||
*/
|
||||
private void startConnectionCheckScheduler() {
|
||||
Thread connectionCheckThread = new Thread(() -> {
|
||||
while (connectionCheckRunning) {
|
||||
try {
|
||||
for(Map.Entry<String, RobotUser> entry : robotRoomMapping.entrySet()) {
|
||||
RobotUser robotUser = entry.getValue();
|
||||
robotConnectionManager.checkIsConnect(robotUser);
|
||||
}
|
||||
|
||||
Thread.sleep(8000);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
log.error("连接检查线程异常", e);
|
||||
}
|
||||
}
|
||||
}, "Connection-Check-Thread");
|
||||
|
||||
connectionCheckThread.setDaemon(true);
|
||||
connectionCheckThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* 独立的事件处理线程
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -47,26 +47,19 @@ public class RobotConnectionManager {
|
|||
private Map<Integer, List<Integer>> getPlayerOutcardsMap(String connecId) {
|
||||
return playerOutcardsMapByConn.computeIfAbsent(connecId, k -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private Map<Integer, List<Integer>> getPlayerchisMap(String connecId) {
|
||||
return playerchisMapByConn.computeIfAbsent(connecId, k -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private Map<Integer, List<Integer>> getPlayerpengsMap(String connecId) {
|
||||
return playerpengsMapByConn.computeIfAbsent(connecId, k -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private Map<Integer, List<Integer>> getPlayermingsMap(String connecId) {
|
||||
return playermingsMapByConn.computeIfAbsent(connecId, k -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
private Map<Integer, List<Integer>> getPlayerzisMap(String connecId) {
|
||||
return playerzisMapByConn.computeIfAbsent(connecId, k -> new ConcurrentHashMap<>());
|
||||
}
|
||||
private int groupId = 0;
|
||||
private int pid = 0;
|
||||
private int playerId = 0;
|
||||
private String playKey = "";
|
||||
private Map<Integer, Integer> count = new HashMap<Integer, Integer>();
|
||||
/*长沙麻将游戏算法相关 end*/
|
||||
|
||||
|
|
@ -178,25 +171,10 @@ public class RobotConnectionManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加leftover_robot数量 机器人退出房间
|
||||
*/
|
||||
private void updateLeftoverRobot(int robotId) {
|
||||
try (Jedis jedis2 = Redis.use("group1_db2").getJedis()) {
|
||||
|
||||
jedis2.hset("gallrobot", String.valueOf(robotId), "0");
|
||||
|
||||
jedis2.hset("{grobot}:" + robotId, "start", "0");
|
||||
|
||||
System.out.println("机器人 {"+robotId+"} 退出房间,修改gallrobot为0");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置事件监听器
|
||||
*/
|
||||
public void setupEventListeners(TaurusClient client, String connecId) {
|
||||
|
||||
//添加消息事件监听器
|
||||
IEventListener messageListener = new IEventListener() {
|
||||
@Override
|
||||
|
|
@ -287,11 +265,14 @@ public class RobotConnectionManager {
|
|||
//同步手牌
|
||||
HuNanChangSha currentInstance = getHuNanChangShaInstance(connecId);
|
||||
|
||||
//检查Redis恢复的数据 避免覆盖
|
||||
if (currentInstance.getChangShaCardInhand().isEmpty()) {
|
||||
//手牌集合为空 需要同步数据
|
||||
//同步逻辑比较手牌数量
|
||||
List<Integer> currentHand = currentInstance.getChangShaCardInhand();
|
||||
if (currentHand.isEmpty() || hcard.size() > currentHand.size()) {
|
||||
//手牌集合为空 或者 玩家出牌了
|
||||
currentInstance.updateHandCard(hcard);
|
||||
System.out.println("断线重连:同步手牌数据");
|
||||
System.out.println("断线重连:同步手牌数据,服务器手牌:" + hcard);
|
||||
} else {
|
||||
System.out.println("断线重连:使用Redis恢复的手牌数据,数量:" + currentHand.size());
|
||||
}
|
||||
|
||||
if(outcard_list.size()>0){
|
||||
|
|
@ -301,9 +282,12 @@ public class RobotConnectionManager {
|
|||
}
|
||||
|
||||
//检查出牌记录是否需要同步
|
||||
if (currentInstance.getChuGuoCardInhand().isEmpty()) {
|
||||
List<Integer> currentOutCards = currentInstance.getChuGuoCardInhand();
|
||||
if (currentOutCards.isEmpty() || outcards.size() > currentOutCards.size()) {
|
||||
currentInstance.updateOutCard(outcards);
|
||||
System.out.println("断线重连:同步出牌数据");
|
||||
System.out.println("断线重连:同步出牌数据,服务器出牌:" + outcards);
|
||||
} else {
|
||||
System.out.println("断线重连:使用Redis恢复的出牌数据,数量:" + currentOutCards.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -336,14 +320,10 @@ public class RobotConnectionManager {
|
|||
HuNanChangSha huNanChangSha = getHuNanChangShaInstance(connecId);
|
||||
try (Jedis jedis0 = Redis.use().getJedis();Jedis jedis2 = Redis.use("group1_db2").getJedis();){
|
||||
//长沙麻将 机器人处理事件
|
||||
|
||||
//[TCP->822] data:{"tip_list":[{"type":8,"id":1,"opcard":[],"weight":8,"card":0}],"types":[{"type":21,"value":1}]}
|
||||
//板胡Event [TCP->823] data:{"type":8,"seat":1,"data":[{"opcard":[204,204,204,108,108,108],"type":21,"value":1}]}
|
||||
//初始化收手牌
|
||||
if ("811".equalsIgnoreCase(command)) {
|
||||
robotUser.setStatus(ROBOTEventType.ROBOT_INTOROOM_WORKING);
|
||||
//初始化收手牌
|
||||
// System.out.println("初始化手牌" + session);
|
||||
String key = robotId+"";
|
||||
log.info("key+++++++++++++++++++++++++++++++++++" + key);
|
||||
if (jedis2.hget("{robortInfo}:" + key, "circleId") != null && jedis2.hget("{robortInfo}:" + key, "pid") != null) {
|
||||
|
|
@ -364,7 +344,6 @@ public class RobotConnectionManager {
|
|||
}
|
||||
//出牌广播
|
||||
else if ("812".equalsIgnoreCase(command)) {
|
||||
//{"opzicards":[{"opzicards":[],"playerId":101555}],"opmingcards":[{"opmingcards":[],"playerId":101555}],"outcard_map":[{"outcards":[209,205],"playerId":101555},{"outcards":[],"playerId":112233}],"card":205,"opchicards":[{"opchicards":[105,103],"playerId":101555}],"oppengcards":[{"oppengcards":[],"playerId":101555}],"seat":1}
|
||||
ITArray outcard_map = param.getTArray("outcard_map");
|
||||
ITArray opchicards = param.getTArray("opchicards");
|
||||
ITArray oppengcards = param.getTArray("oppengcards");
|
||||
|
|
@ -477,7 +456,7 @@ public class RobotConnectionManager {
|
|||
}
|
||||
//出牌提示
|
||||
else if ("813".equalsIgnoreCase(command)) {
|
||||
// 获取当前连接专用的Maps
|
||||
//获取当前连接的Maps
|
||||
Map<Integer, List<Integer>> currentPlayerOutcardsMap = getPlayerOutcardsMap(connecId);
|
||||
Map<Integer, List<Integer>> currentPlayerchisMap = getPlayerchisMap(connecId);
|
||||
Map<Integer, List<Integer>> currentPlayerpengsMap = getPlayerpengsMap(connecId);
|
||||
|
|
@ -561,37 +540,16 @@ public class RobotConnectionManager {
|
|||
}
|
||||
});
|
||||
}
|
||||
//2026.02.03修改 玩家解散房间
|
||||
//2026.02.05修改 玩家解散房间
|
||||
else if ("2005".equalsIgnoreCase(command)) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
ITArray playsList = param.getTArray("list");
|
||||
for (int i = 0; i < playsList.size(); i++) {
|
||||
ITObject playerData = playsList.getTObject(i);
|
||||
Integer userId = playerData.getInt("aid");
|
||||
if (userId.equals(robotId)) {
|
||||
String roomKey = robotUser.getRoomId();
|
||||
String gpid = jedis0.hget(roomKey, "gpid");
|
||||
String gpId = jedis0.hget(roomKey, "group");
|
||||
sleepTime(25000);
|
||||
//更新机器人剩余数量
|
||||
if (count != null && count.containsKey(Integer.parseInt(gpid))) {
|
||||
Integer currentValue = count.get(Integer.parseInt(gpid));
|
||||
if (currentValue > 0) {
|
||||
count.put(Integer.parseInt(gpid), currentValue - 1);
|
||||
}
|
||||
}
|
||||
EXGameController.removeRobotRoomInfo(String.valueOf(robotId));
|
||||
//更新机器人剩余数量
|
||||
updateLeftoverRobot(robotId);
|
||||
disconnectFromGameServer(connecId);
|
||||
System.out.println("2005玩家发送解散房间协议,robotId: {"+robotId+"}");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//2026.02.03修改 解散房间时候恢复机器人账号可以使用
|
||||
else if ("2008".equalsIgnoreCase(command)) {
|
||||
|
||||
updateLeftoverRobot(Integer.parseInt(robotUser.getRobotId()));
|
||||
disconnectFromGameServer(connecId);
|
||||
}
|
||||
|
|
@ -602,7 +560,7 @@ public class RobotConnectionManager {
|
|||
sleepTime(6000);
|
||||
|
||||
if (robotUser != null) {
|
||||
String roomKey = robotUser.getRoomId();
|
||||
String roomKey = String.valueOf(robotUser.getCurrentRoomId());
|
||||
|
||||
//查询该房间的玩家信息
|
||||
String playersStr = jedis0.hget(roomKey, "players");
|
||||
|
|
@ -654,11 +612,6 @@ public class RobotConnectionManager {
|
|||
huNanChangSha.getChuGuoPainum().clear();
|
||||
Integer type = param.getInt("type");
|
||||
if (type == 1 || type == 2) { //为1为大结算 为2为解散
|
||||
Jedis jedis11s = Redis.use("group1_db11").getJedis();
|
||||
try {
|
||||
String key = "g{" + groupId + "}:play:" + pid;
|
||||
// jedis11s.hincrBy(key, "leftover_robot", 1);
|
||||
//
|
||||
if (count != null && count.containsKey(pid)) {
|
||||
Integer currentValue = count.get(pid);
|
||||
if (currentValue > 0) {
|
||||
|
|
@ -666,60 +619,23 @@ public class RobotConnectionManager {
|
|||
}
|
||||
}
|
||||
|
||||
//todo 可能要修改机器人状态
|
||||
/*String sql = String.format("UPDATE `account` SET start = %d WHERE id = %d", 0, playerId);
|
||||
try {
|
||||
DataBase.use().executeUpdate(sql);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
jedis11s.close();
|
||||
//更新机器人剩余数量
|
||||
updateLeftoverRobot(Integer.parseInt(robotUser.getRobotId()));
|
||||
}
|
||||
|
||||
if (count != null && count.containsKey(pid)) {
|
||||
Integer value = count.get(pid);
|
||||
|
||||
// 如果找到了对应的 pid
|
||||
Jedis jedis12 = Redis.use("group1_db11").getJedis();
|
||||
|
||||
String shangxianRobot = jedis12.hget(playKey, "shangxian_robot");
|
||||
String leftoverRobot = jedis12.hget(playKey, "leftover_robot");
|
||||
|
||||
/*if (shangxianRobot != null && leftoverRobot != null) {
|
||||
if (value == 0) {
|
||||
jedis12.hset(playKey, "leftover_robot", shangxianRobot);
|
||||
}
|
||||
}*/
|
||||
jedis12.close();
|
||||
}
|
||||
}
|
||||
// playerState.pongGroups.clear();;
|
||||
// playerState.handCards.clear();
|
||||
// playerState.chiGroups.clear();
|
||||
// playerState.gangGroups.clear();;
|
||||
|
||||
|
||||
sleepTime(1000);
|
||||
|
||||
ITObject params = TObject.newInstance();
|
||||
params.putString("session", client.getSession());
|
||||
//todo session + "," + token
|
||||
client.send("1003", params, new ICallback<MessageResponse>() {
|
||||
|
||||
@Override
|
||||
public void action(MessageResponse messageResponse) {
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
//服务器通知客户端有玩家执行了操作
|
||||
else if ("815".equalsIgnoreCase(command)) {
|
||||
//[TCP->815] data:{"playerid":101555,"card":104,"opcard":[105,103],"from_seat":2,"type":1,"opengang":false}
|
||||
huNanChangSha.shanchuchuguopai(param);
|
||||
//处理完协议后保存到Redis
|
||||
HuNanChangSha currentInstance = huNanChangShaInstances.get(connecId);
|
||||
|
|
@ -742,11 +658,7 @@ public class RobotConnectionManager {
|
|||
}
|
||||
else if ("822".equalsIgnoreCase(command)) {
|
||||
ITObject params = TObject.newInstance();
|
||||
//params.putInt("qi", 0);
|
||||
params.putInt("id", 1);
|
||||
//[TCP->822] data:{"tip_list":[{"type":8,"id":1,"opcard":[],"weight":8,"card":0}],"types":[{"type":21,"value":1}]}
|
||||
//板胡Event [TCP->823] data:{"type":8,"seat":1,"data":[{"opcard":[204,204,204,108,108,108],"type":21,"value":1}]}
|
||||
|
||||
client.send("612", params, response -> {
|
||||
|
||||
});
|
||||
|
|
@ -766,12 +678,17 @@ public class RobotConnectionManager {
|
|||
}
|
||||
}
|
||||
|
||||
public static void sleepTime(int time) {
|
||||
try {
|
||||
// 添加延迟
|
||||
Thread.sleep(time);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
/**
|
||||
* 增加leftover_robot数量 机器人退出房间
|
||||
*/
|
||||
private void updateLeftoverRobot(int robotId) {
|
||||
try (Jedis jedis2 = Redis.use("group1_db2").getJedis()) {
|
||||
|
||||
jedis2.hset("gallrobot", String.valueOf(robotId), "0");
|
||||
|
||||
jedis2.hset("{grobot}:" + robotId, "start", "0");
|
||||
|
||||
System.out.println("机器人 {"+robotId+"} 退出房间,修改gallrobot为0");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -808,6 +725,7 @@ public class RobotConnectionManager {
|
|||
connectGame(robotUser);
|
||||
|
||||
robotUser.setConnecId(robotUser.getCurrentRoomId()+"_"+robotUser.getRobotId());
|
||||
System.err.println("重启获取的机器人还有当前房间,准备加入: "+robotUser.getConnecId());
|
||||
exGameController.webGroupJoinRoom(robotUser);
|
||||
}
|
||||
}
|
||||
|
|
@ -856,72 +774,6 @@ public class RobotConnectionManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void checkIsConnect(RobotUser robotUser){
|
||||
System.out.println("checkIsConnect:"+robotUser.getRobotId()+"==="+robotUser.getStatus());
|
||||
System.out.println("checkIsConnectgetId:"+robotUser.getRobotId()+"==="+robotUser.getClient().getId());
|
||||
System.out.println("checkIsConnectgetGameID:"+robotUser.getRobotId()+"==="+robotUser.getClient().getGameID());
|
||||
if(robotUser.getIsLogin()&&robotUser.getClient()!=null){
|
||||
System.out.println("connectid:"+robotUser.getClient().getId());
|
||||
robotUser.setIsconnect(robotUser.getClient().isConnected());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出 房间
|
||||
*/
|
||||
public void outoRoom(RobotUser robotUser) {
|
||||
//判断当前状态是否在工作
|
||||
System.out.println("outoRoom:"+ROBOTEventType.ROBOT_INTOROOM_READY);
|
||||
if (robotUser.getStatus() == ROBOTEventType.ROBOT_INTOROOM_READY) {
|
||||
//判断房间是否有人
|
||||
//room:197276
|
||||
|
||||
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||
try {
|
||||
System.out.println("getCurrentRoomId:"+robotUser.getCurrentRoomId());
|
||||
if(robotUser.getCurrentRoomId()!=0){
|
||||
System.out.println("getCurrentRoomId:"+ROBOTEventType.ROBOT_INTOROOM_READY);
|
||||
String roomkey="room:"+robotUser.getCurrentRoomId();
|
||||
|
||||
List<String> room_list = jedis0.hmget(roomkey, "fake", "status", "round", "id", "times", "players", "create_time", "fake_existTime");
|
||||
System.out.println("room_list:"+room_list);
|
||||
String roomId = room_list.get(3);
|
||||
if(room_list.get(5)==null){
|
||||
ITObject params = TObject.newInstance();
|
||||
params.putString("session", robotUser.getLoginsession() + "," + robotUser.getToken());
|
||||
System.out.println("logoutroom:"+params);
|
||||
if(robotUser.getClient().isConnected()){
|
||||
robotUser.getClient().send("1005", params,response -> {
|
||||
});
|
||||
robotUser.setStatus(ROBOTEventType.ROBOT_UNUSE);
|
||||
}
|
||||
}
|
||||
ITArray players = TArray.newFromJsonData(room_list.get(5));
|
||||
System.out.println("players:"+players);
|
||||
if(players.size()<2){
|
||||
ITObject params = TObject.newInstance();
|
||||
params.putString("session", robotUser.getLoginsession() + "," + robotUser.getToken());
|
||||
System.out.println("logoutroom:"+params);
|
||||
if(robotUser.getClient().isConnected()){
|
||||
robotUser.getClient().send("1005", params,response -> {
|
||||
});
|
||||
robotUser.setStatus(ROBOTEventType.ROBOT_UNUSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
|
||||
}finally {
|
||||
jedis0.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getTime(){
|
||||
return Integer.parseInt((System.currentTimeMillis() + "").substring(0, 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* 重连
|
||||
*/
|
||||
|
|
@ -935,7 +787,6 @@ public class RobotConnectionManager {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据connecId获取游戏服务器连接
|
||||
*/
|
||||
|
|
@ -943,4 +794,18 @@ public class RobotConnectionManager {
|
|||
return robotRoomMapping.get(connecId) != null ? robotRoomMapping.get(connecId).getClient() : null;
|
||||
}
|
||||
|
||||
|
||||
public int getTime(){
|
||||
return Integer.parseInt((System.currentTimeMillis() + "").substring(0, 10));
|
||||
}
|
||||
|
||||
public static void sleepTime(int time) {
|
||||
try {
|
||||
//添加延迟
|
||||
Thread.sleep(time);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,11 +6,8 @@ import taurus.client.TaurusClient;
|
|||
* 机器人房间信息类
|
||||
*/
|
||||
public class RobotUser {
|
||||
private String roomId;
|
||||
private String connecId;
|
||||
private int userId;
|
||||
private String groupId;
|
||||
private String wanfaId;
|
||||
private String robotId;
|
||||
|
||||
private int seat;
|
||||
|
|
@ -140,14 +137,6 @@ public class RobotUser {
|
|||
this.status = status;
|
||||
}
|
||||
|
||||
public String getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
|
||||
public void setRoomId(String roomId) {
|
||||
this.roomId = roomId;
|
||||
}
|
||||
|
||||
public String getConnecId() {
|
||||
return connecId;
|
||||
}
|
||||
|
|
@ -164,22 +153,6 @@ public class RobotUser {
|
|||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public String getWanfaId() {
|
||||
return wanfaId;
|
||||
}
|
||||
|
||||
public void setWanfaId(String wanfaId) {
|
||||
this.wanfaId = wanfaId;
|
||||
}
|
||||
|
||||
public String getRobotId() {
|
||||
return robotId;
|
||||
}
|
||||
|
|
@ -188,8 +161,4 @@ public class RobotUser {
|
|||
this.robotId = robotId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RobotRoomInfo{roomId='" + roomId + "', connecId='" + connecId + "'}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue