540 lines
20 KiB
Lua
540 lines
20 KiB
Lua
|
------------------------------------------------
|
|||
|
-- 作者: gzg
|
|||
|
-- 日期: 2021-02-25
|
|||
|
-- 文件: ServerListSystem.lua
|
|||
|
-- 模块: ServerListSystem
|
|||
|
-- 描述: 服务器列表的信息
|
|||
|
------------------------------------------------
|
|||
|
local LoginStatus = require("Logic.Login.LoginStatus");
|
|||
|
local ServerUrlInfo = require("Logic.ServerList.ServerUrlInfo");
|
|||
|
local ServerDataInfo = require("Logic.ServerList.ServerDataInfo");
|
|||
|
local ServerGroupInfo = require("Logic.ServerList.ServerGroupInfo");
|
|||
|
local ServerCharInfo = require("Logic.ServerList.ServerCharInfo");
|
|||
|
local SDKCacheData = CS.Thousandto.CoreSDK.SDKCacheData;
|
|||
|
|
|||
|
local L_MAX_SHOW_SERVER_GROUP = 50;
|
|||
|
local L_CN_RECENT_SERVER_KEY = "RecentServerKey";
|
|||
|
|
|||
|
local ServerListSystem = {
|
|||
|
|
|||
|
--通过远程获得所有服务器的列表
|
|||
|
AllList = List:New();
|
|||
|
--所有网关的列表
|
|||
|
AllAgentList = List:New();
|
|||
|
--曾经登录过的服务器列表
|
|||
|
RecentLoginList = List:New(),
|
|||
|
--推荐服务器列表
|
|||
|
RecommendList = List:New(),
|
|||
|
--存在角色的服务器列表
|
|||
|
ExistRoleList = List:New(),
|
|||
|
--获得维护的服务器列表
|
|||
|
MaintenanceList = List:New(),
|
|||
|
--登录服务器
|
|||
|
LoginServer = nil,
|
|||
|
--最后一次登录的服务器
|
|||
|
LastEnterServer = nil,
|
|||
|
--服务器分组
|
|||
|
GroupedList = List:New(),
|
|||
|
|
|||
|
--玩家手动选择的服务器
|
|||
|
ChooseGameServerID = -1,
|
|||
|
--服务器列表下载标记:-1:没有下载, 0:开始下载, >0:成功下载某列表
|
|||
|
DownloadFlag = -1,
|
|||
|
|
|||
|
--服务器下载地址信息
|
|||
|
ServerUrlInfo = nil,
|
|||
|
|
|||
|
--游戏服务器列表下载完毕回调句柄
|
|||
|
--OnGsServerDownloadFinishHandler = nil,
|
|||
|
--登录服务器列表下载完毕回调句柄
|
|||
|
--OnLsServerDownloadFinishHandler = nil,
|
|||
|
|
|||
|
--服务器列表下载完毕的回调句柄
|
|||
|
OnServerDownloadFinishHandler = nil,
|
|||
|
--服务器列表下载失败回调句柄
|
|||
|
OnDownloadFailHandler = nil,
|
|||
|
}
|
|||
|
|
|||
|
function ServerListSystem:Initialize(clearLoginData)
|
|||
|
Debug.Log("ServerListSystem:Initialize:" .. tostring(clearLoginData));
|
|||
|
--重新关联事件,因为所有注册事件都会在一个轮回中清理掉.
|
|||
|
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_SDK_LOGIN_SUCCESS,self.DownloadServerList,self);
|
|||
|
if clearLoginData then
|
|||
|
self.ServerUrlInfo = ServerUrlInfo:New();
|
|||
|
--self.OnGsServerDownloadFinishHandler = Utils.Handler(self.OnGsServerDownloadFinish,self,nil,true);
|
|||
|
--self.OnLsServerDownloadFinishHandler = Utils.Handler(self.OnLsServerDownloadFinish,self,nil,true);
|
|||
|
self.OnServerDownloadFinishHandler = Utils.Handler(self.OnServerDownloadFinish,self,nil,true);
|
|||
|
self.OnDownloadFailHandler = Utils.Handler(self.OnDownloadFail,self,nil,true);
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function ServerListSystem:UnInitialize(clearLoginData)
|
|||
|
Debug.Log("ServerListSystem:UnInitialize:" .. tostring(clearLoginData));
|
|||
|
--重新关联事件,因为所有注册事件都会在一个轮回中清理掉.
|
|||
|
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_SDK_LOGIN_SUCCESS,self.DownloadServerList,self);
|
|||
|
if clearLoginData then
|
|||
|
self.ServerUrlInfo = nil;
|
|||
|
self.OnGsServerDownloadFinishHandler = nil;
|
|||
|
self.OnLsServerDownloadFinishHandler = nil;
|
|||
|
self.OnServerDownloadFinishHandler = nil;
|
|||
|
self.OnDownloadFailHandler = nil;
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--清理所有的服务器列表
|
|||
|
function ServerListSystem:Clear()
|
|||
|
self.AllList:Clear();
|
|||
|
self.AllAgentList:Clear();
|
|||
|
self.RecentLoginList:Clear();
|
|||
|
self.RecommendList:Clear();
|
|||
|
self.ExistRoleList:Clear();
|
|||
|
self.GroupedList:Clear();
|
|||
|
self.LastEnterServer = nil;
|
|||
|
self.LoginServer = nil;
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
function ServerListSystem:GetLoginServer()
|
|||
|
if not self.LoginServer then
|
|||
|
if self.AllAgentList and self.AllAgentList:Count() > 0 then
|
|||
|
math.randomseed(os.time());
|
|||
|
local _idx = math.random(1,self.AllAgentList:Count());
|
|||
|
self.LoginServer = self.AllAgentList[_idx];
|
|||
|
else
|
|||
|
Debug.LogError("当前网关服务器列表为空!!");
|
|||
|
end
|
|||
|
end
|
|||
|
return self.LoginServer;
|
|||
|
end
|
|||
|
|
|||
|
--下载服务器列表
|
|||
|
function ServerListSystem:DownloadServerList()
|
|||
|
if self.DownloadFlag >= 0 then
|
|||
|
return;
|
|||
|
end
|
|||
|
self.DownloadFlag = 0;
|
|||
|
GameCenter.PushFixEvent(UIEventDefine.UI_WAITING_OPEN, DataConfig.DataMessageString.Get("C_XIAOTIAN_TIPS3"));
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_LOGIN_STATUS, LoginStatus.CallServerlist);
|
|||
|
--LuaCoroutineUtils.WebRequestText(self.ServerUrlInfo:GetServerListURL(), self.OnGsServerDownloadFinishHandler, self.OnDownloadFailHandler, nil);
|
|||
|
--LuaCoroutineUtils.WebRequestText(self.ServerUrlInfo:GetLoginServerURL(), self.OnLsServerDownloadFinishHandler, self.OnDownloadFailHandler, nil);
|
|||
|
LuaCoroutineUtils.WebRequestText(self.ServerUrlInfo:GetServerListNewURL(), self.OnServerDownloadFinishHandler, self.OnDownloadFailHandler, nil);
|
|||
|
--self:OnGsServerDownloadFinish("{\"data\":{\"servers\":[{\"group_type\":1,\"svr_host\":\"127.0.0.1\",\"svr_id\":\"20017\",\"svr_idx\":\"20017\",\"svr_label\":\"3\",\"svr_name\":\"本地服务器\",\"svr_pay_callback\":\"xxx\",\"svr_port\":8587,\"svr_sort\":3,\"svr_status\":1}]},\"state\":1}");
|
|||
|
--self:OnLsServerDownloadFinish("{\"data\":{\"extParams\":{\"svr_private_chids\":\"73|74\",\"svr_port\":8887,\"svr_host\":\"127.0.0.1\",\"svr_name\":\"网关服务器\"}},\"state\":1}");
|
|||
|
end
|
|||
|
|
|||
|
--服务器下载完毕
|
|||
|
function ServerListSystem:OnServerDownloadFinish(wwwText)
|
|||
|
--去下载充值列表的数据
|
|||
|
--GameCenter.PaySystem:DownLoadPayList();
|
|||
|
--关闭MessageBox
|
|||
|
GameCenter.MsgPromptSystem:CloseMsgBox();
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_UPDATE_RECORDER_STEP, { CS.Thousandto.Update.Recorder.StepType.RequestServerList, 0, "Success" });
|
|||
|
|
|||
|
--如果www不为空,表示通过url进行下载的.
|
|||
|
if wwwText ~= nil and wwwText ~= "" then
|
|||
|
self:Clear();
|
|||
|
self.AllList,self.AllAgentList = ServerDataInfo:ParseServersJsonNew(wwwText);
|
|||
|
if self.AllAgentList and self.AllList and self.AllAgentList:Count() > 0 then
|
|||
|
self.LoginServer = nil;
|
|||
|
Debug.Log("游戏服务器列表下载完毕!downloadFlag = " .. self.DownloadFlag .. ";;服务器列表数量:" .. self.AllList:Count());
|
|||
|
GameCenter.LoginSystem:ConnectLoginServer();
|
|||
|
else
|
|||
|
Debug.LogError("当前服务器列表为空,wwwText:" .. tostring(wwwText));
|
|||
|
end
|
|||
|
self.DownloadFlag = -1;
|
|||
|
else
|
|||
|
Debug.LogError("下载游戏服务器列表错误!downloadFlag = " .. self.DownloadFlag);
|
|||
|
self.DownloadFlag = -1;
|
|||
|
Utils.ShowMsgBoxAndBtn(nil,"C_MSGBOX_OK","C_LOGIN_DOWNLOAD_SERVER_LIST_FAIL");
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--下载失败
|
|||
|
function ServerListSystem:OnDownloadFail(errCode, error)
|
|||
|
if (errCode <= 0 ) then
|
|||
|
--下载失败,彻底失败,退出
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_UPDATE_RECORDER_STEP, { CS.Thousandto.Update.Recorder.StepType.RequestServerList, 1, error });
|
|||
|
GameCenter.PushFixEvent(UIEventDefine.UI_WAITING_CLOSE);
|
|||
|
self.DownloadFlag = -1;
|
|||
|
--关闭MessageBox
|
|||
|
Utils.ShowMsgBox(function (x)
|
|||
|
if (x == MsgBoxResultCode.Button2) then
|
|||
|
self:DownloadServerList();
|
|||
|
else
|
|||
|
GameCenter.SDKSystem:ExitGame();
|
|||
|
end
|
|||
|
end,"C_GETSERVERLIST_ERROR");
|
|||
|
else
|
|||
|
--下载失败,正在重试
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_UPDATE_RECORDER_STEP, { CS.Thousandto.Update.Recorder.StepType.RequestServerList, 2, error });
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--处理服务器列表
|
|||
|
--List<MSG_Login.serverNumInfo> serNumInfos,List<int> existRoleIDs,int lastEnterID,List<MSG_Login.serverChangeName> changeNameList = null)
|
|||
|
function ServerListSystem:ProcessServerList(serNumInfos,existRoleIDs,lastEnterID,changeNameList)
|
|||
|
|
|||
|
--这里注释了通过服务器白名单的剔除工作,现在服务器列表通过用户ID参数直接过滤
|
|||
|
--1.如果有改名先给服务器名字替换了
|
|||
|
self:UpdateServerNames(changeNameList);
|
|||
|
|
|||
|
--2.为服务器列表数据,增加服务器的其他数据
|
|||
|
self:UpdateServerNums(serNumInfos);
|
|||
|
|
|||
|
--3.处理存在角色的服务器
|
|||
|
self:UpdateExistRoleServer(existRoleIDs);
|
|||
|
|
|||
|
--4.处理推荐服务器
|
|||
|
self:ProcessRecommendServer();
|
|||
|
|
|||
|
--5.处理最后一次登录的服务器
|
|||
|
self:ProcessLastEnterServer(lastEnterID);
|
|||
|
|
|||
|
--6.处理最近登录的服务器列表
|
|||
|
self:ProcessRecentServer();
|
|||
|
|
|||
|
--7.处理服务器分组
|
|||
|
self:ProcessGroupedServerList(L_MAX_SHOW_SERVER_GROUP);
|
|||
|
|
|||
|
--8.处理维护的服务器列表
|
|||
|
self:ProcessMaintenanceServerList();
|
|||
|
|
|||
|
--9.处理默认的当前服务器
|
|||
|
local _defaultCurSer = self:GetCurrentServer();
|
|||
|
if _defaultCurSer then
|
|||
|
SDKCacheData.ServerID = tostring(_defaultCurSer.ServerId);
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--更新服务器名字
|
|||
|
function ServerListSystem:GS2U_ResChangeServerNameSuccess(serverId,changeName)
|
|||
|
|
|||
|
local _cs = self:FindServer(serverId)
|
|||
|
if _cs then
|
|||
|
_cs.Name = changeName;
|
|||
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SERVER_CHANGNAME_SUCCESS );
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
-- 通过服务器ID来查找服务器信息,
|
|||
|
-- 各位亲,请注意,这里很有找不到的情况.
|
|||
|
function ServerListSystem:FindServer(id)
|
|||
|
return self.AllList:Find(function(a)
|
|||
|
return a.ServerId == id;
|
|||
|
end);
|
|||
|
end
|
|||
|
|
|||
|
--更新服务器的名字
|
|||
|
function ServerListSystem:UpdateServerNames(changeNameList)
|
|||
|
if changeNameList then
|
|||
|
for i = 1, changeNameList:Count() do
|
|||
|
local info = self:FindServer(changeNameList[i].serverId)
|
|||
|
if info then
|
|||
|
info.Name = changeNameList[i].changeName;
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--填充服务器的其他数据
|
|||
|
function ServerListSystem:UpdateServerNums(serNumInfos)
|
|||
|
if serNumInfos then
|
|||
|
for _, _si in ipairs(serNumInfos) do
|
|||
|
local _info = self:FindServer(_si.serverId)
|
|||
|
if _info then
|
|||
|
for i, value in ipairs(_si.roles) do
|
|||
|
local _sci = ServerCharInfo:New();
|
|||
|
_info.CharacterList:Add(_sci);
|
|||
|
_sci.ID = value.roleId;
|
|||
|
_sci.ServerId = _si.serverId;
|
|||
|
_sci.Career = value.career;
|
|||
|
_sci.Level = value.lv;
|
|||
|
_sci.Name = value.name;
|
|||
|
_sci.PowerValue = value.fight;
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--处理存在角色的服务器
|
|||
|
function ServerListSystem:UpdateExistRoleServer(existRoleIDs)
|
|||
|
self.ExistRoleList:Clear();
|
|||
|
if existRoleIDs then
|
|||
|
for _, _sid in ipairs(existRoleIDs) do
|
|||
|
local _info = self:FindServer(_sid);
|
|||
|
if _info then
|
|||
|
_info.HasRole = true;
|
|||
|
self.ExistRoleList:Add(_info);
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
--所有推荐服都需要进行排序
|
|||
|
self.ExistRoleList:Sort(function (x,y)
|
|||
|
return x.ShowOrder > y.ShowOrder;
|
|||
|
end);
|
|||
|
end
|
|||
|
|
|||
|
--获取推荐服,如果没有,则返回最新的10个服务器
|
|||
|
function ServerListSystem:ProcessRecommendServer()
|
|||
|
self.RecommendList:Clear();
|
|||
|
local _tmp = List:New();
|
|||
|
for index, value in ipairs(self.AllList) do
|
|||
|
local _item = value;
|
|||
|
if _item and _item.IsRecommendServer then
|
|||
|
self.RecommendList:Add(_item);
|
|||
|
end
|
|||
|
if index <= 10 then
|
|||
|
_tmp:Add(_item);
|
|||
|
end
|
|||
|
|
|||
|
end
|
|||
|
--如果没有推荐服,则默认显示最新的10个服务器
|
|||
|
if self.RecommendList:Count() == 0 then
|
|||
|
self.RecommendList:AddRange(_tmp);
|
|||
|
end
|
|||
|
|
|||
|
--所有推荐服都需要进行排序
|
|||
|
self.RecommendList:Sort(function (x,y)
|
|||
|
if x.PlayerNum == y.PlayerNum then
|
|||
|
return x.ShowOrder > y.ShowOrder;
|
|||
|
else
|
|||
|
return x.PlayerNum < y.PlayerNum;
|
|||
|
end
|
|||
|
end);
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
--处理最后一次登录的服务器
|
|||
|
function ServerListSystem:ProcessLastEnterServer(lastEnterID)
|
|||
|
self.LastEnterServer = self:FindServer(lastEnterID);
|
|||
|
if (self.LastEnterServer == nil and self.RecommendList:Count() > 0) then
|
|||
|
self.LastEnterServer = self.RecommendList[1];
|
|||
|
end
|
|||
|
if (self.LastEnterServer == nil and self.AllList:Count() > 0) then
|
|||
|
self.LastEnterServer = self.AllList[1];
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--添加最近的服务器到本地
|
|||
|
function ServerListSystem:AddRecentServer(ID)
|
|||
|
local _jsonStr = PlayerPrefs.GetString(L_CN_RECENT_SERVER_KEY, "{\"data\":[]}");
|
|||
|
local _tab = Json.decode(_jsonStr);
|
|||
|
for index, value in ipairs(_tab.data) do
|
|||
|
if value == ID then
|
|||
|
table.remove(_tab.data,index);
|
|||
|
break;
|
|||
|
end
|
|||
|
end
|
|||
|
table.insert(_tab.data,1,ID);
|
|||
|
_jsonStr = Json.encode(_tab);
|
|||
|
PlayerPrefs.SetString(L_CN_RECENT_SERVER_KEY, _jsonStr);
|
|||
|
PlayerPrefs.Save();
|
|||
|
end
|
|||
|
|
|||
|
--获取最近登录的服务器ID列表
|
|||
|
function ServerListSystem:GetRecentServerIDList()
|
|||
|
local _jsonStr = PlayerPrefs.GetString(L_CN_RECENT_SERVER_KEY, "{\"data\":[]}");
|
|||
|
local _tab = Json.decode(_jsonStr);
|
|||
|
return List:New(_tab.data);
|
|||
|
end
|
|||
|
|
|||
|
--处理最近登录的服务器
|
|||
|
function ServerListSystem:ProcessRecentServer()
|
|||
|
self.RecentLoginList:Clear();
|
|||
|
local _ids = self:GetRecentServerIDList();
|
|||
|
for _, value in ipairs(_ids) do
|
|||
|
local _item = self:FindServer(value);
|
|||
|
if _item then
|
|||
|
_item.HasRole = true;
|
|||
|
self.RecentLoginList:Add(_item);
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--分组后的列表,以groupCount个为1组
|
|||
|
function ServerListSystem:ProcessGroupedServerList(groupCount)
|
|||
|
|
|||
|
self.GroupedList:Clear();
|
|||
|
|
|||
|
--测试服 grouptype = 0
|
|||
|
local _testList = List:New();
|
|||
|
--先锋服 group type = 1
|
|||
|
local _tryList = List:New();
|
|||
|
--正式服 group type = 2
|
|||
|
local _noSortList = List:New();
|
|||
|
local _sortList = List:New();
|
|||
|
for _, value in ipairs(self.AllList) do
|
|||
|
--value.GroupType = math.random(0,3)
|
|||
|
if value.GroupType == 0 then
|
|||
|
_testList:Add(value)
|
|||
|
elseif value.GroupType == 1 then
|
|||
|
_tryList:Add(value)
|
|||
|
else
|
|||
|
if value.ShowOrder <= 0 then
|
|||
|
_noSortList:Add(value);
|
|||
|
else
|
|||
|
_sortList:Add(value);
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
--把无序的设定位一组
|
|||
|
if _testList:Count() > 0 then
|
|||
|
self.GroupedList:Add(ServerGroupInfo:New(0,0,_testList,DataConfig.DataMessageString.Get("C_TEST_SERVER_AREA")));
|
|||
|
end
|
|||
|
|
|||
|
if _tryList:Count() > 0 then
|
|||
|
self.GroupedList:Add(ServerGroupInfo:New(0,0,_tryList,DataConfig.DataMessageString.Get("C_DNF_SERVER_AREA")));
|
|||
|
end
|
|||
|
|
|||
|
if _noSortList:Count() > 0 then
|
|||
|
self.GroupedList:Add(ServerGroupInfo:New(0,0,_noSortList,DataConfig.DataMessageString.Get("C_INVALID_SERVER_AREA")));
|
|||
|
end
|
|||
|
|
|||
|
--排序
|
|||
|
_sortList:Sort(function (x,y)
|
|||
|
return x.ShowOrder < y.ShowOrder;
|
|||
|
end)
|
|||
|
|
|||
|
while _sortList:Count() > 0 do
|
|||
|
local _gi = ServerGroupInfo:Create(_sortList,_sortList[1].ShowOrder,_sortList[1].ShowOrder + groupCount - 1);
|
|||
|
if _gi then
|
|||
|
self.GroupedList:Add(_gi);
|
|||
|
end
|
|||
|
end
|
|||
|
self.GroupedList:Sort(function (x,y)
|
|||
|
if ( x.EndID == y.EndID) then
|
|||
|
return false;
|
|||
|
elseif(x.EndID == 0)then
|
|||
|
return true;
|
|||
|
elseif(y.EndID == 0)then
|
|||
|
return false;
|
|||
|
else
|
|||
|
return x.EndID > y.EndID;
|
|||
|
end
|
|||
|
end)
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--处理维护服务器列表
|
|||
|
function ServerListSystem:ProcessMaintenanceServerList()
|
|||
|
self.MaintenanceList:Clear();
|
|||
|
for _, value in ipairs(self.AllList) do
|
|||
|
self.MaintenanceList:Add(value);
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--设置最后的进入服务器
|
|||
|
function ServerListSystem:SetLastEnterServer(gs)
|
|||
|
if gs == nil then return; end
|
|||
|
self:AddRecentServer(gs.ServerId);
|
|||
|
self.LastEnterServer = gs;
|
|||
|
end
|
|||
|
|
|||
|
--获得当前服务器
|
|||
|
function ServerListSystem:GetCurrentServer()
|
|||
|
local _result = nil;
|
|||
|
|
|||
|
--如果当前选择的游戏服ID大于0
|
|||
|
if (self.ChooseGameServerID >= 0) then
|
|||
|
_result = self:FindServer(self.ChooseGameServerID);
|
|||
|
end
|
|||
|
|
|||
|
--选择服务器最后一次登录的服务器
|
|||
|
if (_result == nil and self.LastEnterServer) then
|
|||
|
_result = self.LastEnterServer;
|
|||
|
end
|
|||
|
|
|||
|
--选择本地最后一次登录的服务器
|
|||
|
if _result == nil and self.RecentLoginList:Count() > 0 then
|
|||
|
_result = self.RecentLoginList[1];
|
|||
|
end
|
|||
|
|
|||
|
--如果都还是空的,取包含角色的列表第一个服务器
|
|||
|
if (_result == nil and self.ExistRoleList:Count() > 0) then
|
|||
|
_result = self.ExistRoleList[1];
|
|||
|
end
|
|||
|
|
|||
|
--如果都还是空的,取推荐列表的第一个服务器
|
|||
|
if (_result == nil and self.RecommendList:Count() > 0) then
|
|||
|
_result = self.RecommendList[1];
|
|||
|
end
|
|||
|
|
|||
|
--如果都还是空的,取全部列表的第一个服务器
|
|||
|
if (_result == nil and self.AllList:Count() > 0) then
|
|||
|
_result = self.AllList[1];
|
|||
|
end
|
|||
|
|
|||
|
--如果还是空,直接报错吧
|
|||
|
if (_result == nil) then
|
|||
|
Debug.LogError("GetCurrentServer:获取当前服务器为空!");
|
|||
|
end
|
|||
|
return _result;
|
|||
|
end
|
|||
|
|
|||
|
--[[
|
|||
|
|
|||
|
---解析x8的服务器列表--被抛弃了--2021-08-06.
|
|||
|
--游戏服务器列表下载完毕回调
|
|||
|
function ServerListSystem:OnGsServerDownloadFinish(wwwText)
|
|||
|
--去下载充值列表的数据
|
|||
|
GameCenter.PaySystem:DownLoadPayList();
|
|||
|
--关闭MessageBox
|
|||
|
GameCenter.MsgPromptSystem:CloseMsgBox();
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_UPDATE_RECORDER_STEP, { CS.Thousandto.Update.Recorder.StepType.RequestServerList, 0, "Success" });
|
|||
|
|
|||
|
--如果www不为空,表示通过url进行下载的.
|
|||
|
if wwwText ~= nil and wwwText ~= "" then
|
|||
|
self:Clear();
|
|||
|
self.AllList = ServerDataInfo:ParseGameServerListJson(wwwText);
|
|||
|
Debug.Log("游戏服务器列表下载完毕!downloadFlag = " .. self.DownloadFlag .. ";;服务器列表数量:" .. self.AllList:Count());
|
|||
|
self.DownloadFlag = self.DownloadFlag | 2;
|
|||
|
if ((self.DownloadFlag & 3) == 3) then
|
|||
|
GameCenter.LoginSystem:ConnectLoginServer();
|
|||
|
self.DownloadFlag = -1;
|
|||
|
end
|
|||
|
else
|
|||
|
Debug.LogError("下载游戏服务器列表错误!downloadFlag = " .. self.DownloadFlag);
|
|||
|
self.DownloadFlag = -1;
|
|||
|
Utils.ShowMsgBoxAndBtn(nil,"C_MSGBOX_OK","C_LOGIN_DOWNLOAD_SERVER_LIST_FAIL");
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--下载登陆服务器列表完成 -- 回调
|
|||
|
function ServerListSystem:OnLsServerDownloadFinish(wwwText)
|
|||
|
--关闭MessageBox
|
|||
|
GameCenter.MsgPromptSystem:CloseMsgBox();
|
|||
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_UPDATE_RECORDER_STEP, { CS.Thousandto.Update.Recorder.StepType.RequestServerList, 0, "Success" });
|
|||
|
|
|||
|
--如果www不为空,表示通过url进行下载的.
|
|||
|
if wwwText ~= nil and wwwText ~= "" then
|
|||
|
self.LoginServer = null;
|
|||
|
--去掉通配符
|
|||
|
--wwwText = Utils.ReplaceString(wwwText, "\"", "");
|
|||
|
--wwwText = Utils.ReplaceString(wwwText, "\\", "");
|
|||
|
self.LoginServer = ServerDataInfo:ParserLoginServerListJson(wwwText, SDKCacheData.ChannelID);
|
|||
|
Debug.Log("登陆服务器列表下载完毕!downloadFlag = " .. self.DownloadFlag);
|
|||
|
self.DownloadFlag = self.DownloadFlag | 1;
|
|||
|
if ((self.DownloadFlag & 3) == 3) then
|
|||
|
GameCenter.LoginSystem:ConnectLoginServer();
|
|||
|
self.DownloadFlag = -1;
|
|||
|
end
|
|||
|
else
|
|||
|
Debug.LogError("下载登陆服务器列表错误!downloadFlag = " .. self.DownloadFlag);
|
|||
|
self.DownloadFlag = -1;
|
|||
|
Utils.ShowMsgBoxAndBtn(nil,"C_MSGBOX_OK","C_LOGIN_DOWNLOAD_SERVER_LIST_FAIL");
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
]]
|
|||
|
return ServerListSystem;
|