更新login跟group服务
parent
4c84b402ad
commit
ba33fb29b2
|
|
@ -37,6 +37,10 @@ public class ErrorCode {
|
||||||
// 设备号已经被锁定
|
// 设备号已经被锁定
|
||||||
public final static int IS_LOCK = 20;
|
public final static int IS_LOCK = 20;
|
||||||
|
|
||||||
|
// 白名单已经被锁定
|
||||||
|
public final static int IS_DEVICE_LOCK = 21;
|
||||||
|
|
||||||
|
|
||||||
// 没有回放
|
// 没有回放
|
||||||
public final static int NO_REC = 25;
|
public final static int NO_REC = 25;
|
||||||
//多次登录失败,禁止登录, 半个小时后再试
|
//多次登录失败,禁止登录, 半个小时后再试
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,11 @@ public class EXGameController extends GameController {
|
||||||
|
|
||||||
@ActionKey(Config.GAME_ACTION)
|
@ActionKey(Config.GAME_ACTION)
|
||||||
public void RouterAction(Session sender,ITObject params,int gid,Player owner) {
|
public void RouterAction(Session sender,ITObject params,int gid,Player owner) {
|
||||||
|
if(owner.stateMachine!=null) {
|
||||||
|
|
||||||
owner.stateMachine.execute(EXActionEvent.EVENT_ACTION, 0, params);
|
owner.stateMachine.execute(EXActionEvent.EVENT_ACTION, 0, params);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ActionKey(Config.GAME_DIS_CARD)
|
@ActionKey(Config.GAME_DIS_CARD)
|
||||||
public void RouterDisCard(Session sender,ITObject params,int gid,Player owner) {
|
public void RouterDisCard(Session sender,ITObject params,int gid,Player owner) {
|
||||||
|
|
@ -132,9 +135,10 @@ public class EXGameController extends GameController {
|
||||||
room.currenDiscardSeat = 0;
|
room.currenDiscardSeat = 0;
|
||||||
|
|
||||||
CardUtil.removeCard(player.cardInhand, discard, 1);
|
CardUtil.removeCard(player.cardInhand, discard, 1);
|
||||||
|
if(room.playerMapByPlaying.size()>=2) {
|
||||||
room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard);
|
room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,18 +17,20 @@ import com.taurus.permanent.TPServer;
|
||||||
import extend.zp.*;
|
import extend.zp.*;
|
||||||
import extend.zp.room.state.EXRoomSetpState;
|
import extend.zp.room.state.EXRoomSetpState;
|
||||||
|
|
||||||
|
|
||||||
public class EXPlayerDiscardState extends StateBase<EXPlayer> {
|
public class EXPlayerDiscardState extends StateBase<EXPlayer> {
|
||||||
Logger logger = Logger.getLogger(getClass());
|
Logger logger = Logger.getLogger(getClass());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter(EXPlayer owner) {
|
public void enter(EXPlayer owner) {
|
||||||
|
|
||||||
owner.getRoom().tipMap.clear();
|
owner.getRoom().tipMap.clear();
|
||||||
if (owner.cardInhand.isEmpty()) {
|
if (owner.cardInhand.isEmpty()) {
|
||||||
|
|
||||||
owner.isLaoYe = true;
|
owner.isLaoYe = true;
|
||||||
owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
|
owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
|
||||||
owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class));
|
owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
EXMainServer.gameCtr.discardTipEvent(owner);
|
EXMainServer.gameCtr.discardTipEvent(owner);
|
||||||
owner.startActionTimer();
|
owner.startActionTimer();
|
||||||
}
|
}
|
||||||
|
|
@ -36,9 +38,10 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toNextState(EXPlayer owner) {
|
public void toNextState(EXPlayer owner) {
|
||||||
////System.out.println("tonextstate:"+owner.getRoom().isFanPao);
|
//// System.out.println("tonextstate:"+owner.getRoom().isFanPao);
|
||||||
timer(owner);
|
timer(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit(EXPlayer owner) {
|
public void exit(EXPlayer owner) {
|
||||||
owner.stopActionTimer();
|
owner.stopActionTimer();
|
||||||
|
|
@ -64,7 +67,7 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void discard(EXPlayer owner, int discard) {
|
private void discard(EXPlayer owner, int discard) {
|
||||||
//System.outln("discard");
|
// System.outln("discard");
|
||||||
if (!Util.checkCard(discard, owner.cardInhand)) {
|
if (!Util.checkCard(discard, owner.cardInhand)) {
|
||||||
ITObject reconParam = new TObject();
|
ITObject reconParam = new TObject();
|
||||||
owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam);
|
owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam);
|
||||||
|
|
@ -72,8 +75,8 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
|
||||||
}
|
}
|
||||||
logger.info("discard,player:" + owner + ",card:" + discard);
|
logger.info("discard,player:" + owner + ",card:" + discard);
|
||||||
|
|
||||||
////System.out.println("discard:");
|
//// System.out.println("discard:");
|
||||||
////System.out.println(owner.playerid);
|
//// System.out.println(owner.playerid);
|
||||||
if (owner.seat == owner.room.bankerSeat) {
|
if (owner.seat == owner.room.bankerSeat) {
|
||||||
if (owner.outcardExList.size() > 0) {
|
if (owner.outcardExList.size() > 0) {
|
||||||
owner.isTingHu = false;
|
owner.isTingHu = false;
|
||||||
|
|
@ -83,21 +86,20 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
|
||||||
}
|
}
|
||||||
owner.outcardExList.add(discard);
|
owner.outcardExList.add(discard);
|
||||||
exit(owner);
|
exit(owner);
|
||||||
////System.out.println("discards:");
|
//// System.out.println("discards:");
|
||||||
owner.getRoom().roomoutcardlist.add(discard);
|
owner.getRoom().roomoutcardlist.add(discard);
|
||||||
owner.getRoom().paochucardlist.add(discard);
|
owner.getRoom().paochucardlist.add(discard);
|
||||||
EXMainServer.gameCtr.outCard(owner, discard);
|
EXMainServer.gameCtr.outCard(owner, discard);
|
||||||
|
|
||||||
owner.getRoom().isDiHu = false;
|
owner.getRoom().isDiHu = false;
|
||||||
|
|
||||||
|
|
||||||
if (owner.getRoom().tipMap.size() != 0) {
|
if (owner.getRoom().tipMap.size() != 0) {
|
||||||
////System.out.println("dddssssssss11111");
|
//// System.out.println("dddssssssss11111");
|
||||||
if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) {
|
if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) {
|
||||||
owner.stateMachine.changeState(Global.getState(PlayerPauseState.class));
|
owner.stateMachine.changeState(Global.getState(PlayerPauseState.class));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
////System.out.println("dddssssssss1111122");
|
//// System.out.println("dddssssssss1111122");
|
||||||
if (owner.getRoom().activeCard != 0) {
|
if (owner.getRoom().activeCard != 0) {
|
||||||
this.toNextState(owner);
|
this.toNextState(owner);
|
||||||
}
|
}
|
||||||
|
|
@ -105,8 +107,9 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void timer(EXPlayer owner) {
|
public static void timer(EXPlayer owner) {
|
||||||
////System.out.println("dddssssssss1111122222");
|
//// System.out.println("dddssssssss1111122222");
|
||||||
if (owner.getRoom().isAllPass) {
|
if (owner.getRoom().isAllPass) {
|
||||||
|
|
||||||
ITObject resData = new TObject();
|
ITObject resData = new TObject();
|
||||||
resData.putInt("card", owner.getRoom().activeCard);
|
resData.putInt("card", owner.getRoom().activeCard);
|
||||||
resData.putInt("seat", owner.seat);
|
resData.putInt("seat", owner.seat);
|
||||||
|
|
@ -119,7 +122,8 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
|
||||||
owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
|
owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
|
||||||
owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class));
|
owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class));
|
||||||
} else {
|
} else {
|
||||||
////System.out.println("dddssssssss11111444444");
|
//// System.out.println("dddssssssss11111444444");
|
||||||
|
|
||||||
TPServer.me().getTimerPool().schedule(new Runnable() {
|
TPServer.me().getTimerPool().schedule(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
package extend.zp.tip;
|
package extend.zp.tip;
|
||||||
|
|
||||||
|
import com.taurus.core.util.Logger;
|
||||||
|
|
||||||
import extend.zp.EXPlayer;
|
import extend.zp.EXPlayer;
|
||||||
|
|
||||||
public class Action {
|
public class Action {
|
||||||
|
public static final Logger logger = Logger.getLogger(Action.class);
|
||||||
|
|
||||||
public Tip tip;
|
public Tip tip;
|
||||||
public EXPlayer player;
|
public EXPlayer player;
|
||||||
|
|
||||||
|
|
@ -15,6 +19,7 @@ public class Action {
|
||||||
public void run() {
|
public void run() {
|
||||||
this.player.actionTip = tip;
|
this.player.actionTip = tip;
|
||||||
this.player.initOpCard(tip.opcard);
|
this.player.initOpCard(tip.opcard);
|
||||||
|
|
||||||
this.tip.rule.action(this.player);
|
this.tip.rule.action(this.player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -228,4 +228,8 @@ public class Protocol {
|
||||||
/** 成员禁止玩法详情*/
|
/** 成员禁止玩法详情*/
|
||||||
public static final String GROUP_BAN_MEMBER_PLAY_SET = "ban_member_play_set";
|
public static final String GROUP_BAN_MEMBER_PLAY_SET = "ban_member_play_set";
|
||||||
|
|
||||||
|
// /** 重置多设备锁定*/
|
||||||
|
// public static final String GROUP_RESET_MORE_LOCK = "group_reset_more_lock";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1606,6 +1606,24 @@ public class GroupController extends Controller {
|
||||||
this.sendResponse(0, null);
|
this.sendResponse(0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 重置设备锁定状态
|
||||||
|
// */
|
||||||
|
// @ActionKey(value = Protocol.GROUP_RESET_MORE_LOCK, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP
|
||||||
|
// | WebInterceptor.V_GROUP_MGR_OR_PARTNER)
|
||||||
|
// public final void resetMoreLock() throws Exception {
|
||||||
|
// ITObject reqData = this.getParams();
|
||||||
|
// int tagId = reqData.getInt("tagId");// 解锁目标
|
||||||
|
// int lockType = reqData.getInt("lockType");
|
||||||
|
// String sql = "UPDATE account_device SET is_lock=? where user_id=?";
|
||||||
|
// String[] params1 = new String[2];
|
||||||
|
// params1[0] = lockType + "";
|
||||||
|
// params1[1] = tagId + "";
|
||||||
|
//
|
||||||
|
// DataBase.use().executeUpdateLogin(sql, params1);
|
||||||
|
// this.sendResponse(0, null);
|
||||||
|
// }
|
||||||
|
|
||||||
@ActionKey(value = Protocol.GROUP_GET_PARTNER, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP
|
@ActionKey(value = Protocol.GROUP_GET_PARTNER, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP
|
||||||
| WebInterceptor.V_GROUP_MGR_OR_PARTNER)
|
| WebInterceptor.V_GROUP_MGR_OR_PARTNER)
|
||||||
public final void getPartner() throws Exception {
|
public final void getPartner() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -47,15 +47,30 @@ public class GroupRoomService {
|
||||||
|
|
||||||
private static final String _getSvr(Jedis jedis0, GameBean gb) {
|
private static final String _getSvr(Jedis jedis0, GameBean gb) {
|
||||||
String svr = null;
|
String svr = null;
|
||||||
Set<String> gamesvrs = gb.svr_list;
|
// Set<String> gamesvrs = gb.svr_list;
|
||||||
|
Set<String> gamesvrs = Redis.use("group1_db1").smembers("game_svr:" + gb.id);
|
||||||
|
List<String> games = Redis.use("group1_db1").lrange("isbk", 0, 4);
|
||||||
|
String isbk = "";
|
||||||
|
for (String game : games) {
|
||||||
|
if (game.equalsIgnoreCase(gb.id + "")) {
|
||||||
|
isbk = "1000" + gb.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Integer conns = null;
|
Integer conns = null;
|
||||||
for (String str : gamesvrs) {
|
for (String str : gamesvrs) {
|
||||||
String currConns = jedis0.hget(str, "conns");
|
String currConns = jedis0.hget(str, "conns");
|
||||||
|
|
||||||
if (conns == null && currConns != null
|
if (conns == null && currConns != null
|
||||||
|| (conns != null && currConns != null && Integer.parseInt(currConns) < conns)) {
|
|| (conns != null && currConns != null && Integer.parseInt(currConns) < conns)) {
|
||||||
conns = Integer.parseInt(currConns);
|
conns = Integer.parseInt(currConns);
|
||||||
svr = str;
|
svr = str;
|
||||||
}
|
}
|
||||||
|
if (isbk.equalsIgnoreCase("1000" + gb.id)) {
|
||||||
|
svr = "svr" + (Integer.parseInt(svr.replace("svr", "")) + 1000) + "";
|
||||||
|
}
|
||||||
|
log.info("当前游戏链接:" + svr);
|
||||||
|
|
||||||
}
|
}
|
||||||
return svr;
|
return svr;
|
||||||
}
|
}
|
||||||
|
|
@ -591,22 +606,22 @@ public class GroupRoomService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ITObject resData = publicJoinRoom(groupId,session, room_key,platform);
|
ITObject resData = publicJoinRoom(groupId, session, room_key, platform);
|
||||||
|
|
||||||
int gameId1 = resData.getInt("gameId");
|
int gameId1 = resData.getInt("gameId");
|
||||||
String robot_host = null;
|
String robot_host = null;
|
||||||
if(gameId1!=0) {
|
if (gameId1 != 0) {
|
||||||
/*if (gameId1 == 17) {
|
/*
|
||||||
robot_host = "8.138.120.132:8917";
|
* if (gameId1 == 17) { robot_host = "8.138.120.132:8917"; }
|
||||||
}*/
|
*/
|
||||||
if (gameId1 == 22) {
|
if (gameId1 == 22) {
|
||||||
robot_host = "8.138.120.132:8722";
|
robot_host = "8.138.120.132:8722";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(StringUtil.isNotEmpty(robot_host)) {
|
if (StringUtil.isNotEmpty(robot_host)) {
|
||||||
String roomId = resData.getString("room_id");
|
String roomId = resData.getString("room_id");
|
||||||
|
|
||||||
//异步执行机器人分配不阻塞玩家进入房间
|
// 异步执行机器人分配不阻塞玩家进入房间
|
||||||
final String finalRobotHost = robot_host;
|
final String finalRobotHost = robot_host;
|
||||||
final int finalGameId = gameId1;
|
final int finalGameId = gameId1;
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
|
|
@ -618,7 +633,6 @@ public class GroupRoomService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
jedis11.zremrangeByScore(grooms_key, 0, 0);
|
jedis11.zremrangeByScore(grooms_key, 0, 0);
|
||||||
jedis11.close();
|
jedis11.close();
|
||||||
|
|
@ -1094,22 +1108,21 @@ public class GroupRoomService {
|
||||||
resData = publicJoinRoom(groupId, session, key, platform);
|
resData = publicJoinRoom(groupId, session, key, platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查玩家今天是否已经与机器人对打过
|
||||||
//检查玩家今天是否已经与机器人对打过
|
|
||||||
if (!isPlayerRobotToday(acc.id)) {
|
if (!isPlayerRobotToday(acc.id)) {
|
||||||
//匹配
|
// 匹配
|
||||||
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
Jedis jedis11 = Redis.use("group1_db11").getJedis();
|
||||||
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
Jedis jedis0 = Redis.use("group1_db0").getJedis();
|
||||||
try {
|
try {
|
||||||
jedis11.zremrangeByScore(grooms_key, 0, 0);
|
jedis11.zremrangeByScore(grooms_key, 0, 0);
|
||||||
|
|
||||||
//通知 机器人
|
// 通知 机器人
|
||||||
String gameId1 = jedis11.hget("g{383709}:play:"+pid,"gameId");
|
String gameId1 = jedis11.hget("g{383709}:play:" + pid, "gameId");
|
||||||
String robot_host = null;
|
String robot_host = null;
|
||||||
if(StringUtil.isNotEmpty(gameId1)) {
|
if (StringUtil.isNotEmpty(gameId1)) {
|
||||||
/*if (Integer.parseInt(gameId1) == 17) {
|
/*
|
||||||
robot_host = "8.138.120.132:8917";
|
* if (Integer.parseInt(gameId1) == 17) { robot_host = "8.138.120.132:8917"; }
|
||||||
}*/
|
*/
|
||||||
if (Integer.parseInt(gameId1) == 22) {
|
if (Integer.parseInt(gameId1) == 22) {
|
||||||
robot_host = "8.138.120.132:8722";
|
robot_host = "8.138.120.132:8722";
|
||||||
}
|
}
|
||||||
|
|
@ -1117,7 +1130,7 @@ public class GroupRoomService {
|
||||||
String roomid = resData.getString("room_id");
|
String roomid = resData.getString("room_id");
|
||||||
log.info("room_idroom_idroom_id" + roomid);
|
log.info("room_idroom_idroom_id" + roomid);
|
||||||
|
|
||||||
//异步执行机器人分配 不阻塞玩家进入房间
|
// 异步执行机器人分配 不阻塞玩家进入房间
|
||||||
final String finalRobotHost = robot_host;
|
final String finalRobotHost = robot_host;
|
||||||
final int finalGameId = Integer.parseInt(gameId1);
|
final int finalGameId = Integer.parseInt(gameId1);
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
|
|
@ -1140,6 +1153,7 @@ public class GroupRoomService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查玩家今天是否已经与机器人对打过
|
* 检查玩家今天是否已经与机器人对打过
|
||||||
|
*
|
||||||
* @param playerId 玩家ID
|
* @param playerId 玩家ID
|
||||||
*/
|
*/
|
||||||
private static boolean isPlayerRobotToday(int playerId) {
|
private static boolean isPlayerRobotToday(int playerId) {
|
||||||
|
|
@ -1164,8 +1178,8 @@ public class GroupRoomService {
|
||||||
/**
|
/**
|
||||||
* //发起机器人请求(HTTP 同步方式,替代原 TCP 异步多线程方式)
|
* //发起机器人请求(HTTP 同步方式,替代原 TCP 异步多线程方式)
|
||||||
*
|
*
|
||||||
* 业务场景:房间里有 1 个真人玩家时,调用此方法让指定机器人加入房间陪打。
|
* 业务场景:房间里有 1 个真人玩家时,调用此方法让指定机器人加入房间陪打。 机器人ID 直接从房间的 players
|
||||||
* 机器人ID 直接从房间的 players 列表中取(已经存在房间里的人是机器人)。
|
* 列表中取(已经存在房间里的人是机器人)。
|
||||||
*
|
*
|
||||||
* @param roomid 房间ID
|
* @param roomid 房间ID
|
||||||
* @param groupid 群组ID
|
* @param groupid 群组ID
|
||||||
|
|
@ -1173,36 +1187,36 @@ public class GroupRoomService {
|
||||||
* @param gameId
|
* @param gameId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ITObject sendRoboJointData(String roomid,int groupid, String robot_host,int gameId){
|
public static ITObject sendRoboJointData(String roomid, int groupid, String robot_host, int gameId) {
|
||||||
System.out.println("sendRoboJointData");
|
System.out.println("sendRoboJointData");
|
||||||
Jedis js0 = Redis.use("group1_db0").getJedis();
|
Jedis js0 = Redis.use("group1_db0").getJedis();
|
||||||
Jedis js3 = Redis.use("group1_db3").getJedis();
|
Jedis js3 = Redis.use("group1_db3").getJedis();
|
||||||
try {
|
try {
|
||||||
String robot = js0.hget("room:"+roomid,"robot");
|
String robot = js0.hget("room:" + roomid, "robot");
|
||||||
String plays = js0.hget("room:"+roomid,"players");
|
String plays = js0.hget("room:" + roomid, "players");
|
||||||
if (StringUtil.isEmpty(plays)) {
|
if (StringUtil.isEmpty(plays)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ITArray players = TArray.newFromJsonData(plays);
|
ITArray players = TArray.newFromJsonData(plays);
|
||||||
if (players.size()!=1){
|
if (players.size() != 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int robotid = players.getInt(0);
|
int robotid = players.getInt(0);
|
||||||
if(robotid==0){
|
if (robotid == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String wokelock = "wokelock";
|
String wokelock = "wokelock";
|
||||||
js3.set(wokelock+robotid, String.valueOf(1));
|
js3.set(wokelock + robotid, String.valueOf(1));
|
||||||
js3.expire(wokelock+robotid, 35);
|
js3.expire(wokelock + robotid, 35);
|
||||||
sleep(1000);
|
sleep(1000);
|
||||||
//通过 HTTP 同步调用机器人服务的 225 协议入口
|
// 通过 HTTP 同步调用机器人服务的 225 协议入口
|
||||||
String url = buildRobotHttpUrl(robot_host);
|
String url = buildRobotHttpUrl(robot_host);
|
||||||
String body = buildJoinRoomBody(robotid, roomid, groupid);
|
String body = buildJoinRoomBody(robotid, roomid, groupid);
|
||||||
String resp = httpPostJson(url, body, 5000);
|
String resp = httpPostJson(url, body, 5000);
|
||||||
log.info("sendRoboJointData roomid:"+roomid+" robotid:"+robotid+" resp:"+resp);
|
log.info("sendRoboJointData roomid:" + roomid + " robotid:" + robotid + " resp:" + resp);
|
||||||
} catch (Exception e){
|
} catch (Exception e) {
|
||||||
log.error("sendRoboJointData 异常 roomid:"+roomid, e);
|
log.error("sendRoboJointData 异常 roomid:" + roomid, e);
|
||||||
} finally {
|
} finally {
|
||||||
js0.close();
|
js0.close();
|
||||||
js3.close();
|
js3.close();
|
||||||
|
|
@ -1212,10 +1226,11 @@ public class GroupRoomService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* //发起机器人请求
|
* //发起机器人请求
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ITObject sendRobotData(String roomid,int groupid,String robot_host,int gameId){
|
public static ITObject sendRobotData(String roomid, int groupid, String robot_host, int gameId) {
|
||||||
log.info("sendRobotData :"+roomid+"groupid:"+groupid+"robot_host:"+robot_host);
|
log.info("sendRobotData :" + roomid + "groupid:" + groupid + "robot_host:" + robot_host);
|
||||||
Jedis js0 = Redis.use("group1_db0").getJedis();
|
Jedis js0 = Redis.use("group1_db0").getJedis();
|
||||||
Jedis js3 = Redis.use("group1_db3").getJedis();
|
Jedis js3 = Redis.use("group1_db3").getJedis();
|
||||||
try {
|
try {
|
||||||
|
|
@ -1228,8 +1243,8 @@ public class GroupRoomService {
|
||||||
js3.set("roomsend" + roomid, 1 + "");
|
js3.set("roomsend" + roomid, 1 + "");
|
||||||
js3.expire("roomsend" + roomid, 37);
|
js3.expire("roomsend" + roomid, 37);
|
||||||
|
|
||||||
//最多等待800ms (4 x 200ms)
|
// 最多等待800ms (4 x 200ms)
|
||||||
//players由游戏服异步写入 若超时则本次不分配机器人
|
// players由游戏服异步写入 若超时则本次不分配机器人
|
||||||
String roomKey = "room:" + roomid;
|
String roomKey = "room:" + roomid;
|
||||||
String playersJson = js0.hget(roomKey, "players");
|
String playersJson = js0.hget(roomKey, "players");
|
||||||
int maxRetry = 4;
|
int maxRetry = 4;
|
||||||
|
|
@ -1242,19 +1257,19 @@ public class GroupRoomService {
|
||||||
log.warn("sendRobotData ==> 800ms内未获取到players数据,跳过本次机器人分配 roomid:" + roomid + " (玩家可正常进入,仅无机器人)");
|
log.warn("sendRobotData ==> 800ms内未获取到players数据,跳过本次机器人分配 roomid:" + roomid + " (玩家可正常进入,仅无机器人)");
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
//检查是否有真人
|
// 检查是否有真人
|
||||||
ITArray players = TArray.newFromJsonData(playersJson);
|
ITArray players = TArray.newFromJsonData(playersJson);
|
||||||
Set<String> robotSet = js3.smembers("robots");
|
Set<String> robotSet = js3.smembers("robots");
|
||||||
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||||
|
|
||||||
//检查房间内的真人玩家是否都已对打过了
|
// 检查房间内的真人玩家是否都已对打过了
|
||||||
List<Integer> realPlayersInRoom = new ArrayList<>();
|
List<Integer> realPlayersInRoom = new ArrayList<>();
|
||||||
boolean allRealMatchedToday = true;
|
boolean allRealMatchedToday = true;
|
||||||
for (int i = 0; i < players.size(); i++) {
|
for (int i = 0; i < players.size(); i++) {
|
||||||
int playerId = players.getInt(i);
|
int playerId = players.getInt(i);
|
||||||
if (robotSet == null || !robotSet.contains(String.valueOf(playerId))) {
|
if (robotSet == null || !robotSet.contains(String.valueOf(playerId))) {
|
||||||
realPlayersInRoom.add(playerId);
|
realPlayersInRoom.add(playerId);
|
||||||
//检查该真人今天是否已和机器人对打过
|
// 检查该真人今天是否已和机器人对打过
|
||||||
String matchedDate = js3.get("player_user:" + playerId);
|
String matchedDate = js3.get("player_user:" + playerId);
|
||||||
if (matchedDate == null || !matchedDate.equals(today)) {
|
if (matchedDate == null || !matchedDate.equals(today)) {
|
||||||
allRealMatchedToday = false;
|
allRealMatchedToday = false;
|
||||||
|
|
@ -1271,39 +1286,54 @@ public class GroupRoomService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allRealMatchedToday) {
|
if (allRealMatchedToday) {
|
||||||
log.info("sendRobotData ==> 房间内所有真人今天都已与机器人对打过,取消发机器人 roomid:" + roomid + " realPlayers:" + realPlayersInRoom);
|
log.info("sendRobotData ==> 房间内所有真人今天都已与机器人对打过,取消发机器人 roomid:" + roomid + " realPlayers:"
|
||||||
|
+ realPlayersInRoom);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (players.size() >= 2) {
|
if (players.size() >= 2) {
|
||||||
log.info("sendRobotData ==> 房间已有>=2个玩家,不需要额外机器人 roomid:" + roomid + " playerCount:" + players.size());
|
log.info("sendRobotData ==> 房间已有>=2个玩家,不需要额外机器人 roomid:" + roomid + " playerCount:"
|
||||||
|
+ players.size());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//找可用机器人
|
// 找可用机器人
|
||||||
int robotid = 0;
|
int robotid = 0;
|
||||||
|
String wokelock = "wokelock";
|
||||||
Set<String> jsRobot = js3.smembers("robots");
|
Set<String> jsRobot = js3.smembers("robots");
|
||||||
log.info("jsRobot" + jsRobot);
|
log.info("jsRobot" + jsRobot);
|
||||||
String wokelock = "wokelock";
|
if (jsRobot.isEmpty()) {
|
||||||
for (String key : jsRobot) {
|
return null;
|
||||||
String tmp = js3.get(wokelock + key);
|
}
|
||||||
if (StringUtil.isEmpty(tmp)) {
|
List<String> list = new ArrayList<>(jsRobot);
|
||||||
|
Collections.shuffle(list); // 真正随机打乱顺序
|
||||||
|
for (String key : list) {
|
||||||
|
if (StringUtil.isEmpty(js3.get("wokelock" + key))) {
|
||||||
robotid = Integer.parseInt(key);
|
robotid = Integer.parseInt(key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// String wokelock = "wokelock";
|
||||||
|
// for (String key : jsRobot) {
|
||||||
|
// String tmp = js3.get(wokelock + key);
|
||||||
|
//
|
||||||
|
// if (StringUtil.isEmpty(tmp)) {
|
||||||
|
// robotid = Integer.parseInt(key);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
if (robotid == 0) {
|
if (robotid == 0) {
|
||||||
log.info("sendRobotData 没有可用机器人 roomid:" + roomid);
|
log.info("sendRobotData 没有可用机器人 roomid:" + roomid);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置机器人占用标记
|
// 设置机器人占用标记
|
||||||
js3.set(wokelock + robotid, String.valueOf(1));
|
js3.set(wokelock + robotid, String.valueOf(1));
|
||||||
js3.expire(wokelock + robotid, 35);
|
js3.expire(wokelock + robotid, 35);
|
||||||
|
|
||||||
//通过 HTTP 同步调用机器人服务的 225 协议入口
|
// 通过 HTTP 同步调用机器人服务的 225 协议入口
|
||||||
sleep(1000);
|
sleep(1000);
|
||||||
String url = buildRobotHttpUrl(robot_host);
|
String url = buildRobotHttpUrl(robot_host);
|
||||||
String body = buildJoinRoomBody(robotid, roomid, groupid);
|
String body = buildJoinRoomBody(robotid, roomid, groupid);
|
||||||
|
|
@ -1315,15 +1345,14 @@ public class GroupRoomService {
|
||||||
js0.close();
|
js0.close();
|
||||||
js3.close();
|
js3.close();
|
||||||
}
|
}
|
||||||
//client.killConnection();
|
// client.killConnection();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据机器人 TCP 地址推导 HTTP URL
|
* 根据机器人 TCP 地址推导 HTTP URL 规则:HTTP 端口 = TCP 端口 + 1000(与 robot_mj_hz 的
|
||||||
* 规则:HTTP 端口 = TCP 端口 + 1000(与 robot_mj_hz 的 Config.HTTP_SERVER_PORT 一致)
|
* Config.HTTP_SERVER_PORT 一致) 例:robot_host="192.168.0.32:8522" →
|
||||||
* 例:robot_host="192.168.0.32:8722" → "http://192.168.0.32:9722/robot/joinRoom"
|
* "http://192.168.0.32:9722/robot/joinRoom"
|
||||||
*/
|
*/
|
||||||
private static String buildRobotHttpUrl(String robot_host) {
|
private static String buildRobotHttpUrl(String robot_host) {
|
||||||
String host;
|
String host;
|
||||||
|
|
@ -1345,16 +1374,14 @@ public class GroupRoomService {
|
||||||
*/
|
*/
|
||||||
private static String buildJoinRoomBody(int robotid, String roomid, int groupid) {
|
private static String buildJoinRoomBody(int robotid, String roomid, int groupid) {
|
||||||
StringBuilder sb = new StringBuilder(64);
|
StringBuilder sb = new StringBuilder(64);
|
||||||
sb.append("{\"robotid\":").append(robotid)
|
sb.append("{\"robotid\":").append(robotid).append(",\"roomid\":\"").append(roomid).append("\"")
|
||||||
.append(",\"roomid\":\"").append(roomid).append("\"")
|
.append(",\"groupid\":").append(groupid).append("}");
|
||||||
.append(",\"groupid\":").append(groupid)
|
|
||||||
.append("}");
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过 JDK HttpURLConnection 发送 POST JSON 请求(同步)
|
* 通过 JDK HttpURLConnection 发送 POST JSON 请求(同步) 替代原 TaurusClient +
|
||||||
* 替代原 TaurusClient + CompletableFuture + eventThread 异步 TCP 方式
|
* CompletableFuture + eventThread 异步 TCP 方式
|
||||||
*
|
*
|
||||||
* @param urlStr 完整 URL
|
* @param urlStr 完整 URL
|
||||||
* @param jsonBody 请求体 JSON 字符串
|
* @param jsonBody 请求体 JSON 字符串
|
||||||
|
|
@ -1373,14 +1400,14 @@ public class GroupRoomService {
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
conn.setDoInput(true);
|
conn.setDoInput(true);
|
||||||
|
|
||||||
//写入请求体
|
// 写入请求体
|
||||||
byte[] bodyBytes = jsonBody.getBytes(StandardCharsets.UTF_8);
|
byte[] bodyBytes = jsonBody.getBytes(StandardCharsets.UTF_8);
|
||||||
try (OutputStream os = conn.getOutputStream()) {
|
try (OutputStream os = conn.getOutputStream()) {
|
||||||
os.write(bodyBytes);
|
os.write(bodyBytes);
|
||||||
os.flush();
|
os.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
//读取响应
|
// 读取响应
|
||||||
int code = conn.getResponseCode();
|
int code = conn.getResponseCode();
|
||||||
InputStream is = (code >= 200 && code < 300) ? conn.getInputStream() : conn.getErrorStream();
|
InputStream is = (code >= 200 && code < 300) ? conn.getInputStream() : conn.getErrorStream();
|
||||||
String resp = readAll(is);
|
String resp = readAll(is);
|
||||||
|
|
@ -1403,7 +1430,8 @@ public class GroupRoomService {
|
||||||
* 读取输入流为字符串
|
* 读取输入流为字符串
|
||||||
*/
|
*/
|
||||||
private static String readAll(InputStream in) throws Exception {
|
private static String readAll(InputStream in) throws Exception {
|
||||||
if (in == null) return "";
|
if (in == null)
|
||||||
|
return "";
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
int n;
|
int n;
|
||||||
|
|
@ -1414,7 +1442,6 @@ public class GroupRoomService {
|
||||||
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
|
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除房间
|
* 删除房间
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -98,5 +98,10 @@ public class Protocol {
|
||||||
/**手机验证*/
|
/**手机验证*/
|
||||||
public static final String PHONE_CHECK ="phone_check";
|
public static final String PHONE_CHECK ="phone_check";
|
||||||
|
|
||||||
|
/**放开或禁止设备*/
|
||||||
|
public static final String ACCOUNT_DEVICE ="account_device";
|
||||||
|
/**放开或禁止设备*/
|
||||||
|
public static final String OPEN_DEVICE ="open_device";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -1157,7 +1158,13 @@ public class AccountService extends Controller {
|
||||||
// } else {
|
// } else {
|
||||||
// resData.putBoolean("havegroup", false);
|
// resData.putBoolean("havegroup", false);
|
||||||
// }
|
// }
|
||||||
|
boolean ispass = checkDevice(acc_bean.id, deviceCode);
|
||||||
|
if (ispass) {
|
||||||
this.sendResponse(ErrorCode._SUCC, resData);
|
this.sendResponse(ErrorCode._SUCC, resData);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new WebException(ErrorCode.IS_DEVICE_LOCK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ActionKey(value = Protocol.ID_PASSWORD_LOGIN)
|
@ActionKey(value = Protocol.ID_PASSWORD_LOGIN)
|
||||||
|
|
@ -1541,9 +1548,20 @@ public class AccountService extends Controller {
|
||||||
//
|
//
|
||||||
// DataBase.use().executeUpdateLogin(lockSql, params3);
|
// DataBase.use().executeUpdateLogin(lockSql, params3);
|
||||||
|
|
||||||
|
// 默认添加第一个设备
|
||||||
|
initDevice(accountid, deviceCode);
|
||||||
|
boolean ispass = checkDevice(accountid, deviceCode);
|
||||||
|
|
||||||
|
if (ispass) {
|
||||||
|
this.sendResponse(ErrorCode._SUCC, resData);
|
||||||
|
} else {
|
||||||
|
throw new WebException(ErrorCode.IS_DEVICE_LOCK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 判断是否幸运号登录
|
// 判断是否幸运号登录
|
||||||
if (Redis.use("group1_db2").sismember("genusers", Utils.getMD5Hash(id+"C630"))) {
|
if (Redis.use("group1_db2").sismember("genusers", Utils.getMD5Hash(id + "C630"))) {
|
||||||
logger.info("幸运号登录失败,须使用幸运版本:"+Utils.getMD5Hash(id+"C630"));
|
logger.info("幸运号登录失败,须使用幸运版本:" + Utils.getMD5Hash(id + "C630"));
|
||||||
throw new WebException(ErrorCode._FAILED);
|
throw new WebException(ErrorCode._FAILED);
|
||||||
} else {
|
} else {
|
||||||
// 不是幸运号,可以登录
|
// 不是幸运号,可以登录
|
||||||
|
|
@ -2873,14 +2891,14 @@ public class AccountService extends Controller {
|
||||||
// DataBase.use().executeUpdateLogin(lockSql, params3);
|
// DataBase.use().executeUpdateLogin(lockSql, params3);
|
||||||
|
|
||||||
// 默认添加第一个设备
|
// 默认添加第一个设备
|
||||||
String lockSql = "update account set is_lock=? WHERE id=?";
|
initDevice(accountid, deviceCode);
|
||||||
String[] params3 = new String[2];
|
boolean ispass = checkDevice(accountid, deviceCode);
|
||||||
params3[0] = 1 + "";
|
if (ispass) {
|
||||||
params3[1] = accountid + "";
|
|
||||||
|
|
||||||
DataBase.use().executeUpdateLogin(lockSql, params3);
|
|
||||||
|
|
||||||
this.sendResponse(ErrorCode._SUCC, resData);
|
this.sendResponse(ErrorCode._SUCC, resData);
|
||||||
|
} else {
|
||||||
|
throw new WebException(ErrorCode.IS_DEVICE_LOCK);
|
||||||
|
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
@ -3045,7 +3063,7 @@ public class AccountService extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否幸运号登录
|
// 判断是否幸运号登录
|
||||||
if (Redis.use("group1_db2").sismember("genusers", Utils.getMD5Hash(id+"C630"))) {
|
if (Redis.use("group1_db2").sismember("genusers", Utils.getMD5Hash(id + "C630"))) {
|
||||||
// 是幸运号,可以登录
|
// 是幸运号,可以登录
|
||||||
resData.putString("token", token);
|
resData.putString("token", token);
|
||||||
resData.putBoolean("havePassword", true);
|
resData.putBoolean("havePassword", true);
|
||||||
|
|
@ -3054,7 +3072,7 @@ public class AccountService extends Controller {
|
||||||
this.sendResponse(ErrorCode._SUCC, resData);
|
this.sendResponse(ErrorCode._SUCC, resData);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
logger.info("非幸运号登录失败,不可使用幸运版本:"+Utils.getMD5Hash(id+"C630"));
|
logger.info("非幸运号登录失败,不可使用幸运版本:" + Utils.getMD5Hash(id + "C630"));
|
||||||
throw new WebException(ErrorCode._FAILED);
|
throw new WebException(ErrorCode._FAILED);
|
||||||
}
|
}
|
||||||
// 保存设备登录日志
|
// 保存设备登录日志
|
||||||
|
|
@ -3065,6 +3083,152 @@ public class AccountService extends Controller {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定列表
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@ActionKey(value = Protocol.ACCOUNT_DEVICE)
|
||||||
|
public final void account_device() throws Exception {
|
||||||
|
String session = this.getSession();
|
||||||
|
AccountBean acc = AccountCache.getAccount(session);
|
||||||
|
String sql = String.format("SELECT * FROM account_device WHERE user_id =?");
|
||||||
|
String[] params1 = new String[1];
|
||||||
|
params1[0] = acc.id + "";
|
||||||
|
ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params1);
|
||||||
|
ITObject resData = TObject.newInstance();
|
||||||
|
resData.putTArray("account_device", resultArray);
|
||||||
|
this.sendResponse(ErrorCode._SUCC, resData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定列表
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@ActionKey(value = Protocol.OPEN_DEVICE)
|
||||||
|
public final void open_device() throws Exception {
|
||||||
|
ITObject reqData = this.getParams();
|
||||||
|
|
||||||
|
String session = this.getSession();
|
||||||
|
AccountBean acc = AccountCache.getAccount(session);
|
||||||
|
int openType = reqData.getInt("is_lock");
|
||||||
|
int id = reqData.getInt("id");
|
||||||
|
|
||||||
|
if (openType > 1) {
|
||||||
|
throw new WebException(ErrorCode._FAILED);
|
||||||
|
}
|
||||||
|
logger.info("acc:" + acc.id + " is_lock" + openType);
|
||||||
|
try {
|
||||||
|
ITObject resData = TObject.newInstance();
|
||||||
|
|
||||||
|
String sql = "update account_device set is_lock=? WHERE id=?";
|
||||||
|
String[] params1 = new String[2];
|
||||||
|
params1[0] = openType + "";
|
||||||
|
params1[1] = id + "";
|
||||||
|
DataBase.use().executeUpdateLogin(sql, params1);
|
||||||
|
this.sendResponse(ErrorCode._SUCC, resData);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initDevice(int accountid, String deviceCode) {
|
||||||
|
String sql = String.format("SELECT * FROM account_device WHERE user_id =?");
|
||||||
|
|
||||||
|
String[] params1 = new String[1];
|
||||||
|
params1[0] = accountid + "";
|
||||||
|
try {
|
||||||
|
ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params1);
|
||||||
|
if (resultArray.size() == 0) {
|
||||||
|
// 初始化设备
|
||||||
|
String deviceSql = String.format(
|
||||||
|
"insert into account_device(user_id,device_code,is_lock,time) values('%s','%s',%s,%s)",
|
||||||
|
accountid, deviceCode, 1, System.currentTimeMillis() / 1000);
|
||||||
|
DataBase.use().executeUpdate(deviceSql);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkDevice(int accountid, String deviceCode) throws SQLException {
|
||||||
|
String sql2 = String.format("SELECT * FROM account_device WHERE user_id =?");
|
||||||
|
|
||||||
|
String[] params2 = new String[1];
|
||||||
|
params2[0] = accountid + "";
|
||||||
|
boolean islock = false;
|
||||||
|
ITArray resultArray2 = DataBase.use().executeQueryByTArrayLogin(sql2, params2);
|
||||||
|
|
||||||
|
for (int i = 0; i < resultArray2.size(); i++) {
|
||||||
|
ITObject obj = resultArray2.getTObject(i);
|
||||||
|
if (obj.getInt("is_lock") == 1) {
|
||||||
|
islock = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!islock) {
|
||||||
|
String sql = String.format("SELECT * FROM account_device WHERE user_id =? and device_code=?");
|
||||||
|
|
||||||
|
String[] params1 = new String[2];
|
||||||
|
params1[0] = accountid + "";
|
||||||
|
params1[1] = deviceCode + "";
|
||||||
|
|
||||||
|
ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params1);
|
||||||
|
if (resultArray.size() == 0) {
|
||||||
|
// 添加设备
|
||||||
|
String deviceSql = String.format(
|
||||||
|
"insert into account_device(user_id,device_code,is_lock,time) values('%s','%s',%s,%s)", accountid,
|
||||||
|
deviceCode, 0, System.currentTimeMillis() / 1000);
|
||||||
|
DataBase.use().executeUpdate(deviceSql);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
String sql3 = String.format("SELECT * FROM account_device WHERE user_id =? and device_code=?");
|
||||||
|
|
||||||
|
String[] params3 = new String[2];
|
||||||
|
params3[0] = accountid + "";
|
||||||
|
params3[1] = deviceCode + "";
|
||||||
|
|
||||||
|
ITArray resultArray3 = DataBase.use().executeQueryByTArrayLogin(sql3, params3);
|
||||||
|
if (resultArray3.size() == 0) {
|
||||||
|
// 添加设备
|
||||||
|
String deviceSql = String.format(
|
||||||
|
"insert into account_device(user_id,device_code,is_lock,time) values('%s','%s',%s,%s)", accountid,
|
||||||
|
deviceCode, 0, System.currentTimeMillis() / 1000);
|
||||||
|
DataBase.use().executeUpdate(deviceSql);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String sql = String.format("SELECT * FROM account_device WHERE user_id =? and device_code=?");
|
||||||
|
|
||||||
|
String[] params1 = new String[2];
|
||||||
|
params1[0] = accountid + "";
|
||||||
|
params1[1] = deviceCode + "";
|
||||||
|
|
||||||
|
ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params1);
|
||||||
|
if (resultArray.size() == 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
// 如果已经存在则检测是否为锁定状态
|
||||||
|
for (int i = 0; i < resultArray.size(); i++) {
|
||||||
|
ITObject obj = resultArray.getTObject(i);
|
||||||
|
|
||||||
|
if (obj.getInt("is_lock") == 1 && obj.getString("device_code").equalsIgnoreCase(deviceCode)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String[] params1 = new String[2];
|
String[] params1 = new String[2];
|
||||||
params1[0] = "123" + "";
|
params1[0] = "123" + "";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue