Added config options for RestApi
-IP now changes RestApi listening ip.
This commit is contained in:
parent
4b694c0c31
commit
f949738db9
3 changed files with 14 additions and 3 deletions
|
|
@ -193,6 +193,12 @@ namespace TShockAPI
|
||||||
[Description("This is used when the API endpoint /status is queried.")]
|
[Description("This is used when the API endpoint /status is queried.")]
|
||||||
public string ServerNickname = "TShock Server";
|
public string ServerNickname = "TShock Server";
|
||||||
|
|
||||||
|
[Description("Enable/Disable the rest api.")]
|
||||||
|
public bool RestApiEnabled = true;
|
||||||
|
|
||||||
|
[Description("This is the port which the rest api will listen on.")]
|
||||||
|
public int RestApiPort = 8080;
|
||||||
|
|
||||||
public static ConfigFile Read(string path)
|
public static ConfigFile Read(string path)
|
||||||
{
|
{
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
|
|
|
||||||
|
|
@ -58,11 +58,11 @@ namespace Rests
|
||||||
|
|
||||||
string hash;
|
string hash;
|
||||||
var rand = new Random();
|
var rand = new Random();
|
||||||
var randbytes = new byte[20];
|
var randbytes = new byte[32];
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
rand.NextBytes(randbytes);
|
rand.NextBytes(randbytes);
|
||||||
hash = Tools.HashPassword(randbytes);
|
hash = randbytes.Aggregate("", (s, b) => s + b.ToString("X2"));
|
||||||
} while (Tokens.ContainsKey(hash));
|
} while (Tokens.ContainsKey(hash));
|
||||||
|
|
||||||
Tokens.Add(hash, user);
|
Tokens.Add(hash, user);
|
||||||
|
|
@ -71,6 +71,8 @@ namespace Rests
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected override object ExecuteCommand(RestCommand cmd, RestVerbs verbs, IParameterCollection parms)
|
protected override object ExecuteCommand(RestCommand cmd, RestVerbs verbs, IParameterCollection parms)
|
||||||
{
|
{
|
||||||
if (cmd.RequiesToken)
|
if (cmd.RequiesToken)
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,7 @@ namespace TShockAPI
|
||||||
RememberedPos = new RemeberedPosManager(DB);
|
RememberedPos = new RemeberedPosManager(DB);
|
||||||
RestApi = new SecureRest(IPAddress.Any, 8080);
|
RestApi = new SecureRest(IPAddress.Any, 8080);
|
||||||
RestApi.Verify += RestApi_Verify;
|
RestApi.Verify += RestApi_Verify;
|
||||||
|
RestApi.Port = Config.RestApiPort;
|
||||||
RestManager = new RestManager(RestApi);
|
RestManager = new RestManager(RestApi);
|
||||||
RestManager.RegisterRestfulCommands();
|
RestManager.RegisterRestfulCommands();
|
||||||
if (Config.EnableGeoIP)
|
if (Config.EnableGeoIP)
|
||||||
|
|
@ -307,6 +308,7 @@ namespace TShockAPI
|
||||||
if (IPAddress.TryParse(parms[++i], out ip))
|
if (IPAddress.TryParse(parms[++i], out ip))
|
||||||
{
|
{
|
||||||
Netplay.serverListenIP = ip;
|
Netplay.serverListenIP = ip;
|
||||||
|
RestApi.Ip = ip;
|
||||||
Console.Write("Using IP: {0}", ip);
|
Console.Write("Using IP: {0}", ip);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -384,7 +386,8 @@ namespace TShockAPI
|
||||||
AuthToken = 0;
|
AuthToken = 0;
|
||||||
}
|
}
|
||||||
Regions.ReloadAllRegions();
|
Regions.ReloadAllRegions();
|
||||||
RestApi.Start();
|
if (Config.RestApiEnabled)
|
||||||
|
RestApi.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue