diff options
author | Matthew I <matttpt@gmail.com> | 2012-07-22 09:42:43 -0400 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-08-12 16:45:58 +0300 |
commit | b29d609b0bf54345f9c7cb8a1e3d6de6799fa147 (patch) | |
tree | 27fe7910ccc4e1487f0eb56b00868d62b41172a4 /src/servercommand.cpp | |
parent | 8a3c777c40e2b61c1ba561ba0c60ab8d281886d2 (diff) | |
download | minetest-b29d609b0bf54345f9c7cb8a1e3d6de6799fa147.tar.gz minetest-b29d609b0bf54345f9c7cb8a1e3d6de6799fa147.tar.bz2 minetest-b29d609b0bf54345f9c7cb8a1e3d6de6799fa147.zip |
Move chat commands to Lua and remove servercommand.{cpp,h}
Commands moved:
/me
/status
/time
/shutdown
/ban
/clearobjects
Diffstat (limited to 'src/servercommand.cpp')
-rw-r--r-- | src/servercommand.cpp | 191 |
1 files changed, 0 insertions, 191 deletions
diff --git a/src/servercommand.cpp b/src/servercommand.cpp deleted file mode 100644 index f14e0fba1..000000000 --- a/src/servercommand.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/* -Part of Minetest-c55 -Copyright (C) 2010-11 celeron55, Perttu Ahola <celeron55@gmail.com> -Copyright (C) 2011 Ciaran Gultnieks <ciaran@ciarang.com> - -Permission to use, copy, modify, and distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "servercommand.h" -#include "settings.h" -#include "main.h" // For g_settings -#include "content_sao.h" - -#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" - -void cmd_status(std::wostringstream &os, - ServerCommandContext *ctx) -{ - os<<ctx->server->getStatusString(); -} - -void cmd_me(std::wostringstream &os, - ServerCommandContext *ctx) -{ - if(!ctx->server->checkPriv(ctx->player->getName(), "shout")) - { - os<<L"-!- You don't have permission to shout."; - return; - } - - 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_time(std::wostringstream &os, - ServerCommandContext *ctx) -{ - if(ctx->parms.size() != 2) - { - os<<L"-!- Missing parameter"; - return; - } - - if(!ctx->server->checkPriv(ctx->player->getName(), "settime")) - { - os<<L"-!- You don't have permission to do this."; - return; - } - - u32 time = stoi(wide_to_narrow(ctx->parms[1])); - ctx->server->setTimeOfDay(time); - os<<L"-!- Time of day changed."; - - actionstream<<ctx->player->getName()<<" sets time " - <<time<<std::endl; -} - -void cmd_shutdown(std::wostringstream &os, - ServerCommandContext *ctx) -{ - if(!ctx->server->checkPriv(ctx->player->getName(), "server")) - { - os<<L"-!- You don't have permission to do this."; - return; - } - - actionstream<<ctx->player->getName() - <<" shuts down server"<<std::endl; - - ctx->server->requestShutdown(); - - os<<L"*** Server shutting down (operator request)."; - ctx->flags |= SEND_TO_OTHERS; -} - -void cmd_banunban(std::wostringstream &os, ServerCommandContext *ctx) -{ - if(!ctx->server->checkPriv(ctx->player->getName(), "ban")) - { - os<<L"-!- You don't have permission to do this."; - 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; - } - - try{ - Address address = ctx->server->getPeerAddress(player->peer_id); - std::string ip_string = address.serializeString(); - ctx->server->setIpBanned(ip_string, player->getName()); - os<<L"-!- Banned "<<narrow_to_wide(ip_string)<<L"|" - <<narrow_to_wide(player->getName()); - - actionstream<<ctx->player->getName()<<" bans " - <<player->getName()<<" / "<<ip_string<<std::endl; - } catch(con::PeerNotFoundException){ - dstream<<__FUNCTION_NAME<<": peer was not found"<<std::endl; - } - } - 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); - - actionstream<<ctx->player->getName()<<" unbans " - <<ip_or_name<<std::endl; - } -} - -void cmd_clearobjects(std::wostringstream &os, - ServerCommandContext *ctx) -{ - if(!ctx->server->checkPriv(ctx->player->getName(), "server")) - { - os<<L"-!- You don't have permission to do this."; - return; - } - - actionstream<<ctx->player->getName() - <<" clears all objects"<<std::endl; - - { - std::wstring msg; - msg += L"Clearing all objects. This may take long."; - msg += L" You may experience a timeout. (by "; - msg += narrow_to_wide(ctx->player->getName()); - msg += L")"; - ctx->server->notifyPlayers(msg); - } - - ctx->env->clearAllObjects(); - - actionstream<<"object clearing done"<<std::endl; - - os<<L"*** Cleared all objects."; - ctx->flags |= SEND_TO_OTHERS; -} - - -std::wstring processServerCommand(ServerCommandContext *ctx) -{ - std::wostringstream os(std::ios_base::binary); - ctx->flags = SEND_TO_SENDER; // Default, unless we change it. - - if(ctx->parms.size() == 0) - os<<L"-!- Empty command"; - else if(ctx->parms[0] == L"status") - cmd_status(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"ban" || ctx->parms[0] == L"unban") - cmd_banunban(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<<L"-!- Invalid command: " + ctx->parms[0]; - - return os.str(); -} - - |