From 5499f5cc29a29a51033a08c92e3ee3f8ba4b3fa3 Mon Sep 17 00:00:00 2001 From: Nicholas Westerhausen <2317381+nwesterhausen@users.noreply.github.com> Date: Sun, 6 Nov 2022 10:25:04 -0500 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20check=20for=20nulls,?= =?UTF-8?q?=20to=20avoid=20null=20pointers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Patches/ChatPatches.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Patches/ChatPatches.cs b/src/Patches/ChatPatches.cs index 956d9ad..b3c1d89 100644 --- a/src/Patches/ChatPatches.cs +++ b/src/Patches/ChatPatches.cs @@ -11,6 +11,10 @@ internal class OnNewChatMessage { private static void Prefix(ref GameObject go, ref long senderID, ref Vector3 pos, ref Talker.Type type, ref string user, ref string text, ref string senderNetworkUserId) { + if (string.IsNullOrEmpty(user)) + { + Plugin.StaticLogger.LogInfo("Ignored shout from invalid user (null reference)"); + } if (Plugin.StaticConfig.MutedPlayers.IndexOf(user) >= 0 || Plugin.StaticConfig.MutedPlayersRegex.IsMatch(user)) { Plugin.StaticLogger.LogInfo($"Ignored shout from user on muted list. User: {user} Shout: {text}."); @@ -18,8 +22,14 @@ private static void Prefix(ref GameObject go, ref long senderID, ref Vector3 pos } ZNetPeer peerInstance = ZNet.instance.GetPeerByPlayerName(user); + + if (peerInstance == null || peerInstance.m_socket == null) + { + Plugin.StaticLogger.LogInfo($"Ignored shout from {user} because they aren't a real player"); + } + // Get the player's hostname to use for record keeping and logging - string playerHostName = $"{peerInstance.m_socket.GetHostName()}"; + string playerHostName = peerInstance.m_socket.GetHostName(); switch (type) { From c0fe136e0647e37800eeff0ff46831378d884da8 Mon Sep 17 00:00:00 2001 From: Nicholas Westerhausen <2317381+nwesterhausen@users.noreply.github.com> Date: Sun, 6 Nov 2022 11:23:56 -0500 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=F0=9F=9A=91=EF=B8=8F=20return=20whe?= =?UTF-8?q?n=20we=20are=20done?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Patches/ChatPatches.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Patches/ChatPatches.cs b/src/Patches/ChatPatches.cs index b3c1d89..5536575 100644 --- a/src/Patches/ChatPatches.cs +++ b/src/Patches/ChatPatches.cs @@ -26,6 +26,7 @@ private static void Prefix(ref GameObject go, ref long senderID, ref Vector3 pos if (peerInstance == null || peerInstance.m_socket == null) { Plugin.StaticLogger.LogInfo($"Ignored shout from {user} because they aren't a real player"); + return; } // Get the player's hostname to use for record keeping and logging From 76b23bca32db084be941c112375d905499908567 Mon Sep 17 00:00:00 2001 From: Nicholas Westerhausen <2317381+nwesterhausen@users.noreply.github.com> Date: Sun, 6 Nov 2022 11:31:11 -0500 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20=F0=9F=94=96=20prepare=20release?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Metadata/CHANGELOG.md | 8 ++++++++ Metadata/README.md | 8 ++++++++ Metadata/manifest.json | 2 +- docs/changelog.md | 8 ++++++++ src/PluginInfo.cs | 2 +- 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Metadata/CHANGELOG.md b/Metadata/CHANGELOG.md index 77c9392..0dbe9b8 100644 --- a/Metadata/CHANGELOG.md +++ b/Metadata/CHANGELOG.md @@ -4,6 +4,14 @@ A full changelog for reference. ## History +### Version 2.0.2 + +If a shout is performed by a player that isn't a real player (like a mod), it would break the shout call from working. This is because Discord Connector was trying to lookup the player's details and encountering null. The plugin now checks for that and returns early if null is found. + +Fixes: + +- Detect if a shout is by a non-player and gracefully exit. + ### Version 2.0.1 With this update, we bring back Steam_ID variable inclusion and leaderboard message sending (respecting your config settings). I recommend you replace your `discordconnector.valheim.nwest.games-records.db` database, since the records will not line up and will be essentially soft-reset because the column name changed with the different type of data. Steam IDs are prefaced with 'Steam_' now, so you could migrate your stat database with a bit of effort. I believe this could all be done with queries inside the LiteDB Query Tool. diff --git a/Metadata/README.md b/Metadata/README.md index 35c186b..bd66d1b 100644 --- a/Metadata/README.md +++ b/Metadata/README.md @@ -35,6 +35,14 @@ See the [current roadmap](https://github.com/nwesterhausen/valheim-discordconnec ## Changelog +### Version 2.0.2 + +If a shout is performed by a player that isn't a real player (like a mod), it would break the shout call from working. This is because Discord Connector was trying to lookup the player's details and encountering null. The plugin now checks for that and returns early if null is found. + +Fixes: + +- Detect if a shout is by a non-player and gracefully exit. + ### Version 2.0.1 With this update, we bring back Steam_ID variable inclusion and leaderboard message sending (respecting your config settings). I recommend you replace your `discordconnector.valheim.nwest.games-records.db` database, since the records will not line up and will be essentially soft-reset because the column name changed with the different type of data. Steam IDs are prefaced with 'Steam_' now, so you could migrate your stat database with a bit of effort. I believe this could all be done with queries inside the LiteDB Query Tool. diff --git a/Metadata/manifest.json b/Metadata/manifest.json index f07ee3b..421af0b 100644 --- a/Metadata/manifest.json +++ b/Metadata/manifest.json @@ -1,6 +1,6 @@ { "name": "DiscordConnector", - "version_number": "2.0.1", + "version_number": "2.0.2", "website_url": "https://discordconnector.valheim.nwest.games/", "description": "Connects your Valheim server to a Discord webhook. Works for both dedicated and client-hosted servers.", "dependencies": ["denikson-BepInExPack_Valheim-5.4.1901"] diff --git a/docs/changelog.md b/docs/changelog.md index f8d5f7d..cb9ec51 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,14 @@ A full changelog ## History +### Version 2.0.2 + +If a shout is performed by a player that isn't a real player (like a mod), it would break the shout call from working. This is because Discord Connector was trying to lookup the player's details and encountering null. The plugin now checks for that and returns early if null is found. + +Fixes: + +- Detect if a shout is by a non-player and gracefully exit. + ### Version 2.0.1 With this update, we bring back Steam_ID variable inclusion and leaderboard message sending (respecting your config settings). I recommend you replace your `discordconnector.valheim.nwest.games-records.db` database, since the records will not line up and will be essentially soft-reset because the column name changed with the different type of data. Steam IDs are prefaced with 'Steam_' now, so you could migrate your stat database with a bit of effort. I believe this could all be done with queries inside the LiteDB Query Tool. diff --git a/src/PluginInfo.cs b/src/PluginInfo.cs index c1ca1ea..1da33ab 100644 --- a/src/PluginInfo.cs +++ b/src/PluginInfo.cs @@ -17,7 +17,7 @@ internal static class PluginInfo { public const string PLUGIN_ID = "games.nwest.valheim.discordconnector"; public const string PLUGIN_NAME = "Valheim Discord Connector"; - public const string PLUGIN_VERSION = "2.0.1"; + public const string PLUGIN_VERSION = "2.0.2"; public const string PLUGIN_REPO_SHORT = "github: nwesterhausen/valheim-discordconnector"; public const string PLUGIN_AUTHOR = "Nicholas Westerhausen"; }