Only allow players with shout to chat
authorest31 <MTest31@outlook.com>
Fri, 13 Nov 2015 00:35:54 +0000 (01:35 +0100)
committerest31 <MTest31@outlook.com>
Fri, 13 Nov 2015 01:35:02 +0000 (02:35 +0100)
Fix regression of commit

5e507c9829942c434a6f1ae7a4f3a488c7e50bef "Add server side ncurses terminal"

which allowed all players, even those without a shout priv, to chat.

Fixes #3362.

src/network/serverpackethandler.cpp
src/server.cpp
src/server.h

index 3c446e31d2926c973bef211ceaf399b21ebb371b..a4fa502aecf02afe101a2742eaec3a4d15141dc7 100644 (file)
@@ -1063,7 +1063,8 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt)
        std::string name = player->getName();
        std::wstring wname = narrow_to_wide(name);
 
-       std::wstring answer_to_sender = handleChat(name, wname, message, pkt->getPeerId());
+       std::wstring answer_to_sender = handleChat(name, wname, message,
+               true, pkt->getPeerId());
        if (!answer_to_sender.empty()) {
                // Send the answer to sender
                SendChatMessage(pkt->getPeerId(), answer_to_sender);
index c93abb10c2d0b9ab6bbc76ccee40c93ef5bd3832..f6faccb1f2f455287577e3b4c4a2dd2043def6a2 100644 (file)
@@ -2755,7 +2755,8 @@ void Server::handleChatInterfaceEvent(ChatEvent *evt)
 }
 
 std::wstring Server::handleChat(const std::string &name, const std::wstring &wname,
-       const std::wstring &wmessage, u16 peer_id_to_avoid_sending)
+       const std::wstring &wmessage, bool check_shout_priv,
+       u16 peer_id_to_avoid_sending)
 {
        // If something goes wrong, this player is to blame
        RollbackScopeActor rollback_scope(m_rollback,
@@ -2783,10 +2784,15 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
                else
                        line += L"-!- Invalid command: " + str_split(wcmd, L' ')[0];
        } else {
-               line += L"<";
-               line += wname;
-               line += L"> ";
-               line += wmessage;
+               if (check_shout_priv && !checkPriv(name, "shout")) {
+                       line += L"-!- You don't have permission to shout.";
+                       broadcast_line = false;
+               } else {
+                       line += L"<";
+                       line += wname;
+                       line += L"> ";
+                       line += wmessage;
+               }
        }
 
        /*
index 5a19677cd3f8ed4f7c2b5c31157dc1fc630ca007..fd559ba149f1c7a4a5d8954217ba75f7c806a81a 100644 (file)
@@ -481,6 +481,7 @@ private:
        // This returns the answer to the sender of wmessage, or "" if there is none
        std::wstring handleChat(const std::string &name, const std::wstring &wname,
                const std::wstring &wmessage,
+               bool check_shout_priv = false,
                u16 peer_id_to_avoid_sending = PEER_ID_INEXISTENT);
        void handleAdminChat(const ChatEventChat *evt);