From 82bd37b012e1c9e76adfc3e7e40886081d1238c3 Mon Sep 17 00:00:00 2001 From: sfb Date: Mon, 12 Mar 2012 13:28:56 -0500 Subject: [PATCH] Fixed: #1449 Added missing header, fixed CMake configuration, fixed iterators. GUS builds fine without MFC extensions. --- .../ryzom/common/src/game_share/txt_command.h | 174 ++++++++++++++++++ code/ryzom/server/src/CMakeLists.txt | 2 +- .../general_utilities_service/CMakeLists.txt | 117 +++++++++++- .../general_utilities_service/em_commands.cpp | 3 +- .../em_event_manager.cpp | 8 +- .../general_utilities_service/gus_utils.cpp | 68 ------- .../src/general_utilities_service/gus_utils.h | 21 --- .../service_main.cpp | 6 +- 8 files changed, 300 insertions(+), 99 deletions(-) create mode 100644 code/ryzom/common/src/game_share/txt_command.h diff --git a/code/ryzom/common/src/game_share/txt_command.h b/code/ryzom/common/src/game_share/txt_command.h new file mode 100644 index 000000000..f8d2ec39e --- /dev/null +++ b/code/ryzom/common/src/game_share/txt_command.h @@ -0,0 +1,174 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +#ifndef TXT_COMMAND_H +#define TXT_COMMAND_H + + +//------------------------------------------------------------------------------------------------- +// includes +//------------------------------------------------------------------------------------------------- + +#include "nel/misc/types_nl.h" +#include "nel/misc/common.h" +#include "nel/misc/debug.h" +#include "nel/misc/sstring.h" + + +//------------------------------------------------------------------------------------------------- +// MACRO TXT_COMMAND_SET +//------------------------------------------------------------------------------------------------- + +#define TXT_COMMAND_SET(setName,CONTEXT_CLASS)\ +class __CTxtCommandSet_##setName: public ITxtCommandSet\ +{\ +public:\ + static __CTxtCommandSet_##setName* getInstance()\ + {\ + static __CTxtCommandSet_##setName *p=NULL;\ + if (p==NULL) p= new __CTxtCommandSet_##setName;\ + return p;\ + }\ +};\ +static CTxtCommandSetPtr<__CTxtCommandSet_##setName> setName; + + +//------------------------------------------------------------------------------------------------- +// MACRO TXT_COMMAND +//------------------------------------------------------------------------------------------------- + +#define TXT_COMMAND(cmdName,setName,CONTEXT_CLASS)\ +struct __CTxtCommand_##cmdName: public ITxtCommand\ +{\ + static __CTxtCommand_##cmdName* getInstance()\ + {\ + static __CTxtCommand_##cmdName *p=NULL;\ + if (p==NULL) p= new __CTxtCommand_##cmdName;\ + return p;\ + }\ + virtual const char* getName() const {return #cmdName;}\ + virtual CTxtCommandResult execute(CONTEXT_CLASS& context,const NLMISC::CVectorSString& args,const NLMISC::CSString& rawArgs,const NLMISC::CSString& fullCmdLine);\ +private:\ + __CTxtCommand_##cmdName() {}\ +};\ +static ITxtCommandRegisterer<__CTxtCommand_##cmdName,__CTxtCommandSet_##setName> __CTxtCommand_##cmdName##_Registerer;\ +CTxtCommandResult __CTxtCommand_##cmdName::execute(CONTEXT_CLASS& context,const NLMISC::CVectorSString& args,const NLMISC::CSString& rawArgs,const NLMISC::CSString& fullCmdLine) + + +//------------------------------------------------------------------------------------------------- +// class CTxtCommandResult +//------------------------------------------------------------------------------------------------- + +class CTxtCommandResult +{ +public: + enum TType + { + SUCCESS, // command execution was successful + SYNTAX_ERROR, // there was a syntax error in the command line + BAD_PERMISSION, // the user doesn't have the right to run the given command + UNKNOWN_COMMAND, // behave as if the command was not recognised + EXECUTION_ERROR // there was an error during execution of the command + }; + CTxtCommandResult(const bool& success): _Type(success?SUCCESS:SYNTAX_ERROR) {} + CTxtCommandResult(const TType& type): _Type(type) {} + CTxtCommandResult(const TType& type,const NLMISC::CSString& reason): _Type(type), _Reason(reason) {} + TType getType() const { return _Type; } + const NLMISC::CSString& getReason() const { return _Reason; } +private: + TType _Type; + NLMISC::CSString _Reason; +}; + + +//------------------------------------------------------------------------------------------------- +// class ITxtCommand +//------------------------------------------------------------------------------------------------- + +template class ITxtCommand +{ +public: + virtual const char* getName() const =0; + virtual CTxtCommandResult execute(CONTEXT_CLASS& context,const NLMISC::CVectorSString& args,const NLMISC::CSString& rawArgs,const NLMISC::CSString& fullCmdLine) =0; +}; + + +//------------------------------------------------------------------------------------------------- +// class ITxtCommandRegisterer +//------------------------------------------------------------------------------------------------- + +template struct ITxtCommandRegisterer +{ + ITxtCommandRegisterer() + { + SET::getInstance()->registerTxtCommand(CMD::getInstance()); + } +}; + + +//------------------------------------------------------------------------------------------------- +// class ITxtCommandSet +//------------------------------------------------------------------------------------------------- + +template class ITxtCommandSet +{ +public: + void registerTxtCommand(ITxtCommand* txtCommand) + { + nlassert(_TxtCommands.find(txtCommand->getName())==_TxtCommands.end()); + _TxtCommands[txtCommand->getName()]= txtCommand; + } + CTxtCommandResult execute(CONTEXT_CLASS& context,const NLMISC::CSString& cmdLine) + { + NLMISC::CSString cmdTail=cmdLine; + NLMISC::CSString keyword=cmdTail.firstWord(true); + typename TTxtCommands::iterator it= _TxtCommands.find(keyword); + if (it==_TxtCommands.end()) return CTxtCommandResult::UNKNOWN_COMMAND; + NLMISC::CVectorSString args; + cmdTail.splitWords(args); + return it->second->execute(context,args,cmdTail,cmdLine); + } +private: + typedef ITxtCommand TTxtCommand; + typedef std::map TTxtCommands; + TTxtCommands _TxtCommands; +}; + + +//------------------------------------------------------------------------------------------------- +// class ITxtCommandRegisterer +//------------------------------------------------------------------------------------------------- + +template struct CTxtCommandSetPtr +{ + CTxtCommandSetPtr() + { + SET::getInstance(); + } + + SET& operator*() + { + return *SET::getInstance(); + } + + SET* operator->() + { + return SET::getInstance(); + } +}; + + +//------------------------------------------------------------------------------------------------- +#endif diff --git a/code/ryzom/server/src/CMakeLists.txt b/code/ryzom/server/src/CMakeLists.txt index ddcca99bb..13cee545a 100644 --- a/code/ryzom/server/src/CMakeLists.txt +++ b/code/ryzom/server/src/CMakeLists.txt @@ -34,7 +34,7 @@ ADD_SUBDIRECTORY(patchman_service) #ADD_SUBDIRECTORY(ags_test) #ADD_SUBDIRECTORY(ai_data_service) #ADD_SUBDIRECTORY(entity_view_service) -#ADD_SUBDIRECTORY(general_utilities_service) +ADD_SUBDIRECTORY(general_utilities_service) # Not sure, no longer used maybe? #sabrina diff --git a/code/ryzom/server/src/general_utilities_service/CMakeLists.txt b/code/ryzom/server/src/general_utilities_service/CMakeLists.txt index 8dc1216d0..a50f7e67c 100644 --- a/code/ryzom/server/src/general_utilities_service/CMakeLists.txt +++ b/code/ryzom/server/src/general_utilities_service/CMakeLists.txt @@ -11,9 +11,120 @@ LIST(REMOVE_ITEM SRC ${CMAKE_CURRENT_SOURCE_DIR}/re_repository_emitter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rr_module_itf.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rr_module_itf.h - ${CMAKE_CURRENT_SOURCE_DIR}/rr_repository_reciever.cpp) + ${CMAKE_CURRENT_SOURCE_DIR}/rr_repository_reciever.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/mfc/*) -ADD_EXECUTABLE(ryzom_general_utilities_service ${SRC}) + + +SOURCE_GROUP("Documentation" FILES ss_notes.txt + ce_notes.txt + ec_notes.txt + ee_notes.txt + em_notes.txt + merge_notes.txt + gus_module_notes.txt + gus_net_notes.txt + saves_notes.txt + rs_notes.txt + rsaves_notes.txt + stats_notes.txt + server control module notes.txt) + +SOURCE_GROUP("GUS Modules\\Contest Control (CC)" FILES cc_commands.cpp cc_contest_ctrl_script.cpp cc_contest_ctrl_script.h cc_module_messages.h) + +SOURCE_GROUP("GUS Modules\\Contest Executor (CE)" FILES ce_commands.cpp ce_contest_executor.cpp ce_module_messages.h ce_contest_executor.h) + +SOURCE_GROUP("GUS Modules\\Contest Logger (CL)" FILES cl_contest_logger.cpp cl_module_messages.h) + +SOURCE_GROUP("GUS Modules\\Event Chat (EC)" FILES ec_channel.cpp + ec_channel.h + ec_ctrl_channel.cpp + ec_ctrl_channel.h + ec_event_chat.cpp + ec_event_chat_module.cpp + ec_event_chat_module.h + ec_faction_channel.cpp + ec_faction_channel.h + ec_party_channel.cpp + ec_party_channel.h + ec_types.h) + +SOURCE_GROUP("GUS Modules\\Event Executor (EE)" FILES ee_event_executor.cpp ee_event_executor.h ee_module_messages.h) + +SOURCE_GROUP("GUS Modules\\Event Executor (EE)" FILES em_commands.cpp em_event_manager.cpp em_event_manager.h em_module_messages.h) + +SOURCE_GROUP("GUS Modules\\Shard Merge (MERGE)" FILES merge_commands.cpp merge_shard_merger.cpp) + +SOURCE_GROUP("GUS Modules\\Remote Saves (RSAVES)" FILES remote_saves_interface.cpp remote_saves_interface.h rs_remote_saves.cpp rs_remote_saves.h rs_module_messages.h) + +SOURCE_GROUP("GUS Modules\\Shard Saves (SAVES)" FILES saves_module_messages.h saves_shard_saves.cpp saves_unit.cpp saves_unit.h) + +SOURCE_GROUP("GUS Modules\\Shard Script (SS)" FILES ss_command_executor.cpp + ss_command_executor.h + ss_script_manager.cpp + ss_commands.cpp + ss_script_manager.h + ss_service_comms_manager.cpp + ss_service_comms_manager.h + ss_state_manager.cpp + ss_state_manager.h) + + +SOURCE_GROUP("GUS Modules\\Stats Scan (STATS)" FILES stats_guild_commands.cpp + stats_guild_scan_job.cpp + stats_guild_scan_job.h + stat_character.cpp + stat_character.h + stat_character_scan_job.cpp + stat_character_scan_job.h + stat_char_commands.cpp + stat_char_filter_factory.cpp + stat_char_filter_factory.h + stat_char_info_extractor_factory.cpp + stat_char_info_extractor_factory.h + stat_char_scan_script.cpp + stat_char_scan_script.h + stat_file_list_builder_factory.cpp + stat_file_list_builder_factory.h + stat_globals.cpp stat_globals.h + stat_guild_container.cp + stat_guild_container.h + stat_job_manager.cpp + stat_job_manager.h + stat_user_char_filters.cpp + stat_user_char_info_extractors.cpp + stat_user_file_list_builders.cpp) + +SOURCE_GROUP("GUS Modules\\GUS Networking" FILES gus_net.cpp + gus_net.h + gus_net_commands.cpp + gus_net_connection.cpp + gus_net_connection.h + gus_net_hub.cpp + gus_net_hub.h + gus_net_implementation.cpp + gus_net_implementation.h + gus_net_messages.cpp + gus_net_messages.h + gus_net_remote_module.cpp + gus_net_remote_module.h + gus_net_types.h) + +SOURCE_GROUP("GUS Modules" FILES gus_module.cpp gus_module.h gus_module_commands.cpp gus_module_factory.cpp gus_module_factory.h gus_module_manager.cpp gus_module_manager.h) + +SOURCE_GROUP("GUS Core" FILES gus_chat.cpp + gus_chat.h + gus_client_manager.cpp + gus_client_manager.h + gus_mirror.cpp + gus_mirror.h + gus_text.cpp + gus_text.h + gus_utils.cpp + gus_utils.h + gus_util_commands.cpp) + +ADD_EXECUTABLE(ryzom_general_utilities_service WIN32 ${SRC}) INCLUDE_DIRECTORIES(${RZ_SERVER_SRC_DIR} ${LIBXML2_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${NEL_INCLUDE_DIR}) @@ -26,7 +137,7 @@ TARGET_LINK_LIBRARIES(ryzom_general_utilities_service ${ZLIB_LIBRARIES} nelmisc nelnet - nelgeorges} + nelgeorges nelligo) NL_DEFAULT_PROPS(ryzom_general_utilities_service "Ryzom, Services: General Utilities Service (GUS)") diff --git a/code/ryzom/server/src/general_utilities_service/em_commands.cpp b/code/ryzom/server/src/general_utilities_service/em_commands.cpp index 7437f4865..1411e515e 100644 --- a/code/ryzom/server/src/general_utilities_service/em_commands.cpp +++ b/code/ryzom/server/src/general_utilities_service/em_commands.cpp @@ -312,7 +312,8 @@ NLMISC_CATEGORISED_COMMAND(EventManager,emUpdateTools,"update tools installed on // Extra commands that open MFC windows //----------------------------------------------------------------------------- -#ifdef _WINDOWS +//#ifdef _WINDOWS +#if 0 #include "mfc/stdafx.h" #include "nel/misc/win_displayer.h" diff --git a/code/ryzom/server/src/general_utilities_service/em_event_manager.cpp b/code/ryzom/server/src/general_utilities_service/em_event_manager.cpp index 3958b360f..f000dc2e7 100644 --- a/code/ryzom/server/src/general_utilities_service/em_event_manager.cpp +++ b/code/ryzom/server/src/general_utilities_service/em_event_manager.cpp @@ -358,7 +358,7 @@ void CEventManagerImplementation::displayModule() const for (TShards::const_iterator it=_Shards.begin(); it!=_Shards.end(); ++it) { CSString s= (*it).first+ ": "; - for (TShardsMapEntry::iterator it2= (*it).second.begin(); it2!=(*it).second.end(); ++it2) + for (TShardsMapEntry::const_iterator it2= (*it).second.begin(); it2!=(*it).second.end(); ++it2) { s+= NLMISC::toString((*it2))+" "; } @@ -478,7 +478,7 @@ void CEventManagerImplementation::startEvent(const NLMISC::CSString& shardName) // build vector of destinations to send the module message to TModuleIdVector moduleIds; - for (TShardsMapEntry::iterator it= (*shard).second.begin(); it!= (*shard).second.end(); ++it) + for (TShardsMapEntry::const_iterator it= (*shard).second.begin(); it!= (*shard).second.end(); ++it) { nlinfo("Sending event start request to event executor: %d",(*it)); moduleIds.push_back(*it); @@ -502,7 +502,7 @@ void CEventManagerImplementation::stopEvent(const NLMISC::CSString& shardName) // build vector of destinations to send the module message to TModuleIdVector moduleIds; - for (TShardsMapEntry::iterator it= (*shard).second.begin(); it!= (*shard).second.end(); ++it) + for (TShardsMapEntry::const_iterator it= (*shard).second.begin(); it!= (*shard).second.end(); ++it) { nlinfo("Sending event stop request to event executor: %d",(*it)); moduleIds.push_back(*it); @@ -569,7 +569,7 @@ void CEventManagerImplementation::peekInstalledEvent(const NLMISC::CSString& sha // build vector of destinations to send the module message to TModuleIdVector moduleIds; - for (TShardsMapEntry::iterator it= (*shard).second.begin(); it!= (*shard).second.end(); ++it) + for (TShardsMapEntry::const_iterator it= (*shard).second.begin(); it!= (*shard).second.end(); ++it) { nlinfo("Sending history request to event executor: %d",(*it)); moduleIds.push_back(*it); diff --git a/code/ryzom/server/src/general_utilities_service/gus_utils.cpp b/code/ryzom/server/src/general_utilities_service/gus_utils.cpp index db1f2bf5a..183386bc5 100644 --- a/code/ryzom/server/src/general_utilities_service/gus_utils.cpp +++ b/code/ryzom/server/src/general_utilities_service/gus_utils.cpp @@ -45,74 +45,6 @@ using namespace NLNET; namespace GUS { - //----------------------------------------------------------------------------- - // cleanPath - convert a path to standardised format - //----------------------------------------------------------------------------- - - CSString cleanPath(const CSString& path,bool addTrailingSlash) - { - CSString result; - - // split the path up into its component elements - CVectorSString pathComponents; - path.unquoteIfQuoted().splitByOneOfSeparators("/\\",pathComponents,false,false,true,false,true); - - // iterate over path components collapsing '.' and '..' entries - for (uint32 i=0;i a:/bcd/efg/ (no change) - // - a:\bcd\efg => a:/bcd/efg/ - // - \bcd\\efg => /bcd/efg/ - // - \\bcd\efg => //bcd/efg/ - // - \bcd\.\efg => /bcd/efg/ - // - \bcd\..\efg => /efg/ - // - bcd\..\efg => efg/ - // - bcd\..\..\efg => ../efg/ - // - \bcd\..\..\efg => /efg/ (NOTE: the redundant '..' entry is lost due to leading '\') - // - NLMISC::CSString cleanPath(const NLMISC::CSString& path,bool addTrailingSlash); - - // execute a command on a remote service void executeRemoteCommand(NLNET::TServiceId sid,const NLMISC::CSString& cmdLine); void executeRemoteCommand(const char* serviceName,const NLMISC::CSString& cmdLine); diff --git a/code/ryzom/server/src/general_utilities_service/service_main.cpp b/code/ryzom/server/src/general_utilities_service/service_main.cpp index 573770fea..90633fa6f 100644 --- a/code/ryzom/server/src/general_utilities_service/service_main.cpp +++ b/code/ryzom/server/src/general_utilities_service/service_main.cpp @@ -28,11 +28,15 @@ #include "game_share/ryzom_version.h" #include "game_share/tick_event_handler.h" #include "game_share/singleton_registry.h" -#include "game_share/handy_commands.h" +#include "server_share/handy_commands.h" // local #include "service_main.h" +#ifdef NL_OS_WINDOWS +# define NOMINMAX +# include +#endif // NL_OS_WINDOWS //----------------------------------------------------------------------------- // namespaces