diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 206db6bd..27dfc469 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using Terraria; @@ -100,10 +101,11 @@ namespace TShockAPI commands.Add(new Command("protectspawn", "editspawn", new CommandDelegate(ProtectSpawn))); commands.Add(new Command("debug-config", "cfg", new CommandDelegate(DebugConfiguration))); commands.Add(new Command("playing", "", new CommandDelegate(Playing))); + commands.Add(new Command("auth", "", new CommandDelegate(AuthToken))); //TShock.admincommandList.Add("debug-config", new CommandDelegate(DebugConfiguration)); //TShock.admincommandList.Add("playing", new CommandDelegate(Playing)); //TShock.commandList.Add("help", new CommandDelegate(Help)); - //TShock.commandList.Add("playing", new CommandDelegate(Playing)); + //TShock.commandList.Add("playing", new CommandDelegate(Playing));); if (ConfigurationManager.distributationAgent != "terraria-online") { commands.Add(new Command("kill", "kill", new CommandDelegate(Kill))); @@ -314,6 +316,20 @@ namespace TShockAPI Tools.SendMessage(ply, "Teleported to your spawnpoint."); } + public static void AuthToken(CommandArgs args) + { + if (ConfigurationManager.authToken == 0) + return; + int givenCode = Convert.ToInt32(args.Message.Remove(0, 5)); + if (givenCode == ConfigurationManager.authToken) + { + TextWriter tw = new StreamWriter(FileTools.SaveDir + "users.txt", true); + tw.WriteLine(Tools.GetRealIP(Convert.ToString(Netplay.serverSock[args.PlayerID].tcpClient.Client.RemoteEndPoint)) + " superadmin"); + Tools.SendMessage(args.PlayerID, "SuperAdmin authenticated. Please re-connect using the same IP."); + ConfigurationManager.authToken = 0; + } + } + public static void TP(CommandArgs args) { int ply = args.PlayerID; diff --git a/TShockAPI/ConfigurationManager.cs b/TShockAPI/ConfigurationManager.cs index 5090e0e9..7927645a 100644 --- a/TShockAPI/ConfigurationManager.cs +++ b/TShockAPI/ConfigurationManager.cs @@ -32,6 +32,7 @@ namespace TShockAPI public static bool spawnProtect = true; public static int spawnProtectRadius = 5; public static string distributationAgent = "facepunch"; + public static int authToken = 0; public enum NPCList : int { @@ -79,10 +80,7 @@ namespace TShockAPI return; } else - { FileTools.CreateFile(FileTools.SaveDir + "config.json"); - } - ConfigFile cfg = new ConfigFile(); cfg.InvasionMultiplier = 50; cfg.DefaultMaximumSpawns = 4; diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 9efc5314..5554f3d9 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -15,9 +15,9 @@ namespace TShockAPI public static string saveDir = "./tshock/"; - public static Version VersionNum = new Version(1, 7, 0, 0); + public static Version VersionNum = new Version(1, 8, 0, 0); - public static string VersionCodename = "Facepunch"; + public static string VersionCodename = "Fuck the wiki!"; public static bool shownVersion = false; @@ -111,6 +111,14 @@ namespace TShockAPI Console.WriteLine(ex.ToString()); } Console.WriteLine("TShock Version " + Version.Major + "." + Version.Minor + "." + Version.Build + "." + Version.Revision + " (" + VersionCodename + ") now running."); + if (!System.IO.File.Exists(FileTools.SaveDir + "auth.lck")) + { + Random r = new Random((int)System.DateTime.Now.ToBinary()); + ConfigurationManager.authToken = r.Next(100000, 10000000); + Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type /auth " + ConfigurationManager.authToken); + Console.WriteLine("This token will only display ONCE."); + FileTools.CreateFile(FileTools.SaveDir + "auth.lck"); + } Log.Initialize(FileTools.SaveDir + "log.txt", LogLevel.All, true); Log.Info("Starting..."); GameHooks.OnPreInitialize += OnPreInit; @@ -484,7 +492,6 @@ namespace TShockAPI void OnPreInit() { - FileTools.SetupConfig(); } void OnPostInit()