修改一些变量的命名和注释

This commit is contained in:
Mili 2022-11-25 20:12:48 +08:00
parent e131fc44f6
commit 9748f3138a
6 changed files with 39 additions and 42 deletions

View File

@ -24,10 +24,10 @@ namespace Milimoe.FunGame.Core.Library.Constant
public class SocketSet public class SocketSet
{ {
public static int MaxRetryTimes { get; } = 20; public const int MaxRetryTimes = 20;
public static int MaxConnection_1C2G { get; } = 10; public const int MaxConnection_1C2G = 10;
public static int MaxConnection_General { get; } = 20; public const int MaxConnection_General = 20;
public static int MaxConnection_4C4G { get; } = 40; public const int MaxConnection_4C4G = 40;
public const string Unknown = "Unknown"; public const string Unknown = "Unknown";
public const string Connect = "Connect"; public const string Connect = "Connect";

View File

@ -9,16 +9,9 @@ namespace Milimoe.FunGame.Core.Library.Exception
{ {
public static class ExceptionHelper public static class ExceptionHelper
{ {
public static string GetStackTrace(this System.Exception e) public static string GetErrorInfo(this System.Exception e)
{ {
if (e.Message != null && e.Message != "") return (e.InnerException != null) ? $"InnerExceoption: {e.InnerException}\n{e}" : e.ToString();
{
return $"ERROR: {e.Message}\n{e.StackTrace}";
}
else
{
return $"ERROR: \n{e.StackTrace}";
}
} }
} }
} }

View File

@ -26,9 +26,9 @@ namespace Milimoe.FunGame.Core.Library.Exception
e = new System.Exception(Name); e = new System.Exception(Name);
} }
public string GetStackTrace() public string GetErrorInfo()
{ {
return e.GetStackTrace(); return e.GetErrorInfo();
} }
} }
} }

View File

@ -12,7 +12,7 @@ namespace Milimoe.FunGame.Core.Service
/// <summary> /// <summary>
/// 最大接受的线程数量 /// 最大接受的线程数量
/// </summary> /// </summary>
private int MaxConnection { get; } private int MaxTask { get; }
/// <summary> /// <summary>
/// 可参与高并发的字典,但添加效率较低 /// 可参与高并发的字典,但添加效率较低
@ -22,14 +22,14 @@ namespace Milimoe.FunGame.Core.Service
/// <summary> /// <summary>
/// Init ThreadManager /// Init ThreadManager
/// </summary> /// </summary>
/// <param name="MaxConnection">MaxConnection</param> /// <param name="MaxTask">MaxTask</param>
internal ThreadManager(int MaxConnection = 0) internal ThreadManager(int MaxTask = 0)
{ {
if (MaxConnection <= 0) if (MaxTask <= 0)
this.MaxConnection = Library.Constant.General.MaxTask_General; this.MaxTask = Library.Constant.General.MaxTask_General;
else else
{ {
this.MaxConnection = MaxConnection; this.MaxTask = MaxTask;
} }
} }
@ -54,7 +54,7 @@ namespace Milimoe.FunGame.Core.Service
/// <returns>True操作成功</returns> /// <returns>True操作成功</returns>
internal bool Add(string name, Task t) internal bool Add(string name, Task t)
{ {
if (Threads.Count + 1 > MaxConnection) return false; if (Threads.Count + 1 > MaxTask) return false;
return Threads.TryAdd(name, t); return Threads.TryAdd(name, t);
} }

View File

