Skip to content

Commit

Permalink
Merge pull request #127 from nwesterhausen/126-bug-saychat-from-sever…
Browse files Browse the repository at this point in the history
…-control-bot-crashes

126 bug saychat from sever control bot crashes
  • Loading branch information
nwesterhausen authored Nov 6, 2022
2 parents 15ed8c8 + 76b23bc commit 118ae1b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Metadata/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions Metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Metadata/manifest.json
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 12 additions & 1 deletion src/Patches/ChatPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,26 @@ 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}.");
return;
}

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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PluginInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down

0 comments on commit 118ae1b

Please sign in to comment.