2024-07-15 16:12:09 +08:00
using AxibugEmuOnline.Web.Common ;
2025-01-08 13:30:58 +08:00
using AxibugProtobuf ;
2024-07-15 16:12:09 +08:00
using Microsoft.AspNetCore.Mvc ;
using MySql.Data.MySqlClient ;
2024-11-28 18:01:27 +08:00
using Mysqlx.Crud ;
2025-01-08 13:30:58 +08:00
using System.Reflection.PortableExecutable ;
2024-07-15 16:12:09 +08:00
namespace AxibugEmuOnline.Web.Controllers
{
public class ApiController : Controller
{
private readonly ILogger < ApiController > _logger ;
public ApiController ( ILogger < ApiController > logger )
{
_logger = logger ;
}
2025-01-08 13:30:58 +08:00
static bool TryDecrypToken ( string tokenStr , out Protobuf_Token_Struct tokenData )
{
if ( string . IsNullOrEmpty ( tokenStr ) | | string . IsNullOrEmpty ( tokenStr . Trim ( ) ) )
{
tokenData = null ;
return false ;
}
try
{
byte [ ] encryptData = Convert . FromBase64String ( tokenStr . Trim ( ) ) ;
byte [ ] decryptData = AESHelper . Decrypt ( encryptData ) ;
tokenData = ProtoBufHelper . DeSerizlize < Protobuf_Token_Struct > ( decryptData ) ;
return true ;
}
catch
{
tokenData = null ;
return false ;
}
}
2024-09-12 14:35:44 +08:00
[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]
2025-01-08 13:30:58 +08:00
public JsonResult RomList ( string SearchKey , int Ptype , int GType , int Page , int PageSize , string Token )
2024-07-15 16:12:09 +08:00
{
2025-01-08 13:30:58 +08:00
long UID = 0 ;
if ( TryDecrypToken ( Token , out Protobuf_Token_Struct tokenData ) )
{
UID = tokenData . UID ;
}
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 > ( ) ;
2025-01-08 13:30:58 +08:00
MySqlConnection conn = SQLPool . DequeueSQLConn ( "RomList" ) ;
2024-07-15 16:12:09 +08:00
{
2025-01-07 10:51:12 +08:00
string platformCond = "" ;
2025-01-08 13:30:58 +08:00
if ( GType > ( int ) RomPlatformType . Invalid & & GType < ( int ) RomPlatformType . All )
2025-01-07 10:51:12 +08:00
{
platformCond = $" and PlatformType = '{Ptype}' " ;
}
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 ;
}
2025-01-07 10:51:12 +08:00
string query = "SELECT count(id) FROM romlist where `Name` like ?searchPattern " + platformCond + 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-11-28 18:01:27 +08:00
string HotOrderBy = "ORDER BY playcount DESC, id ASC" ;
2025-01-07 10:51:12 +08:00
query = $"SELECT id,`Name`,GameType,Note,RomUrl,ImgUrl,`Hash`,`playcount`,`stars`,`PlatformType` FROM romlist where `Name` like ?searchPattern {platformCond} {GameTypeCond} {HotOrderBy} 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 ( ) )
{
2025-01-08 13:30:58 +08:00
Resp_RomInfo data = new Resp_RomInfo ( )
2024-08-16 10:09:45 +08:00
{
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 ,
2024-11-28 18:01:27 +08:00
playcount = reader . GetInt32 ( 7 ) ,
stars = reader . GetInt32 ( 8 ) ,
2025-01-07 10:51:12 +08:00
ptype = reader . GetInt32 ( 9 ) ,
2025-01-08 13:30:58 +08:00
} ;
if ( UID > 0 )
{
if ( CheckIsRomStar ( data . id , UID ) )
data . isStar = 1 ;
}
resp . gameList . Add ( data ) ;
2024-07-15 16:12:09 +08:00
}
}
}
2025-01-08 13:30:58 +08:00
SQLPool . EnqueueSQLConn ( conn ) ;
2024-07-15 16:12:09 +08:00
}
return new JsonResult ( resp ) ;
}
2025-01-08 13:30:58 +08:00
2024-09-18 12:54:13 +08:00
[HttpGet]
2025-01-08 13:30:58 +08:00
public JsonResult MarkList ( string SearchKey , int Ptype , int GType , int Page , int PageSize , string Token )
2024-09-18 12:54:13 +08:00
{
2025-01-08 13:30:58 +08:00
long UID = 0 ;
if ( TryDecrypToken ( Token , out Protobuf_Token_Struct tokenData ) )
{
UID = tokenData . UID ;
}
string searchPattern = $"%{SearchKey}%" ;
Resp_GameList resp = new Resp_GameList ( ) ;
resp . gameList = new List < Resp_RomInfo > ( ) ;
MySqlConnection conn = SQLPool . DequeueSQLConn ( "MarkList" ) ;
{
string platformCond = "" ;
if ( GType > ( int ) RomPlatformType . Invalid & & GType < ( int ) RomPlatformType . All )
{
platformCond = $" and romlist.PlatformType = '{Ptype}' " ;
}
GameType SearchGType = ( GameType ) GType ;
string GameTypeCond = "" ;
switch ( SearchGType )
{
case GameType . NONE :
GameTypeCond = string . Empty ;
break ;
case GameType . ALLINONE :
GameTypeCond = $" and romlist.GameType = '<27> Ͽ<EFBFBD> ' " ;
break ;
default :
GameTypeCond = $" and romlist.GameType = '{SearchGType.ToString()}' " ;
break ;
}
string query = "SELECT count(romlist.id) from rom_stars LEFT JOIN romlist on romlist.Id = rom_stars.id where rom_stars.uid = ?uid and romlist.`Name` like ?searchPattern " + platformCond + GameTypeCond ;
using ( var command = new MySqlCommand ( query , conn ) )
{
// <20> <> <EFBFBD> ò<EFBFBD> <C3B2> <EFBFBD> ֵ
command . Parameters . AddWithValue ( "?uid" , UID ) ;
command . Parameters . AddWithValue ( "?searchPattern" , searchPattern ) ;
// ִ<> в<EFBFBD> ѯ<EFBFBD> <D1AF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
using ( var reader = command . ExecuteReader ( ) )
{
while ( reader . Read ( ) )
{
resp . resultAllCount = reader . GetInt32 ( 0 ) ;
resp . page = Page ;
resp . maxPage = ( int ) Math . Ceiling ( ( float ) resp . resultAllCount / PageSize ) ;
}
}
}
string HotOrderBy = "ORDER BY playcount DESC, id ASC" ;
query = $"SELECT romlist.id,romlist.`Name`,romlist.GameType,romlist.Note,romlist.RomUrl,romlist.ImgUrl,romlist.`Hash`,romlist.`playcount`,romlist.`stars`,romlist.`PlatformType` from rom_stars LEFT JOIN romlist on romlist.Id = rom_stars.id where rom_stars.uid = ?uid and romlist.`Name` like ?searchPattern {platformCond} {GameTypeCond} {HotOrderBy} LIMIT ?offset, ?pageSize;" ;
using ( var command = new MySqlCommand ( query , conn ) )
{
// <20> <> <EFBFBD> ò<EFBFBD> <C3B2> <EFBFBD> ֵ
command . Parameters . AddWithValue ( "?uid" , UID ) ;
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 ( ) )
{
int orderIndex = Page * PageSize ;
while ( reader . Read ( ) )
{
Resp_RomInfo data = new Resp_RomInfo ( )
{
orderid = orderIndex + + ,
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 ,
playcount = reader . GetInt32 ( 7 ) ,
stars = reader . GetInt32 ( 8 ) ,
ptype = reader . GetInt32 ( 9 ) ,
} ;
//<2F> Ͼ<EFBFBD> <CFBE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ѿ<EFBFBD> <D1BE> ղ<EFBFBD> <D5B2> ˵<EFBFBD>
data . isStar = 1 ;
resp . gameList . Add ( data ) ;
}
}
}
SQLPool . EnqueueSQLConn ( conn ) ;
}
return new JsonResult ( resp ) ;
}
[HttpGet]
public JsonResult RomInfo ( int Ptype , int RomID , string Token )
{
long UID = 0 ;
if ( TryDecrypToken ( Token , out Protobuf_Token_Struct tokenData ) )
{
UID = tokenData . UID ;
}
2024-09-18 12:54:13 +08:00
string searchPattern = $"%{RomInfo}%" ;
Resp_RomInfo resp = new Resp_RomInfo ( ) ;
2025-01-08 13:30:58 +08:00
MySqlConnection conn = SQLPool . DequeueSQLConn ( "NesRomList" ) ;
2024-09-18 12:54:13 +08:00
{
2025-01-07 10:51:12 +08:00
string query = $"SELECT id,`Name`,GameType,Note,RomUrl,ImgUrl,`Hash`,`playcount`,`stars`,`PlatformType` FROM romlist where id = ?romid;" ;
2024-09-18 12:54:13 +08:00
using ( var command = new MySqlCommand ( query , conn ) )
{
// <20> <> <EFBFBD> ò<EFBFBD> <C3B2> <EFBFBD> ֵ
command . Parameters . AddWithValue ( "?romid" , RomID ) ;
// ִ<> в<EFBFBD> ѯ<EFBFBD> <D1AF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
using ( var reader = command . ExecuteReader ( ) )
{
while ( reader . Read ( ) )
{
resp . id = reader . GetInt32 ( 0 ) ;
resp . romName = ! reader . IsDBNull ( 1 ) ? reader . GetString ( 1 ) : string . Empty ;
resp . gType = ! reader . IsDBNull ( 2 ) ? reader . GetString ( 2 ) : string . Empty ;
resp . desc = ! reader . IsDBNull ( 3 ) ? reader . GetString ( 3 ) : string . Empty ;
resp . url = ! reader . IsDBNull ( 4 ) ? reader . GetString ( 4 ) : string . Empty ;
resp . imgUrl = ! reader . IsDBNull ( 5 ) ? reader . GetString ( 5 ) : string . Empty ;
resp . hash = ! reader . IsDBNull ( 6 ) ? reader . GetString ( 6 ) : string . Empty ;
2024-11-28 19:54:59 +08:00
resp . playcount = reader . GetInt32 ( 7 ) ;
resp . stars = reader . GetInt32 ( 8 ) ;
2025-01-07 10:51:12 +08:00
resp . ptype = reader . GetInt32 ( 9 ) ;
2024-09-18 12:54:13 +08:00
}
}
}
2025-01-08 13:30:58 +08:00
SQLPool . EnqueueSQLConn ( conn ) ;
2024-09-18 12:54:13 +08:00
}
2025-01-08 13:30:58 +08:00
if ( UID > 0 )
{
if ( CheckIsRomStar ( resp . id , UID ) )
resp . isStar = 1 ;
}
2024-09-18 12:54:13 +08:00
return new JsonResult ( resp ) ;
}
2024-08-16 10:09:45 +08:00
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
2025-01-08 13:30:58 +08:00
public bool CheckIsRomStar ( int RomId , long uid )
{
bool bhad = false ;
MySqlConnection conn = SQLPool . DequeueSQLConn ( "CheckIsRomStart" ) ;
try
{
string query = $"SELECT count(0) from rom_stars where uid = ?uid and = ?romid" ;
using ( var command = new MySqlCommand ( query , conn ) )
{
// <20> <> <EFBFBD> ò<EFBFBD> <C3B2> <EFBFBD> ֵ
command . Parameters . AddWithValue ( "?RomID" , RomId ) ;
command . Parameters . AddWithValue ( "?uid" , uid ) ;
// ִ<> в<EFBFBD> ѯ<EFBFBD> <D1AF> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
using ( var reader = command . ExecuteReader ( ) )
{
while ( reader . Read ( ) )
{
bhad = reader . GetInt32 ( 0 ) > 0 ;
}
}
}
}
catch ( Exception e )
{
//AppSrv.g_Log.Error(e);
}
SQLPool . EnqueueSQLConn ( conn ) ;
return bhad ;
}
2024-09-12 14:35:44 +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 ; }
2025-01-07 10:51:12 +08:00
public int ptype { get ; set ; }
2024-09-18 12:54:13 +08:00
public string romName { get ; set ; }
2024-08-16 10:09:45 +08:00
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-11-28 18:01:27 +08:00
public int playcount { get ; set ; }
2025-01-08 13:30:58 +08:00
public int isStar { get ; set ; }
2024-07-15 16:12:09 +08:00
}
}
}