Skip to content

Commit

Permalink
Add motd to autohost and challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
CupnPlateGames committed Feb 22, 2024
1 parent c65c43d commit 5e21bad
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion doc/hosting/AutohostConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Each player slot can be customized, starting from 0. The first slot will be defi
* `difficulty` sets the difficulty for an AI. It can be one of `Easy`, `Medium`, `Hard` or `Insane`.
* `name` sets a custom name for the AI.

## Message of the Day

The `motd` is displayed in the chat box when a player joins the game. It is optional and will be truncated if it exceeds 256 characters.

## Sample file

```
Expand Down Expand Up @@ -83,6 +87,7 @@ Each player slot can be customized, starting from 0. The first slot will be defi
},
"player_3": {
"team": 1
}
},
"motd": "Good Luck, Have Fun!"
}
```
35 changes: 35 additions & 0 deletions src/multiint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ static struct
} locked;
static bool spectatorHost = false;
static uint16_t defaultOpenSpectatorSlots = 0;
static WzString motd = WzString();

struct AIDATA
{
Expand Down Expand Up @@ -6035,6 +6036,23 @@ static void resetPlayerConfiguration(const bool bShouldResetLocal = false)
}
}

static void loadMapMessageOfTheDay(WzConfig& ini)
{
if (ini.contains("motd"))
{
motd = ini.value("motd").toWzString();
if (motd.length() > MAX_CONSOLE_STRING_LENGTH)
{
motd.truncate(MAX_CONSOLE_STRING_LENGTH);
debug(LOG_WARNING, "MOTD was truncated to fit into %d characters.", MAX_CONSOLE_STRING_LENGTH);
}
}
else
{
motd = WzString("");
}
}

/**
* Loads challenge and player configurations from level/autohost/test .json-files.
*/
Expand Down Expand Up @@ -6080,6 +6098,7 @@ static void loadMapChallengeAndPlayerSettings(bool forceLoadPlayers = false)
WzConfig ini(ininame, WzConfig::ReadOnly);

loadMapChallengeSettings(ini);
loadMapMessageOfTheDay(ini);

/* Do not load player settings if we are already hosting an online match */
if (!bIsOnline || forceLoadPlayers)
Expand Down Expand Up @@ -7664,6 +7683,11 @@ void WzMultiplayerOptionsTitleUI::screenSizeDidChange(unsigned int oldWidth, uns
static void printHostHelpMessagesToConsole()
{
char buf[512] = { '\0' };
if (!motd.isEmpty())
{
ssprintf(buf, motd.toUtf8().c_str());
displayRoomNotifyMessage(buf);
}
if (challengeActive)
{
ssprintf(buf, "%s", _("Hit the ready box to begin your challenge!"));
Expand Down Expand Up @@ -8613,6 +8637,17 @@ void sendRoomSystemMessageToSingleReceiver(char const *text, uint32_t receiver,
message.enqueue(NETnetQueue(receiver));
}

void sendRoomMotdToSingleReceiver(uint32_t receiver)
{
if (motd.isEmpty())
{
return;
}
ASSERT_OR_RETURN(, isHumanPlayer(receiver), "Invalid receiver: %" PRIu32 "", receiver);
NetworkTextMessage message(NOTIFY_MESSAGE, motd.toUtf8().c_str());
message.enqueue(NETnetQueue(receiver));
}

static void sendRoomChatMessage(char const *text, bool skipLocalDisplay)
{
NetworkTextMessage message(selectedPlayer, text);
Expand Down
1 change: 1 addition & 0 deletions src/multiint.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ WzString formatGameName(WzString name);
void sendRoomSystemMessage(char const *text);
void sendRoomNotifyMessage(char const *text);
void sendRoomSystemMessageToSingleReceiver(char const *text, uint32_t receiver, bool skipLocalDisplay = false);
void sendRoomMotdToSingleReceiver(uint32_t receiver);
void displayRoomSystemMessage(char const *text);
void displayRoomNotifyMessage(char const *text);
void displayLobbyDisabledNotification();
Expand Down
1 change: 1 addition & 0 deletions src/multijoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ bool MultiPlayerJoin(UDWORD playerIndex)
}
}
}
sendRoomMotdToSingleReceiver(playerIndex);
if (lobby_slashcommands_enabled())
{
// Inform the new player that this lobby has slash commands enabled.
Expand Down

0 comments on commit 5e21bad

Please sign in to comment.