When granting or revoking privileges, notify the target player too
authorPerttu Ahola <celeron55@gmail.com>
Sun, 16 Oct 2011 17:03:43 +0000 (20:03 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 16 Oct 2011 17:03:43 +0000 (20:03 +0300)
src/server.cpp
src/server.h
src/servercommand.cpp

index 3e22a023aded7a77cd05e7b395dfbda301fad514..3e1034f50e78ab0d49de7969453d84632df6c119 100644 (file)
@@ -4148,6 +4148,14 @@ void Server::saveConfig()
                g_settings->updateConfigFile(m_configpath.c_str());
 }
 
+void Server::notifyPlayer(const char *name, const std::wstring msg)
+{
+       Player *player = m_env.getPlayer(name);
+       if(!player)
+               return;
+       SendChatMessage(player->peer_id, std::wstring(L"Server: -!- ")+msg);
+}
+
 v3f findSpawnPos(ServerMap &map)
 {
        //return v3f(50,50,50)*BS;
index f65bd1957186a9ca9ea1be3b643bfa3b0b36b5c5..1e7e41c9673a4a942d62a584b5eae3c954d4c987 100644 (file)
@@ -472,6 +472,9 @@ public:
        {
                return m_con.GetPeerNoEx(peer_id);
        }
+       
+       // Envlock and conlock should be locked when calling this
+       void notifyPlayer(const char *name, const std::wstring msg);
 
 private:
 
index 98777adcc782d8007aea3bb69d5930b26be92953..3c0e6d5108086f93c8505ec968fb86b9dfe84a82 100644 (file)
@@ -97,15 +97,29 @@ void cmd_grantrevoke(std::wostringstream &os,
        u64 privs = ctx->server->getPlayerAuthPrivs(playername);
 
        if(ctx->parms[0] == L"grant"){
+               privs |= newprivs;
                actionstream<<ctx->player->getName()<<" grants "
                                <<wide_to_narrow(ctx->parms[2])<<" to "
                                <<playername<<std::endl;
-               privs |= newprivs;
+
+               std::wstring msg;
+               msg += narrow_to_wide(ctx->player->getName());
+               msg += L" granted you the privilege \"";
+               msg += ctx->parms[2];
+               msg += L"\"";
+               ctx->server->notifyPlayer(playername.c_str(), msg);
        } else {
+               privs &= ~newprivs;
                actionstream<<ctx->player->getName()<<" revokes "
                                <<wide_to_narrow(ctx->parms[2])<<" from "
                                <<playername<<std::endl;
-               privs &= ~newprivs;
+
+               std::wstring msg;
+               msg += narrow_to_wide(ctx->player->getName());
+               msg += L" revoked from you the privilege \"";
+               msg += ctx->parms[2];
+               msg += L"\"";
+               ctx->server->notifyPlayer(playername.c_str(), msg);
        }
        
        ctx->server->setPlayerAuthPrivs(playername, privs);