diff --git a/TShockAPI/Rest/SecureRest.cs b/TShockAPI/Rest/SecureRest.cs index bf41e2cd..976d6aae 100644 --- a/TShockAPI/Rest/SecureRest.cs +++ b/TShockAPI/Rest/SecureRest.cs @@ -43,6 +43,10 @@ namespace Rests Register(new RestCommand("/token/create/{username}/{password}", NewToken) {RequiresToken = false}); Register(new RestCommand("/v2/token/create/{password}", NewTokenV2) { RequiresToken = false }); Register(new RestCommand("/token/destroy/{token}", DestroyToken) {RequiresToken = true}); + foreach (KeyValuePair t in TShockAPI.TShock.RESTStartupTokens) + { + Tokens.Add(t.Key, t.Value); + } } private object DestroyToken(RestVerbs verbs, IParameterCollection parameters) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index fc880bce..2eefb04f 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -64,6 +64,10 @@ namespace TShockAPI public static RestManager RestManager; public static Utils Utils = new Utils(); public static StatTracker StatTracker = new StatTracker(); + /// + /// Used for implementing REST Tokens prior to the REST system starting up. + /// + public static Dictionary RESTStartupTokens = new Dictionary(); /// /// Called after TShock is initialized. Useful for plugins that needs hooks before tshock but also depend on tshock being loaded. @@ -128,7 +132,7 @@ namespace TShockAPI ConfigFile.ConfigRead += OnConfigRead; FileTools.SetupConfig(); - HandleCommandLine_Port(Environment.GetCommandLineArgs()); + HandleCommandLinePostConfigLoad(Environment.GetCommandLineArgs()); if (Config.StorageType.ToLower() == "sqlite") { @@ -173,7 +177,7 @@ namespace TShockAPI Itembans = new ItemManager(DB); RememberedPos = new RemeberedPosManager(DB); InventoryDB = new InventoryManager(DB); - RestApi = new SecureRest(Netplay.serverListenIP, 8080); + RestApi = new SecureRest(Netplay.serverListenIP, Config.RestApiPort); RestApi.Verify += RestApi_Verify; RestApi.Port = Config.RestApiPort; RestManager = new RestManager(RestApi); @@ -351,7 +355,7 @@ namespace TShockAPI } } - private void HandleCommandLine_Port(string[] parms) + private void HandleCommandLinePostConfigLoad(string[] parms) { for (int i = 0; i < parms.Length; i++) { @@ -363,6 +367,11 @@ namespace TShockAPI OverridePort = true; Log.ConsoleInfo("Port overridden by startup argument. Set to " + port); } + if (parms[i].ToLower() == "-rest-token") + { + string token = Convert.ToString(parms[++i]); + RESTStartupTokens.Add(token, "null"); + } } }