Skip to content

Commit

Permalink
Only allow players with shout to chat
Browse files Browse the repository at this point in the history
Fix regression of commit

5e507c9 "Add server side ncurses terminal"

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

Fixes #3362.
  • Loading branch information
est31 committed Nov 13, 2015
1 parent 3685552 commit 657a16d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/network/serverpackethandler.cpp
Expand Up @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions src/server.cpp
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Expand Up @@ -481,6 +481,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
// 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);

Expand Down

0 comments on commit 657a16d

Please sign in to comment.