更新login跟group服务

master
李泽帆 2026-08-17 16:34:13 +08:00
parent 4c84b402ad
commit ba33fb29b2
10 changed files with 330 additions and 95 deletions

View File

@ -37,6 +37,10 @@ public class ErrorCode {
// 设备号已经被锁定
public final static int IS_LOCK = 20;
// 白名单已经被锁定
public final static int IS_DEVICE_LOCK = 21;
// 没有回放
public final static int NO_REC = 25;
//多次登录失败,禁止登录, 半个小时后再试

View File

@ -29,7 +29,10 @@ public class EXGameController extends GameController {
@ActionKey(Config.GAME_ACTION)
public void RouterAction(Session sender,ITObject params,int gid,Player owner) {
owner.stateMachine.execute(EXActionEvent.EVENT_ACTION, 0, params);
if(owner.stateMachine!=null) {
owner.stateMachine.execute(EXActionEvent.EVENT_ACTION, 0, params);
}
}
@ActionKey(Config.GAME_DIS_CARD)
@ -132,8 +135,9 @@ public class EXGameController extends GameController {
room.currenDiscardSeat = 0;
CardUtil.removeCard(player.cardInhand, discard, 1);
room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard);
if(room.playerMapByPlaying.size()>=2) {
room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard);
}
}
}

View File

