From 65fe410c31f1b890e15e94d08d550dbb030cf49b Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Mon, 24 Oct 2016 10:58:17 -0600 Subject: [PATCH] Fix KnownIps == 0 causing .Last() to fail (Fixes #1319 again). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to @Simon311 for being able to read. We love you. 💘 "You should laugh at yourself at least once every day." --- CHANGELOG.md | 2 +- TShockAPI/TShock.cs | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f16918c..1a1aeea2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * `/v2/server/rawcmd` (@WhiteXZ). * Fixed `/user group` always giving an unhelpful error messaging telling you to check the console, even if we knew exactly why it failed (@nicatronTg). * Removed _all obsolete methods in TShock marked obsolete prior to this version (all of them)_ (@nicatronTg). -* Fixed issue where registration + login would fail with no pre-existing users (@DogooFalchion). +* Fixed issue where registration + login would fail because KnownIps had 0 items and .Last() doesn't work on collections with 0 items (@DogooFalchion, @nicatronTg, @Simon311). * Added `/uploadssc [player]` which allows someone to upload SSC data for [player] and store it on the server. Adds `tshock.ssc.upload` and `tshock.ssc.upload.others` permission nodes to match (@DogooFalchion). * Added hardened stone to the whitelist of tiles editable by players (@DogooFalchion). * Added conversion system to send convert old MOTD format into smart text, while preserving initial line starting values to keep byte optimization for background colors Thanks to (@WhiteXZ, @Simon311, and especially @DogooFalchion) for the hard work on this issue. diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 9a6aac10..9e459ec2 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -409,16 +409,23 @@ namespace TShockAPI KnownIps = JsonConvert.DeserializeObject>(args.Player.User.KnownIps); } - bool last = KnownIps.Last() == args.Player.IP; - if (!last) + if (KnownIps.Count == 0) { - if (KnownIps.Count == 100) - { - KnownIps.RemoveAt(0); - } - KnownIps.Add(args.Player.IP); } + else + { + bool last = KnownIps.Last() == args.Player.IP; + if (!last) + { + if (KnownIps.Count == 100) + { + KnownIps.RemoveAt(0); + } + + KnownIps.Add(args.Player.IP); + } + } args.Player.User.KnownIps = JsonConvert.SerializeObject(KnownIps, Formatting.Indented); Users.UpdateLogin(args.Player.User);