1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-22 23:58:48 -05:00

Only allow players with shout to chat

Fix regression of commit

5e507c9829 "Add server side ncurses terminal"

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

Fixes #3362.
This commit is contained in:
est31 2015-11-13 01:35:54 +01:00
parent 36855522a5
commit 657a16d90c
3 changed files with 14 additions and 6 deletions

View 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);

View 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,
@ -2782,12 +2783,17 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
line += L"-!- Empty command";
else
line += L"-!- Invalid command: " + str_split(wcmd, L' ')[0];
} else {
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;
}
}
/*
Tell calling method to send the message to sender

View 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);