From bc19916d79e10328e6852dafbd21f547d9a4cb19 Mon Sep 17 00:00:00 2001 From: Aokromes Date: Fri, 10 Feb 2017 06:45:33 +0100 Subject: [PATCH] Sync with 3.3.5a --- dep/boost/CMakeLists.txt | 43 +++++++++++++------ src/common/Utilities/Regex.h | 39 +++++++++++++++++ src/server/game/DataStores/DBCStores.cpp | 28 +++++++----- src/server/game/DataStores/DBCStores.h | 2 +- src/server/game/Globals/ObjectMgr.cpp | 4 +- src/server/game/Scripting/ScriptReloadMgr.cpp | 8 ++-- 6 files changed, 92 insertions(+), 32 deletions(-) create mode 100644 src/common/Utilities/Regex.h diff --git a/dep/boost/CMakeLists.txt b/dep/boost/CMakeLists.txt index f9c98090d3f..988006b2ecd 100644 --- a/dep/boost/CMakeLists.txt +++ b/dep/boost/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2008-2017 TrinityCore +# Copyright (C) 2008-2016 TrinityCore # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without @@ -26,28 +26,32 @@ if(WIN32) set(Boost_USE_STATIC_RUNTIME OFF) endif() -find_package(Boost 1.55 REQUIRED system filesystem thread program_options iostreams regex date_time chrono) +include (CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + #include + int main() { std::wregex r(L\".*\"); }" + STD_HAS_WORKING_WREGEX) + +if (STD_HAS_WORKING_WREGEX) + find_package(Boost 1.55 REQUIRED system filesystem thread program_options iostreams) +else() + find_package(Boost 1.55 REQUIRED system filesystem thread program_options iostreams regex) +endif() # Find if Boost was compiled in C++03 mode because it requires -DBOOST_NO_CXX11_SCOPED_ENUMS -include (CheckCXXSourceCompiles) - set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIR}) set(CMAKE_REQUIRED_LIBRARIES ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_IOSTREAMS_LIBRARY}) set(CMAKE_REQUIRED_FLAGS "-std=c++11") -unset(boost_filesystem_copy_links_without_NO_SCOPED_ENUM CACHE) check_cxx_source_compiles(" #include #include int main() { boost::filesystem::copy_file(boost::filesystem::path(), boost::filesystem::path()); }" boost_filesystem_copy_links_without_NO_SCOPED_ENUM) -unset(CMAKE_REQUIRED_INCLUDES CACHE) -unset(CMAKE_REQUIRED_LIBRARIES CACHE) -unset(CMAKE_REQUIRED_FLAGS CACHE) - -if (NOT boost_filesystem_copy_links_without_NO_SCOPED_ENUM) - set(OPTIONAL_BOOST_NO_SCOPED_ENUMS -DBOOST_NO_CXX11_SCOPED_ENUMS) -endif() +unset(CMAKE_REQUIRED_INCLUDES) +unset(CMAKE_REQUIRED_LIBRARIES) +unset(CMAKE_REQUIRED_FLAGS) add_library(boost INTERFACE) @@ -63,5 +67,16 @@ target_compile_definitions(boost INTERFACE -DBOOST_DATE_TIME_NO_LIB -DBOOST_REGEX_NO_LIB - -DBOOST_CHRONO_NO_LIB - ${OPTIONAL_BOOST_NO_SCOPED_ENUMS}) + -DBOOST_CHRONO_NO_LIB) + +if (NOT boost_filesystem_copy_links_without_NO_SCOPED_ENUM) + target_compile_definitions(boost + INTERFACE + -DBOOST_NO_CXX11_SCOPED_ENUMS) +endif() + +if (NOT STD_HAS_WORKING_WREGEX) + target_compile_definitions(boost + INTERFACE + -DTC_HAS_BROKEN_WSTRING_REGEX) +endif() diff --git a/src/common/Utilities/Regex.h b/src/common/Utilities/Regex.h new file mode 100644 index 00000000000..1d1ebca1b17 --- /dev/null +++ b/src/common/Utilities/Regex.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008-2017 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef TrinityCore_Regex_h__ +#define TrinityCore_Regex_h__ + +#ifndef TC_HAS_BROKEN_WSTRING_REGEX +#include +#define TC_REGEX_NAMESPACE std +#else +#include +#define TC_REGEX_NAMESPACE boost +#endif + +// regex compatibility layer, required for clang building with libstdc++-4.9 +namespace Trinity +{ + using regex = TC_REGEX_NAMESPACE :: regex; + using wregex = TC_REGEX_NAMESPACE :: wregex; + + using :: TC_REGEX_NAMESPACE :: regex_match; + using :: TC_REGEX_NAMESPACE :: regex_search; +} + +#endif // TrinityCore_Regex_h__ diff --git a/src/server/game/DataStores/DBCStores.cpp b/src/server/game/DataStores/DBCStores.cpp index c5dc1046b8d..8c59ce0909f 100644 --- a/src/server/game/DataStores/DBCStores.cpp +++ b/src/server/game/DataStores/DBCStores.cpp @@ -25,8 +25,8 @@ #include "ItemTemplate.h" #include "Timer.h" #include "ObjectDefines.h" +#include "Regex.h" -#include #include typedef std::map AreaFlagByAreaID; @@ -176,7 +176,7 @@ DBCStorage sNumTalentsAtLevelStore(NumTalentsAtLevelfmt DBCStorage sNamesProfanityStore(NamesProfanityEntryfmt); DBCStorage sNamesReservedStore(NamesReservedEntryfmt); -typedef std::array, TOTAL_LOCALES> NameValidationRegexContainer; +typedef std::array, TOTAL_LOCALES> NameValidationRegexContainer; NameValidationRegexContainer NamesProfaneValidators; NameValidationRegexContainer NamesReservedValidators; @@ -517,11 +517,14 @@ void LoadDBCStores(const std::string& dataPath) continue; ASSERT(namesProfanity->Language < TOTAL_LOCALES || namesProfanity->Language == -1); + std::wstring wname; + ASSERT(Utf8toWStr(namesProfanity->Name, wname)); + if (namesProfanity->Language != -1) - NamesProfaneValidators[namesProfanity->Language].emplace_back(namesProfanity->Name, boost::regex::perl | boost::regex::icase | boost::regex::optimize); + NamesProfaneValidators[namesProfanity->Language].emplace_back(wname, Trinity::regex::perl | Trinity::regex::icase | Trinity::regex::optimize); else for (uint32 i = 0; i < TOTAL_LOCALES; ++i) - NamesProfaneValidators[i].emplace_back(namesProfanity->Name, boost::regex::perl | boost::regex::icase | boost::regex::optimize); + NamesProfaneValidators[i].emplace_back(wname, Trinity::regex::perl | Trinity::regex::icase | Trinity::regex::optimize); } for (uint32 i = 0; i < sNamesReservedStore.GetNumRows(); ++i) @@ -531,11 +534,14 @@ void LoadDBCStores(const std::string& dataPath) continue; ASSERT(namesReserved->Language < TOTAL_LOCALES || namesReserved->Language == -1); + std::wstring wname; + ASSERT(Utf8toWStr(namesReserved->Name, wname)); + if (namesReserved->Language != -1) - NamesReservedValidators[namesReserved->Language].emplace_back(namesReserved->Name, boost::regex::perl | boost::regex::icase | boost::regex::optimize); + NamesReservedValidators[namesReserved->Language].emplace_back(wname, Trinity::regex::perl | Trinity::regex::icase | Trinity::regex::optimize); else for (uint32 i = 0; i < TOTAL_LOCALES; ++i) - NamesReservedValidators[i].emplace_back(namesReserved->Name, boost::regex::perl | boost::regex::icase | boost::regex::optimize); + NamesReservedValidators[i].emplace_back(wname, Trinity::regex::perl | Trinity::regex::icase | Trinity::regex::optimize); } LoadDBC(availableDbcLocales, bad_dbc_files, sPhaseStore, dbcPath, "Phase.dbc"); // 15595 @@ -1346,18 +1352,18 @@ std::set const& GetPhasesForGroup(uint32 group) return sPhasesByGroup[group]; } -ResponseCodes ValidateName(std::string const& name, LocaleConstant locale) +ResponseCodes ValidateName(std::wstring const& name, LocaleConstant locale) { if (locale >= TOTAL_LOCALES) return RESPONSE_FAILURE; - for (boost::regex const& regex : NamesProfaneValidators[locale]) - if (boost::regex_search(name, regex)) + for (Trinity::wregex const& regex : NamesProfaneValidators[locale]) + if (Trinity::regex_search(name, regex)) return CHAR_NAME_PROFANE; // regexes at TOTAL_LOCALES are loaded from NamesReserved which is not locale specific - for (boost::regex const& regex : NamesReservedValidators[locale]) - if (boost::regex_search(name, regex)) + for (Trinity::wregex const& regex : NamesReservedValidators[locale]) + if (Trinity::regex_search(name, regex)) return CHAR_NAME_RESERVED; return CHAR_NAME_SUCCESS; diff --git a/src/server/game/DataStores/DBCStores.h b/src/server/game/DataStores/DBCStores.h index fc05f8f4a3a..efb6c4fd5db 100644 --- a/src/server/game/DataStores/DBCStores.h +++ b/src/server/game/DataStores/DBCStores.h @@ -86,7 +86,7 @@ typedef std::unordered_multimap SkillRac typedef std::pair SkillRaceClassInfoBounds; TC_GAME_API SkillRaceClassInfoEntry const* GetSkillRaceClassInfo(uint32 skill, uint8 race, uint8 class_); -TC_GAME_API ResponseCodes ValidateName(std::string const& name, LocaleConstant locale); +TC_GAME_API ResponseCodes ValidateName(std::wstring const& name, LocaleConstant locale); TC_GAME_API EmotesTextSoundEntry const* FindTextSoundEmoteFor(uint32 emote, uint32 race, uint32 gender); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 50246b45d82..fec5ba1bfd2 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -7841,7 +7841,7 @@ ResponseCodes ObjectMgr::CheckPlayerName(std::string const& name, LocaleConstant if (wname[i] == wname[i-1] && wname[i] == wname[i-2]) return CHAR_NAME_THREE_CONSECUTIVE; - return ValidateName(name, locale); + return ValidateName(wname, locale); } bool ObjectMgr::IsValidCharterName(const std::string& name) @@ -7879,7 +7879,7 @@ PetNameInvalidReason ObjectMgr::CheckPetName(const std::string& name, LocaleCons if (!isValidString(wname, strictMask, false)) return PET_NAME_MIXED_LANGUAGES; - switch (ValidateName(name, locale)) + switch (ValidateName(wname, locale)) { case CHAR_NAME_PROFANE: return PET_NAME_PROFANE; diff --git a/src/server/game/Scripting/ScriptReloadMgr.cpp b/src/server/game/Scripting/ScriptReloadMgr.cpp index efc2cc5e67a..e06b3bb4b27 100644 --- a/src/server/game/Scripting/ScriptReloadMgr.cpp +++ b/src/server/game/Scripting/ScriptReloadMgr.cpp @@ -297,12 +297,12 @@ Optional> static bool HasValidScriptModuleName(std::string const& name) { // Detects scripts_NAME.dll's / .so's - static std::regex const regex( + static Trinity::regex const regex( Trinity::StringFormat("^%s[sS]cripts_[a-zA-Z0-9_]+\\.%s$", GetSharedLibraryPrefix(), GetSharedLibraryExtension())); - return std::regex_match(name, regex); + return Trinity::regex_match(name, regex); } /// File watcher responsible for watching shared libraries @@ -1509,8 +1509,8 @@ void LibraryUpdateListener::handleFileAction(efsw::WatchID watchid, std::string /// Returns true when the given path has a known C++ file extension static bool HasCXXSourceFileExtension(fs::path const& path) { - static std::regex const regex("^\\.(h|hpp|c|cc|cpp)$"); - return std::regex_match(path.extension().generic_string(), regex); + static Trinity::regex const regex("^\\.(h|hpp|c|cc|cpp)$"); + return Trinity::regex_match(path.extension().generic_string(), regex); } SourceUpdateListener::SourceUpdateListener(fs::path path, std::string script_module_name)