Skip to content

Commit

Permalink
Merge pull request #40 from nwesterhausen/hotfix/toggle-indepenece
Browse files Browse the repository at this point in the history
Hotfix/toggle indepenece
  • Loading branch information
nwesterhausen authored Oct 7, 2021
2 parents 3a9596d + ece968b commit 169ad00
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 83 deletions.
6 changes: 6 additions & 0 deletions Metadata/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions Metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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": "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"]
Expand Down
191 changes: 111 additions & 80 deletions Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
Expand All @@ -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;
}

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

0 comments on commit 169ad00

Please sign in to comment.