diff --git a/Api/Transmittal/DataRequest.cs b/Api/Transmittal/DataRequest.cs
index 90b1a5b..083eb2b 100644
--- a/Api/Transmittal/DataRequest.cs
+++ b/Api/Transmittal/DataRequest.cs
@@ -70,13 +70,13 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
/// 插件则使用 中的 创建一个新的请求
/// 此数据请求只能调用异步方法 请求数据
///
- ///
+ ///
///
///
///
- internal DataRequest(HTTPClient WebSocket, DataRequestType RequestType, bool IsLongRunning = false, SocketRuntimeType RuntimeType = SocketRuntimeType.Client)
+ internal DataRequest(HTTPClient HTTPClient, DataRequestType RequestType, bool IsLongRunning = false, SocketRuntimeType RuntimeType = SocketRuntimeType.Client)
{
- Worker = new(WebSocket, RequestType, Guid.NewGuid(), IsLongRunning, RuntimeType);
+ Worker = new(HTTPClient, RequestType, Guid.NewGuid(), IsLongRunning, RuntimeType);
}
///
@@ -99,13 +99,13 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
/// 此构造方法是给 提供的
/// 此数据请求只能调用异步方法 请求数据
///
- ///
+ ///
///
///
///
- internal DataRequest(HTTPClient WebSocket, GamingType GamingType, bool IsLongRunning = false, SocketRuntimeType RuntimeType = SocketRuntimeType.Client)
+ internal DataRequest(HTTPClient Client, GamingType GamingType, bool IsLongRunning = false, SocketRuntimeType RuntimeType = SocketRuntimeType.Client)
{
- GamingWorker = new(WebSocket, GamingType, Guid.NewGuid(), IsLongRunning, RuntimeType);
+ GamingWorker = new(Client, GamingType, Guid.NewGuid(), IsLongRunning, RuntimeType);
}
///
@@ -194,7 +194,7 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
public string Error => _Error;
private readonly Socket? Socket = null;
- private readonly HTTPClient? WebSocket = null;
+ private readonly HTTPClient? HTTPClient = null;
private readonly DataRequestType RequestType = DataRequestType.UnKnown;
private readonly Guid RequestID = Guid.Empty;
private readonly bool IsLongRunning = false;
@@ -212,9 +212,9 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
this.RuntimeType = RuntimeType;
}
- public SocketRequest(HTTPClient? WebSocket, DataRequestType RequestType, Guid RequestID, bool IsLongRunning = false, SocketRuntimeType RuntimeType = SocketRuntimeType.Client) : base(WebSocket)
+ public SocketRequest(HTTPClient? HTTPClient, DataRequestType RequestType, Guid RequestID, bool IsLongRunning = false, SocketRuntimeType RuntimeType = SocketRuntimeType.Client) : base(HTTPClient)
{
- this.WebSocket = WebSocket;
+ this.HTTPClient = HTTPClient;
this.RequestType = RequestType;
this.RequestID = RequestID;
this.IsLongRunning = IsLongRunning;
@@ -236,7 +236,7 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
{
WaitForWorkDone();
}
- else if (WebSocket != null)
+ else if (HTTPClient != null)
{
throw new AsyncSendException();
}
@@ -265,7 +265,7 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
{
await WaitForWorkDoneAsync();
}
- else if (WebSocket != null && await WebSocket.Send(SocketMessageType.DataRequest, RequestType, RequestID, RequestData) == SocketResult.Success)
+ else if (HTTPClient != null && await HTTPClient.Send(SocketMessageType.DataRequest, RequestType, RequestID, RequestData) == SocketResult.Success)
{
await WaitForWorkDoneAsync();
}
@@ -317,7 +317,7 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
public string Error => _Error;
private readonly Socket? Socket = null;
- private readonly HTTPClient? WebSocket = null;
+ private readonly HTTPClient? HTTPClient = null;
private readonly GamingType GamingType = GamingType.None;
private readonly Guid RequestID = Guid.Empty;
private readonly bool IsLongRunning = false;
@@ -335,9 +335,9 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
this.RuntimeType = RuntimeType;
}
- public GamingRequest(HTTPClient? WebSocket, GamingType GamingType, Guid RequestID, bool IsLongRunning = false, SocketRuntimeType RuntimeType = SocketRuntimeType.Client) : base(WebSocket)
+ public GamingRequest(HTTPClient? HTTPClient, GamingType GamingType, Guid RequestID, bool IsLongRunning = false, SocketRuntimeType RuntimeType = SocketRuntimeType.Client) : base(HTTPClient)
{
- this.WebSocket = WebSocket;
+ this.HTTPClient = HTTPClient;
this.GamingType = GamingType;
this.RequestID = RequestID;
this.IsLongRunning = IsLongRunning;
@@ -359,7 +359,7 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
{
WaitForWorkDone();
}
- else if (WebSocket != null)
+ else if (HTTPClient != null)
{
throw new AsyncSendException();
}
@@ -388,7 +388,7 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
{
await WaitForWorkDoneAsync();
}
- else if (WebSocket != null && await WebSocket.Send(SocketMessageType.GamingRequest, GamingType, RequestID, RequestData) == SocketResult.Success)
+ else if (HTTPClient != null && await HTTPClient.Send(SocketMessageType.GamingRequest, GamingType, RequestID, RequestData) == SocketResult.Success)
{
await WaitForWorkDoneAsync();
}
diff --git a/Api/Utility/General.cs b/Api/Utility/General.cs
index 87e6ffb..bd54cc8 100644
--- a/Api/Utility/General.cs
+++ b/Api/Utility/General.cs
@@ -443,7 +443,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
byte[] key_bytes = General.DefaultEncoding.GetBytes(key);
HMACSHA512 hmacsha512 = new(key_bytes);
byte[] hash_bytes = hmacsha512.ComputeHash(text_bytes);
- string hmac = BitConverter.ToString(hash_bytes).Replace("-", "");
+ string hmac = Convert.ToHexString(hash_bytes);
return hmac.ToLower();
}
@@ -452,12 +452,12 @@ namespace Milimoe.FunGame.Core.Api.Utility
///
/// 要计算哈希值的文件路径
/// 文件的 SHA-256 哈希值
- public static string FileSha512(string file_path)
+ public static string FileSha256(string file_path)
{
using SHA256 sha256 = SHA256.Create();
using FileStream stream = File.OpenRead(file_path);
byte[] hash = sha256.ComputeHash(stream);
- return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
+ return Convert.ToHexStringLower(hash);
}
///
@@ -471,7 +471,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
byte[] plain = General.DefaultEncoding.GetBytes(plain_text);
using RSACryptoServiceProvider rsa = new();
rsa.FromXmlString(plublic_key);
- byte[] encrypted = rsa.Encrypt(plain, false);
+ byte[] encrypted = rsa.Encrypt(plain, true);
return Convert.ToBase64String(encrypted);
}
@@ -486,7 +486,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
byte[] secret = Convert.FromBase64String(secret_text);
using RSACryptoServiceProvider rsa = new();
rsa.FromXmlString(private_key);
- byte[] decrypted = rsa.Decrypt(secret, false);
+ byte[] decrypted = rsa.Decrypt(secret, true);
return General.DefaultEncoding.GetString(decrypted);
}
}
diff --git a/Api/Utility/TextReader.cs b/Api/Utility/TextReader.cs
index 8768534..6ed1091 100644
--- a/Api/Utility/TextReader.cs
+++ b/Api/Utility/TextReader.cs
@@ -76,12 +76,16 @@ namespace Milimoe.FunGame.Core.Api.Utility
WriteINI("Account", "AutoKey", "");
break;
case FunGameInfo.FunGame.FunGame_Server:
+ /**
+ * Console
+ */
+ WriteINI("Console", "LogLevel", "INFO");
/**
* Server
*/
WriteINI("Server", "Name", "FunGame Server");
WriteINI("Server", "Password", "");
- WriteINI("Server", "Describe", "Just Another FunGame Server.");
+ WriteINI("Server", "Description", "Just Another FunGame Server.");
WriteINI("Server", "Notice", "This is the FunGame Server's Notice.");
WriteINI("Server", "Key", "");
WriteINI("Server", "Status", "1");
diff --git a/Controller/BaseAddonController.cs b/Controller/BaseAddonController.cs
index 4824c47..88497da 100644
--- a/Controller/BaseAddonController.cs
+++ b/Controller/BaseAddonController.cs
@@ -1,5 +1,6 @@
using Milimoe.FunGame.Core.Interface.Addons;
using Milimoe.FunGame.Core.Library.Common.Addon;
+using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Controller
{
@@ -17,7 +18,7 @@ namespace Milimoe.FunGame.Core.Controller
///
/// 输出系统消息
///
- protected Action MaskMethod_WriteLine { get; set; }
+ protected Action MaskMethod_WriteLine { get; set; }
///
/// 输出错误消息
@@ -28,8 +29,10 @@ namespace Milimoe.FunGame.Core.Controller
/// 输出系统消息
///
///
+ ///
+ ///
///
- public void WriteLine(string msg) => MaskMethod_WriteLine(msg);
+ public void WriteLine(string msg, LogLevel level = LogLevel.Info, bool useLevel = true) => MaskMethod_WriteLine(Addon.Name, msg, level, useLevel);
///
/// 输出错误消息
@@ -46,7 +49,7 @@ namespace Milimoe.FunGame.Core.Controller
public BaseAddonController(IAddon addon, Dictionary delegates)
{
Addon = (T)addon;
- if (delegates.TryGetValue("WriteLine", out object? value)) MaskMethod_WriteLine = value != null ? (Action)value : new(DefaultPrint);
+ if (delegates.TryGetValue("WriteLine", out object? value)) MaskMethod_WriteLine = value != null ? (Action)value : new(DefaultPrint);
if (delegates.TryGetValue("Error", out value)) MaskMethod_Error = value != null ? (Action)value : new(DefaultPrint);
MaskMethod_WriteLine ??= new(DefaultPrint);
MaskMethod_Error ??= new(DefaultPrint);
@@ -55,15 +58,22 @@ namespace Milimoe.FunGame.Core.Controller
///
/// 默认的输出错误消息方法
///
+ ///
///
+ ///
+ ///
///
- private void DefaultPrint(string msg) => Console.Write("\r" + msg + "\n\r> ");
+ private void DefaultPrint(string name, string msg, LogLevel level = LogLevel.Info, bool useLevel = true)
+ {
+ DateTime now = DateTime.Now;
+ Console.Write("\r" + now.AddMilliseconds(-now.Millisecond).ToString() + $" {CommonSet.GetLogLevelPrefix(level)}/[Addon] {Addon.Name}:\n\r> ");
+ }
///
/// 输出错误消息
///
///
///
- private void DefaultPrint(Exception e) => DefaultPrint(e.ToString());
+ private void DefaultPrint(Exception e) => DefaultPrint(Addon.Name, e.ToString(), LogLevel.Error);
}
}
diff --git a/Controller/RunTimeController.cs b/Controller/RunTimeController.cs
index 420d9c0..b70b1d6 100644
--- a/Controller/RunTimeController.cs
+++ b/Controller/RunTimeController.cs
@@ -21,7 +21,7 @@ namespace Milimoe.FunGame.Core.Controller
///
/// 与服务器的连接套接字实例(WebSocket)
///
- public HTTPClient? WebSocket => _WebSocket;
+ public HTTPClient? HTTPClient => _HTTPClient;
///
/// 套接字是否已经连接
@@ -41,7 +41,7 @@ namespace Milimoe.FunGame.Core.Controller
///
/// 用于类内赋值
///
- protected HTTPClient? _WebSocket;
+ protected HTTPClient? _HTTPClient;
///
/// 是否正在接收服务器信息
@@ -204,6 +204,7 @@ namespace Milimoe.FunGame.Core.Controller
}
}
});
+ _Socket.ConnectionLost += Error;
}
}
}
@@ -231,12 +232,12 @@ namespace Milimoe.FunGame.Core.Controller
string serverName = "";
string notice = "";
- _WebSocket?.Close();
- _WebSocket = await HTTPClient.Connect(address, ssl, port, subUrl, connectArgs.Cast