-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<<L"-!- " + narrow_to_wide(privsToString(
- ctx->server->getPlayerAuthPrivs(ctx->player->getName())));
- return;
- }
-
- if((ctx->privs & PRIV_PRIVS) == 0)
- {
- os<<L"-!- You don't have permission to do that";
- return;
- }
-
- Player *tp = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str());
- if(tp == NULL)
- {
- os<<L"-!- No such player";
- return;
- }
-
- os<<L"-!- " + narrow_to_wide(privsToString(ctx->server->getPlayerAuthPrivs(tp->getName())));
-}
-
-void cmd_grantrevoke(std::wostringstream &os,
- ServerCommandContext *ctx)
-{
- if(ctx->parms.size() != 3)
- {
- os<<L"-!- Missing parameter";
- return;
- }
-
- if((ctx->privs & PRIV_PRIVS) == 0)
- {
- os<<L"-!- You don't have permission to do that";
- return;
- }
-
- u64 newprivs = stringToPrivs(wide_to_narrow(ctx->parms[2]));
- if(newprivs == PRIV_INVALID)
- {
- os<<L"-!- Invalid privileges specified";
- return;
- }
-
- Player *tp = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str());
- if(tp == NULL)
- {
- os<<L"-!- No such player";
- return;
- }
-
- std::string playername = wide_to_narrow(ctx->parms[1]);
- 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;
-
- 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;
-
- 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);
-
- os<<L"-!- Privileges change to ";
- os<<narrow_to_wide(privsToString(privs));
-}
-