From fd353792c289a98aa29ebb2e31ab703ee5e09fd9 Mon Sep 17 00:00:00 2001 From: amibu Date: Thu, 14 Sep 2017 17:07:58 +0200 Subject: [PATCH] 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 );