//更新服务器列表 public static UpdateRetCode ParseRoleList(string account, string roleListFile, List <AccountRoleInfo> roleList, List <ServerInfo> testServerList) { try { StreamReader reader = FileOperate.OpenTextFile(roleListFile); if (reader == null) { return(UpdateRetCode.role_list_no_file); } string text = reader.ReadToEnd(); reader.Close(); string ext = Path.GetExtension(roleListFile); if (ext != null && ext.ToLower() == ".json") // Unity官方说 string.Equals效率优于string.Compare { if (!AccountRoleInfo.ParseFromJsonString(account, text, roleList, testServerList)) { return(UpdateRetCode.role_list_parse_err); } } else { FileOperate.DeleteFile(roleListFile); return(UpdateRetCode.role_list_parse_err); } } catch (Exception e) { Common.HobaDebuger.LogErrorFormat("An Exception was raised when ParseRoleList, {0}", e); return(UpdateRetCode.role_list_parse_err); } return(UpdateRetCode.success); }
IEnumerable RequestAccountRoleListCoroutine(string account, Action <bool> callback) { var patcher = Patcher.Instance; if (patcher.AccoutRoleListResult.IsRunning) { Common.HobaDebuger.LogWarning("RequestAccountRoleListCoroutine Start Failed, AccountRoleList Downloading"); yield break; } _AccountRoleInfoList.Clear(); _TestServerInfoList.Clear(); AccountRoleInfo.ResetOrderZoneId(); string url = patcher.strDynamicAccountRoleDir + account; string hostName = patcher.strDynamicServerHostName; string jsonFile = patcher.strAccountRoleListJSON; FileOperate.DeleteFile(jsonFile); //Common.HobaDebuger.LogWarning("Start DownloadAccountListFile"); patcher.DownloadAccountListFile(url, hostName, jsonFile); //开启线程从中心服下载JSON文件 while (patcher.AccoutRoleListResult.IsRunning) { yield return(null); } //Common.HobaDebuger.LogWarning("End DownloadAccountListFile"); patcher.OnDynamicDownloadComplete(); bool isSuccessful = true; var dlCode = patcher.AccoutRoleListResult.ErrorCode; if (dlCode != Downloader.DownloadTaskErrorCode.Success) { // 下载失败 Common.HobaDebuger.LogWarningFormat("DownloadAccountRoleListFile Failed! DownloadTaskErrorCode: {0} {1}", dlCode, patcher.AccoutRoleListResult.ErrMsg); isSuccessful = false; } else { var code = Patcher.ParseRoleList(account, jsonFile, _AccountRoleInfoList, _TestServerInfoList); if (code != UpdateRetCode.success) { // 解析失败 Common.HobaDebuger.LogWarningFormat("Read AccountRoleJson Failed!"); isSuccessful = false; } } if (callback != null) { callback(isSuccessful); } }
private static int GetAccountRoleList(IntPtr L) { int count = LuaDLL.lua_gettop(L); const int nRet = 1; if (count == 0) { var accountRoleList = EntryPoint.Instance.AccountRoleInfoList; if (accountRoleList != null) { LuaDLL.lua_newtable(L); using (var iter = accountRoleList.GetEnumerator()) { int key = 1; while (iter.MoveNext()) { AccountRoleInfo accountRoleInfo = iter.Current; if (accountRoleInfo == null) { continue; } LuaScriptMgr.Push(L, key); { LuaDLL.lua_newtable(L); LuaScriptMgr.Push(L, "roleId"); LuaScriptMgr.Push(L, accountRoleInfo.roleId); LuaDLL.lua_settable(L, -3); LuaScriptMgr.Push(L, "level"); LuaScriptMgr.Push(L, accountRoleInfo.level); LuaDLL.lua_settable(L, -3); LuaScriptMgr.Push(L, "name"); LuaScriptMgr.Push(L, accountRoleInfo.name); LuaDLL.lua_settable(L, -3); LuaScriptMgr.Push(L, "profession"); LuaScriptMgr.Push(L, accountRoleInfo.profession); LuaDLL.lua_settable(L, -3); LuaScriptMgr.Push(L, "customSet"); LuaScriptMgr.Push(L, accountRoleInfo.customSet); LuaDLL.lua_settable(L, -3); LuaScriptMgr.Push(L, "zoneId"); LuaScriptMgr.Push(L, accountRoleInfo.zoneId); LuaDLL.lua_settable(L, -3); } LuaDLL.lua_settable(L, -3); key++; } } } } else { LuaDLL.lua_pushnil(L); LogParamError("GetAccountRoleList", count); } return(CheckReturnNum(L, count, nRet)); }