@ -38,7 +38,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
Main?.GetMessage(e.GetStackTrace()); Main?.GetMessage(e.GetErrorInfo());
} }
return false; return false;
} }
@ -51,7 +51,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
Main?.GetMessage(e.GetStackTrace()); Main?.GetMessage(e.GetErrorInfo());
} }
return false; return false;
} }
@ -64,7 +64,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
Main?.GetMessage(e.GetStackTrace()); Main?.GetMessage(e.GetErrorInfo());
} }
} }
@ -92,7 +92,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
Main?.GetMessage(e.GetStackTrace(), false); Main?.GetMessage(e.GetErrorInfo(), false);
} }
return false; return false;
@ -160,7 +160,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
Main?.GetMessage(e.GetStackTrace(), false); Main?.GetMessage(e.GetErrorInfo(), false);
} }
return ConnectResult.ConnectFailed; return ConnectResult.ConnectFailed;
@ -183,7 +183,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
Main.GetMessage(e.GetStackTrace(), false); Main.GetMessage(e.GetErrorInfo(), false);
return false; return false;
} }
return true; return true;
@ -259,7 +259,7 @@ namespace Milimoe.FunGame.Desktop.Model
catch (Exception e) catch (Exception e)
{ {
// 报错中断服务器连接 // 报错中断服务器连接
Main?.GetMessage(e.GetStackTrace(), false); Main?.GetMessage(e.GetErrorInfo(), false);
Main?.UpdateUI(MainControllerSet.Disconnected); Main?.UpdateUI(MainControllerSet.Disconnected);
Close(); Close();
} }
@ -292,7 +292,7 @@ namespace Milimoe.FunGame.Desktop.Model
// 返回的objs是该Login的User对象的各个属性 // 返回的objs是该Login的User对象的各个属性
if (objs.Length > 0) msg = (string)objs[0]; if (objs.Length > 0) msg = (string)objs[0];
Main?.GetMessage(msg); Main?.GetMessage(msg);
Main?.UpdateUI(MainControllerSet.SetUser, true, TimeType.TimeOnly, new object[] { Factory.New<User>(msg) }); Main?.UpdateUI(MainControllerSet.SetUser, new object[] { Factory.New<User>(msg) });
} }
private void SocketHandle_Disconnect(object[] objs) private void SocketHandle_Disconnect(object[] objs)

View File

@ -90,7 +90,7 @@ namespace Milimoe.FunGame.Desktop.UI
/// <param name="time"></param> /// <param name="time"></param>
/// <param name="timetype"></param> /// <param name="timetype"></param>
/// <param name="objs"></param> /// <param name="objs"></param>
public void UpdateUI(string? updatetype, bool time = true, TimeType timetype = TimeType.TimeOnly, object[]? objs = null) public void UpdateUI(string? updatetype, object[]? objs = null)
{ {
void action() void action()
{ {
@ -164,16 +164,10 @@ namespace Milimoe.FunGame.Desktop.UI
Thread.Sleep(5000); Thread.Sleep(5000);
if (Others.Config.FunGame_isAutoRetry) MainController?.Do<object>(MainControllerSet.Connect); // 再次判断是否开启自动重连 if (Others.Config.FunGame_isAutoRetry) MainController?.Do<object>(MainControllerSet.Connect); // 再次判断是否开启自动重连
}); });
if (time) WritelnSystemInfo("连接服务器失败5秒后自动尝试重连。");
WritelnGameInfo(DateTimeUtility.GetDateTimeToString(timetype) + "\n连接服务器失败5秒后自动尝试重连。");
else
WritelnGameInfo("连接服务器失败5秒后自动尝试重连。");
} }
else else
if (time) WritelnSystemInfo("无法连接至服务器,请检查你的网络连接。");
WritelnGameInfo(DateTimeUtility.GetDateTimeToString(timetype) + "\n无法连接至服务器请检查你的网络连接。");
else
WritelnGameInfo("无法连接至服务器,请检查你的网络连接。");
break; break;
case Others.MainControllerSet.Disconnect: case Others.MainControllerSet.Disconnect:
@ -235,7 +229,7 @@ namespace Milimoe.FunGame.Desktop.UI
} }
catch (Exception e) catch (Exception e)
{ {
WritelnGameInfo(e.GetStackTrace()); WritelnGameInfo(e.GetErrorInfo());
UpdateUI(Others.MainControllerSet.SetRed); UpdateUI(Others.MainControllerSet.SetRed);
} }
} }
@ -260,7 +254,7 @@ namespace Milimoe.FunGame.Desktop.UI
} }
catch (Exception e) catch (Exception e)
{ {
WritelnGameInfo(e.GetStackTrace()); WritelnGameInfo(e.GetErrorInfo());
} }
}; };
InvokeUpdateUI(action); InvokeUpdateUI(action);
@ -307,7 +301,7 @@ namespace Milimoe.FunGame.Desktop.UI
} }
catch (Exception e) catch (Exception e)
{ {
WritelnGameInfo(e.GetStackTrace()); WritelnGameInfo(e.GetErrorInfo());
} }
} }
@ -378,6 +372,16 @@ namespace Milimoe.FunGame.Desktop.UI
} }
} }
/// <summary>
/// 向消息队列输出一行系统信息
/// </summary>
/// <param name="msg"></param>
private void WritelnSystemInfo(string msg)
{
msg = DateTimeUtility.GetDateTimeToString(TimeType.TimeOnly) + " >> " + msg;
WritelnGameInfo(msg);
}
/// <summary> /// <summary>
/// 在大厅中,设置按钮的显示和隐藏 /// 在大厅中,设置按钮的显示和隐藏
/// </summary> /// </summary>