From b3268ff3896097abdd9199e4bb8ee826afda8388 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Mon, 16 May 2011 17:13:33 +0100 Subject: Server commands without classes --- src/servercommand.cpp | 132 +++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 67 deletions(-) (limited to 'src/servercommand.cpp') diff --git a/src/servercommand.cpp b/src/servercommand.cpp index 21483b548..215dc0d27 100644 --- a/src/servercommand.cpp +++ b/src/servercommand.cpp @@ -22,73 +22,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #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, +void cmd_status(std::wostringstream &os, ServerCommandContext *ctx) { os<server->getStatusString(); } -void ServerCommand::cmd_privs(std::wostringstream &os, +void cmd_privs(std::wostringstream &os, ServerCommandContext *ctx) { if(ctx->parms.size() == 1) @@ -113,7 +53,7 @@ void ServerCommand::cmd_privs(std::wostringstream &os, os<privs); } -void ServerCommand::cmd_grantrevoke(std::wostringstream &os, +void cmd_grantrevoke(std::wostringstream &os, ServerCommandContext *ctx) { if(ctx->parms.size() != 3) @@ -151,7 +91,7 @@ void ServerCommand::cmd_grantrevoke(std::wostringstream &os, os<privs); } -void ServerCommand::cmd_time(std::wostringstream &os, +void cmd_time(std::wostringstream &os, ServerCommandContext *ctx) { if(ctx->parms.size() != 2) @@ -171,7 +111,7 @@ void ServerCommand::cmd_time(std::wostringstream &os, os<player->privs & PRIV_SERVER) ==0) @@ -188,7 +128,7 @@ void ServerCommand::cmd_shutdown(std::wostringstream &os, ctx->flags |= 2; } -void ServerCommand::cmd_setting(std::wostringstream &os, +void cmd_setting(std::wostringstream &os, ServerCommandContext *ctx) { if((ctx->player->privs & PRIV_SERVER) ==0) @@ -202,7 +142,7 @@ void ServerCommand::cmd_setting(std::wostringstream &os, os<< L"-!- Setting changed."; } -void ServerCommand::cmd_teleport(std::wostringstream &os, +void cmd_teleport(std::wostringstream &os, ServerCommandContext *ctx) { if((ctx->player->privs & PRIV_TELEPORT) ==0) @@ -231,3 +171,61 @@ void ServerCommand::cmd_teleport(std::wostringstream &os, os<< L"-!- Teleported."; } + +std::wstring processServerCommand(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(); +} + + -- cgit v1.2.3