From 8bba9cde5c2536812679855e145954929a054d48 Mon Sep 17 00:00:00 2001
From: Ciaran Gultnieks <ciaran@ciarang.com>
Date: Mon, 16 May 2011 18:26:37 +0100
Subject: [PATCH] Restored the auto-admin powers of the local user (via name=
 in the config)

--HG--
extra : rebase_source : a35aa0d978990c28fa4fc158ce47d1f4aa967c04
---
 src/server.cpp        | 10 ++++++++--
 src/servercommand.cpp | 16 +++++++++-------
 src/servercommand.h   |  8 ++++++--
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/server.cpp b/src/server.cpp
index 6c57daa5c..d211186eb 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -2870,12 +2870,18 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
 
 			message = message.substr(commandprefix.size());
 
+			// Local player gets all privileges regardless of
+			// what's set on their account.
+			u64 privs = player->privs;
+			if(g_settings.get("name") == player->getName())
+				privs = PRIV_ALL;
+
 			ServerCommandContext *ctx = new ServerCommandContext(
 				str_split(message, L' '),
 				this,
 				&m_env,
-				player
-				);
+				player,
+				privs);
 
 			line += processServerCommand(ctx);
 			send_to_sender = ctx->flags & 1;
diff --git a/src/servercommand.cpp b/src/servercommand.cpp
index 215dc0d27..5bb4f67f8 100644
--- a/src/servercommand.cpp
+++ b/src/servercommand.cpp
@@ -33,11 +33,13 @@ void cmd_privs(std::wostringstream &os,
 {
 	if(ctx->parms.size() == 1)
 	{
+		// Show our own real privs, without any adjustments
+		// made for admin status
 		os<<L"-!- " + privsToString(ctx->player->privs);
 		return;
 	}
 
-	if((ctx->player->privs & PRIV_PRIVS) == 0)
+	if((ctx->privs & PRIV_PRIVS) == 0)
 	{
 		os<<L"-!- You don't have permission to do that";
 		return;
@@ -62,7 +64,7 @@ void cmd_grantrevoke(std::wostringstream &os,
 		return;
 	}
 
-	if((ctx->player->privs & PRIV_PRIVS) == 0)
+	if((ctx->privs & PRIV_PRIVS) == 0)
 	{
 		os<<L"-!- You don't have permission to do that";
 		return;
@@ -100,7 +102,7 @@ void cmd_time(std::wostringstream &os,
 		return;
 	}
 
-	if((ctx->player->privs & PRIV_SETTIME) ==0)
+	if((ctx->privs & PRIV_SETTIME) ==0)
 	{
 		os<<L"-!- You don't have permission to do that";
 		return;
@@ -114,7 +116,7 @@ void cmd_time(std::wostringstream &os,
 void cmd_shutdown(std::wostringstream &os,
 	ServerCommandContext *ctx)
 {
-	if((ctx->player->privs & PRIV_SERVER) ==0)
+	if((ctx->privs & PRIV_SERVER) ==0)
 	{
 		os<<L"-!- You don't have permission to do that";
 		return;
@@ -131,7 +133,7 @@ void cmd_shutdown(std::wostringstream &os,
 void cmd_setting(std::wostringstream &os,
 	ServerCommandContext *ctx)
 {
-	if((ctx->player->privs & PRIV_SERVER) ==0)
+	if((ctx->privs & PRIV_SERVER) ==0)
 	{
 		os<<L"-!- You don't have permission to do that";
 		return;
@@ -145,7 +147,7 @@ void cmd_setting(std::wostringstream &os,
 void cmd_teleport(std::wostringstream &os,
 	ServerCommandContext *ctx)
 {
-	if((ctx->player->privs & PRIV_TELEPORT) ==0)
+	if((ctx->privs & PRIV_TELEPORT) ==0)
 	{
 		os<<L"-!- You don't have permission to do that";
 		return;
@@ -178,7 +180,7 @@ 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;
+	u64 privs = ctx->privs;
 
 	if(ctx->parms.size() == 0 || ctx->parms[0] == L"help")
 	{
diff --git a/src/servercommand.h b/src/servercommand.h
index bc7823c66..058fbe65b 100644
--- a/src/servercommand.h
+++ b/src/servercommand.h
@@ -34,14 +34,18 @@ struct ServerCommandContext
 	Server* server;
 	ServerEnvironment *env;
 	Player* player;
+	// Effective privs for the player, which may be different to their
+	// stored ones - e.g. if they are named in the config as an admin.
+	u64 privs;
 	u32 flags;
 
 	ServerCommandContext(
 		std::vector<std::wstring> parms,
 		Server* server,
 		ServerEnvironment *env,
-		Player* player)
-		: parms(parms), server(server), env(env), player(player)
+		Player* player,
+		u64 privs)
+		: parms(parms), server(server), env(env), player(player), privs(privs)
 	{
 	}
 
-- 
GitLab