Reworked a lot of how REST works
This commit is contained in:
parent
d824e71507
commit
d7012bd094
3 changed files with 58 additions and 22 deletions
52
TShockAPI/RestManager.cs
Normal file
52
TShockAPI/RestManager.cs
Normal file
|
|
@ -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<string, string> verbs, IParameterCollection parameters, RequestEventArgs request)
|
||||
{
|
||||
var ret = new Dictionary<string, string>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 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(Dictionary<string,string> verbs, IParameterCollection parameters, RequestEventArgs request)
|
||||
{
|
||||
var ret = new Dictionary<string, string>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles exceptions that we didn't catch or that Red fucked up
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@
|
|||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Rest.cs" />
|
||||
<Compile Include="RestManager.cs" />
|
||||
<Compile Include="Tools.cs" />
|
||||
<Compile Include="TShock.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
@ -181,7 +182,7 @@
|
|||
</PropertyGroup>
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_BuildAction="Both" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_StartDate="2011/6/17" BuildVersion_IncrementBeforeBuild="False" />
|
||||
<UserProperties BuildVersion_IncrementBeforeBuild="False" BuildVersion_StartDate="2011/6/17" BuildVersion_BuildVersioningStyle="None.None.None.MonthAndDayStamp" BuildVersion_BuildAction="Both" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" />
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue