mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-25 05:57:45 +00:00
Remove UserLevel, handle DebugCommand permissions via internal GM rank
This commit is contained in:
parent
d12db28951
commit
00d5e93e74
4 changed files with 22 additions and 32 deletions
|
@ -424,15 +424,6 @@ namespace Core {
|
||||||
Land = 0x200,
|
Land = 0x200,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum UserLevel : uint8_t
|
|
||||||
{
|
|
||||||
all = 0xff,
|
|
||||||
player = 0x01,
|
|
||||||
gm = 0x02,
|
|
||||||
dev = 0x04,
|
|
||||||
admin = 0x08
|
|
||||||
};
|
|
||||||
|
|
||||||
struct QuestActive
|
struct QuestActive
|
||||||
{
|
{
|
||||||
QuestActive()
|
QuestActive()
|
||||||
|
|
|
@ -29,14 +29,14 @@ namespace Core {
|
||||||
std::string m_helpText;
|
std::string m_helpText;
|
||||||
|
|
||||||
// userlevel needed to execute the command
|
// 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_commandName = n;
|
||||||
m_pFunc = functionPtr;
|
m_pFunc = functionPtr;
|
||||||
m_helpText = hText;
|
m_helpText = hText;
|
||||||
m_userLevel = uLevel;
|
m_gmLevel = uLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
~DebugCommand()
|
~DebugCommand()
|
||||||
|
@ -54,9 +54,9 @@ namespace Core {
|
||||||
return m_helpText;
|
return m_helpText;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::UserLevel getUserLevel() const
|
uint8_t getRequiredGmLevel() const
|
||||||
{
|
{
|
||||||
return m_userLevel;
|
return m_gmLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,16 +41,15 @@ extern Core::ServerZone g_serverZone;
|
||||||
Core::DebugCommandHandler::DebugCommandHandler()
|
Core::DebugCommandHandler::DebugCommandHandler()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Push all commands onto the register map
|
// Push all commands onto the register map ( command name - function - description - required GM level )
|
||||||
registerCommand( "set", &DebugCommandHandler::set, "Loads and injects a premade Packet.", Common::UserLevel::all );
|
registerCommand( "set", &DebugCommandHandler::set, "Loads and injects a premade Packet.", 1 );
|
||||||
registerCommand( "get", &DebugCommandHandler::get, "Loads and injects a premade Packet.", Common::UserLevel::all );
|
registerCommand( "get", &DebugCommandHandler::get, "Loads and injects a premade Packet.", 1 );
|
||||||
registerCommand( "add", &DebugCommandHandler::add, "Loads and injects a premade Packet.", Common::UserLevel::all );
|
registerCommand( "add", &DebugCommandHandler::add, "Loads and injects a premade Packet.", 1 );
|
||||||
//registerCommand( "debug", &DebugCommandHandler::debug, "Loads and injects a premade Packet.", Common::UserLevel::all );
|
registerCommand( "inject", &DebugCommandHandler::injectPacket, "Loads and injects a premade Packet.", 1 );
|
||||||
registerCommand( "inject", &DebugCommandHandler::injectPacket, "Loads and injects a premade Packet.", Common::UserLevel::all );
|
registerCommand( "injectc", &DebugCommandHandler::injectChatPacket, "Loads and injects a premade Packet.", 1 );
|
||||||
registerCommand( "injectc", &DebugCommandHandler::injectChatPacket, "Loads and injects a premade Packet.", Common::UserLevel::all );
|
registerCommand( "script_reload", &DebugCommandHandler::scriptReload, "Loads and injects a premade Packet.", 1 );
|
||||||
registerCommand( "script_reload", &DebugCommandHandler::scriptReload, "Loads and injects a premade Packet.", Common::UserLevel::all );
|
registerCommand( "nudge", &DebugCommandHandler::nudge, "Nudges you forward/up/down", 1 );
|
||||||
registerCommand( "nudge", &DebugCommandHandler::nudge, "Nudges you forward/up/down", Common::UserLevel::all );
|
registerCommand( "info", &DebugCommandHandler::serverInfo, "Send server info", 0 );
|
||||||
registerCommand( "info", &DebugCommandHandler::serverInfo, "Send server info", Common::UserLevel::all );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ Core::DebugCommandHandler::~DebugCommandHandler()
|
||||||
|
|
||||||
// add a command set to the register map
|
// add a command set to the register map
|
||||||
void Core::DebugCommandHandler::registerCommand( const std::string& n, Core::DebugCommand::pFunc functionPtr,
|
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 );
|
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
|
// no parameters, just get the command
|
||||||
commandString = tmpCommand;
|
commandString = tmpCommand;
|
||||||
|
|
||||||
if ( pPlayer->getGmRank() <= 0 && commandString != "info" )
|
|
||||||
{
|
|
||||||
pPlayer->sendUrgent( "You are not allowed to use debug commands." );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// try to retrieve the command
|
// try to retrieve the command
|
||||||
auto it = m_commandMap.find( commandString );
|
auto it = m_commandMap.find( commandString );
|
||||||
|
|
||||||
|
@ -102,6 +95,12 @@ void Core::DebugCommandHandler::execCommand( char * data, Core::Entity::PlayerPt
|
||||||
pPlayer->sendUrgent( "Command not found." );
|
pPlayer->sendUrgent( "Command not found." );
|
||||||
else
|
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.
|
// command found, call the callback function and pass parameters if present.
|
||||||
pf = ( *it ).second->m_pFunc;
|
pf = ( *it ).second->m_pFunc;
|
||||||
( this->*pf )( data, pPlayer, ( *it ).second );
|
( this->*pf )( data, pPlayer, ( *it ).second );
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
~DebugCommandHandler();
|
~DebugCommandHandler();
|
||||||
|
|
||||||
// register command to command map
|
// 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
|
// execute command if registered
|
||||||
void execCommand( char * data, Entity::PlayerPtr pPlayer );
|
void execCommand( char * data, Entity::PlayerPtr pPlayer );
|
||||||
|
|
Loading…
Add table
Reference in a new issue