Преглед изворни кода

自动重复登录+从服务器获取url

123 пре 1 година
родитељ
комит
ee4e99c3e6

+ 2 - 1
Assets/Content/Config/LanguagePackage_cn.csv

@@ -10026,4 +10026,5 @@ DiffGroupTaskConditionTxt,任务完成:{0}/{1}
 WanTxt,万
 YiTxt,亿
 ItemTypeDes_56,道具
-LoginGetServerListError,当前玩家用户过多,请稍后再试
+LoginGetServerListError,当前玩家用户过多,请稍后再试
+LoginGetServerListErrorString,正在登录玩家用户过多,{0}s后将重试

Разлика између датотеке није приказан због своје велике величине
+ 346 - 58
Assets/Content/Prefabs/UI/UIWaiting/UIWaiting.prefab


+ 2 - 1
Assets/Editor/Pack/PackConstant.cs

@@ -47,7 +47,8 @@ namespace Pack
             "LEBIAN_YUN_CLIENT",
             "GAME_DEBUG",
              "GAME_ONE",
-             "CN_I7GAME_0_1"
+             "CN_I7GAME_0_1",
+                "CN_I7GAME_ZHUAN"
         };
 
         public static readonly string[] BuildScenes = {

+ 29 - 4
Assets/Lua/Managers/LoginMgr.lua

@@ -484,7 +484,7 @@ function LoginMgr:StartCheckServer(isAgain)
     if self.checkWWW then
         self.checkWWW:Dispose()
     end
-    LogWarning('checkWWW-----'..url)
+    --LogWarning('checkWWW-----'..url)
     self.preLoginStatus = self.loginStatus
     self.loginStatus = LoginStatus.CheckServer
     --url = "http://103.239.245.64:81/serverlist/test"
@@ -500,14 +500,39 @@ function LoginMgr:CheckServerFail()
     end
     self.checkWWW = nil
     self.checkServerAgain = nil
-    local data = {"LoginTips4", nil, nil, self, self.InternalRelogin, self.QuitGame}
+   
     if error == "429 Too Many Requests" then
-        data = {"LoginTips14", nil, nil, self, self.InternalRelogin, self.QuitGame}
+        --data = {"LoginTips14", nil, nil, self, self.InternalRelogin, self.QuitGame}
+        ManagerContainer.LuaGameMgr:ClearServerData()
+        ManagerContainer.LuaUIMgr:CloseNetWaiting()
+        ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SERVER_CHANGED)
+       
+       self.waitNoticeTimer = ManagerContainer.LuaTimerMgr:AddLuaTimer(500, 1,function ()
+            local seed = tostring({}):sub(7)
+            math.randomseed(seed)
+            math.random(); math.random(); math.random()
+            local waitTime = math.random(2,10)
+            local waitData ={2,"LoginGetServerListErrorString",{waitTime,1,function ()
+                ManagerContainer.LuaUIMgr:CloseNetWaiting()
+
+                self.waitCloseNoticeTimer =   ManagerContainer.LuaTimerMgr:AddLuaTimer(200, 1,function () 
+                    self:InternalRelogin()
+                    ManagerContainer.LuaTimerMgr:RemoveTimer(self.waitCloseNoticeTimer)
+                end,nil)
+
+                
+            end}}
+            ManagerContainer.LuaUIMgr:ShowNetWaiting_New(waitData)
+            ManagerContainer.LuaTimerMgr:RemoveTimer(self.waitNoticeTimer)
+        end, nil)
+        
+
+        return
     end
 
     --LoginTips14
     ManagerContainer.LuaUIMgr:CloseNetWaiting()
-    
+    local data = {"LoginTips4", nil, nil, self, self.InternalRelogin, self.QuitGame}
     ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UISystemNoticeTips, data, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 10)
     ManagerContainer.LuaGameMgr:ClearServerData()
     ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.CURRENT_SERVER_CHANGED)

+ 7 - 0
Assets/Lua/Managers/LuaUIMgr.lua

@@ -428,6 +428,13 @@ function LuaUIMgr:CloseNetWaiting()
     self:ClosePage(Enum.UIPageName.UIWaiting)
 end
 
