Переглянути джерело

【优化】抖音组件修改为条件挂载,避免多人启动本地服务器后,影响抖音access_token有效时间

johnclot69 1 рік тому
батько
коміт
03bb2e43bf

+ 6 - 0
DotNet/Hotfix/Helper/MapHelper.cs

@@ -102,6 +102,12 @@ namespace ET.Server
             // 老场景
             if (map != null)
             {
+                // 下一局
+                if (map.IsGameOver())
+                {
+                    map.Init();
+                    player.GetComponent<PlayerTempDataComponent>().MapData.ready = false;
+                }
                 return map;
             }
 

+ 0 - 2
DotNet/Hotfix/Helper/SceneFactory.cs

@@ -40,8 +40,6 @@ namespace ET.Server
                     scene.AddComponent<GameTokenInfoComponent>();
                     scene.AddComponent<GamePlayerComponent>();
                     scene.AddComponent<GameMapComponent>();
-                    // 抖音组件
-                    scene.AddComponent<GameDouyinComponent>();
                     // 战斗服的Ice会话组件
                     scene.AddComponent<BattleIceAgentComponent>();
                     scene.AddComponent<ObjectWait>();

+ 1 - 0
DotNet/Hotfix/Module/FastStream/FastStreamComponentSystem.cs

@@ -24,6 +24,7 @@ namespace ET.Server
 
                 //IPAddress ipAddress = Dns.GetHostAddresses("localhost")[0];
                 IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3370);
+                // IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("47.97.163.95"), 3370);
                 self.FastStreamClient.ConnectAsync(endpoint);
             }
         }

+ 2 - 0
DotNet/Hotfix/Scenes/Game/GameDouyinComponentSystem.cs

@@ -13,6 +13,8 @@ namespace ET.Server
         {
             protected override void Awake(GameDouyinComponent self)
             {
+                Log.Info($"创建抖音组件...");
+                self.InitAccessToken();
             }
         }
 

+ 5 - 3
DotNet/Hotfix/Scenes/Game/Handler/C2G_BindPlayerHandler.cs

@@ -36,9 +36,11 @@ namespace ET.Server
             if (player != null)
             {
                 // 重新登录,赋值session
-                player.Session = session;
-
-                Log.Debug($"重新登录,赋值session...");
+                if (player.Session.InstanceId != session.InstanceId)
+                {
+                    player.Session = session;
+                    Log.Debug($"重新登录,赋值session...");
+                }
             }
             else
             {

+ 7 - 4
DotNet/Hotfix/Scenes/Game/Handler/C2G_LoginGameHandler.cs

@@ -37,11 +37,16 @@ namespace ET.Server
                 playerInfo.AvatarUrl = "";
                 playerInfo.Name = "主播-" + playerInfo.Id;
 
-                scene.GetComponent<GameDouyinComponent>().TokenIsNull = true;
+                scene.AddComponent<GameDouyinComponent>().TokenIsNull = true;
             }
             else
             {
-                JObject roomInfo = scene.GetComponent<GameDouyinComponent>().GetRoomInfo(request.Token.Trim());
+                // 添加抖音组件
+                GameDouyinComponent douyinComponent = scene.AddComponent<GameDouyinComponent>();
+
+                douyinComponent.TokenIsNull = false;
+
+                JObject roomInfo = douyinComponent.GetRoomInfo(request.Token.Trim());
 
                 if (roomInfo == null)
                 {
@@ -56,8 +61,6 @@ namespace ET.Server
                 playerInfo.AnchorOpenId = Convert.ToString(info.SelectToken("anchor_open_id"));
                 playerInfo.AvatarUrl = Convert.ToString(info.SelectToken("avatar_url"));
                 playerInfo.Name = Convert.ToString(info.SelectToken("nick_name"));
-
-                scene.GetComponent<GameDouyinComponent>().TokenIsNull = false;
             }
 
             playerInfo.Sex = 0;

+ 2 - 13
DotNet/Hotfix/Scenes/Game/Map/MapEventComponentSystem.cs

@@ -120,22 +120,11 @@ namespace ET.Server
             }
             // 场景结束排行榜逻辑
             map.GetComponent<MapRankComponent>().OnGameOver();
-            // 玩家离开
-            map.Player.GetComponent<PlayerTempDataComponent>().MapData.ready = false;
-            // 记录玩家历史
-            map.SyncPlayerHistoryData(map.Player);
+
             // 战斗服场景玩家离开
             map.PlayerLeaveRequest(map.Player, false);
-            // 本地场景移除玩家
+            // 本地场景玩家离开
             map.RemovePlayer(map.Player, false);
-            // 战斗服结束场景
-            map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
-            // 移除本地场景数据
-            map.DomainScene().GetComponent<GameMapComponent>().Remove(map.Id, map.RoomId);
-
-            map.Player.Map = null;
-
-            map.Dispose();
         }
 
         /// <summary>

+ 23 - 2
DotNet/Hotfix/Scenes/Game/Map/MapSystem.cs

@@ -56,6 +56,21 @@ namespace ET.Server
             }
         }
 
+        /// <summary>
+        /// 初始化场景数据
+        /// </summary>
+        /// <param name="self"></param>
+        public static void Init(this Map self)
+        {
+            self.UnitPlayers = new Dictionary<string, Struct.UnitPlayerData>();
+            self.TotalLikeNum = 0;
+            self.ConfigNum = 0;
+            self.DeadUnits = new List<int>();
+            self.DeadUnitPlayer = new List<int>();
+            self.IsGameOver = false;
+            self.CurBattleIndex = 0;
+        }
+
         public static ZoneManagerPrx GetZoneManager(this Map self)
         {
             return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceZoneManager;
@@ -66,7 +81,13 @@ namespace ET.Server
             return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceXmdsManager;
         }
 
-        public static GetPlayerData GetPlayerData(this Map self, long playerId)
+        /// <summary>
+        /// 获取战斗服角色数据
+        /// </summary>
+        /// <param name="self"></param>
+        /// <param name="playerId"></param>
+        /// <returns></returns>
+        private static GetPlayerData GetBattleServerPlayerData(this Map self, long playerId)
         {
             string result = self.GetXmdsManager().getPlayerData(playerId.ToString().Trim(), true);
             return string.IsNullOrEmpty(result)? null : JsonConvert.DeserializeObject<GetPlayerData>(result);
@@ -79,7 +100,7 @@ namespace ET.Server
         /// <param name="player"></param>
         public static void SyncPlayerHistoryData(this Map self, WNPlayer player)
         {
-            GetPlayerData result = self.GetPlayerData(player.GetId());
+            GetPlayerData result = self.GetBattleServerPlayerData(player.GetId());
             if (result == null)
             {
                 return;