Skip to content

Commit

Permalink
feat: add %JOIN_CODE% variable to display join code #269
Browse files Browse the repository at this point in the history
This will only show the join code if there is one -- if the server is not crossplay it will be blank.
  • Loading branch information
nwesterhausen committed Jun 7, 2024
1 parent 79f12b6 commit f6b0aff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/config/messages.player.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
| `%DAY_NUMBER%` | Current day number on server | Any messages |
| `%WORLD_NAME%` | World name of the world used on the server | Any messages |
| `%NUM_PLAYERS%` | Number of currently online players | Any messages |
| `%JOIN_CODE%` | Server's join code (only if a join code exists, blank otherwise) | Any messages |
:::

:::details Random Messages
Expand Down
1 change: 1 addition & 0 deletions docs/config/messages.playerfirsts.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
| `%DAY_NUMBER%` | Current day number on server | Any messages |
| `%WORLD_NAME%` | World name of the world used on the server | Any messages |
| `%NUM_PLAYERS%` | Number of currently online players | Any messages |
| `%JOIN_CODE%` | Server's join code (only if a join code exists, blank otherwise) | Any messages |
:::

:::details Random Messages
Expand Down
1 change: 1 addition & 0 deletions docs/config/messages.server.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
| `%DAY_NUMBER%` | Current day number on server | Any messages |
| `%WORLD_NAME%` | World name of the world used on the server | Any messages |
| `%NUM_PLAYERS%` | Number of currently online players | Any messages |
| `%JOIN_CODE%` | Server's join code (only if a join code exists, blank otherwise) | Any messages |
:::

## Server Launch Message
Expand Down
13 changes: 13 additions & 0 deletions src/MessageTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal static class MessageTransformer
private const string WORLD_NAME = "%WORLD_NAME%";
private const string DAY_NUMBER = "%DAY_NUMBER%";
private const string NUM_PLAYERS = "%NUM_PLAYERS%";
private const string JOIN_CODE = "%JOIN_CODE%";

private static readonly Regex OpenCaretRegex = new(@"<[\w=]+>");
private static readonly Regex CloseCaretRegex = new(@"</[\w]+>");
Expand Down Expand Up @@ -59,6 +60,7 @@ private static string ReplaceVariables(string rawMessage)
/// - `%WORLD_NAME%` with the name of the world
/// - `%DAY_NUMBER%` with the current day number
/// - `%NUM_PLAYERS%` with the number of players in the server
/// - `%JOIN_CODE%` with the join code of the server
/// </summary>
/// <param name="rawMessage">Raw message to format</param>
private static string ReplaceDynamicVariables(string rawMessage)
Expand All @@ -68,10 +70,21 @@ private static string ReplaceDynamicVariables(string rawMessage)
dynamicReplacedMessage = ReplaceWorldName(dynamicReplacedMessage);
dynamicReplacedMessage = ReplaceDayNumber(dynamicReplacedMessage);
dynamicReplacedMessage = ReplaceNumPlayers(dynamicReplacedMessage);
dynamicReplacedMessage = ReplaceJoinCode(dynamicReplacedMessage);

return dynamicReplacedMessage;
}

/// <summary>
/// Replace the join code in the message. Uses the ZPlayFabMatchmaking class to get the join code.
/// </summary>
/// <param name="rawMessage">Raw message to format</param>
private static string ReplaceJoinCode(string rawMessage)
{
return rawMessage
.Replace(JOIN_CODE, ZPlayFabMatchmaking.JoinCode);
}

/// <summary>
/// Replace the day number in the message. Uses the EnvMan instance to get the current day.
/// This will only replace `%DAY_NUMBER%` with the current day if the EnvMan instance is available.
Expand Down

0 comments on commit f6b0aff

Please sign in to comment.