From 00d5e93e742604853076da8a65dbfe04d8dfdf16 Mon Sep 17 00:00:00 2001 From: amibu Date: Mon, 18 Sep 2017 18:44:38 +0200 Subject: [PATCH] Remove UserLevel, handle DebugCommand permissions via internal GM rank --- src/servers/Server_Common/Common.h | 9 ----- .../Server_Zone/DebugCommand/DebugCommand.h | 10 +++--- .../DebugCommand/DebugCommandHandler.cpp | 33 +++++++++---------- .../DebugCommand/DebugCommandHandler.h | 2 +- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/servers/Server_Common/Common.h b/src/servers/Server_Common/Common.h index 966596bc..3247044a 100644 --- a/src/servers/Server_Common/Common.h +++ b/src/servers/Server_Common/Common.h @@ -424,15 +424,6 @@ namespace Core { Land = 0x200, }; - enum UserLevel : uint8_t - { - all = 0xff, - player = 0x01, - gm = 0x02, - dev = 0x04, - admin = 0x08 - }; - struct QuestActive { QuestActive() diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommand.h b/src/servers/Server_Zone/DebugCommand/DebugCommand.h index a35e72f1..082995fa 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommand.h +++ b/src/servers/Server_Zone/DebugCommand/DebugCommand.h @@ -29,14 +29,14 @@ namespace Core { std::string m_helpText; // userlevel needed to execute the command - Common::UserLevel m_userLevel; + uint8_t m_gmLevel; - DebugCommand( const std::string& n, pFunc functionPtr, const std::string& hText, Common::UserLevel uLevel ) + DebugCommand( const std::string& n, pFunc functionPtr, const std::string& hText, uint8_t uLevel ) { m_commandName = n; m_pFunc = functionPtr; m_helpText = hText; - m_userLevel = uLevel; + m_gmLevel = uLevel; } ~DebugCommand() @@ -54,9 +54,9 @@ namespace Core { return m_helpText; } - Common::UserLevel getUserLevel() const + uint8_t getRequiredGmLevel() const { - return m_userLevel; + return m_gmLevel; } }; diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp index b04d4389..2d9c3d2a 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp +++ b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp @@ -41,16 +41,15 @@ extern Core::ServerZone g_serverZone; Core::DebugCommandHandler::DebugCommandHandler() { - // Push all commands onto the register map - registerCommand( "set", &DebugCommandHandler::set, "Loads and injects a premade Packet.", Common::UserLevel::all ); - registerCommand( "get", &DebugCommandHandler::get, "Loads and injects a premade Packet.", Common::UserLevel::all ); - registerCommand( "add", &DebugCommandHandler::add, "Loads and injects a premade Packet.", Common::UserLevel::all ); - //registerCommand( "debug", &DebugCommandHandler::debug, "Loads and injects a premade Packet.", Common::UserLevel::all ); - registerCommand( "inject", &DebugCommandHandler::injectPacket, "Loads and injects a premade Packet.", Common::UserLevel::all ); - registerCommand( "injectc", &DebugCommandHandler::injectChatPacket, "Loads and injects a premade Packet.", Common::UserLevel::all ); - registerCommand( "script_reload", &DebugCommandHandler::scriptReload, "Loads and injects a premade Packet.", Common::UserLevel::all ); - registerCommand( "nudge", &DebugCommandHandler::nudge, "Nudges you forward/up/down", Common::UserLevel::all ); - registerCommand( "info", &DebugCommandHandler::serverInfo, "Send server info", Common::UserLevel::all ); + // Push all commands onto the register map ( command name - function - description - required GM level ) + registerCommand( "set", &DebugCommandHandler::set, "Loads and injects a premade Packet.", 1 ); + registerCommand( "get", &DebugCommandHandler::get, "Loads and injects a premade Packet.", 1 ); + registerCommand( "add", &DebugCommandHandler::add, "Loads and injects a premade Packet.", 1 ); + registerCommand( "inject", &DebugCommandHandler::injectPacket, "Loads and injects a premade Packet.", 1 ); + registerCommand( "injectc", &DebugCommandHandler::injectChatPacket, "Loads and injects a premade Packet.", 1 ); + registerCommand( "script_reload", &DebugCommandHandler::scriptReload, "Loads and injects a premade Packet.", 1 ); + registerCommand( "nudge", &DebugCommandHandler::nudge, "Nudges you forward/up/down", 1 ); + registerCommand( "info", &DebugCommandHandler::serverInfo, "Send server info", 0 ); } @@ -63,7 +62,7 @@ Core::DebugCommandHandler::~DebugCommandHandler() // add a command set to the register map void Core::DebugCommandHandler::registerCommand( const std::string& n, Core::DebugCommand::pFunc functionPtr, - const std::string& hText, Core::Common::UserLevel uLevel ) + const std::string& hText, uint8_t uLevel ) { m_commandMap[std::string( n )] = boost::make_shared( n, functionPtr, hText, uLevel ); } @@ -88,12 +87,6 @@ void Core::DebugCommandHandler::execCommand( char * data, Core::Entity::PlayerPt // no parameters, just get the command commandString = tmpCommand; - if ( pPlayer->getGmRank() <= 0 && commandString != "info" ) - { - pPlayer->sendUrgent( "You are not allowed to use debug commands." ); - return; - } - // try to retrieve the command auto it = m_commandMap.find( commandString ); @@ -102,6 +95,12 @@ void Core::DebugCommandHandler::execCommand( char * data, Core::Entity::PlayerPt pPlayer->sendUrgent( "Command not found." ); else { + if( pPlayer->getGmRank() < it->second->getRequiredGmLevel() ) + { + pPlayer->sendUrgent( "You are not allowed to use this command." ); + return; + } + // command found, call the callback function and pass parameters if present. pf = ( *it ).second->m_pFunc; ( this->*pf )( data, pPlayer, ( *it ).second ); diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h index fc12606e..12ff13b3 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h +++ b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h @@ -22,7 +22,7 @@ public: ~DebugCommandHandler(); // register command to command map - void registerCommand( const std::string& n, DebugCommand::pFunc, const std::string& hText, Common::UserLevel uLevel ); + void registerCommand( const std::string& n, DebugCommand::pFunc, const std::string& hText, uint8_t uLevel ); // execute command if registered void execCommand( char * data, Entity::PlayerPtr pPlayer );