|
|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.izouma.meta.config.Constants;
|
|
|
import com.izouma.meta.domain.MetaMMOLoginInfo;
|
|
|
+import com.izouma.meta.domain.MetaObjectMove;
|
|
|
import com.izouma.meta.domain.MetaObjectMoveCoordinate;
|
|
|
import com.izouma.meta.dto.MMOMessage;
|
|
|
import com.izouma.meta.dto.MMOSingleMessage;
|
|
|
@@ -11,6 +12,7 @@ import com.izouma.meta.dto.MetaRestResult;
|
|
|
import com.izouma.meta.dto.MetaServiceResult;
|
|
|
import com.izouma.meta.enums.MoveType;
|
|
|
import com.izouma.meta.repo.MetaMMOLoginInfoRepo;
|
|
|
+import com.izouma.meta.repo.MetaObjectMoveRepo;
|
|
|
import com.izouma.meta.utils.ApplicationContextUtil;
|
|
|
import com.izouma.meta.utils.ObjUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -43,6 +45,7 @@ public class MMOWebSocket {
|
|
|
private RedisTemplate redisTemplate;
|
|
|
private MetaMMOLoginInfoRepo metaMMOLoginInfoRepo;
|
|
|
private WebsocketCommon websocketCommon;
|
|
|
+ private MetaObjectMoveRepo metaObjectMoveRepo;
|
|
|
|
|
|
private void init() {
|
|
|
if (Objects.isNull(redisTemplate)) {
|
|
|
@@ -54,6 +57,9 @@ public class MMOWebSocket {
|
|
|
if (Objects.isNull(websocketCommon)) {
|
|
|
websocketCommon = (WebsocketCommon) ApplicationContextUtil.getBean("websocketCommon");
|
|
|
}
|
|
|
+ if (Objects.isNull(metaObjectMoveRepo)) {
|
|
|
+ metaObjectMoveRepo = (MetaObjectMoveRepo) ApplicationContextUtil.getBean("metaObjectMoveRepo");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@OnOpen
|
|
|
@@ -153,27 +159,37 @@ public class MMOWebSocket {
|
|
|
}
|
|
|
log.info("来自客户端消息:" + message + "客户端的id是:" + session.getId());
|
|
|
int type = Integer.parseInt(jsonObject.getString("type"));
|
|
|
- String cityId = jsonObject.getString("cityId");
|
|
|
- String regionId = jsonObject.getString("regionId");
|
|
|
- String key = cityId.concat(":").concat(regionId);
|
|
|
- List<String> otherUserIds = remove(key, userId);
|
|
|
if (type == 9) {
|
|
|
- String objectId = jsonObject.getString("objectId");
|
|
|
- MetaObjectMoveCoordinate metaObjectMoveCoordinate = null;
|
|
|
- try {
|
|
|
- String str = websocketCommon.getRequest("/metaObjectMove/".concat(objectId).concat("/queryCoordinate"));
|
|
|
- metaObjectMoveCoordinate = JSONObject.parseObject(str, MetaObjectMoveCoordinate.class);
|
|
|
- } catch (Exception e) {
|
|
|
- String errMsg = String.format("MetaObjectMoveCoordinate JSON parse throw exception:[%S]", e);
|
|
|
- log.error(errMsg);
|
|
|
+ List<MetaObjectMove> metaObjectMoves = metaObjectMoveRepo.findAllByDelAndRun(false, true);
|
|
|
+ if (CollectionUtils.isEmpty(metaObjectMoves)) {
|
|
|
+ return;
|
|
|
}
|
|
|
- if (Objects.isNull(metaObjectMoveCoordinate)) {
|
|
|
- log.error(String.format("物体[%S]坐标不存在", objectId));
|
|
|
+ for (MetaObjectMove metaObjectMove : metaObjectMoves) {
|
|
|
+ String cityId = String.valueOf(metaObjectMove.getCityId());
|
|
|
+ String regionId = String.valueOf(metaObjectMove.getRegionId());
|
|
|
+ String key = cityId.concat(":").concat(regionId);
|
|
|
+ List<String> otherUserIds = remove(key, userId);
|
|
|
+ MetaObjectMoveCoordinate metaObjectMoveCoordinate = null;
|
|
|
+ try {
|
|
|
+ String str = websocketCommon.getRequest("/metaObjectMove/".concat(String.valueOf(metaObjectMove.getObjectId())).concat("/queryCoordinate"));
|
|
|
+ metaObjectMoveCoordinate = JSONObject.parseObject(str, MetaObjectMoveCoordinate.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ String errMsg = String.format("MetaObjectMoveCoordinate JSON parse throw exception:[%S]", e);
|
|
|
+ log.error(errMsg);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaObjectMoveCoordinate)) {
|
|
|
+ log.error(String.format("物体[%S]坐标不存在", metaObjectMove.getObjectId()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ buildMessageForSendingToAllOther(otherUserIds, 9, metaObjectMoveCoordinate);
|
|
|
return;
|
|
|
}
|
|
|
- buildMessageForSendingToAllOther(otherUserIds, 9, metaObjectMoveCoordinate);
|
|
|
- return;
|
|
|
+ ;
|
|
|
}
|
|
|
+ String cityId = jsonObject.getString("cityId");
|
|
|
+ String regionId = jsonObject.getString("regionId");
|
|
|
+ String key = cityId.concat(":").concat(regionId);
|
|
|
+ List<String> otherUserIds = remove(key, userId);
|
|
|
MetaMMOLoginInfo metaMMOLoginInfo;
|
|
|
List<MetaMMOLoginInfo> metaMMOLoginInfos = redisTemplate.opsForValue().multiGet(otherUserIds);
|
|
|
switch (type) {
|
|
|
@@ -414,19 +430,16 @@ public class MMOWebSocket {
|
|
|
if (Objects.isNull(jsonObject.getString("type"))) {
|
|
|
return MetaServiceResult.returnError("Illegal parameter : type can not be null");
|
|
|
}
|
|
|
+ int type = Integer.parseInt(jsonObject.getString("type"));
|
|
|
+ if (type == 9) {
|
|
|
+ return MetaServiceResult.returnSuccess("check success");
|
|
|
+ }
|
|
|
if (Objects.isNull(jsonObject.getString("cityId"))) {
|
|
|
return MetaServiceResult.returnError("Illegal parameter : cityId can not be null");
|
|
|
}
|
|
|
if (Objects.isNull(jsonObject.getString("regionId"))) {
|
|
|
return MetaServiceResult.returnError("Illegal parameter : regionId can not be null");
|
|
|
}
|
|
|
- int type = Integer.parseInt(jsonObject.getString("type"));
|
|
|
- if (type == 9) {
|
|
|
- if (Objects.isNull(jsonObject.getString("objectId"))) {
|
|
|
- return MetaServiceResult.returnError("Illegal parameter : objectId can not be null");
|
|
|
- }
|
|
|
- return MetaServiceResult.returnSuccess("check success");
|
|
|
- }
|
|
|
if (Objects.isNull(jsonObject.getString("id"))) {
|
|
|
return MetaServiceResult.returnError("Illegal parameter : id can not be null");
|
|
|
}
|