Skip to content

Commit

Permalink
Also make /updates timeout after 10 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jul 4, 2017
1 parent 3cd6d70 commit 1da2e1c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions fCraft/Commands/MaintenanceCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,24 +1347,28 @@ static void DoPlayerDB( Player player, CommandReader cmd ) {
};

static void UpdatesHandler(Player player, CommandReader cmd) {
DateTime latest = DateTime.UtcNow, current = DateTime.UtcNow;
current = File.GetLastWriteTime(Process.GetCurrentProcess().MainModule.FileName);
TimeSpan zipTime = TimeSpan.Zero, currentTime = (DateTime.Now - current);
DateTime latest = DateTime.UtcNow;
DateTime current = File.GetLastWriteTimeUtc(Process.GetCurrentProcess().MainModule.FileName);

try {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://123DMWM.tk/ProCraft/Builds/Latest.zip?");
Uri uri = new Uri("https://123DMWM.tk/ProCraft/Builds/Latest.zip?");
HttpWebRequest request = HttpUtil.CreateRequest(uri, TimeSpan.FromSeconds(10));
request.Method = "HEAD";

using (var resp = (HttpWebResponse)request.GetResponse()) {
latest = resp.LastModified;
latest = resp.LastModified.ToUniversalTime();
}
zipTime = (DateTime.Now - latest);
player.Message("ProCraft.zip last update (&7" + zipTime.ToMiniString() + " &Sago):");

TimeSpan zipDelta = DateTime.UtcNow - latest;
player.Message("ProCraft.zip last update (&7" + zipDelta.ToMiniString() + " &Sago):");
player.Message(" &7" + latest.ToLongDateString() + " &Sat &7" + latest.ToLongTimeString());
} catch (Exception ex) {
Logger.Log(LogType.Error, "Updates.UpdaterHandler:" + ex);
player.Message("Cannot access http://123dmwm.tk/ at the moment.");
}
player.Message("Server file last update (&7" + currentTime.ToMiniString() + " &Sago):");

TimeSpan currentDelta = DateTime.UtcNow - current;
player.Message("Server file last update (&7" + currentDelta.ToMiniString() + " &Sago):");
player.Message(" &7" + current.ToLongDateString() + " &Sat &7" + current.ToLongTimeString());

player.Message("Download updated Zip here: &9http://123DMWM.tk/ProCraft/Builds/Latest.zip");
Expand Down

0 comments on commit 1da2e1c

Please sign in to comment.