连接服务器应该是使用Implement的地址

This commit is contained in:
milimoe 2023-12-12 00:36:02 +08:00
parent 21ffa8dfa2
commit 1d70b5019f
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
2 changed files with 17 additions and 17 deletions

View File

@ -107,13 +107,6 @@ namespace Milimoe.FunGame.Desktop.Controller
throw new CanNotConnectException(); throw new CanNotConnectException();
} }
Config.FunGame_isRetrying = true; Config.FunGame_isRetrying = true;
// 如果服务器地址为空需要获取一次地址
if (ip == "" || port <= 0)
{
(ip, port) = GetServerAddress();
RunTime.Session.Server_IP = ip;
RunTime.Session.Server_Port = port;
}
return true; return true;
} }
else else

View File

@ -79,7 +79,7 @@ namespace Milimoe.FunGame.Desktop.UI
ComboGameMap.SelectedIndex = 0; ComboGameMap.SelectedIndex = 0;
}); });
// 自动连接服务器 // 自动连接服务器
if (Config.FunGame_isAutoConnect) InvokeController_Connect(); if (Config.FunGame_isAutoConnect) InvokeController_Connect(true);
}); });
} }
@ -1194,7 +1194,7 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
if (ShowMessage(ShowMessageType.OKCancel, "你确定要退出登录吗?", "退出登录") == MessageResult.OK) if (ShowMessage(ShowMessageType.OKCancel, "你确定要退出登录吗?", "退出登录") == MessageResult.OK)
{ {
if (MainController == null || !await LogOut()) if (MainController == null || !await InvokeController_LogOut())
ShowMessage(ShowMessageType.Warning, "请求无效:退出登录失败!"); ShowMessage(ShowMessageType.Warning, "请求无效:退出登录失败!");
} }
}); });
@ -1671,7 +1671,7 @@ namespace Milimoe.FunGame.Desktop.UI
{ {
CurrentRetryTimes = -1; CurrentRetryTimes = -1;
Config.FunGame_isAutoRetry = true; Config.FunGame_isAutoRetry = true;
InvokeController_Connect(); InvokeController_Connect(true);
} }
break; break;
case Constant.FunGame_Disconnect: case Constant.FunGame_Disconnect:
@ -1681,7 +1681,7 @@ namespace Milimoe.FunGame.Desktop.UI
bool SuccessLogOut = false; bool SuccessLogOut = false;
TaskUtility.NewTask(async () => TaskUtility.NewTask(async () =>
{ {
if (await LogOut()) SuccessLogOut = true; if (await InvokeController_LogOut()) SuccessLogOut = true;
}).OnCompleted(() => }).OnCompleted(() =>
{ {
if (SuccessLogOut) InvokeController_Disconnect(); if (SuccessLogOut) InvokeController_Disconnect();
@ -1704,12 +1704,12 @@ namespace Milimoe.FunGame.Desktop.UI
int port; int port;
if (addr.Length < 2) if (addr.Length < 2)
{ {
ip = addr[0]; ip = addr[0].Trim();
port = 22222; port = 22222;
} }
else if (addr.Length < 3) else if (addr.Length < 3)
{ {
ip = addr[0]; ip = addr[0].Trim();
port = Convert.ToInt32(addr[1]); port = Convert.ToInt32(addr[1]);
} }
else else
@ -1760,16 +1760,23 @@ namespace Milimoe.FunGame.Desktop.UI
/// <summary> /// <summary>
/// 连接服务器,并处理事件 /// 连接服务器,并处理事件
/// </summary> /// </summary>
/// <param name="original">如果为false则使用上一次连接的服务器的地址</param>
/// <returns></returns> /// <returns></returns>
private void InvokeController_Connect() private void InvokeController_Connect(bool original = false)
{ {
if (original)
{
// 使用Implement中的原始服务器地址下面会重新获取
(RunTime.Session.Server_IP, RunTime.Session.Server_Port) = ("", 0);
}
ConnectEventArgs EventArgs = new(RunTime.Session.Server_IP, RunTime.Session.Server_Port); ConnectEventArgs EventArgs = new(RunTime.Session.Server_IP, RunTime.Session.Server_Port);
ConnectResult result = ConnectResult.CanNotConnect; ConnectResult result = ConnectResult.CanNotConnect;
TaskUtility.NewTask(() => TaskUtility.NewTask(() =>
{ {
if (RunTime.Controller != null) // 如果服务器地址为空需要获取一次地址
if (RunTime.Controller != null && RunTime.Session.Server_IP.Trim() == "" && RunTime.Session.Server_Port == 0)
{ {
(RunTime.Session.Server_IP, RunTime.Session.Server_Port) = RunTime.Controller.GetServerAddress(); (RunTime.Session.Server_IP, RunTime.Session.Server_Port) = RunTime.Controller.GetServerAddress();
} }
@ -1823,7 +1830,7 @@ namespace Milimoe.FunGame.Desktop.UI
if (Usercfg.LoginUser.Id != 0) if (Usercfg.LoginUser.Id != 0)
{ {
await LogOut(); await InvokeController_LogOut();
} }
result = RunTime.Controller?.Disconnect() ?? false; result = RunTime.Controller?.Disconnect() ?? false;
@ -2035,7 +2042,7 @@ namespace Milimoe.FunGame.Desktop.UI
/// 退出登录 /// 退出登录
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task<bool> LogOut() public async Task<bool> InvokeController_LogOut()
{ {
GeneralEventArgs EventArgs = new(); GeneralEventArgs EventArgs = new();
bool result = false; bool result = false;