Merge pull request #1486 from bartico6/issue-1485
Add "less than 2gb ram" warning
This commit is contained in:
commit
623815b9f6
3 changed files with 54 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
|
|||
* Validated tile placement on PlaceObject; clients can no longer place frames, paintings etc with dirt blocks (@bartico6, @ProfessorXZ)
|
||||
* Updated to new stat tracking system with more data so we can actually make informed software decisions (Jordan Coulam)
|
||||
* Fixed /time display at the end of Terraria hours (@koneko-nyan)
|
||||
* Added a warning notifying users of the minimum memory required to run TShock (@bartico6)
|
||||
|
||||
## TShock 4.3.24
|
||||
* API: Changed `PlayerHooks` permission hook mechanisms to allow negation from hooks (@deadsurgeon42)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ using System.Runtime.InteropServices;
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using TShockAPI.Extensions;
|
||||
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -177,7 +178,50 @@ namespace TShockAPI
|
|||
return plugins;
|
||||
}
|
||||
|
||||
private long GetTotalSystemRam(bool isMono)
|
||||
/// <summary>
|
||||
/// Returns the amount of free RAM, in megabytes.
|
||||
/// </summary>
|
||||
/// <param name="mono">Whether or not this program is being executed in a Mono runtime</param>
|
||||
/// <returns>Free RAM memory amount, in megabytes</returns>
|
||||
public long GetFreeSystemRam(bool mono)
|
||||
{
|
||||
if (mono)
|
||||
{
|
||||
//Temporary in case mono won't work
|
||||
if (File.Exists("/proc/meminfo"))
|
||||
{
|
||||
var l = File.ReadAllLines("/proc/meminfo");
|
||||
foreach (string s in l)
|
||||
{
|
||||
if (s.StartsWith("MemFree:"))
|
||||
{
|
||||
var m = Regex.Match(s, "MemFree:(\\s*)(\\d*) kB");
|
||||
if (m.Success)
|
||||
{
|
||||
long val;
|
||||
if (long.TryParse(m.Groups[2].Value, out val))
|
||||
{
|
||||
return val / 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
var pc = new PerformanceCounter("Memory", "Available MBytes");
|
||||
return pc.RawValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the total amount of installed RAM, in gigabytes.
|
||||
/// </summary>
|
||||
/// <param name="isMono">Whether or not this program is being executed in a Mono runtime</param>
|
||||
/// <returns>Total RAM memory amount, in gigabytes</returns>
|
||||
public long GetTotalSystemRam(bool isMono)
|
||||
{
|
||||
if (totalMem != 0)
|
||||
{
|
||||
|
|
@ -267,4 +311,4 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
public bool mono;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -329,6 +329,12 @@ namespace TShockAPI
|
|||
|
||||
Log.ConsoleInfo("TShock {0} ({1}) now running.", Version, VersionCodename);
|
||||
|
||||
var systemRam = StatTracker.GetFreeSystemRam(ServerApi.RunningMono);
|
||||
if (systemRam > -1 && systemRam < 2048)
|
||||
{
|
||||
Log.ConsoleError("This machine has less than 2 gigabytes of RAM free. Be advised that it might not be enough to run TShock.");
|
||||
}
|
||||
|
||||
ServerApi.Hooks.GamePostInitialize.Register(this, OnPostInit);
|
||||
ServerApi.Hooks.GameUpdate.Register(this, OnUpdate);
|
||||
ServerApi.Hooks.GameHardmodeTileUpdate.Register(this, OnHardUpdate);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue