From b387d42e5342eb2c3eda941a40f0a2ec922b0677 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 16 Jul 2017 21:21:42 -0600 Subject: [PATCH 01/14] Add PR template file --- PULL_REQUEST_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 PULL_REQUEST_TEMPLATE.md diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..9e7b1cc8 --- /dev/null +++ b/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1 @@ + From 4216501c458698b2235a185f3912cf6bfd5dcfcc Mon Sep 17 00:00:00 2001 From: Ruby Rose Date: Thu, 13 Jul 2017 16:00:40 +0300 Subject: [PATCH 02/14] Make User implement IEquatable for more consistent comparisons --- TShockAPI/DB/UserManager.cs | 64 ++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index e79fb933..88103899 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -363,7 +363,7 @@ namespace TShockAPI.DB } /// A database user. - public class User + public class User : IEquatable { /// The database ID of the user. public int ID { get; set; } @@ -581,10 +581,66 @@ namespace TShockAPI.DB return HashPassword(Encoding.UTF8.GetBytes(password)); } - } + #region IEquatable - /// UserManagerException - An exception generated by the user manager. - [Serializable] + /// Indicates whether the current is equal to another . + /// true if the is equal to the parameter; otherwise, false. + /// An to compare with this . + public bool Equals(User other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return ID == other.ID && string.Equals(Name, other.Name); + } + + /// Indicates whether the current is equal to another object. + /// true if the is equal to the parameter; otherwise, false. + /// An to compare with this . + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((User)obj); + } + + /// Serves as the hash function. + /// A hash code for the current . + public override int GetHashCode() + { + unchecked + { + return (ID * 397) ^ (Name != null ? Name.GetHashCode() : 0); + } + } + + /// + /// Compares equality of two objects. + /// + /// Left hand of the comparison. + /// Right hand of the comparison. + /// true if the objects are equal; otherwise, false. + public static bool operator ==(User left, User right) + { + return Equals(left, right); + } + + /// + /// Compares equality of two objects. + /// + /// Left hand of the comparison. + /// Right hand of the comparison. + /// true if the objects aren't equal; otherwise, false. + public static bool operator !=(User left, User right) + { + return !Equals(left, right); + } + + #endregion + } + + /// UserManagerException - An exception generated by the user manager. + [Serializable] public class UserManagerException : Exception { /// Creates a new UserManagerException object. From c8e31231ba135465160eb43e20858d3c38c41a68 Mon Sep 17 00:00:00 2001 From: Ruby Rose Date: Thu, 13 Jul 2017 16:01:47 +0300 Subject: [PATCH 03/14] override ToString of user --- TShockAPI/DB/UserManager.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 88103899..f93f9935 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -637,7 +637,12 @@ namespace TShockAPI.DB } #endregion - } + + public override string ToString() + { + return Name; + } + } /// UserManagerException - An exception generated by the user manager. [Serializable] From 5e1be5b19b08350d833a96c46917248641b32782 Mon Sep 17 00:00:00 2001 From: Ruby Rose Date: Thu, 13 Jul 2017 16:04:17 +0300 Subject: [PATCH 04/14] Fix formatting below IEquatable block --- TShockAPI/DB/UserManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index f93f9935..368c2dae 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -644,8 +644,8 @@ namespace TShockAPI.DB } } - /// UserManagerException - An exception generated by the user manager. - [Serializable] + /// UserManagerException - An exception generated by the user manager. + [Serializable] public class UserManagerException : Exception { /// Creates a new UserManagerException object. @@ -704,4 +704,4 @@ namespace TShockAPI.DB { } } -} \ No newline at end of file +} From 02be378a2ec5b71ab1e878d22ac14a37b19f3da1 Mon Sep 17 00:00:00 2001 From: Ruby Rose Date: Fri, 14 Jul 2017 08:03:16 +0300 Subject: [PATCH 05/14] change doc of Equals --- TShockAPI/DB/UserManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/DB/UserManager.cs b/TShockAPI/DB/UserManager.cs index 368c2dae..07662b2b 100644 --- a/TShockAPI/DB/UserManager.cs +++ b/TShockAPI/DB/UserManager.cs @@ -595,7 +595,7 @@ namespace TShockAPI.DB /// Indicates whether the current is equal to another object. /// true if the is equal to the parameter; otherwise, false. - /// An to compare with this . + /// An to compare with this . public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; From 031ef517e3875e7be8edae0ae53b95052daff4a2 Mon Sep 17 00:00:00 2001 From: quake1337 Date: Fri, 4 Aug 2017 12:52:07 +0200 Subject: [PATCH 06/14] Change field visibility --- TShockAPI/Sockets/LinuxTcpSocket.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/TShockAPI/Sockets/LinuxTcpSocket.cs b/TShockAPI/Sockets/LinuxTcpSocket.cs index 98df1674..86381237 100644 --- a/TShockAPI/Sockets/LinuxTcpSocket.cs +++ b/TShockAPI/Sockets/LinuxTcpSocket.cs @@ -12,23 +12,23 @@ namespace TShockAPI.Sockets { public class LinuxTcpSocket : ISocket { - private byte[] _packetBuffer = new byte[1024]; + public byte[] _packetBuffer = new byte[1024]; - private int _packetBufferLength; + public int _packetBufferLength; - private List _callbackBuffer = new List(); + public List _callbackBuffer = new List(); - private int _messagesInQueue; + public int _messagesInQueue; - private TcpClient _connection; + public TcpClient _connection; - private TcpListener _listener; + public TcpListener _listener; - private SocketConnectionAccepted _listenerCallback; + public SocketConnectionAccepted _listenerCallback; - private RemoteAddress _remoteAddress; + public RemoteAddress _remoteAddress; - private bool _isListening; + public bool _isListening; public int MessagesInQueue { From 68437f0a224580de572737d853addadc06cc5970 Mon Sep 17 00:00:00 2001 From: quake1337 Date: Mon, 14 Aug 2017 14:39:22 +0200 Subject: [PATCH 07/14] 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 5a04b6651427dca02018effe87ab4ae208cf48fe Mon Sep 17 00:00:00 2001 From: ProfessorXZ Date: Fri, 8 Sep 2017 21:59:13 +0200 Subject: [PATCH 08/14] Make Utils.GetBuffDescription actually return the buff's description & properly read 'buffTime' from the stream. Fixes #1469 --- TShockAPI/GetDataHandlers.cs | 8 ++++---- TShockAPI/Utils.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 77e37c03..b593af2c 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -895,14 +895,14 @@ namespace TShockAPI /// /// Time the buff lasts /// - public short Time { get; set; } + public int Time { get; set; } } /// /// PlayerBuff - Called when a player is buffed /// public static HandlerList PlayerBuff; - private static bool OnPlayerBuff(byte id, byte type, short time) + private static bool OnPlayerBuff(byte id, byte type, int time) { if (PlayerBuff == null) return false; @@ -911,7 +911,7 @@ namespace TShockAPI { ID = id, Type = type, - Time = time, + Time = time }; PlayerBuff.Invoke(null, args); return args.Handled; @@ -3425,7 +3425,7 @@ namespace TShockAPI { var id = args.Data.ReadInt8(); var type = args.Data.ReadInt8(); - var time = args.Data.ReadInt16(); + var time = args.Data.ReadInt32(); if (OnPlayerBuff(id, type, time)) return true; diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 520bed9c..5081f8e4 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -465,7 +465,7 @@ namespace TShockAPI /// description public string GetBuffDescription(int id) { - return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffName(id) : "null"; + return (id > 0 && id < Main.maxBuffTypes) ? Lang.GetBuffDescription(id) : "null"; } /// From c8549db08726122a5ea1cc62946fc1fe3249d625 Mon Sep 17 00:00:00 2001 From: koneko-nyan <31385587+koneko-nyan@users.noreply.github.com> Date: Tue, 19 Sep 2017 21:00:15 +0200 Subject: [PATCH 09/14] Update Commands.cs (time % 1.0) * 60.0 can be equal to 59.8, then it gets rounded to undesirable 60 displayed in the time format --- TShockAPI/Commands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 5e7b84bf..fbc6c061 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -3872,7 +3872,7 @@ namespace TShockAPI if (!Main.dayTime) time += 15.0; time = time % 24.0; - args.Player.SendInfoMessage("The current time is {0}:{1:D2}.", (int)Math.Floor(time), (int)Math.Round((time % 1.0) * 60.0)); + args.Player.SendInfoMessage("The current time is {0}:{1:D2}.", (int)Math.Floor(time), (int)Math.Floor((time % 1.0) * 60.0)); return; } From 65582ceaecb4be28acecf88059a4bc4798e38bbd Mon Sep 17 00:00:00 2001 From: koneko-nyan <31385587+koneko-nyan@users.noreply.github.com> Date: Tue, 19 Sep 2017 21:22:56 +0200 Subject: [PATCH 10/14] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7ab5308..efa71d54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Fixed /spawnmob not spawning negative IDs (@MarioE) * 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) ## TShock 4.3.24 * API: Changed `PlayerHooks` permission hook mechanisms to allow negation from hooks (@deadsurgeon42) From e6ec63a90ee17ac374fba66a8ec3441e4ec8f421 Mon Sep 17 00:00:00 2001 From: quake1337 Date: Wed, 20 Sep 2017 09:27:28 +0200 Subject: [PATCH 11/14] 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 12/14] 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 13/14] 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 14/14] 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)