Commented out debug statements again
[oweals/minetest.git] / src / servercommand.cpp
index 333e29084cd85ddec67496005de0b03b353ccd2a..89ba0771fe93f8ed91be720ab408b1398c9da34d 100644 (file)
@@ -25,6 +25,14 @@ void cmd_status(std::wostringstream &os,
        os<<ctx->server->getStatusString();
 }
 
+void cmd_me(std::wostringstream &os,
+       ServerCommandContext *ctx)
+{
+       std::wstring name = narrow_to_wide(ctx->player->getName());
+       os << L"* " << name << L" " << ctx->paramstring;
+       ctx->flags |= SEND_TO_OTHERS | SEND_NO_PREFIX;
+}
+
 void cmd_privs(std::wostringstream &os,
        ServerCommandContext *ctx)
 {
@@ -130,7 +138,7 @@ void cmd_shutdown(std::wostringstream &os,
        ctx->server->requestShutdown();
                                        
        os<<L"*** Server shutting down (operator request)";
-       ctx->flags |= 2;
+       ctx->flags |= SEND_TO_OTHERS;
 }
 
 void cmd_setting(std::wostringstream &os,
@@ -142,9 +150,16 @@ void cmd_setting(std::wostringstream &os,
                return;
        }
 
-       std::string confline = wide_to_narrow(ctx->parms[1] + L" = " + ctx->parms[2]);
+       /*std::string confline = wide_to_narrow(
+                       ctx->parms[1] + L" = " + ctx->params[2]);*/
+
+       std::string confline = wide_to_narrow(ctx->paramstring);
+       
        g_settings.parseConfigLine(confline);
-       os<< L"-!- Setting changed.";
+       
+       ctx->server->saveConfig();
+
+       os<< L"-!- Setting changed and configuration saved.";
 }
 
 void cmd_teleport(std::wostringstream &os,
@@ -176,12 +191,56 @@ void cmd_teleport(std::wostringstream &os,
        os<< L"-!- Teleported.";
 }
 
+void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx)
+{
+       if((ctx->privs & PRIV_BAN) == 0)
+       {
+               os<<L"-!- You don't have permission to do that";
+               return;
+       }
+
+       if(ctx->parms.size() < 2)
+       {
+               std::string desc = ctx->server->getBanDescription("");
+               os<<L"-!- Ban list: "<<narrow_to_wide(desc);
+               return;
+       }
+       if(ctx->parms[0] == L"ban")
+       {
+               Player *player = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str());
+
+               if(player == NULL)
+               {
+                       os<<L"-!- No such player";
+                       return;
+               }
+
+               con::Peer *peer = ctx->server->getPeerNoEx(player->peer_id);
+               if(peer == NULL)
+               {
+                       dstream<<__FUNCTION_NAME<<": peer was not found"<<std::endl;
+                       return;
+               }
+               std::string ip_string = peer->address.serializeString();
+               ctx->server->setIpBanned(ip_string, player->getName());
+               os<<L"-!- Banned "<<narrow_to_wide(ip_string)<<L"|"
+                               <<narrow_to_wide(player->getName());
+       }
+       else
+       {
+               std::string ip_or_name = wide_to_narrow(ctx->parms[1]);
+               std::string desc = ctx->server->getBanDescription(ip_or_name);
+               ctx->server->unsetIpBanned(ip_or_name);
+               os<<L"-!- Unbanned "<<narrow_to_wide(desc);
+       }
+}
+
 
 std::wstring processServerCommand(ServerCommandContext *ctx)
 {
 
        std::wostringstream os(std::ios_base::binary);
-       ctx->flags = 1; // Default, unless we change it.
+       ctx->flags = SEND_TO_SENDER;    // Default, unless we change it.
 
        u64 privs = ctx->privs;
 
@@ -197,6 +256,8 @@ std::wstring processServerCommand(ServerCommandContext *ctx)
                        os<<L" teleport";
                if(privs & PRIV_PRIVS)
                        os<<L" grant revoke";
+               if(privs & PRIV_BAN)
+                       os<<L" ban unban";
        }
        else if(ctx->parms[0] == L"status")
        {
@@ -226,6 +287,14 @@ 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"me")
+       {
+               cmd_me(os, ctx);
+       }
        else
        {
                os<<L"-!- Invalid command: " + ctx->parms[0];