X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fservercommand.cpp;h=e2e84bacb000945e4bf2ac08a392217cc8045fea;hb=58bed83d03bbe53f8286640fbc33043800e1c318;hp=333e29084cd85ddec67496005de0b03b353ccd2a;hpb=75f3e6845187b539a82f8a5e66c2aa48caa0dca8;p=dragonfireclient.git diff --git a/src/servercommand.cpp b/src/servercommand.cpp index 333e29084..e2e84bacb 100644 --- a/src/servercommand.cpp +++ b/src/servercommand.cpp @@ -18,6 +18,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "servercommand.h" #include "utility.h" +#include "settings.h" +#include "main.h" // For g_settings + +#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" void cmd_status(std::wostringstream &os, ServerCommandContext *ctx) @@ -25,6 +29,14 @@ void cmd_status(std::wostringstream &os, os<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) { @@ -85,10 +97,31 @@ void cmd_grantrevoke(std::wostringstream &os, std::string playername = wide_to_narrow(ctx->parms[1]); u64 privs = ctx->server->getPlayerAuthPrivs(playername); - if(ctx->parms[0] == L"grant") + if(ctx->parms[0] == L"grant"){ privs |= newprivs; - else + 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); @@ -114,6 +147,9 @@ void cmd_time(std::wostringstream &os, u32 time = stoi(wide_to_narrow(ctx->parms[1])); ctx->server->setTimeOfDay(time); os<player->getName()<<" sets time " + <player->getName() + <<" shuts down server"<server->requestShutdown(); os<flags |= 2; + ctx->flags |= SEND_TO_OTHERS; } void cmd_setting(std::wostringstream &os, @@ -142,9 +179,19 @@ void cmd_setting(std::wostringstream &os, return; } - std::string confline = wide_to_narrow(ctx->parms[1] + L" = " + ctx->parms[2]); - g_settings.parseConfigLine(confline); - os<< L"-!- Setting changed."; + /*std::string confline = wide_to_narrow( + ctx->parms[1] + L" = " + ctx->params[2]);*/ + + std::string confline = wide_to_narrow(ctx->paramstring); + + actionstream<player->getName() + <<" sets: "<parseConfigLine(confline); + + ctx->server->saveConfig(); + + os<< L"-!- Setting changed and configuration saved."; } void cmd_teleport(std::wostringstream &os, @@ -170,66 +217,202 @@ void cmd_teleport(std::wostringstream &os, } v3f dest(stoi(coords[0])*10, stoi(coords[1])*10, stoi(coords[2])*10); - ctx->player->setPosition(dest); + + actionstream<player->getName()<<" teleports from " + <player->getPosition()/BS)<<" to " + <player->setPosition(dest); + + // Use the ServerActiveObject interface of ServerRemotePlayer + ServerRemotePlayer *srp = static_cast(ctx->player); + srp->setPos(dest); ctx->server->SendMovePlayer(ctx->player); os<< L"-!- Teleported."; } +void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx) +{ + if((ctx->privs & PRIV_BAN) == 0) + { + os<parms.size() < 2) + { + std::string desc = ctx->server->getBanDescription(""); + os<parms[0] == L"ban") + { + Player *player = ctx->env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str()); + + if(player == NULL) + { + os<server->getPeerAddress(player->peer_id); + std::string ip_string = address.serializeString(); + ctx->server->setIpBanned(ip_string, player->getName()); + os<getName()); + + actionstream<player->getName()<<" bans " + <getName()<<" / "<parms[1]); + std::string desc = ctx->server->getBanDescription(ip_or_name); + ctx->server->unsetIpBanned(ip_or_name); + os<player->getName()<<" unbans " + <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) + { + os<player->getName() + <<" clears all objects"<player->getName()); + msg += L")"; + ctx->server->notifyPlayers(msg); + } + + ctx->env->clearAllObjects(); + + actionstream<<"object clearing done"<flags |= SEND_TO_OTHERS; +} + 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; if(ctx->parms.size() == 0 || ctx->parms[0] == L"help") { 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") - { cmd_shutdown(os, ctx); - } else if(ctx->parms[0] == L"setting") - { cmd_setting(os, ctx); - } else if(ctx->parms[0] == L"teleport") - { 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") + cmd_clearobjects(os, ctx); else - { os<parms[0]; - } + return os.str(); }