Parcourir la source

解决创建房间和加入房间的问题

johnclot69 il y a 4 mois
Parent
commit
b73717544f
32 fichiers modifiés avec 45 ajouts et 52 suppressions
  1. BIN
      .gradle/7.5.1/executionHistory/executionHistory.bin
  2. BIN
      .gradle/7.5.1/executionHistory/executionHistory.lock
  3. BIN
      .gradle/7.5.1/fileHashes/fileHashes.bin
  4. BIN
      .gradle/7.5.1/fileHashes/fileHashes.lock
  5. BIN
      .gradle/7.5.1/fileHashes/resourceHashesCache.bin
  6. BIN
      .gradle/buildOutputCleanup/buildOutputCleanup.lock
  7. BIN
      .gradle/file-system.probe
  8. 3 7
      incubator-center/src/main/java/com/incubator/center/listener/CenterInnerListener.java
  9. BIN
      incubator-common/build/tmp/compileJava/previous-compilation-data.bin
  10. BIN
      incubator-core/build/tmp/compileJava/previous-compilation-data.bin
  11. BIN
      incubator-game/build/classes/java/main/com/incubator/game/GGame.class
  12. BIN
      incubator-game/build/classes/java/main/com/incubator/game/data/entity/PlayerInfoPO.class
  13. BIN
      incubator-game/build/classes/java/main/com/incubator/game/data/model/RoomPO.class
  14. BIN
      incubator-game/build/classes/java/main/com/incubator/game/handler/CreatRoomHandler.class
  15. BIN
      incubator-game/build/classes/java/main/com/incubator/game/handler/JoinRoomHandler.class
  16. BIN
      incubator-game/build/classes/java/main/com/incubator/game/handler/LoginGameHandler.class
  17. BIN
      incubator-game/build/classes/java/main/com/incubator/game/listener/CenterClientListener.class
  18. BIN
      incubator-game/build/classes/java/main/com/incubator/game/listener/PublicListener.class
  19. BIN
      incubator-game/build/classes/java/main/com/incubator/game/player/Player.class
  20. BIN
      incubator-game/build/classes/java/main/com/incubator/game/room/Room.class
  21. BIN
      incubator-game/build/classes/java/main/com/incubator/game/service/RoomService.class
  22. BIN
      incubator-game/build/classes/java/main/com/incubator/game/timer/FlushDB.class
  23. BIN
      incubator-game/build/classes/java/main/com/incubator/game/util/MsgUtil.class
  24. BIN
      incubator-game/build/tmp/compileJava/previous-compilation-data.bin
  25. 2 2
      incubator-game/src/main/java/com/incubator/game/handler/CreatRoomHandler.java
  26. 2 3
      incubator-game/src/main/java/com/incubator/game/handler/JoinRoomHandler.java
  27. 4 1
      incubator-game/src/main/java/com/incubator/game/handler/LoginGameHandler.java
  28. 2 6
      incubator-game/src/main/java/com/incubator/game/listener/CenterClientListener.java
  29. 2 7
      incubator-game/src/main/java/com/incubator/game/listener/PublicListener.java
  30. 7 1
      incubator-game/src/main/java/com/incubator/game/room/Room.java
  31. 3 0
      incubator-game/src/main/java/com/incubator/game/service/RoomService.java
  32. 20 25
      incubator-game/src/main/java/com/incubator/game/util/MsgUtil.java

BIN
.gradle/7.5.1/executionHistory/executionHistory.bin


BIN
.gradle/7.5.1/executionHistory/executionHistory.lock


BIN
.gradle/7.5.1/fileHashes/fileHashes.bin


BIN
.gradle/7.5.1/fileHashes/fileHashes.lock


BIN
.gradle/7.5.1/fileHashes/resourceHashesCache.bin


BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock


BIN
.gradle/file-system.probe


+ 3 - 7
incubator-center/src/main/java/com/incubator/center/listener/CenterInnerListener.java

