diff --git a/src/server.cpp b/src/server.cpp index 338b528e..d3ca32ac 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2877,7 +2877,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) player ); - line += ServerCommand::processCommand(ctx); + line += processServerCommand(ctx); send_to_sender = ctx->flags & 1; send_to_others = ctx->flags & 2; delete ctx; diff --git a/src/servercommand.cpp b/src/servercommand.cpp index 21483b54..215dc0d2 100644 --- a/src/servercommand.cpp +++ b/src/servercommand.cpp @@ -22,11 +22,157 @@ 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) +void cmd_status(std::wostringstream &os, + ServerCommandContext *ctx) +{ + os<server->getStatusString(); +} + +void 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 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 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 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 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."; +} + + +std::wstring processServerCommand(ServerCommandContext *ctx) { std::wostringstream os(std::ios_base::binary); @@ -82,152 +228,4 @@ std::wstring ServerCommand::processCommand(ServerCommandContext *ctx) 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."; -} diff --git a/src/servercommand.h b/src/servercommand.h index 01efcae0..bc7823c6 100644 --- a/src/servercommand.h +++ b/src/servercommand.h @@ -47,29 +47,11 @@ struct ServerCommandContext }; -class ServerCommand -{ -public: - - static std::wstring processCommand(ServerCommandContext *ctx); - -private: - - static void cmd_status(std::wostringstream &os, - ServerCommandContext *ctx); - static void cmd_privs(std::wostringstream &os, - ServerCommandContext *ctx); - static void cmd_grantrevoke(std::wostringstream &os, - ServerCommandContext *ctx); - static void cmd_time(std::wostringstream &os, - ServerCommandContext *ctx); - static void cmd_shutdown(std::wostringstream &os, - ServerCommandContext *ctx); - static void cmd_setting(std::wostringstream &os, - ServerCommandContext *ctx); - static void cmd_teleport(std::wostringstream &os, - ServerCommandContext *ctx); -}; +// 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 processServerCommand(ServerCommandContext *ctx); #endif