优化机器人
parent
f41267beba
commit
bd72325aa9
|
|
@ -1112,10 +1112,11 @@ public class GroupRoomService {
|
|||
if (StringUtil.isNotEmpty(playersStr)) {
|
||||
ITArray players = TArray.newFromJsonData(playersStr);
|
||||
System.out.println("players:" + playersStr);
|
||||
if (players.size() == 2) {
|
||||
/*if (players.size() == 2) {
|
||||
System.out.println("******************房间是2个人空的:" + roomid);
|
||||
sendRoboJointData(roomid, groupId,robot_host,Integer.parseInt(gameId1));
|
||||
} else if (players.size() == 1) {
|
||||
} 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));
|
||||
|
|
@ -1179,7 +1180,7 @@ public class GroupRoomService {
|
|||
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();
|
||||
Jedis js3 = Redis.use("group1_db3").getJedis();
|
||||
try {
|
||||
String robot = js0.hget("room:"+roomid,"robot");
|
||||
String plays = js0.hget("room:"+roomid,"players");
|
||||
|
|
@ -1196,8 +1197,8 @@ public class GroupRoomService {
|
|||
}
|
||||
|
||||
String wokelock = "wokelock";
|
||||
js2.set(wokelock+robotid, String.valueOf(1));
|
||||
js2.expire(wokelock+robotid, 900);
|
||||
js3.set(wokelock+robotid, String.valueOf(1));
|
||||
js3.expire(wokelock+robotid, 35);
|
||||
sleep(1000);
|
||||
//通过 HTTP 同步调用机器人服务的 225 协议入口
|
||||
String url = buildRobotHttpUrl(robot_host);
|
||||
|
|
@ -1208,7 +1209,7 @@ public class GroupRoomService {
|
|||
log.error("sendRoboJointData 异常 roomid:"+roomid, e);
|
||||
} finally {
|
||||
js0.close();
|
||||
js2.close();
|
||||
js3.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
@ -1223,22 +1224,22 @@ public class GroupRoomService {
|
|||
|
||||
|
||||
log.info("sendRobotData :"+roomid+"groupid:"+groupid+"robot_host:"+robot_host);
|
||||
Jedis js1 = Redis.use("group1_db3").getJedis();
|
||||
Jedis js3 = Redis.use("group1_db3").getJedis();
|
||||
try {
|
||||
|
||||
String flag = js1.get("roomsend" + roomid);
|
||||
String flag = js3.get("roomsend" + roomid);
|
||||
if (flag != null) {
|
||||
return null;
|
||||
}
|
||||
js1.set("roomsend" + roomid, 1 + "");
|
||||
js1.expire("roomsend" + roomid, 5);
|
||||
js3.set("roomsend" + roomid, 1 + "");
|
||||
js3.expire("roomsend" + roomid, 5);
|
||||
|
||||
int robotid = 0;
|
||||
Set<String> jsRobot = js1.smembers("robots");
|
||||
Set<String> jsRobot = js3.smembers("robots");
|
||||
log.info("jsRobot" + jsRobot);
|
||||
String wokelock = "wokelock";
|
||||
for (String key : jsRobot) {
|
||||
String tmp = js1.get(wokelock + key);
|
||||
String tmp = js3.get(wokelock + key);
|
||||
if (StringUtil.isEmpty(tmp)) {
|
||||
robotid = Integer.parseInt(key);
|
||||
}
|
||||
|
|
@ -1262,8 +1263,8 @@ public class GroupRoomService {
|
|||
}
|
||||
|
||||
//设置机器人占用标记
|
||||
js1.set(wokelock + robotid, String.valueOf(1));
|
||||
js1.expire(wokelock + robotid, 2);
|
||||
js3.set(wokelock + robotid, String.valueOf(1));
|
||||
js3.expire(wokelock + robotid, 35);
|
||||
|
||||
// js1.expire(wokelock + robotid, 900);
|
||||
|
||||
|
|
@ -1276,7 +1277,7 @@ public class GroupRoomService {
|
|||
} catch (Exception e) {
|
||||
log.error("sendRobotData 异常 roomid:" + roomid, e);
|
||||
} finally {
|
||||
js1.close();
|
||||
js3.close();
|
||||
}
|
||||
//client.killConnection();
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue