Browse Source

【优化】提交token为空时得处理

johnclot69 1 year ago
parent
commit
752a98c618

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

@@ -30,6 +30,11 @@ namespace ET.Server
         {
             protected override void Update(GameDouyinComponent self)
             {
+                if (self.TokenIsNull)
+                {
+                    return;
+                }
+
                 if (TimeHelper.ClientNow() >= self.AccessTokenTime)
                 {
                     Log.Info($"刷新AccessToken...");
@@ -45,6 +50,11 @@ namespace ET.Server
         /// <param name="self"></param>
         private static void InitAccessToken(this GameDouyinComponent self)
         {
+            if (self.TokenIsNull)
+            {
+                return;
+            }
+
             // 请求头
             Dictionary<string, string> head = new Dictionary<string, string>();
             // 参数

+ 22 - 16
DotNet/Hotfix/Scenes/Game/Handler/C2G_LoginGameHandler.cs

@@ -18,31 +18,37 @@ namespace ET.Server
                 return;
             }
 
-            // 判断参数
-            if (string.IsNullOrEmpty(request.Token.Trim()))
-            {
-                Log.Debug($"Game token 登陆超时");
-                response.Error = ErrorCore.ERR_ConnectGateKeyError;
-                response.Message = "Game token 登陆超时";
-                reply();
-                session.Disconnect().Coroutine();
-                return;
-            }
-
             // 移除session自动超时组件
             session.RemoveComponent<SessionAcceptTimeoutComponent>();
 
             Scene scene = session.DomainScene();
 
-            JObject roomInfo = scene.GetComponent<GameDouyinComponent>().GetRoomInfo(request.Token.Trim());
+            bool tokenIsNull = string.IsNullOrEmpty(request.Token.Trim()) || "NoToken".Equals(request.Token.Trim());
+
+            scene.GetComponent<GameDouyinComponent>().TokenIsNull = tokenIsNull;
 
             // 预先创建数据
             PlayerInfo playerInfo = new PlayerInfo();
             playerInfo.Id = IdGenerater.Instance.GenerateUnitId(scene.DomainZone());
-            playerInfo.RoomId = Convert.ToInt64(roomInfo.SelectToken("data").SelectToken("info").SelectToken("room_id"));
-            playerInfo.AnchorOpenId = Convert.ToString(roomInfo.SelectToken("data").SelectToken("info").SelectToken("anchor_open_id"));
-            playerInfo.AvatarUrl = Convert.ToString(roomInfo.SelectToken("data").SelectToken("info").SelectToken("avatar_url"));
-            playerInfo.Name = Convert.ToString(roomInfo.SelectToken("data").SelectToken("info").SelectToken("nick_name"));
+
+            if (tokenIsNull)
+            {
+                // Token为空初始化信息
+                playerInfo.RoomId = playerInfo.Id;
+                playerInfo.AnchorOpenId = playerInfo.Id.ToString();
+                playerInfo.AvatarUrl = "测试头像";
+                playerInfo.Name = "主播-" + playerInfo.Id;
+            }
+            else
+            {
+                JObject roomInfo = scene.GetComponent<GameDouyinComponent>().GetRoomInfo(request.Token.Trim());
+
+                playerInfo.RoomId = Convert.ToInt64(roomInfo.SelectToken("data").SelectToken("info").SelectToken("room_id"));
+                playerInfo.AnchorOpenId = Convert.ToString(roomInfo.SelectToken("data").SelectToken("info").SelectToken("anchor_open_id"));
+                playerInfo.AvatarUrl = Convert.ToString(roomInfo.SelectToken("data").SelectToken("info").SelectToken("avatar_url"));
+                playerInfo.Name = Convert.ToString(roomInfo.SelectToken("data").SelectToken("info").SelectToken("nick_name"));
+            }
+
             playerInfo.Sex = 0;
             playerInfo.Pro = (int)PlayerProType.CANG_LANG;
             playerInfo.Level = 1;

+ 17 - 4
DotNet/Hotfix/Scenes/Game/Map/MapDouyinLiveCommentComponentSystem.cs

@@ -12,7 +12,6 @@ namespace ET.Server
             protected override void Awake(MapDouyinLiveCommentComponent self)
             {
                 Log.Info($"创建抖音直播评论任务组件...");
-                // self.StartTask();
             }
         }
 
@@ -21,6 +20,14 @@ namespace ET.Server
             protected override void Destroy(MapDouyinLiveCommentComponent self)
             {
                 Log.Info($"销毁抖音直播评论任务组件");
+
+                bool tokenIsNull = self.GetParent<Map>().TokenIsNull();
+
+                if (tokenIsNull)
+                {
+                    return;
+                }
+
                 self.StopTask();
             }
         }
@@ -29,6 +36,12 @@ namespace ET.Server
         {
             protected override void Update(MapDouyinLiveCommentComponent self)
             {
+                bool tokenIsNull = self.GetParent<Map>().TokenIsNull();
+
+                if (tokenIsNull)
+                {
+                    return;
+                }
                 // 运行中状态
                 if (self.Status == 3)
                 {
@@ -74,7 +87,7 @@ namespace ET.Server
         {
             // 请求头
             Dictionary<string, string> head = new Dictionary<string, string>();
-            head.Add("access-token", self.GetParent<Map>().AccessToken);
+            head.Add("access-token", self.GetParent<Map>().GetDouyinAccessToken());
             // 参数
             JObject param = new JObject();
             param.Add("roomid", self.GetParent<Map>().RoomId.ToString());
@@ -111,7 +124,7 @@ namespace ET.Server
         {
             // 请求头
             Dictionary<string, string> head = new Dictionary<string, string>();
-            head.Add("access-token", self.GetParent<Map>().AccessToken);
+            head.Add("access-token", self.GetParent<Map>().GetDouyinAccessToken());
             // 参数
             JObject param = new JObject();
             param.Add("roomid", self.GetParent<Map>().RoomId.ToString());
@@ -147,7 +160,7 @@ namespace ET.Server
         private static int CheckTaskStatus(this MapDouyinLiveCommentComponent self)
         {
             Dictionary<string, string> head = new Dictionary<string, string>();
-            head.Add("access-token", self.GetParent<Map>().AccessToken);
+            head.Add("access-token", self.GetParent<Map>().GetDouyinAccessToken());
             // 参数
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("roomid", self.GetParent<Map>().RoomId.ToString());

+ 17 - 4
DotNet/Hotfix/Scenes/Game/Map/MapDouyinLiveLikeComponentSystem.cs

@@ -12,7 +12,6 @@ namespace ET.Server
             protected override void Awake(MapDouyinLiveLikeComponent self)
             {
                 Log.Info($"创建抖音直播点赞任务组件...");
-                // self.StartTask();
             }
         }
 
@@ -21,6 +20,14 @@ namespace ET.Server
             protected override void Destroy(MapDouyinLiveLikeComponent self)
             {
                 Log.Info($"销毁抖音直播点赞任务组件");
+
+                bool tokenIsNull = self.GetParent<Map>().TokenIsNull();
+
+                if (tokenIsNull)
+                {
+                    return;
+                }
+
                 self.StopTask();
             }
         }
@@ -29,6 +36,12 @@ namespace ET.Server
         {
             protected override void Update(MapDouyinLiveLikeComponent self)
             {
+                bool tokenIsNull = self.GetParent<Map>().TokenIsNull();
+
+                if (tokenIsNull)
+                {
+                    return;
+                }
                 // 运行中状态
                 if (self.Status == 3)
                 {
@@ -74,7 +87,7 @@ namespace ET.Server
         {
             // 请求头
             Dictionary<string, string> head = new Dictionary<string, string>();
-            head.Add("access-token", self.GetParent<Map>().AccessToken);
+            head.Add("access-token", self.GetParent<Map>().GetDouyinAccessToken());
             // 参数
             JObject param = new JObject();
             param.Add("roomid", self.GetParent<Map>().RoomId.ToString());
@@ -111,7 +124,7 @@ namespace ET.Server
         {
             // 请求头
             Dictionary<string, string> head = new Dictionary<string, string>();
-            head.Add("access-token", self.GetParent<Map>().AccessToken);
+            head.Add("access-token", self.GetParent<Map>().GetDouyinAccessToken());
             // 参数
             JObject param = new JObject();
             param.Add("roomid", self.GetParent<Map>().RoomId.ToString());
@@ -147,7 +160,7 @@ namespace ET.Server
         private static int CheckTaskStatus(this MapDouyinLiveLikeComponent self)
         {
             Dictionary<string, string> head = new Dictionary<string, string>();
-            head.Add("access-token", self.GetParent<Map>().AccessToken);
+            head.Add("access-token", self.GetParent<Map>().GetDouyinAccessToken());
             // 参数
             Dictionary<string, string> param = new Dictionary<string, string>();
             param.Add("roomid", self.GetParent<Map>().RoomId.ToString());

+ 20 - 3
DotNet/Hotfix/Scenes/Game/Map/MapSystem.cs

@@ -15,9 +15,6 @@ namespace ET.Server
             protected override void Awake(Map self, JObject opts, WNPlayer player)
             {
                 Log.Debug($"create area opts:{JsonConvert.SerializeObject(opts, Formatting.Indented)}");
-
-                GameDouyinComponent gameDouyinComponent = player.DomainScene().GetComponent<GameDouyinComponent>();
-                self.AccessToken = gameDouyinComponent.AccessToken;
                 self.RoomId = player.GetRoomId();
                 self.createTime = TimeHelper.ServerNow();
                 self.LogicServerId = opts.SelectToken("logicServerId") != null? Convert.ToInt32(opts.SelectToken("logicServerId")) : 0;
@@ -371,5 +368,25 @@ namespace ET.Server
             // todo 默认塔1位置,后面调整为路点
             return "218;78";
         }
+
+        /// <summary>
+        /// 获取抖音直播接口调用凭证
+        /// </summary>
+        /// <param name="self"></param>
+        /// <returns></returns>
+        public static string GetDouyinAccessToken(this Map self)
+        {
+            return self.DomainScene().GetComponent<GameDouyinComponent>().AccessToken;
+        }
+
+        /// <summary>
+        /// Token 是否为空
+        /// </summary>
+        /// <param name="self"></param>
+        /// <returns></returns>
+        public static bool TokenIsNull(this Map self)
+        {
+            return self.DomainScene().GetComponent<GameDouyinComponent>().TokenIsNull;
+        }
     }
 }

+ 0 - 2
DotNet/Hotfix/Scenes/Game/Player/PlayerSystem.cs

@@ -31,8 +31,6 @@ namespace ET.Server
                 self.AddComponent<PlayerSkillComponent>();
                 // 玩家货币组件
                 self.AddComponent<PlayerMoneyComponent>();
-                // 玩家背包组件
-                // self.AddComponent<BagComponent>();
                 // 玩家属性组件
                 self.AddComponent<PlayerBtlComponent>();
             }

+ 2 - 0
DotNet/Model/Scenes/Game/GameDouyinComponent.cs

@@ -7,5 +7,7 @@
         public string AccessToken { get; set; }
         /** 有效时间 (时间戳) **/
         public long AccessTokenTime { get; set; }
+        /** Token标记 **/
+        public bool TokenIsNull { get; set; }
     }
 }

+ 0 - 2
DotNet/Model/Scenes/Game/Map/Map.cs

@@ -11,8 +11,6 @@ namespace ET.Server
     {
         /** 房间id **/
         public long RoomId { get; set; }
-        /** 抖音接口全局唯一调用凭据 **/
-        public string AccessToken { get; set; }
         /** 地图id **/
         public int MapId { get; set; }
         /** 场景玩法类型 **/