Skip to content

Commit 1da2e1c

Browse files
Also make /updates timeout after 10 seconds
1 parent 3cd6d70 commit 1da2e1c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

fCraft/Commands/MaintenanceCommands.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,24 +1347,28 @@ static void DoPlayerDB( Player player, CommandReader cmd ) {
13471347
};
13481348

13491349
static void UpdatesHandler(Player player, CommandReader cmd) {
1350-
DateTime latest = DateTime.UtcNow, current = DateTime.UtcNow;
1351-
current = File.GetLastWriteTime(Process.GetCurrentProcess().MainModule.FileName);
1352-
TimeSpan zipTime = TimeSpan.Zero, currentTime = (DateTime.Now - current);
1350+
DateTime latest = DateTime.UtcNow;
1351+
DateTime current = File.GetLastWriteTimeUtc(Process.GetCurrentProcess().MainModule.FileName);
1352+
13531353
try {
1354-
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://123DMWM.tk/ProCraft/Builds/Latest.zip?");
1354+
Uri uri = new Uri("https://123DMWM.tk/ProCraft/Builds/Latest.zip?");
1355+
HttpWebRequest request = HttpUtil.CreateRequest(uri, TimeSpan.FromSeconds(10));
13551356
request.Method = "HEAD";
13561357

13571358
using (var resp = (HttpWebResponse)request.GetResponse()) {
1358-
latest = resp.LastModified;
1359+
latest = resp.LastModified.ToUniversalTime();
13591360
}
1360-
zipTime = (DateTime.Now - latest);
1361-
player.Message("ProCraft.zip last update (&7" + zipTime.ToMiniString() + " &Sago):");
1361+
1362+
TimeSpan zipDelta = DateTime.UtcNow - latest;
1363+
player.Message("ProCraft.zip last update (&7" + zipDelta.ToMiniString() + " &Sago):");
13621364
player.Message(" &7" + latest.ToLongDateString() + " &Sat &7" + latest.ToLongTimeString());
13631365
} catch (Exception ex) {
13641366
Logger.Log(LogType.Error, "Updates.UpdaterHandler:" + ex);
13651367
player.Message("Cannot access http://123dmwm.tk/ at the moment.");
13661368
}
1367-
player.Message("Server file last update (&7" + currentTime.ToMiniString() + " &Sago):");
1369+
1370+
TimeSpan currentDelta = DateTime.UtcNow - current;
1371+
player.Message("Server file last update (&7" + currentDelta.ToMiniString() + " &Sago):");
13681372
player.Message(" &7" + current.ToLongDateString() + " &Sat &7" + current.ToLongTimeString());
13691373

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

0 commit comments

Comments
 (0)