From c8ebb7054ef8c75cf0fe27cc81a17ddffc5f1bbb Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Fri, 17 Nov 2023 12:50:26 -0500 Subject: [PATCH] Tweak sendRoomSystemMessageToSingleReceiver --- src/multiint.cpp | 8 +++++--- src/multiint.h | 2 +- src/multijoin.cpp | 2 +- src/multilobbycommands.cpp | 36 ++++++++++++++++++------------------ 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/multiint.cpp b/src/multiint.cpp index b00f57368cd..11712e3bfc3 100644 --- a/src/multiint.cpp +++ b/src/multiint.cpp @@ -260,7 +260,6 @@ bool changeReadyStatus(UBYTE player, bool bReady); static void stopJoining(std::shared_ptr 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(); @@ -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)); } diff --git a/src/multiint.h b/src/multiint.h index be0b4965897..605ec4f6be3 100644 --- a/src/multiint.h +++ b/src/multiint.h @@ -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(); diff --git a/src/multijoin.cpp b/src/multijoin.cpp index 8fe4f5d76dc..c2eb3c1a434 100644 --- a/src/multijoin.cpp +++ b/src/multijoin.cpp @@ -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); diff --git a/src/multilobbycommands.cpp b/src/multilobbycommands.cpp index ecfa9231f25..7be245925da 100644 --- a/src/multilobbycommands.cpp +++ b/src/multilobbycommands.cpp @@ -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()); @@ -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 - Swap player/slot positions", receiver); - sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "makespec - Move a player to spectators", receiver); - sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "makeplayer s - Request to move a spectator to players", receiver); - sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "kick - Kick a player; (or s for spectator - ex. s0)", receiver); - sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "team - Change team for player/slot", receiver); - sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "base - Change base level (0, 1, 2)", receiver); - sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "alliance - Change alliance setting (0, 1, 2, 3)", receiver); - sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "scav - 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 - Swap player/slot positions", receiver, true); + sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "makespec - Move a player to spectators", receiver, true); + sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "makeplayer s - Request to move a spectator to players", receiver, true); + sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "kick - Kick a player; (or s for spectator - ex. s0)", receiver, true); + sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "team - Change team for player/slot", receiver, true); + sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "base - Change base level (0, 1, 2)", receiver, true); + sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "alliance - Change alliance setting (0, 1, 2, 3)", receiver, true); + sendRoomSystemMessageToSingleReceiver(LOBBY_COMMAND_PREFIX "scav - Change scav setting (0=off, 1=on, 2=ultimate)", receiver, true); } static std::unordered_set getConnectedAdminPlayerIndexes() @@ -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(message.sender), true); \ return false; \ } @@ -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) { @@ -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(message.sender)); + sendRoomSystemMessageToSingleReceiver("Use the UI to move yourself.", static_cast(message.sender), true); return false; } if (!cmdInterface.movePlayerToSpectators(playerIdx))