源战役客户端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

272 righe
7.4 KiB

4 settimane fa
  1. GameError = GameError or BaseClass()
  2. function GameError:__init()
  3. GameError.Instance = self
  4. self.wait_sent_list = {}
  5. self.last_sent_time = 0
  6. self.sent_interval = 10
  7. self.save_file_error_count = 0
  8. self.download_file_error_count = 0
  9. LogType = UnityEngine.LogType
  10. local func = function(msg, stackTrace,msg_type)
  11. if msg_type == LogType.Warning or msg_type == LogType.Exception or msg_type == LogType.Assert or msg_type == LogType.Error then
  12. pcall(self.SendErrorToPHP, self, msg, msg_type)
  13. end
  14. end
  15. UnityEngine.Application.logMessageReceived = UnityEngine.Application.logMessageReceived + func
  16. end
  17. function GameError:SendErrorToPHP( str, msg_type )
  18. if not str or str == "" then return end
  19. -- if string.find(str, "NullReferenceException") then
  20. -- if not self.show_profiler_flag then
  21. -- self.show_profiler_flag = true
  22. -- PrintTimerQuest()
  23. -- LuaProfiler.start()
  24. -- local function on_delay( )
  25. -- LuaProfiler.stop()
  26. -- local str = LuaProfiler._CUSTOM_REPORTS
  27. -- GameError:SendErrorMsg(str)
  28. -- print("tanar: [GameError 35]=> str: ",str)
  29. -- end
  30. -- setTimeout(on_delay, 1)
  31. -- end
  32. -- end
  33. local ignore_list =
  34. {
  35. [1] = "not wrap to lua",
  36. [2] = "current connect info",
  37. [3] = "Stale touch detected",
  38. [4] = "Animator.GotoState",
  39. [5] = "create a MonoBehaviour using the 'new' keyword",
  40. [6] = "Animator does not have an AnimatorController",
  41. [7] = "Can't call Animator.Update on inactive object",
  42. [8] = "Invalid Layer Index",
  43. [9] = "Animator is not playing an AnimatorController",
  44. [10] = "This MeshCollider requires the mesh to be marked as readable",
  45. [11] = "auto download res timeout",
  46. [12] = "res download error occurr",
  47. [13] = "GLSL: unsupported array parameter",
  48. [14] = "Mesh does not have normals",
  49. [15] = "Game object with animator is inactive",
  50. [16] = "CollisionMeshData couldn't be created",
  51. [17] = "Mesh does not have normals for Global Illumination",
  52. [18] = "The request timed out",
  53. [19] = "Screen position out of view frustum",
  54. [20] = "Internal: JobTempAlloc has allocations that are more than 4 frames old",
  55. [21] = "To Debug, enable the define: TLA_DEBUG_STACK_LEAK in ThreadsafeLinearAllocator.cpp",
  56. }
  57. if tonumber(AppConst.EnglineVer) < 89 then
  58. table.insert(ignore_list,"The AssetBundle 'Memory'")
  59. end
  60. for key,ignore_str in pairs(ignore_list) do
  61. local find_succeed = string.find(str, ignore_str)
  62. if find_succeed then
  63. return
  64. end
  65. end
  66. local no_show_error_list =
  67. {
  68. }
  69. if ClientConfig.open_lua_error_win and LuaErrorModel then
  70. local no_show = false
  71. for key,no_show_str in pairs(no_show_error_list) do
  72. local find_succeed = string.find(str, no_show_str)
  73. if find_succeed then
  74. no_show = true
  75. end
  76. end
  77. if not no_show then
  78. GlobalEventSystem:Fire(LuaErrorModel.SEND_LUAERROR_MESSAGE,str)
  79. end
  80. end
  81. if not AppConst.UpdateMode or not ClientConfig.php_website_error or ClientConfig.php_website_error == "" then
  82. return
  83. end
  84. local old_ver_ignore_list =
  85. {
  86. [1] = "because another AssetBundle with the same files is already loaded",
  87. [2] = "You are trying to load data from a www stream which had the following error when downloading",
  88. }
  89. for key,ignore_str in pairs(old_ver_ignore_list) do
  90. local find_succeed = string.find(str, ignore_str)
  91. if find_succeed and Scene and Scene.Instance and Scene.Instance:IsSceneProloadFinish() then
  92. Message.show("网络连接出现异常,请重新进入游戏")
  93. end
  94. end
  95. if string.find(str,"SQLite") or string.find(str,"database") then
  96. local date_ver_file = Util.DataPath .. "ver.flag"
  97. os.remove(date_ver_file)
  98. Message.show("检测到游戏资源可能损坏,重启游戏后将会自动修复")
  99. end
  100. if string.find(str, "Could not allocate memory: System out of memory!") then
  101. Message.show("手机运行内存不足,请清理后台应用缓存后,重新进入游戏")
  102. end
  103. if string.find(str, "Disk full") then
  104. Message.show("储存文件异常,请检查手机剩余空间大小")
  105. end
  106. if string.find(str, "res save error occurr") then
  107. self.save_file_error_count = self.save_file_error_count + 1
  108. if self.save_file_error_count > 10 then
  109. Message.show("储存文件异常,请检查手机剩余空间大小")
  110. return
  111. end
  112. end
  113. if string.find(str, "res download error occurr") then
  114. self.download_file_error_count = self.download_file_error_count + 1
  115. if self.download_file_error_count > 10 then
  116. Message.show("游戏资源加载异常,请检查网络连接")
  117. return
  118. end
  119. end
  120. local error_str = str
  121. local f1 = string.find(error_str,"%[")
  122. local f2 = string.find(error_str,"%]")
  123. if f1 == 1 and f2 == 14 then
  124. error_str = string.sub(error_str,15)
  125. end
  126. local exist = self:ExistSameError(error_str)
  127. if exist then
  128. return
  129. end
  130. table.insert(self.wait_sent_list,"<br>")
  131. table.insert(self.wait_sent_list,error_str)
  132. if not self.cur_timer then
  133. local sent_func = function()
  134. self:SendNow()
  135. end
  136. local wait_time = self.sent_interval - ( os.time() - self.last_sent_time )
  137. if wait_time > 0 then
  138. self.cur_timer = GlobalTimerQuest:AddDelayQuest(sent_func, wait_time)
  139. else
  140. sent_func()
  141. end
  142. end
  143. end
  144. function GameError:ExistSameError(error_str)
  145. for _, content in ipairs(self.wait_sent_list) do
  146. if error_str == content then
  147. return true
  148. end
  149. end
  150. return false
  151. end
  152. function GameError:SendNow()
  153. self.last_sent_time = os.time()
  154. self.cur_timer = nil
  155. if not Util.NetAvailable then
  156. return
  157. end
  158. local error_str = ""
  159. for _, content in ipairs(self.wait_sent_list) do
  160. error_str = error_str .. "\n" .. content
  161. end
  162. self:SendErrorMsg(error_str)
  163. self.wait_sent_list = {}
  164. end
  165. function GameError:SendErrorMsg(error_str, force_sent)
  166. if not AppConst.UpdateMode and not force_sent then
  167. return
  168. end
  169. if not Util.NetAvailable then
  170. return
  171. end
  172. if not error_str or error_str == "" then
  173. return
  174. end
  175. local role_id = 0
  176. local role_name = ""
  177. local role_lv = 0
  178. if RoleManager and RoleManager.Instance then
  179. local vo = RoleManager.Instance:GetMainRoleVo()
  180. if vo then
  181. role_id = tostring(vo.role_id) or 0
  182. role_name = vo.name or ""
  183. role_lv = vo.level or 0
  184. end
  185. end
  186. local cur_server = 0
  187. local server_name = ""
  188. if LoginController and LoginController.Instance then
  189. local playerInfo = LoginController.Instance:GetPlatUserInfo()
  190. if playerInfo then
  191. cur_server = playerInfo.server_id or 0
  192. server_name = playerInfo.server_name or ""
  193. end
  194. end
  195. local no_empty_str = string.gsub(error_str,"%s","")
  196. if string.len(no_empty_str) < 10 then
  197. return
  198. end
  199. local no_line_str = string.gsub(error_str, "-", "")
  200. if string.len(no_line_str) < 10 then
  201. return
  202. end
  203. -- local scripts_ver = GameConfigUtil.GetValue("scriptsver")
  204. -- if scripts_ver == "" or not scripts_ver then
  205. -- scripts_ver = "1.0.0"
  206. -- end
  207. local scripts_ver = ClientConfig.scripts_ver or "0"
  208. scripts_ver = tostring(AppConst.EnglineVer) .. "." .. scripts_ver
  209. local ticket = ClientConfig.login_key
  210. local now_method = "log_client_error"
  211. local cur_time = tostring(os.time())
  212. local post_param = {
  213. time = cur_time,
  214. content = "version:" .. scripts_ver .. " plat:" .. ClientConfig.plat_name .. " server:" .. server_name .. " lv:" .. role_lv .. " phone:" .. SystemInfo.deviceModel .. "\n" .. error_str,
  215. method = now_method,
  216. player_id = role_id,
  217. nickname = role_name,
  218. sign = string.lower(Util.md5( ticket .. cur_time .. now_method )),
  219. server_id = cur_server,
  220. plat = ClientConfig.plat_name,
  221. game = "mrzj",
  222. }
  223. local call_func = function(ret,error_msg,data)
  224. end
  225. HttpUtil.HttpPostRequest(ClientConfig.php_website_error, post_param, call_func)
  226. end