From fd353792c289a98aa29ebb2e31ab703ee5e09fd9 Mon Sep 17 00:00:00 2001 From: amibu Date: Thu, 14 Sep 2017 17:07:58 +0200 Subject: [PATCH 1/3] Add basic server info command --- .../DebugCommand/DebugCommandHandler.cpp | 22 +++++++++++++------ .../DebugCommand/DebugCommandHandler.h | 1 + src/servers/Server_Zone/ServerZone.cpp | 5 +++++ src/servers/Server_Zone/ServerZone.h | 2 ++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp index eaf9c731..46bae275 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp +++ b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -49,6 +50,7 @@ Core::DebugCommandHandler::DebugCommandHandler() 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); } @@ -70,12 +72,6 @@ void Core::DebugCommandHandler::registerCommand( const std::string& n, Core::Deb void Core::DebugCommandHandler::execCommand( char * data, Core::Entity::PlayerPtr pPlayer ) { - if( pPlayer->getGmRank() <= 0 ) - { - pPlayer->sendUrgent( "You are not allowed to use debug commands." ); - return; - } - // define callback pointer void ( DebugCommandHandler::*pf )( char *, Entity::PlayerPtr, boost::shared_ptr< DebugCommand > ); @@ -92,13 +88,18 @@ 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 ); if( it == m_commandMap.end() ) // no command found, do something... or not pPlayer->sendUrgent( "Command not found." ); - // TODO Notify the client of the failed command else { // command found, call the callback function and pass parameters if present. @@ -534,3 +535,10 @@ void Core::DebugCommandHandler::nudge( char * data, Entity::PlayerPtr pPlayer, b pPlayer->queuePacket( setActorPosPacket ); } } + +void Core::DebugCommandHandler::serverInfo(char * data, Core::Entity::PlayerPtr pPlayer, boost::shared_ptr< Core::DebugCommand > command) +{ + pPlayer->sendDebug( "SapphireServer " + Version::VERSION + " - " + Version::GIT_HASH ); + pPlayer->sendDebug( "Sessions: " + std::to_string( g_serverZone.getSessionCount() ) ); +} + diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h index 69ef7c4a..fa481889 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h +++ b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h @@ -37,6 +37,7 @@ public: void injectPacket( char * data, Entity::PlayerPtr pPlayer, boost::shared_ptr command ); void injectChatPacket( char * data, Entity::PlayerPtr pPlayer, boost::shared_ptr command ); void nudge( char* data, Entity::PlayerPtr pPlayer, boost::shared_ptr command ); + void serverInfo(char * data, Entity::PlayerPtr pPlayer, boost::shared_ptr command); }; diff --git a/src/servers/Server_Zone/ServerZone.cpp b/src/servers/Server_Zone/ServerZone.cpp index 8d5bb5dc..6fb74f16 100644 --- a/src/servers/Server_Zone/ServerZone.cpp +++ b/src/servers/Server_Zone/ServerZone.cpp @@ -55,6 +55,11 @@ Core::XMLConfigPtr Core::ServerZone::getConfig() const return m_pConfig; } +size_t Core::ServerZone::getSessionCount() const +{ + return m_sessionMap.size(); +} + bool Core::ServerZone::registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, uint32_t modelId, std::string aiName ) { diff --git a/src/servers/Server_Zone/ServerZone.h b/src/servers/Server_Zone/ServerZone.h index b6878c5a..ab0b81b9 100644 --- a/src/servers/Server_Zone/ServerZone.h +++ b/src/servers/Server_Zone/ServerZone.h @@ -33,6 +33,8 @@ namespace Core { XMLConfigPtr getConfig() const; + size_t Core::ServerZone::getSessionCount() const; + bool registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, uint32_t modelId, std::string aiName ); From 22b983cdcf6a3c464f02fd17b9aeb121d160e308 Mon Sep 17 00:00:00 2001 From: amibu Date: Thu, 14 Sep 2017 17:19:44 +0200 Subject: [PATCH 2/3] Style fixes --- .../Server_Zone/DebugCommand/DebugCommandHandler.cpp | 8 ++++---- .../Server_Zone/DebugCommand/DebugCommandHandler.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp index 46bae275..b04d4389 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp +++ b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp @@ -50,7 +50,7 @@ Core::DebugCommandHandler::DebugCommandHandler() 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); + registerCommand( "info", &DebugCommandHandler::serverInfo, "Send server info", Common::UserLevel::all ); } @@ -88,9 +88,9 @@ void Core::DebugCommandHandler::execCommand( char * data, Core::Entity::PlayerPt // no parameters, just get the command commandString = tmpCommand; - if (pPlayer->getGmRank() <= 0 && commandString != "info") + if ( pPlayer->getGmRank() <= 0 && commandString != "info" ) { - pPlayer->sendUrgent("You are not allowed to use debug commands."); + pPlayer->sendUrgent( "You are not allowed to use debug commands." ); return; } @@ -536,7 +536,7 @@ void Core::DebugCommandHandler::nudge( char * data, Entity::PlayerPtr pPlayer, b } } -void Core::DebugCommandHandler::serverInfo(char * data, Core::Entity::PlayerPtr pPlayer, boost::shared_ptr< Core::DebugCommand > command) +void Core::DebugCommandHandler::serverInfo( char * data, Core::Entity::PlayerPtr pPlayer, boost::shared_ptr< Core::DebugCommand > command ) { pPlayer->sendDebug( "SapphireServer " + Version::VERSION + " - " + Version::GIT_HASH ); pPlayer->sendDebug( "Sessions: " + std::to_string( g_serverZone.getSessionCount() ) ); diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h index fa481889..fc12606e 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h +++ b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.h @@ -37,7 +37,7 @@ public: void injectPacket( char * data, Entity::PlayerPtr pPlayer, boost::shared_ptr command ); void injectChatPacket( char * data, Entity::PlayerPtr pPlayer, boost::shared_ptr command ); void nudge( char* data, Entity::PlayerPtr pPlayer, boost::shared_ptr command ); - void serverInfo(char * data, Entity::PlayerPtr pPlayer, boost::shared_ptr command); + void serverInfo( char * data, Entity::PlayerPtr pPlayer, boost::shared_ptr command ); }; From 7d8e62d95f1acc6467169adad20caf2a4cb751d0 Mon Sep 17 00:00:00 2001 From: Mordred <30826167+SapphireMordred@users.noreply.github.com> Date: Thu, 14 Sep 2017 17:28:24 +0200 Subject: [PATCH 3/3] no qualifiers in headers --- src/servers/Server_Zone/ServerZone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/servers/Server_Zone/ServerZone.h b/src/servers/Server_Zone/ServerZone.h index ab0b81b9..2472c487 100644 --- a/src/servers/Server_Zone/ServerZone.h +++ b/src/servers/Server_Zone/ServerZone.h @@ -33,7 +33,7 @@ namespace Core { XMLConfigPtr getConfig() const; - size_t Core::ServerZone::getSessionCount() const; + size_t getSessionCount() const; bool registerBnpcTemplate( std::string templateName, uint32_t bnpcBaseId, uint32_t bnpcNameId, uint32_t modelId, std::string aiName );