ソースを参照

fix : Websocket调试修改13

bilingfeng 1 年間 前
コミット
8cfc3b0b9a

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 <Websocket调试修改12> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <Websocket调试修改13> ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 25 - 37
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfAppletMsgServiceImpl.java

@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.util.Collections;
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -64,12 +65,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         //用户进入会话事件
         if (Objects.equals(kfAppletMsgDTO.getMsgType(), KfAppletMsgDTO.MSG_TYPE_EVENT)
                 && Objects.equals(kfAppletMsgDTO.getEvent(), KfAppletMsgDTO.EVENT_USER_ENTER_TEMP_SESSION)) {
-            KfSessionUser kfSessionUser = kfSessionUserService.getById(kfAppletMsgDTO.getFromUserName());
-            if (kfSessionUser != null) {
-                return;
-            }
-            //创建保存用户信息
-            kfSessionUserService.save(this.transform(kfAppletMsgDTO, gameApplet));
+            this.kfSessionUserUpdateSave(kfAppletMsgDTO, gameApplet);
             return;
         }
         //非玩家消息, 不做处理
@@ -98,42 +94,31 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
     }
 
     private KfWebSocketMsgDTO transform(KfRoom kfRoom, Long gameId, KfRoomMsg kfRoomMsg, KfWebSocketMsgDTO.MsgContentBean msgContent) {
-        //消息对象
-        KfWebSocketMsgDTO.RoomMsgBean roomMsgBean = BeanUtil.copy(kfRoomMsg, KfWebSocketMsgDTO.RoomMsgBean.class);
-        roomMsgBean.setContent(msgContent);
-        //
 
-
-        return KfWebSocketMsgDTO.builder()
-                .webSocketMsgType(kfRoom == null ? KfWebSocketMsgEnum.WEBSOCKET_MSG_WAIT_LIST : KfWebSocketMsgEnum.WEBSOCKET_MSG_ROOM_MSG)
+        //消息类型
+        KfWebSocketMsgEnum kfWebSocketMsgEnum = kfRoom == null ? KfWebSocketMsgEnum.WEBSOCKET_MSG_WAIT_LIST
+                : KfWebSocketMsgEnum.WEBSOCKET_MSG_ROOM_MSG;
+        KfWebSocketMsgDTO kfWebSocketMsgDTO = KfWebSocketMsgDTO.builder()
+                .webSocketMsgType(kfWebSocketMsgEnum)
                 .kfUserId(kfRoom == null ? null : kfRoom.getKfUserId())
                 .gameId(gameId)
                 .roomId(kfRoom == null ? null : kfRoom.getId())
-                .roomMsgList(Collections.singletonList(roomMsgBean))
                 .build();
-    }
-
-    private KfSessionUser transform(KfAppletMsgDTO kfAppletMsgDTO, GameApplet gameApplet) {
-        //查询用户
-        User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenId, kfAppletMsgDTO.getFromUserName()));
-        //最近角色信息
-        GameUserRole gameUserRole = null;
-        if (user != null) {
-            gameUserRole = gameUserRoleService.getLastGameUserRoleName(user.getId(), user.getGameId());
+        //待接入消息
+        if (Objects.equals(kfWebSocketMsgEnum, KfWebSocketMsgEnum.WEBSOCKET_MSG_WAIT_LIST)) {
+            List<KfWebSocketMsgDTO.WaitUserBean> waitUserList = kfSessionUserService.getWaitUserList(gameId);
+            kfWebSocketMsgDTO.setWaitUserList(waitUserList);
         }
-        return KfSessionUser.builder()
-                .openId(kfAppletMsgDTO.getFromUserName())
-                .gameId(gameApplet.getGameId())
-                .userId(user == null ? null : user.getId())
-                .isWait(Boolean.FALSE)
-                .lastRoleId(gameUserRole == null ? "0" : gameUserRole.getRoleId())
-                .lastRoleName(gameUserRole == null ? kfAppletMsgDTO.getFromUserName() : gameUserRole.getRoleName())
-                .createTime(LocalDateTime.now())
-                .updateTime(LocalDateTime.now())
-                .build();
+        //房间消息
+        if (Objects.equals(kfWebSocketMsgEnum, KfWebSocketMsgEnum.WEBSOCKET_MSG_ROOM_MSG)) {
+            //消息对象
+            KfWebSocketMsgDTO.RoomMsgBean roomMsgBean = BeanUtil.copy(kfRoomMsg, KfWebSocketMsgDTO.RoomMsgBean.class);
+            roomMsgBean.setContent(msgContent);
+            kfWebSocketMsgDTO.setRoomMsgList(Collections.singletonList(roomMsgBean));
+        }
+        return kfWebSocketMsgDTO;
     }
 
-
     private void kfSessionUserUpdateSave(KfAppletMsgDTO kfAppletMsgDTO, GameApplet gameApplet) {
         KfSessionUser kfSessionUser = kfSessionUserService.getById(kfAppletMsgDTO.getFromUserName());
         //查询用户
@@ -149,8 +134,12 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
             return;
         }
         //存在, 更新玩家信息
-//        kfSessionUserService.update()
-
+        kfSessionUserService.update(new LambdaUpdateWrapper<KfSessionUser>()
+                .set(KfSessionUser::getUserId, user == null ? null : user.getId())
+                .set(KfSessionUser::getLastRoleId, gameUserRole == null ? "0" : gameUserRole.getRoleId())
+                .set(KfSessionUser::getLastRoleName, gameUserRole == null ? kfAppletMsgDTO.getFromUserName() : gameUserRole.getRoleName())
+                .set(KfSessionUser::getUpdateTime, LocalDateTime.now())
+                .eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName()));
     }
 
 
@@ -167,7 +156,6 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
                 .build();
     }
 
-
     private KfRoomMsg transform(KfAppletMsgDTO kfAppletMsgDTO, GameApplet gameApplet, KfRoom kfRoom, String postData,
                                 KfWebSocketMsgDTO.MsgContentBean msgContent) {
         return KfRoomMsg.builder()