|
@@ -1,16 +1,14 @@
|
|
|
package com.fdkk.fdkkmeta.grpcService;
|
|
|
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkk.fdkkmeta.config.MetaConfig;
|
|
|
import com.fdkk.fdkkmeta.domain.dto.RouteDto;
|
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.BreakpointsEntity;
|
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.UserEntity;
|
|
|
-import com.fdkk.fdkkmeta.domain.po.AnglePO;
|
|
|
-import com.fdkk.fdkkmeta.domain.po.JoystickPO;
|
|
|
-import com.fdkk.fdkkmeta.domain.po.PointPO;
|
|
|
-import com.fdkk.fdkkmeta.domain.po.RotatePO;
|
|
|
+import com.fdkk.fdkkmeta.domain.po.*;
|
|
|
import com.fdkk.fdkkmeta.grpc.*;
|
|
|
import com.fdkk.fdkkmeta.redis.RedisCache;
|
|
|
import com.fdkk.fdkkmeta.service.BreakpointsService;
|
|
@@ -320,100 +318,164 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
|
|
|
//builder.setCode(0);
|
|
|
}
|
|
|
}
|
|
|
+ @Override
|
|
|
public void echo(EchoRequest request, StreamObserver<EchoReply> responseObserver){
|
|
|
|
|
|
- int action_type = request.getActionType();
|
|
|
- String trace_id = request.getTraceId();
|
|
|
-
|
|
|
- EchoReply.Builder builder = EchoReply.newBuilder();
|
|
|
- builder.setActionType(action_type);
|
|
|
- builder.setPointType(100);
|
|
|
- builder.setExtra("");
|
|
|
- builder.setTraceId(trace_id);
|
|
|
- builder.setPacketId("");
|
|
|
- //builder.setNps(nps);
|
|
|
- builder.setPeopleNum(0);
|
|
|
- builder.setZoneId("");
|
|
|
- builder.setEchoMsg("");
|
|
|
- builder.setReserveDetail(null);
|
|
|
- //builder.setUserWithAvatarList();
|
|
|
- //builder.setNewUserStates();
|
|
|
- builder.setCode(0);
|
|
|
- builder.setMsg("");
|
|
|
-
|
|
|
- responseObserver.onNext(builder.build());
|
|
|
- responseObserver.onCompleted();
|
|
|
+ try{
|
|
|
+ int action_type = request.getActionType();
|
|
|
+ String trace_id = request.getTraceId();
|
|
|
+
|
|
|
+ EchoReply.Builder builder = EchoReply.newBuilder();
|
|
|
+ builder.setActionType(action_type);
|
|
|
+ builder.setPointType(100);
|
|
|
+ builder.setExtra("");
|
|
|
+ builder.setTraceId(trace_id);
|
|
|
+ builder.setPacketId("");
|
|
|
+ //builder.setNps(nps);
|
|
|
+ builder.setPeopleNum(0);
|
|
|
+ builder.setZoneId("");
|
|
|
+ builder.setEchoMsg("");
|
|
|
+ builder.setReserveDetail(null);
|
|
|
+ //builder.setUserWithAvatarList();
|
|
|
+ //builder.setNewUserStates();
|
|
|
+ builder.setCode(0);
|
|
|
+ builder.setMsg("");
|
|
|
+
|
|
|
+ responseObserver.onNext(builder.build());
|
|
|
+ responseObserver.onCompleted();
|
|
|
+ }
|
|
|
+ catch(Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
- public void usersState(RotateRequest request, StreamObserver<GetNewUserStateReply> responseObserver){
|
|
|
-
|
|
|
- int action_type = request.getActionType();
|
|
|
- String trace_id = request.getTraceId();
|
|
|
- String user_id = request.getUserId();
|
|
|
-
|
|
|
- //从数据库中取全部在线的user表
|
|
|
- List<UserEntity> list = userService.findUserOnline(true);
|
|
|
-
|
|
|
- GetNewUserStateReply.Builder builder = GetNewUserStateReply.newBuilder();
|
|
|
- builder.setActionType(action_type);
|
|
|
- builder.setPointType(100);
|
|
|
- builder.setExtra("");
|
|
|
- builder.setTraceId(trace_id);
|
|
|
- builder.setPacketId("");
|
|
|
- //builder.setNps(nps);
|
|
|
- builder.setPeopleNum(0);
|
|
|
- builder.setZoneId("");
|
|
|
- builder.setEchoMsg("");
|
|
|
- builder.setReserveDetail(null);
|
|
|
- //builder.setUserWithAvatarList();
|
|
|
- if(list.size()>0){
|
|
|
- for(int i=0;i<list.size();++i){
|
|
|
- UserEntity user = list.get(i);
|
|
|
- JSONObject userInfo = new JSONObject();
|
|
|
- userInfo.put("roomTypeId","");
|
|
|
- userInfo.put("person",0);
|
|
|
- userInfo.put("avatarId",user.getAvatarId());
|
|
|
- userInfo.put("skinId",user.getSkinId());
|
|
|
- userInfo.put("roomId",user.getRoomId());
|
|
|
- userInfo.put("isHost",false);
|
|
|
- userInfo.put("isFollowHost",false);
|
|
|
- userInfo.put("skinDataVersion",user.getSkinDataVersion());
|
|
|
- userInfo.put("avatarComponents","");
|
|
|
- userInfo.put("nickName",user.getNickName());
|
|
|
- userInfo.put("movingMode",0); //后续会修改
|
|
|
- userInfo.put("attitude","walk");
|
|
|
- userInfo.put("areaName","");
|
|
|
- userInfo.put("pathName","");
|
|
|
- userInfo.put("pathId","thirdwalk");
|
|
|
- userInfo.put("avatarSize",1);
|
|
|
- Extra extra = Extra.newBuilder().setRemoveWhenDisconnected(true).build();
|
|
|
- userInfo.put("extra",extra);
|
|
|
- userInfo.put("prioritySync",false);
|
|
|
-
|
|
|
- Space.Builder player = Space.newBuilder();
|
|
|
- PointPO playerPosition = user.getPlayerPosition();
|
|
|
- Point playerPt = Point.newBuilder().setX(String.valueOf(playerPosition.getX())).setY(String.valueOf(playerPosition.getY())).setZ(String.valueOf(playerPosition.getZ())).build();
|
|
|
- player.setPosition(playerPt);
|
|
|
- AnglePO playerAngle = user.getPlayerAngle();
|
|
|
- AngleUe4 playerAg =AngleUe4.newBuilder().setPitch(playerAngle.getPitch()).setYaw(playerAngle.getYaw()).setRoll(playerAngle.getRoll()).build();
|
|
|
- player.setAngle(playerAg);
|
|
|
- userInfo.put("player",player);
|
|
|
- userInfo.put("camera",null);
|
|
|
- userInfo.put("cameraCenter",null);
|
|
|
-
|
|
|
- State playerState = sceneGrpcService.createPlayerState(userInfo);
|
|
|
- RenderInfo renderInfo = sceneGrpcService.createRenderInfo();
|
|
|
- Event event = sceneGrpcService.createEvent();
|
|
|
-
|
|
|
- UserState userState = sceneGrpcService.createUserState( user.getUserId(), playerState, renderInfo, event);
|
|
|
- builder.addNewUserStates(userState);
|
|
|
+ @Override
|
|
|
+ public void usersState(GetNewUserStateRequest request, StreamObserver<GetNewUserStateReply> responseObserver){
|
|
|
+
|
|
|
+ try{
|
|
|
+ int action_type = request.getActionType();
|
|
|
+ String trace_id = request.getTraceId();
|
|
|
+ String user_id = request.getUserId();
|
|
|
+
|
|
|
+ //从数据库中取全部在线的user表
|
|
|
+ List<UserEntity> list = userService.findUserOnline(true);
|
|
|
+
|
|
|
+ GetNewUserStateReply.Builder builder = GetNewUserStateReply.newBuilder();
|
|
|
+ builder.setActionType(action_type);
|
|
|
+ builder.setPointType(100);
|
|
|
+ builder.setExtra("");
|
|
|
+ builder.setTraceId(trace_id);
|
|
|
+ builder.setPacketId("");
|
|
|
+ //builder.setNps(nps);
|
|
|
+ builder.setPeopleNum(0);
|
|
|
+ builder.setZoneId("");
|
|
|
+ builder.setEchoMsg("");
|
|
|
+ builder.setReserveDetail(null);
|
|
|
+ //builder.setUserWithAvatarList();
|
|
|
+ if(list.size()>0){
|
|
|
+ for(int i=0;i<list.size();++i){
|
|
|
+ UserEntity user = list.get(i);
|
|
|
+ JSONObject userInfo = new JSONObject();
|
|
|
+ userInfo.put("roomTypeId","");
|
|
|
+ userInfo.put("person",0);
|
|
|
+ userInfo.put("avatarId",user.getAvatarId());
|
|
|
+ userInfo.put("skinId",user.getSkinId());
|
|
|
+ userInfo.put("roomId",user.getRoomId());
|
|
|
+ userInfo.put("isHost",false);
|
|
|
+ userInfo.put("isFollowHost",false);
|
|
|
+ userInfo.put("skinDataVersion",user.getSkinDataVersion());
|
|
|
+ userInfo.put("avatarComponents","");
|
|
|
+ userInfo.put("nickName",user.getNickName());
|
|
|
+ userInfo.put("movingMode",0); //后续会修改
|
|
|
+ userInfo.put("attitude","walk");
|
|
|
+ userInfo.put("areaName","");
|
|
|
+ userInfo.put("pathName","");
|
|
|
+ userInfo.put("pathId","thirdwalk");
|
|
|
+ userInfo.put("avatarSize",1);
|
|
|
+ Extra extra = Extra.newBuilder().setRemoveWhenDisconnected(true).build();
|
|
|
+ userInfo.put("extra",extra);
|
|
|
+ userInfo.put("prioritySync",false);
|
|
|
+
|
|
|
+ Space.Builder player = Space.newBuilder();
|
|
|
+ PointPO playerPosition = user.getPlayerPosition();
|
|
|
+ Point playerPt = Point.newBuilder().setX(String.valueOf(playerPosition.getX())).setY(String.valueOf(playerPosition.getY())).setZ(String.valueOf(playerPosition.getZ())).build();
|
|
|
+ player.setPosition(playerPt);
|
|
|
+ AnglePO playerAngle = user.getPlayerAngle();
|
|
|
+ AngleUe4 playerAg =AngleUe4.newBuilder().setPitch(playerAngle.getPitch()).setYaw(playerAngle.getYaw()).setRoll(playerAngle.getRoll()).build();
|
|
|
+ player.setAngle(playerAg);
|
|
|
+ userInfo.put("player",player);
|
|
|
+ userInfo.put("camera",null);
|
|
|
+ userInfo.put("cameraCenter",null);
|
|
|
+
|
|
|
+ State playerState = sceneGrpcService.createPlayerState(userInfo);
|
|
|
+ RenderInfo renderInfo = sceneGrpcService.createRenderInfo();
|
|
|
+ Event event = sceneGrpcService.createEvent();
|
|
|
+
|
|
|
+ UserState userState = sceneGrpcService.createUserState( user.getUserId(), playerState, renderInfo, event);
|
|
|
+ builder.addNewUserStates(userState);
|
|
|
+ }
|
|
|
}
|
|
|
+ //builder.setNewUserStates();
|
|
|
+ builder.setCode(0);
|
|
|
+ builder.setMsg("");
|
|
|
+
|
|
|
+ responseObserver.onNext(builder.build());
|
|
|
+ responseObserver.onCompleted();
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- //builder.setNewUserStates();
|
|
|
- builder.setCode(0);
|
|
|
- builder.setMsg("");
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void move(MoveRequest request, StreamObserver<NormalReply> responseObserver){
|
|
|
+ try{
|
|
|
+ int action_type= request.getActionType();
|
|
|
+ ClickingAction clicking_action = request.getClickingAction();
|
|
|
+ State clicking_state = request.getClickingState();
|
|
|
+ String trace_id = request.getTraceId();
|
|
|
+ String user_id = request.getUserId();
|
|
|
+
|
|
|
+ UserEntity user = userService.findUserId(user_id);
|
|
|
+ String appId = user.getAppId();
|
|
|
+ //Long breakPointId = user.getBreakPointId();
|
|
|
+ //BreakpointsEntity breakpointsEntity = breakpointsService.findByAppIdAndBreakPointId(appId,breakPointId);
|
|
|
+ Point end = clicking_action.getClickingPoint();
|
|
|
+ //RotateFrameEntity rotateFrameEntity = rotateFrameService.findById(user.getFrameId());
|
|
|
+ //计算路径
|
|
|
+ RouteDto po=new RouteDto();
|
|
|
+ PointPO s= user.getPlayerPosition();
|
|
|
+ PointPO e=new PointPO();
|
|
|
+ e.setX(Double.parseDouble(end.getX()));
|
|
|
+ e.setY(Double.parseDouble(end.getY()));
|
|
|
+ e.setZ(Double.parseDouble(end.getZ()));
|
|
|
+ po.setE_location(e);
|
|
|
+ po.setS_location(s);
|
|
|
+ po.setSceneCode(appId);
|
|
|
+ JSONArray path = new JSONArray();
|
|
|
+
|
|
|
+ JSONArray maps = GetRoute.getRoute(metaConfig.getFreespacePath()+ File.separator +appId+"_target_freespace.json", po);
|
|
|
+ if (maps!=null&&maps.size()>=2){
|
|
|
+ Long nextbreakPointId = JSON.parseObject(JSONObject.toJSON(maps.get(1)).toString()).getLong("id");
|
|
|
+ path.add(nextbreakPointId);
|
|
|
+ }
|
|
|
|
|
|
- responseObserver.onNext(builder.build());
|
|
|
- responseObserver.onCompleted();
|
|
|
+ MovePO movePO = new MovePO();
|
|
|
+ movePO.setAction_type(action_type);
|
|
|
+ movePO.setClicking_action(clicking_action);
|
|
|
+ movePO.setClicking_state(clicking_state);
|
|
|
+ movePO.setTrace_id(trace_id);
|
|
|
+ movePO.setUser_id(user_id);
|
|
|
+ movePO.setPath(path);
|
|
|
+
|
|
|
+ redisCache.setCacheList("setCacheRequest:move:"+user_id, Arrays.asList(movePO));
|
|
|
+ NormalReply.Builder builder = NormalReply.newBuilder();
|
|
|
+ builder.setCode(1);
|
|
|
+ responseObserver.onNext(builder.build());
|
|
|
+ responseObserver.onCompleted();
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ //builder.setCode(0);
|
|
|
+ }
|
|
|
}
|
|
|
/*
|
|
|
//返回的是角度矫正数据
|