+function LuaUIMgr:ShowNetWaiting_New(data)
+    if self:HasOpenPage(Enum.UIPageName.UIWaiting) then
+        return
+    end
+    self:Open(Enum.UIPageName.UIWaiting,data)
+end
+
 --显示单按钮mesbox
 function LuaUIMgr:ShowOkMessageBox(tipsKey,OkCb)
     ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIAntiCheatMsgWnd,  {tipsKey,OkCb})

+ 18 - 0
Assets/Lua/UI/UIWaiting/UIWaitingCtr.lua

@@ -2,12 +2,25 @@ local UIWaitingCtr = class("UIWaitingCtr", require("UICtrBase"))
 
 function UIWaitingCtr:Init(view)
 	self.view = view
+	self.NoticeType = -1
+	self.NoticeText = ""
+	self.TimeData = nil
 end
 
 function UIWaitingCtr:SetData(data)
 	self.asyncIdx = 0
 	if data == nil then return end
 	self.data = data
+	self.NoticeType = -1
+	self.NoticeText = ""
+	self.TimeData = nil
+	
+	if self.data then
+		self.NoticeType = self.data[1] or -1
+		self.NoticeText = self.data[2] or ""
+		self.TimeData = self.data[3]
+	end
+
 end
 
 function UIWaitingCtr:GetAsyncIdx()
@@ -24,5 +37,10 @@ function UIWaitingCtr:OnDispose()
 	self.view = nil
 end
 
+
+function UIWaitingCtr:GetNoticeType()
+	return self.NoticeType
+end
+
 return UIWaitingCtr
 

+ 57 - 1
Assets/Lua/UI/UIWaiting/UIWaitingView.lua

@@ -23,6 +23,13 @@ function UIWaitingView:FillContent(data, uiBase)
 end
 
 function UIWaitingView:Init()
+	--LogError("Type = "..self.controller.NoticeType)
+	self.noticeRoot:SetActive(self.controller.NoticeType >= 0)
+	if self.controller.NoticeType == 1 then -- 普通
+		self.notice.text.text = self.controller.NoticeText
+	elseif self.controller.NoticeType == 2 then --计时
+		self:AutoPlayTimer()
+	end
 end
 
 function UIWaitingView:RemoveEventListener()
@@ -36,7 +43,10 @@ function UIWaitingView:AddUIEventListener()
 end
 
 function UIWaitingView:OnHide()
-
+	if self.curTimer then
+		ManagerContainer.LuaTimerMgr:RemoveTimer(self.curTimer)
+		self.curTimer = nil
+	end
 end
 
 function UIWaitingView:OnShow(data)
@@ -45,6 +55,10 @@ function UIWaitingView:OnShow(data)
 end
 
 function UIWaitingView:OnClose()
+	if self.curTimer then
+		ManagerContainer.LuaTimerMgr:RemoveTimer(self.curTimer)
+		self.curTimer = nil
+	end
 
 end
 
@@ -53,5 +67,47 @@ function UIWaitingView:OnDispose()
 
 end
 
+
+function UIWaitingView:AutoPlayTimer()
+	self.maxTime = self.controller.TimeData[1]
+	self.dtTime = self.controller.TimeData[2]
+	self.TimerCount = math.ceil(self.maxTime/self.dtTime)
+	self.EndTimerCb =  self.controller.TimeData[3]
+	self.EndTimerCbParams =  self.controller.TimeData[4]
+	self.curTime =0
+	self.curTimer = nil
+
+	--LogError("maxTime = "..self.maxTime.."	 dtTime = "..self.dtTime.."	 TimerCount = "..self.TimerCount)
+	self:StartTimer()
+end
+
+
+function  UIWaitingView:StartTimer()
+
+	self.notice.text.text = string.formatbykey(self.controller.NoticeText,tostring(self.maxTime))
+	self.curTimer = ManagerContainer.LuaTimerMgr:AddLuaTimer(self.dtTime * 1000, self.TimerCount,function ()
+		self:UpdateTimer()
+	end, nil)
+end
+
+
+function UIWaitingView:UpdateTimer()
+    self.curTime = self.curTime + 1
+    --self.timersTxt.text.text = tostring(self.maxTime - self.curTime)
+	--string.formatbykey('WalletGold',price)--tostring(price)  
+-- if self.notice then
+--     self.notice.text.text = string.formatbykey(self.controller.NoticeText,
+--         tostring(self.maxTime - (self.dtTime * self.curTime)))
+-- end
+
+	
+	self.notice.text.text = string.formatbykey(self.controller.NoticeText,tostring(self.maxTime - (self.dtTime* self.curTime)))
+    if (self.TimerCount <= self.curTime) then
+		ManagerContainer.LuaTimerMgr:RemoveTimer(self.curTimer)
+		self.curTimer = nil
+		self.EndTimerCb(self.EndTimerCbParams)
+    end
+end
+
 return UIWaitingView
 

