summaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp91
1 files changed, 26 insertions, 65 deletions
diff --git a/src/server.cpp b/src/server.cpp
index b5a38aa06..f77b4f3c6 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "materials.h"
#include "mineral.h"
#include "config.h"
+#include "servercommand.h"
#define BLOCK_EMERGE_FLAG_FROMDISK (1<<0)
@@ -1994,6 +1995,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(datasize < 13)
return;
+ if((player->privs & PRIV_BUILD) == 0)
+ return;
+
/*
[0] u16 command
[2] u8 button (0=left, 1=right)
@@ -2075,6 +2079,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(datasize < 7)
return;
+ if((player->privs & PRIV_BUILD) == 0)
+ return;
+
/*
length: 7
[0] u16 command
@@ -2167,6 +2174,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
{
if(datasize < 17)
return;
+ if((player->privs & PRIV_BUILD) == 0)
+ return;
/*
length: 17
[0] u16 command
@@ -2615,6 +2624,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
#endif
else if(command == TOSERVER_SIGNTEXT)
{
+ if((player->privs & PRIV_BUILD) == 0)
+ return;
/*
u16 command
v3s16 blockpos
@@ -2672,6 +2683,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
else if(command == TOSERVER_SIGNNODETEXT)
{
+ if((player->privs & PRIV_BUILD) == 0)
+ return;
/*
u16 command
v3s16 p
@@ -2853,71 +2866,19 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
line += L"Server: ";
message = message.substr(commandprefix.size());
- // Get player name as narrow string
- std::string name_s = player->getName();
- // Convert message to narrow string
- std::string message_s = wide_to_narrow(message);
- // Operator is the single name defined in config.
- std::string operator_name = g_settings.get("name");
- bool is_operator = (operator_name != "" &&
- wide_to_narrow(name) == operator_name);
- bool valid_command = false;
- if(message_s == "help")
- {
- line += L"-!- Available commands: ";
- line += L"status ";
- if(is_operator)
- {
- line += L"shutdown setting time ";
- }
- else
- {
- }
- send_to_sender = true;
- valid_command = true;
- }
- else if(message_s == "status")
- {
- line = getStatusString();
- send_to_sender = true;
- valid_command = true;
- }
- else if(is_operator)
- {
- if(message_s == "shutdown")
- {
- dstream<<DTIME<<" Server: Operator requested shutdown."
- <<std::endl;
- m_shutdown_requested.set(true);
-
- line += L"*** Server shutting down (operator request)";
- send_to_sender = true;
- valid_command = true;
- }
- else if(message_s.substr(0,8) == "setting ")
- {
- std::string confline = message_s.substr(8);
- g_settings.parseConfigLine(confline);
- line += L"-!- Setting changed.";
- send_to_sender = true;
- valid_command = true;
- }
- else if(message_s.substr(0,5) == "time ")
- {
- u32 time = stoi(message_s.substr(5));
- m_time_of_day.set(time);
- m_time_of_day_send_timer = 0;
- line += L"-!- time_of_day changed.";
- send_to_sender = true;
- valid_command = true;
- }
- }
-
- if(valid_command == false)
- {
- line += L"-!- Invalid command: " + message;
- send_to_sender = true;
- }
+
+ ServerCommandContext *ctx = new ServerCommandContext(
+ str_split(message, L' '),
+ this,
+ &m_env,
+ player
+ );
+
+ line += ServerCommand::processCommand(ctx);
+ send_to_sender = ctx->flags & 1;
+ send_to_others = ctx->flags & 2;
+ delete ctx;
+
}
else
{