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/Patches/ChatPatches.cs b/src/Patches/ChatPatches.cs index 956d9ad..5536575 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,15 @@ 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"); + return; + } + // 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) { 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"; }