@@ -46,19 +46,15 @@ public class CenterInnerListener extends GameServerConnectionListener {
 				byte[] bytes = new byte[byteBuf.readableBytes()];
 				byteBuf.readBytes(bytes);
 
-//				MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(bytes);
-//				WSRequest request = super.parseWSRequest(unpacker);
-
 				WSRequest request = new WSRequest(bytes);
 
 				NetHandler handler = GCenter.getHandler(request.getCmd());
 				if (handler != null) {
-					request.bindSession(conn);
-					request.bindHandler(handler);
-					logger.info("收到消息 : cmd={}", request.getCmd());
+					logger.info("收到消息 : cmd={}, 请求内容 : {}", request.getCmd(), request.toJson());
 					WSResponse response = new WSResponse();
-					handler.onDate(request, response);
+					handler.onDate(conn, request, response);
 					conn.writeAndFlush(response.toBytes());
+					logger.info("返回消息 : cmd={}, 返回内容 : {}", request.getCmd(), response.toJson());
 				} else {
 					logger.info("消息号错误... cmd={}", request.getCmd());
 					conn.close();

BIN
incubator-common/build/tmp/compileJava/previous-compilation-data.bin


BIN
incubator-core/build/tmp/compileJava/previous-compilation-data.bin


BIN
incubator-game/build/classes/java/main/com/incubator/game/GGame.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/data/entity/PlayerInfoPO.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/data/model/RoomPO.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/handler/CreatRoomHandler.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/handler/JoinRoomHandler.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/handler/LoginGameHandler.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/listener/CenterClientListener.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/listener/PublicListener.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/player/WNPlayer.class → incubator-game/build/classes/java/main/com/incubator/game/player/Player.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/room/Room.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/service/RoomService.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/timer/FlushDB.class


BIN
incubator-game/build/classes/java/main/com/incubator/game/util/MsgUtil.class


BIN
incubator-game/build/tmp/compileJava/previous-compilation-data.bin


+ 2 - 2
incubator-game/src/main/java/com/incubator/game/handler/CreatRoomHandler.java

@@ -30,8 +30,8 @@ public class CreatRoomHandler extends NetHandler {
 			return;
 		}
 
-		// 判断参数
-		int type = Integer.parseInt(request.getData().getOrDefault("Type", "").toString());
+		// todo 判断参数
+		int type = (int) request.getData().getOrDefault("type", 0);
 		if (type <= 0) {
 			logger.info("参数错误");
 			response.setCode(CommonProto.Code.PARAMETER_ERR_VALUE);

+ 2 - 3
incubator-game/src/main/java/com/incubator/game/handler/JoinRoomHandler.java

@@ -7,7 +7,6 @@ import com.incubator.core.net.ws.WSResponse;
 import com.incubator.game.player.Player;
 import com.incubator.game.room.Room;
 import com.incubator.game.service.RoomService;
-import com.incubator.game.util.MsgUtil;
 import com.incubator.game.util.PlayerUtil;
 import com.incubator.message.proto.CommonProto;
 
@@ -31,7 +30,7 @@ public class JoinRoomHandler extends NetHandler {
 		}
 
 		// 判断参数
-		int roomId = Integer.parseInt(request.getData().getOrDefault("RoomId", "").toString());
+		int roomId = Integer.parseInt(request.getData().getOrDefault("roomId", "").toString());
 		if (roomId <= 0) {
 			logger.info("参数错误");
 			response.setCode(CommonProto.Code.PARAMETER_ERR_VALUE);
@@ -49,7 +48,7 @@ public class JoinRoomHandler extends NetHandler {
 		}
 
 		// 判断玩家绑定房间
-		if (player.data.roomId >= 0 && player.data.roomId != roomId) {
+		if (player.data.roomId != 0 && player.data.roomId != roomId) {
 			logger.info("不可重复加入其他房间");
 			response.setCode(CommonProto.Code.JOIN_ROOM_REPEATEDLY_ERR_VALUE);
 			response.setMessage("操作失败,不可重复加入其他房间...");

+ 4 - 1
incubator-game/src/main/java/com/incubator/game/handler/LoginGameHandler.java

@@ -36,9 +36,12 @@ public class LoginGameHandler extends NetHandler {
 //		}
 		// 根据token获取用户信息
 
+		String username = request.getData().getOrDefault("username", "").toString();
+
 		// 创建player
 		String player_id = UUID.randomUUID().toString();
 		PlayerInfoPO playerInfoPO = PlayerUtil.createPlayer(player_id);
+		playerInfoPO.name = "玩家" + username;
 		Player player = new Player(playerInfoPO);
 
 		// 绑定session
@@ -53,7 +56,7 @@ public class LoginGameHandler extends NetHandler {
 
 		// 正常返回
 		Map<String, Object> map = new HashMap<>();
-		map.put("PlayerInfo", MsgUtil.playerInfoToMessage(player));
+		map.put("playerInfo", MsgUtil.playerInfoToMessage(player));
 		map.put("roomId", room != null? room.data.roomId : 0);
 		response.setData(map);
 	}

+ 2 - 6
incubator-game/src/main/java/com/incubator/game/listener/CenterClientListener.java

@@ -46,18 +46,14 @@ public class CenterClientListener extends GameClientConnectionListener {
 				byte[] bytes = new byte[byteBuf.readableBytes()];
 				byteBuf.readBytes(bytes);
 
-//				MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(bytes);
-//				WSRequest request = super.parseWSRequest(unpacker);
-
 				WSRequest request = new WSRequest(bytes);
 
 				NetHandler handler = GGame.handlers.get(request.getCmd());
 				if (handler != null) {
-//					request.bindSession(conn);
-//					request.bindHandler(handler);
-					logger.info("收到消息 : cmd={}", request.getCmd());
+					logger.info("收到消息 : cmd={}, 请求内容 : {}", request.getCmd(), request.toJson());
 					WSResponse response = new WSResponse();
 					handler.onDate(conn, request, response);
+					logger.info("返回消息 : cmd={}, 返回内容 : {}", request.getCmd(), response.toJson());
 				} else {
 					logger.info("消息号错误... cmd={}", request.getCmd());
 				}

+ 2 - 7
incubator-game/src/main/java/com/incubator/game/listener/PublicListener.java

@@ -62,24 +62,19 @@ public class PublicListener extends GameServerConnectionListener {
 				byte[] bytes = new byte[byteBuf.readableBytes()];
 				byteBuf.readBytes(bytes);
 
-//				MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(bytes);
-//				WSRequest request = super.parseWSRequest(unpacker);
-
 				WSRequest request = new WSRequest(bytes);
 
 				NetHandler handler = GGame.handlers.get(request.getCmd());
 				if (handler != null) {
-//					request.bindSession(conn);
-//					request.bindHandler(handler);
 					// 过滤一下心跳消息
 					if (request.getCmd() != CommonProto.Cmd.HeartBeatReq_VALUE) {
-						logger.info("收到ws消息 : cmd={}, 请求参数 : data={}", request.getCmd(), request.toJson());
+						logger.info("收到消息 : cmd={}, 请求内容 : {}", request.getCmd(), request.toJson());
 					}
 					WSResponse response = new WSResponse();
 					handler.onDate(conn, request, response);
 					conn.writeAndFlush(response.toBytes());
 					if (request.getCmd() != CommonProto.Cmd.HeartBeatReq_VALUE) {
-						logger.info("返回ws消息 : cmd={}, 返回内容 : data={}", request.getCmd(), response.toJson());
+						logger.info("返回消息 : cmd={}, 返回内容 : {}", request.getCmd(), response.toJson());
 					}
 				} else {
 					logger.error("消息号错误... cmd={}", request.getCmd());

+ 7 - 1
incubator-game/src/main/java/com/incubator/game/room/Room.java

@@ -15,5 +15,11 @@ public class Room {
     /** 房间数据 **/
     public RoomPO data;
 
-    public Room() {}
+    public Room() {
+        this.init();
+    }
+
+    public void init(){
+        this.data = new RoomPO();
+    }
 }

+ 3 - 0
incubator-game/src/main/java/com/incubator/game/service/RoomService.java

@@ -93,6 +93,9 @@ public class RoomService {
         }
         room.data.playerMap.put(0, player);
 
+        // 加入缓存
+        this.roomMap.put(room.data.roomId, room);
+
         return room;
     }
 

+ 20 - 25
incubator-game/src/main/java/com/incubator/game/util/MsgUtil.java

@@ -38,18 +38,18 @@ public final class MsgUtil {
      */
     public static Map<String, Object> roomToMessage(Room room, Player player, Player opPlayer) {
         Map<String, Object> data = new HashMap<>();
-        data.put("RoomId", room.data.roomId);
-        data.put("Type", room.data.type);
-        data.put("OwnerId", room.data.ownerId);
-        data.put("State", room.data.state);
-        data.put("Time", room.data.time);
-        data.put("CurRound", room.data.curRound);
-        data.put("ZhuangPos", room.data.zhuangPos);
-        data.put("OpId", opPlayer != null ? opPlayer.getId() : "");
-        data.put("OpPos", room.data.opPos);
-        data.put("CurDisCardList", room.data.curDisCardList);
+        data.put("roomId", room.data.roomId);
+        data.put("type", room.data.type);
+        data.put("ownerId", room.data.ownerId);
+        data.put("state", room.data.state);
+        data.put("time", room.data.time);
+        data.put("curRound", room.data.curRound);
+        data.put("zhuangPos", room.data.zhuangPos);
+        data.put("opId", opPlayer != null ? opPlayer.getId() : "");
+        data.put("opPos", room.data.opPos);
+        data.put("curDisCardList", room.data.curDisCardList);
         data.put("CurDisCardSex", room.data.CurDisCardSex);
-        data.put("MyInfo", playerRoomToMessage(room, player, true));
+        data.put("myInfo", playerRoomToMessage(room, player, true));
         return data;
     }
 
@@ -62,21 +62,16 @@ public final class MsgUtil {
      * @return
      */
     public static Map<String, Object> playerRoomToMessage(Room room, Player player, boolean flag) {
-        Map<String, Object> data = new HashMap<>();
-        data.put("Id", player.getId());
-        data.put("Name", player.data.name);
-        data.put("Sex", player.data.sex);
-        data.put("Exp", player.data.exp);
-        data.put("Level", player.data.level);
-        data.put("Vip", player.data.vip);
-        data.put("Diamond", player.data.diamond);
-        data.put("Pos", player.data.pos);
-        data.put("State", player.data.state);
-        data.put("IsAuto", player.data.isAuto);
+        Map<String, Object> data = playerInfoToMessage(player);
+
+        data.put("diamond", player.data.diamond);
+        data.put("pos", player.data.pos);
+        data.put("state", player.data.state);
+        data.put("isAuto", player.data.isAuto);
         Map<String, Object> cardInfo = new HashMap<>();
-        cardInfo.put("RemainCards", flag? player.data.remainCards : "");
-        cardInfo.put("RemainCardsNum", player.data.remainCards.size());
-        data.put("CardInfo", cardInfo);
+        cardInfo.put("remainCards", flag? player.data.remainCards : "");
+        cardInfo.put("remainCardsNum", player.data.remainCards.size());
+        data.put("cardInfo", cardInfo);
         return data;
     }