]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Server commands without classes
authorCiaran Gultnieks <ciaran@ciarang.com>
Mon, 16 May 2011 16:13:33 +0000 (17:13 +0100)
committerCiaran Gultnieks <ciaran@ciarang.com>
Mon, 16 May 2011 16:13:33 +0000 (17:13 +0100)
src/server.cpp
src/servercommand.cpp
src/servercommand.h

index 338b528e75432785dc59c1195746544015cf9c1e..d3ca32ac7d1a7473de3851da8e78cf8165075226 100644 (file)
@@ -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;
index 21483b548f4c68ab2a4d3ed2be7e08c2c0448da0..215dc0d275f09ff07efb0071c5620c03812bd8da 100644 (file)
@@ -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<<L"-!- Available commands: ";
-               os<<L"status privs ";
-               if(privs & PRIV_SERVER)
-                       os<<L"shutdown setting ";
-               if(privs & PRIV_SETTIME)
-                       os<<L" time";
-               if(privs & PRIV_TELEPORT)
-                       os<<L" teleport";
-               if(privs & PRIV_PRIVS)
-                       os<<L" grant revoke";
-       }
-       else if(ctx->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<<L"-!- Invalid command: " + ctx->parms[0];
-       }
-       return os.str();
-}
-
-void ServerCommand::cmd_status(std::wostringstream &os,
+void cmd_status(std::wostringstream &os,
        ServerCommandContext *ctx)
 {
        os<<ctx->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<<L"-!- " + privsToString(tp->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<<privsToString(tp->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<<L"-!- time_of_day changed.";
 }
 
-void ServerCommand::cmd_shutdown(std::wostringstream &os,
+void cmd_shutdown(std::wostringstream &os,
        ServerCommandContext *ctx)
 {
        if((ctx->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<<L"-!- Available commands: ";
+               os<<L"status privs ";
+               if(privs & PRIV_SERVER)
+                       os<<L"shutdown setting ";
+               if(privs & PRIV_SETTIME)
+                       os<<L" time";
+               if(privs & PRIV_TELEPORT)
+                       os<<L" teleport";
+               if(privs & PRIV_PRIVS)
+                       os<<L" grant revoke";
+       }
+       else if(ctx->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<<L"-!- Invalid command: " + ctx->parms[0];
+       }
+       return os.str();
+}
+
+
index 01efcae06a0ccea5af5f647bb0770c09a4196c04..bc7823c66ed0dc1dfa7241c02f509312f8bec9f8 100644 (file)
@@ -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