mirror of
https://github.com/oshima-studios/OshimaGameModule.git
synced 2025-04-22 20:09:35 +08:00
将 OshimaCore 独立,分离出 WebAPI 项目
This commit is contained in:
parent
de96aa3593
commit
09ecda02be
@ -43,6 +43,7 @@ namespace Oshima.Core.Configs
|
||||
{
|
||||
ReverseAtIgnore = (List<long>)value;
|
||||
}
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
public static void SaveConfig()
|
||||
|
@ -84,6 +84,7 @@ namespace Oshima.Core.Configs
|
||||
}
|
||||
}
|
||||
}
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
public static void SaveConfig()
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,29 +5,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Oshima.Core</RootNamespace>
|
||||
<AssemblyName>OshimaCore</AssemblyName>
|
||||
<BaseOutputPath>..\bin\</BaseOutputPath>
|
||||
<Authors>Oshima Studios</Authors>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE0130;CA1822;IDE1006</NoWarn>
|
||||
<NoWarn>1701;1702;IDE0130</NoWarn>
|
||||
<DebugType>embedded</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE0130;CA1822;IDE1006</NoWarn>
|
||||
<NoWarn>1701;1702;IDE0130</NoWarn>
|
||||
<DebugType>embedded</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OshimaModules\OshimaModules.csproj" />
|
||||
<ProjectReference Include="..\OshimaServers\OshimaServers.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="FunGame.Core">
|
||||
<HintPath>..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll</HintPath>
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向客户端推送事件
|
||||
/// </summary>
|
||||
@ -100,15 +114,115 @@ namespace Oshima.FunGame.OshimaServers
|
||||
Controller.WriteLine("接收匿名服务器消息", LogLevel.Debug);
|
||||
|
||||
// 根据服务器和客户端的数据传输约定,自行处理 data,并返回。
|
||||
string msg = "";
|
||||
if (data.Count > 0)
|
||||
{
|
||||
string command = NetworkUtility.JsonDeserializeFromDictionary<string>(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<string, object> data)
|
||||
{
|
||||
string result = "";
|
||||
|
||||
SQLHelper? sql = Factory.OpenFactory.GetSQLHelper();
|
||||
if (sql != null)
|
||||
{
|
||||
using (sql)
|
||||
{
|
||||
try
|
||||
{
|
||||
long qq = NetworkUtility.JsonDeserializeFromDictionary<long>(data, "qq");
|
||||
double sc = NetworkUtility.JsonDeserializeFromDictionary<double>(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<Dictionary<string, object>> GamingMessageHandler(string username, GamingType type, Dictionary<string, object> data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
@ -18,6 +18,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OshimaCore\OshimaCore.csproj" />
|
||||
<ProjectReference Include="..\OshimaModules\OshimaModules.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
using Milimoe.FunGame.Core.Library.Common.Addon;
|
||||
|
||||
namespace Oshima.Core.Constant
|
||||
namespace Oshima.FunGame.WebAPI.Constant
|
||||
{
|
||||
public class Statics
|
||||
{
|
@ -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]
|
@ -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]")]
|
@ -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]")]
|
@ -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]")]
|
@ -1,4 +1,4 @@
|
||||
namespace Oshima.Core.Models
|
||||
namespace Oshima.FunGame.WebAPI.Models
|
||||
{
|
||||
public class BindQQ(string openid, long qq)
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace Oshima.Core.Models
|
||||
namespace Oshima.FunGame.WebAPI.Models
|
||||
{
|
||||
public class UserDaily(long user_id, long type, string daily)
|
||||
{
|
@ -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), () =>
|
||||
{
|
39
OshimaWebAPI/OshimaWebAPI.csproj
Normal file
39
OshimaWebAPI/OshimaWebAPI.csproj
Normal file
@ -0,0 +1,39 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Oshima.FunGame.WebAPI</RootNamespace>
|
||||
<AssemblyName>OshimaWebAPI</AssemblyName>
|
||||
<BaseOutputPath>..\bin\</BaseOutputPath>
|
||||
<Authors>Oshima Studios</Authors>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE0130;CA1822;IDE1006</NoWarn>
|
||||
<DebugType>embedded</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<NoWarn>1701;1702;IDE0130;CA1822;IDE1006</NoWarn>
|
||||
<DebugType>embedded</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OshimaCore\OshimaCore.csproj" />
|
||||
<ProjectReference Include="..\OshimaModules\OshimaModules.csproj" />
|
||||
<ProjectReference Include="..\OshimaServers\OshimaServers.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="FunGame.Core">
|
||||
<HintPath>..\..\FunGame.Core\bin\Debug\net9.0\FunGame.Core.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -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
|
||||
{
|
Loading…
x
Reference in New Issue
Block a user