diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs index 13fd0a20..f2f36cc1 100644 --- a/TShockAPI/Properties/AssemblyInfo.cs +++ b/TShockAPI/Properties/AssemblyInfo.cs @@ -36,5 +36,5 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.3.0.0904")] -[assembly: AssemblyFileVersion("3.3.0.0904")] +[assembly: AssemblyVersion("3.3.0.0905")] +[assembly: AssemblyFileVersion("3.3.0.0905")] diff --git a/TShockAPI/RestManager.cs b/TShockAPI/RestManager.cs new file mode 100644 index 00000000..792119c2 --- /dev/null +++ b/TShockAPI/RestManager.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using HttpServer; + +namespace TShockAPI { + + public class RestManager + { + private Rest Rest; + public RestManager(Rest rest) + { + Rest = rest; + } + + public void RegisterRestfulCommands() + { + Rest.Register(new RestCommand("/HelloWorld/name/{username}", usertest)); + } + + #region RestMethods + //http://127.0.0.1:8080/HelloWorld/name/{username}?type=status + object usertest(Dictionary verbs, IParameterCollection parameters, RequestEventArgs request) + { + var ret = new Dictionary(); + var type = parameters["type"]; + if (type == null) + { + ret.Add("Error", "Invalid Type"); + return ret; + } + if (type == "status") + { + ret.Add("Users", "Info here"); + return ret; + } + return null; + } + #endregion + + public void Start() + { + Rest.Start(); + } + + public void Dispose() + { + Rest.Dispose(); + } + } +} diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 62c9691e..eb4e075b 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -69,7 +69,7 @@ namespace TShockAPI public static bool OverridePort; public static PacketBufferer PacketBuffer; public static MaxMind.GeoIPCountry Geo; - public static Rest RestApi; + public static RestManager RestApi; /// /// Called after TShock is initialized. Useful for plugins that needs hooks before tshock but also depend on tshock being loaded. @@ -175,7 +175,7 @@ namespace TShockAPI Regions = new RegionManager(DB); Itembans = new ItemManager(DB); RememberedPos = new RemeberedPosManager(DB); - RestApi = new Rest(IPAddress.Any, 8080); + RestApi = new RestManager(new Rest(IPAddress.Any, 8080)); if (Config.EnableGeoIP) Geo = new MaxMind.GeoIPCountry(Path.Combine(SavePath, "GeoIP.dat")); @@ -205,7 +205,8 @@ namespace TShockAPI if (Initialized != null) Initialized(); - RestApi.Register(new RestCommand("/HelloWorld/name/{username}", usertest)); + RestApi.RegisterRestfulCommands(); + } catch (Exception ex) { @@ -236,24 +237,6 @@ namespace TShockAPI //RconHandler.ShutdownAllThreads(); } - //http://127.0.0.1:8080/HelloWorld/name/{username}?type=status - object usertest(RestVerbs verbs, IParameterCollection parameters, RequestEventArgs request) - { - var ret = new Dictionary(); - var type = parameters["type"]; - if (type == null) - { - ret.Add("Error", "Invalid Type"); - return ret; - } - if (type == "status") - { - ret.Add("Users", "Info here"); - return ret; - } - return null; - } - /// /// Handles exceptions that we didn't catch or that Red fucked up /// diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index f6dfb3e8..adadb917 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -125,6 +125,7 @@ Resources.resx + @@ -181,7 +182,7 @@ - +