forked from project-redbud/FunGame-Core
修复不能自动重连的BUG
This commit is contained in:
parent
c82eafb294
commit
403ed7d923
@ -8,6 +8,7 @@ using Milimoe.FunGame.Core.Entity;
|
|||||||
using Milimoe.FunGame.Core.Library.Common.Event;
|
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
using Milimoe.FunGame.Core.Library.Exception;
|
using Milimoe.FunGame.Core.Library.Exception;
|
||||||
|
using Milimoe.FunGame.Desktop.Controller;
|
||||||
using Milimoe.FunGame.Desktop.Library.Component;
|
using Milimoe.FunGame.Desktop.Library.Component;
|
||||||
using Milimoe.FunGame.Desktop.Others;
|
using Milimoe.FunGame.Desktop.Others;
|
||||||
using Milimoe.FunGame.Desktop.UI;
|
using Milimoe.FunGame.Desktop.UI;
|
||||||
@ -97,15 +98,13 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConnectResult Connect()
|
public ConnectResult Connect()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (Others.Constant.SERVER_IPADRESS == "" || Others.Constant.SERVER_PORT <= 0)
|
if (Others.Constant.SERVER_IPADRESS == "" || Others.Constant.SERVER_PORT <= 0)
|
||||||
{
|
{
|
||||||
ShowMessage.ErrorMessage("查找可用的服务器失败!");
|
ShowMessage.ErrorMessage("查找可用的服务器失败!");
|
||||||
return ConnectResult.FindServerFailed;
|
return ConnectResult.FindServerFailed;
|
||||||
}
|
}
|
||||||
while (true)
|
try
|
||||||
{
|
{
|
||||||
if (Others.Config.FunGame_isRetrying)
|
if (Others.Config.FunGame_isRetrying)
|
||||||
{
|
{
|
||||||
@ -145,7 +144,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
}
|
}
|
||||||
Socket?.Close();
|
Socket?.Close();
|
||||||
Config.FunGame_isRetrying = false;
|
Config.FunGame_isRetrying = false;
|
||||||
return ConnectResult.ConnectFailed;
|
throw new Exception("无法连接至服务器,请检查网络并重启游戏再试。");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -154,14 +153,22 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
return ConnectResult.CanNotConnect;
|
return ConnectResult.CanNotConnect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Main?.GetMessage(e.GetErrorInfo(), false);
|
Main?.GetMessage(e.GetErrorInfo(), false);
|
||||||
Config.FunGame_isRetrying = false;
|
Config.FunGame_isRetrying = false;
|
||||||
|
if (Config.FunGame_isAutoRetry && Main!.CurrentRetryTimes <= Main!.MaxRetryTimes)
|
||||||
|
{
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
if (Others.Config.FunGame_isAutoRetry) Connect(); // 再次判断是否开启自动重连
|
||||||
|
});
|
||||||
|
Main?.GetMessage("连接服务器失败,5秒后自动尝试重连。");
|
||||||
}
|
}
|
||||||
|
else return ConnectResult.ConnectFailed;
|
||||||
return ConnectResult.ConnectFailed;
|
}
|
||||||
|
return ConnectResult.CanNotConnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Close()
|
public bool Close()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user