+ 66 - 0
Assets/Lua/UI/UIWaiting/UIWaitingView_Generate.lua

@@ -1,6 +1,17 @@
+---@class UIWaiting__Generate_cancelBtn
+---@field public gameObject UnityEngine.GameObject
+---@field public button UnityEngine.UI.Button
+
+---@class UIWaiting__Generate_notice
+---@field public gameObject UnityEngine.GameObject
+---@field public text UnityEngine.UI.Text
+
 ---@class UIWaiting__Generate
 ---@field private gameObject UnityEngine.GameObject
 ---@field private transform UnityEngine.Transform
+---@field private noticeRoot UnityEngine.GameObject
+---@field private notice UIWaiting__Generate_notice
+---@field private cancelBtn UIWaiting__Generate_cancelBtn
 local UIWaitingView = class("UIWaitingView", require("UIViewBase"))
 
 function UIWaitingView:ctor()
@@ -20,12 +31,67 @@ function UIWaitingView:InitGenerate(Root, data)
 	end
 	local tmp
 
+	self:InitGenerate__1(Root,data)
+	self:InitGenerate__2(Root,data)
+	self:InitGenerate__3(Root,data)
 
 
 end
 
+---@private
+function UIWaitingView:InitGenerate__1(Root, data)
+--[[
+	WaitingRoot/NoticeRoot
+--]]
+	local tmp = Root:Find("WaitingRoot/NoticeRoot").gameObject
+	if tolua.getpeer(tmp) == nil then
+		tolua.setpeer(tmp, {})
+	end
+	self.noticeRoot = tmp
+end
+
+---@private
+function UIWaitingView:InitGenerate__2(Root, data)
+--[[
+	WaitingRoot/NoticeRoot/Notice
+--]]
+	local tmp = Root:Find("WaitingRoot/NoticeRoot/Notice").gameObject
+	if tolua.getpeer(tmp) == nil then
+		tolua.setpeer(tmp, {})
+	end
+	self.notice = tmp
+
+	tmp.text = tmp:GetComponent(Enum.TypeInfo.Text)
+end
+
+---@private
+function UIWaitingView:InitGenerate__3(Root, data)
+--[[
+	WaitingRoot/NoticeRoot/CancelBtn
+--]]
+	local tmp = Root:Find("WaitingRoot/NoticeRoot/CancelBtn").gameObject
+	if tolua.getpeer(tmp) == nil then
+		tolua.setpeer(tmp, {})
+	end
+	self.cancelBtn = tmp
+
+	tmp.button = tmp:GetComponent(Enum.TypeInfo.Button)
+end
+
 ---@private
 function UIWaitingView:GenerateDestroy()
+	if tolua.getpeer(self.noticeRoot) ~= nil then
+		tolua.setpeer(self.noticeRoot, nil)
+	end
+	self.noticeRoot = nil
+	if tolua.getpeer(self.notice) ~= nil then
+		tolua.setpeer(self.notice, nil)
+	end
+	self.notice = nil
+	if tolua.getpeer(self.cancelBtn) ~= nil then
+		tolua.setpeer(self.cancelBtn, nil)
+	end
+	self.cancelBtn = nil
 	self.transform = nil
 	self.gameObject = nil
 	self.inited = false

+ 86 - 11
Assets/Src/Core/DownLoad/DownloadMgr.cs

