diff --git a/TOOHUCardAPI/Controllers/PlayerDataController.cs b/TOOHUCardAPI/Controllers/PlayerDataController.cs index cc28761..f7ee7ad 100644 --- a/TOOHUCardAPI/Controllers/PlayerDataController.cs +++ b/TOOHUCardAPI/Controllers/PlayerDataController.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using TOOHUCardAPI.Data; namespace TOOHUCardAPI.Controllers { @@ -11,5 +13,43 @@ namespace TOOHUCardAPI.Controllers [ApiController] public class PlayerDataController : ControllerBase { + private delegate Task EndpointHandler(string requestBody); + // Mapping of method => handler + private Dictionary registeredEndpointHandlers; + + private void RegisterEndpointHandlers() + { + MethodInfo[] methods = typeof(PlayerDataController).GetMethods(); + registeredEndpointHandlers = methods + .Aggregate(new Dictionary(), (handlers, m) => + { + Attribute attr = m.GetCustomAttribute(typeof(EndpointHandlerAttribute), false); + if (attr != null) + { + EndpointHandlerAttribute e = (EndpointHandlerAttribute) attr; + handlers.Add(e.Method, (EndpointHandler)m.CreateDelegate(typeof(EndpointHandler), this)); + } + return handlers; + }); + } + + public PlayerDataController() + { + RegisterEndpointHandlers(); + + } + + /** + * The game uses a single endpoint for player data. + * The object they send has a method field that's used to decide what's being done + * So let's use a single entry point and redirect based on that + */ + [HttpPost] + public async Task EntryPoint() + { + + return null; + } + } } \ No newline at end of file diff --git a/TOOHUCardAPI/Data/EndpointHandlerAttribute.cs b/TOOHUCardAPI/Data/EndpointHandlerAttribute.cs new file mode 100644 index 0000000..80bcab4 --- /dev/null +++ b/TOOHUCardAPI/Data/EndpointHandlerAttribute.cs @@ -0,0 +1,15 @@ +using System; + +namespace TOOHUCardAPI.Data +{ + [AttributeUsage(AttributeTargets.Method)] + public class EndpointHandlerAttribute : System.Attribute + { + public string Method; + + public EndpointHandlerAttribute(string method) + { + Method = method; + } + } +} \ No newline at end of file diff --git a/TOOHUCardAPI/Models/PlayerDataRequestObjects.cs b/TOOHUCardAPI/Models/PlayerDataRequestObjects.cs new file mode 100644 index 0000000..2213af6 --- /dev/null +++ b/TOOHUCardAPI/Models/PlayerDataRequestObjects.cs @@ -0,0 +1,8 @@ +namespace TOOHUCardAPI.Models +{ + public class PlayerDataRequestObject + { + public string Method { get; set; } + public string[] Ids { get; set; } + } +} \ No newline at end of file diff --git a/TOOHUCardAPI/Models/PlayerDataResponse.cs b/TOOHUCardAPI/Models/PlayerDataResponseObjects.cs similarity index 93% rename from TOOHUCardAPI/Models/PlayerDataResponse.cs rename to TOOHUCardAPI/Models/PlayerDataResponseObjects.cs index 84d2e0f..85cf95a 100644 --- a/TOOHUCardAPI/Models/PlayerDataResponse.cs +++ b/TOOHUCardAPI/Models/PlayerDataResponseObjects.cs @@ -4,7 +4,7 @@ namespace TOOHUCardAPI.Models * Fields pulled from the game code * Looking up Gamerules.Playerdata */ - public class PlayerDataResponsePlayerObject + public class PlayerDataGetResponseObject { public string Code { get; set; }