From 7cad0a2dcd817b179f82066964c45937a603d138 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 30 Mar 2012 18:42:18 +0300 Subject: Reimplement authentication handler in Lua; now we have 1) infinite privilege names, 2) minetest.register_authentication_handler() --- src/servercommand.cpp | 164 +++----------------------------------------------- 1 file changed, 7 insertions(+), 157 deletions(-) (limited to 'src/servercommand.cpp') diff --git a/src/servercommand.cpp b/src/servercommand.cpp index 48ada56fe..64c43d4f5 100644 --- a/src/servercommand.cpp +++ b/src/servercommand.cpp @@ -38,98 +38,6 @@ void cmd_me(std::wostringstream &os, ctx->flags |= SEND_TO_OTHERS | SEND_NO_PREFIX; } -void cmd_privs(std::wostringstream &os, - ServerCommandContext *ctx) -{ - if(ctx->parms.size() == 1) - { - // Show our own real privs, without any adjustments - // made for admin status - os<server->getPlayerAuthPrivs(ctx->player->getName()))); - return; - } - - if((ctx->privs & PRIV_PRIVS) == 0) - { - os<env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str()); - if(tp == NULL) - { - os<server->getPlayerAuthPrivs(tp->getName()))); -} - -void cmd_grantrevoke(std::wostringstream &os, - ServerCommandContext *ctx) -{ - if(ctx->parms.size() != 3) - { - os<privs & PRIV_PRIVS) == 0) - { - os<parms[2])); - if(newprivs == PRIV_INVALID) - { - os<env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str()); - if(tp == NULL) - { - os<parms[1]); - u64 privs = ctx->server->getPlayerAuthPrivs(playername); - - if(ctx->parms[0] == L"grant"){ - privs |= newprivs; - actionstream<player->getName()<<" grants " - <parms[2])<<" to " - <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<player->getName()<<" revokes " - <parms[2])<<" from " - <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); - - os<privs & PRIV_SETTIME) ==0) + + if(!ctx->server->checkPriv(ctx->player->getName(), "settime")) { os<privs & PRIV_SERVER) ==0) + if(!ctx->server->checkPriv(ctx->player->getName(), "server")) { os<privs & PRIV_SERVER) ==0) + if(!ctx->server->checkPriv(ctx->player->getName(), "server")) { os<privs & PRIV_TELEPORT) ==0) + if(!ctx->server->checkPriv(ctx->player->getName(), "teleport")) { os<privs & PRIV_BAN) == 0) + if(!ctx->server->checkPriv(ctx->player->getName(), "ban")) { os<privs & PRIV_PASSWORD) == 0) - { - os<parms[0] == L"setpassword") - { - if(ctx->parms.size() != 3) - { - os<parms[1]); - password = ctx->parms[2]; - - actionstream<player->getName()<<" sets password of " - <parms.size() != 2) - { - os<parms[1]); - password = L""; - - actionstream<player->getName()<<" clears password of" - <server->setPlayerPassword(playername, password); - - std::wostringstream msg; - msg<player->getName()<server->notifyPlayer(playername.c_str(), msg.str()); - - os<privs & PRIV_SERVER) ==0) + if(!ctx->server->checkPriv(ctx->player->getName(), "server")) { os<parms[0] == L"status") cmd_status(os, ctx); - else if(ctx->parms[0] == L"privs") - cmd_privs(os, ctx); - else if(ctx->parms[0] == L"grant" || ctx->parms[0] == L"revoke") - cmd_grantrevoke(os, ctx); else if(ctx->parms[0] == L"time") cmd_time(os, ctx); else if(ctx->parms[0] == L"shutdown") @@ -392,8 +244,6 @@ std::wstring processServerCommand(ServerCommandContext *ctx) cmd_teleport(os, ctx); else if(ctx->parms[0] == L"ban" || ctx->parms[0] == L"unban") cmd_banunban(os, ctx); - else if(ctx->parms[0] == L"setpassword" || ctx->parms[0] == L"clearpassword") - cmd_setclearpassword(os, ctx); else if(ctx->parms[0] == L"me") cmd_me(os, ctx); else if(ctx->parms[0] == L"clearobjects") -- cgit v1.2.3