@@ -118,8 +118,10 @@ public class DownloadMgr : Singleton<DownloadMgr>
     {
 #if GAME_ONE
         return "http://101.43.46.101:88/";
+#elif CN_I7GAME_ZHUAN
+          return "http://43.248.186.74:88/";
 #elif CN_I7GAME_0_1
-        return "http://weix.vvfyj.cn/";//"http://103.239.245.64:88/";
+        return "http://weix.vvfyj.cn/";//return "http://103.239.245.64:88/"; //
 #elif GAME_DEBUG
          return "http://110.40.223.119:88/";
 #else
@@ -130,6 +132,27 @@ public class DownloadMgr : Singleton<DownloadMgr>
         return  "http://cdn.yishanyou.com:88/";
 #endif
 
+#endif
+    }
+
+    private string GetBaseUrl()
+    {
+#if GAME_ONE
+        return "";//"http://101.43.46.101:81/";
+#elif CN_I7GAME_ZHUAN
+          return "http://43.248.186.74:81/";
+#elif CN_I7GAME_0_1
+        return "http://103.239.245.64:81/";
+#elif GAME_DEBUG
+         return "";//"http://110.40.223.119:81/";
+#else
+
+#if UNITY_EDITOR
+        return "";//"http://43.248.187.68:81/";
+#else
+        return  ""//"http://cdn.yishanyou.com:81/";
+#endif
+
 #endif
     }
 
@@ -141,7 +164,14 @@ public class DownloadMgr : Singleton<DownloadMgr>
         return GetDownloadBaseUrl() + GetAndroidDownloadPath();
 #endif
     }
-
+    private string GetDownloadUrlFormServer(string baseUrl)
+    {
+#if UNITY_IOS
+        return baseUrl + GetIOSDownloadPath();
+#else
+        return baseUrl + GetAndroidDownloadPath();
+#endif
+    }
     private void InitField()
     {
         if (!isInited)
@@ -185,11 +215,60 @@ public class DownloadMgr : Singleton<DownloadMgr>
             totalSize = 0;
         }
     }
+    //
+    private string GetPlatform()
+    {
+#if UNITY_EDITOR
+        return "PC";
+#else
+#if UNITY_IOS
+       return "IOS";
+#else
+         return "Android";
+#endif
+#endif
+
+    }
 
     public void CheckVersion()
     {
+        string baseUrl = GetBaseUrl();
+        if (!string.IsNullOrEmpty(baseUrl))
+        {
+            baseUrl += $"serverlist/download?platform={GetPlatform()}";
+            AssetDownloader.Instance.DownLoadFileByCoroutine(baseUrl,webReq=> 
+            {
+                if (webReq == null)
+                {
+                    CheckFinish = true;
+                    DowmloadError = true;
+                    return;
+                }
+                
+                string url = webReq.downloadHandler.text;
+                url = url.Substring(1, url.Length - 2);
+                if (url.IndexOf("http://") < 0)
+                {
+                    url = "http://"+ url;
+                }
 
-        AssetDownloader.Instance.DownLoadFileByCoroutine(GetRemoteUrl(versionFileName), webRqst => 
+                Debug.Log("请求得到:" + url);
+                downloadUrl = GetDownloadUrlFormServer(url + "/");
+                StartCheck();
+            });
+        }
+        else
+        {
+            StartCheck();
+        }
+       
+       
+    }
+
+
+    private void StartCheck()
+    {
+        AssetDownloader.Instance.DownLoadFileByCoroutine(GetRemoteUrl(versionFileName), webRqst =>
         {
             if (webRqst == null)
             {
@@ -198,26 +277,22 @@ public class DownloadMgr : Singleton<DownloadMgr>
                 return;
             }
             byte[] data = webRqst.downloadHandler.data;
-           
+
             //versionData = new byte[data.Length];
-             //data.CopyTo(versionData,0);
+            //data.CopyTo(versionData,0);
             string version = Encoding.UTF8.GetString(data);
             Debug.Log("服务器 version = " + version);
             versionData = version;
 
-            ReadDataFromFile(versionFileName,lVdatas=> 
+            ReadDataFromFile(versionFileName, lVdatas =>
             {
                 //OnloadedVersion(lVdatas, version);
                 OnloadedLocalVersion(lVdatas, version);
-            },true);          
+            }, true);
         });
 
-       
     }
 
-
-
-
     public void DownLoadRemoteRes()
     {
         int size = needDownloadList.Count;

Неке датотеке нису приказане због велике количине промена