mirror of
https://github.com/oshima-studios/OshimaGameModule.git
synced 2025-04-23 12:29:35 +08:00
测试单例 SQLHelper
This commit is contained in:
parent
46d1d64e1c
commit
46f5f76f81
9
OshimaCore/Constant/Statics.cs
Normal file
9
OshimaCore/Constant/Statics.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Milimoe.FunGame.Core.Library.Common.Addon;
|
||||
|
||||
namespace Oshima.Core.Constant
|
||||
{
|
||||
public class Statics
|
||||
{
|
||||
public static WebAPIPlugin? RunningPlugin { get; set; } = null;
|
||||
}
|
||||
}
|
@ -1,6 +1,10 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Globalization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Library.Exception;
|
||||
using Oshima.Core.Constant;
|
||||
|
||||
namespace Oshima.Core.Controllers
|
||||
{
|
||||
@ -15,5 +19,36 @@ namespace Oshima.Core.Controllers
|
||||
{
|
||||
return msg.Encrypt(key);
|
||||
}
|
||||
|
||||
[HttpGet("getlastlogintime")]
|
||||
public string GetLastLoginTime()
|
||||
{
|
||||
if (Statics.RunningPlugin != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
SQLHelper? sql = Statics.RunningPlugin.SQLHelper;
|
||||
if (sql != null)
|
||||
{
|
||||
sql.ExecuteDataSet("Select Max(LoginTime) LastTime From ServerLoginLogs");
|
||||
if (sql.Success && DateTime.TryParse(sql.DataSet.Tables[0].Rows[0]["LastTime"].ToString(), out DateTime date))
|
||||
{
|
||||
string month = date.ToString("MMM", CultureInfo.InvariantCulture);
|
||||
int day = date.Day;
|
||||
string time = date.ToString("HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
|
||||
string msg = "服务器最后启动时间:" + $"{month}. {day}, {date.Year} {time}";
|
||||
return NetworkUtility.JsonSerialize(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Statics.RunningPlugin.Controller?.Error(e);
|
||||
return NetworkUtility.JsonSerialize("无法调用此接口。原因:\r\n" + e.GetErrorInfo());
|
||||
}
|
||||
}
|
||||
return NetworkUtility.JsonSerialize("无法调用此接口。原因:与 SQL 服务器通信失败。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Milimoe.FunGame.Core.Library.Common.Addon;
|
||||
using Oshima.Core.Configs;
|
||||
using Oshima.Core.Constant;
|
||||
using Oshima.Core.Utils;
|
||||
using Oshima.FunGame.OshimaModules;
|
||||
|
||||
@ -27,6 +28,7 @@ namespace Oshima.Core.WebAPI
|
||||
|
||||
public override void AfterLoad(params object[] objs)
|
||||
{
|
||||
Statics.RunningPlugin = this;
|
||||
GeneralSettings.LoadSetting();
|
||||
GeneralSettings.SaveConfig();
|
||||
QQOpenID.LoadConfig();
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Core.Model;
|
||||
using Oshima.FunGame.OshimaModules.Characters;
|
||||
using Oshima.FunGame.OshimaModules.Items;
|
||||
using Oshima.FunGame.OshimaModules.Skills;
|
||||
|
@ -5,6 +5,7 @@ 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 Milimoe.FunGame.Core.Model;
|
||||
using Oshima.FunGame.OshimaModules;
|
||||
using Oshima.FunGame.OshimaModules.Items;
|
||||
using Oshima.FunGame.OshimaModules.Skills;
|
||||
|
Loading…
x
Reference in New Issue
Block a user