diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 3058c91f..8c2c7c36 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; +using System.Diagnostics; +using System.Net; using Microsoft.Xna.Framework; using Terraria; @@ -850,6 +852,39 @@ namespace TShockAPI "Spawn is now " + (ConfigurationManager.spawnProtect ? "protected" : "open") + "."); } + public static void UpdateNow(CommandArgs args) + { + Process TServer = Process.GetCurrentProcess(); + + StreamWriter sw = new StreamWriter("pid"); + sw.Write(TServer.Id); + sw.Close(); + + sw = new StreamWriter("pn"); + sw.Write(TServer.ProcessName + " " + Environment.CommandLine); + sw.Close(); + + WebClient client = new WebClient(); + client.Headers.Add("user-agent", "TShock"); + byte[] updatefile = client.DownloadData("http://tsupdate.shankshock.com/UpdateTShock.exe"); + + BinaryWriter bw = new BinaryWriter(new FileStream("UpdateTShock.exe", FileMode.Create)); + bw.Write(updatefile); + bw.Close(); + + Process.Start(new ProcessStartInfo("UpdateTShock.exe")); + + for (int player = 0; player < Main.maxPlayers; player++) + { + if (Main.player[player].active) + { + Tools.ForceKick(player, "Server shutting down for update!"); + } + } + WorldGen.saveWorld(); + Netplay.disconnect = true; + } + #endregion Command Methods } } \ No newline at end of file diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 8e92738a..eb2996eb 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -24,6 +24,8 @@ namespace TShockAPI private static bool[] BlacklistTiles; + public static bool updateCmd; + public static BanManager Bans = new BanManager(Path.Combine(saveDir, "bans.txt")); public override Version Version @@ -665,7 +667,12 @@ namespace TShockAPI float[] color = { 255, 255, 000 }; if (VersionNum.CompareTo(updateVersion) < 0) { - Tools.SendMessage(ply, "This server is out of date."); + Tools.SendMessage(ply, "This server is out of date, to update now type /updatenow"); + if (!updateCmd) + { + Commands.commands.Add(new Commands.Command("/updatenow", "maintenance", Commands.UpdateNow)); + updateCmd = true; + } for (int i = 4; i <= changes.Length; i++) { Tools.SendMessage(ply, changes[i], color);