Player data initial
This commit is contained in:
@@ -12,7 +12,7 @@ namespace TOOHUCardAPI.Controllers
|
|||||||
public class MethodBasedController : ControllerBase
|
public class MethodBasedController : ControllerBase
|
||||||
{
|
{
|
||||||
public delegate Task<object> EndpointHandler(string requestBody);
|
public delegate Task<object> EndpointHandler(string requestBody);
|
||||||
private static Dictionary<Type, MethodMap> MethodMapByType;
|
private static Dictionary<Type, MethodMap> MethodMapByType = new Dictionary<Type, MethodMap>();
|
||||||
|
|
||||||
protected Task<object> InvokeEndpointHandlerForMethod<T>(object _this, string method, string body)
|
protected Task<object> InvokeEndpointHandlerForMethod<T>(object _this, string method, string body)
|
||||||
{
|
{
|
||||||
@@ -20,7 +20,7 @@ namespace TOOHUCardAPI.Controllers
|
|||||||
if (registeredEndpointHandlers.ContainsKey(method))
|
if (registeredEndpointHandlers.ContainsKey(method))
|
||||||
{
|
{
|
||||||
return ((EndpointHandler) registeredEndpointHandlers[method]
|
return ((EndpointHandler) registeredEndpointHandlers[method]
|
||||||
.CreateDelegate(typeof(EndpointHandler), _this)).Invoke(body);
|
.CreateDelegate(typeof(EndpointHandler), _this))(body);
|
||||||
}
|
}
|
||||||
throw new MissingEndpointHandlerException(method);
|
throw new MissingEndpointHandlerException(method);
|
||||||
}
|
}
|
||||||
@@ -29,15 +29,14 @@ namespace TOOHUCardAPI.Controllers
|
|||||||
{
|
{
|
||||||
if (!MethodMapByType.ContainsKey(typeof(T)))
|
if (!MethodMapByType.ContainsKey(typeof(T)))
|
||||||
{
|
{
|
||||||
RegisterEndpointHandlers<T>();
|
MethodMapByType[typeof(T)] = RegisterEndpointHandlers<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return MethodMapByType[typeof(T)];
|
return MethodMapByType[typeof(T)];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodMap RegisterEndpointHandlers<T>()
|
private static MethodMap RegisterEndpointHandlers<T>()
|
||||||
{
|
{
|
||||||
MethodInfo[] methods = typeof(T).GetMethods();
|
MethodInfo[] methods = typeof(T).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
return methods
|
return methods
|
||||||
.Aggregate(new MethodMap(), (handlers, m) =>
|
.Aggregate(new MethodMap(), (handlers, m) =>
|
||||||
{
|
{
|
||||||
@@ -51,4 +50,11 @@ namespace TOOHUCardAPI.Controllers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class MissingEndpointHandlerException : Exception
|
||||||
|
{
|
||||||
|
public MissingEndpointHandlerException(string method) : base($"Handler for [{method}] is either missing or incorrectly setup.")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using TOOHUCardAPI.Data;
|
using TOOHUCardAPI.Data;
|
||||||
using TOOHUCardAPI.Models;
|
using TOOHUCardAPI.Models;
|
||||||
|
|
||||||
@@ -20,17 +24,22 @@ namespace TOOHUCardAPI.Controllers
|
|||||||
* So let's use a single entry point and redirect based on that
|
* So let's use a single entry point and redirect based on that
|
||||||
*/
|
*/
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<object> EntryPoint(IMethodBasedRequest methodRequest)
|
public async Task<object> EntryPoint([FromBody] object bodyObj)
|
||||||
{
|
{
|
||||||
return null;
|
string body = JsonConvert.SerializeObject(bodyObj);
|
||||||
|
JObject request = JObject.Parse(body);
|
||||||
|
string method = request["method"].ToString();
|
||||||
|
return await InvokeEndpointHandlerForMethod<PlayerDataController>(this, method, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[EndpointHandler("get")]
|
||||||
|
private async Task<object> Test(string body)
|
||||||
|
{
|
||||||
|
PlayerDataGetRequestObject requestObject = JsonConvert.DeserializeObject<PlayerDataGetRequestObject>(body);
|
||||||
|
PlayerDataGetResponseObject response = new PlayerDataGetResponseObject(requestObject.Ids.Length);
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MissingEndpointHandlerException : Exception
|
|
||||||
{
|
|
||||||
public MissingEndpointHandlerException(string? method) : base($"Handler for [{method}] is either missing or incorrectly setup.")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
6
TOOHUCardAPI/Data/CardEncodingUtil.cs
Normal file
6
TOOHUCardAPI/Data/CardEncodingUtil.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace TOOHUCardAPI.Data
|
||||||
|
{
|
||||||
|
public static class CardEncodingUtil
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,16 +19,16 @@ namespace TOOHUCardAPI.Models
|
|||||||
public class GameConfigResponse
|
public class GameConfigResponse
|
||||||
{
|
{
|
||||||
private static string SUCCESS_CODE = "0000";
|
private static string SUCCESS_CODE = "0000";
|
||||||
[JsonPropertyName("code")] public string Code { get; set; } = SUCCESS_CODE;
|
[JsonProperty("code")] public string Code { get; set; } = SUCCESS_CODE;
|
||||||
[JsonPropertyName("msg")] public string Message { get; set; } = string.Empty;
|
[JsonProperty("msg")] public string Message { get; set; } = string.Empty;
|
||||||
[JsonPropertyName("game_code")] public string GameCode { get; set; } = string.Empty;
|
[JsonProperty("game_code")] public string GameCode { get; set; } = string.Empty;
|
||||||
[JsonPropertyName("game_msg")] public string GameMessage { get; set; } = string.Empty;
|
[JsonProperty("game_msg")] public string GameMessage { get; set; } = string.Empty;
|
||||||
[JsonPropertyName("luck_card")] public string LuckCard { get; set; } = string.Empty;
|
[JsonProperty("luck_card")] public string LuckCard { get; set; } = string.Empty;
|
||||||
[JsonPropertyName("luck_crit")] public float LuckCrit { get; set; }
|
[JsonProperty("luck_crit")] public float LuckCrit { get; set; }
|
||||||
[JsonPropertyName("new_card_list")] public string NewCardList { get; set; } = string.Empty;
|
[JsonProperty("new_card_list")] public string NewCardList { get; set; } = string.Empty;
|
||||||
[JsonPropertyName("open_day_list")] public string OpenDayList { get; set; } = String.Empty;
|
[JsonProperty("open_day_list")] public string OpenDayList { get; set; } = String.Empty;
|
||||||
[JsonPropertyName("is_open_day")] public int IsOpenDay { get; set; }
|
[JsonProperty("is_open_day")] public int IsOpenDay { get; set; }
|
||||||
[JsonPropertyName("server_time")] public string ServerTime { get; set; } = string.Empty;
|
[JsonProperty("server_time")] public string ServerTime { get; set; } = string.Empty;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace TOOHUCardAPI.Models
|
namespace TOOHUCardAPI.Models
|
||||||
{
|
{
|
||||||
public class PlayerDataRequestObject
|
public class PlayerDataGetRequestObject
|
||||||
{
|
{
|
||||||
public string Method { get; set; }
|
public string Method { get; set; }
|
||||||
public string[] Ids { get; set; }
|
public string[] Ids { get; set; }
|
||||||
|
|||||||
@@ -1,23 +1,41 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace TOOHUCardAPI.Models
|
namespace TOOHUCardAPI.Models
|
||||||
{
|
{
|
||||||
|
public class PlayerDataGetResponseObject
|
||||||
|
{
|
||||||
|
public Dictionary<int, PlayerDataGetResponseObjectPlayer> bo { get; set; }
|
||||||
|
|
||||||
|
public PlayerDataGetResponseObject(int players)
|
||||||
|
{
|
||||||
|
this.bo = new Dictionary<int, PlayerDataGetResponseObjectPlayer>();
|
||||||
|
foreach (int i in Enumerable.Range(0, players))
|
||||||
|
{
|
||||||
|
bo[i] = new PlayerDataGetResponseObjectPlayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Fields pulled from the game code
|
* Fields pulled from the game code
|
||||||
* Looking up Gamerules.Playerdata
|
* Looking up Gamerules.Playerdata
|
||||||
*/
|
*/
|
||||||
public class PlayerDataGetResponseObject
|
public class PlayerDataGetResponseObjectPlayer
|
||||||
{
|
{
|
||||||
|
[JsonProperty("code")] public string Code { get; set; } = "0000";
|
||||||
|
|
||||||
public string Code { get; set; }
|
[JsonProperty("msg")] public string Message { get; set; } = string.Empty;
|
||||||
public string Message { get; set; }
|
//[JsonProperty("steamid")]
|
||||||
public string SteamId { get; set; }
|
//public string SteamId { get; set; }
|
||||||
public int MaxWave { get; set; }
|
[JsonProperty("max_wave")] public int MaxWave { get; set; } = 0;
|
||||||
public int MaxTeamWave { get; set; }
|
[JsonProperty("max_team_wave")] public int MaxTeamWave { get; set; } = 0;
|
||||||
public int PetLevel { get; set; }
|
[JsonProperty("pet_level")] public int PetLevel { get; set; } = 1;
|
||||||
public string EndTime { get; set; }
|
[JsonProperty("end_time")] public string EndTime { get; set; } = string.Empty;
|
||||||
public int KeyTotal { get; set; }
|
[JsonProperty("key_total")] public int KeyTotal { get; set; } = 100;
|
||||||
public string KeySaveDate { get; set; }
|
[JsonProperty("key_save_date")] public string KeySaveDate { get; set; } = string.Empty;
|
||||||
public int Vip { get; set; }
|
[JsonProperty("vip")] public int Vip { get; set; } = 1;
|
||||||
public int Point { get; set; }
|
[JsonProperty("point")] public int Point { get; set; } = 10000;
|
||||||
public string LevelList { get; set; }
|
[JsonProperty("level_list")] public string LevelList { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ namespace TOOHUCardAPI
|
|||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddControllers();
|
services.AddControllers().AddNewtonsoftJson();
|
||||||
services.AddSwaggerGen(c =>
|
services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
c.SwaggerDoc("v1", new OpenApiInfo {Title = "TOOHUCardAPI", Version = "v1"});
|
c.SwaggerDoc("v1", new OpenApiInfo {Title = "TOOHUCardAPI", Version = "v1"});
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.11" />
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user