From: Perttu Ahola Date: Thu, 15 Mar 2012 13:27:16 +0000 (+0200) Subject: Fix and improve Server's privilege get/setters X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=5957fed9a7df9297dd218b6400d612434e87ac5a;p=zefram%2Fminetest%2Fminetest_engine.git Fix and improve Server's privilege get/setters --- diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 99c3767a..e8ebecb5 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -3551,10 +3551,7 @@ static int l_get_player_privs(lua_State *L) // Do it lua_newtable(L); int table = lua_gettop(L); - u64 privs_i = server->getPlayerAuthPrivs(name); - // Special case for the "name" setting (local player / server owner) - if(name == g_settings->get("name")) - privs_i = PRIV_ALL; + u64 privs_i = server->getPlayerEffectivePrivs(name); std::set privs_s = privsToSet(privs_i); for(std::set::const_iterator i = privs_s.begin(); i != privs_s.end(); i++){ diff --git a/src/server.cpp b/src/server.cpp index a74a2ee7..2139df95 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -4182,6 +4182,40 @@ std::wstring Server::getStatusString() return os.str(); } +u64 Server::getPlayerAuthPrivs(const std::string &name) +{ + try{ + return m_authmanager.getPrivs(name); + } + catch(AuthNotFoundException &e) + { + dstream<<"WARNING: Auth not found for "<get("name")) + return PRIV_ALL; + return getPlayerAuthPrivs(name); +} + void Server::setPlayerPassword(const std::string &name, const std::wstring &password) { // Add player to auth manager @@ -4570,16 +4604,7 @@ u64 Server::getPlayerPrivs(Player *player) if(player==NULL) return 0; std::string playername = player->getName(); - // Local player gets all privileges regardless of - // what's set on their account. - if(g_settings->get("name") == playername) - { - return PRIV_ALL; - } - else - { - return getPlayerAuthPrivs(playername); - } + return getPlayerEffectivePrivs(playername); } void dedicated_server_loop(Server &server, bool &kill) diff --git a/src/server.h b/src/server.h index 31e3ed17..f149ac68 100644 --- a/src/server.h +++ b/src/server.h @@ -465,32 +465,13 @@ public: m_shutdown_requested = true; } - // Envlock and conlock should be locked when calling this void SendMovePlayer(Player *player); - u64 getPlayerAuthPrivs(const std::string &name) - { - try{ - return m_authmanager.getPrivs(name); - } - catch(AuthNotFoundException &e) - { - dstream<<"WARNING: Auth not found for "<