From 248d7c8469f8cb37406ea0ce56d0945e38334cfb Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Mon, 16 May 2011 10:41:19 +0100 Subject: Improved server commands and added player permissions. --HG-- extra : rebase_source : 178fe08f10b7de3ebaba088bd24faad795114216 --- src/servercommand.cpp | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 src/servercommand.cpp (limited to 'src/servercommand.cpp') diff --git a/src/servercommand.cpp b/src/servercommand.cpp new file mode 100644 index 000000000..fa841a1bb --- /dev/null +++ b/src/servercommand.cpp @@ -0,0 +1,233 @@ +/* +Minetest-c55 +Copyright (C) 2010-2011 celeron55, Perttu Ahola +Copyright (C) 2011 Ciaran Gultnieks + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + + +#include "servercommand.h" +#include "utility.h" + +// Process a command sent from a client. The environment and connection +// should be locked when this is called. +// Returns a response message, to be dealt with according to the flags set +// in the context. +std::wstring ServerCommand::processCommand(ServerCommandContext *ctx) +{ + + std::wostringstream os(std::ios_base::binary); + ctx->flags = 1; // Default, unless we change it. + + u64 privs = ctx->player->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 + { + os<parms[0]; + } + return os.str(); +} + +void ServerCommand::cmd_status(std::wostringstream &os, + ServerCommandContext *ctx) +{ + os<server->getStatusString(); +} + +void ServerCommand::cmd_privs(std::wostringstream &os, + ServerCommandContext *ctx) +{ + if(ctx->parms.size() == 1) + { + os<player->privs); + return; + } + + if((ctx->player->privs & PRIV_PRIVS) == 0) + { + os<env->getPlayer(wide_to_narrow(ctx->parms[1]).c_str()); + if(tp == NULL) + { + os<privs); +} + +void ServerCommand::cmd_grantrevoke(std::wostringstream &os, + ServerCommandContext *ctx) +{ + if(ctx->parms.size() != 3) + { + os<player->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[0] == L"grant") + tp->privs |= newprivs; + else + tp->privs &= ~newprivs; + + os<privs); +} + +void ServerCommand::cmd_time(std::wostringstream &os, + ServerCommandContext *ctx) +{ + if(ctx->parms.size() != 2) + { + os<player->privs & PRIV_SETTIME) ==0) + { + os<parms[1])); + ctx->server->setTimeOfDay(time); + os<player->privs & PRIV_SERVER) ==0) + { + os<server->requestShutdown(); + + os<flags |= 2; +} + +void ServerCommand::cmd_setting(std::wostringstream &os, + ServerCommandContext *ctx) +{ + if((ctx->player->privs & PRIV_SERVER) ==0) + { + os<parms[1] + L" = " + ctx->parms[2]); + g_settings.parseConfigLine(confline); + os<< L"-!- Setting changed."; +} + +void ServerCommand::cmd_teleport(std::wostringstream &os, + ServerCommandContext *ctx) +{ + if((ctx->player->privs & PRIV_TELEPORT) ==0) + { + os<parms.size() != 2) + { + os< coords = str_split(ctx->parms[1], L','); + if(coords.size() != 3) + { + os<player->setPosition(dest); + ctx->server->SendMovePlayer(ctx->player); + + os<< L"-!- Teleported."; +} + -- cgit v1.2.3