瀏覽代碼

优化连接关闭

johnclot69 4 月之前
父節點
當前提交
5d71b666c0

+ 2 - 1
incubator-common/src/main/java/com/incubator/common/net/netty/NettyConnection.java

@@ -124,7 +124,8 @@ public class NettyConnection implements Connection {
 
 	@Override
 	public void close() {
-		if (channel != null && channel.isActive()) {
+//		if (channel != null && channel.isActive()) {
+		if (channel != null) {
 			channel.close();
 		}
 	}

+ 6 - 6
incubator-game/src/main/java/com/incubator/game/player/Player.java

@@ -37,17 +37,16 @@ public class Player extends GPlayer {
         GGame.addPlayer(this);
     }
 
-    public void reset() {
-        this.data = new PlayerInfoPO();
-    }
-
     /**
      * 销毁玩家,释放资源
      */
     public void destroy() {
-        reset();
-        logger.debug("Player {} has been destroyed.", this.data.player_id);
         this.doLogout();
+        this.data = new PlayerInfoPO();
+        this.session.close();
+        // 归还玩家对象
+        GGame.playerPool.releasePlayer(this);
+        logger.debug("Player {} has been destroyed.", this.data.player_id);
     }
 
     /**
@@ -74,6 +73,7 @@ public class Player extends GPlayer {
 
     @Override
     public void playerRemoveSessionBind() {
+        this.session.close();
         this.logger.info("玩家移除绑定了...");
     }
 

+ 0 - 2
incubator-game/src/main/java/com/incubator/game/player/PlayerPool.java

@@ -41,8 +41,6 @@ public final class PlayerPool {
      */
     public void releasePlayer(Player player) {
         if (player != null) {
-            // 重置玩家状态
-            player.reset();
             // 放回池中
             this.playerPool.offer(player);
         }

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

@@ -62,10 +62,10 @@ public class Room {
         this.reset();
         this.scheduler.shutdownNow();
         this.scheduler = null;
-        logger.debug("Room {} has been destroyed.", this.data.roomId);
         // 清空房间数据
         this.data = null;
         // 归还房间对象
         RoomManager.getInstance().releaseRoom(this);
+        logger.debug("Room {} has been destroyed.", this.data.roomId);
     }
 }