Skip to content

Commit

Permalink
fix: 🚑️ fix issues preventing player join/leave from being sent
Browse files Browse the repository at this point in the history
due to changes in Valheim to using PlayFab, any previous methods of using the steamid in the plugin are broken

Records reset, cannot use %STEAMID% variable, periodic leaderboard with never be sent
  • Loading branch information
nwesterhausen committed Nov 2, 2022
1 parent c795f86 commit cd991fb
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 99 deletions.
10 changes: 10 additions & 0 deletions Metadata/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

A full changelog for reference.

### Version 2.0.0

Previous version broke with the new updates to Valheim using the PlayFab server stuff. Previously, the steam ID was grabbed directly from the socket but that doesn't work anymore. To get something workable (the other messages work), I have removed the code which tried to get the SteamID and disabled leaderboard sending.

Breaking changes:

- Removed steamid variable (internally) and tracking stats by steamid. This broke with the PlayFab changes to Valheim. It will be a bit involved to figure out how to deliver the same thing again, so if you have an idea or seen it done in another mod, please reach out with a Github Issue or ping on Discord.
- Leaderboard records will reset and a new database with suffix '-records2.db' will be saved anew. This is because what is being tracked is changed (used to be steamid, now it is using the character id).
- Perodic leaderboard messages will not send, ignoring the setting in the config (for now). This is until a more reliable method of determining players apart.

### Version 1.8.0

Features:
Expand Down
4 changes: 2 additions & 2 deletions Metadata/DiscordConnector-Nexus.readme
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DISCORD CONNECTOR - 1.8.0
DISCORD CONNECTOR - 2.0.0
Connect your Valheim server to a Discord Webhook. Works for both dedicated and client-hosted servers. (Visit the github repo for a how-to guide.)

:: REQUIREMENTS ::
Expand All @@ -11,7 +11,7 @@ Connect your Valheim server to a Discord Webhook. Works for both dedicated and c
- Optionally set multiple messages for each notification and have a random message sent
- Supports both the client and the server
- Will use an embed for coordinates if enabled
- Periodic leader board messages with death,ping,shout and join|leave leader. (optional)
- ~Periodic leader board messages with death,ping,shout and join|leave leader. (optional)~ (disabled in 2.0.0)
- A message for the first time a player does something (join and death by default, can be entirely disabled)
- Add almost anything to your messages with 10 user defined variables

Expand Down
10 changes: 10 additions & 0 deletions Metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ See the [current roadmap](https://github.com/nwesterhausen/valheim-discordconnec

## Changelog

### Version 2.0.0

Previous version broke with the new updates to Valheim using the PlayFab server stuff. Previously, the steam ID was grabbed directly from the socket but that doesn't work anymore. To get something workable (the other messages work), I have removed the code which tried to get the SteamID and disabled leaderboard sending.

Breaking changes:

- Removed steamid variable (internally) and tracking stats by steamid. This broke with the PlayFab changes to Valheim. It will be a bit involved to figure out how to deliver the same thing again, so if you have an idea or seen it done in another mod, please reach out with a Github Issue or ping on Discord.
- Leaderboard records will reset and a new database with suffix '-records2.db' will be saved anew. This is because what is being tracked is changed (used to be steamid, now it is using the character id).
- Perodic leaderboard messages will not send, ignoring the setting in the config (for now). This is until a more reliable method of determining players apart.

### Version 1.8.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": "1.8.0",
"version_number": "2.0.0",
"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
10 changes: 10 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

A full changelog

### Version 2.0.0

Previous version broke with the new updates to Valheim using the PlayFab server stuff. Previously, the steam ID was grabbed directly from the socket but that doesn't work anymore. To get something workable (the other messages work), I have removed the code which tried to get the SteamID and disabled leaderboard sending.

Breaking changes:

- Removed steamid variable (internally) and tracking stats by steamid. This broke with the PlayFab changes to Valheim. It will be a bit involved to figure out how to deliver the same thing again, so if you have an idea or seen it done in another mod, please reach out with a Github Issue or ping on Discord.
- Leaderboard records will reset and a new database with suffix '-records2.db' will be saved anew. This is because what is being tracked is changed (used to be steamid, now it is using the character id).
- Perodic leaderboard messages will not send, ignoring the setting in the config (for now). This is until a more reliable method of determining players apart.

### Version 1.8.0

Features:
Expand Down
3 changes: 2 additions & 1 deletion src/Config/MainConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public string ConfigAsJson()
}

public string WebHookURL => webhookUrl.Value;
public bool StatsAnnouncementEnabled => statsAnnouncementToggle.Value;
// public bool StatsAnnouncementEnabled => statsAnnouncementToggle.Value;
public bool StatsAnnouncementEnabled => false; // Hard-coded false due to issues with the playFab changes
public int StatsAnnouncementPeriod => statsAnnouncementPeriod.Value;
public bool CollectStatsEnabled => colectStatsToggle.Value;
public bool DiscordEmbedsEnabled => discordEmbedMessagesToggle.Value;
Expand Down
2 changes: 1 addition & 1 deletion src/MessageTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static string FormatServerMessage(string rawMessage)
public static string FormatPlayerMessage(string rawMessage, string playerName, string playerSteamId)
{
return MessageTransformer.ReplaceVariables(rawMessage)
.Replace(PLAYER_STEAMID, playerSteamId)
.Replace(PLAYER_STEAMID, "")
.Replace(PLAYER_NAME, playerName);
}

