Merge branch 'general-devel-rest' of github.com:TShock/TShock into general-devel-rest
Conflicts: TShockAPI/TShock.cs
This commit is contained in:
commit
595efa4d41
4 changed files with 60 additions and 24 deletions
|
|
@ -36,5 +36,5 @@ using System.Runtime.InteropServices;
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
|
|
||||||
[assembly: AssemblyVersion("3.3.0.0904")]
|
[assembly: AssemblyVersion("3.3.0.0905")]
|
||||||
[assembly: AssemblyFileVersion("3.3.0.0904")]
|
[assembly: AssemblyFileVersion("3.3.0.0905")]
|
||||||
|
|
|
||||||
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 bool OverridePort;
|
||||||
public static PacketBufferer PacketBuffer;
|
public static PacketBufferer PacketBuffer;
|
||||||
public static MaxMind.GeoIPCountry Geo;
|
public static MaxMind.GeoIPCountry Geo;
|
||||||
public static Rest RestApi;
|
public static RestManager RestApi;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called after TShock is initialized. Useful for plugins that needs hooks before tshock but also depend on tshock being loaded.
|
/// 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);
|
Regions = new RegionManager(DB);
|
||||||
Itembans = new ItemManager(DB);
|
Itembans = new ItemManager(DB);
|
||||||
RememberedPos = new RemeberedPosManager(DB);
|
RememberedPos = new RemeberedPosManager(DB);
|
||||||
RestApi = new Rest(IPAddress.Any, 8080);
|
RestApi = new RestManager(new Rest(IPAddress.Any, 8080));
|
||||||
if (Config.EnableGeoIP)
|
if (Config.EnableGeoIP)
|
||||||
Geo = new MaxMind.GeoIPCountry(Path.Combine(SavePath, "GeoIP.dat"));
|
Geo = new MaxMind.GeoIPCountry(Path.Combine(SavePath, "GeoIP.dat"));
|
||||||
|
|
||||||
|
|
@ -205,7 +205,8 @@ namespace TShockAPI
|
||||||
if (Initialized != null)
|
if (Initialized != null)
|
||||||
Initialized();
|
Initialized();
|
||||||
|
|
||||||
RestApi.Register(new RestCommand("/HelloWorld/name/{username}", usertest));
|
RestApi.RegisterRestfulCommands();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -236,24 +237,6 @@ namespace TShockAPI
|
||||||
//RconHandler.ShutdownAllThreads();
|
//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<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>
|
/// <summary>
|
||||||
/// Handles exceptions that we didn't catch or that Red fucked up
|
/// Handles exceptions that we didn't catch or that Red fucked up
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Rest.cs" />
|
<Compile Include="Rest.cs" />
|
||||||
|
<Compile Include="RestManager.cs" />
|
||||||
<Compile Include="Tools.cs" />
|
<Compile Include="Tools.cs" />
|
||||||
<Compile Include="TShock.cs" />
|
<Compile Include="TShock.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|
@ -181,7 +182,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ProjectExtensions>
|
<ProjectExtensions>
|
||||||
<VisualStudio>
|
<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>
|
</VisualStudio>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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