@ -17,18 +17,20 @@ import com.taurus.permanent.TPServer;
import extend.zp.*;
import extend.zp.room.state.EXRoomSetpState;
public class EXPlayerDiscardState extends StateBase<EXPlayer> {
Logger logger = Logger.getLogger(getClass());
@Override
public void enter(EXPlayer owner) {
owner.getRoom().tipMap.clear();
if (owner.cardInhand.isEmpty()) {
owner.isLaoYe = true;
owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class));
} else {
EXMainServer.gameCtr.discardTipEvent(owner);
owner.startActionTimer();
}
@ -36,9 +38,10 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
@Override
public void toNextState(EXPlayer owner) {
////System.out.println("tonextstate:"+owner.getRoom().isFanPao);
//// System.out.println("tonextstate:"+owner.getRoom().isFanPao);
timer(owner);
}
@Override
public void exit(EXPlayer owner) {
owner.stopActionTimer();
@ -64,7 +67,7 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
}
private void discard(EXPlayer owner, int discard) {
//System.outln("discard");
// System.outln("discard");
if (!Util.checkCard(discard, owner.cardInhand)) {
ITObject reconParam = new TObject();
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);
////System.out.println("discard:");
////System.out.println(owner.playerid);
//// System.out.println("discard:");
//// System.out.println(owner.playerid);
if (owner.seat == owner.room.bankerSeat) {
if (owner.outcardExList.size() > 0) {
owner.isTingHu = false;
@ -83,21 +86,20 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
}
owner.outcardExList.add(discard);
exit(owner);
////System.out.println("discards:");
//// System.out.println("discards:");
owner.getRoom().roomoutcardlist.add(discard);
owner.getRoom().paochucardlist.add(discard);
EXMainServer.gameCtr.outCard(owner, discard);
owner.getRoom().isDiHu = false;
if (owner.getRoom().tipMap.size() != 0) {
////System.out.println("dddssssssss11111");
//// System.out.println("dddssssssss11111");
if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) {
owner.stateMachine.changeState(Global.getState(PlayerPauseState.class));
}
}
} else {
////System.out.println("dddssssssss1111122");
//// System.out.println("dddssssssss1111122");
if (owner.getRoom().activeCard != 0) {
this.toNextState(owner);
}
@ -105,8 +107,9 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
}
public static void timer(EXPlayer owner) {
////System.out.println("dddssssssss1111122222");
//// System.out.println("dddssssssss1111122222");
if (owner.getRoom().isAllPass) {
ITObject resData = new TObject();
resData.putInt("card", owner.getRoom().activeCard);
resData.putInt("seat", owner.seat);
@ -119,7 +122,8 @@ public class EXPlayerDiscardState extends StateBase<EXPlayer> {
owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class));
} else {
////System.out.println("dddssssssss11111444444");
//// System.out.println("dddssssssss11111444444");
TPServer.me().getTimerPool().schedule(new Runnable() {
@Override
public void run() {

View File

@ -1,10 +1,14 @@
package extend.zp.tip;
import com.taurus.core.util.Logger;
import extend.zp.EXPlayer;
public class Action {
public Tip tip;
public EXPlayer player;
public static final Logger logger = Logger.getLogger(Action.class);
public Tip tip;
public EXPlayer player;
public Action(Tip tip, EXPlayer player) {
this.tip = tip;
@ -15,6 +19,7 @@ public class Action {
public void run() {
this.player.actionTip = tip;
this.player.initOpCard(tip.opcard);
this.tip.rule.action(this.player);
}
}

View File

@ -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_RESET_MORE_LOCK = "group_reset_more_lock";
}

View File

@ -1606,6 +1606,24 @@ public class GroupController extends Controller {
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
| WebInterceptor.V_GROUP_MGR_OR_PARTNER)
public final void getPartner() throws Exception {

View File

@ -47,15 +47,30 @@ public class GroupRoomService {
private static final String _getSvr(Jedis jedis0, GameBean gb) {
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;
for (String str : gamesvrs) {
String currConns = jedis0.hget(str, "conns");
if (conns == null && currConns != null
|| (conns != null && currConns != null && Integer.parseInt(currConns) < conns)) {
conns = Integer.parseInt(currConns);
svr = str;
}
if (isbk.equalsIgnoreCase("1000" + gb.id)) {
svr = "svr" + (Integer.parseInt(svr.replace("svr", "")) + 1000) + "";
}
log.info("当前游戏链接:" + svr);
}
return svr;
}
@ -591,22 +606,22 @@ 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 != 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)) {
if (StringUtil.isNotEmpty(robot_host)) {
String roomId = resData.getString("room_id");
//异步执行机器人分配不阻塞玩家进入房间
// 异步执行机器人分配不阻塞玩家进入房间
final String finalRobotHost = robot_host;
final int finalGameId = gameId1;
CompletableFuture.runAsync(() -> {
@ -618,7 +633,6 @@ public class GroupRoomService {
});
}
Jedis jedis11 = Redis.use("group1_db11").getJedis();
jedis11.zremrangeByScore(grooms_key, 0, 0);
jedis11.close();
@ -1094,22 +1108,21 @@ public class GroupRoomService {
resData = publicJoinRoom(groupId, session, key, platform);
}
//检查玩家今天是否已经与机器人对打过
// 检查玩家今天是否已经与机器人对打过
if (!isPlayerRobotToday(acc.id)) {
//匹配
// 匹配
Jedis jedis11 = Redis.use("group1_db11").getJedis();
Jedis jedis0 = Redis.use("group1_db0").getJedis();
try {
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;
if(StringUtil.isNotEmpty(gameId1)) {
/*if (Integer.parseInt(gameId1) == 17) {
robot_host = "8.138.120.132:8917";
}*/
if (StringUtil.isNotEmpty(gameId1)) {
/*
* if (Integer.parseInt(gameId1) == 17) { robot_host = "8.138.120.132:8917"; }
*/
if (Integer.parseInt(gameId1) == 22) {
robot_host = "8.138.120.132:8722";
}
@ -1117,7 +1130,7 @@ public class GroupRoomService {
String roomid = resData.getString("room_id");
log.info("room_idroom_idroom_id" + roomid);
//异步执行机器人分配 不阻塞玩家进入房间
// 异步执行机器人分配 不阻塞玩家进入房间
final String finalRobotHost = robot_host;
final int finalGameId = Integer.parseInt(gameId1);
CompletableFuture.runAsync(() -> {
@ -1140,6 +1153,7 @@ public class GroupRoomService {
/**
*
*
* @param playerId ID
*/
private static boolean isPlayerRobotToday(int playerId) {
@ -1164,45 +1178,45 @@ public class GroupRoomService {
/**
* //发起机器人请求HTTP 同步方式,替代原 TCP 异步多线程方式)
*
* 1
* ID players
* 1 ID players
*
*
* @param roomid ID
* @param groupid ID
* @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){
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 js3 = Redis.use("group1_db3").getJedis();
try {
String robot = js0.hget("room:"+roomid,"robot");
String plays = js0.hget("room:"+roomid,"players");
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){
if (players.size() != 1) {
return null;
}
int robotid = players.getInt(0);
if(robotid==0){
if (robotid == 0) {
return null;
}
String wokelock = "wokelock";
js3.set(wokelock+robotid, String.valueOf(1));
js3.expire(wokelock+robotid, 35);
js3.set(wokelock + robotid, String.valueOf(1));
js3.expire(wokelock + robotid, 35);
sleep(1000);
//通过 HTTP 同步调用机器人服务的 225 协议入口
// 通过 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);
log.info("sendRoboJointData roomid:" + roomid + " robotid:" + robotid + " resp:" + resp);
} catch (Exception e) {
log.error("sendRoboJointData 异常 roomid:" + roomid, e);
} finally {
js0.close();
js3.close();
@ -1212,10 +1226,11 @@ public class GroupRoomService {
/**
* //发起机器人请求
*
* @return
*/
public static ITObject sendRobotData(String roomid,int groupid,String robot_host,int gameId){
log.info("sendRobotData :"+roomid+"groupid:"+groupid+"robot_host:"+robot_host);
public static ITObject sendRobotData(String roomid, int groupid, String robot_host, int gameId) {
log.info("sendRobotData :" + roomid + "groupid:" + groupid + "robot_host:" + robot_host);
Jedis js0 = Redis.use("group1_db0").getJedis();
Jedis js3 = Redis.use("group1_db3").getJedis();
try {
@ -1228,8 +1243,8 @@ public class GroupRoomService {
js3.set("roomsend" + roomid, 1 + "");
js3.expire("roomsend" + roomid, 37);
//最多等待800ms (4 x 200ms)
//players由游戏服异步写入 若超时则本次不分配机器人
// 最多等待800ms (4 x 200ms)
// players由游戏服异步写入 若超时则本次不分配机器人
String roomKey = "room:" + roomid;
String playersJson = js0.hget(roomKey, "players");
int maxRetry = 4;
@ -1242,19 +1257,19 @@ public class GroupRoomService {
log.warn("sendRobotData ==> 800ms内未获取到players数据跳过本次机器人分配 roomid:" + roomid + " (玩家可正常进入,仅无机器人)");
return null;
} else {
//检查是否有真人
// 检查是否有真人
ITArray players = TArray.newFromJsonData(playersJson);
Set<String> robotSet = js3.smembers("robots");
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
//检查房间内的真人玩家是否都已对打过了
// 检查房间内的真人玩家是否都已对打过了
List<Integer> realPlayersInRoom = new ArrayList<>();
boolean allRealMatchedToday = true;
for (int i = 0; i < players.size(); i++) {
int playerId = players.getInt(i);
if (robotSet == null || !robotSet.contains(String.valueOf(playerId))) {
realPlayersInRoom.add(playerId);
//检查该真人今天是否已和机器人对打过
// 检查该真人今天是否已和机器人对打过
String matchedDate = js3.get("player_user:" + playerId);
if (matchedDate == null || !matchedDate.equals(today)) {
allRealMatchedToday = false;
@ -1271,39 +1286,54 @@ public class GroupRoomService {
}
if (allRealMatchedToday) {
log.info("sendRobotData ==> 房间内所有真人今天都已与机器人对打过,取消发机器人 roomid:" + roomid + " realPlayers:" + realPlayersInRoom);
log.info("sendRobotData ==> 房间内所有真人今天都已与机器人对打过,取消发机器人 roomid:" + roomid + " realPlayers:"
+ realPlayersInRoom);
return null;
}
if (players.size() >= 2) {
log.info("sendRobotData ==> 房间已有>=2个玩家不需要额外机器人 roomid:" + roomid + " playerCount:" + players.size());
log.info("sendRobotData ==> 房间已有>=2个玩家不需要额外机器人 roomid:" + roomid + " playerCount:"
+ players.size());
return null;
}
}
//找可用机器人
// 找可用机器人
int robotid = 0;
String wokelock = "wokelock";
Set<String> jsRobot = js3.smembers("robots");
log.info("jsRobot" + jsRobot);
String wokelock = "wokelock";
for (String key : jsRobot) {
String tmp = js3.get(wokelock + key);
if (StringUtil.isEmpty(tmp)) {
if (jsRobot.isEmpty()) {
return null;
}
List<String> list = new ArrayList<>(jsRobot);
Collections.shuffle(list); // 真正随机打乱顺序
for (String key : list) {
if (StringUtil.isEmpty(js3.get("wokelock" + key))) {
robotid = Integer.parseInt(key);
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) {
log.info("sendRobotData 没有可用机器人 roomid:" + roomid);
return null;
}
//设置机器人占用标记
// 设置机器人占用标记
js3.set(wokelock + robotid, String.valueOf(1));
js3.expire(wokelock + robotid, 35);
//通过 HTTP 同步调用机器人服务的 225 协议入口
// 通过 HTTP 同步调用机器人服务的 225 协议入口
sleep(1000);
String url = buildRobotHttpUrl(robot_host);
String body = buildJoinRoomBody(robotid, roomid, groupid);
@ -1315,15 +1345,14 @@ public class GroupRoomService {
js0.close();
js3.close();
}
//client.killConnection();
// client.killConnection();
return null;
}
/**
* TCP HTTP URL
* HTTP = TCP + 1000 robot_mj_hz Config.HTTP_SERVER_PORT
* robot_host="192.168.0.32:8722" "http://192.168.0.32:9722/robot/joinRoom"
* TCP HTTP URL HTTP = TCP + 1000 robot_mj_hz
* Config.HTTP_SERVER_PORT robot_host="192.168.0.32:8522"
* "http://192.168.0.32:9722/robot/joinRoom"
*/
private static String buildRobotHttpUrl(String robot_host) {
String host;
@ -1345,16 +1374,14 @@ public class GroupRoomService {
*/
private static String buildJoinRoomBody(int robotid, String roomid, int groupid) {
StringBuilder sb = new StringBuilder(64);
sb.append("{\"robotid\":").append(robotid)
.append(",\"roomid\":\"").append(roomid).append("\"")
.append(",\"groupid\":").append(groupid)
.append("}");
sb.append("{\"robotid\":").append(robotid).append(",\"roomid\":\"").append(roomid).append("\"")
.append(",\"groupid\":").append(groupid).append("}");
return sb.toString();
}
/**
* JDK HttpURLConnection POST JSON
* TaurusClient + CompletableFuture + eventThread TCP
* JDK HttpURLConnection POST JSON TaurusClient +
* CompletableFuture + eventThread TCP
*
* @param urlStr URL
* @param jsonBody JSON
@ -1373,14 +1400,14 @@ public class GroupRoomService {
conn.setDoOutput(true);
conn.setDoInput(true);
//写入请求体
// 写入请求体
byte[] bodyBytes = jsonBody.getBytes(StandardCharsets.UTF_8);
try (OutputStream os = conn.getOutputStream()) {
os.write(bodyBytes);
os.flush();
}
//读取响应
// 读取响应
int code = conn.getResponseCode();
InputStream is = (code >= 200 && code < 300) ? conn.getInputStream() : conn.getErrorStream();
String resp = readAll(is);
@ -1403,7 +1430,8 @@ public class GroupRoomService {
*
*/
private static String readAll(InputStream in) throws Exception {
if (in == null) return "";
if (in == null)
return "";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n;
@ -1414,7 +1442,6 @@ public class GroupRoomService {
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
}
/**
*
*

View File

@ -98,5 +98,10 @@ public class Protocol {
/**手机验证*/
public static final String PHONE_CHECK ="phone_check";
/**放开或禁止设备*/
public static final String ACCOUNT_DEVICE ="account_device";
/**放开或禁止设备*/
public static final String OPEN_DEVICE ="open_device";
}

View File

@ -9,6 +9,7 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
@ -1157,7 +1158,13 @@ public class AccountService extends Controller {
// } else {
// resData.putBoolean("havegroup", false);
// }
this.sendResponse(ErrorCode._SUCC, resData);
boolean ispass = checkDevice(acc_bean.id, deviceCode);
if (ispass) {
this.sendResponse(ErrorCode._SUCC, resData);
} else {
throw new WebException(ErrorCode.IS_DEVICE_LOCK);
}
}
@ActionKey(value = Protocol.ID_PASSWORD_LOGIN)
@ -1541,9 +1548,20 @@ public class AccountService extends Controller {
//
// 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"))) {
logger.info("幸运号登录失败,须使用幸运版本:"+Utils.getMD5Hash(id+"C630"));
if (Redis.use("group1_db2").sismember("genusers", Utils.getMD5Hash(id + "C630"))) {
logger.info("幸运号登录失败,须使用幸运版本:" + Utils.getMD5Hash(id + "C630"));
throw new WebException(ErrorCode._FAILED);
} else {
// 不是幸运号,可以登录
@ -2873,14 +2891,14 @@ public class AccountService extends Controller {
// DataBase.use().executeUpdateLogin(lockSql, params3);
// 默认添加第一个设备
String lockSql = "update account set is_lock=? WHERE id=?";
String[] params3 = new String[2];
params3[0] = 1 + "";
params3[1] = accountid + "";
initDevice(accountid, deviceCode);
boolean ispass = checkDevice(accountid, deviceCode);
if (ispass) {
this.sendResponse(ErrorCode._SUCC, resData);
} else {
throw new WebException(ErrorCode.IS_DEVICE_LOCK);
DataBase.use().executeUpdateLogin(lockSql, params3);
this.sendResponse(ErrorCode._SUCC, resData);
}
} finally {
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.putBoolean("havePassword", true);
@ -3054,7 +3072,7 @@ public class AccountService extends Controller {
this.sendResponse(ErrorCode._SUCC, resData);
} else {
logger.info("非幸运号登录失败,不可使用幸运版本:"+Utils.getMD5Hash(id+"C630"));
logger.info("非幸运号登录失败,不可使用幸运版本:" + Utils.getMD5Hash(id + "C630"));
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) {
String[] params1 = new String[2];
params1[0] = "123" + "";