Fixed the update check spamming.
Moved the update check out of the main thread to prevent locking up the server.
This commit is contained in:
parent
9d193ba651
commit
55000158ee
2 changed files with 25 additions and 16 deletions
|
|
@ -4,6 +4,7 @@ using System.IO;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Threading;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
|
|
||||||
|
|
@ -127,7 +128,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
public static void CheckUpdates(CommandArgs args)
|
public static void CheckUpdates(CommandArgs args)
|
||||||
{
|
{
|
||||||
UpdateManager.CheckUpdate();
|
ThreadPool.QueueUserWorkItem(UpdateManager.CheckUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PartyChat(CommandArgs args)
|
public static void PartyChat(CommandArgs args)
|
||||||
|
|
@ -231,10 +232,11 @@ namespace TShockAPI
|
||||||
{
|
{
|
||||||
string ip = args.Message.Split(' ')[1];
|
string ip = args.Message.Split(' ')[1];
|
||||||
TShock.Bans.AddBan(ip, "", "Manually added IP address ban.");
|
TShock.Bans.AddBan(ip, "", "Manually added IP address ban.");
|
||||||
} else if (args.Message.Split(' ').Length > 2)
|
}
|
||||||
|
else if (args.Message.Split(' ').Length > 2)
|
||||||
{
|
{
|
||||||
string reason = "";
|
string reason = "";
|
||||||
for (int i = 2; i > args.Message.Split(' ').Length;i++)
|
for (int i = 2; i > args.Message.Split(' ').Length; i++)
|
||||||
{
|
{
|
||||||
reason += args.Message.Split(' ')[i];
|
reason += args.Message.Split(' ')[i];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,23 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Terraria;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
class UpdateManager
|
class UpdateManager
|
||||||
{
|
{
|
||||||
static string updateUrl = "http://shankshock.com/tshock-update.txt";
|
static string updateUrl = "http://shankshock.com/tshock-update.txt";
|
||||||
public static bool updateCmd;
|
public static bool updateCmd;
|
||||||
public static long updateEpoch = 0;
|
public static DateTime lastcheck = DateTime.MinValue;
|
||||||
public static string[] globalChanges = {};
|
public static string[] globalChanges = {};
|
||||||
|
/// <summary>
|
||||||
|
/// Check once every X minutes.
|
||||||
|
/// </summary>
|
||||||
|
static readonly int CheckXMinutes = 30;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks to see if the server is out of date.
|
/// Checks to see if the server is out of date.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -48,31 +55,31 @@ namespace TShockAPI
|
||||||
|
|
||||||
public static void NotifyAdministrators(string[] changes)
|
public static void NotifyAdministrators(string[] changes)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ConfigurationManager.maxSlots; i++)
|
for (int i = 0; i < Main.maxPlayers; i++)
|
||||||
{
|
{
|
||||||
if (Terraria.Main.player[i].active)
|
if (Main.player[i].active)
|
||||||
{
|
{
|
||||||
if (!TShock.players[i].group.HasPermission("maintenance"))
|
if (!TShock.players[i].group.HasPermission("maintenance"))
|
||||||
return;
|
return;
|
||||||
Tools.SendMessage(i, "The server is out of date. To update, type /updatenow.");
|
Tools.SendMessage(i, "The server is out of date. To update, type /updatenow.");
|
||||||
for (int j = 4; j <= changes.Length; j++)
|
for (int j = 4; j < changes.Length; j++)
|
||||||
{
|
{
|
||||||
Tools.SendMessage(i, changes[i], new float[] { 255, 0, 0 });
|
Tools.SendMessage(i, changes[j], new float[] { 255, 0, 0 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateProcedureCheck()
|
public static void UpdateProcedureCheck()
|
||||||
{
|
{
|
||||||
long currentEpoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
|
if ((DateTime.Now - lastcheck).TotalMinutes >= CheckXMinutes)
|
||||||
if (currentEpoch > UpdateManager.updateEpoch)
|
|
||||||
{
|
{
|
||||||
CheckUpdate();
|
ThreadPool.QueueUserWorkItem(CheckUpdate);
|
||||||
|
lastcheck = DateTime.Now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CheckUpdate()
|
public static void CheckUpdate(object o)
|
||||||
{
|
{
|
||||||
if (ServerIsOutOfDate())
|
if (ServerIsOutOfDate())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue