修改红中打包问题
parent
4ea9fea6f0
commit
f22e96c4d4
|
|
@ -25,6 +25,25 @@
|
|||
|
||||
|
||||
</dependencies>
|
||||
<!-- -->
|
||||
<!-- <build>-->
|
||||
<!-- <finalName>robot</finalName>-->
|
||||
<!-- <plugins>-->
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
|
||||
<!-- <version>3.6.1</version>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <!– <compilerArgument>-parameters</compilerArgument> –>-->
|
||||
<!-- <source>1.8</source>-->
|
||||
<!-- <target>1.8</target>-->
|
||||
<!-- <encoding>UTF-8</encoding>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </plugin>-->
|
||||
|
||||
<!-- </plugins>-->
|
||||
<!-- </build>-->
|
||||
|
||||
|
||||
<build>
|
||||
<finalName>robot</finalName>
|
||||
|
|
@ -41,7 +60,29 @@
|
|||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>robot.mj.EXMainServer</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@ public class Config {
|
|||
/** 游戏服务器主机地址 */
|
||||
/*public static final String GAME_SERVER_HOST = "8.134.76.43";
|
||||
public static final String DEFAULT_GROUP_ID = "762479";*/
|
||||
public static final String DEFAULT_GROUP_ID = "426149";
|
||||
public static final String GAME_SERVER_HOST = "127.0.0.1";
|
||||
public static final String DEFAULT_GROUP_ID = "383709";
|
||||
public static final String GAME_SERVER_HOST = "8.163.97.101";
|
||||
|
||||
/** 游戏服务器端口 */
|
||||
public static final String GAME_SERVER_PORT = "6421";
|
||||
public static final String GAME_SERVER_PORT = "26421";
|
||||
|
||||
/** 默认密码 */
|
||||
public static final String DEFAULT_PASSWORD = "123456";
|
||||
|
|
|
|||
|
|
@ -416,6 +416,8 @@ public class EXGameController extends GameController {
|
|||
//成功响应后才建立映射关系
|
||||
synchronized (robotRoomMapping) {
|
||||
robotRoomMapping.put(robotUser.getConnecId(), robotUser);
|
||||
robotConnectionManager.reconnectToGameServer(response, robotUser, client);
|
||||
|
||||
}
|
||||
|
||||
log.info("机器人{"+robotId+"}已成功加入房间{"+roomId+"},建立映射关系");
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import com.taurus.core.events.Event;
|
|||
import com.taurus.core.events.IEventListener;
|
||||
import com.taurus.core.plugin.redis.Redis;
|
||||
import com.taurus.core.util.ICallback;
|
||||
import com.taurus.core.util.Logger;
|
||||
import com.taurus.core.util.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import robot.mj.business.AccountBusiness;
|
||||
import robot.mj.handler.HuNanHongZhong;
|
||||
|
|
@ -20,6 +20,7 @@ import taurus.client.TaurusClient;
|
|||
import taurus.client.SocketCode;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import taurus.util.ROBOTEventType;
|
||||
import com.taurus.core.util.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
|
@ -31,8 +32,9 @@ import static robot.mj.thread.ThreadPoolConfig.scheduleDelay;
|
|||
* 机器人连接管理器 - 管理与游戏服务器的连接
|
||||
*/
|
||||
public class RobotConnectionManager {
|
||||
private static final Logger log = Logger.getLogger(RobotConnectionManager.class);
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RobotConnectionManager.class);
|
||||
// private static final Logger log = LoggerFactory.getLogger(RobotConnectionManager.class);
|
||||
private static final Map<String, HuNanHongZhong> huNanHongZhongInstances = new ConcurrentHashMap<>();
|
||||
|
||||
//记录活跃连接 用于资源清理判断
|
||||
|
|
@ -208,7 +210,7 @@ public class RobotConnectionManager {
|
|||
ITObject param = message.param;
|
||||
//回调协议号
|
||||
String command = message.command;
|
||||
|
||||
log.info("收到游戏协议 " + command);
|
||||
//根据玩法 ID 处理不同的回调
|
||||
if (StringUtil.isNotEmpty(command)) {
|
||||
//直接处理协议
|
||||
|
|
@ -376,6 +378,19 @@ public class RobotConnectionManager {
|
|||
*/
|
||||
private void handleProtocol(String command, Message message, TaurusClient client, String connecId) {
|
||||
RobotUser robotUser = robotRoomMapping.get(connecId);
|
||||
log.info("connecId " + connecId);
|
||||
|
||||
|
||||
for (Map.Entry<String, RobotUser> entry : robotRoomMapping.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
RobotUser user = entry.getValue();
|
||||
log.info("Key" + key);
|
||||
log.info("user seat" + user.getSeat());
|
||||
log.info("user connecId" + user.getConnecId());
|
||||
log.info("user robotId" + user.getRobotId());
|
||||
|
||||
log.info("robotRoomMapping " + robotRoomMapping);
|
||||
}
|
||||
|
||||
//更新连接的最后访问时间
|
||||
EXGameController.updateLastAccessTime(connecId);
|
||||
|
|
@ -409,7 +424,7 @@ public class RobotConnectionManager {
|
|||
}
|
||||
//摸牌
|
||||
else if ("819".equalsIgnoreCase(command)) {
|
||||
huNanHongZhong.getCard(command, message);
|
||||
huNanHongZhong.getCard(command, message, robotUser);
|
||||
//处理完协议后保存到Redis
|
||||
HuNanHongZhong currentInstance = huNanHongZhongInstances.get(connecId);
|
||||
currentInstance.saveToRedis(connecId);
|
||||
|
|
@ -555,8 +570,7 @@ public class RobotConnectionManager {
|
|||
else if ("2008".equalsIgnoreCase(command)) {
|
||||
updateLeftoverRobot(Integer.parseInt(robotUser.getRobotId()));
|
||||
disconnectFromGameServer(connecId);
|
||||
}
|
||||
else if ("2009".equalsIgnoreCase(command)) {
|
||||
} else if ("2009".equalsIgnoreCase(command)) {
|
||||
scheduleDelay(() -> {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
|
|
@ -649,7 +663,8 @@ public class RobotConnectionManager {
|
|||
if (finalObject.getTObject("account") != null) {
|
||||
ITObject validate = TObject.newInstance();
|
||||
validate.putString("token", finalObject.getString("token"));
|
||||
robotUser.setToken(finalObject.getString("token"));;
|
||||
robotUser.setToken(finalObject.getString("token"));
|
||||
;
|
||||
robotUser.setLoginsession("{user}:" + robotUser.getRobotId());
|
||||
if (robotUser.getLoginsession() != null) {
|
||||
robotUser.setIsLogin(true);
|
||||
|
|
|
|||
|
|
@ -6,22 +6,26 @@ import com.taurus.core.entity.ITArray;
|
|||
import com.taurus.core.entity.ITObject;
|
||||
import com.taurus.core.entity.TObject;
|
||||
import com.taurus.core.plugin.redis.Redis;
|
||||
import com.taurus.core.util.Logger;
|
||||
import com.taurus.core.util.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import robot.mj.info.RobotUser;
|
||||
import taurus.client.Message;
|
||||
import taurus.client.TaurusClient;
|
||||
import taurus.util.CardUtil;
|
||||
import taurus.util.HongZhongSuanFaTest;
|
||||
import taurus.util.Util;
|
||||
import com.taurus.core.util.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static robot.mj.thread.ThreadPoolConfig.getBusinessThreadPool;
|
||||
|
||||
public class HuNanHongZhong {
|
||||
private static final Logger log = LoggerFactory.getLogger(HuNanHongZhong.class);
|
||||
// private static final Logger log = LoggerFactory.getLogger(HuNanHongZhong.class);
|
||||
private static final Logger log = Logger.getLogger(HuNanHongZhong.class);
|
||||
|
||||
|
||||
//红中麻将手牌
|
||||
private final List<Integer> hongZhongCardInhand = new ArrayList<>();
|
||||
|
|
@ -92,9 +96,9 @@ public class HuNanHongZhong {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 将当前实例状态序列化为JSON字符串并保存到Redis
|
||||
*
|
||||
* @param connecId 连接ID
|
||||
*/
|
||||
public void saveToRedis(String connecId) {
|
||||
|
|
@ -122,6 +126,7 @@ public class HuNanHongZhong {
|
|||
|
||||
/**
|
||||
* 从Redis恢复实例状态
|
||||
*
|
||||
* @param connecId 连接ID
|
||||
* @return 是否成功恢复
|
||||
*/
|
||||
|
|
@ -140,14 +145,16 @@ public class HuNanHongZhong {
|
|||
if (stateMap.containsKey("hongZhongCardInhand")) {
|
||||
hongZhongCardInhand.clear();
|
||||
List<Integer> handCards = gson.fromJson(stateMap.get("hongZhongCardInhand"),
|
||||
new TypeToken<List<Integer>>(){}.getType());
|
||||
new TypeToken<List<Integer>>() {
|
||||
}.getType());
|
||||
if (handCards != null) hongZhongCardInhand.addAll(handCards);
|
||||
}
|
||||
|
||||
if (stateMap.containsKey("hongZhongchuguopai")) {
|
||||
hongZhongchuguopai.clear();
|
||||
List<Integer> handCards = gson.fromJson(stateMap.get("hongZhongchuguopai"),
|
||||
new TypeToken<List<Integer>>(){}.getType());
|
||||
new TypeToken<List<Integer>>() {
|
||||
}.getType());
|
||||
if (handCards != null) hongZhongchuguopai.addAll(handCards);
|
||||
}
|
||||
|
||||
|
|
@ -167,6 +174,7 @@ public class HuNanHongZhong {
|
|||
|
||||
/**
|
||||
* 从Redis清除实例状态
|
||||
*
|
||||
* @param connecId 连接ID
|
||||
*/
|
||||
public static void removeFromRedis(String connecId) {
|
||||
|
|
@ -184,6 +192,7 @@ public class HuNanHongZhong {
|
|||
|
||||
/**
|
||||
* 同步手牌
|
||||
*
|
||||
* @param handCard
|
||||
*/
|
||||
public void updateHandCard(List<Integer> handCard) {
|
||||
|
|
@ -227,18 +236,19 @@ public class HuNanHongZhong {
|
|||
* @param message 消息对象
|
||||
* @return
|
||||
*/
|
||||
public String getCard(String command, Message message) {
|
||||
log.info("摸牌协议-----{} message---{}", command, message);
|
||||
public String getCard(String command, Message message, RobotUser robotUser) {
|
||||
if (command.equalsIgnoreCase("819")) {
|
||||
ITObject param = message.param;
|
||||
if (param == null) {
|
||||
return null;
|
||||
}
|
||||
// {seat=2, Ishupai=0, isBaoTing=-1, tingcard=0, isgang=0, card=101, left_count=106}
|
||||
log.info("轮到用户:{}的用户摸牌, 牌为:{}", param.getInt("player"), param.getInt("card"));
|
||||
log.debug("用户id: {}", playerId);
|
||||
log.debug("座位号: {}", param.getInt("seat"));
|
||||
if (param.getInt("player") != null) {
|
||||
log.info("819机器人摸牌所有参数" + param);
|
||||
Integer seat1 = param.getInt("seat");
|
||||
Integer seat2 = robotUser.getSeat();
|
||||
log.info("819摸牌 后台发的座位号" + seat1);
|
||||
log.info("819摸牌 机器人座位号" + seat2);
|
||||
|
||||
if (Objects.equals(seat1, seat2)) {
|
||||
int drawnCard = param.getInt("card");
|
||||
|
||||
hongZhongSuanFaTest.drawnCards = drawnCard;
|
||||
|
|
@ -459,15 +469,14 @@ public class HuNanHongZhong {
|
|||
params.putTArray("outcard_list", CardUtil.maJiangToTArray(cardsToSend));
|
||||
}
|
||||
params.putTArray("card_list", CardUtil.maJiangToTArray(hongZhongCardInhand));
|
||||
log.info("机器人牌============{}", params);
|
||||
// 将当前出的牌添加到历史出牌列表
|
||||
hongZhongchuguopai.add(cardToOut);
|
||||
// 从手牌中移除
|
||||
hongZhongCardInhand.remove(Integer.valueOf(cardToOut));
|
||||
log.info("出牌: {}", cardToOut);
|
||||
log.info("目前机器人剩余手牌:{}", hongZhongCardInhand.toString());
|
||||
log.info("机器人 出牌"+ cardToOut);
|
||||
log.info("目前机器人剩余手牌"+ hongZhongCardInhand);
|
||||
params.putString("session", session + "," + token);
|
||||
|
||||
log.info("机器人params" + params);
|
||||
//使用线程池替代CompletableFuture.runAsync + Thread.sleep
|
||||
getBusinessThreadPool().execute(() -> {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue