mirror of
https://github.com/minetest/minetest.git
synced 2024-11-09 17:23:45 +01:00
Fix and improve Server's privilege get/setters
This commit is contained in:
parent
6298878bfa
commit
5957fed9a7
@ -3551,10 +3551,7 @@ static int l_get_player_privs(lua_State *L)
|
|||||||
// Do it
|
// Do it
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int table = lua_gettop(L);
|
int table = lua_gettop(L);
|
||||||
u64 privs_i = server->getPlayerAuthPrivs(name);
|
u64 privs_i = server->getPlayerEffectivePrivs(name);
|
||||||
// Special case for the "name" setting (local player / server owner)
|
|
||||||
if(name == g_settings->get("name"))
|
|
||||||
privs_i = PRIV_ALL;
|
|
||||||
std::set<std::string> privs_s = privsToSet(privs_i);
|
std::set<std::string> privs_s = privsToSet(privs_i);
|
||||||
for(std::set<std::string>::const_iterator
|
for(std::set<std::string>::const_iterator
|
||||||
i = privs_s.begin(); i != privs_s.end(); i++){
|
i = privs_s.begin(); i != privs_s.end(); i++){
|
||||||
|
@ -4182,6 +4182,40 @@ std::wstring Server::getStatusString()
|
|||||||
return os.str();
|
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 "<<name<<std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server::setPlayerAuthPrivs(const std::string &name, u64 privs)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
return m_authmanager.setPrivs(name, privs);
|
||||||
|
}
|
||||||
|
catch(AuthNotFoundException &e)
|
||||||
|
{
|
||||||
|
dstream<<"WARNING: Auth not found for "<<name<<std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 Server::getPlayerEffectivePrivs(const std::string &name)
|
||||||
|
{
|
||||||
|
// Local player gets all privileges regardless of
|
||||||
|
// what's set on their account.
|
||||||
|
if(m_simple_singleplayer_mode)
|
||||||
|
return PRIV_ALL;
|
||||||
|
if(name == g_settings->get("name"))
|
||||||
|
return PRIV_ALL;
|
||||||
|
return getPlayerAuthPrivs(name);
|
||||||
|
}
|
||||||
|
|
||||||
void Server::setPlayerPassword(const std::string &name, const std::wstring &password)
|
void Server::setPlayerPassword(const std::string &name, const std::wstring &password)
|
||||||
{
|
{
|
||||||
// Add player to auth manager
|
// Add player to auth manager
|
||||||
@ -4570,16 +4604,7 @@ u64 Server::getPlayerPrivs(Player *player)
|
|||||||
if(player==NULL)
|
if(player==NULL)
|
||||||
return 0;
|
return 0;
|
||||||
std::string playername = player->getName();
|
std::string playername = player->getName();
|
||||||
// Local player gets all privileges regardless of
|
return getPlayerEffectivePrivs(playername);
|
||||||
// what's set on their account.
|
|
||||||
if(g_settings->get("name") == playername)
|
|
||||||
{
|
|
||||||
return PRIV_ALL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return getPlayerAuthPrivs(playername);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dedicated_server_loop(Server &server, bool &kill)
|
void dedicated_server_loop(Server &server, bool &kill)
|
||||||
|
27
src/server.h
27
src/server.h
@ -465,32 +465,13 @@ public:
|
|||||||
m_shutdown_requested = true;
|
m_shutdown_requested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Envlock and conlock should be locked when calling this
|
// Envlock and conlock should be locked when calling this
|
||||||
void SendMovePlayer(Player *player);
|
void SendMovePlayer(Player *player);
|
||||||
|
|
||||||
u64 getPlayerAuthPrivs(const std::string &name)
|
// Thread-safe
|
||||||
{
|
u64 getPlayerAuthPrivs(const std::string &name);
|
||||||
try{
|
void setPlayerAuthPrivs(const std::string &name, u64 privs);
|
||||||
return m_authmanager.getPrivs(name);
|
u64 getPlayerEffectivePrivs(const std::string &name);
|
||||||
}
|
|
||||||
catch(AuthNotFoundException &e)
|
|
||||||
{
|
|
||||||
dstream<<"WARNING: Auth not found for "<<name<<std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPlayerAuthPrivs(const std::string &name, u64 privs)
|
|
||||||
{
|
|
||||||
try{
|
|
||||||
return m_authmanager.setPrivs(name, privs);
|
|
||||||
}
|
|
||||||
catch(AuthNotFoundException &e)
|
|
||||||
{
|
|
||||||
dstream<<"WARNING: Auth not found for "<<name<<std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Changes a player's password, password must be given as plaintext
|
// Changes a player's password, password must be given as plaintext
|
||||||
// If the player doesn't exist, a new entry is added to the auth manager
|
// If the player doesn't exist, a new entry is added to the auth manager
|
||||||
|
Loading…
Reference in New Issue
Block a user