From 09ecda02be1d7e558833860773e9618ecbedd588 Mon Sep 17 00:00:00 2001 From: milimoe Date: Thu, 16 Jan 2025 00:59:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=20OshimaCore=20=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=EF=BC=8C=E5=88=86=E7=A6=BB=E5=87=BA=20WebAPI=20=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OshimaCore/Configs/Ignore.cs | 1 + OshimaCore/Configs/SayNo.cs | 1 + OshimaCore/{Configs => }/OSMCore.cs | 16 ++- OshimaCore/OshimaCore.csproj | 50 +++----- OshimaGameModule.sln | 8 +- OshimaServers/AnonymousServer.cs | 118 +++++++++++++++++- OshimaServers/OshimaServers.csproj | 1 + .../Constant/Statics.cs | 2 +- .../Controllers/FunGameController.cs | 4 +- .../Controllers/QQController.cs | 4 +- .../Controllers/TestController.cs | 4 +- .../Controllers/UserDailyController.cs | 6 +- {OshimaCore => OshimaWebAPI}/Models/BindQQ.cs | 2 +- .../Models/UserDaily.cs | 2 +- {OshimaCore => OshimaWebAPI}/OshimaWebAPI.cs | 13 +- OshimaWebAPI/OshimaWebAPI.csproj | 39 ++++++ .../Properties/launchSettings.json | 0 .../Utils/UserDailyUtil.cs | 4 +- 18 files changed, 215 insertions(+), 60 deletions(-) rename OshimaCore/{Configs => }/OSMCore.cs (65%) rename {OshimaCore => OshimaWebAPI}/Constant/Statics.cs (80%) rename {OshimaCore => OshimaWebAPI}/Controllers/FunGameController.cs (99%) rename {OshimaCore => OshimaWebAPI}/Controllers/QQController.cs (96%) rename {OshimaCore => OshimaWebAPI}/Controllers/TestController.cs (97%) rename {OshimaCore => OshimaWebAPI}/Controllers/UserDailyController.cs (94%) rename {OshimaCore => OshimaWebAPI}/Models/BindQQ.cs (79%) rename {OshimaCore => OshimaWebAPI}/Models/UserDaily.cs (84%) rename {OshimaCore => OshimaWebAPI}/OshimaWebAPI.cs (93%) create mode 100644 OshimaWebAPI/OshimaWebAPI.csproj rename {OshimaCore => OshimaWebAPI}/Properties/launchSettings.json (100%) rename {OshimaCore => OshimaWebAPI}/Utils/UserDailyUtil.cs (97%) diff --git a/OshimaCore/Configs/Ignore.cs b/OshimaCore/Configs/Ignore.cs index 887ada4..d394c01 100644 --- a/OshimaCore/Configs/Ignore.cs +++ b/OshimaCore/Configs/Ignore.cs @@ -43,6 +43,7 @@ namespace Oshima.Core.Configs { ReverseAtIgnore = (List)value; } + SaveConfig(); } public static void SaveConfig() diff --git a/OshimaCore/Configs/SayNo.cs b/OshimaCore/Configs/SayNo.cs index f41cb57..ebfb43f 100644 --- a/OshimaCore/Configs/SayNo.cs +++ b/OshimaCore/Configs/SayNo.cs @@ -84,6 +84,7 @@ namespace Oshima.Core.Configs } } } + SaveConfig(); } public static void SaveConfig() diff --git a/OshimaCore/Configs/OSMCore.cs b/OshimaCore/OSMCore.cs similarity index 65% rename from OshimaCore/Configs/OSMCore.cs rename to OshimaCore/OSMCore.cs index 5def975..fa4cf0a 100644 --- a/OshimaCore/Configs/OSMCore.cs +++ b/OshimaCore/OSMCore.cs @@ -1,12 +1,13 @@ using System.Globalization; using System.Reflection; +using Oshima.Core.Configs; -namespace Oshima.Core.Configs +namespace Oshima.Core { public class OSMCore { public const string version = "v1.0"; - public const string version2 = "Beta5"; + public const string version2 = "Rebirth"; public static string Info => $"OSM Core {version} {version2}\r\nAuthor: Milimoe\r\nBuilt on {GetBuiltTime(Assembly.GetExecutingAssembly().Location)}\r\nSee: https://github.com/milimoe"; @@ -20,5 +21,16 @@ namespace Oshima.Core.Configs return $"{month}. {day}, {lastWriteTime.Year} {time}"; } + + public static void InitOSMCore() + { + GeneralSettings.LoadSetting(); + GeneralSettings.SaveConfig(); + QQOpenID.LoadConfig(); + QQOpenID.SaveConfig(); + Daily.InitDaily(); + SayNo.InitSayNo(); + Ignore.InitIgnore(); + } } } diff --git a/OshimaCore/OshimaCore.csproj b/OshimaCore/OshimaCore.csproj index 4ac21a5..1496492 100644 --- a/OshimaCore/OshimaCore.csproj +++ b/OshimaCore/OshimaCore.csproj @@ -1,37 +1,27 @@  - - net9.0 - enable - enable - Oshima.Core - OshimaCore - ..\bin\ - + + net9.0 + enable + enable + Oshima.Core + Oshima Studios + - - 1701;1702;IDE0130;CA1822;IDE1006 - embedded - + + 1701;1702;IDE0130 + embedded + - - 1701;1702;IDE0130;CA1822;IDE1006 - embedded - + + 1701;1702;IDE0130 + embedded + - - - - - - - - - - - - ..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll - - + + + ..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll + + diff --git a/OshimaGameModule.sln b/OshimaGameModule.sln index d1951a2..b0c6cb1 100644 --- a/OshimaGameModule.sln +++ b/OshimaGameModule.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OshimaModes", "OshimaModes\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OshimaServers", "OshimaServers\OshimaServers.csproj", "{E8C696E0-96E4-45C3-8CB4-A02145179590}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OshimaCore", "OshimaCore\OshimaCore.csproj", "{978B06DE-2AD8-4DC4-B53A-D744781FDEA1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OshimaWebAPI", "OshimaWebAPI\OshimaWebAPI.csproj", "{978B06DE-2AD8-4DC4-B53A-D744781FDEA1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OshimaCore", "OshimaCore\OshimaCore.csproj", "{E0E709F9-755C-4BE7-915C-9B0A8CBBBF34}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {978B06DE-2AD8-4DC4-B53A-D744781FDEA1}.Debug|Any CPU.Build.0 = Debug|Any CPU {978B06DE-2AD8-4DC4-B53A-D744781FDEA1}.Release|Any CPU.ActiveCfg = Release|Any CPU {978B06DE-2AD8-4DC4-B53A-D744781FDEA1}.Release|Any CPU.Build.0 = Release|Any CPU + {E0E709F9-755C-4BE7-915C-9B0A8CBBBF34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0E709F9-755C-4BE7-915C-9B0A8CBBBF34}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0E709F9-755C-4BE7-915C-9B0A8CBBBF34}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0E709F9-755C-4BE7-915C-9B0A8CBBBF34}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/OshimaServers/AnonymousServer.cs b/OshimaServers/AnonymousServer.cs index cfd1fe7..689e34b 100644 --- a/OshimaServers/AnonymousServer.cs +++ b/OshimaServers/AnonymousServer.cs @@ -1,8 +1,13 @@ -using Milimoe.FunGame.Core.Entity; +using System.Data; +using Milimoe.FunGame.Core.Api.Transmittal; +using Milimoe.FunGame.Core.Api.Utility; +using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Interface.Base; using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Constant; +using Oshima.Core; using Oshima.FunGame.OshimaModules; +using Oshima.FunGame.OshimaServers.Service; namespace Oshima.FunGame.OshimaServers { @@ -73,6 +78,15 @@ namespace Oshima.FunGame.OshimaServers Controller.WriteLine($"{model.GetClientName()} 从匿名服务器断开", LogLevel.Info); } + public override void AfterLoad(params object[] args) + { + Controller.NewSQLHelper(); + Controller.NewMailSender(); + OSMCore.InitOSMCore(); + FunGameService.InitFunGame(); + FunGameSimulation.InitFunGameSimulation(); + } + /// /// 向客户端推送事件 /// @@ -100,15 +114,115 @@ namespace Oshima.FunGame.OshimaServers Controller.WriteLine("接收匿名服务器消息", LogLevel.Debug); // 根据服务器和客户端的数据传输约定,自行处理 data,并返回。 + string msg = ""; if (data.Count > 0) { + string command = NetworkUtility.JsonDeserializeFromDictionary(data, "command") ?? ""; + switch (command.Trim().ToLower()) + { + case "scadd": + msg = SCAdd(data); + break; + case "sclist": + msg = SCList(); + break; + case "att": + break; + default: + msg = "匿名服务器已经收到消息了"; + break; + } await Task.Delay(1); } - result.Add("msg", "匿名服务器已经收到消息了"); + if (msg.Trim() != "") + { + result.Add("msg", msg); + } return result; } + public string SCAdd(Dictionary data) + { + string result = ""; + + SQLHelper? sql = Factory.OpenFactory.GetSQLHelper(); + if (sql != null) + { + using (sql) + { + try + { + long qq = NetworkUtility.JsonDeserializeFromDictionary(data, "qq"); + double sc = NetworkUtility.JsonDeserializeFromDictionary(data, "sc"); + sql.NewTransaction(); + sql.Script = "select * from saints where qq = @qq"; + sql.Parameters.Add("qq", qq); + sql.ExecuteDataSet(); + sql.Parameters.Add("sc", sc); + sql.Parameters.Add("qq", qq); + if (sql.Success) + { + sql.Script = "update saints set sc = sc + @sc where qq = @qq"; + } + else + { + sql.Script = "insert into saints(qq, sc) values(@qq, @sc)"; + } + sql.Execute(); + if (sql.Success) + { + Controller.WriteLine($"用户 {qq} 的圣人点数增加了 {sc}", LogLevel.Debug); + sql.Commit(); + } + else + { + sql.Rollback(); + } + } + catch (Exception e) + { + result = e.ToString(); + sql.Rollback(); + } + finally + { + sql.Close(); + } + } + } + else result = "无法调用此接口:SQL 服务不可用。"; + + return result; + } + + public string SCList() + { + string result = "☆--- OSMTV 圣人排行榜 TOP10 ---☆\r\n统计时间:" + DateTime.Now.ToString(General.GeneralDateTimeFormatChinese); + + SQLHelper? sql = Controller.SQLHelper; + if (sql != null) + { + sql.Script = "select * from saints order by sc desc"; + sql.ExecuteDataSet(); + if (sql.Success && sql.DataSet.Tables.Count > 0) + { + int count = 0; + foreach (DataRow dr in sql.DataSet.Tables[0].Rows) + { + count++; + if (count > 10) break; + long qq = Convert.ToInt64(dr["qq"]); + double sc = Convert.ToDouble(dr["sc"]); + result += $"{count}. 用户:{qq},圣人点数:{sc} 分\r\n"; + } + } + } + else result = "无法调用此接口:SQL 服务不可用。"; + + return result.Trim(); + } + public override Task> GamingMessageHandler(string username, GamingType type, Dictionary data) { throw new NotImplementedException(); diff --git a/OshimaServers/OshimaServers.csproj b/OshimaServers/OshimaServers.csproj index 0996f54..35d094e 100644 --- a/OshimaServers/OshimaServers.csproj +++ b/OshimaServers/OshimaServers.csproj @@ -18,6 +18,7 @@ + diff --git a/OshimaCore/Constant/Statics.cs b/OshimaWebAPI/Constant/Statics.cs similarity index 80% rename from OshimaCore/Constant/Statics.cs rename to OshimaWebAPI/Constant/Statics.cs index d47f004..73c05d9 100644 --- a/OshimaCore/Constant/Statics.cs +++ b/OshimaWebAPI/Constant/Statics.cs @@ -1,6 +1,6 @@ using Milimoe.FunGame.Core.Library.Common.Addon; -namespace Oshima.Core.Constant +namespace Oshima.FunGame.WebAPI.Constant { public class Statics { diff --git a/OshimaCore/Controllers/FunGameController.cs b/OshimaWebAPI/Controllers/FunGameController.cs similarity index 99% rename from OshimaCore/Controllers/FunGameController.cs rename to OshimaWebAPI/Controllers/FunGameController.cs index f5d6660..c33a124 100644 --- a/OshimaCore/Controllers/FunGameController.cs +++ b/OshimaWebAPI/Controllers/FunGameController.cs @@ -7,12 +7,12 @@ using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Library.Constant; using Oshima.Core.Configs; -using Oshima.Core.Models; using Oshima.FunGame.OshimaModules.Characters; using Oshima.FunGame.OshimaModules.Items; using Oshima.FunGame.OshimaServers.Service; +using Oshima.FunGame.WebAPI.Models; -namespace Oshima.Core.Controllers +namespace Oshima.FunGame.WebAPI.Controllers { [Authorize(AuthenticationSchemes = "CustomBearer")] [ApiController] diff --git a/OshimaCore/Controllers/QQController.cs b/OshimaWebAPI/Controllers/QQController.cs similarity index 96% rename from OshimaCore/Controllers/QQController.cs rename to OshimaWebAPI/Controllers/QQController.cs index 33a058c..f191f10 100644 --- a/OshimaCore/Controllers/QQController.cs +++ b/OshimaWebAPI/Controllers/QQController.cs @@ -2,9 +2,9 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Milimoe.FunGame.Core.Api.Utility; using Oshima.Core.Configs; -using Oshima.Core.Models; +using Oshima.FunGame.WebAPI.Models; -namespace Oshima.Core.Controllers +namespace Oshima.FunGame.WebAPI.Controllers { [ApiController] [Route("[controller]")] diff --git a/OshimaCore/Controllers/TestController.cs b/OshimaWebAPI/Controllers/TestController.cs similarity index 97% rename from OshimaCore/Controllers/TestController.cs rename to OshimaWebAPI/Controllers/TestController.cs index d6623bf..2601438 100644 --- a/OshimaCore/Controllers/TestController.cs +++ b/OshimaWebAPI/Controllers/TestController.cs @@ -6,10 +6,10 @@ using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Core.Library.SQLScript.Common; using Oshima.Core.Configs; -using Oshima.Core.Constant; +using Oshima.FunGame.WebAPI.Constant; using TaskScheduler = Milimoe.FunGame.Core.Api.Utility.TaskScheduler; -namespace Oshima.Core.Controllers +namespace Oshima.FunGame.WebAPI.Controllers { [ApiController] [Route("[controller]")] diff --git a/OshimaCore/Controllers/UserDailyController.cs b/OshimaWebAPI/Controllers/UserDailyController.cs similarity index 94% rename from OshimaCore/Controllers/UserDailyController.cs rename to OshimaWebAPI/Controllers/UserDailyController.cs index 02f97b9..fca13cb 100644 --- a/OshimaCore/Controllers/UserDailyController.cs +++ b/OshimaWebAPI/Controllers/UserDailyController.cs @@ -2,10 +2,10 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Milimoe.FunGame.Core.Api.Utility; using Oshima.Core.Configs; -using Oshima.Core.Models; -using Oshima.Core.Utils; +using Oshima.FunGame.WebAPI.Models; +using Oshima.FunGame.WebAPI.Utils; -namespace Oshima.Core.Controllers +namespace Oshima.FunGame.WebAPI.Controllers { [ApiController] [Route("[controller]")] diff --git a/OshimaCore/Models/BindQQ.cs b/OshimaWebAPI/Models/BindQQ.cs similarity index 79% rename from OshimaCore/Models/BindQQ.cs rename to OshimaWebAPI/Models/BindQQ.cs index eecf7c6..50b3fe6 100644 --- a/OshimaCore/Models/BindQQ.cs +++ b/OshimaWebAPI/Models/BindQQ.cs @@ -1,4 +1,4 @@ -namespace Oshima.Core.Models +namespace Oshima.FunGame.WebAPI.Models { public class BindQQ(string openid, long qq) { diff --git a/OshimaCore/Models/UserDaily.cs b/OshimaWebAPI/Models/UserDaily.cs similarity index 84% rename from OshimaCore/Models/UserDaily.cs rename to OshimaWebAPI/Models/UserDaily.cs index 0cce933..170d075 100644 --- a/OshimaCore/Models/UserDaily.cs +++ b/OshimaWebAPI/Models/UserDaily.cs @@ -1,4 +1,4 @@ -namespace Oshima.Core.Models +namespace Oshima.FunGame.WebAPI.Models { public class UserDaily(long user_id, long type, string daily) { diff --git a/OshimaCore/OshimaWebAPI.cs b/OshimaWebAPI/OshimaWebAPI.cs similarity index 93% rename from OshimaCore/OshimaWebAPI.cs rename to OshimaWebAPI/OshimaWebAPI.cs index d428de3..6f0d6f7 100644 --- a/OshimaCore/OshimaWebAPI.cs +++ b/OshimaWebAPI/OshimaWebAPI.cs @@ -3,12 +3,12 @@ using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Constant; using Oshima.Core.Configs; -using Oshima.Core.Constant; using Oshima.FunGame.OshimaModules; using Oshima.FunGame.OshimaServers.Service; +using Oshima.FunGame.WebAPI.Constant; using TaskScheduler = Milimoe.FunGame.Core.Api.Utility.TaskScheduler; -namespace Oshima.Core.WebAPI +namespace Oshima.FunGame.WebAPI { public class OshimaWebAPI : WebAPIPlugin { @@ -39,15 +39,6 @@ namespace Oshima.Core.WebAPI Statics.RunningPlugin = this; Controller.NewSQLHelper(); Controller.NewMailSender(); - GeneralSettings.LoadSetting(); - GeneralSettings.SaveConfig(); - QQOpenID.LoadConfig(); - QQOpenID.SaveConfig(); - Daily.InitDaily(); - SayNo.InitSayNo(); - Ignore.InitIgnore(); - FunGameService.InitFunGame(); - FunGameSimulation.InitFunGameSimulation(); WebAPIAuthenticator.WebAPICustomBearerTokenAuthenticator += CustomBearerTokenAuthenticator; TaskScheduler.Shared.AddTask("重置每日运势", new TimeSpan(0, 0, 0), () => { diff --git a/OshimaWebAPI/OshimaWebAPI.csproj b/OshimaWebAPI/OshimaWebAPI.csproj new file mode 100644 index 0000000..daad622 --- /dev/null +++ b/OshimaWebAPI/OshimaWebAPI.csproj @@ -0,0 +1,39 @@ + + + + net9.0 + enable + enable + Oshima.FunGame.WebAPI + OshimaWebAPI + ..\bin\ + Oshima Studios + + + + 1701;1702;IDE0130;CA1822;IDE1006 + embedded + + + + 1701;1702;IDE0130;CA1822;IDE1006 + embedded + + + + + + + + + + + + + + + ..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll + + + + diff --git a/OshimaCore/Properties/launchSettings.json b/OshimaWebAPI/Properties/launchSettings.json similarity index 100% rename from OshimaCore/Properties/launchSettings.json rename to OshimaWebAPI/Properties/launchSettings.json diff --git a/OshimaCore/Utils/UserDailyUtil.cs b/OshimaWebAPI/Utils/UserDailyUtil.cs similarity index 97% rename from OshimaCore/Utils/UserDailyUtil.cs rename to OshimaWebAPI/Utils/UserDailyUtil.cs index 4ae3487..ad83001 100644 --- a/OshimaCore/Utils/UserDailyUtil.cs +++ b/OshimaWebAPI/Utils/UserDailyUtil.cs @@ -1,9 +1,9 @@ using Milimoe.FunGame.Core.Api.Utility; using Oshima.Core.Configs; using Oshima.Core.Constant; -using Oshima.Core.Models; +using Oshima.FunGame.WebAPI.Models; -namespace Oshima.Core.Utils +namespace Oshima.FunGame.WebAPI.Utils { public class UserDailyUtil {