Update to latest TSAPI. Changed update manager to use same code as stat tracker, which hopefully doesnt break on mono. Also changed it to not check every update to see if time has passed. Made packetbufferer async for windows and if specified for mono. Fixed maxspawns error message to explain range. Ticked version.
This commit is contained in:
parent
1421c23df7
commit
444af6cf57
8 changed files with 83 additions and 52 deletions
|
|
@ -1541,7 +1541,15 @@ namespace TShockAPI
|
|||
private static void CheckUpdates(CommandArgs args)
|
||||
{
|
||||
args.Player.SendInfoMessage("An update check has been queued.");
|
||||
ThreadPool.QueueUserWorkItem(UpdateManager.CheckUpdate);
|
||||
try
|
||||
{
|
||||
TShock.UpdateManager.UpdateCheck(null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//swallow the exception
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdatePlugins(CommandArgs args)
|
||||
|
|
@ -3363,7 +3371,7 @@ namespace TShockAPI
|
|||
int maxSpawns = -1;
|
||||
if (!int.TryParse(args.Parameters[0], out maxSpawns) || maxSpawns < 0 || maxSpawns > Main.maxNPCs)
|
||||
{
|
||||
args.Player.SendWarningMessage("Invalid maximum spawns!");
|
||||
args.Player.SendWarningMessage("Invalid maximum spawns! Acceptable range is {0} to {1}", 0, Main.maxNPCs);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -197,10 +197,10 @@ namespace TShockAPI
|
|||
{
|
||||
if (socket.tcpClient.Client != null && socket.tcpClient.Client.Poll(0, SelectMode.SelectWrite))
|
||||
{
|
||||
if (ServerApi.RunningMono)
|
||||
if (ServerApi.RunningMono && !ServerApi.UseAsyncSocketsInMono)
|
||||
socket.networkStream.Write(buffer, offset, count);
|
||||
else
|
||||
socket.tcpClient.Client.Send(buffer, offset, count, SocketFlags.None);
|
||||
socket.networkStream.BeginWrite(buffer, offset, count, socket.ServerWriteCallBack, socket.networkStream);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,5 +49,5 @@ using System.Runtime.InteropServices;
|
|||
// Build Number
|
||||
// MMdd of the build
|
||||
|
||||
[assembly: AssemblyVersion("4.2.3.0720")]
|
||||
[assembly: AssemblyFileVersion("4.2.3.0720")]
|
||||
[assembly: AssemblyVersion("4.2.3.0909")]
|
||||
[assembly: AssemblyFileVersion("4.2.3.0909")]
|
||||
|
|
|
|||
|
|
@ -28,21 +28,6 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
private HttpWebResponse GetResponseNoException(HttpWebRequest req)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (HttpWebResponse)req.GetResponse();
|
||||
}
|
||||
catch (WebException we)
|
||||
{
|
||||
var resp = we.Response as HttpWebResponse;
|
||||
if (resp == null)
|
||||
throw;
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
|
||||
private void SendUpdate(object info)
|
||||
{
|
||||
Thread.Sleep(1000*60*15);
|
||||
|
|
@ -65,7 +50,7 @@ namespace TShockAPI
|
|||
client.Timeout = 5000;
|
||||
try
|
||||
{
|
||||
using (var resp = GetResponseNoException(client))
|
||||
using (var resp = TShock.Utils.GetResponseNoException(client))
|
||||
{
|
||||
if (resp.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ namespace TShockAPI
|
|||
public static RestManager RestManager;
|
||||
public static Utils Utils = Utils.Instance;
|
||||
public static StatTracker StatTracker = new StatTracker();
|
||||
public static UpdateManager UpdateManager;
|
||||
/// <summary>
|
||||
/// Used for implementing REST Tokens prior to the REST system starting up.
|
||||
/// </summary>
|
||||
|
|
@ -613,6 +614,7 @@ namespace TShockAPI
|
|||
FixChestStacks();
|
||||
|
||||
StatTracker.Initialize();
|
||||
UpdateManager = new UpdateManager();
|
||||
}
|
||||
|
||||
private void ComputeMaxStyles()
|
||||
|
|
@ -656,7 +658,6 @@ namespace TShockAPI
|
|||
|
||||
private void OnUpdate(EventArgs args)
|
||||
{
|
||||
UpdateManager.UpdateProcedureCheck();
|
||||
if (Backups.IsBackupTime)
|
||||
Backups.Backup();
|
||||
//call these every second, not every update
|
||||
|
|
|
|||
|
|
@ -18,32 +18,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
internal class UpdateManager
|
||||
public class UpdateManager
|
||||
{
|
||||
private static string updateUrl = "https://github.com/NyxStudios/TShock/blob/general-devel/tshock_update.json?raw=true";
|
||||
public static DateTime lastcheck = DateTime.MinValue;
|
||||
private string updateUrl = "https://github.com/NyxStudios/TShock/blob/general-devel/tshock_update.json?raw=true";
|
||||
|
||||
/// <summary>
|
||||
/// Check once every X minutes.
|
||||
/// </summary>
|
||||
private static readonly int CheckXMinutes = 30;
|
||||
private readonly int CheckXMinutes = 30;
|
||||
|
||||
public static void UpdateProcedureCheck()
|
||||
public UpdateManager()
|
||||
{
|
||||
if ((DateTime.Now - lastcheck).TotalMinutes >= CheckXMinutes)
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(CheckUpdate);
|
||||
lastcheck = DateTime.Now;
|
||||
}
|
||||
ThreadPool.QueueUserWorkItem(CheckForUpdates);
|
||||
}
|
||||
|
||||
public static void CheckUpdate(object o)
|
||||
private void CheckForUpdates(object state)
|
||||
{
|
||||
try
|
||||
{
|
||||
UpdateCheck(state);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//swallow the exception
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.Sleep(CheckXMinutes * 60 * 1000);
|
||||
ThreadPool.QueueUserWorkItem(CheckForUpdates);
|
||||
}
|
||||
|
||||
public void UpdateCheck(object o)
|
||||
{
|
||||
var updates = ServerIsOutOfDate();
|
||||
if (updates != null)
|
||||
|
|
@ -56,29 +68,39 @@ namespace TShockAPI
|
|||
/// Checks to see if the server is out of date.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static Dictionary<string, string> ServerIsOutOfDate()
|
||||
private Dictionary<string, string> ServerIsOutOfDate()
|
||||
{
|
||||
using (var client = new WebClient())
|
||||
var client = (HttpWebRequest)WebRequest.Create(updateUrl);
|
||||
client.Timeout = 5000;
|
||||
try
|
||||
{
|
||||
client.Headers.Add("user-agent",
|
||||
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)");
|
||||
try
|
||||
using (var resp = TShock.Utils.GetResponseNoException(client))
|
||||
{
|
||||
string updatejson = client.DownloadString(updateUrl);
|
||||
var update = JsonConvert.DeserializeObject<Dictionary<string, string>>(updatejson);
|
||||
var version = new Version(update["version"]);
|
||||
if (TShock.VersionNum.CompareTo(version) < 0)
|
||||
return update;
|
||||
if (resp.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
throw new IOException("Server did not respond with an OK.");
|
||||
}
|
||||
|
||||
using(var reader = new StreamReader(resp.GetResponseStream()))
|
||||
{
|
||||
string updatejson = reader.ReadToEnd();
|
||||
var update = JsonConvert.DeserializeObject<Dictionary<string, string>>(updatejson);
|
||||
var version = new Version(update["version"]);
|
||||
if (TShock.VersionNum.CompareTo(version) < 0)
|
||||
return update;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.ToString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.ConsoleError("UpdateManager Exception: {0}", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void NotifyAdministrators(Dictionary<string, string> update)
|
||||
private void NotifyAdministrators(Dictionary<string, string> update)
|
||||
{
|
||||
var changes = update["changes"].Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
NotifyAdministrator(TSPlayer.Server, changes);
|
||||
|
|
@ -91,7 +113,7 @@ namespace TShockAPI
|
|||
}
|
||||
}
|
||||
|
||||
private static void NotifyAdministrator(TSPlayer player, string[] changes)
|
||||
private void NotifyAdministrator(TSPlayer player, string[] changes)
|
||||
{
|
||||
player.SendMessage("The server is out of date.", Color.Red);
|
||||
for (int j = 0; j < changes.Length; j++)
|
||||
|
|
|
|||
|
|
@ -1014,5 +1014,20 @@ namespace TShockAPI
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
public HttpWebResponse GetResponseNoException(HttpWebRequest req)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (HttpWebResponse)req.GetResponse();
|
||||
}
|
||||
catch (WebException we)
|
||||
{
|
||||
var resp = we.Response as HttpWebResponse;
|
||||
if (resp == null)
|
||||
throw;
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit d446a8288a5d7984f4298a507a64249865259472
|
||||
Subproject commit 2fc5b098323ce7062df5ed91b1c532066fb8cb65
|
||||
Loading…
Add table
Add a link
Reference in a new issue