2025-01-06 11:59:06 +08:00
|
|
|
|
using AxibugEmuOnline.Client.ClientCore;
|
2024-12-11 21:21:27 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace AxibugEmuOnline.Client
|
|
|
|
|
{
|
|
|
|
|
public class HttpAPI
|
|
|
|
|
{
|
|
|
|
|
public string WebHost = "http://emu.axibug.com";
|
|
|
|
|
public string WebSiteApi => WebHost + "/api";
|
|
|
|
|
|
2025-01-07 10:51:12 +08:00
|
|
|
|
public delegate void GetRomListAPI(Action<int, Resp_GameList> callback, AxibugProtobuf.RomPlatformType Platform, int page, int pageSize = 10);
|
|
|
|
|
public delegate void SearchRomListAPI(Action<int, Resp_GameList> callback, AxibugProtobuf.RomPlatformType Platform, string searchKey, int page, int pageSize = 10);
|
2025-01-06 11:59:06 +08:00
|
|
|
|
|
2025-01-08 13:30:58 +08:00
|
|
|
|
public void GetRomList(Action<int, Resp_GameList> callback, AxibugProtobuf.RomPlatformType platform, int page, int pageSize = 10)
|
2024-12-11 21:21:27 +08:00
|
|
|
|
{
|
2025-01-07 14:21:22 +08:00
|
|
|
|
App.StartCoroutine(GetRomListFlow(platform, page, pageSize, callback));
|
2024-12-11 21:21:27 +08:00
|
|
|
|
}
|
2025-01-08 13:30:58 +08:00
|
|
|
|
public void SearchRomList(Action<int, Resp_GameList> callback, AxibugProtobuf.RomPlatformType platform, string searchKey, int page, int pageSize = 10)
|
2024-12-11 21:21:27 +08:00
|
|
|
|
{
|
2025-01-08 13:30:58 +08:00
|
|
|
|
App.StartCoroutine(SearchRomListFlow(platform, searchKey, page, pageSize, callback));
|
2024-12-11 21:21:27 +08:00
|
|
|
|
}
|
2025-01-08 13:30:58 +08:00
|
|
|
|
private IEnumerator SearchRomListFlow(AxibugProtobuf.RomPlatformType platform, string searchKey, int page, int pageSize, Action<int, Resp_GameList> callback)
|
2024-12-11 21:21:27 +08:00
|
|
|
|
{
|
2025-01-06 00:05:37 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(searchKey))
|
|
|
|
|
{
|
|
|
|
|
string oldsearch = searchKey;
|
2025-01-06 01:12:21 +08:00
|
|
|
|
//searchKey = System.Net.WebUtility.UrlEncode(searchKey);
|
|
|
|
|
searchKey = AxiHttp.UrlEncode(searchKey);
|
2025-01-06 00:05:37 +08:00
|
|
|
|
App.log.Info($"search->{oldsearch} ->{searchKey}");
|
|
|
|
|
//searchKey = HttpUtility.UrlDecode(searchKey);
|
|
|
|
|
}
|
2025-01-06 01:01:58 +08:00
|
|
|
|
//避免特殊字符和个别文字编码问题
|
2025-01-06 00:05:37 +08:00
|
|
|
|
//byte[] gb2312Bytes = Encoding.Default.GetBytes(searchKey);
|
|
|
|
|
//byte[] utf8Bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, gb2312Bytes);
|
|
|
|
|
//// 将UTF-8编码的字节数组转换回字符串(此时是UTF-8编码的字符串)
|
|
|
|
|
//string utf8String = Encoding.UTF8.GetString(utf8Bytes);
|
|
|
|
|
//searchKey = UrlEncode(utf8String);
|
|
|
|
|
//App.log.Info($"search->{utf8String} ->{searchKey}");
|
2025-01-08 13:30:58 +08:00
|
|
|
|
string url = $"{WebSiteApi}/RomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}&Token={App.user.Token}";
|
2025-01-06 00:05:37 +08:00
|
|
|
|
App.log.Info($"GetRomList=>{url}");
|
|
|
|
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get(url);
|
2024-12-16 23:50:00 +08:00
|
|
|
|
yield return request.SendWebRequest;
|
|
|
|
|
if (!request.downloadHandler.isDone)
|
|
|
|
|
{
|
2025-01-06 11:59:06 +08:00
|
|
|
|
callback.Invoke(page, null);
|
2024-12-16 23:50:00 +08:00
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-06 01:01:58 +08:00
|
|
|
|
if (!request.downloadHandler.bHadErr)
|
2024-12-27 14:10:22 +08:00
|
|
|
|
{
|
2025-01-06 01:01:58 +08:00
|
|
|
|
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
2025-01-06 11:59:06 +08:00
|
|
|
|
callback.Invoke(page, resp);
|
2024-12-27 14:10:22 +08:00
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-06 01:01:58 +08:00
|
|
|
|
App.log.Error(request.downloadHandler.ErrInfo);
|
2025-01-06 11:59:06 +08:00
|
|
|
|
callback.Invoke(page, null);
|
2025-01-06 01:01:58 +08:00
|
|
|
|
|
2024-12-16 23:50:00 +08:00
|
|
|
|
/*
|
2024-12-11 21:21:27 +08:00
|
|
|
|
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
|
|
|
|
|
yield return request.SendWebRequest();
|
|
|
|
|
|
|
|
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
|
|
|
{
|
|
|
|
|
callback.Invoke(null);
|
|
|
|
|
yield break;
|
2024-12-16 23:50:00 +08:00
|
|
|
|
}*/
|
2024-12-11 21:21:27 +08:00
|
|
|
|
|
|
|
|
|
}
|
2025-01-07 10:51:12 +08:00
|
|
|
|
private IEnumerator GetRomListFlow(AxibugProtobuf.RomPlatformType platform, int page, int pageSize, Action<int, Resp_GameList> callback)
|
2024-12-11 21:21:27 +08:00
|
|
|
|
{
|
2025-01-08 13:30:58 +08:00
|
|
|
|
string url = $"{WebSiteApi}/RomList?Page={page}&PageSize={pageSize}&PType={(int)platform}&Token={App.user.Token}";
|
|
|
|
|
App.log.Info($"GetRomList=>{url}");
|
|
|
|
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get(url);
|
|
|
|
|
yield return request.SendWebRequest;
|
|
|
|
|
if (!request.downloadHandler.isDone)
|
|
|
|
|
{
|
|
|
|
|
callback.Invoke(page, null);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//请求成功
|
|
|
|
|
if (!request.downloadHandler.bHadErr)
|
|
|
|
|
{
|
|
|
|
|
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
|
|
|
|
callback.Invoke(page, resp);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
App.log.Error(request.downloadHandler.ErrInfo);
|
|
|
|
|
callback.Invoke(page, null);
|
|
|
|
|
/*
|
|
|
|
|
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
|
|
|
|
|
yield return request.SendWebRequest();
|
|
|
|
|
|
|
|
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
|
|
|
{
|
|
|
|
|
callback.Invoke(null);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GetMarkList(Action<int, Resp_GameList> callback, AxibugProtobuf.RomPlatformType platform, int page, int pageSize = 10)
|
|
|
|
|
{
|
|
|
|
|
App.StartCoroutine(GetMarkListFlow(platform, page, pageSize, callback));
|
|
|
|
|
}
|
|
|
|
|
public void SearchMarkList(Action<int, Resp_GameList> callback, AxibugProtobuf.RomPlatformType platform, string searchKey, int page, int pageSize = 10)
|
|
|
|
|
{
|
|
|
|
|
App.StartCoroutine(SearchMarkListFlow(platform, searchKey, page, pageSize, callback));
|
|
|
|
|
}
|
|
|
|
|
private IEnumerator SearchMarkListFlow(AxibugProtobuf.RomPlatformType platform, string searchKey, int page, int pageSize, Action<int, Resp_GameList> callback)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(searchKey))
|
|
|
|
|
{
|
|
|
|
|
string oldsearch = searchKey;
|
|
|
|
|
//searchKey = System.Net.WebUtility.UrlEncode(searchKey);
|
|
|
|
|
searchKey = AxiHttp.UrlEncode(searchKey);
|
|
|
|
|
App.log.Info($"search->{oldsearch} ->{searchKey}");
|
|
|
|
|
//searchKey = HttpUtility.UrlDecode(searchKey);
|
|
|
|
|
}
|
|
|
|
|
//避免特殊字符和个别文字编码问题
|
|
|
|
|
//byte[] gb2312Bytes = Encoding.Default.GetBytes(searchKey);
|
|
|
|
|
//byte[] utf8Bytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, gb2312Bytes);
|
|
|
|
|
//// 将UTF-8编码的字节数组转换回字符串(此时是UTF-8编码的字符串)
|
|
|
|
|
//string utf8String = Encoding.UTF8.GetString(utf8Bytes);
|
|
|
|
|
//searchKey = UrlEncode(utf8String);
|
|
|
|
|
//App.log.Info($"search->{utf8String} ->{searchKey}");
|
|
|
|
|
string url = $"{WebSiteApi}/RomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}&Token={App.user.Token}";
|
|
|
|
|
App.log.Info($"GetRomList=>{url}");
|
|
|
|
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get(url);
|
|
|
|
|
yield return request.SendWebRequest;
|
|
|
|
|
if (!request.downloadHandler.isDone)
|
|
|
|
|
{
|
|
|
|
|
callback.Invoke(page, null);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!request.downloadHandler.bHadErr)
|
|
|
|
|
{
|
|
|
|
|
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
|
|
|
|
callback.Invoke(page, resp);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
App.log.Error(request.downloadHandler.ErrInfo);
|
|
|
|
|
callback.Invoke(page, null);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}&SearchKey={searchKey}");
|
|
|
|
|
yield return request.SendWebRequest();
|
|
|
|
|
|
|
|
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
|
|
|
{
|
|
|
|
|
callback.Invoke(null);
|
|
|
|
|
yield break;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private IEnumerator GetMarkListFlow(AxibugProtobuf.RomPlatformType platform, int page, int pageSize, Action<int, Resp_GameList> callback)
|
|
|
|
|
{
|
|
|
|
|
string url = $"{WebSiteApi}/RomList?Page={page}&PageSize={pageSize}&PType={(int)platform}&Token={App.user.Token}";
|
2025-01-06 00:05:37 +08:00
|
|
|
|
App.log.Info($"GetRomList=>{url}");
|
|
|
|
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get(url);
|
2024-12-16 23:50:00 +08:00
|
|
|
|
yield return request.SendWebRequest;
|
|
|
|
|
if (!request.downloadHandler.isDone)
|
|
|
|
|
{
|
2025-01-06 11:59:06 +08:00
|
|
|
|
callback.Invoke(page, null);
|
2024-12-16 23:50:00 +08:00
|
|
|
|
yield break;
|
|
|
|
|
}
|
2024-12-27 14:10:22 +08:00
|
|
|
|
|
2025-01-06 01:01:58 +08:00
|
|
|
|
//请求成功
|
|
|
|
|
if (!request.downloadHandler.bHadErr)
|
2024-12-27 14:10:22 +08:00
|
|
|
|
{
|
2025-01-06 01:01:58 +08:00
|
|
|
|
var resp = JsonUtility.FromJson<Resp_GameList>(request.downloadHandler.text);
|
2025-01-06 11:59:06 +08:00
|
|
|
|
callback.Invoke(page, resp);
|
2024-12-27 14:10:22 +08:00
|
|
|
|
yield break;
|
|
|
|
|
}
|
2025-01-06 01:01:58 +08:00
|
|
|
|
|
|
|
|
|
App.log.Error(request.downloadHandler.ErrInfo);
|
2025-01-06 11:59:06 +08:00
|
|
|
|
callback.Invoke(page, null);
|
2024-12-16 23:50:00 +08:00
|
|
|
|
/*
|
2024-12-11 21:21:27 +08:00
|
|
|
|
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/NesRomList?Page={page}&PageSize={pageSize}");
|
|
|
|
|
yield return request.SendWebRequest();
|
|
|
|
|
|
|
|
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
|
|
|
{
|
|
|
|
|
callback.Invoke(null);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
2024-12-16 23:50:00 +08:00
|
|
|
|
*/
|
2024-12-11 21:21:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-08 13:30:58 +08:00
|
|
|
|
|
2025-01-07 10:51:12 +08:00
|
|
|
|
public IEnumerator GetRomInfo(int RomID, Action<Resp_RomInfo> callback)
|
2024-12-11 21:21:27 +08:00
|
|
|
|
{
|
2024-12-16 23:50:00 +08:00
|
|
|
|
|
2025-01-08 13:30:58 +08:00
|
|
|
|
AxiHttpProxy.SendWebRequestProxy request = AxiHttpProxy.Get($"{WebSiteApi}/RomInfo?RomID={RomID}&Token={App.user.Token}");
|
2024-12-16 23:50:00 +08:00
|
|
|
|
yield return request.SendWebRequest;
|
|
|
|
|
if (!request.downloadHandler.isDone)
|
|
|
|
|
{
|
|
|
|
|
callback.Invoke(null);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-06 01:01:58 +08:00
|
|
|
|
//成功
|
|
|
|
|
if (!request.downloadHandler.bHadErr)
|
2024-12-27 14:10:22 +08:00
|
|
|
|
{
|
2025-01-06 01:01:58 +08:00
|
|
|
|
var resp = JsonUtility.FromJson<Resp_RomInfo>(request.downloadHandler.text);
|
|
|
|
|
callback.Invoke(resp);
|
2024-12-27 14:10:22 +08:00
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-06 01:01:58 +08:00
|
|
|
|
App.log.Error(request.downloadHandler.ErrInfo);
|
|
|
|
|
callback.Invoke(null);
|
|
|
|
|
|
2024-12-16 23:50:00 +08:00
|
|
|
|
/*
|
2024-12-11 21:21:27 +08:00
|
|
|
|
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/RomInfo?PType={PlatformType.Nes}&RomID={RomID}");
|
|
|
|
|
yield return request.SendWebRequest();
|
|
|
|
|
|
|
|
|
|
if (request.result != UnityWebRequest.Result.Success)
|
|
|
|
|
{
|
|
|
|
|
callback.Invoke(null);
|
|
|
|
|
yield break;
|
2024-12-16 23:50:00 +08:00
|
|
|
|
}*/
|
2024-12-11 21:21:27 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum GameType : byte
|
|
|
|
|
{
|
|
|
|
|
NONE = 0,
|
|
|
|
|
ACT,
|
|
|
|
|
ARPG,
|
|
|
|
|
AVG,
|
|
|
|
|
ETC,
|
|
|
|
|
FTG,
|
|
|
|
|
PUZ,
|
|
|
|
|
RAC,
|
|
|
|
|
RPG,
|
|
|
|
|
SLG,
|
|
|
|
|
SPG,
|
|
|
|
|
SRPG,
|
|
|
|
|
STG,
|
|
|
|
|
TAB,
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 合卡
|
|
|
|
|
/// </summary>
|
|
|
|
|
ALLINONE,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class Resp_GameList
|
|
|
|
|
{
|
|
|
|
|
public int page;
|
|
|
|
|
public int maxPage;
|
|
|
|
|
public int resultAllCount;
|
|
|
|
|
public List<Resp_RomInfo> gameList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class Resp_RomInfo
|
|
|
|
|
{
|
2025-01-07 10:51:12 +08:00
|
|
|
|
public int orderid;
|
2024-12-11 21:21:27 +08:00
|
|
|
|
public int id;
|
2025-01-07 10:51:12 +08:00
|
|
|
|
//TODO 后续根据ptype,启动游戏时选择核心。和列表设计和UI分组解耦,比如无视平台搜索列表,收藏列表
|
|
|
|
|
public int ptype;
|
2024-12-11 21:21:27 +08:00
|
|
|
|
public string romName;
|
|
|
|
|
public string gType;
|
|
|
|
|
public string desc;
|
|
|
|
|
public string url;
|
|
|
|
|
public string imgUrl;
|
|
|
|
|
public string hash;
|
2025-01-08 13:30:58 +08:00
|
|
|
|
public int stars;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 游玩计数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int playcount;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否收藏
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int isStar;
|
2024-12-11 21:21:27 +08:00
|
|
|
|
}
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class Resp_CheckStandInfo
|
|
|
|
|
{
|
|
|
|
|
public int needUpdateClient;
|
|
|
|
|
public string serverIp;
|
|
|
|
|
public ushort serverPort;
|
|
|
|
|
public string clientVersion;
|
|
|
|
|
public string downLoadUrl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|