验证是否打过

master
zhouwei 2026-07-10 00:41:09 +08:00
parent 4de59b6d59
commit 32dfab453c
2 changed files with 66 additions and 68 deletions

View File

@ -43,10 +43,6 @@ 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);
}
@ -90,25 +86,4 @@ public class GroupRoomController extends Controller {
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();
}
}
}

View File

@ -6,12 +6,8 @@ import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import com.data.bean.AccountBean;
@ -1086,6 +1082,10 @@ public class GroupRoomService {
resData = publicJoinRoom(groupId, session, key, platform);
}
//检查玩家今天是否已经与机器人对打过
if (!isPlayerRobotToday(acc.id)) {
log.info("matchRoom() ==> 玩家今天和机器人对打过了isPlayerRobotToday = " + isPlayerRobotToday(acc.id));
//匹配
Jedis jedis11 = Redis.use("group1_db11").getJedis();
Jedis jedis0 = Redis.use("group1_db0").getJedis();
@ -1138,10 +1138,33 @@ public class GroupRoomService {
jedis11.close();
jedis0.close();
}
}
return resData;
}
/**
*
* @param playerId ID
*/
private static boolean 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)) {
log.info("玩家{" + playerId + "}当天已与机器人对打");
return true;
}
} catch (Exception e) {
log.error("检查玩家对打记录时发生异常", e);
} finally {
jedis.close();
}
return false;
}
/**
* //发起机器人请求HTTP 同步方式,替代原 TCP 异步多线程方式)
*