diff --git a/Metadata/CHANGELOG.md b/Metadata/CHANGELOG.md index bd6b67c..e69c30e 100644 --- a/Metadata/CHANGELOG.md +++ b/Metadata/CHANGELOG.md @@ -2,6 +2,12 @@ A full changelog for reference. +### Version 0.10.1 + +Hotfix: Message toggles don't act independently. + +This is fixed and you can have join messages disabled and death messages enabled and get death messages sent. + ### Version 0.10.0 Features: diff --git a/Metadata/README.md b/Metadata/README.md index 6ec4746..3169caf 100644 --- a/Metadata/README.md +++ b/Metadata/README.md @@ -33,6 +33,12 @@ Connect your Valheim server (dedicated or served from the game itself) to a Disc Full changelog history available on the [Github repository](https://github.com/nwesterhausen/valheim-discordconnector/blob/main/Metadata/CHANGELOG.md). +### Version 0.10.1 + +Hotfix: Message toggles don't act independently. + +This is fixed and you can have join messages disabled and death messages enabled and get death messages sent. + ### Version 0.10.0 Features: diff --git a/Metadata/manifest.json b/Metadata/manifest.json index d4c43ba..9fd5140 100644 --- a/Metadata/manifest.json +++ b/Metadata/manifest.json @@ -1,6 +1,6 @@ { "name": "DiscordConnector", - "version_number": "0.10.0", + "version_number": "0.10.1", "website_url": "https://github.com/nwesterhausen/valheim-discordconnector", "description": "Connects your Valheim server to a Discord webhook.", "dependencies": ["denikson-BepInExPack_Valheim-5.4.1600"] diff --git a/Patches.cs b/Patches.cs index e7c3eab..7a6b4f3 100644 --- a/Patches.cs +++ b/Patches.cs @@ -51,44 +51,56 @@ internal class RPC_CharacterID private static void Postfix(ZRpc rpc, ZDOID characterID) { ZNetPeer peer = ZNet.instance.GetPeer(rpc); - if (peer == null) return; + if (peer == null) + { + return; + } if (joinedPlayers.IndexOf(peer.m_uid) >= 0) { // Seems that player is dead if character ZDOID id is 0 // m_characterID id=0 means dead, user_id always matches peer.m_uid - if (peer.m_characterID.id != 0 || !Plugin.StaticConfig.PlayerDeathMessageEnabled) return; - string message = Plugin.StaticConfig.DeathMessage.Replace("%PLAYER_NAME%", peer.m_playerName); - if (Plugin.StaticConfig.PlayerDeathPosEnabled) + if (peer.m_characterID.id != 0) { - DiscordApi.SendMessage( - message, - peer.m_refPos - ); + return; } - else + if (Plugin.StaticConfig.PlayerDeathMessageEnabled) { - DiscordApi.SendMessage(message); + string message = Plugin.StaticConfig.DeathMessage.Replace("%PLAYER_NAME%", peer.m_playerName); + if (Plugin.StaticConfig.PlayerDeathPosEnabled) + { + DiscordApi.SendMessage( + message, + peer.m_refPos + ); + } + else + { + DiscordApi.SendMessage(message); + } } if (Plugin.StaticConfig.StatsDeathEnabled) { Plugin.StaticRecords.Store(Categories.Death, peer.m_playerName, 1); } } - else if (Plugin.StaticConfig.PlayerJoinMessageEnabled) + else { // PLAYER JOINED joinedPlayers.Add(peer.m_uid); - string message = Plugin.StaticConfig.JoinMessage.Replace("%PLAYER_NAME%", peer.m_playerName); - if (Plugin.StaticConfig.PlayerJoinPosEnabled) - { - DiscordApi.SendMessage( - message, - peer.m_refPos - ); - } - else + if (Plugin.StaticConfig.PlayerJoinMessageEnabled) { - DiscordApi.SendMessage(message); + string message = Plugin.StaticConfig.JoinMessage.Replace("%PLAYER_NAME%", peer.m_playerName); + if (Plugin.StaticConfig.PlayerJoinPosEnabled) + { + DiscordApi.SendMessage( + message, + peer.m_refPos + ); + } + else + { + DiscordApi.SendMessage(message); + } } if (Plugin.StaticConfig.StatsJoinEnabled) { @@ -103,23 +115,25 @@ internal class RPC_Disconnect { private static void Prefix(ZRpc rpc) { - if (!Plugin.StaticConfig.PlayerLeaveMessageEnabled) return; ZNetPeer peer = ZNet.instance.GetPeer(rpc); if (peer != null && peer.m_uid != 0) { - string message = Plugin.StaticConfig.LeaveMessage.Replace("%PLAYER_NAME%", peer.m_playerName); - if (Plugin.StaticConfig.PlayerLeavePosEnabled) - { - DiscordApi.SendMessage( - message, - peer.m_refPos - ); - } - else + if (Plugin.StaticConfig.PlayerLeaveMessageEnabled) { - DiscordApi.SendMessage( - message - ); + string message = Plugin.StaticConfig.LeaveMessage.Replace("%PLAYER_NAME%", peer.m_playerName); + if (Plugin.StaticConfig.PlayerLeavePosEnabled) + { + DiscordApi.SendMessage( + message, + peer.m_refPos + ); + } + else + { + DiscordApi.SendMessage( + message + ); + } } if (Plugin.StaticConfig.StatsLeaveEnabled) { @@ -138,50 +152,66 @@ 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) { - if (Plugin.StaticConfig.ChatMessageEnabled) + if (Plugin.StaticConfig.MutedPlayers.IndexOf(user) >= 0) { - if (Plugin.StaticConfig.MutedPlayers.IndexOf(user) >= 0) - { - Plugin.StaticLogger.LogInfo($"Ignored shout from user on muted list. User: {user} Shout: {text}. Index {Plugin.StaticConfig.MutedPlayers.IndexOf(user)}"); - return; - } - switch (type) - { - case Talker.Type.Ping: - if (Plugin.StaticConfig.ChatPingEnabled) + Plugin.StaticLogger.LogInfo($"Ignored shout from user on muted list. User: {user} Shout: {text}. Index {Plugin.StaticConfig.MutedPlayers.IndexOf(user)}"); + return; + } + switch (type) + { + case Talker.Type.Ping: + if (Plugin.StaticConfig.ChatPingEnabled) + { + string message = Plugin.StaticConfig.PingMessage.Replace("%PLAYER_NAME%", user); + if (Plugin.StaticConfig.ChatPingPosEnabled) + { + DiscordApi.SendMessage( + message, + pos + ); + } + else { - string message = Plugin.StaticConfig.PingMessage.Replace("%PLAYER_NAME%", user); - if (Plugin.StaticConfig.ChatPingPosEnabled) + DiscordApi.SendMessage(message); + } + } + if (Plugin.StaticConfig.StatsPingEnabled) + { + Plugin.StaticRecords.Store(Categories.Ping, user, 1); + } + break; + case Talker.Type.Shout: + if (text.Equals("I have arrived!")) + { + if (!Plugin.IsHeadless()) + { + if (Plugin.StaticConfig.PlayerJoinMessageEnabled) { - DiscordApi.SendMessage( + string message = Plugin.StaticConfig.JoinMessage.Replace("%PLAYER_NAME%", user); + if (Plugin.StaticConfig.PlayerJoinPosEnabled) + { + DiscordApi.SendMessage( message, pos - ); - } - else - { - DiscordApi.SendMessage(message); - } - if (Plugin.StaticConfig.StatsPingEnabled) - { - Plugin.StaticRecords.Store(Categories.Ping, user, 1); + ); + } + else + { + DiscordApi.SendMessage(message); + } } - } - break; - case Talker.Type.Shout: - if (text.Equals("I have arrived!")) - { - if (!Plugin.IsHeadless()) + if (Plugin.StaticConfig.StatsJoinEnabled) { - DiscordApi.SendMessage( - Plugin.StaticConfig.JoinMessage.Replace("%PLAYER_NAME%", user) - ); + Plugin.StaticRecords.Store(Categories.Join, user, 1); } - Plugin.StaticLogger.LogDebug( - $"{user} shouts 'I have arrived!'" - ); } - else if (Plugin.StaticConfig.ChatShoutEnabled) + Plugin.StaticLogger.LogDebug( + $"{user} shouts 'I have arrived!'" + ); + } + else + { + if (Plugin.StaticConfig.ChatShoutEnabled) { string message = Plugin.StaticConfig.ShoutMessage.Replace("%PLAYER_NAME%", user).Replace("%SHOUT%", text); if (Plugin.StaticConfig.ChatShoutPosEnabled) @@ -195,19 +225,20 @@ private static void Prefix(ref GameObject go, ref long senderID, ref Vector3 pos { DiscordApi.SendMessage(message); } - if (Plugin.StaticConfig.StatsShoutEnabled) - { - Plugin.StaticRecords.Store(Categories.Shout, user, 1); - } } - break; - default: - Plugin.StaticLogger.LogInfo( - $"Ignoring chat message. [{type}] {user}: {text} at {pos}" - ); - break; - } + if (Plugin.StaticConfig.StatsShoutEnabled) + { + Plugin.StaticRecords.Store(Categories.Shout, user, 1); + } + } + break; + default: + Plugin.StaticLogger.LogDebug( + $"Unmatched chat message. [{type}] {user}: {text} at {pos}" + ); + break; } + } } } diff --git a/PluginConfig.cs b/PluginConfig.cs index 8001423..4bad4de 100644 --- a/PluginConfig.cs +++ b/PluginConfig.cs @@ -283,7 +283,7 @@ private void LoadConfig() public bool ChatPingPosEnabled => chatPingPosToggle.Value; public bool PlayerJoinMessageEnabled => playerJoinToggle.Value; public bool PlayerJoinPosEnabled => playerJoinPosToggle.Value; - public bool PlayerDeathMessageEnabled => playerJoinToggle.Value; + public bool PlayerDeathMessageEnabled => playerDeathToggle.Value; public bool PlayerDeathPosEnabled => playerJoinPosToggle.Value; public bool PlayerLeaveMessageEnabled => playerLeaveToggle.Value; public bool PlayerLeavePosEnabled => playerLeavePosToggle.Value; diff --git a/PluginInfo.cs b/PluginInfo.cs index 46cce2a..562c865 100644 --- a/PluginInfo.cs +++ b/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 = "0.10.0"; + public const string PLUGIN_VERSION = "0.10.1"; public const string PLUGIN_REPO_SHORT = "github: nwesterhausen/valheim-discordconnector"; public const string PLUGIN_AUTHOR = "Nicholas Westerhausen"; }