修复不同时间多客户端连接游戏模组时可能产生的线程安全问题

This commit is contained in:
milimoe 2025-01-16 20:22:21 +08:00
parent 303c0baf9b
commit dcbcdd17fa
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
3 changed files with 26 additions and 10 deletions

View File

@ -4,6 +4,10 @@ using Oshima.FunGame.WebAPI.Controllers;
using Oshima.FunGame.OshimaModules; using Oshima.FunGame.OshimaModules;
using Oshima.FunGame.OshimaServers.Service; using Oshima.FunGame.OshimaServers.Service;
_ = new Milimoe.FunGame.Testing.Tests.CheckDLL();
Console.WriteLine();
_ = new Milimoe.FunGame.Testing.Tests.WebSocketTest(); _ = new Milimoe.FunGame.Testing.Tests.WebSocketTest();
CharacterModule cm = new(); CharacterModule cm = new();

View File

@ -16,11 +16,11 @@ namespace Milimoe.FunGame.Testing.Tests
Console.WriteLine(plugin + " is loaded."); Console.WriteLine(plugin + " is loaded.");
} }
Dictionary<string, string> plugindllsha512 = []; Dictionary<string, string> plugindllsha256 = [];
foreach (string pfp in PluginLoader.PluginFilePaths.Keys) foreach (string pfp in PluginLoader.PluginFilePaths.Keys)
{ {
string text = Encryption.FileSha512(PluginLoader.PluginFilePaths[pfp]); string text = Encryption.FileSha256(PluginLoader.PluginFilePaths[pfp]);
plugindllsha512.Add(pfp, text); plugindllsha256.Add(pfp, text);
Console.WriteLine(pfp + $" is {text}."); Console.WriteLine(pfp + $" is {text}.");
} }
@ -45,20 +45,26 @@ namespace Milimoe.FunGame.Testing.Tests
} }
} }
Dictionary<string, string> moduledllsha512 = []; Dictionary<string, string> moduledllsha256 = [];
foreach (string mfp in GameModuleLoader.ModuleFilePaths.Keys) foreach (string mfp in GameModuleLoader.ModuleFilePaths.Keys)
{ {
string text = Encryption.FileSha512(GameModuleLoader.ModuleFilePaths[mfp]); string text = Encryption.FileSha256(GameModuleLoader.ModuleFilePaths[mfp]);
moduledllsha512.Add(mfp, text); moduledllsha256.Add(mfp, text);
Console.WriteLine(mfp + $" is {text}."); Console.WriteLine(mfp + $" is {text}.");
} }
foreach (string moduledll in moduledllsha512.Keys) GameModuleLoader serverModels = GameModuleLoader.LoadGameModules(FunGameInfo.FunGame.FunGame_Server, []);
foreach (string moduledll in serverModels.ModuleServers.Keys)
{ {
string server = moduledllsha512[moduledll]; if (!serverModels.ModuleServers[moduledll].IsAnonymous)
if (plugindllsha512.TryGetValue(moduledll, out string? client) && client != "" && server == client)
{ {
Console.WriteLine(moduledll + $" is checked pass."); string server = Encryption.FileSha256(GameModuleLoader.ModuleFilePaths[moduledll]);
string client = moduledllsha256[moduledll];
if (server == client)
{
Console.WriteLine(moduledll + $" is checked pass.");
}
} }
} }
} }

View File

@ -66,6 +66,12 @@ namespace Milimoe.FunGame.Testing.Tests
data.Add("sc", 1); data.Add("sc", 1);
await HTTPClient.Send(SocketMessageType.AnonymousGameServer, OshimaGameModuleConstant.Anonymous, data); await HTTPClient.Send(SocketMessageType.AnonymousGameServer, OshimaGameModuleConstant.Anonymous, data);
} }
if (str == "sclist")
{
Dictionary<string, object> data = [];
data.Add("command", "sclist");
await HTTPClient.Send(SocketMessageType.AnonymousGameServer, OshimaGameModuleConstant.Anonymous, data);
}
if (str == "wsclose") if (str == "wsclose")
{ {
await HTTPClient.Send(SocketMessageType.EndGame); await HTTPClient.Send(SocketMessageType.EndGame);