From 68437f0a224580de572737d853addadc06cc5970 Mon Sep 17 00:00:00 2001 From: quake1337 Date: Mon, 14 Aug 2017 14:39:22 +0200 Subject: [PATCH 1/5] Add "less than 2gb ram" warning --- TShockAPI/StatTracker.cs | 2 +- TShockAPI/TShock.cs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/TShockAPI/StatTracker.cs b/TShockAPI/StatTracker.cs index 47e5d2cc..61f42d14 100644 --- a/TShockAPI/StatTracker.cs +++ b/TShockAPI/StatTracker.cs @@ -177,7 +177,7 @@ namespace TShockAPI return plugins; } - private long GetTotalSystemRam(bool isMono) + public long GetTotalSystemRam(bool isMono) { if (totalMem != 0) { diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 022e70e5..8a109a08 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -329,6 +329,10 @@ namespace TShockAPI Log.ConsoleInfo("TShock {0} ({1}) now running.", Version, VersionCodename); + if (StatTracker.GetTotalSystemRam(ServerApi.RunningMono) < 2) + { + Log.ConsoleInfo("This machine has less than 2 gigabytes of RAM installed. 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); From e6ec63a90ee17ac374fba66a8ec3441e4ec8f421 Mon Sep 17 00:00:00 2001 From: quake1337 Date: Wed, 20 Sep 2017 09:27:28 +0200 Subject: [PATCH 2/5] Add @ijwu's changes + add /proc/meminfo trick for linux --- TShockAPI/StatTracker.cs | 38 +++++++++++++++++++++++++++++++++++--- TShockAPI/TShock.cs | 6 ++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/TShockAPI/StatTracker.cs b/TShockAPI/StatTracker.cs index 61f42d14..1e4124b6 100644 --- a/TShockAPI/StatTracker.cs +++ b/TShockAPI/StatTracker.cs @@ -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 { @@ -176,7 +177,38 @@ namespace TShockAPI } return plugins; } - + 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; + } + } public long GetTotalSystemRam(bool isMono) { if (totalMem != 0) @@ -267,4 +299,4 @@ namespace TShockAPI /// public bool mono; } -} \ No newline at end of file +} diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 8a109a08..db15277b 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -329,10 +329,12 @@ namespace TShockAPI Log.ConsoleInfo("TShock {0} ({1}) now running.", Version, VersionCodename); - if (StatTracker.GetTotalSystemRam(ServerApi.RunningMono) < 2) + var systemRam = StatTracker.GetFreeSystemRam(ServerApi.RunningMono); + if (systemRam > -1 && systemRam < 2048) { - Log.ConsoleInfo("This machine has less than 2 gigabytes of RAM installed. Be advised that it might not be enough to run TShock."); + 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); From 4aa81a3d308998c83b6ce6269ccacbcc93284227 Mon Sep 17 00:00:00 2001 From: quake1337 Date: Wed, 20 Sep 2017 17:39:38 +0200 Subject: [PATCH 3/5] Add changes requested by @hakusaro --- TShockAPI/StatTracker.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/TShockAPI/StatTracker.cs b/TShockAPI/StatTracker.cs index 1e4124b6..b59d5cbc 100644 --- a/TShockAPI/StatTracker.cs +++ b/TShockAPI/StatTracker.cs @@ -177,6 +177,12 @@ namespace TShockAPI } return plugins; } + + /// + /// Returns the amount of free RAM, in megabytes. + /// + /// Whether or not this program is being executed in a Mono runtime + /// Free RAM memory amount, in megabytes public long GetFreeSystemRam(bool mono) { if (mono) @@ -209,6 +215,11 @@ namespace TShockAPI return pc.RawValue; } } + /// + /// Returns the total amount of installed RAM, in gigabytes. + /// + /// Whether or not this program is being executed in a Mono runtime + /// Total RAM memory amount, in gigabytes public long GetTotalSystemRam(bool isMono) { if (totalMem != 0) From 7d5a74330a6e4b5a611e81abde5dda11336b8686 Mon Sep 17 00:00:00 2001 From: quake1337 Date: Wed, 20 Sep 2017 17:42:32 +0200 Subject: [PATCH 4/5] Ate one newline. --- TShockAPI/StatTracker.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TShockAPI/StatTracker.cs b/TShockAPI/StatTracker.cs index b59d5cbc..1151d170 100644 --- a/TShockAPI/StatTracker.cs +++ b/TShockAPI/StatTracker.cs @@ -215,6 +215,7 @@ namespace TShockAPI return pc.RawValue; } } + /// /// Returns the total amount of installed RAM, in gigabytes. /// From d396dc5cbbd7d4de2b48b24d750ec2e6aeae5c9c Mon Sep 17 00:00:00 2001 From: quake1337 Date: Wed, 20 Sep 2017 18:42:36 +0200 Subject: [PATCH 5/5] Add CHANGELOG.md entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index efa71d54..2e455dab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)