Expand Down
35 changes: 17 additions & 18 deletions src/Patches/ChatPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,34 @@ internal class ChatPatches
[HarmonyPatch(typeof(Chat), nameof(Chat.OnNewChatMessage))]
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)
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 (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;
}
ulong peerSteamID = 0;
ZNetPeer peerInstance = ZNet.instance.GetPeerByPlayerName(user);
if (peerInstance != null)
{
peerSteamID = ((ZSteamSocket)peerInstance.m_socket).GetPeerID().m_SteamID; // Get the SteamID from peer.
}

// Player steam ID is no longer guarenteed. Instead use the characterId (if possible)
string playerCharacterId = $"{peerInstance.m_characterID}"; // Player SteamID is not guarenteed, so a work-around is needed.

switch (type)
{
case Talker.Type.Ping:
if (Plugin.StaticConfig.AnnouncePlayerFirstPingEnabled && Plugin.StaticDatabase.CountOfRecordsByName(Records.Categories.Ping, user) == 0)
{
DiscordApi.SendMessage(
MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PlayerFirstPingMessage, user, peerSteamID.ToString())
MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PlayerFirstPingMessage, user, playerCharacterId.ToString())
);
}
if (Plugin.StaticConfig.StatsPingEnabled)
{
Plugin.StaticDatabase.InsertSimpleStatRecord(Records.Categories.Ping, user, peerSteamID, pos);
Plugin.StaticDatabase.InsertSimpleStatRecord(Records.Categories.Ping, user, playerCharacterId, pos);
}
if (Plugin.StaticConfig.ChatPingEnabled)
{
string message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PingMessage, user, peerSteamID.ToString());
string message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PingMessage, user, playerCharacterId.ToString());
if (Plugin.StaticConfig.ChatPingPosEnabled)
{
if (Plugin.StaticConfig.DiscordEmbedsEnabled || !message.Contains("%POS%"))
Expand All @@ -48,7 +47,7 @@ private static void Prefix(ref GameObject go, ref long senderID, ref Vector3 pos
);
break;
}
message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PingMessage, user, peerSteamID.ToString(), pos);
message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PingMessage, user, playerCharacterId.ToString(), pos);
}
if (message.Contains("%POS%"))
{
Expand All @@ -65,16 +64,16 @@ private static void Prefix(ref GameObject go, ref long senderID, ref Vector3 pos
if (Plugin.StaticConfig.AnnouncePlayerFirstJoinEnabled && Plugin.StaticDatabase.CountOfRecordsByName(Records.Categories.Join, user) == 0)
{
DiscordApi.SendMessage(
MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PlayerFirstJoinMessage, user, peerSteamID.ToString())
MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PlayerFirstJoinMessage, user, playerCharacterId.ToString())
);
}
if (Plugin.StaticConfig.StatsJoinEnabled)
{
Plugin.StaticDatabase.InsertSimpleStatRecord(Records.Categories.Join, user, peerSteamID, pos);
Plugin.StaticDatabase.InsertSimpleStatRecord(Records.Categories.Join, user, playerCharacterId, pos);
}
if (Plugin.StaticConfig.PlayerJoinMessageEnabled)
{
string message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.JoinMessage, user, peerSteamID.ToString());
string message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.JoinMessage, user, playerCharacterId.ToString());
if (Plugin.StaticConfig.PlayerJoinPosEnabled)
{
if (Plugin.StaticConfig.DiscordEmbedsEnabled || !message.Contains("%POS%"))
Expand All @@ -85,7 +84,7 @@ private static void Prefix(ref GameObject go, ref long senderID, ref Vector3 pos
);
break;
}
message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.JoinMessage, user, peerSteamID.ToString(), pos);
message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.JoinMessage, user, playerCharacterId.ToString(), pos);
}
if (message.Contains("%POS%"))
{
Expand All @@ -100,16 +99,16 @@ private static void Prefix(ref GameObject go, ref long senderID, ref Vector3 pos
if (Plugin.StaticConfig.AnnouncePlayerFirstShoutEnabled && Plugin.StaticDatabase.CountOfRecordsByName(Records.Categories.Shout, user) == 0)
{
DiscordApi.SendMessage(
MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PlayerFirstShoutMessage, user, peerSteamID.ToString(), text)
MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.PlayerFirstShoutMessage, user, playerCharacterId.ToString(), text)
);
}
if (Plugin.StaticConfig.StatsShoutEnabled)
{
Plugin.StaticDatabase.InsertSimpleStatRecord(Records.Categories.Shout, user, peerSteamID, pos);
Plugin.StaticDatabase.InsertSimpleStatRecord(Records.Categories.Shout, user, playerCharacterId, pos);
}
if (Plugin.StaticConfig.ChatShoutEnabled)
{
string message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.ShoutMessage, user, peerSteamID.ToString(), text);
string message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.ShoutMessage, user, playerCharacterId.ToString(), text);
if (Plugin.StaticConfig.ChatShoutPosEnabled)
{
if (Plugin.StaticConfig.DiscordEmbedsEnabled || !message.Contains("%POS%"))
Expand All @@ -120,7 +119,7 @@ private static void Prefix(ref GameObject go, ref long senderID, ref Vector3 pos
);
break;
}
message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.ShoutMessage, user, peerSteamID.ToString(), text, pos);
message = MessageTransformer.FormatPlayerMessage(Plugin.StaticConfig.ShoutMessage, user, playerCharacterId.ToString(), text, pos);
}
if (message.Contains("%POS%"))
{
Expand Down
Loading

0 comments on commit cd991fb

Please sign in to comment.