验证是否打过
parent
5dcf9e1b44
commit
4de59b6d59
|
|
@ -9,10 +9,16 @@ import com.group.Protocol;
|
|||
import com.group.WebInterceptor;
|
||||
import com.group.service.GroupRoomService;
|
||||
import com.taurus.core.entity.ITObject;
|
||||
import com.taurus.core.plugin.redis.Redis;
|
||||
import com.taurus.core.routes.ActionKey;
|
||||
import com.taurus.web.Controller;
|
||||
import com.taurus.web.WebException;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class GroupRoomController extends Controller {
|
||||
|
||||
/**
|
||||
|
|
@ -37,6 +43,9 @@ public class GroupRoomController extends Controller {
|
|||
throw new WebException(ErrorCode.GROUP_MEMBER_BAN);
|
||||
|
||||
}
|
||||
|
||||
//检查玩家今天是否已经与机器人对打过
|
||||
isPlayerRobotToday(acc.id);
|
||||
|
||||
ITObject resData = GroupRoomService.matchRoom(groupId, pid, session, platform, is_null);
|
||||
this.sendResponse(0, resData);
|
||||
|
|
@ -80,4 +89,26 @@ public class GroupRoomController extends Controller {
|
|||
ITObject obj = GroupRoomService.delRoom(groupId, roomId);
|
||||
this.sendResponse(0, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查玩家今天是否已经与机器人对打过
|
||||
* @param playerId 玩家ID
|
||||
*/
|
||||
private void isPlayerRobotToday(int playerId) {
|
||||
Jedis jedis = Redis.use("group1_db3").getJedis();
|
||||
try {
|
||||
String redisKey = "player_user:" + playerId;
|
||||
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
String matchedDate = jedis.get(redisKey);
|
||||
|
||||
if (matchedDate != null && matchedDate.equals(today)) {
|
||||
logger.info("玩家{" + playerId + "}当天已与机器人对打");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("检查玩家对打记录时发生异常", e);
|
||||
} finally {
|
||||
jedis.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -594,7 +594,23 @@ public class GroupRoomService {
|
|||
}
|
||||
}
|
||||
try {
|
||||
ITObject resData = publicJoinRoom(groupId, session, room_key, platform);
|
||||
ITObject resData = publicJoinRoom(groupId,session, room_key,platform);
|
||||
|
||||
int gameId1 = resData.getInt("gameId");
|
||||
String robot_host = null;
|
||||
if(gameId1!=0) {
|
||||
if (gameId1 == 17) {
|
||||
robot_host = "8.138.120.132:8917";
|
||||
}
|
||||
if (gameId1 == 22) {
|
||||
robot_host = "8.138.120.132:8722";
|
||||
}
|
||||
}
|
||||
if(StringUtil.isNotEmpty(robot_host)) {
|
||||
sendRoboJointData(resData.getString("room_id"),groupId,robot_host,gameId1);
|
||||
}
|
||||
|
||||
|
||||
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||
jedis11.zremrangeByScore(grooms_key, 0, 0);
|
||||
jedis11.close();
|
||||
|
|
@ -1070,8 +1086,9 @@ public class GroupRoomService {
|
|||
resData = publicJoinRoom(groupId, session, key, platform);
|
||||
}
|
||||
|
||||
/* robot jefe
|
||||
//匹配
|
||||
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||
try {
|
||||
jedis11.zremrangeByScore(grooms_key, 0, 0);
|
||||
|
||||
|
|
@ -1090,22 +1107,90 @@ public class GroupRoomService {
|
|||
|
||||
if (StringUtil.isNotEmpty(gameId1)) {
|
||||
String roomid = resData.getString("room_id");
|
||||
String playersStr = jedis0.hget("room:" + roomid, "players");
|
||||
//String players = playersStr.substring(1, playersStr.length() - 1);
|
||||
//判断是否有开机器人
|
||||
sendRobotData(roomid, groupId,robot_host,Integer.parseInt(gameId1));
|
||||
|
||||
if (StringUtil.isNotEmpty(playersStr)) {
|
||||
ITArray players = TArray.newFromJsonData(playersStr);
|
||||
System.out.println("players:" + playersStr);
|
||||
if (players.size() == 2) {
|
||||
System.out.println("******************房间是2个人空的:" + roomid);
|
||||
sendRoboJointData(roomid, groupId,robot_host,Integer.parseInt(gameId1));
|
||||
} else if (players.size() == 1) {
|
||||
System.out.println("******************房间是有人的:" + roomid);
|
||||
if (Integer.parseInt(players.get(0).toString()) != acc.id) {
|
||||
sendRoboJointData(roomid, groupId,robot_host,Integer.parseInt(gameId1));
|
||||
} else {
|
||||
sendRobotData(roomid, groupId,robot_host,Integer.parseInt(gameId1));
|
||||
}
|
||||
} else {
|
||||
System.out.println("******************房间没有人的:" + roomid);
|
||||
sendRobotData(roomid, groupId,robot_host,Integer.parseInt(gameId1));
|
||||
}
|
||||
} else {
|
||||
sendRobotData(roomid, groupId,robot_host,Integer.parseInt(gameId1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} finally {
|
||||
jedis11.close();
|
||||
jedis0.close();
|
||||
}
|
||||
|
||||
*/
|
||||
return resData;
|
||||
}
|
||||
|
||||
/**
|
||||
* //发起机器人请求(HTTP 同步方式,替代原 TCP 异步多线程方式)
|
||||
*
|
||||
* 业务场景:房间里有 1 个真人玩家时,调用此方法让指定机器人加入房间陪打。
|
||||
* 机器人ID 直接从房间的 players 列表中取(已经存在房间里的人是机器人)。
|
||||
*
|
||||
* @param roomid 房间ID
|
||||
* @param groupid 群组ID
|
||||
* @param robot_host 机器人服务 TCP 地址 "ip:tcpport",HTTP 端口 = TCP端口 + 1000
|
||||
* @param gameId
|
||||
* @return
|
||||
*/
|
||||
public static ITObject sendRoboJointData(String roomid,int groupid, String robot_host,int gameId){
|
||||
System.out.println("sendRoboJointData");
|
||||
Jedis js0 = Redis.use("group1_db0").getJedis();
|
||||
Jedis js2 = Redis.use("group1_db2").getJedis();
|
||||
try {
|
||||
String robot = js0.hget("room:"+roomid,"robot");
|
||||
String plays = js0.hget("room:"+roomid,"players");
|
||||
if (StringUtil.isEmpty(plays)) {
|
||||
return null;
|
||||
}
|
||||
ITArray players = TArray.newFromJsonData(plays);
|
||||
if (players.size()!=1){
|
||||
return null;
|
||||
}
|
||||
int robotid = players.getInt(0);
|
||||
if(robotid==0){
|
||||
return null;
|
||||
}
|
||||
|
||||
String wokelock = "wokelock";
|
||||
js2.set(wokelock+robotid, String.valueOf(1));
|
||||
js2.expire(wokelock+robotid, 900);
|
||||
sleep(1000);
|
||||
//通过 HTTP 同步调用机器人服务的 225 协议入口
|
||||
String url = buildRobotHttpUrl(robot_host);
|
||||
String body = buildJoinRoomBody(robotid, roomid, groupid);
|
||||
String resp = httpPostJson(url, body, 5000);
|
||||
log.info("sendRoboJointData roomid:"+roomid+" robotid:"+robotid+" resp:"+resp);
|
||||
} catch (Exception e){
|
||||
log.error("sendRoboJointData 异常 roomid:"+roomid, e);
|
||||
} finally {
|
||||
js0.close();
|
||||
js2.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* //发起机器人请求
|
||||
* @return
|
||||
|
|
|
|||
Loading…
Reference in New Issue