Got TShock's part of updating done, waiting from ftp access from shank to test

This commit is contained in:
Maverick Motherfucker 2011-06-07 19:04:35 -07:00
parent e61d0a74fe
commit 61624249a2
2 changed files with 43 additions and 1 deletions

View file

@ -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
}
}

View file

@ -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);