#include "servercommand.h"
#include "utility.h"
+#include "settings.h"
+#include "main.h" // For g_settings
+
+#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)
+{
+ 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_privs(std::wostringstream &os,
ServerCommandContext *ctx)
{
std::string playername = wide_to_narrow(ctx->parms[1]);
u64 privs = ctx->server->getPlayerAuthPrivs(playername);
- if(ctx->parms[0] == L"grant")
+ if(ctx->parms[0] == L"grant"){
privs |= newprivs;
- else
+ actionstream<<ctx->player->getName()<<" grants "
+ <<wide_to_narrow(ctx->parms[2])<<" to "
+ <<playername<<std::endl;
+
+ std::wstring msg;
+ msg += narrow_to_wide(ctx->player->getName());
+ msg += L" granted you the privilege \"";
+ msg += ctx->parms[2];
+ msg += L"\"";
+ ctx->server->notifyPlayer(playername.c_str(), msg);
+ } else {
privs &= ~newprivs;
+ actionstream<<ctx->player->getName()<<" revokes "
+ <<wide_to_narrow(ctx->parms[2])<<" from "
+ <<playername<<std::endl;
+
+ std::wstring msg;
+ msg += narrow_to_wide(ctx->player->getName());
+ msg += L" revoked from you the privilege \"";
+ msg += ctx->parms[2];
+ msg += L"\"";
+ ctx->server->notifyPlayer(playername.c_str(), msg);
+ }
ctx->server->setPlayerAuthPrivs(playername, privs);
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,
return;
}
- dstream<<DTIME<<" Server: Operator requested shutdown."
- <<std::endl;
+ actionstream<<ctx->player->getName()
+ <<" shuts down server"<<std::endl;
+
ctx->server->requestShutdown();
os<<L"*** Server shutting down (operator request)";
std::string confline = wide_to_narrow(ctx->paramstring);
- g_settings.parseConfigLine(confline);
+ actionstream<<ctx->player->getName()
+ <<" sets: "<<confline<<std::endl;
+
+ g_settings->parseConfigLine(confline);
ctx->server->saveConfig();
}
v3f dest(stoi(coords[0])*10, stoi(coords[1])*10, stoi(coords[2])*10);
+
+ actionstream<<ctx->player->getName()<<" teleports from "
+ <<PP(ctx->player->getPosition()/BS)<<" to "
+ <<PP(dest/BS)<<std::endl;
+
ctx->player->setPosition(dest);
ctx->server->SendMovePlayer(ctx->player);
os<<L"-!- No such player";
return;
}
-
- con::Peer *peer = ctx->server->getPeerNoEx(player->peer_id);
- if(peer == NULL)
- {
+
+ 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;
- return;
}
- std::string ip_string = peer->address.serializeString();
- ctx->server->setIpBanned(ip_string, player->getName());
- os<<L"-!- Banned "<<narrow_to_wide(ip_string)<<L"|"
- <<narrow_to_wide(player->getName());
}
else
{
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->privs & PRIV_SERVER) ==0)
+ {
+ os<<L"-!- You don't have permission to do that";
+ 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)
{
os<<L" ban unban";
}
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 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();
}