Skip to content

Commit

Permalink
Tweak sendRoomSystemMessageToSingleReceiver
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Nov 17, 2023
1 parent 2b01a5a commit c8ebb70
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
8 changes: 5 additions & 3 deletions src/multiint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ bool changeReadyStatus(UBYTE player, bool bReady);
static void stopJoining(std::shared_ptr<WzTitleUI> parent);
static int difficultyIcon(int difficulty);

void sendRoomSystemMessageToSingleReceiver(char const *text, uint32_t receiver);
static void sendRoomChatMessage(char const *text, bool skipLocalDisplay = false);

static bool multiplayPlayersReady();
Expand Down Expand Up @@ -8604,11 +8603,14 @@ void sendRoomNotifyMessage(char const *text)
message.enqueue(NETbroadcastQueue());
}

void sendRoomSystemMessageToSingleReceiver(char const *text, uint32_t receiver)
void sendRoomSystemMessageToSingleReceiver(char const *text, uint32_t receiver, bool skipLocalDisplay)
{
ASSERT_OR_RETURN(, isHumanPlayer(receiver), "Invalid receiver: %" PRIu32 "", receiver);
NetworkTextMessage message(SYSTEM_MESSAGE, text);
displayRoomSystemMessage(text);
if (!skipLocalDisplay || receiver == selectedPlayer)
{
displayRoomSystemMessage(text);
}
message.enqueue(NETnetQueue(receiver));
}

Expand Down
2 changes: 1 addition & 1 deletion src/multiint.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool changeReadyStatus(UBYTE player, bool bReady);
WzString formatGameName(WzString name);
void sendRoomSystemMessage(char const *text);
void sendRoomNotifyMessage(char const *text);
void sendRoomSystemMessageToSingleReceiver(char const *text, uint32_t receiver);
void sendRoomSystemMessageToSingleReceiver(char const *text, uint32_t receiver, bool skipLocalDisplay = false);
void displayRoomSystemMessage(char const *text);
void displayRoomNotifyMessage(char const *text);
void displayLobbyDisabledNotification();
Expand Down
2 changes: 1 addition & 1 deletion src/multijoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ bool MultiPlayerJoin(UDWORD playerIndex)
if (lobby_slashcommands_enabled())
{
// Inform the new player that this lobby has slash commands enabled.
sendRoomSystemMessageToSingleReceiver("Lobby slash commands enabled. Type " LOBBY_COMMAND_PREFIX "help to see details.", playerIndex);
sendRoomSystemMessageToSingleReceiver("Lobby slash commands enabled. Type " LOBBY_COMMAND_PREFIX "help to see details.", playerIndex, true);
}
}
addConsolePlayerJoinMessage(playerIndex);
Expand Down
36 changes: 18 additions & 18 deletions src/multilobbycommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static bool senderHasLobbyCommandAdminPrivs(uint32_t playerIdx)
auto& identity = getMultiStats(playerIdx).identity;
std::string senderIdentityHash = identity.publicHashString();
std::string senderPublicKeyB64 = base64Encode(identity.toBytes(EcKey::Public));
sendRoomSystemMessageToSingleReceiver("Waiting for sync (admin privileges not yet enabled)", playerIdx);
sendRoomSystemMessageToSingleReceiver("Waiting for sync (admin privileges not yet enabled)", playerIdx, true);
if (lobbyAdminPublicKeys.count(senderPublicKeyB64) > 0)
{
debug(LOG_INFO, "Received an admin check for player %" PRIu32 " that passed (public key: %s), but they have not yet verified their identity", playerIdx, senderPublicKeyB64.c_str());
Expand All @@ -126,25 +126,25 @@ static bool senderHasLobbyCommandAdminPrivs(uint32_t playerIdx)

static void lobbyCommand_PrintHelp(uint32_t receiver)
{
sendRoomSystemMessageToSingleReceiver("Command list:", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "help - Get this message", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "admin - Display currently-connected admin players", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "me - Display your information", receiver);
sendRoomSystemMessageToSingleReceiver("Command list:", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "help - Get this message", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "admin - Display currently-connected admin players", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "me - Display your information", receiver, true);
if (!senderApparentlyMatchesAdmin(receiver))
{
sendRoomSystemMessageToSingleReceiver("(Additional commands are available for admins)", receiver);
sendRoomSystemMessageToSingleReceiver("(Additional commands are available for admins)", receiver, true);
return;
}
// admin-only commands
sendRoomSystemMessageToSingleReceiver("Admin-only commands: (All slots count from 0)", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "swap <slot-from> <slot-to> - Swap player/slot positions", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "makespec <slot> - Move a player to spectators", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "makeplayer s<slot> - Request to move a spectator to players", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "kick <slot> - Kick a player; (or s<slot> for spectator - ex. s0)", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "team <slot> <team> - Change team for player/slot", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "base <base level> - Change base level (0, 1, 2)", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "alliance <alliance type> - Change alliance setting (0, 1, 2, 3)", receiver);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "scav <scav level> - Change scav setting (0=off, 1=on, 2=ultimate)", receiver);
sendRoomSystemMessageToSingleReceiver("Admin-only commands: (All slots count from 0)", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "swap <slot-from> <slot-to> - Swap player/slot positions", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "makespec <slot> - Move a player to spectators", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "makeplayer s<slot> - Request to move a spectator to players", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "kick <slot> - Kick a player; (or s<slot> for spectator - ex. s0)", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "team <slot> <team> - Change team for player/slot", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "base <base level> - Change base level (0, 1, 2)", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "alliance <alliance type> - Change alliance setting (0, 1, 2, 3)", receiver, true);
sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "scav <scav level> - Change scav setting (0=off, 1=on, 2=ultimate)", receiver, true);
}

static std::unordered_set<size_t> getConnectedAdminPlayerIndexes()
Expand Down Expand Up @@ -193,7 +193,7 @@ static void lobbyCommand_Admin()
#define ADMIN_REQUIRED_FOR_COMMAND(command) \
if (!senderHasLobbyCommandAdminPrivs(message.sender)) \
{ \
sendRoomSystemMessage("Only admin can use the \"" command "\" command"); \
sendRoomSystemMessageToSingleReceiver("Only admin can use the \"" command "\" command", static_cast<uint32_t>(message.sender), true); \
return false; \
}

Expand Down Expand Up @@ -282,7 +282,7 @@ bool processChatLobbySlashCommands(const NetworkTextMessage& message, HostLobbyO
message.sender,
NetPlay.players[message.sender].position,
NetPlay.players[message.sender].name);
sendRoomSystemMessageToSingleReceiver(msg.c_str(), message.sender);
sendRoomSystemMessageToSingleReceiver(msg.c_str(), message.sender, true);
}
else if (strncmp(&message.text[startingCommandPosition], "team ", 5) == 0)
{
Expand Down Expand Up @@ -504,7 +504,7 @@ bool processChatLobbySlashCommands(const NetworkTextMessage& message, HostLobbyO
if (playerIdx == message.sender)
{
// Can't move self this way (or it'll prevent us from moving back) - use the UI!
sendRoomSystemMessageToSingleReceiver("Use the UI to move yourself.", static_cast<uint32_t>(message.sender));
sendRoomSystemMessageToSingleReceiver("Use the UI to move yourself.", static_cast<uint32_t>(message.sender), true);
return false;
}
if (!cmdInterface.movePlayerToSpectators(playerIdx))
Expand Down

0 comments on commit c8ebb70

Please sign in to comment.