AxibugEmuOnline/AxibugEmuOnline.Web/Controllers/ApiController.cs

166 lines
5.9 KiB
C#
Raw Normal View History

2024-07-15 16:12:09 +08:00
using AxibugEmuOnline.Web.Common;
using Microsoft.AspNetCore.Mvc;
using MySql.Data.MySqlClient;
namespace AxibugEmuOnline.Web.Controllers
{
public class ApiController : Controller
{
private readonly ILogger<ApiController> _logger;
public ApiController(ILogger<ApiController> logger)
{
_logger = logger;
}
[HttpGet]
public JsonResult CheckStandInfo(int platform, string version)
{
Resp_CheckStandInfo resp = new Resp_CheckStandInfo()
{
needUpdateClient = 0,
clientVersion = Config.cfg.ClientVersion,
serverIp = Config.cfg.ServerIp,
serverPort = Config.cfg.ServerPort,
downLoadUrl = ""
};
return new JsonResult(resp);
}
2024-07-15 16:12:09 +08:00
[HttpGet]
2024-08-16 10:09:45 +08:00
public JsonResult NesRomList(string SearchKey,int Ptype,int GType,int Page, int PageSize)
2024-07-15 16:12:09 +08:00
{
string searchPattern = $"%{SearchKey}%";
Resp_GameList resp = new Resp_GameList();
2024-08-16 10:09:45 +08:00
resp.gameList = new List<Resp_RomInfo>();
MySqlConnection conn = Haoyue_SQLPoolManager.DequeueSQLConn("NesRomList");
2024-07-15 16:12:09 +08:00
{
2024-08-16 10:09:45 +08:00
GameType SearchGType = (GameType)GType;
string GameTypeCond = "";
switch (SearchGType)
{
case GameType.NONE:
GameTypeCond = string.Empty;
break;
case GameType.ALLINONE:
GameTypeCond = $" and GameType = '<27>Ͽ<EFBFBD>' ";
break;
default:
GameTypeCond = $" and GameType = '{SearchGType.ToString()}' ";
break;
}
string query = "SELECT count(id) FROM romlist_nes where `Name` like ?searchPattern " + GameTypeCond;
2024-07-15 16:12:09 +08:00
using (var command = new MySqlCommand(query, conn))
{
// <20><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>ֵ
command.Parameters.AddWithValue("?searchPattern", searchPattern);
// ִ<>в<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
2024-08-16 10:09:45 +08:00
resp.resultAllCount = reader.GetInt32(0);
resp.page = Page;
resp.maxPage = (int)Math.Ceiling((float)resp.resultAllCount / PageSize);
2024-07-15 16:12:09 +08:00
}
}
}
2024-08-16 10:09:45 +08:00
query = $"SELECT id,`Name`,GameType,Note,RomUrl,ImgUrl,`Hash` FROM romlist_nes where `Name` like ?searchPattern {GameTypeCond} LIMIT ?offset, ?pageSize;";
2024-07-15 16:12:09 +08:00
using (var command = new MySqlCommand(query, conn))
{
// <20><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>ֵ
command.Parameters.AddWithValue("?searchPattern", searchPattern);
command.Parameters.AddWithValue("?offset", Page * PageSize);
command.Parameters.AddWithValue("?pageSize", PageSize);
// ִ<>в<EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
using (var reader = command.ExecuteReader())
{
2024-08-22 14:24:11 +08:00
int orderIndex = Page * PageSize;
2024-07-15 16:12:09 +08:00
while (reader.Read())
{
2024-08-16 10:09:45 +08:00
resp.gameList.Add(new Resp_RomInfo()
{
2024-08-22 14:24:11 +08:00
orderid = orderIndex++,
2024-08-16 10:09:45 +08:00
id = reader.GetInt32(0),
romName = !reader.IsDBNull(1) ? reader.GetString(1) : string.Empty,
gType = !reader.IsDBNull(2) ? reader.GetString(2) : string.Empty,
desc = !reader.IsDBNull(3) ? reader.GetString(3) : string.Empty,
url = !reader.IsDBNull(4) ? reader.GetString(4) : string.Empty,
imgUrl = !reader.IsDBNull(5) ? reader.GetString(5) : string.Empty,
hash = !reader.IsDBNull(6) ? reader.GetString(6) : string.Empty,
stars = 0,
2024-07-15 16:12:09 +08:00
});
}
}
}
Haoyue_SQLPoolManager.EnqueueSQLConn(conn);
}
return new JsonResult(resp);
}
2024-08-16 10:09:45 +08:00
enum PlatformType : byte
{
All = 0,
Nes,
}
enum GameType : byte
{
NONE = 0,
ACT,
ARPG,
AVG,
ETC,
FTG,
PUZ,
RAC,
RPG,
SLG,
SPG,
SRPG,
STG,
TAB,
/// <summary>
/// <20>Ͽ<EFBFBD>
/// </summary>
ALLINONE,
}
2024-07-15 16:12:09 +08:00
class Resp_CheckStandInfo
{
public int needUpdateClient { get; set; }
public string serverIp { get; set; }
public ushort serverPort { get; set; }
public string clientVersion { get; set; }
public string downLoadUrl { get; set; }
}
2024-07-15 16:12:09 +08:00
class Resp_GameList
{
2024-08-16 10:09:45 +08:00
public int page { get; set; }
public int maxPage { get; set; }
public int resultAllCount { get; set; }
public List<Resp_RomInfo> gameList { get; set; }
2024-07-15 16:12:09 +08:00
}
public class Resp_RomInfo
{
2024-08-22 14:24:11 +08:00
public int orderid { get; set; }
2024-08-16 10:09:45 +08:00
public int id { get; set; }
public string romName { get; set;}
public string gType { get; set; }
public string desc { get; set; }
public string url { get; set; }
public string imgUrl { get; set; }
public string hash { get; set; }
public int stars { get; set; }
2024-07-15 16:12:09 +08:00
}
}
}