1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-24 21:57:44 +00:00

Remove UserLevel, handle DebugCommand permissions via internal GM rank

This commit is contained in:
amibu 2017-09-18 18:44:38 +02:00
parent d12db28951
commit 00d5e93e74
4 changed files with 22 additions and 32 deletions

View file

@ -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()

View file

@ -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;
}
};

View file

@ -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<DebugCommand>( 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 );

View file

@ -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 );