aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--cmake/macros/ConfigureBoost.cmake34
-rw-r--r--cmake/macros/FindBoost.cmake1162
-rw-r--r--dep/SFMT/SFMT.h87
-rw-r--r--dep/g3dlite/Readme.txt1
-rw-r--r--dep/g3dlite/include/G3D/g3dmath.h2
-rw-r--r--src/server/authserver/CMakeLists.txt1
-rw-r--r--src/server/authserver/Main.cpp215
-rw-r--r--src/server/authserver/PrecompiledHeaders/authPCH.h5
-rw-r--r--src/server/authserver/Realms/RealmList.cpp25
-rw-r--r--src/server/authserver/Realms/RealmList.h47
-rw-r--r--src/server/authserver/Server/AuthServer.cpp40
-rw-r--r--src/server/authserver/Server/AuthServer.h44
-rw-r--r--src/server/authserver/Server/AuthSession.cpp (renamed from src/server/authserver/Server/AuthSocket.cpp)772
-rw-r--r--src/server/authserver/Server/AuthSession.h84
-rw-r--r--src/server/authserver/Server/AuthSocket.h83
-rw-r--r--src/server/authserver/Server/RealmAcceptor.h70
-rw-r--r--src/server/authserver/Server/RealmSocket.cpp291
-rw-r--r--src/server/authserver/Server/RealmSocket.h80
-rw-r--r--src/server/collision/BoundingIntervalHierarchy.h4
-rw-r--r--src/server/collision/Management/VMapManager2.cpp5
-rw-r--r--src/server/collision/Management/VMapManager2.h6
-rw-r--r--src/server/collision/Models/ModelInstance.cpp4
-rw-r--r--src/server/collision/VMapDefinitions.h1
-rw-r--r--src/server/game/AI/CreatureAIFactory.h2
-rw-r--r--src/server/game/AI/CreatureAISelector.cpp6
-rw-r--r--src/server/game/Achievements/AchievementMgr.cpp2
-rw-r--r--src/server/game/Events/GameEventMgr.cpp16
-rw-r--r--src/server/game/Globals/ObjectAccessor.cpp23
-rw-r--r--src/server/game/Globals/ObjectAccessor.h53
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp2
-rw-r--r--src/server/game/Handlers/MiscHandler.cpp3
-rw-r--r--src/server/game/Instances/InstanceSaveMgr.h28
-rw-r--r--src/server/game/Maps/Map.cpp6
-rw-r--r--src/server/game/Maps/Map.h4
-rw-r--r--src/server/game/Maps/MapInstanced.cpp4
-rw-r--r--src/server/game/Maps/MapManager.cpp6
-rw-r--r--src/server/game/Maps/MapManager.h2
-rw-r--r--src/server/game/Maps/MapUpdater.cpp39
-rw-r--r--src/server/game/Maps/MapUpdater.h26
-rwxr-xr-xsrc/server/game/Movement/MovementGenerator.h1
-rw-r--r--src/server/game/PrecompiledHeaders/gamePCH.h4
-rw-r--r--src/server/game/Server/WorldSession.h2
-rw-r--r--src/server/game/Server/WorldSocketMgr.cpp8
-rw-r--r--src/server/game/Weather/Weather.cpp2
-rw-r--r--src/server/game/World/World.cpp10
-rw-r--r--src/server/game/World/World.h4
-rw-r--r--src/server/scripts/Commands/cs_ban.cpp12
-rw-r--r--src/server/scripts/Commands/cs_debug.cpp8
-rw-r--r--src/server/scripts/Commands/cs_gm.cpp2
-rw-r--r--src/server/scripts/Commands/cs_mmaps.cpp4
-rw-r--r--src/server/scripts/Commands/cs_reset.cpp2
-rw-r--r--src/server/shared/Common.h32
-rw-r--r--src/server/shared/Configuration/Config.cpp122
-rw-r--r--src/server/shared/Configuration/Config.h35
-rw-r--r--src/server/shared/Cryptography/BigNumber.cpp8
-rw-r--r--src/server/shared/Cryptography/BigNumber.h5
-rw-r--r--src/server/shared/Database/MySQLThreading.h27
-rw-r--r--src/server/shared/Define.h45
-rw-r--r--src/server/shared/Dynamic/FactoryHolder.h6
-rw-r--r--src/server/shared/Dynamic/ObjectRegistry.h12
-rw-r--r--src/server/shared/Logging/Appender.cpp3
-rw-r--r--src/server/shared/Logging/AppenderConsole.cpp6
-rw-r--r--src/server/shared/Logging/AppenderFile.cpp2
-rw-r--r--src/server/shared/Logging/AppenderFile.h4
-rw-r--r--src/server/shared/Logging/Log.cpp8
-rw-r--r--src/server/shared/Logging/Log.h11
-rw-r--r--src/server/shared/Packets/ByteBuffer.cpp1
-rw-r--r--src/server/shared/Packets/ByteBuffer.h4
-rw-r--r--src/server/shared/Threading/DelayExecutor.cpp3
-rw-r--r--src/server/shared/Threading/LockedQueue.h240
-rw-r--r--src/server/shared/Threading/Threading.cpp235
-rw-r--r--src/server/shared/Threading/Threading.h108
-rw-r--r--src/server/shared/Utilities/Timer.h248
-rw-r--r--src/server/shared/Utilities/Util.cpp55
-rw-r--r--src/server/shared/Utilities/Util.h9
-rw-r--r--src/server/worldserver/CMakeLists.txt1
-rw-r--r--src/server/worldserver/CommandLine/CliRunnable.cpp2
-rw-r--r--src/server/worldserver/CommandLine/CliRunnable.h7
-rw-r--r--src/server/worldserver/Master.cpp106
-rw-r--r--src/server/worldserver/PrecompiledHeaders/worldPCH.h3
-rw-r--r--src/server/worldserver/RemoteAccess/RARunnable.cpp28
-rw-r--r--src/server/worldserver/RemoteAccess/RARunnable.h16
-rw-r--r--src/server/worldserver/TCSoap/TCSoap.cpp10
-rw-r--r--src/server/worldserver/TCSoap/TCSoap.h22
-rw-r--r--src/server/worldserver/WorldThread/WorldRunnable.cpp7
-rw-r--r--src/server/worldserver/WorldThread/WorldRunnable.h7
87 files changed, 2452 insertions, 2332 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21fa378fad0..7923fc33eb7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,6 +56,8 @@ find_package(ACE REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
+include(ConfigureBoost)
+
if( NOT USE_MYSQL_SOURCES )
find_package(MySQL REQUIRED)
endif()
diff --git a/cmake/macros/ConfigureBoost.cmake b/cmake/macros/ConfigureBoost.cmake
new file mode 100644
index 00000000000..8ade7a0db5b
--- /dev/null
+++ b/cmake/macros/ConfigureBoost.cmake
@@ -0,0 +1,34 @@
+macro(get_WIN32_WINNT version)
+ if (WIN32 AND CMAKE_SYSTEM_VERSION)
+ set(ver ${CMAKE_SYSTEM_VERSION})
+ string(REPLACE "." "" ver ${ver})
+ string(REGEX REPLACE "([0-9])" "0\\1" ver ${ver})
+
+ set(${version} "0x${ver}")
+ endif()
+endmacro()
+
+if(WIN32)
+ set(BOOST_DEBUG ON)
+ if(DEFINED ENV{BOOST_ROOT})
+ set(BOOST_ROOT $ENV{BOOST_ROOT})
+ set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib${PLATFORM}-msvc-12.0)
+ message(${BOOST_ROOT})
+ else()
+ message(FATAL_ERROR "No BOOST_ROOT environment variable could be found! Please make sure it is set and the points to your Boost installation.")
+ endif()
+
+ set(Boost_ADDITIONAL_VERSIONS "1.55" "1.55.0")
+ set(Boost_USE_STATIC_LIBS ON)
+ set(Boost_USE_MULTITHREADED ON)
+ set(Boost_USE_STATIC_RUNTIME OFF)
+
+ get_WIN32_WINNT(ver)
+ add_definitions(-D_WIN32_WINNT=${ver})
+endif()
+
+find_package(Boost 1.55 REQUIRED atomic chrono date_time exception regex system thread)
+
+if(Boost_FOUND)
+ include_directories(${Boost_INCLUDE_DIRS})
+endif()
diff --git a/cmake/macros/FindBoost.cmake b/cmake/macros/FindBoost.cmake
new file mode 100644
index 00000000000..12dc4f0f67b
--- /dev/null
+++ b/cmake/macros/FindBoost.cmake
@@ -0,0 +1,1162 @@
+# - Find Boost include dirs and libraries
+# Use this module by invoking find_package with the form:
+# find_package(Boost
+# [version] [EXACT] # Minimum or EXACT version e.g. 1.36.0
+# [REQUIRED] # Fail with error if Boost is not found
+# [COMPONENTS <libs>...] # Boost libraries by their canonical name
+# ) # e.g. "date_time" for "libboost_date_time"
+# This module finds headers and requested component libraries OR a CMake
+# package configuration file provided by a "Boost CMake" build. For the
+# latter case skip to the "Boost CMake" section below. For the former
+# case results are reported in variables:
+# Boost_FOUND - True if headers and requested libraries were found
+# Boost_INCLUDE_DIRS - Boost include directories
+# Boost_LIBRARY_DIRS - Link directories for Boost libraries
+# Boost_LIBRARIES - Boost component libraries to be linked
+# Boost_<C>_FOUND - True if component <C> was found (<C> is upper-case)
+# Boost_<C>_LIBRARY - Libraries to link for component <C> (may include
+# target_link_libraries debug/optimized keywords)
+# Boost_VERSION - BOOST_VERSION value from boost/version.hpp
+# Boost_LIB_VERSION - Version string appended to library filenames
+# Boost_MAJOR_VERSION - Boost major version number (X in X.y.z)
+# Boost_MINOR_VERSION - Boost minor version number (Y in x.Y.z)
+# Boost_SUBMINOR_VERSION - Boost subminor version number (Z in x.y.Z)
+# Boost_LIB_DIAGNOSTIC_DEFINITIONS (Windows)
+# - Pass to add_definitions() to have diagnostic
+# information about Boost's automatic linking
+# displayed during compilation
+#
+# This module reads hints about search locations from variables:
+# BOOST_ROOT - Preferred installation prefix
+# (or BOOSTROOT)
+# BOOST_INCLUDEDIR - Preferred include directory e.g. <prefix>/include
+# BOOST_LIBRARYDIR - Preferred library directory e.g. <prefix>/lib
+# Boost_NO_SYSTEM_PATHS - Set to ON to disable searching in locations not
+# specified by these hint variables. Default is OFF.
+# Boost_ADDITIONAL_VERSIONS
+# - List of Boost versions not known to this module
+# (Boost install locations may contain the version)
+# and saves search results persistently in CMake cache entries:
+# Boost_INCLUDE_DIR - Directory containing Boost headers
+# Boost_LIBRARY_DIR - Directory containing Boost libraries
+# Boost_<C>_LIBRARY_DEBUG - Component <C> library debug variant
+# Boost_<C>_LIBRARY_RELEASE - Component <C> library release variant
+# Users may set these hints or results as cache entries. Projects should
+# not read these entries directly but instead use the above result variables.
+# Note that some hint names start in upper-case "BOOST". One may specify
+# these as environment variables if they are not specified as CMake variables
+# or cache entries.
+#
+# This module first searches for the Boost header files using the above hint
+# variables (excluding BOOST_LIBRARYDIR) and saves the result in
+# Boost_INCLUDE_DIR. Then it searches for requested component libraries using
+# the above hints (excluding BOOST_INCLUDEDIR and Boost_ADDITIONAL_VERSIONS),
+# "lib" directories near Boost_INCLUDE_DIR, and the library name configuration
+# settings below. It saves the library directory in Boost_LIBRARY_DIR and
+# individual library locations in Boost_<C>_LIBRARY_DEBUG and
+# Boost_<C>_LIBRARY_RELEASE. When one changes settings used by previous
+# searches in the same build tree (excluding environment variables) this
+# module discards previous search results affected by the changes and searches
+# again.
+#
+# Boost libraries come in many variants encoded in their file name. Users or
+# projects may tell this module which variant to find by setting variables:
+# Boost_USE_MULTITHREADED - Set to OFF to use the non-multithreaded
+# libraries ('mt' tag). Default is ON.
+# Boost_USE_STATIC_LIBS - Set to ON to force the use of the static
+# libraries. Default is OFF.
+# Boost_USE_STATIC_RUNTIME - Set to ON or OFF to specify whether to use
+# libraries linked statically to the C++ runtime
+# ('s' tag). Default is platform dependent.
+# Boost_USE_DEBUG_PYTHON - Set to ON to use libraries compiled with a
+# debug Python build ('y' tag). Default is OFF.
+# Boost_USE_STLPORT - Set to ON to use libraries compiled with
+# STLPort ('p' tag). Default is OFF.
+# Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS
+# - Set to ON to use libraries compiled with
+# STLPort deprecated "native iostreams"
+# ('n' tag). Default is OFF.
+# Boost_COMPILER - Set to the compiler-specific library suffix
+# (e.g. "-gcc43"). Default is auto-computed
+# for the C++ compiler in use.
+# Boost_THREADAPI - Suffix for "thread" component library name,
+# such as "pthread" or "win32". Names with
+# and without this suffix will both be tried.
+# Other variables one may set to control this module are:
+# Boost_DEBUG - Set to ON to enable debug output from FindBoost.
+# Please enable this before filing any bug report.
+# Boost_DETAILED_FAILURE_MSG
+# - Set to ON to add detailed information to the
+# failure message even when the REQUIRED option
+# is not given to the find_package call.
+# Boost_REALPATH - Set to ON to resolve symlinks for discovered
+# libraries to assist with packaging. For example,
+# the "system" component library may be resolved to
+# "/usr/lib/libboost_system.so.1.42.0" instead of
+# "/usr/lib/libboost_system.so". This does not
+# affect linking and should not be enabled unless
+# the user needs this information.
+# On Visual Studio and Borland compilers Boost headers request automatic
+# linking to corresponding libraries. This requires matching libraries to be
+# linked explicitly or available in the link library search path. In this
+# case setting Boost_USE_STATIC_LIBS to OFF may not achieve dynamic linking.
+# Boost automatic linking typically requests static libraries with a few
+# exceptions (such as Boost.Python). Use
+# add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})
+# to ask Boost to report information about automatic linking requests.
+#
+# Example to find Boost headers only:
+# find_package(Boost 1.36.0)
+# if(Boost_FOUND)
+# include_directories(${Boost_INCLUDE_DIRS})
+# add_executable(foo foo.cc)
+# endif()
+# Example to find Boost headers and some libraries:
+# set(Boost_USE_STATIC_LIBS ON)
+# set(Boost_USE_MULTITHREADED ON)
+# set(Boost_USE_STATIC_RUNTIME OFF)
+# find_package(Boost 1.36.0 COMPONENTS date_time filesystem system ...)
+# if(Boost_FOUND)
+# include_directories(${Boost_INCLUDE_DIRS})
+# add_executable(foo foo.cc)
+# target_link_libraries(foo ${Boost_LIBRARIES})
+# endif()
+#
+# Boost CMake ----------------------------------------------------------
+#
+# If Boost was built using the boost-cmake project it provides a package
+# configuration file for use with find_package's Config mode. This module
+# looks for the package configuration file called BoostConfig.cmake or
+# boost-config.cmake and stores the result in cache entry "Boost_DIR". If
+# found, the package configuration file is loaded and this module returns with
+# no further action. See documentation of the Boost CMake package
+# configuration for details on what it provides.
+#
+# Set Boost_NO_BOOST_CMAKE to ON to disable the search for boost-cmake.
+
+#=============================================================================
+# Copyright 2006-2012 Kitware, Inc.
+# Copyright 2006-2008 Andreas Schneider <mail@cynapses.org>
+# Copyright 2007 Wengo
+# Copyright 2007 Mike Jackson
+# Copyright 2008 Andreas Pakulat <apaku@gmx.de>
+# Copyright 2008-2012 Philip Lowman <philip@yhbt.com>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+# License text for the above reference.)
+
+
+#-------------------------------------------------------------------------------
+# Before we go searching, check whether boost-cmake is available, unless the
+# user specifically asked NOT to search for boost-cmake.
+#
+# If Boost_DIR is set, this behaves as any find_package call would. If not,
+# it looks at BOOST_ROOT and BOOSTROOT to find Boost.
+#
+if (NOT Boost_NO_BOOST_CMAKE)
+ # If Boost_DIR is not set, look for BOOSTROOT and BOOST_ROOT as alternatives,
+ # since these are more conventional for Boost.
+ if ("$ENV{Boost_DIR}" STREQUAL "")
+ if (NOT "$ENV{BOOST_ROOT}" STREQUAL "")
+ set(ENV{Boost_DIR} $ENV{BOOST_ROOT})
+ elseif (NOT "$ENV{BOOSTROOT}" STREQUAL "")
+ set(ENV{Boost_DIR} $ENV{BOOSTROOT})
+ endif()
+ endif()
+
+ # Do the same find_package call but look specifically for the CMake version.
+ # Note that args are passed in the Boost_FIND_xxxxx variables, so there is no
+ # need to delegate them to this find_package call.
+ find_package(Boost QUIET NO_MODULE)
+ mark_as_advanced(Boost_DIR)
+
+ # If we found boost-cmake, then we're done. Print out what we found.
+ # Otherwise let the rest of the module try to find it.
+ if (Boost_FOUND)
+ message("Boost ${Boost_FIND_VERSION} found.")
+ if (Boost_FIND_COMPONENTS)
+ message("Found Boost components:")
+ message(" ${Boost_FIND_COMPONENTS}")
+ endif()
+ return()
+ endif()
+endif()
+
+
+#-------------------------------------------------------------------------------
+# FindBoost functions & macros
+#
+
+############################################
+#
+# Check the existence of the libraries.
+#
+############################################
+# This macro was taken directly from the FindQt4.cmake file that is included
+# with the CMake distribution. This is NOT my work. All work was done by the
+# original authors of the FindQt4.cmake file. Only minor modifications were
+# made to remove references to Qt and make this file more generally applicable
+# And ELSE/ENDIF pairs were removed for readability.
+#########################################################################
+
+macro(_Boost_ADJUST_LIB_VARS basename)
+ if(Boost_INCLUDE_DIR )
+ if(Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE)
+ # if the generator supports configuration types then set
+ # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
+ if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
+ set(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
+ else()
+ # if there are no configuration types and CMAKE_BUILD_TYPE has no value
+ # then just use the release libraries
+ set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} )
+ endif()
+ # FIXME: This probably should be set for both cases
+ set(Boost_${basename}_LIBRARIES optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG})
+ endif()
+
+ # if only the release version was found, set the debug variable also to the release version
+ if(Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG)
+ set(Boost_${basename}_LIBRARY_DEBUG ${Boost_${basename}_LIBRARY_RELEASE})
+ set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE})
+ set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE})
+ endif()
+
+ # if only the debug version was found, set the release variable also to the debug version
+ if(Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE)
+ set(Boost_${basename}_LIBRARY_RELEASE ${Boost_${basename}_LIBRARY_DEBUG})
+ set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_DEBUG})
+ set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_DEBUG})
+ endif()
+
+ # If the debug & release library ends up being the same, omit the keywords
+ if(${Boost_${basename}_LIBRARY_RELEASE} STREQUAL ${Boost_${basename}_LIBRARY_DEBUG})
+ set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} )
+ set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE} )
+ endif()
+
+ if(Boost_${basename}_LIBRARY)
+ set(Boost_${basename}_FOUND ON)
+ endif()
+
+ endif()
+ # Make variables changeable to the advanced user
+ mark_as_advanced(
+ Boost_${basename}_LIBRARY_RELEASE
+ Boost_${basename}_LIBRARY_DEBUG
+ )
+endmacro()
+
+macro(_Boost_CHANGE_DETECT changed_var)
+ set(${changed_var} 0)
+ foreach(v ${ARGN})
+ if(DEFINED _Boost_COMPONENTS_SEARCHED)
+ if(${v})
+ if(_${v}_LAST)
+ string(COMPARE NOTEQUAL "${${v}}" "${_${v}_LAST}" _${v}_CHANGED)
+ else()
+ set(_${v}_CHANGED 1)
+ endif()
+ elseif(_${v}_LAST)
+ set(_${v}_CHANGED 1)
+ endif()
+ if(_${v}_CHANGED)
+ set(${changed_var} 1)
+ endif()
+ else()
+ set(_${v}_CHANGED 0)
+ endif()
+ endforeach()
+endmacro()
+
+macro(_Boost_FIND_LIBRARY var)
+ find_library(${var} ${ARGN})
+
+ # If we found the first library save Boost_LIBRARY_DIR.
+ if(${var} AND NOT Boost_LIBRARY_DIR)
+ get_filename_component(_dir "${${var}}" PATH)
+ set(Boost_LIBRARY_DIR "${_dir}" CACHE PATH "Boost library directory" FORCE)
+ endif()
+
+ # If Boost_LIBRARY_DIR is known then search only there.
+ if(Boost_LIBRARY_DIR)
+ set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH)
+ endif()
+endmacro()
+
+#-------------------------------------------------------------------------------
+
+#
+# Runs compiler with "-dumpversion" and parses major/minor
+# version with a regex.
+#
+function(_Boost_COMPILER_DUMPVERSION _OUTPUT_VERSION)
+
+ exec_program(${CMAKE_CXX_COMPILER}
+ ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
+ OUTPUT_VARIABLE _boost_COMPILER_VERSION
+ )
+ string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
+ _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION})
+
+ set(${_OUTPUT_VERSION} ${_boost_COMPILER_VERSION} PARENT_SCOPE)
+endfunction()
+
+#
+# Take a list of libraries with "thread" in it
+# and prepend duplicates with "thread_${Boost_THREADAPI}"
+# at the front of the list
+#
+function(_Boost_PREPEND_LIST_WITH_THREADAPI _output)
+ set(_orig_libnames ${ARGN})
+ string(REPLACE "thread" "thread_${Boost_THREADAPI}" _threadapi_libnames "${_orig_libnames}")
+ set(${_output} ${_threadapi_libnames} ${_orig_libnames} PARENT_SCOPE)
+endfunction()
+
+#
+# If a library is found, replace its cache entry with its REALPATH
+#
+function(_Boost_SWAP_WITH_REALPATH _library _docstring)
+ if(${_library})
+ get_filename_component(_boost_filepathreal ${${_library}} REALPATH)
+ unset(${_library} CACHE)
+ set(${_library} ${_boost_filepathreal} CACHE FILEPATH "${_docstring}")
+ endif()
+endfunction()
+
+function(_Boost_CHECK_SPELLING _var)
+ if(${_var})
+ string(TOUPPER ${_var} _var_UC)
+ message(FATAL_ERROR "ERROR: ${_var} is not the correct spelling. The proper spelling is ${_var_UC}.")
+ endif()
+endfunction()
+
+# Guesses Boost's compiler prefix used in built library names
+# Returns the guess by setting the variable pointed to by _ret
+function(_Boost_GUESS_COMPILER_PREFIX _ret)
+ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel"
+ OR "${CMAKE_CXX_COMPILER}" MATCHES "icl"
+ OR "${CMAKE_CXX_COMPILER}" MATCHES "icpc")
+ if(WIN32)
+ set (_boost_COMPILER "-iw")
+ else()
+ set (_boost_COMPILER "-il")
+ endif()
+ elseif (MSVC12)
+ set(_boost_COMPILER "-vc120")
+ elseif (MSVC11)
+ set(_boost_COMPILER "-vc110")
+ elseif (MSVC10)
+ set(_boost_COMPILER "-vc100")
+ elseif (MSVC90)
+ set(_boost_COMPILER "-vc90")
+ elseif (MSVC80)
+ set(_boost_COMPILER "-vc80")
+ elseif (MSVC71)
+ set(_boost_COMPILER "-vc71")
+ elseif (MSVC70) # Good luck!
+ set(_boost_COMPILER "-vc7") # yes, this is correct
+ elseif (MSVC60) # Good luck!
+ set(_boost_COMPILER "-vc6") # yes, this is correct
+ elseif (BORLAND)
+ set(_boost_COMPILER "-bcb")
+ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "SunPro")
+ set(_boost_COMPILER "-sw")
+ elseif (MINGW)
+ if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34)
+ set(_boost_COMPILER "-mgw") # no GCC version encoding prior to 1.34
+ else()
+ _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION)
+ set(_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}")
+ endif()
+ elseif (UNIX)
+ if (CMAKE_COMPILER_IS_GNUCXX)
+ if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34)
+ set(_boost_COMPILER "-gcc") # no GCC version encoding prior to 1.34
+ else()
+ _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION)
+ # Determine which version of GCC we have.
+ if(APPLE)
+ if(Boost_MINOR_VERSION)
+ if(${Boost_MINOR_VERSION} GREATER 35)
+ # In Boost 1.36.0 and newer, the mangled compiler name used
+ # on Mac OS X/Darwin is "xgcc".
+ set(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}")
+ else()
+ # In Boost <= 1.35.0, there is no mangled compiler name for
+ # the Mac OS X/Darwin version of GCC.
+ set(_boost_COMPILER "")
+ endif()
+ else()
+ # We don't know the Boost version, so assume it's
+ # pre-1.36.0.
+ set(_boost_COMPILER "")
+ endif()
+ else()
+ set(_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}")
+ endif()
+ endif()
+ endif ()
+ else()
+ # TODO at least Boost_DEBUG here?
+ set(_boost_COMPILER "")
+ endif()
+ set(${_ret} ${_boost_COMPILER} PARENT_SCOPE)
+endfunction()
+
+#
+# End functions/macros
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+# main.
+#-------------------------------------------------------------------------------
+
+if(NOT DEFINED Boost_USE_MULTITHREADED)
+ set(Boost_USE_MULTITHREADED TRUE)
+endif()
+
+# Check the version of Boost against the requested version.
+if(Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR)
+ message(SEND_ERROR "When requesting a specific version of Boost, you must provide at least the major and minor version numbers, e.g., 1.34")
+endif()
+
+if(Boost_FIND_VERSION_EXACT)
+ # The version may appear in a directory with or without the patch
+ # level, even when the patch level is non-zero.
+ set(_boost_TEST_VERSIONS
+ "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}.${Boost_FIND_VERSION_PATCH}"
+ "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
+else()
+ # The user has not requested an exact version. Among known
+ # versions, find those that are acceptable to the user request.
+ set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS}
+ "1.56.0" "1.56" "1.55.0" "1.55" "1.54.0" "1.54"
+ "1.53.0" "1.53" "1.52.0" "1.52" "1.51.0" "1.51"
+ "1.50.0" "1.50" "1.49.0" "1.49" "1.48.0" "1.48" "1.47.0" "1.47" "1.46.1"
+ "1.46.0" "1.46" "1.45.0" "1.45" "1.44.0" "1.44" "1.43.0" "1.43" "1.42.0" "1.42"
+ "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37"
+ "1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0"
+ "1.34" "1.33.1" "1.33.0" "1.33")
+ set(_boost_TEST_VERSIONS)
+ if(Boost_FIND_VERSION)
+ set(_Boost_FIND_VERSION_SHORT "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
+ # Select acceptable versions.
+ foreach(version ${_Boost_KNOWN_VERSIONS})
+ if(NOT "${version}" VERSION_LESS "${Boost_FIND_VERSION}")
+ # This version is high enough.
+ list(APPEND _boost_TEST_VERSIONS "${version}")
+ elseif("${version}.99" VERSION_EQUAL "${_Boost_FIND_VERSION_SHORT}.99")
+ # This version is a short-form for the requested version with
+ # the patch level dropped.
+ list(APPEND _boost_TEST_VERSIONS "${version}")
+ endif()
+ endforeach()
+ else()
+ # Any version is acceptable.
+ set(_boost_TEST_VERSIONS "${_Boost_KNOWN_VERSIONS}")
+ endif()
+endif()
+
+# The reason that we failed to find Boost. This will be set to a
+# user-friendly message when we fail to find some necessary piece of
+# Boost.
+set(Boost_ERROR_REASON)
+
+if(Boost_DEBUG)
+ # Output some of their choices
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_USE_MULTITHREADED = ${Boost_USE_MULTITHREADED}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_USE_STATIC_LIBS = ${Boost_USE_STATIC_LIBS}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_USE_STATIC_RUNTIME = ${Boost_USE_STATIC_RUNTIME}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_ADDITIONAL_VERSIONS = ${Boost_ADDITIONAL_VERSIONS}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Boost_NO_SYSTEM_PATHS = ${Boost_NO_SYSTEM_PATHS}")
+endif()
+
+if(WIN32)
+ # In windows, automatic linking is performed, so you do not have
+ # to specify the libraries. If you are linking to a dynamic
+ # runtime, then you can choose to link to either a static or a
+ # dynamic Boost library, the default is to do a static link. You
+ # can alter this for a specific library "whatever" by defining
+ # BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to be
+ # linked dynamically. Alternatively you can force all Boost
+ # libraries to dynamic link by defining BOOST_ALL_DYN_LINK.
+
+ # This feature can be disabled for Boost library "whatever" by
+ # defining BOOST_WHATEVER_NO_LIB, or for all of Boost by defining
+ # BOOST_ALL_NO_LIB.
+
+ # If you want to observe which libraries are being linked against
+ # then defining BOOST_LIB_DIAGNOSTIC will cause the auto-linking
+ # code to emit a #pragma message each time a library is selected
+ # for linking.
+ set(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC")
+endif()
+
+_Boost_CHECK_SPELLING(Boost_ROOT)
+_Boost_CHECK_SPELLING(Boost_LIBRARYDIR)
+_Boost_CHECK_SPELLING(Boost_INCLUDEDIR)
+
+# Collect environment variable inputs as hints. Do not consider changes.
+foreach(v BOOSTROOT BOOST_ROOT BOOST_INCLUDEDIR BOOST_LIBRARYDIR)
+ set(_env $ENV{${v}})
+ if(_env)
+ file(TO_CMAKE_PATH "${_env}" _ENV_${v})
+ else()
+ set(_ENV_${v} "")
+ endif()
+endforeach()
+if(NOT _ENV_BOOST_ROOT AND _ENV_BOOSTROOT)
+ set(_ENV_BOOST_ROOT "${_ENV_BOOSTROOT}")
+endif()
+
+# Collect inputs and cached results. Detect changes since the last run.
+if(NOT BOOST_ROOT AND BOOSTROOT)
+ set(BOOST_ROOT "${BOOSTROOT}")
+endif()
+set(_Boost_VARS_DIR
+ BOOST_ROOT
+ Boost_NO_SYSTEM_PATHS
+ )
+
+if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Declared as CMake or Environmental Variables:")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " BOOST_ROOT = ${BOOST_ROOT}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " BOOST_INCLUDEDIR = ${BOOST_INCLUDEDIR}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " BOOST_LIBRARYDIR = ${BOOST_LIBRARYDIR}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}")
+endif()
+
+# ------------------------------------------------------------------------
+# Search for Boost include DIR
+# ------------------------------------------------------------------------
+
+set(_Boost_VARS_INC BOOST_INCLUDEDIR Boost_INCLUDE_DIR Boost_ADDITIONAL_VERSIONS)
+_Boost_CHANGE_DETECT(_Boost_CHANGE_INCDIR ${_Boost_VARS_DIR} ${_Boost_VARS_INC})
+# Clear Boost_INCLUDE_DIR if it did not change but other input affecting the
+# location did. We will find a new one based on the new inputs.
+if(_Boost_CHANGE_INCDIR AND NOT _Boost_INCLUDE_DIR_CHANGED)
+ unset(Boost_INCLUDE_DIR CACHE)
+endif()
+
+if(NOT Boost_INCLUDE_DIR)
+ set(_boost_INCLUDE_SEARCH_DIRS "")
+ if(BOOST_INCLUDEDIR)
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_INCLUDEDIR})
+ elseif(_ENV_BOOST_INCLUDEDIR)
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_INCLUDEDIR})
+ endif()
+
+ if( BOOST_ROOT )
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_ROOT}/include ${BOOST_ROOT})
+ elseif( _ENV_BOOST_ROOT )
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_ROOT}/include ${_ENV_BOOST_ROOT})
+ endif()
+
+ if( Boost_NO_SYSTEM_PATHS)
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH)
+ else()
+ list(APPEND _boost_INCLUDE_SEARCH_DIRS PATHS
+ C:/boost/include
+ C:/boost
+ /sw/local/include
+ )
+ endif()
+
+ # Try to find Boost by stepping backwards through the Boost versions
+ # we know about.
+ # Build a list of path suffixes for each version.
+ set(_boost_PATH_SUFFIXES)
+ foreach(_boost_VER ${_boost_TEST_VERSIONS})
+ # Add in a path suffix, based on the required version, ideally
+ # we could read this from version.hpp, but for that to work we'd
+ # need to know the include dir already
+ set(_boost_BOOSTIFIED_VERSION)
+
+ # Transform 1.35 => 1_35 and 1.36.0 => 1_36_0
+ if(_boost_VER MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
+ string(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1_\\2_\\3"
+ _boost_BOOSTIFIED_VERSION ${_boost_VER})
+ elseif(_boost_VER MATCHES "[0-9]+\\.[0-9]+")
+ string(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1_\\2"
+ _boost_BOOSTIFIED_VERSION ${_boost_VER})
+ endif()
+
+ list(APPEND _boost_PATH_SUFFIXES
+ "boost-${_boost_BOOSTIFIED_VERSION}"
+ "boost_${_boost_BOOSTIFIED_VERSION}"
+ "boost/boost-${_boost_BOOSTIFIED_VERSION}"
+ "boost/boost_${_boost_BOOSTIFIED_VERSION}"
+ )
+
+ endforeach()
+
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Include debugging info:")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " _boost_INCLUDE_SEARCH_DIRS = ${_boost_INCLUDE_SEARCH_DIRS}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ " _boost_PATH_SUFFIXES = ${_boost_PATH_SUFFIXES}")
+ endif()
+
+ # Look for a standard boost header file.
+ find_path(Boost_INCLUDE_DIR
+ NAMES boost/config.hpp
+ HINTS ${_boost_INCLUDE_SEARCH_DIRS}
+ PATH_SUFFIXES ${_boost_PATH_SUFFIXES}
+ )
+endif()
+
+# ------------------------------------------------------------------------
+# Extract version information from version.hpp
+# ------------------------------------------------------------------------
+
+# Set Boost_FOUND based only on header location and version.
+# It will be updated below for component libraries.
+if(Boost_INCLUDE_DIR)
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "location of version.hpp: ${Boost_INCLUDE_DIR}/boost/version.hpp")
+ endif()
+
+ # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
+ set(Boost_VERSION 0)
+ set(Boost_LIB_VERSION "")
+ file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS REGEX "#define BOOST_(LIB_)?VERSION ")
+ set(_Boost_VERSION_REGEX "([0-9]+)")
+ set(_Boost_LIB_VERSION_REGEX "\"([0-9_]+)\"")
+ foreach(v VERSION LIB_VERSION)
+ if("${_boost_VERSION_HPP_CONTENTS}" MATCHES ".*#define BOOST_${v} ${_Boost_${v}_REGEX}.*")
+ set(Boost_${v} "${CMAKE_MATCH_1}")
+ endif()
+ endforeach()
+ unset(_boost_VERSION_HPP_CONTENTS)
+
+ math(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000")
+ math(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000")
+ math(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100")
+
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}\nBoost include path: ${Boost_INCLUDE_DIR}")
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "version.hpp reveals boost "
+ "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
+ endif()
+
+ if(Boost_FIND_VERSION)
+ # Set Boost_FOUND based on requested version.
+ set(_Boost_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
+ if("${_Boost_VERSION}" VERSION_LESS "${Boost_FIND_VERSION}")
+ set(Boost_FOUND 0)
+ set(_Boost_VERSION_AGE "old")
+ elseif(Boost_FIND_VERSION_EXACT AND
+ NOT "${_Boost_VERSION}" VERSION_EQUAL "${Boost_FIND_VERSION}")
+ set(Boost_FOUND 0)
+ set(_Boost_VERSION_AGE "new")
+ else()
+ set(Boost_FOUND 1)
+ endif()
+ if(NOT Boost_FOUND)
+ # State that we found a version of Boost that is too new or too old.
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}\nDetected version of Boost is too ${_Boost_VERSION_AGE}. Requested version was ${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}")
+ if (Boost_FIND_VERSION_PATCH)
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}.${Boost_FIND_VERSION_PATCH}")
+ endif ()
+ if (NOT Boost_FIND_VERSION_EXACT)
+ set(Boost_ERROR_REASON "${Boost_ERROR_REASON} (or newer)")
+ endif ()
+ set(Boost_ERROR_REASON "${Boost_ERROR_REASON}.")
+ endif ()
+ else()
+ # Caller will accept any Boost version.
+ set(Boost_FOUND 1)
+ endif()
+else()
+ set(Boost_FOUND 0)
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.")
+endif()
+
+# ------------------------------------------------------------------------
+# Suffix initialization and compiler suffix detection.
+# ------------------------------------------------------------------------
+
+set(_Boost_VARS_NAME
+ Boost_COMPILER
+ Boost_THREADAPI
+ Boost_USE_DEBUG_PYTHON
+ Boost_USE_MULTITHREADED
+ Boost_USE_STATIC_LIBS
+ Boost_USE_STATIC_RUNTIME
+ Boost_USE_STLPORT
+ Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS
+ )
+_Boost_CHANGE_DETECT(_Boost_CHANGE_LIBNAME ${_Boost_VARS_NAME})
+
+# Setting some more suffixes for the library
+set(Boost_LIB_PREFIX "")
+if ( WIN32 AND Boost_USE_STATIC_LIBS AND NOT CYGWIN)
+ set(Boost_LIB_PREFIX "lib")
+endif()
+
+if (Boost_COMPILER)
+ set(_boost_COMPILER ${Boost_COMPILER})
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "using user-specified Boost_COMPILER = ${_boost_COMPILER}")
+ endif()
+else()
+ # Attempt to guess the compiler suffix
+ # NOTE: this is not perfect yet, if you experience any issues
+ # please report them and use the Boost_COMPILER variable
+ # to work around the problems.
+ _Boost_GUESS_COMPILER_PREFIX(_boost_COMPILER)
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "guessed _boost_COMPILER = ${_boost_COMPILER}")
+ endif()
+endif()
+
+set (_boost_MULTITHREADED "-mt")
+if( NOT Boost_USE_MULTITHREADED )
+ set (_boost_MULTITHREADED "")
+endif()
+if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_MULTITHREADED = ${_boost_MULTITHREADED}")
+endif()
+
+#======================
+# Systematically build up the Boost ABI tag
+# http://boost.org/doc/libs/1_41_0/more/getting_started/windows.html#library-naming
+set( _boost_RELEASE_ABI_TAG "-")
+set( _boost_DEBUG_ABI_TAG "-")
+# Key Use this library when:
+# s linking statically to the C++ standard library and
+# compiler runtime support libraries.
+if(Boost_USE_STATIC_RUNTIME)
+ set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}s")
+ set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}s")
+endif()
+# g using debug versions of the standard and runtime
+# support libraries
+if(WIN32)
+ if(MSVC OR "${CMAKE_CXX_COMPILER}" MATCHES "icl"
+ OR "${CMAKE_CXX_COMPILER}" MATCHES "icpc")
+ set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}g")
+ endif()
+endif()
+# y using special debug build of python
+if(Boost_USE_DEBUG_PYTHON)
+ set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}y")
+endif()
+# d using a debug version of your code
+set(_boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}d")
+# p using the STLport standard library rather than the
+# default one supplied with your compiler
+if(Boost_USE_STLPORT)
+ set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}p")
+ set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}p")
+endif()
+# n using the STLport deprecated "native iostreams" feature
+if(Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS)
+ set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}n")
+ set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}n")
+endif()
+
+if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_RELEASE_ABI_TAG = ${_boost_RELEASE_ABI_TAG}")
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_DEBUG_ABI_TAG = ${_boost_DEBUG_ABI_TAG}")
+endif()
+
+# ------------------------------------------------------------------------
+# Begin finding boost libraries
+# ------------------------------------------------------------------------
+set(_Boost_VARS_LIB BOOST_LIBRARYDIR Boost_LIBRARY_DIR)
+_Boost_CHANGE_DETECT(_Boost_CHANGE_LIBDIR ${_Boost_VARS_DIR} ${_Boost_VARS_LIB} Boost_INCLUDE_DIR)
+# Clear Boost_LIBRARY_DIR if it did not change but other input affecting the
+# location did. We will find a new one based on the new inputs.
+if(_Boost_CHANGE_LIBDIR AND NOT _Boost_LIBRARY_DIR_CHANGED)
+ unset(Boost_LIBRARY_DIR CACHE)
+endif()
+
+if(Boost_LIBRARY_DIR)
+ set(_boost_LIBRARY_SEARCH_DIRS ${Boost_LIBRARY_DIR} NO_DEFAULT_PATH)
+else()
+ set(_boost_LIBRARY_SEARCH_DIRS "")
+ if(BOOST_LIBRARYDIR)
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS ${BOOST_LIBRARYDIR})
+ elseif(_ENV_BOOST_LIBRARYDIR)
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS ${_ENV_BOOST_LIBRARYDIR})
+ endif()
+
+ if(BOOST_ROOT)
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS ${BOOST_ROOT}/lib ${BOOST_ROOT}/stage/lib)
+ elseif(_ENV_BOOST_ROOT)
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS ${_ENV_BOOST_ROOT}/lib ${_ENV_BOOST_ROOT}/stage/lib)
+ endif()
+
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS
+ ${Boost_INCLUDE_DIR}/lib
+ ${Boost_INCLUDE_DIR}/../lib
+ ${Boost_INCLUDE_DIR}/stage/lib
+ )
+ if( Boost_NO_SYSTEM_PATHS )
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH)
+ else()
+ list(APPEND _boost_LIBRARY_SEARCH_DIRS PATHS
+ C:/boost/lib
+ C:/boost
+ /sw/local/lib
+ )
+ endif()
+endif()
+
+if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "_boost_LIBRARY_SEARCH_DIRS = ${_boost_LIBRARY_SEARCH_DIRS}")
+endif()
+
+# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
+if( Boost_USE_STATIC_LIBS )
+ set( _boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ if(WIN32)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ else()
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
+ endif()
+endif()
+
+# We want to use the tag inline below without risking double dashes
+if(_boost_RELEASE_ABI_TAG)
+ if(${_boost_RELEASE_ABI_TAG} STREQUAL "-")
+ set(_boost_RELEASE_ABI_TAG "")
+ endif()
+endif()
+if(_boost_DEBUG_ABI_TAG)
+ if(${_boost_DEBUG_ABI_TAG} STREQUAL "-")
+ set(_boost_DEBUG_ABI_TAG "")
+ endif()
+endif()
+
+# The previous behavior of FindBoost when Boost_USE_STATIC_LIBS was enabled
+# on WIN32 was to:
+# 1. Search for static libs compiled against a SHARED C++ standard runtime library (use if found)
+# 2. Search for static libs compiled against a STATIC C++ standard runtime library (use if found)
+# We maintain this behavior since changing it could break people's builds.
+# To disable the ambiguous behavior, the user need only
+# set Boost_USE_STATIC_RUNTIME either ON or OFF.
+set(_boost_STATIC_RUNTIME_WORKAROUND false)
+if(WIN32 AND Boost_USE_STATIC_LIBS)
+ if(NOT DEFINED Boost_USE_STATIC_RUNTIME)
+ set(_boost_STATIC_RUNTIME_WORKAROUND true)
+ endif()
+endif()
+
+# On versions < 1.35, remove the System library from the considered list
+# since it wasn't added until 1.35.
+if(Boost_VERSION AND Boost_FIND_COMPONENTS)
+ if(Boost_VERSION LESS 103500)
+ list(REMOVE_ITEM Boost_FIND_COMPONENTS system)
+ endif()
+endif()
+
+# If the user changed any of our control inputs flush previous results.
+if(_Boost_CHANGE_LIBDIR OR _Boost_CHANGE_LIBNAME)
+ foreach(COMPONENT ${_Boost_COMPONENTS_SEARCHED})
+ string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+ foreach(c DEBUG RELEASE)
+ set(_var Boost_${UPPERCOMPONENT}_LIBRARY_${c})
+ unset(${_var} CACHE)
+ set(${_var} "${_var}-NOTFOUND")
+ endforeach()
+ endforeach()
+ set(_Boost_COMPONENTS_SEARCHED "")
+endif()
+
+foreach(COMPONENT ${Boost_FIND_COMPONENTS})
+ string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+
+ set( _boost_docstring_release "Boost ${COMPONENT} library (release)")
+ set( _boost_docstring_debug "Boost ${COMPONENT} library (debug)")
+
+ #
+ # Find RELEASE libraries
+ #
+ set(_boost_RELEASE_NAMES
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT} )
+ if(_boost_STATIC_RUNTIME_WORKAROUND)
+ set(_boost_RELEASE_STATIC_ABI_TAG "-s${_boost_RELEASE_ABI_TAG}")
+ list(APPEND _boost_RELEASE_NAMES
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} )
+ endif()
+ if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread")
+ _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_RELEASE_NAMES ${_boost_RELEASE_NAMES})
+ endif()
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Searching for ${UPPERCOMPONENT}_LIBRARY_RELEASE: ${_boost_RELEASE_NAMES}")
+ endif()
+
+ # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing.
+ string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS}")
+
+ _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE
+ NAMES ${_boost_RELEASE_NAMES}
+ HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp}
+ NAMES_PER_DIR
+ DOC "${_boost_docstring_release}"
+ )
+
+ #
+ # Find DEBUG libraries
+ #
+ set(_boost_DEBUG_NAMES
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT} )
+ if(_boost_STATIC_RUNTIME_WORKAROUND)
+ set(_boost_DEBUG_STATIC_ABI_TAG "-s${_boost_DEBUG_ABI_TAG}")
+ list(APPEND _boost_DEBUG_NAMES
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION}
+ ${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} )
+ endif()
+ if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread")
+ _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_DEBUG_NAMES ${_boost_DEBUG_NAMES})
+ endif()
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Searching for ${UPPERCOMPONENT}_LIBRARY_DEBUG: ${_boost_DEBUG_NAMES}")
+ endif()
+
+ # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing.
+ string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS}")
+
+ _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG
+ NAMES ${_boost_DEBUG_NAMES}
+ HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp}
+ NAMES_PER_DIR
+ DOC "${_boost_docstring_debug}"
+ )
+
+ if(Boost_REALPATH)
+ _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE "${_boost_docstring_release}")
+ _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG "${_boost_docstring_debug}" )
+ endif()
+
+ _Boost_ADJUST_LIB_VARS(${UPPERCOMPONENT})
+
+endforeach()
+
+# Restore the original find library ordering
+if( Boost_USE_STATIC_LIBS )
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${_boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
+endif()
+
+# ------------------------------------------------------------------------
+# End finding boost libraries
+# ------------------------------------------------------------------------
+
+set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
+set(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR})
+
+# The above setting of Boost_FOUND was based only on the header files.
+# Update it for the requested component libraries.
+if(Boost_FOUND)
+ # The headers were found. Check for requested component libs.
+ set(_boost_CHECKED_COMPONENT FALSE)
+ set(_Boost_MISSING_COMPONENTS "")
+ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
+ string(TOUPPER ${COMPONENT} COMPONENT)
+ set(_boost_CHECKED_COMPONENT TRUE)
+ if(NOT Boost_${COMPONENT}_FOUND)
+ string(TOLOWER ${COMPONENT} COMPONENT)
+ list(APPEND _Boost_MISSING_COMPONENTS ${COMPONENT})
+ endif()
+ endforeach()
+
+ if(Boost_DEBUG)
+ message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] Boost_FOUND = ${Boost_FOUND}")
+ endif()
+
+ if (_Boost_MISSING_COMPONENTS)
+ set(Boost_FOUND 0)
+ # We were unable to find some libraries, so generate a sensible
+ # error message that lists the libraries we were unable to find.
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}\nCould not find the following")
+ if(Boost_USE_STATIC_LIBS)
+ set(Boost_ERROR_REASON "${Boost_ERROR_REASON} static")
+ endif()
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON} Boost libraries:\n")
+ foreach(COMPONENT ${_Boost_MISSING_COMPONENTS})
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON} boost_${COMPONENT}\n")
+ endforeach()
+
+ list(LENGTH Boost_FIND_COMPONENTS Boost_NUM_COMPONENTS_WANTED)
+ list(LENGTH _Boost_MISSING_COMPONENTS Boost_NUM_MISSING_COMPONENTS)
+ if (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS})
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.")
+ else ()
+ set(Boost_ERROR_REASON
+ "${Boost_ERROR_REASON}Some (but not all) of the required Boost libraries were found. You may need to install these additional Boost libraries. Alternatively, set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.")
+ endif ()
+ endif ()
+
+ if( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT )
+ # Compatibility Code for backwards compatibility with CMake
+ # 2.4's FindBoost module.
+
+ # Look for the boost library path.
+ # Note that the user may not have installed any libraries
+ # so it is quite possible the Boost_LIBRARY_DIRS may not exist.
+ set(_boost_LIB_DIR ${Boost_INCLUDE_DIR})
+
+ if("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+")
+ get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH)
+ endif()
+
+ if("${_boost_LIB_DIR}" MATCHES "/include$")
+ # Strip off the trailing "/include" in the path.
+ get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH)
+ endif()
+
+ if(EXISTS "${_boost_LIB_DIR}/lib")
+ set(_boost_LIB_DIR ${_boost_LIB_DIR}/lib)
+ else()
+ if(EXISTS "${_boost_LIB_DIR}/stage/lib")
+ set(_boost_LIB_DIR ${_boost_LIB_DIR}/stage/lib)
+ else()
+ set(_boost_LIB_DIR "")
+ endif()
+ endif()
+
+ if(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}")
+ set(Boost_LIBRARY_DIRS ${_boost_LIB_DIR})
+ endif()
+
+ endif()
+else()
+ # Boost headers were not found so no components were found.
+ foreach(COMPONENT ${Boost_FIND_COMPONENTS})
+ string(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+ set(Boost_${UPPERCOMPONENT}_FOUND 0)
+ endforeach()
+endif()
+
+# ------------------------------------------------------------------------
+# Notification to end user about what was found
+# ------------------------------------------------------------------------
+
+set(Boost_LIBRARIES "")
+if(Boost_FOUND)
+ if(NOT Boost_FIND_QUIETLY)
+ message(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
+ if(Boost_FIND_COMPONENTS)
+ message(STATUS "Found the following Boost libraries:")
+ endif()
+ endif()
+ foreach( COMPONENT ${Boost_FIND_COMPONENTS} )
+ string( TOUPPER ${COMPONENT} UPPERCOMPONENT )
+ if( Boost_${UPPERCOMPONENT}_FOUND )
+ if(NOT Boost_FIND_QUIETLY)
+ message (STATUS " ${COMPONENT}")
+ endif()
+ list(APPEND Boost_LIBRARIES ${Boost_${UPPERCOMPONENT}_LIBRARY})
+ endif()
+ endforeach()
+else()
+ if(Boost_FIND_REQUIRED)
+ message(SEND_ERROR "Unable to find the requested Boost libraries.\n${Boost_ERROR_REASON}")
+ else()
+ if(NOT Boost_FIND_QUIETLY)
+ # we opt not to automatically output Boost_ERROR_REASON here as
+ # it could be quite lengthy and somewhat imposing in its requests
+ # Since Boost is not always a required dependency we'll leave this
+ # up to the end-user.
+ if(Boost_DEBUG OR Boost_DETAILED_FAILURE_MSG)
+ message(STATUS "Could NOT find Boost\n${Boost_ERROR_REASON}")
+ else()
+ message(STATUS "Could NOT find Boost")
+ endif()
+ endif()
+ endif()
+endif()
+
+# Configure display of cache entries in GUI.
+foreach(v BOOSTROOT BOOST_ROOT ${_Boost_VARS_INC} ${_Boost_VARS_LIB})
+ get_property(_type CACHE ${v} PROPERTY TYPE)
+ if(_type)
+ set_property(CACHE ${v} PROPERTY ADVANCED 1)
+ if("x${_type}" STREQUAL "xUNINITIALIZED")
+ if("x${v}" STREQUAL "xBoost_ADDITIONAL_VERSIONS")
+ set_property(CACHE ${v} PROPERTY TYPE STRING)
+ else()
+ set_property(CACHE ${v} PROPERTY TYPE PATH)
+ endif()
+ endif()
+ endif()
+endforeach()
+
+# Record last used values of input variables so we can
+# detect on the next run if the user changed them.
+foreach(v
+ ${_Boost_VARS_INC} ${_Boost_VARS_LIB}
+ ${_Boost_VARS_DIR} ${_Boost_VARS_NAME}
+ )
+ if(DEFINED ${v})
+ set(_${v}_LAST "${${v}}" CACHE INTERNAL "Last used ${v} value.")
+ else()
+ unset(_${v}_LAST CACHE)
+ endif()
+endforeach()
+
+# Maintain a persistent list of components requested anywhere since
+# the last flush.
+set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}")
+list(APPEND _Boost_COMPONENTS_SEARCHED ${Boost_FIND_COMPONENTS})
+list(REMOVE_DUPLICATES _Boost_COMPONENTS_SEARCHED)
+list(SORT _Boost_COMPONENTS_SEARCHED)
+set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}"
+ CACHE INTERNAL "Components requested for this build tree.")
diff --git a/dep/SFMT/SFMT.h b/dep/SFMT/SFMT.h
index 4004ae1db6e..3d15d651e5b 100644
--- a/dep/SFMT/SFMT.h
+++ b/dep/SFMT/SFMT.h
@@ -150,9 +150,13 @@ __m128i const &c, __m128i const &d, __m128i const &mask) {
return z2;
}
+namespace boost {
+ template <typename T> class thread_specific_ptr;
+}
+
// Class for SFMT generator
class SFMTRand { // Encapsulate random number generator
- friend class ACE_TSS<SFMTRand>;
+ friend class boost::thread_specific_ptr<SFMTRand>;
public:
SFMTRand()
@@ -243,6 +247,47 @@ public:
y = ((uint32_t*)state)[ix++];
return y;
}
+
+ void* operator new(size_t size, std::nothrow_t const&)
+ {
+ return _mm_malloc(size, 16);
+ }
+
+ void operator delete(void* ptr, std::nothrow_t const&)
+ {
+ _mm_free(ptr);
+ }
+
+ void* operator new(size_t size)
+ {
+ return _mm_malloc(size, 16);
+ }
+
+ void operator delete(void* ptr)
+ {
+ _mm_free(ptr);
+ }
+
+ void* operator new[](size_t size, std::nothrow_t const&)
+ {
+ return _mm_malloc(size, 16);
+ }
+
+ void operator delete[](void* ptr, std::nothrow_t const&)
+ {
+ _mm_free(ptr);
+ }
+
+ void* operator new[](size_t size)
+ {
+ return _mm_malloc(size, 16);
+ }
+
+ void operator delete[](void* ptr)
+ {
+ _mm_free(ptr);
+ }
+
private:
void Init2() // Various initializations and period certification
{
@@ -307,46 +352,6 @@ private:
ix = 0;
}
- void* operator new(size_t size, std::nothrow_t const&)
- {
- return _mm_malloc(size, 16);
- }
-
- void operator delete(void* ptr, std::nothrow_t const&)
- {
- _mm_free(ptr);
- }
-
- void* operator new(size_t size)
- {
- return _mm_malloc(size, 16);
- }
-
- void operator delete(void* ptr)
- {
- _mm_free(ptr);
- }
-
- void* operator new[](size_t size, std::nothrow_t const&)
- {
- return _mm_malloc(size, 16);
- }
-
- void operator delete[](void* ptr, std::nothrow_t const&)
- {
- _mm_free(ptr);
- }
-
- void* operator new[](size_t size)
- {
- return _mm_malloc(size, 16);
- }
-
- void operator delete[](void* ptr)
- {
- _mm_free(ptr);
- }
-
__m128i mask; // AND mask
__m128i state[SFMT_N]; // State vector for SFMT generator
uint32_t ix; // Index into state array
diff --git a/dep/g3dlite/Readme.txt b/dep/g3dlite/Readme.txt
index 7988d1f314e..739f6985090 100644
--- a/dep/g3dlite/Readme.txt
+++ b/dep/g3dlite/Readme.txt
@@ -9,3 +9,4 @@ G3D-v8.0_hotfix5.diff - 2013-02-27 - fix compilation in cygwin environments
G3D-v8.0_hotfix6.diff - 2013-03-08 - fix compilation in mingw
G3D-v8.0_hotfix7.diff - 2013-08-31 - fix typo in Matrix4 == operator
G3D-v8.0_hotfix8.diff - 2013-09-01 - fix typo in Vector3int32 += operator
+G3D-v8.0_hotfix9.diff - 2014-06-01 - only VS < 10 don't ship inttypes.h
diff --git a/dep/g3dlite/include/G3D/g3dmath.h b/dep/g3dlite/include/G3D/g3dmath.h
index b0c98aeaf04..4be723ca30c 100644
--- a/dep/g3dlite/include/G3D/g3dmath.h
+++ b/dep/g3dlite/include/G3D/g3dmath.h
@@ -30,7 +30,7 @@
#include <limits>
#include <stdlib.h>
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && (_MSC_VER < 1000)
// Visual Studio is missing inttypes.h
# ifndef PRId64
# define PRId64 "I64d"
diff --git a/src/server/authserver/CMakeLists.txt b/src/server/authserver/CMakeLists.txt
index 4391ac0450a..6d11ce21c00 100644
--- a/src/server/authserver/CMakeLists.txt
+++ b/src/server/authserver/CMakeLists.txt
@@ -80,6 +80,7 @@ target_link_libraries(authserver
${OPENSSL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${ACE_LIBRARY}
+ ${Boost_LIBRARIES}
)
if( WIN32 )
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp
index be6623c7fa3..2427c47a438 100644
--- a/src/server/authserver/Main.cpp
+++ b/src/server/authserver/Main.cpp
@@ -24,12 +24,13 @@
* authentication server
*/
-#include <ace/Dev_Poll_Reactor.h>
-#include <ace/TP_Reactor.h>
-#include <ace/ACE.h>
-#include <ace/Sig_Handler.h>
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
+#include <iostream>
+#include <cstdlib>
+#include <boost/bind.hpp>
+#include <boost/asio.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
#include "Common.h"
#include "Database/DatabaseEnv.h"
@@ -37,9 +38,9 @@
#include "Log.h"
#include "SystemConfig.h"
#include "Util.h"
-#include "SignalHandler.h"
#include "RealmList.h"
-#include "RealmAcceptor.h"
+#include "AuthServer.h"
+
#ifdef __linux__
#include <sched.h>
@@ -53,26 +54,42 @@
bool StartDB();
void StopDB();
+void SetProcessPriority();
-bool stopEvent = false; // Setting it to true stops the server
+boost::asio::io_service _ioService;
+boost::asio::deadline_timer _dbPingTimer(_ioService);
+uint32 _dbPingInterval;
LoginDatabaseWorkerPool LoginDatabase; // Accessor to the authserver database
-/// Handle authserver's termination signals
-class AuthServerSignalHandler : public Trinity::SignalHandler
+using boost::asio::ip::tcp;
+
+
+void SignalHandler(const boost::system::error_code& error, int signalNumber)
{
-public:
- virtual void HandleSignal(int sigNum)
+ TC_LOG_ERROR("server.authserver", "SIGNAL HANDLER WORKING");
+ if (!error)
{
- switch (sigNum)
+ switch (signalNumber)
{
case SIGINT:
case SIGTERM:
- stopEvent = true;
+ _ioService.stop();
break;
}
}
-};
+}
+
+void KeepDatabaseAliveHandler(const boost::system::error_code& error)
+{
+ if (!error)
+ {
+ TC_LOG_INFO("server.authserver", "Ping MySQL to keep connection alive");
+ LoginDatabase.KeepAlive();
+
+ _dbPingTimer.expires_from_now(boost::posix_time::minutes(_dbPingInterval));
+ }
+}
/// Print out the usage string for this program on the console.
void usage(const char* prog)
@@ -83,7 +100,7 @@ void usage(const char* prog)
}
/// Launch the auth server
-extern int main(int argc, char** argv)
+int main(int argc, char** argv)
{
// Command line parsing to get the configuration file name
char const* configFile = _TRINITY_REALM_CONFIG;
@@ -117,14 +134,6 @@ extern int main(int argc, char** argv)
TC_LOG_WARN("server.authserver", "%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
-#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
- ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true);
-#else
- ACE_Reactor::instance(new ACE_Reactor(new ACE_TP_Reactor(), true), true);
-#endif
-
- TC_LOG_DEBUG("server.authserver", "Max allowed open files is %d", ACE::max_handles());
-
// authserver PID file creation
std::string pidFile = sConfigMgr->GetStringDefault("PidFile", "");
if (!pidFile.empty())
@@ -143,41 +152,97 @@ extern int main(int argc, char** argv)
return 1;
// Get the list of realms for the server
- sRealmList->Initialize(sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 20));
- if (sRealmList->size() == 0)
+ sRealmList.Initialize(sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 20));
+
+ if (sRealmList.size() == 0)
{
TC_LOG_ERROR("server.authserver", "No valid realms specified.");
return 1;
}
// Launch the listening network socket
- RealmAcceptor acceptor;
- int32 rmport = sConfigMgr->GetIntDefault("RealmServerPort", 3724);
- if (rmport < 0 || rmport > 0xFFFF)
+ int32 port = sConfigMgr->GetIntDefault("RealmServerPort", 3724);
+ if (port < 0 || port > 0xFFFF)
{
TC_LOG_ERROR("server.authserver", "Specified port out of allowed range (1-65535)");
return 1;
}
- std::string bind_ip = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
+ std::string bindIp = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
+
+ AuthServer authServer(_ioService, bindIp, port);
+
+ // Set signal handlers
+ boost::asio::signal_set signals(_ioService, SIGINT, SIGTERM);
+ signals.async_wait(SignalHandler);
+
+ SetProcessPriority();
- ACE_INET_Addr bind_addr(uint16(rmport), bind_ip.c_str());
- if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
+ _dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
+
+ _dbPingTimer.expires_from_now(boost::posix_time::seconds(_dbPingInterval));
+ _dbPingTimer.async_wait(KeepDatabaseAliveHandler);
+
+ // Start the io service
+ _ioService.run();
+
+ // Close the Database Pool and library
+ StopDB();
+
+ TC_LOG_INFO("server.authserver", "Halting process...");
+ return 0;
+}
+
+
+/// Initialize connection to the database
+bool StartDB()
+{
+ MySQL::Library_Init();
+
+ std::string dbstring = sConfigMgr->GetStringDefault("LoginDatabaseInfo", "");
+ if (dbstring.empty())
{
- TC_LOG_ERROR("server.authserver", "Auth server can not bind to %s:%d", bind_ip.c_str(), rmport);
- return 1;
+ TC_LOG_ERROR("server.authserver", "Database not specified");
+ return false;
+ }
+
+ int32 worker_threads = sConfigMgr->GetIntDefault("LoginDatabase.WorkerThreads", 1);
+ if (worker_threads < 1 || worker_threads > 32)
+ {
+ TC_LOG_ERROR("server.authserver", "Improper value specified for LoginDatabase.WorkerThreads, defaulting to 1.");
+ worker_threads = 1;
+ }
+
+ int32 synch_threads = sConfigMgr->GetIntDefault("LoginDatabase.SynchThreads", 1);
+ if (synch_threads < 1 || synch_threads > 32)
+ {
+ TC_LOG_ERROR("server.authserver", "Improper value specified for LoginDatabase.SynchThreads, defaulting to 1.");
+ synch_threads = 1;
+ }
+
+ // NOTE: While authserver is singlethreaded you should keep synch_threads == 1. Increasing it is just silly since only 1 will be used ever.
+ if (!LoginDatabase.Open(dbstring, uint8(worker_threads), uint8(synch_threads)))
+ {
+ TC_LOG_ERROR("server.authserver", "Cannot connect to database");
+ return false;
}
- // Initialize the signal handlers
- AuthServerSignalHandler SignalINT, SignalTERM;
+ TC_LOG_INFO("server.authserver", "Started auth database connection pool.");
+ sLog->SetRealmId(0); // Enables DB appenders when realm is set.
+ return true;
+}
- // Register authservers's signal handlers
- ACE_Sig_Handler Handler;
- Handler.register_handler(SIGINT, &SignalINT);
- Handler.register_handler(SIGTERM, &SignalTERM);
+/// Close the connection to the database
+void StopDB()
+{
+ LoginDatabase.Close();
+ MySQL::Library_End();
+}
+void SetProcessPriority()
+{
#if defined(_WIN32) || defined(__linux__)
///- Handle affinity for multiple processors and process priority
@@ -245,76 +310,4 @@ extern int main(int argc, char** argv)
#endif
#endif
-
- // maximum counter for next ping
- uint32 numLoops = (sConfigMgr->GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
- uint32 loopCounter = 0;
-
- // Wait for termination signal
- while (!stopEvent)
- {
- // dont move this outside the loop, the reactor will modify it
- ACE_Time_Value interval(0, 100000);
-
- if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1)
- break;
-
- if ((++loopCounter) == numLoops)
- {
- loopCounter = 0;
- TC_LOG_INFO("server.authserver", "Ping MySQL to keep connection alive");
- LoginDatabase.KeepAlive();
- }
- }
-
- // Close the Database Pool and library
- StopDB();
-
- TC_LOG_INFO("server.authserver", "Halting process...");
- return 0;
-}
-
-/// Initialize connection to the database
-bool StartDB()
-{
- MySQL::Library_Init();
-
- std::string dbstring = sConfigMgr->GetStringDefault("LoginDatabaseInfo", "");
- if (dbstring.empty())
- {
- TC_LOG_ERROR("server.authserver", "Database not specified");
- return false;
- }
-
- int32 worker_threads = sConfigMgr->GetIntDefault("LoginDatabase.WorkerThreads", 1);
- if (worker_threads < 1 || worker_threads > 32)
- {
- TC_LOG_ERROR("server.authserver", "Improper value specified for LoginDatabase.WorkerThreads, defaulting to 1.");
- worker_threads = 1;
- }
-
- int32 synch_threads = sConfigMgr->GetIntDefault("LoginDatabase.SynchThreads", 1);
- if (synch_threads < 1 || synch_threads > 32)
- {
- TC_LOG_ERROR("server.authserver", "Improper value specified for LoginDatabase.SynchThreads, defaulting to 1.");
- synch_threads = 1;
- }
-
- // NOTE: While authserver is singlethreaded you should keep synch_threads == 1. Increasing it is just silly since only 1 will be used ever.
- if (!LoginDatabase.Open(dbstring, uint8(worker_threads), uint8(synch_threads)))
- {
- TC_LOG_ERROR("server.authserver", "Cannot connect to database");
- return false;
- }
-
- TC_LOG_INFO("server.authserver", "Started auth database connection pool.");
- sLog->SetRealmId(0); // Enables DB appenders when realm is set.
- return true;
-}
-
-/// Close the connection to the database
-void StopDB()
-{
- LoginDatabase.Close();
- MySQL::Library_End();
}
diff --git a/src/server/authserver/PrecompiledHeaders/authPCH.h b/src/server/authserver/PrecompiledHeaders/authPCH.h
index 5fc3b0a3416..61059ae91b0 100644
--- a/src/server/authserver/PrecompiledHeaders/authPCH.h
+++ b/src/server/authserver/PrecompiledHeaders/authPCH.h
@@ -1,6 +1,7 @@
+#include "Common.h"
#include "Configuration/Config.h"
#include "Database/DatabaseEnv.h"
#include "Log.h"
#include "RealmList.h"
-#include "RealmSocket.h"
-#include "Common.h"
+#include "AuthServer.h"
+#include "AuthSession.h"
diff --git a/src/server/authserver/Realms/RealmList.cpp b/src/server/authserver/Realms/RealmList.cpp
index 4aeecfc0aaa..94d52fb3138 100644
--- a/src/server/authserver/Realms/RealmList.cpp
+++ b/src/server/authserver/Realms/RealmList.cpp
@@ -16,10 +16,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <boost/asio.hpp>
#include "Common.h"
#include "RealmList.h"
#include "Database/DatabaseEnv.h"
+namespace boost { namespace asio { namespace ip { class address; } } }
+
RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)) { }
// Load the realm list from the database
@@ -31,7 +34,8 @@ void RealmList::Initialize(uint32 updateInterval)
UpdateRealms(true);
}
-void RealmList::UpdateRealm(uint32 id, const std::string& name, ACE_INET_Addr const& address, ACE_INET_Addr const& localAddr, ACE_INET_Addr const& localSubmask, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build)
+void RealmList::UpdateRealm(uint32 id, const std::string& name, ip::address const& address, ip::address const& localAddr,
+ ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build)
{
// Create new if not exist or update existed
Realm& realm = m_realms[name];
@@ -42,12 +46,14 @@ void RealmList::UpdateRealm(uint32 id, const std::string& name, ACE_INET_Addr co
realm.flag = flag;
realm.timezone = timezone;
realm.allowedSecurityLevel = allowedSecurityLevel;
- realm.populationLevel = popu;
+ realm.populationLevel = population;
// Append port to IP address.
+
realm.ExternalAddress = address;
realm.LocalAddress = localAddr;
realm.LocalSubnetMask = localSubmask;
+ realm.port = port;
realm.gamebuild = build;
}
@@ -81,9 +87,9 @@ void RealmList::UpdateRealms(bool init)
Field* fields = result->Fetch();
uint32 realmId = fields[0].GetUInt32();
std::string name = fields[1].GetString();
- std::string externalAddress = fields[2].GetString();
- std::string localAddress = fields[3].GetString();
- std::string localSubmask = fields[4].GetString();
+ ip::address externalAddress = ip::address::from_string(fields[2].GetString());
+ ip::address localAddress = ip::address::from_string(fields[3].GetString());
+ ip::address localSubmask = ip::address::from_string(fields[4].GetString());
uint16 port = fields[5].GetUInt16();
uint8 icon = fields[6].GetUInt8();
RealmFlags flag = RealmFlags(fields[7].GetUInt8());
@@ -92,14 +98,11 @@ void RealmList::UpdateRealms(bool init)
float pop = fields[10].GetFloat();
uint32 build = fields[11].GetUInt32();
- ACE_INET_Addr externalAddr(port, externalAddress.c_str(), AF_INET);
- ACE_INET_Addr localAddr(port, localAddress.c_str(), AF_INET);
- ACE_INET_Addr submask(0, localSubmask.c_str(), AF_INET);
-
- UpdateRealm(realmId, name, externalAddr, localAddr, submask, icon, flag, timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build);
+ UpdateRealm(realmId, name, externalAddress, localAddress, localSubmask, port, icon, flag, timezone,
+ (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build);
if (init)
- TC_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(), m_realms[name].ExternalAddress.get_host_addr(), port);
+ TC_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(), m_realms[name].ExternalAddress.to_string().c_str(), port);
}
while (result->NextRow());
}
diff --git a/src/server/authserver/Realms/RealmList.h b/src/server/authserver/Realms/RealmList.h
index 1d76c39e4f0..b96d5523da9 100644
--- a/src/server/authserver/Realms/RealmList.h
+++ b/src/server/authserver/Realms/RealmList.h
@@ -19,30 +19,31 @@
#ifndef _REALMLIST_H
#define _REALMLIST_H
-#include <ace/Singleton.h>
-#include <ace/Null_Mutex.h>
-#include <ace/INET_Addr.h>
+#include <boost/asio.hpp>
#include "Common.h"
+using namespace boost::asio;
+
enum RealmFlags
{
- REALM_FLAG_NONE = 0x00,
- REALM_FLAG_INVALID = 0x01,
- REALM_FLAG_OFFLINE = 0x02,
- REALM_FLAG_SPECIFYBUILD = 0x04,
- REALM_FLAG_UNK1 = 0x08,
- REALM_FLAG_UNK2 = 0x10,
- REALM_FLAG_RECOMMENDED = 0x20,
- REALM_FLAG_NEW = 0x40,
- REALM_FLAG_FULL = 0x80
+ REALM_FLAG_NONE = 0x00,
+ REALM_FLAG_INVALID = 0x01,
+ REALM_FLAG_OFFLINE = 0x02,
+ REALM_FLAG_SPECIFYBUILD = 0x04,
+ REALM_FLAG_UNK1 = 0x08,
+ REALM_FLAG_UNK2 = 0x10,
+ REALM_FLAG_RECOMMENDED = 0x20,
+ REALM_FLAG_NEW = 0x40,
+ REALM_FLAG_FULL = 0x80
};
// Storage object for a realm
struct Realm
{
- ACE_INET_Addr ExternalAddress;
- ACE_INET_Addr LocalAddress;
- ACE_INET_Addr LocalSubnetMask;
+ ip::address ExternalAddress;
+ ip::address LocalAddress;
+ ip::address LocalSubnetMask;
+ uint16 port;
std::string name;
uint8 icon;
RealmFlags flag;
@@ -59,8 +60,11 @@ class RealmList
public:
typedef std::map<std::string, Realm> RealmMap;
- RealmList();
- ~RealmList() { }
+ static RealmList& instance()
+ {
+ static RealmList *instance = new RealmList();
+ return *instance;
+ }
void Initialize(uint32 updateInterval);
@@ -73,13 +77,16 @@ public:
uint32 size() const { return m_realms.size(); }
private:
- void UpdateRealms(bool init=false);
- void UpdateRealm(uint32 id, const std::string& name, ACE_INET_Addr const& address, ACE_INET_Addr const& localAddr, ACE_INET_Addr const& localSubmask, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build);
+ RealmList();
+
+ void UpdateRealms(bool init = false);
+ void UpdateRealm(uint32 id, const std::string& name, ip::address const& address, ip::address const& localAddr,
+ ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build);
RealmMap m_realms;
uint32 m_UpdateInterval;
time_t m_NextUpdateTime;
};
-#define sRealmList ACE_Singleton<RealmList, ACE_Null_Mutex>::instance()
+#define sRealmList RealmList::instance()
#endif
diff --git a/src/server/authserver/Server/AuthServer.cpp b/src/server/authserver/Server/AuthServer.cpp
new file mode 100644
index 00000000000..5c3ef247254
--- /dev/null
+++ b/src/server/authserver/Server/AuthServer.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "AuthServer.h"
+#include "AuthSession.h"
+
+#include <boost/bind.hpp>
+#include <boost/asio.hpp>
+
+using boost::asio::ip::tcp;
+
+void AuthServer::AsyncAccept()
+{
+ _acceptor.async_accept(_socket, [this](boost::system::error_code error)
+ {
+ if (!error)
+ {
+ std::make_shared<AuthSession>(std::move(_socket))->Start();
+ }
+
+ AsyncAccept();
+ });
+}
+
+
+
diff --git a/src/server/authserver/Server/AuthServer.h b/src/server/authserver/Server/AuthServer.h
new file mode 100644
index 00000000000..985a48ad243
--- /dev/null
+++ b/src/server/authserver/Server/AuthServer.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __AUTHSERVER_H__
+#define __AUTHSERVER_H__
+
+#include <boost/asio.hpp>
+
+using boost::asio::ip::tcp;
+
+class AuthServer
+{
+public:
+ AuthServer(boost::asio::io_service& ioService, std::string bindIp, int port) : _socket(ioService), _acceptor(ioService, tcp::endpoint(tcp::v4(), port))
+ {
+ tcp::endpoint endpoint(boost::asio::ip::address::from_string(bindIp), port);
+
+ _acceptor = tcp::acceptor(ioService, endpoint);
+
+ AsyncAccept();
+ };
+
+private:
+ void AsyncAccept();
+
+ tcp::acceptor _acceptor;
+ tcp::socket _socket;
+};
+
+#endif /* __AUTHSERVER_H__ */
diff --git a/src/server/authserver/Server/AuthSocket.cpp b/src/server/authserver/Server/AuthSession.cpp
index 4ddad3e6eb0..5b56a99d640 100644
--- a/src/server/authserver/Server/AuthSocket.cpp
+++ b/src/server/authserver/Server/AuthSession.cpp
@@ -1,64 +1,57 @@
/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#include <algorithm>
-#include <openssl/md5.h>
-
-#include "Common.h"
-#include "Database/DatabaseEnv.h"
+* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+*
+* 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <memory>
+#include <boost/asio.hpp>
+#include <boost/lexical_cast.hpp>
+#include <AuthSession.h>
+#include <Log.h>
#include "ByteBuffer.h"
-#include "Configuration/Config.h"
-#include "Log.h"
-#include "RealmList.h"
-#include "AuthSocket.h"
#include "AuthCodes.h"
-#include "TOTP.h"
+#include "Database/DatabaseEnv.h"
#include "SHA1.h"
#include "openssl/crypto.h"
+#include "Configuration/Config.h"
+#include "RealmList.h"
-#define ChunkSize 2048
+using boost::asio::ip::tcp;
enum eAuthCmd
{
- AUTH_LOGON_CHALLENGE = 0x00,
- AUTH_LOGON_PROOF = 0x01,
- AUTH_RECONNECT_CHALLENGE = 0x02,
- AUTH_RECONNECT_PROOF = 0x03,
- REALM_LIST = 0x10,
- XFER_INITIATE = 0x30,
- XFER_DATA = 0x31,
- XFER_ACCEPT = 0x32,
- XFER_RESUME = 0x33,
- XFER_CANCEL = 0x34
+ AUTH_LOGON_CHALLENGE = 0x00,
+ AUTH_LOGON_PROOF = 0x01,
+ AUTH_RECONNECT_CHALLENGE = 0x02,
+ AUTH_RECONNECT_PROOF = 0x03,
+ REALM_LIST = 0x10,
+ XFER_INITIATE = 0x30,
+ XFER_DATA = 0x31,
+ XFER_ACCEPT = 0x32,
+ XFER_RESUME = 0x33,
+ XFER_CANCEL = 0x34
};
enum eStatus
{
- STATUS_CONNECTED = 0,
+ STATUS_CONNECTED = 0,
STATUS_AUTHED
};
-// GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push, N), also any gcc version not support it at some paltform
-#if defined(__GNUC__)
-#pragma pack(1)
-#else
#pragma pack(push, 1)
-#endif
typedef struct AUTH_LOGON_CHALLENGE_C
{
@@ -86,7 +79,7 @@ typedef struct AUTH_LOGON_PROOF_C
uint8 M1[20];
uint8 crc_hash[20];
uint8 number_of_keys;
- uint8 securityFlags; // 0x00-0x04
+ uint8 securityFlags;
} sAuthLogonProof_C;
typedef struct AUTH_LOGON_PROOF_S
@@ -116,245 +109,110 @@ typedef struct AUTH_RECONNECT_PROOF_C
uint8 number_of_keys;
} sAuthReconnectProof_C;
-typedef struct XFER_INIT
-{
- uint8 cmd; // XFER_INITIATE
- uint8 fileNameLen; // strlen(fileName);
- uint8 fileName[5]; // fileName[fileNameLen]
- uint64 file_size; // file size (bytes)
- uint8 md5[MD5_DIGEST_LENGTH]; // MD5
-} XFER_INIT;
-
-typedef struct XFER_DATA
-{
- uint8 opcode;
- uint16 data_size;
- uint8 data[ChunkSize];
-} XFER_DATA_STRUCT;
+#pragma pack(pop)
+
typedef struct AuthHandler
{
eAuthCmd cmd;
uint32 status;
- bool (AuthSocket::*handler)(void);
+ size_t packetSize;
+ bool (AuthSession::*handler)();
} AuthHandler;
-// GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some paltform
-#if defined(__GNUC__)
-#pragma pack()
-#else
-#pragma pack(pop)
-#endif
-
-// Launch a thread to transfer a patch to the client
-class PatcherRunnable: public ACE_Based::Runnable
-{
-public:
- PatcherRunnable(class AuthSocket*);
- void run();
-
-private:
- AuthSocket* mySocket;
-};
-
-typedef struct PATCH_INFO
-{
- uint8 md5[MD5_DIGEST_LENGTH];
-} PATCH_INFO;
-
-// Caches MD5 hash of client patches present on the server
-class Patcher
-{
-public:
- typedef std::map<std::string, PATCH_INFO*> Patches;
- ~Patcher();
- Patcher();
- Patches::const_iterator begin() const { return _patches.begin(); }
- Patches::const_iterator end() const { return _patches.end(); }
- void LoadPatchMD5(char*);
- bool GetHash(char * pat, uint8 mymd5[16]);
-
-private:
- void LoadPatchesInfo();
- Patches _patches;
-};
+#define BYTE_SIZE 32
+#define REALMLIST_SKIP_PACKETS 5
const AuthHandler table[] =
{
- { AUTH_LOGON_CHALLENGE, STATUS_CONNECTED, &AuthSocket::_HandleLogonChallenge },
- { AUTH_LOGON_PROOF, STATUS_CONNECTED, &AuthSocket::_HandleLogonProof },
- { AUTH_RECONNECT_CHALLENGE, STATUS_CONNECTED, &AuthSocket::_HandleReconnectChallenge},
- { AUTH_RECONNECT_PROOF, STATUS_CONNECTED, &AuthSocket::_HandleReconnectProof },
- { REALM_LIST, STATUS_AUTHED, &AuthSocket::_HandleRealmList },
- { XFER_ACCEPT, STATUS_CONNECTED, &AuthSocket::_HandleXferAccept },
- { XFER_RESUME, STATUS_CONNECTED, &AuthSocket::_HandleXferResume },
- { XFER_CANCEL, STATUS_CONNECTED, &AuthSocket::_HandleXferCancel }
+ { AUTH_LOGON_CHALLENGE, STATUS_CONNECTED, sizeof(AUTH_LOGON_CHALLENGE_C), &AuthSession::_HandleLogonChallenge },
+ { AUTH_LOGON_PROOF, STATUS_CONNECTED, sizeof(AUTH_LOGON_PROOF_C), &AuthSession::_HandleLogonProof },
+ { AUTH_RECONNECT_CHALLENGE, STATUS_CONNECTED, sizeof(AUTH_LOGON_CHALLENGE_C), &AuthSession::_HandleReconnectChallenge },
+ { AUTH_RECONNECT_PROOF, STATUS_CONNECTED, sizeof(AUTH_RECONNECT_PROOF_C), &AuthSession::_HandleReconnectProof },
+ { REALM_LIST, STATUS_AUTHED, REALMLIST_SKIP_PACKETS, &AuthSession::_HandleRealmList }
};
-#define AUTH_TOTAL_COMMANDS 8
-
-// Holds the MD5 hash of client patches present on the server
-Patcher PatchesCache;
-
-// Constructor - set the N and g values for SRP6
-AuthSocket::AuthSocket(RealmSocket& socket) :
- pPatch(NULL), socket_(socket), _authed(false), _build(0),
- _expversion(0), _accountSecurityLevel(SEC_PLAYER)
+void AuthSession::AsyncReadHeader()
{
- N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
- g.SetDword(7);
-}
+ auto self(shared_from_this());
-// Close patch file descriptor before leaving
-AuthSocket::~AuthSocket(void) { }
+ _socket.async_read_some(boost::asio::buffer(_readBuffer, 1), [this, self](boost::system::error_code error, size_t transferedBytes)
+ {
+ if (!error && transferedBytes == 1)
+ {
+ for (const AuthHandler& entry : table)
+ {
+ if ((uint8)entry.cmd == _readBuffer[0] && (entry.status == STATUS_CONNECTED || (_isAuthenticated && entry.status == STATUS_AUTHED)))
+ {
+ // Handle dynamic size packet
+ if (_readBuffer[0] == AUTH_LOGON_CHALLENGE)
+ {
+ _socket.read_some(boost::asio::buffer(&_readBuffer[1], sizeof(uint8) + sizeof(uint16))); //error + size
-// Accept the connection
-void AuthSocket::OnAccept(void)
-{
- TC_LOG_DEBUG("server.authserver", "'%s:%d' Accepting connection", socket().getRemoteAddress().c_str(), socket().getRemotePort());
+ AsyncReadData(entry.handler, *reinterpret_cast<uint16*>(&_readBuffer[2]), sizeof(uint8) + sizeof(uint8) + sizeof(uint16)); // cmd + error + size
+ }
+ else
+ {
+ AsyncReadData(entry.handler, entry.packetSize, sizeof(uint8));
+ }
+ break;
+ }
+ }
+ }
+ else
+ {
+ _socket.close();
+ }
+ });
}
-void AuthSocket::OnClose(void)
+void AuthSession::AsyncReadData(bool (AuthSession::*handler)(), size_t dataSize, size_t bufferOffSet)
{
- TC_LOG_DEBUG("server.authserver", "AuthSocket::OnClose");
-}
+ auto self(shared_from_this());
-// Read the packet from the client
-void AuthSocket::OnRead()
-{
- #define MAX_AUTH_LOGON_CHALLENGES_IN_A_ROW 3
- uint32 challengesInARow = 0;
- uint8 _cmd;
- while (1)
+ _socket.async_read_some(boost::asio::buffer(&_readBuffer[bufferOffSet], dataSize), [handler, this, self](boost::system::error_code error, size_t transferedBytes)
{
- if (!socket().recv_soft((char *)&_cmd, 1))
- return;
-
- if (_cmd == AUTH_LOGON_CHALLENGE)
+ if (!error && transferedBytes > 0)
{
- ++challengesInARow;
- if (challengesInARow == MAX_AUTH_LOGON_CHALLENGES_IN_A_ROW)
+ if (!(*this.*handler)())
{
- TC_LOG_WARN("server.authserver", "Got %u AUTH_LOGON_CHALLENGE in a row from '%s', possible ongoing DoS", challengesInARow, socket().getRemoteAddress().c_str());
- socket().shutdown();
+ _socket.close();
return;
}
- }
-
- size_t i;
- // Circle through known commands and call the correct command handler
- for (i = 0; i < AUTH_TOTAL_COMMANDS; ++i)
- {
- if ((uint8)table[i].cmd == _cmd && (table[i].status == STATUS_CONNECTED || (_authed && table[i].status == STATUS_AUTHED)))
- {
- TC_LOG_DEBUG("server.authserver", "Got data for cmd %u recv length %u", (uint32)_cmd, (uint32)socket().recv_len());
-
- if (!(*this.*table[i].handler)())
- {
- TC_LOG_DEBUG("server.authserver", "Command handler failed for cmd %u recv length %u", (uint32)_cmd, (uint32)socket().recv_len());
- return;
- }
- break;
- }
+ AsyncReadHeader();
}
-
- // Report unknown packets in the error log
- if (i == AUTH_TOTAL_COMMANDS)
+ else
{
- TC_LOG_ERROR("server.authserver", "Got unknown packet from '%s'", socket().getRemoteAddress().c_str());
- socket().shutdown();
- return;
+ _socket.close();
}
- }
+ });
}
-// Make the SRP6 calculation from hash in dB
-void AuthSocket::_SetVSFields(const std::string& rI)
+void AuthSession::AsyncWrite(std::size_t length)
{
- s.SetRand(s_BYTE_SIZE * 8);
-
- BigNumber I;
- I.SetHexStr(rI.c_str());
-
- // In case of leading zeros in the rI hash, restore them
- uint8 mDigest[SHA_DIGEST_LENGTH];
- memset(mDigest, 0, SHA_DIGEST_LENGTH);
- if (I.GetNumBytes() <= SHA_DIGEST_LENGTH)
- memcpy(mDigest, I.AsByteArray().get(), I.GetNumBytes());
-
- std::reverse(mDigest, mDigest + SHA_DIGEST_LENGTH);
-
- SHA1Hash sha;
- sha.UpdateData(s.AsByteArray().get(), s.GetNumBytes());
- sha.UpdateData(mDigest, SHA_DIGEST_LENGTH);
- sha.Finalize();
- BigNumber x;
- x.SetBinary(sha.GetDigest(), sha.GetLength());
- v = g.ModExp(x, N);
-
- // No SQL injection (username escaped)
- char *v_hex, *s_hex;
- v_hex = v.AsHexStr();
- s_hex = s.AsHexStr();
-
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_VS);
- stmt->setString(0, v_hex);
- stmt->setString(1, s_hex);
- stmt->setString(2, _login);
- LoginDatabase.Execute(stmt);
-
- OPENSSL_free(v_hex);
- OPENSSL_free(s_hex);
+ boost::asio::async_write(_socket, boost::asio::buffer(_writeBuffer, length), [this](boost::system::error_code error, std::size_t /*length*/)
+ {
+ if (error)
+ {
+ _socket.close();
+ }
+ });
}
-// Logon Challenge command handler
-bool AuthSocket::_HandleLogonChallenge()
+bool AuthSession::_HandleLogonChallenge()
{
- TC_LOG_DEBUG("server.authserver", "Entering _HandleLogonChallenge");
- if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
- return false;
+ sAuthLogonChallenge_C *challenge = (sAuthLogonChallenge_C*)&_readBuffer;
- // Read the first 4 bytes (header) to get the length of the remaining of the packet
- std::vector<uint8> buf;
- buf.resize(4);
-
- socket().recv((char *)&buf[0], 4);
-
- EndianConvertPtr<uint16>(&buf[0]);
-
- uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
- TC_LOG_DEBUG("server.authserver", "[AuthChallenge] got header, body is %#04x bytes", remaining);
-
- if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (socket().recv_len() < remaining))
- return false;
-
- //No big fear of memory outage (size is int16, i.e. < 65536)
- buf.resize(remaining + buf.size() + 1);
- buf[buf.size() - 1] = 0;
- sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[0];
-
- // Read the remaining of the packet
- socket().recv((char *)&buf[4], remaining);
- TC_LOG_DEBUG("server.authserver", "[AuthChallenge] got full packet, %#04x bytes", ch->size);
- TC_LOG_DEBUG("server.authserver", "[AuthChallenge] name(%d): '%s'", ch->I_len, ch->I);
-
- // BigEndian code, nop in little endian case
- // size already converted
- EndianConvertPtr<uint32>(&ch->gamename[0]);
- EndianConvert(ch->build);
- EndianConvertPtr<uint32>(&ch->platform[0]);
- EndianConvertPtr<uint32>(&ch->os[0]);
- EndianConvertPtr<uint32>(&ch->country[0]);
- EndianConvert(ch->timezone_bias);
- EndianConvert(ch->ip);
+ //TC_LOG_DEBUG("server.authserver", "[AuthChallenge] got full packet, %#04x bytes", challenge->size);
+ TC_LOG_DEBUG("server.authserver", "[AuthChallenge] name(%d): '%s'", challenge->I_len, challenge->I);
ByteBuffer pkt;
- _login = (const char*)ch->I;
- _build = ch->build;
+ _login.assign((const char*)challenge->I, challenge->I_len);
+ _build = challenge->build;
_expversion = uint8(AuthHelper::IsPostBCAcceptedClientBuild(_build) ? POST_BC_EXP_FLAG : (AuthHelper::IsPreBCAcceptedClientBuild(_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG));
- _os = (const char*)ch->os;
+ _os = (const char*)challenge->os;
if (_os.size() > 4)
return false;
@@ -368,14 +226,16 @@ bool AuthSocket::_HandleLogonChallenge()
// Verify that this IP is not in the ip_banned table
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS));
- std::string const& ip_address = socket().getRemoteAddress();
+ std::string const& ipAddress = _socket.remote_endpoint().address().to_string();
+ unsigned short port = _socket.remote_endpoint().port();
+
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED);
- stmt->setString(0, ip_address);
+ stmt->setString(0, ipAddress);
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (result)
{
pkt << uint8(WOW_FAIL_BANNED);
- TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] Banned ip tries to login!", socket().getRemoteAddress().c_str(), socket().getRemotePort());
+ TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] Banned ip tries to login!", ipAddress.c_str(), port);
}
else
{
@@ -394,9 +254,9 @@ bool AuthSocket::_HandleLogonChallenge()
if (fields[2].GetUInt8() == 1) // if ip is locked
{
TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account '%s' is locked to IP - '%s'", _login.c_str(), fields[4].GetCString());
- TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Player address is '%s'", ip_address.c_str());
+ TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Player address is '%s'", ipAddress.c_str());
- if (strcmp(fields[4].GetCString(), ip_address.c_str()) != 0)
+ if (strcmp(fields[4].GetCString(), ipAddress.c_str()) != 0)
{
TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account IP differs");
pkt << uint8(WOW_FAIL_LOCKED_ENFORCED);
@@ -413,7 +273,7 @@ bool AuthSocket::_HandleLogonChallenge()
TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account '%s' is not locked to country", _login.c_str());
else if (!accountCountry.empty())
{
- uint32 ip = inet_addr(ip_address.c_str());
+ uint32 ip = inet_addr(ipAddress.c_str());
EndianConvertReverse(ip);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_LOGON_COUNTRY);
@@ -421,7 +281,9 @@ bool AuthSocket::_HandleLogonChallenge()
if (PreparedQueryResult sessionCountryQuery = LoginDatabase.Query(stmt))
{
std::string loginCountry = (*sessionCountryQuery)[0].GetString();
- TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account '%s' is locked to country: '%s' Player country is '%s'", _login.c_str(), accountCountry.c_str(), loginCountry.c_str());
+ TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account '%s' is locked to country: '%s' Player country is '%s'", _login.c_str(),
+ accountCountry.c_str(), loginCountry.c_str());
+
if (loginCountry != accountCountry)
{
TC_LOG_DEBUG("server.authserver", "[AuthChallenge] Account country differs.");
@@ -450,12 +312,14 @@ bool AuthSocket::_HandleLogonChallenge()
if ((*banresult)[0].GetUInt32() == (*banresult)[1].GetUInt32())
{
pkt << uint8(WOW_FAIL_BANNED);
- TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] Banned account %s tried to login!", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str ());
+ TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] Banned account %s tried to login!", ipAddress.c_str(),
+ port, _login.c_str());
}
else
{
pkt << uint8(WOW_FAIL_SUSPENDED);
- TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] Temporarily banned account %s tried to login!", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str ());
+ TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] Temporarily banned account %s tried to login!",
+ ipAddress.c_str(), port, _login.c_str());
}
}
else
@@ -470,8 +334,8 @@ bool AuthSocket::_HandleLogonChallenge()
TC_LOG_DEBUG("network", "database authentication values: v='%s' s='%s'", databaseV.c_str(), databaseS.c_str());
// multiply with 2 since bytes are stored as hexstring
- if (databaseV.size() != s_BYTE_SIZE * 2 || databaseS.size() != s_BYTE_SIZE * 2)
- _SetVSFields(rI);
+ if (databaseV.size() != BYTE_SIZE * 2 || databaseS.size() != BYTE_SIZE * 2)
+ SetVSFields(rI);
else
{
s.SetHexStr(databaseS.c_str());
@@ -533,10 +397,12 @@ bool AuthSocket::_HandleLogonChallenge()
_localizationName.resize(4);
for (int i = 0; i < 4; ++i)
- _localizationName[i] = ch->country[4-i-1];
+ _localizationName[i] = challenge->country[4 - i - 1];
- TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] account %s is using '%c%c%c%c' locale (%u)", socket().getRemoteAddress().c_str(), socket().getRemotePort(),
- _login.c_str (), ch->country[3], ch->country[2], ch->country[1], ch->country[0], GetLocaleByName(_localizationName)
+ TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] account %s is using '%c%c%c%c' locale (%u)",
+ ipAddress.c_str(), port, _login.c_str(),
+ challenge->country[3], challenge->country[2], challenge->country[1], challenge->country[0],
+ GetLocaleByName(_localizationName)
);
}
}
@@ -545,39 +411,38 @@ bool AuthSocket::_HandleLogonChallenge()
pkt << uint8(WOW_FAIL_UNKNOWN_ACCOUNT);
}
- socket().send((char const*)pkt.contents(), pkt.size());
+ std::memcpy(_writeBuffer, (char const*)pkt.contents(), pkt.size());
+
+ AsyncWrite(pkt.size());
+
return true;
}
// Logon Proof command handler
-bool AuthSocket::_HandleLogonProof()
+bool AuthSession::_HandleLogonProof()
{
+
TC_LOG_DEBUG("server.authserver", "Entering _HandleLogonProof");
// Read the packet
- sAuthLogonProof_C lp;
-
- if (!socket().recv((char *)&lp, sizeof(sAuthLogonProof_C)))
- return false;
+ sAuthLogonProof_C *logonProof = (sAuthLogonProof_C*)&_readBuffer;
// If the client has no valid version
if (_expversion == NO_VALID_EXP_FLAG)
{
// Check if we have the appropriate patch on the disk
TC_LOG_DEBUG("network", "Client with invalid version, patching is not implemented");
- socket().shutdown();
- return true;
+ return false;
}
// Continue the SRP6 calculation based on data received from the client
BigNumber A;
- A.SetBinary(lp.A, 32);
+ A.SetBinary(logonProof->A, 32);
// SRP safeguard: abort if A == 0
if (A.isZero())
{
- socket().shutdown();
- return true;
+ return false;
}
SHA1Hash sha;
@@ -645,9 +510,9 @@ bool AuthSocket::_HandleLogonProof()
M.SetBinary(sha.GetDigest(), 20);
// Check if SRP6 results match (password is correct), else send an error
- if (!memcmp(M.AsByteArray().get(), lp.M1, 20))
+ if (!memcmp(M.AsByteArray().get(), logonProof->M1, 20))
{
- TC_LOG_DEBUG("server.authserver", "'%s:%d' User '%s' successfully authenticated", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
+ TC_LOG_DEBUG("server.authserver", "'%s:%d' User '%s' successfully authenticated", GetRemoteIpAddress().c_str(), GetRemotePort(), _login.c_str());
// Update the sessionkey, last_ip, last login time and reset number of failed logins in the account table for this account
// No SQL injection (escaped user name) and IP address as received by socket
@@ -655,7 +520,7 @@ bool AuthSocket::_HandleLogonProof()
PreparedStatement *stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGONPROOF);
stmt->setString(0, K_hex);
- stmt->setString(1, socket().getRemoteAddress().c_str());
+ stmt->setString(1, GetRemoteIpAddress().c_str());
stmt->setUInt32(2, GetLocaleByName(_localizationName));
stmt->setString(3, _os);
stmt->setString(4, _login);
@@ -669,8 +534,11 @@ bool AuthSocket::_HandleLogonProof()
sha.Finalize();
// Check auth token
- if ((lp.securityFlags & 0x04) || !_tokenKey.empty())
+ if ((logonProof->securityFlags & 0x04) || !_tokenKey.empty())
{
+ // TODO To be fixed
+
+ /*
uint8 size;
socket().recv((char*)&size, 1);
char* token = new char[size + 1];
@@ -681,10 +549,10 @@ bool AuthSocket::_HandleLogonProof()
delete[] token;
if (validToken != incomingToken)
{
- char data[] = { AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT, 3, 0 };
- socket().send(data, sizeof(data));
- return false;
- }
+ char data[] = { AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT, 3, 0 };
+ socket().send(data, sizeof(data));
+ return false;
+ }*/
}
if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
@@ -696,7 +564,9 @@ bool AuthSocket::_HandleLogonProof()
proof.unk1 = 0x00800000; // Accountflags. 0x01 = GM, 0x08 = Trial, 0x00800000 = Pro pass (arena tournament)
proof.unk2 = 0x00; // SurveyId
proof.unk3 = 0x00;
- socket().send((char *)&proof, sizeof(proof));
+
+ std::memcpy(_writeBuffer, (char *)&proof, sizeof(proof));
+ AsyncWrite(sizeof(proof));
}
else
{
@@ -705,17 +575,22 @@ bool AuthSocket::_HandleLogonProof()
proof.cmd = AUTH_LOGON_PROOF;
proof.error = 0;
proof.unk2 = 0x00;
- socket().send((char *)&proof, sizeof(proof));
+
+ std::memcpy(_writeBuffer, (char *)&proof, sizeof(proof));
+ AsyncWrite(sizeof(proof));
}
- _authed = true;
+ _isAuthenticated = true;
}
else
{
char data[4] = { AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT, 3, 0 };
- socket().send(data, sizeof(data));
- TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] account %s tried to login with invalid password!", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
+ std::memcpy(_writeBuffer, data, sizeof(data));
+ AsyncWrite(sizeof(data));
+
+ TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] account %s tried to login with invalid password!",
+ GetRemoteIpAddress().c_str(), GetRemotePort(), _login.c_str());
uint32 MaxWrongPassCount = sConfigMgr->GetIntDefault("WrongPass.MaxCount", 0);
@@ -758,17 +633,17 @@ bool AuthSocket::_HandleLogonProof()
LoginDatabase.Execute(stmt);
TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] account %s got banned for '%u' seconds because it failed to authenticate '%u' times",
- socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str(), WrongPassBanTime, failed_logins);
+ GetRemoteIpAddress().c_str(), GetRemotePort(), _login.c_str(), WrongPassBanTime, failed_logins);
}
else
{
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_IP_AUTO_BANNED);
- stmt->setString(0, socket().getRemoteAddress());
+ stmt->setString(0, GetRemoteIpAddress());
stmt->setUInt32(1, WrongPassBanTime);
LoginDatabase.Execute(stmt);
- TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] IP %s got banned for '%u' seconds because account %s failed to authenticate '%u' times",
- socket().getRemoteAddress().c_str(), socket().getRemotePort(), socket().getRemoteAddress().c_str(), WrongPassBanTime, _login.c_str(), failed_logins);
+ TC_LOG_DEBUG("server.authserver", "'%s:%d' [AuthChallenge] IP got banned for '%u' seconds because account %s failed to authenticate '%u' times",
+ GetRemoteIpAddress().c_str(), GetRemotePort(), WrongPassBanTime, _login.c_str(), failed_logins);
}
}
}
@@ -778,38 +653,15 @@ bool AuthSocket::_HandleLogonProof()
return true;
}
-// Reconnect Challenge command handler
-bool AuthSocket::_HandleReconnectChallenge()
+bool AuthSession::_HandleReconnectChallenge()
{
TC_LOG_DEBUG("server.authserver", "Entering _HandleReconnectChallenge");
- if (socket().recv_len() < sizeof(sAuthLogonChallenge_C))
- return false;
-
- // Read the first 4 bytes (header) to get the length of the remaining of the packet
- std::vector<uint8> buf;
- buf.resize(4);
-
- socket().recv((char *)&buf[0], 4);
+ sAuthLogonChallenge_C *challenge = (sAuthLogonChallenge_C*)&_readBuffer;
- EndianConvertPtr<uint16>(&buf[0]);
+ //TC_LOG_DEBUG("server.authserver", "[AuthChallenge] got full packet, %#04x bytes", challenge->size);
+ TC_LOG_DEBUG("server.authserver", "[AuthChallenge] name(%d): '%s'", challenge->I_len, challenge->I);
- uint16 remaining = ((sAuthLogonChallenge_C *)&buf[0])->size;
- TC_LOG_DEBUG("server.authserver", "[ReconnectChallenge] got header, body is %#04x bytes", remaining);
-
- if ((remaining < sizeof(sAuthLogonChallenge_C) - buf.size()) || (socket().recv_len() < remaining))
- return false;
-
- // No big fear of memory outage (size is int16, i.e. < 65536)
- buf.resize(remaining + buf.size() + 1);
- buf[buf.size() - 1] = 0;
- sAuthLogonChallenge_C *ch = (sAuthLogonChallenge_C*)&buf[0];
-
- // Read the remaining of the packet
- socket().recv((char *)&buf[4], remaining);
- TC_LOG_DEBUG("server.authserver", "[ReconnectChallenge] got full packet, %#04x bytes", ch->size);
- TC_LOG_DEBUG("server.authserver", "[ReconnectChallenge] name(%d): '%s'", ch->I_len, ch->I);
-
- _login = (const char*)ch->I;
+ _login.assign((const char*)challenge->I, challenge->I_len);
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_SESSIONKEY);
stmt->setString(0, _login);
@@ -818,15 +670,15 @@ bool AuthSocket::_HandleReconnectChallenge()
// Stop if the account is not found
if (!result)
{
- TC_LOG_ERROR("server.authserver", "'%s:%d' [ERROR] user %s tried to login and we cannot find his session key in the database.", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
- socket().shutdown();
+ TC_LOG_ERROR("server.authserver", "'%s:%d' [ERROR] user %s tried to login and we cannot find his session key in the database.",
+ GetRemoteIpAddress().c_str(), GetRemotePort(), _login.c_str());
return false;
}
// Reinitialize build, expansion and the account securitylevel
- _build = ch->build;
+ _build = challenge->build;
_expversion = uint8(AuthHelper::IsPostBCAcceptedClientBuild(_build) ? POST_BC_EXP_FLAG : (AuthHelper::IsPreBCAcceptedClientBuild(_build) ? PRE_BC_EXP_FLAG : NO_VALID_EXP_FLAG));
- _os = (const char*)ch->os;
+ _os = (const char*)challenge->os;
if (_os.size() > 4)
return false;
@@ -838,7 +690,7 @@ bool AuthSocket::_HandleReconnectChallenge()
uint8 secLevel = fields[2].GetUInt8();
_accountSecurityLevel = secLevel <= SEC_ADMINISTRATOR ? AccountTypes(secLevel) : SEC_ADMINISTRATOR;
- K.SetHexStr ((*result)[0].GetCString());
+ K.SetHexStr((*result)[0].GetCString());
// Sending response
ByteBuffer pkt;
@@ -847,24 +699,22 @@ bool AuthSocket::_HandleReconnectChallenge()
_reconnectProof.SetRand(16 * 8);
pkt.append(_reconnectProof.AsByteArray(16).get(), 16); // 16 bytes random
pkt << uint64(0x00) << uint64(0x00); // 16 bytes zeros
- socket().send((char const*)pkt.contents(), pkt.size());
+
+ std::memcpy(_writeBuffer, (char const*)pkt.contents(), pkt.size());
+ AsyncWrite(pkt.size());
+
return true;
}
-
-// Reconnect Proof command handler
-bool AuthSocket::_HandleReconnectProof()
+bool AuthSession::_HandleReconnectProof()
{
TC_LOG_DEBUG("server.authserver", "Entering _HandleReconnectProof");
- // Read the packet
- sAuthReconnectProof_C lp;
- if (!socket().recv((char *)&lp, sizeof(sAuthReconnectProof_C)))
- return false;
+ sAuthReconnectProof_C *reconnectProof = (sAuthReconnectProof_C*)&_readBuffer;
if (_login.empty() || !_reconnectProof.GetNumBytes() || !K.GetNumBytes())
return false;
BigNumber t1;
- t1.SetBinary(lp.R1, 16);
+ t1.SetBinary(reconnectProof->R1, 16);
SHA1Hash sha;
sha.Initialize();
@@ -872,55 +722,64 @@ bool AuthSocket::_HandleReconnectProof()
sha.UpdateBigNumbers(&t1, &_reconnectProof, &K, NULL);
sha.Finalize();
- if (!memcmp(sha.GetDigest(), lp.R2, SHA_DIGEST_LENGTH))
+ if (!memcmp(sha.GetDigest(), reconnectProof->R2, SHA_DIGEST_LENGTH))
{
// Sending response
ByteBuffer pkt;
pkt << uint8(AUTH_RECONNECT_PROOF);
pkt << uint8(0x00);
pkt << uint16(0x00); // 2 bytes zeros
- socket().send((char const*)pkt.contents(), pkt.size());
- _authed = true;
+ std::memcpy(_writeBuffer, (char const*)pkt.contents(), pkt.size());
+ AsyncWrite(pkt.size());
+ _isAuthenticated = true;
return true;
}
else
{
- TC_LOG_ERROR("server.authserver", "'%s:%d' [ERROR] user %s tried to login, but session is invalid.", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
- socket().shutdown();
+ TC_LOG_ERROR("server.authserver", "'%s:%d' [ERROR] user %s tried to login, but session is invalid.", GetRemoteIpAddress().c_str(),
+ GetRemotePort(), _login.c_str());
return false;
}
}
-ACE_INET_Addr const& AuthSocket::GetAddressForClient(Realm const& realm, ACE_INET_Addr const& clientAddr)
+tcp::endpoint const GetAddressForClient(Realm const& realm, ip::address const& clientAddr)
{
+ ip::address realmIp;
+
// Attempt to send best address for client
if (clientAddr.is_loopback())
{
// Try guessing if realm is also connected locally
if (realm.LocalAddress.is_loopback() || realm.ExternalAddress.is_loopback())
- return clientAddr;
-
- // Assume that user connecting from the machine that authserver is located on
- // has all realms available in his local network
- return realm.LocalAddress;
+ realmIp = clientAddr;
+ else
+ {
+ // Assume that user connecting from the machine that authserver is located on
+ // has all realms available in his local network
+ realmIp = realm.LocalAddress;
+ }
+ }
+ else
+ {
+ if (clientAddr.is_v4() &&
+ (clientAddr.to_v4().to_ulong() & realm.LocalSubnetMask.to_v4().to_ulong()) ==
+ (realm.LocalAddress.to_v4().to_ulong() & realm.LocalSubnetMask.to_v4().to_ulong()))
+ {
+ realmIp = realm.LocalAddress;
+ }
+ else
+ realmIp = realm.ExternalAddress;
}
- // Check if connecting client is in the same network
- if (IsIPAddrInNetwork(realm.LocalAddress, clientAddr, realm.LocalSubnetMask))
- return realm.LocalAddress;
+ tcp::endpoint endpoint(realmIp, realm.port);
// Return external IP
- return realm.ExternalAddress;
+ return endpoint;
}
-// Realm List command handler
-bool AuthSocket::_HandleRealmList()
+bool AuthSession::_HandleRealmList()
{
TC_LOG_DEBUG("server.authserver", "Entering _HandleRealmList");
- if (socket().recv_len() < 5)
- return false;
-
- socket().recv_skip(5);
// Get the user id (else close the connection)
// No SQL injection (prepared statement)
@@ -929,8 +788,8 @@ bool AuthSocket::_HandleRealmList()
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (!result)
{
- TC_LOG_ERROR("server.authserver", "'%s:%d' [ERROR] user %s tried to login but we cannot find him in the database.", socket().getRemoteAddress().c_str(), socket().getRemotePort(), _login.c_str());
- socket().shutdown();
+ TC_LOG_ERROR("server.authserver", "'%s:%d' [ERROR] user %s tried to login but we cannot find him in the database.", GetRemoteIpAddress().c_str(),
+ GetRemotePort(), _login.c_str());
return false;
}
@@ -938,16 +797,13 @@ bool AuthSocket::_HandleRealmList()
uint32 id = fields[0].GetUInt32();
// Update realm list if need
- sRealmList->UpdateIfNeed();
-
- ACE_INET_Addr clientAddr;
- socket().peer().get_remote_addr(clientAddr);
+ sRealmList.UpdateIfNeed();
// Circle through realms in the RealmList and construct the return packet (including # of user characters in each realm)
ByteBuffer pkt;
size_t RealmListSize = 0;
- for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i)
+ for (RealmList::RealmMap::const_iterator i = sRealmList.begin(); i != sRealmList.end(); ++i)
{
const Realm &realm = i->second;
// don't work with realms which not compatible with the client
@@ -975,9 +831,6 @@ bool AuthSocket::_HandleRealmList()
name = ss.str();
}
- // We don't need the port number from which client connects with but the realm's port
- clientAddr.set_port_number(realm.ExternalAddress.get_port_number());
-
uint8 lock = (realm.allowedSecurityLevel > _accountSecurityLevel) ? 1 : 0;
uint8 AmountOfCharacters = 0;
@@ -993,7 +846,7 @@ bool AuthSocket::_HandleRealmList()
pkt << lock; // if 1, then realm locked
pkt << uint8(flag); // RealmFlags
pkt << name;
- pkt << GetAddressString(GetAddressForClient(realm, clientAddr));
+ pkt << boost::lexical_cast<std::string>(GetAddressForClient(realm, _socket.remote_endpoint().address()));
pkt << realm.populationLevel;
pkt << AmountOfCharacters;
pkt << realm.timezone; // realm category
@@ -1038,182 +891,47 @@ bool AuthSocket::_HandleRealmList()
hdr.append(RealmListSizeBuffer); // append RealmList's size buffer
hdr.append(pkt); // append realms in the realmlist
- socket().send((char const*)hdr.contents(), hdr.size());
-
- return true;
-}
-
-// Resume patch transfer
-bool AuthSocket::_HandleXferResume()
-{
- TC_LOG_DEBUG("server.authserver", "Entering _HandleXferResume");
- // Check packet length and patch existence
- if (socket().recv_len() < 9 || !pPatch) // FIXME: pPatch is never used
- {
- TC_LOG_ERROR("server.authserver", "Error while resuming patch transfer (wrong packet)");
- return false;
- }
+ std::memcpy(_writeBuffer, (char const*)hdr.contents(), hdr.size());
+ AsyncWrite(hdr.size());
- // Launch a PatcherRunnable thread starting at given patch file offset
- uint64 start;
- socket().recv_skip(1);
- socket().recv((char*)&start, sizeof(start));
- fseek(pPatch, long(start), 0);
-
- ACE_Based::Thread u(new PatcherRunnable(this));
return true;
}
-// Cancel patch transfer
-bool AuthSocket::_HandleXferCancel()
-{
- TC_LOG_DEBUG("server.authserver", "Entering _HandleXferCancel");
-
- // Close and delete the socket
- socket().recv_skip(1); //clear input buffer
- socket().shutdown();
-
- return true;
-}
-
-// Accept patch transfer
-bool AuthSocket::_HandleXferAccept()
-{
- TC_LOG_DEBUG("server.authserver", "Entering _HandleXferAccept");
-
- // Check packet length and patch existence
- if (!pPatch)
- {
- TC_LOG_ERROR("server.authserver", "Error while accepting patch transfer (wrong packet)");
- return false;
- }
-
- // Launch a PatcherRunnable thread, starting at the beginning of the patch file
- socket().recv_skip(1); // clear input buffer
- fseek(pPatch, 0, 0);
-
- ACE_Based::Thread u(new PatcherRunnable(this));
- return true;
-}
-
-PatcherRunnable::PatcherRunnable(class AuthSocket* as)
-{
- mySocket = as;
-}
-
-// Send content of patch file to the client
-void PatcherRunnable::run() { }
-
-// Preload MD5 hashes of existing patch files on server
-#ifndef _WIN32
-#include <dirent.h>
-#include <errno.h>
-void Patcher::LoadPatchesInfo()
-{
- DIR *dirp;
- struct dirent *dp;
- dirp = opendir("./patches/");
-
- if (!dirp)
- return;
-
- while (dirp)
- {
- errno = 0;
- if ((dp = readdir(dirp)) != NULL)
- {
- int l = strlen(dp->d_name);
-
- if (l < 8)
- continue;
-
- if (!memcmp(&dp->d_name[l - 4], ".mpq", 4))
- LoadPatchMD5(dp->d_name);
- }
- else
- {
- if (errno != 0)
- {
- closedir(dirp);
- return;
- }
- break;
- }
- }
-
- if (dirp)
- closedir(dirp);
-}
-#else
-void Patcher::LoadPatchesInfo()
-{
- WIN32_FIND_DATA fil;
- HANDLE hFil = FindFirstFile("./patches/*.mpq", &fil);
- if (hFil == INVALID_HANDLE_VALUE)
- return; // no patches were found
-
- do
- LoadPatchMD5(fil.cFileName);
- while (FindNextFile(hFil, &fil));
-}
-#endif
-
-// Calculate and store MD5 hash for a given patch file
-void Patcher::LoadPatchMD5(char *szFileName)
+// Make the SRP6 calculation from hash in dB
+void AuthSession::SetVSFields(const std::string& rI)
{
- // Try to open the patch file
- std::string path = "./patches/";
- path += szFileName;
- FILE* pPatch = fopen(path.c_str(), "rb");
- TC_LOG_DEBUG("network", "Loading patch info from %s\n", path.c_str());
-
- if (!pPatch)
- {
- TC_LOG_ERROR("server.authserver", "Error loading patch %s\n", path.c_str());
- return;
- }
-
- // Calculate the MD5 hash
- MD5_CTX ctx;
- MD5_Init(&ctx);
- uint8* buf = new uint8[512 * 1024];
+ s.SetRand(BYTE_SIZE * 8);
- while (!feof(pPatch))
- {
- size_t read = fread(buf, 1, 512 * 1024, pPatch);
- MD5_Update(&ctx, buf, read);
- }
+ BigNumber I;
+ I.SetHexStr(rI.c_str());
- delete [] buf;
- fclose(pPatch);
+ // In case of leading zeros in the rI hash, restore them
+ uint8 mDigest[SHA_DIGEST_LENGTH];
+ memset(mDigest, 0, SHA_DIGEST_LENGTH);
+ if (I.GetNumBytes() <= SHA_DIGEST_LENGTH)
+ memcpy(mDigest, I.AsByteArray().get(), I.GetNumBytes());
- // Store the result in the internal patch hash map
- _patches[path] = new PATCH_INFO;
- MD5_Final((uint8 *)&_patches[path]->md5, &ctx);
-}
+ std::reverse(mDigest, mDigest + SHA_DIGEST_LENGTH);
-// Get cached MD5 hash for a given patch file
-bool Patcher::GetHash(char * pat, uint8 mymd5[16])
-{
- for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
- if (!stricmp(pat, i->first.c_str()))
- {
- memcpy(mymd5, i->second->md5, 16);
- return true;
- }
+ SHA1Hash sha;
+ sha.UpdateData(s.AsByteArray().get(), s.GetNumBytes());
+ sha.UpdateData(mDigest, SHA_DIGEST_LENGTH);
+ sha.Finalize();
+ BigNumber x;
+ x.SetBinary(sha.GetDigest(), sha.GetLength());
+ v = g.ModExp(x, N);
- return false;
-}
+ // No SQL injection (username escaped)
+ char *v_hex, *s_hex;
+ v_hex = v.AsHexStr();
+ s_hex = s.AsHexStr();
-// Launch the patch hashing mechanism on object creation
-Patcher::Patcher()
-{
- LoadPatchesInfo();
-}
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_VS);
+ stmt->setString(0, v_hex);
+ stmt->setString(1, s_hex);
+ stmt->setString(2, _login);
+ LoginDatabase.Execute(stmt);
-// Empty and delete the patch map on termination
-Patcher::~Patcher()
-{
- for (Patches::iterator i = _patches.begin(); i != _patches.end(); ++i)
- delete i->second;
+ OPENSSL_free(v_hex);
+ OPENSSL_free(s_hex);
}
diff --git a/src/server/authserver/Server/AuthSession.h b/src/server/authserver/Server/AuthSession.h
new file mode 100644
index 00000000000..32e81d5240e
--- /dev/null
+++ b/src/server/authserver/Server/AuthSession.h
@@ -0,0 +1,84 @@
+/*
+* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+*
+* 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __AUTHSESSION_H__
+#define __AUTHSESSION_H__
+
+#include <memory>
+#include <boost/asio.hpp>
+#include "Common.h"
+#include "BigNumber.h"
+
+using boost::asio::ip::tcp;
+
+const size_t bufferSize = 4096;
+
+#define BUFFER_SIZE 4096
+
+class AuthSession : public std::enable_shared_from_this < AuthSession >
+{
+public:
+ AuthSession(tcp::socket socket) : _socket(std::move(socket))
+ {
+ N.SetHexStr("894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7");
+ g.SetDword(7);
+ }
+
+ void Start()
+ {
+ AsyncReadHeader();
+ }
+
+ bool _HandleLogonChallenge();
+ bool _HandleLogonProof();
+ bool _HandleReconnectChallenge();
+ bool _HandleReconnectProof();
+ bool _HandleRealmList();
+
+ const std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); };
+ unsigned short GetRemotePort() const { return _socket.remote_endpoint().port(); }
+
+private:
+ void AsyncReadHeader();
+ void AsyncReadData(bool (AuthSession::*handler)(), size_t dataSize, size_t bufferOffset);
+ void AsyncWrite(size_t length);
+
+
+ void SetVSFields(const std::string& rI);
+
+ BigNumber N, s, g, v;
+ BigNumber b, B;
+ BigNumber K;
+ BigNumber _reconnectProof;
+
+ tcp::socket _socket;
+ char _readBuffer[BUFFER_SIZE];
+ char _writeBuffer[BUFFER_SIZE];
+
+ bool _isAuthenticated;
+ std::string _tokenKey;
+ std::string _login;
+ std::string _localizationName;
+ std::string _os;
+ uint16 _build;
+ uint8 _expversion;
+
+ AccountTypes _accountSecurityLevel;
+};
+
+#endif
diff --git a/src/server/authserver/Server/AuthSocket.h b/src/server/authserver/Server/AuthSocket.h
deleted file mode 100644
index 5e04d459ba1..00000000000
--- a/src/server/authserver/Server/AuthSocket.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef _AUTHSOCKET_H
-#define _AUTHSOCKET_H
-
-#include "Common.h"
-#include "BigNumber.h"
-#include "RealmSocket.h"
-
-class ACE_INET_Addr;
-struct Realm;
-
-// Handle login commands
-class AuthSocket: public RealmSocket::Session
-{
-public:
- const static int s_BYTE_SIZE = 32;
-
- AuthSocket(RealmSocket& socket);
- virtual ~AuthSocket(void);
-
- virtual void OnRead(void);
- virtual void OnAccept(void);
- virtual void OnClose(void);
-
- static ACE_INET_Addr const& GetAddressForClient(Realm const& realm, ACE_INET_Addr const& clientAddr);
-
- bool _HandleLogonChallenge();
- bool _HandleLogonProof();
- bool _HandleReconnectChallenge();
- bool _HandleReconnectProof();
- bool _HandleRealmList();
-
- //data transfer handle for patch
- bool _HandleXferResume();
- bool _HandleXferCancel();
- bool _HandleXferAccept();
-
- void _SetVSFields(const std::string& rI);
-
- FILE* pPatch;
- ACE_Thread_Mutex patcherLock;
-
-private:
- RealmSocket& socket_;
- RealmSocket& socket(void) { return socket_; }
-
- BigNumber N, s, g, v;
- BigNumber b, B;
- BigNumber K;
- BigNumber _reconnectProof;
-
- bool _authed;
-
- std::string _login;
- std::string _tokenKey;
-
- // Since GetLocaleByName() is _NOT_ bijective, we have to store the locale as a string. Otherwise we can't differ
- // between enUS and enGB, which is important for the patch system
- std::string _localizationName;
- std::string _os;
- uint16 _build;
- uint8 _expversion;
- AccountTypes _accountSecurityLevel;
-};
-
-#endif
diff --git a/src/server/authserver/Server/RealmAcceptor.h b/src/server/authserver/Server/RealmAcceptor.h
deleted file mode 100644
index e89135c4896..00000000000
--- a/src/server/authserver/Server/RealmAcceptor.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __REALMACCEPTOR_H__
-#define __REALMACCEPTOR_H__
-
-#include <ace/Acceptor.h>
-#include <ace/SOCK_Acceptor.h>
-
-#include "RealmSocket.h"
-#include "AuthSocket.h"
-
-class RealmAcceptor : public ACE_Acceptor<RealmSocket, ACE_SOCK_Acceptor>
-{
-public:
- RealmAcceptor(void) { }
- virtual ~RealmAcceptor(void)
- {
- if (reactor())
- reactor()->cancel_timer(this, 1);
- }
-
-protected:
- virtual int make_svc_handler(RealmSocket* &sh)
- {
- if (sh == 0)
- ACE_NEW_RETURN(sh, RealmSocket, -1);
-
- sh->reactor(reactor());
- sh->set_session(new AuthSocket(*sh));
- return 0;
- }
-
- virtual int handle_timeout(const ACE_Time_Value& /*current_time*/, const void* /*act = 0*/)
- {
- TC_LOG_DEBUG("server.authserver", "Resuming acceptor");
- reactor()->cancel_timer(this, 1);
- return reactor()->register_handler(this, ACE_Event_Handler::ACCEPT_MASK);
- }
-
- virtual int handle_accept_error(void)
- {
-#if defined(ENFILE) && defined(EMFILE)
- if (errno == ENFILE || errno == EMFILE)
- {
- TC_LOG_ERROR("server.authserver", "Out of file descriptors, suspending incoming connections for 10 seconds");
- reactor()->remove_handler(this, ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL);
- reactor()->schedule_timer(this, NULL, ACE_Time_Value(10));
- }
-#endif
- return 0;
- }
-};
-
-#endif
diff --git a/src/server/authserver/Server/RealmSocket.cpp b/src/server/authserver/Server/RealmSocket.cpp
deleted file mode 100644
index 1013639cc50..00000000000
--- a/src/server/authserver/Server/RealmSocket.cpp
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#include <ace/OS_NS_string.h>
-#include <ace/INET_Addr.h>
-#include <ace/SString.h>
-
-#include "RealmSocket.h"
-#include "Log.h"
-
-RealmSocket::Session::Session(void) { }
-
-RealmSocket::Session::~Session(void) { }
-
-RealmSocket::RealmSocket(void) :
- input_buffer_(4096), session_(NULL),
- _remoteAddress(), _remotePort(0)
-{
- reference_counting_policy().value(ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
-
- msg_queue()->high_water_mark(8 * 1024 * 1024);
- msg_queue()->low_water_mark(8 * 1024 * 1024);
-}
-
-RealmSocket::~RealmSocket(void)
-{
- if (msg_queue())
- msg_queue()->close();
-
- // delete RealmSocketObject must never be called from our code.
- closing_ = true;
-
- delete session_;
-
- peer().close();
-}
-
-int RealmSocket::open(void * arg)
-{
- ACE_INET_Addr addr;
-
- if (peer().get_remote_addr(addr) == -1)
- {
- TC_LOG_ERROR("server.authserver", "Error %s while opening realm socket!", ACE_OS::strerror(errno));
- return -1;
- }
-
- _remoteAddress = addr.get_host_addr();
- _remotePort = addr.get_port_number();
-
- // Register with ACE Reactor
- if (Base::open(arg) == -1)
- return -1;
-
- if (session_)
- session_->OnAccept();
-
- // reactor takes care of the socket from now on
- remove_reference();
-
- return 0;
-}
-
-int RealmSocket::close(u_long)
-{
- shutdown();
-
- closing_ = true;
-
- remove_reference();
-
- return 0;
-}
-
-const std::string& RealmSocket::getRemoteAddress(void) const
-{
- return _remoteAddress;
-}
-
-uint16 RealmSocket::getRemotePort(void) const
-{
- return _remotePort;
-}
-
-size_t RealmSocket::recv_len(void) const
-{
- return input_buffer_.length();
-}
-
-bool RealmSocket::recv_soft(char *buf, size_t len)
-{
- if (input_buffer_.length() < len)
- return false;
-
- ACE_OS::memcpy(buf, input_buffer_.rd_ptr(), len);
-
- return true;
-}
-
-bool RealmSocket::recv(char *buf, size_t len)
-{
- bool ret = recv_soft(buf, len);
-
- if (ret)
- recv_skip(len);
-
- return ret;
-}
-
-void RealmSocket::recv_skip(size_t len)
-{
- input_buffer_.rd_ptr(len);
-}
-
-ssize_t RealmSocket::noblk_send(ACE_Message_Block &message_block)
-{
- const size_t len = message_block.length();
-
- if (len == 0)
- return -1;
-
- // Try to send the message directly.
-#ifdef MSG_NOSIGNAL
- ssize_t n = peer().send(message_block.rd_ptr(), len, MSG_NOSIGNAL);
-#else
- ssize_t n = peer().send(message_block.rd_ptr(), len);
-#endif // MSG_NOSIGNAL
-
- if (n < 0)
- {
- if (errno == EWOULDBLOCK) // Blocking signal
- return 0;
- else // Error happened
- return -1;
- }
- else if (n == 0)
- {
- // Can this happen ?
- return -1;
- }
-
- // return bytes transmitted
- return n;
-}
-
-bool RealmSocket::send(const char *buf, size_t len)
-{
- if (buf == NULL || len == 0)
- return true;
-
- ACE_Data_Block db(len, ACE_Message_Block::MB_DATA, (const char*)buf, 0, 0, ACE_Message_Block::DONT_DELETE, 0);
- ACE_Message_Block message_block(&db, ACE_Message_Block::DONT_DELETE, 0);
-
- message_block.wr_ptr(len);
-
- if (msg_queue()->is_empty())
- {
- // Try to send it directly.
- ssize_t n = noblk_send(message_block);
-
- if (n < 0)
- return false;
-
- size_t un = size_t(n);
- if (un == len)
- return true;
-
- // fall down
- message_block.rd_ptr(un);
- }
-
- ACE_Message_Block* mb = message_block.clone();
-
- if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value *)(&ACE_Time_Value::zero)) == -1)
- {
- mb->release();
- return false;
- }
-
- if (reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
- return false;
-
- return true;
-}
-
-int RealmSocket::handle_output(ACE_HANDLE)
-{
- if (closing_)
- return -1;
-
- ACE_Message_Block* mb = 0;
-
- if (msg_queue()->is_empty())
- {
- reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
- return 0;
- }
-
- if (msg_queue()->dequeue_head(mb, (ACE_Time_Value *)(&ACE_Time_Value::zero)) == -1)
- return -1;
-
- ssize_t n = noblk_send(*mb);
-
- if (n < 0)
- {
- mb->release();
- return -1;
- }
- else if (size_t(n) == mb->length())
- {
- mb->release();
- return 1;
- }
- else
- {
- mb->rd_ptr(n);
-
- if (msg_queue()->enqueue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
- {
- mb->release();
- return -1;
- }
-
- return 0;
- }
-
- ACE_NOTREACHED(return -1);
-}
-
-int RealmSocket::handle_close(ACE_HANDLE h, ACE_Reactor_Mask)
-{
- // As opposed to WorldSocket::handle_close, we don't need locks here.
- closing_ = true;
-
- if (h == ACE_INVALID_HANDLE)
- peer().close_writer();
-
- if (session_)
- session_->OnClose();
-
- reactor()->remove_handler(this, ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::ALL_EVENTS_MASK);
- return 0;
-}
-
-int RealmSocket::handle_input(ACE_HANDLE)
-{
- if (closing_)
- return -1;
-
- const ssize_t space = input_buffer_.space();
-
- ssize_t n = peer().recv(input_buffer_.wr_ptr(), space);
-
- if (n < 0)
- return errno == EWOULDBLOCK ? 0 : -1;
- else if (n == 0) // EOF
- return -1;
-
- input_buffer_.wr_ptr((size_t)n);
-
- if (session_ != NULL)
- {
- session_->OnRead();
- input_buffer_.crunch();
- }
-
- // return 1 in case there is more data to read from OS
- return n == space ? 1 : 0;
-}
-
-void RealmSocket::set_session(Session* session)
-{
- delete session_;
-
- session_ = session;
-}
diff --git a/src/server/authserver/Server/RealmSocket.h b/src/server/authserver/Server/RealmSocket.h
deleted file mode 100644
index c1190d638b3..00000000000
--- a/src/server/authserver/Server/RealmSocket.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __REALMSOCKET_H__
-#define __REALMSOCKET_H__
-
-#include <ace/Synch_Traits.h>
-#include <ace/Svc_Handler.h>
-#include <ace/SOCK_Stream.h>
-#include <ace/Message_Block.h>
-#include <ace/Basic_Types.h>
-#include "Common.h"
-
-class RealmSocket : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
-{
-private:
- typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> Base;
-
-public:
- class Session
- {
- public:
- Session(void);
- virtual ~Session(void);
-
- virtual void OnRead(void) = 0;
- virtual void OnAccept(void) = 0;
- virtual void OnClose(void) = 0;
- };
-
- RealmSocket(void);
- virtual ~RealmSocket(void);
-
- size_t recv_len(void) const;
- bool recv_soft(char *buf, size_t len);
- bool recv(char *buf, size_t len);
- void recv_skip(size_t len);
-
- bool send(const char *buf, size_t len);
-
- const std::string& getRemoteAddress(void) const;
-
- uint16 getRemotePort(void) const;
-
- virtual int open(void *);
-
- virtual int close(u_long);
-
- virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE);
- virtual int handle_output(ACE_HANDLE = ACE_INVALID_HANDLE);
-
- virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
-
- void set_session(Session* session);
-
-private:
- ssize_t noblk_send(ACE_Message_Block &message_block);
-
- ACE_Message_Block input_buffer_;
- Session* session_;
- std::string _remoteAddress;
- uint16 _remotePort;
-};
-
-#endif /* __REALMSOCKET_H__ */
diff --git a/src/server/collision/BoundingIntervalHierarchy.h b/src/server/collision/BoundingIntervalHierarchy.h
index 4d38bfc18c4..491a299ca68 100644
--- a/src/server/collision/BoundingIntervalHierarchy.h
+++ b/src/server/collision/BoundingIntervalHierarchy.h
@@ -177,7 +177,7 @@ class BIH
{
uint32 tn = tree[node];
uint32 axis = (tn & (3 << 30)) >> 30;
- bool BVH2 = tn & (1 << 29);
+ bool BVH2 = (tn & (1 << 29)) != 0;
int offset = tn & ~(7 << 29);
if (!BVH2)
{
@@ -271,7 +271,7 @@ class BIH
{
uint32 tn = tree[node];
uint32 axis = (tn & (3 << 30)) >> 30;
- bool BVH2 = tn & (1 << 29);
+ bool BVH2 = (tn & (1 << 29)) != 0;
int offset = tn & ~(7 << 29);
if (!BVH2)
{
diff --git a/src/server/collision/Management/VMapManager2.cpp b/src/server/collision/Management/VMapManager2.cpp
index 813a3c04288..2aa3b6ab40d 100644
--- a/src/server/collision/Management/VMapManager2.cpp
+++ b/src/server/collision/Management/VMapManager2.cpp
@@ -18,6 +18,7 @@
#include <iostream>
#include <iomanip>
+#include <mutex>
#include <string>
#include <sstream>
#include "VMapManager2.h"
@@ -252,7 +253,7 @@ namespace VMAP
WorldModel* VMapManager2::acquireModelInstance(const std::string& basepath, const std::string& filename)
{
//! Critical section, thread safe access to iLoadedModelFiles
- TRINITY_GUARD(ACE_Thread_Mutex, LoadedModelFilesLock);
+ std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
if (model == iLoadedModelFiles.end())
@@ -275,7 +276,7 @@ namespace VMAP
void VMapManager2::releaseModelInstance(const std::string &filename)
{
//! Critical section, thread safe access to iLoadedModelFiles
- TRINITY_GUARD(ACE_Thread_Mutex, LoadedModelFilesLock);
+ std::lock_guard<std::mutex> lock(LoadedModelFilesLock);
ModelFileMap::iterator model = iLoadedModelFiles.find(filename);
if (model == iLoadedModelFiles.end())
diff --git a/src/server/collision/Management/VMapManager2.h b/src/server/collision/Management/VMapManager2.h
index 711025e67c0..03de6951d5d 100644
--- a/src/server/collision/Management/VMapManager2.h
+++ b/src/server/collision/Management/VMapManager2.h
@@ -19,10 +19,10 @@
#ifndef _VMAPMANAGER2_H
#define _VMAPMANAGER2_H
+#include <mutex>
+#include <unordered_map>
#include "Define.h"
#include "IVMapManager.h"
-#include <unordered_map>
-#include <ace/Thread_Mutex.h>
//===========================================================
@@ -73,7 +73,7 @@ namespace VMAP
ModelFileMap iLoadedModelFiles;
InstanceTreeMap iInstanceMapTrees;
// Mutex for iLoadedModelFiles
- ACE_Thread_Mutex LoadedModelFilesLock;
+ std::mutex LoadedModelFilesLock;
bool _loadMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY);
/* void _unloadMap(uint32 pMapId, uint32 x, uint32 y); */
diff --git a/src/server/collision/Models/ModelInstance.cpp b/src/server/collision/Models/ModelInstance.cpp
index 3262c154965..475984c4fd3 100644
--- a/src/server/collision/Models/ModelInstance.cpp
+++ b/src/server/collision/Models/ModelInstance.cpp
@@ -167,7 +167,7 @@ namespace VMAP
check += fread(&spawn.iPos, sizeof(float), 3, rf);
check += fread(&spawn.iRot, sizeof(float), 3, rf);
check += fread(&spawn.iScale, sizeof(float), 1, rf);
- bool has_bound = (spawn.flags & MOD_HAS_BOUND);
+ bool has_bound = (spawn.flags & MOD_HAS_BOUND) != 0;
if (has_bound) // only WMOs have bound in MPQ, only available after computation
{
Vector3 bLow, bHigh;
@@ -206,7 +206,7 @@ namespace VMAP
check += fwrite(&spawn.iPos, sizeof(float), 3, wf);
check += fwrite(&spawn.iRot, sizeof(float), 3, wf);
check += fwrite(&spawn.iScale, sizeof(float), 1, wf);
- bool has_bound = (spawn.flags & MOD_HAS_BOUND);
+ bool has_bound = (spawn.flags & MOD_HAS_BOUND) != 0;
if (has_bound) // only WMOs have bound in MPQ, only available after computation
{
check += fwrite(&spawn.iBound.low(), sizeof(float), 3, wf);
diff --git a/src/server/collision/VMapDefinitions.h b/src/server/collision/VMapDefinitions.h
index 0bc74df51ec..8cd965ddffd 100644
--- a/src/server/collision/VMapDefinitions.h
+++ b/src/server/collision/VMapDefinitions.h
@@ -19,6 +19,7 @@
#ifndef _VMAPDEFINITIONS_H
#define _VMAPDEFINITIONS_H
#include <cstring>
+#include <cstdio>
#define LIQUID_TILE_SIZE (533.333f / 128.f)
diff --git a/src/server/game/AI/CreatureAIFactory.h b/src/server/game/AI/CreatureAIFactory.h
index fc2d009e673..f2854f1a9ce 100644
--- a/src/server/game/AI/CreatureAIFactory.h
+++ b/src/server/game/AI/CreatureAIFactory.h
@@ -49,7 +49,6 @@ CreatureAIFactory<REAL_AI>::Create(void* data) const
typedef FactoryHolder<CreatureAI> CreatureAICreator;
typedef FactoryHolder<CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
-typedef FactoryHolder<CreatureAI>::FactoryHolderRepository CreatureAIRepository;
//GO
struct SelectableGameObjectAI : public FactoryHolder<GameObjectAI>, public Permissible<GameObject>
@@ -77,5 +76,4 @@ GameObjectAIFactory<REAL_GO_AI>::Create(void* data) const
typedef FactoryHolder<GameObjectAI> GameObjectAICreator;
typedef FactoryHolder<GameObjectAI>::FactoryHolderRegistry GameObjectAIRegistry;
-typedef FactoryHolder<GameObjectAI>::FactoryHolderRepository GameObjectAIRepository;
#endif
diff --git a/src/server/game/AI/CreatureAISelector.cpp b/src/server/game/AI/CreatureAISelector.cpp
index 473af0d787e..afbd306c184 100644
--- a/src/server/game/AI/CreatureAISelector.cpp
+++ b/src/server/game/AI/CreatureAISelector.cpp
@@ -31,7 +31,7 @@ namespace FactorySelector
CreatureAI* selectAI(Creature* creature)
{
const CreatureAICreator* ai_factory = NULL;
- CreatureAIRegistry& ai_registry(*CreatureAIRepository::instance());
+ CreatureAIRegistry& ai_registry(*CreatureAIRegistry::instance());
if (creature->IsPet())
ai_factory = ai_registry.GetRegistryItem("PetAI");
@@ -101,7 +101,7 @@ namespace FactorySelector
MovementGenerator* selectMovementGenerator(Creature* creature)
{
- MovementGeneratorRegistry& mv_registry(*MovementGeneratorRepository::instance());
+ MovementGeneratorRegistry& mv_registry(*MovementGeneratorRegistry::instance());
ASSERT(creature->GetCreatureTemplate());
const MovementGeneratorCreator* mv_factory = mv_registry.GetRegistryItem(creature->GetDefaultMovementType());
@@ -130,7 +130,7 @@ namespace FactorySelector
GameObjectAI* SelectGameObjectAI(GameObject* go)
{
const GameObjectAICreator* ai_factory = NULL;
- GameObjectAIRegistry& ai_registry(*GameObjectAIRepository::instance());
+ GameObjectAIRegistry& ai_registry(*GameObjectAIRegistry::instance());
// scriptname in db
if (GameObjectAI* scriptedAI = sScriptMgr->GetGameObjectAI(go))
diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp
index 302adda0c8e..6e0de858561 100644
--- a/src/server/game/Achievements/AchievementMgr.cpp
+++ b/src/server/game/Achievements/AchievementMgr.cpp
@@ -425,7 +425,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
{
time_t birthday_start = time_t(sWorld->getIntConfig(CONFIG_BIRTHDAY_TIME));
tm birthday_tm;
- ACE_OS::localtime_r(&birthday_start, &birthday_tm);
+ localtime_r(&birthday_start, &birthday_tm);
// exactly N birthday
birthday_tm.tm_year += birthday_login.nth_birthday;
diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp
index e4522536a81..9e1514f11bd 100644
--- a/src/server/game/Events/GameEventMgr.cpp
+++ b/src/server/game/Events/GameEventMgr.cpp
@@ -1163,7 +1163,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element %i (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element %i (size: %zu)",
internal_event_id, mGameEventCreatureGuids.size());
return;
}
@@ -1190,7 +1190,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventGameobjectGuids.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element %i (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element %i (size: %zu)",
internal_event_id, mGameEventGameobjectGuids.size());
return;
}
@@ -1223,7 +1223,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventPoolIds.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventPoolIds element %u (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventPoolIds element %u (size: %zu)",
internal_event_id, mGameEventPoolIds.size());
return;
}
@@ -1238,7 +1238,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventCreatureGuids element %i (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventCreatureGuids element %i (size: %zu)",
internal_event_id, mGameEventCreatureGuids.size());
return;
}
@@ -1260,7 +1260,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventGameobjectGuids.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventGameobjectGuids element %i (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventGameobjectGuids element %i (size: %zu)",
internal_event_id, mGameEventGameobjectGuids.size());
return;
}
@@ -1281,7 +1281,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
}
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventPoolIds.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventPoolIds element %u (size: " SIZEFMTD ")", internal_event_id, mGameEventPoolIds.size());
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventPoolIds element %u (size: %zu)", internal_event_id, mGameEventPoolIds.size());
return;
}
@@ -1600,14 +1600,14 @@ void GameEventMgr::RunSmartAIScripts(uint16 event_id, bool activate)
//! Iterate over every supported source type (creature and gameobject)
//! Not entirely sure how this will affect units in non-loaded grids.
{
- TRINITY_READ_GUARD(HashMapHolder<Creature>::LockType, *HashMapHolder<Creature>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Creature>::GetLock());
HashMapHolder<Creature>::MapType const& m = ObjectAccessor::GetCreatures();
for (HashMapHolder<Creature>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
if (iter->second->IsInWorld())
iter->second->AI()->sOnGameEvent(activate, event_id);
}
{
- TRINITY_READ_GUARD(HashMapHolder<GameObject>::LockType, *HashMapHolder<GameObject>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<GameObject>::GetLock());
HashMapHolder<GameObject>::MapType const& m = ObjectAccessor::GetGameObjects();
for (HashMapHolder<GameObject>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
if (iter->second->IsInWorld())
diff --git a/src/server/game/Globals/ObjectAccessor.cpp b/src/server/game/Globals/ObjectAccessor.cpp
index 8bf353d3eaa..ec33d8efbe1 100644
--- a/src/server/game/Globals/ObjectAccessor.cpp
+++ b/src/server/game/Globals/ObjectAccessor.cpp
@@ -16,6 +16,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/locks.hpp>
+
#include "ObjectAccessor.h"
#include "CellImpl.h"
#include "Corpse.h"
@@ -205,7 +208,8 @@ Unit* ObjectAccessor::FindUnit(uint64 guid)
Player* ObjectAccessor::FindPlayerByName(std::string const& name)
{
- TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
+
std::string nameStr = name;
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
HashMapHolder<Player>::MapType const& m = GetPlayers();
@@ -224,7 +228,8 @@ Player* ObjectAccessor::FindPlayerByName(std::string const& name)
void ObjectAccessor::SaveAllPlayers()
{
- TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
+
HashMapHolder<Player>::MapType const& m = GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
itr->second->SaveToDB();
@@ -232,7 +237,7 @@ void ObjectAccessor::SaveAllPlayers()
Corpse* ObjectAccessor::GetCorpseForPlayerGUID(uint64 guid)
{
- TRINITY_READ_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
+ boost::shared_lock<boost::shared_mutex> lock(_corpseLock);
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
if (iter == i_player2corpse.end())
@@ -247,6 +252,8 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse)
{
ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
+ boost::upgrade_lock<boost::shared_mutex> lock(_corpseLock);
+
/// @todo more works need to be done for corpse and other world object
if (Map* map = corpse->FindMap())
{
@@ -265,7 +272,7 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse)
// Critical section
{
- TRINITY_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
+ boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGUID());
if (iter == i_player2corpse.end()) /// @todo Fix this
@@ -285,7 +292,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
// Critical section
{
- TRINITY_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
+ boost::unique_lock<boost::shared_mutex> lock(_corpseLock);
ASSERT(i_player2corpse.find(corpse->GetOwnerGUID()) == i_player2corpse.end());
i_player2corpse[corpse->GetOwnerGUID()] = corpse;
@@ -298,7 +305,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
void ObjectAccessor::AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map)
{
- TRINITY_READ_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
+ boost::shared_lock<boost::shared_mutex> lock(_corpseLock);
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
{
@@ -431,8 +438,8 @@ void ObjectAccessor::UnloadAll()
/// Define the static members of HashMapHolder
-template <class T> std::unordered_map< uint64, T* > HashMapHolder<T>::m_objectMap;
-template <class T> typename HashMapHolder<T>::LockType HashMapHolder<T>::i_lock;
+template <class T> std::unordered_map< uint64, T* > HashMapHolder<T>::_objectMap;
+template <class T> boost::shared_mutex HashMapHolder<T>::_lock;
/// Global definitions for the hashmap storage
diff --git a/src/server/game/Globals/ObjectAccessor.h b/src/server/game/Globals/ObjectAccessor.h
index b52699c85ac..79799cec55f 100644
--- a/src/server/game/Globals/ObjectAccessor.h
+++ b/src/server/game/Globals/ObjectAccessor.h
@@ -19,17 +19,17 @@
#ifndef TRINITY_OBJECTACCESSOR_H
#define TRINITY_OBJECTACCESSOR_H
-#include "Define.h"
-#include <ace/Singleton.h>
-#include <ace/Thread_Mutex.h>
+#include <mutex>
+#include <set>
#include <unordered_map>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
-#include "UpdateData.h"
-
+#include "Define.h"
#include "GridDefines.h"
+#include "UpdateData.h"
#include "Object.h"
-#include <set>
class Creature;
class Corpse;
@@ -48,42 +48,41 @@ class HashMapHolder
public:
typedef std::unordered_map<uint64, T*> MapType;
- typedef ACE_RW_Thread_Mutex LockType;
static void Insert(T* o)
{
- TRINITY_WRITE_GUARD(LockType, i_lock);
- m_objectMap[o->GetGUID()] = o;
+ boost::shared_lock<boost::shared_mutex> lock(_lock);
+
+ _objectMap[o->GetGUID()] = o;
}
static void Remove(T* o)
{
- TRINITY_WRITE_GUARD(LockType, i_lock);
- m_objectMap.erase(o->GetGUID());
+ boost::unique_lock<boost::shared_mutex> lock(_lock);
+ _objectMap.erase(o->GetGUID());
}
static T* Find(uint64 guid)
{
- TRINITY_READ_GUARD(LockType, i_lock);
- typename MapType::iterator itr = m_objectMap.find(guid);
- return (itr != m_objectMap.end()) ? itr->second : NULL;
+ boost::shared_lock<boost::shared_mutex> lock(_lock);
+ typename MapType::iterator itr = _objectMap.find(guid);
+ return (itr != _objectMap.end()) ? itr->second : NULL;
}
- static MapType& GetContainer() { return m_objectMap; }
+ static MapType& GetContainer() { return _objectMap; }
- static LockType* GetLock() { return &i_lock; }
+ static boost::shared_mutex* GetLock() { return &_lock; }
private:
//Non instanceable only static
HashMapHolder() { }
- static LockType i_lock;
- static MapType m_objectMap;
+ static boost::shared_mutex _lock;
+ static MapType _objectMap;
};
class ObjectAccessor
{
- friend class ACE_Singleton<ObjectAccessor, ACE_Null_Mutex>;
private:
ObjectAccessor();
~ObjectAccessor();
@@ -93,6 +92,12 @@ class ObjectAccessor
public:
/// @todo: Override these template functions for each holder type and add assertions
+ static ObjectAccessor* instance()
+ {
+ static ObjectAccessor *instance = new ObjectAccessor();
+ return instance;
+ }
+
template<class T> static T* GetObjectInOrOutOfWorld(uint64 guid, T* /*typeSpecifier*/)
{
return HashMapHolder<T>::Find(guid);
@@ -195,13 +200,13 @@ class ObjectAccessor
//non-static functions
void AddUpdateObject(Object* obj)
{
- TRINITY_GUARD(ACE_Thread_Mutex, i_objectLock);
+ std::lock_guard<std::mutex> lock(_objectLock);
i_objects.insert(obj);
}
void RemoveUpdateObject(Object* obj)
{
- TRINITY_GUARD(ACE_Thread_Mutex, i_objectLock);
+ std::lock_guard<std::mutex> lock(_objectLock);
i_objects.erase(obj);
}
@@ -228,9 +233,9 @@ class ObjectAccessor
std::set<Object*> i_objects;
Player2CorpsesMapType i_player2corpse;
- ACE_Thread_Mutex i_objectLock;
- ACE_RW_Thread_Mutex i_corpseLock;
+ std::mutex _objectLock;
+ boost::shared_mutex _corpseLock;
};
-#define sObjectAccessor ACE_Singleton<ObjectAccessor, ACE_Null_Mutex>::instance()
+#define sObjectAccessor ObjectAccessor::instance()
#endif
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 72ea1b16864..db97ea270ef 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -5347,7 +5347,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
time_t curTime = time(NULL);
tm lt;
- ACE_OS::localtime_r(&curTime, &lt);
+ localtime_r(&curTime, &lt);
uint64 basetime(curTime);
TC_LOG_INFO("misc", "Returning mails current time: hour: %d, minute: %d, second: %d ", lt.tm_hour, lt.tm_min, lt.tm_sec);
diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp
index c4ff2581e75..baa20f76a40 100644
--- a/src/server/game/Handlers/MiscHandler.cpp
+++ b/src/server/game/Handlers/MiscHandler.cpp
@@ -255,7 +255,8 @@ void WorldSession::HandleWhoOpcode(WorldPacket& recvData)
data << uint32(matchcount); // placeholder, count of players matching criteria
data << uint32(displaycount); // placeholder, count of players displayed
- TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
+
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
diff --git a/src/server/game/Instances/InstanceSaveMgr.h b/src/server/game/Instances/InstanceSaveMgr.h
index 4f1b576cae6..98b37386a3f 100644
--- a/src/server/game/Instances/InstanceSaveMgr.h
+++ b/src/server/game/Instances/InstanceSaveMgr.h
@@ -19,12 +19,12 @@
#ifndef _INSTANCESAVEMGR_H
#define _INSTANCESAVEMGR_H
-#include "Define.h"
-#include <ace/Singleton.h>
-#include <ace/Thread_Mutex.h>
#include <list>
#include <map>
+#include <mutex>
#include <unordered_map>
+
+#include "Define.h"
#include "DatabaseEnv.h"
#include "DBCEnums.h"
#include "ObjectDefines.h"
@@ -80,13 +80,18 @@ class InstanceSave
/* online players bound to the instance (perm/solo)
does not include the members of the group unless they have permanent saves */
- void AddPlayer(Player* player) { TRINITY_GUARD(ACE_Thread_Mutex, _lock); m_playerList.push_back(player); }
+ void AddPlayer(Player* player)
+ {
+ std::lock_guard<std::mutex> lock(_playerListLock);
+ m_playerList.push_back(player);
+ }
+
bool RemovePlayer(Player* player)
{
- _lock.acquire();
+ _playerListLock.lock();
m_playerList.remove(player);
bool isStillValid = UnloadIfEmpty();
- _lock.release();
+ _playerListLock.unlock();
//delete here if needed, after releasing the lock
if (m_toDelete)
@@ -137,14 +142,13 @@ class InstanceSave
bool m_canReset;
bool m_toDelete;
- ACE_Thread_Mutex _lock;
+ std::mutex _playerListLock;
};
typedef std::unordered_map<uint32 /*PAIR32(map, difficulty)*/, time_t /*resetTime*/> ResetTimeByMapDifficultyMap;
class InstanceSaveManager
{
- friend class ACE_Singleton<InstanceSaveManager, ACE_Thread_Mutex>;
friend class InstanceSave;
private:
@@ -154,6 +158,12 @@ class InstanceSaveManager
public:
typedef std::unordered_map<uint32 /*InstanceId*/, InstanceSave*> InstanceSaveHashMap;
+ static InstanceSaveManager* instance()
+ {
+ static InstanceSaveManager *instance = new InstanceSaveManager();
+ return instance;
+ }
+
/* resetTime is a global propery of each (raid/heroic) map
all instances of that map reset at the same time */
struct InstResetEvent
@@ -221,5 +231,5 @@ class InstanceSaveManager
ResetTimeQueue m_resetTimeQueue;
};
-#define sInstanceSaveMgr ACE_Singleton<InstanceSaveManager, ACE_Thread_Mutex>::instance()
+#define sInstanceSaveMgr InstanceSaveManager::instance()
#endif
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 01e3af149dc..bdf42a26320 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -382,7 +382,7 @@ void Map::DeleteFromWorld(Player* player)
void Map::EnsureGridCreated(const GridCoord &p)
{
- TRINITY_GUARD(ACE_Thread_Mutex, GridLock);
+ std::lock_guard<std::mutex> lock(_gridLock);
EnsureGridCreated_i(p);
}
@@ -2894,7 +2894,7 @@ bool InstanceMap::AddPlayerToMap(Player* player)
// Is it needed?
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapLock);
// Check moved to void WorldSession::HandleMoveWorldportAckOpcode()
//if (!CanEnter(player))
//return false;
@@ -3235,7 +3235,7 @@ bool BattlegroundMap::CanEnter(Player* player)
bool BattlegroundMap::AddPlayerToMap(Player* player)
{
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapLock);
//Check moved to void WorldSession::HandleMoveWorldportAckOpcode()
//if (!CanEnter(player))
//return false;
diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h
index a2d88905f50..27c290264b2 100644
--- a/src/server/game/Maps/Map.h
+++ b/src/server/game/Maps/Map.h
@@ -574,8 +574,8 @@ class Map : public GridRefManager<NGridType>
protected:
void SetUnloadReferenceLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); }
- ACE_Thread_Mutex Lock;
- ACE_Thread_Mutex GridLock;
+ std::mutex _mapLock;
+ std::mutex _gridLock;
MapEntry const* i_mapEntry;
uint8 i_spawnMode;
diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp
index e914a5c3eee..498c669ba01 100644
--- a/src/server/game/Maps/MapInstanced.cpp
+++ b/src/server/game/Maps/MapInstanced.cpp
@@ -187,7 +187,7 @@ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player)
InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save, Difficulty difficulty)
{
// load/create a map
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapLock);
// make sure we have a valid map id
const MapEntry* entry = sMapStore.LookupEntry(GetId());
@@ -223,7 +223,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save,
BattlegroundMap* MapInstanced::CreateBattleground(uint32 InstanceId, Battleground* bg)
{
// load/create a map
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapLock);
TC_LOG_DEBUG("maps", "MapInstanced::CreateBattleground: map bg %d for %d created.", InstanceId, GetId());
diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp
index d8c8889da67..2b8dbde8280 100644
--- a/src/server/game/Maps/MapManager.cpp
+++ b/src/server/game/Maps/MapManager.cpp
@@ -68,7 +68,7 @@ Map* MapManager::CreateBaseMap(uint32 id)
if (map == NULL)
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapsLock);
MapEntry const* entry = sMapStore.LookupEntry(id);
ASSERT(entry);
@@ -302,7 +302,7 @@ void MapManager::UnloadAll()
uint32 MapManager::GetNumInstances()
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapsLock);
uint32 ret = 0;
for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
@@ -319,7 +319,7 @@ uint32 MapManager::GetNumInstances()
uint32 MapManager::GetNumPlayersInInstances()
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapsLock);
uint32 ret = 0;
for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h
index b7fb0617a46..91becb88dfe 100644
--- a/src/server/game/Maps/MapManager.h
+++ b/src/server/game/Maps/MapManager.h
@@ -141,7 +141,7 @@ class MapManager
MapManager(const MapManager &);
MapManager& operator=(const MapManager &);
- ACE_Thread_Mutex Lock;
+ std::mutex _mapsLock;
uint32 i_gridCleanUpDelay;
MapMapType i_maps;
IntervalTimer i_timer;
diff --git a/src/server/game/Maps/MapUpdater.cpp b/src/server/game/Maps/MapUpdater.cpp
index dd697719d54..2a6b810fcef 100644
--- a/src/server/game/Maps/MapUpdater.cpp
+++ b/src/server/game/Maps/MapUpdater.cpp
@@ -1,10 +1,30 @@
+/*
+* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+*
+* 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 <http://www.gnu.org/licenses/>.
+*/
+
+#include <mutex>
+#include <condition_variable>
+#include <ace/Method_Request.h>
+
#include "MapUpdater.h"
#include "DelayExecutor.h"
#include "Map.h"
#include "DatabaseEnv.h"
-#include <ace/Guard_T.h>
-#include <ace/Method_Request.h>
class MapUpdateRequest : public ACE_Method_Request
{
@@ -29,8 +49,7 @@ class MapUpdateRequest : public ACE_Method_Request
}
};
-MapUpdater::MapUpdater():
-m_executor(), m_mutex(), m_condition(m_mutex), pending_requests(0) { }
+MapUpdater::MapUpdater(): m_executor(), pending_requests(0) { }
MapUpdater::~MapUpdater()
{
@@ -51,17 +70,19 @@ int MapUpdater::deactivate()
int MapUpdater::wait()
{
- TRINITY_GUARD(ACE_Thread_Mutex, m_mutex);
+ std::unique_lock<std::mutex> lock(_lock);
while (pending_requests > 0)
- m_condition.wait();
+ _condition.wait(lock);
+
+ lock.unlock();
return 0;
}
int MapUpdater::schedule_update(Map& map, ACE_UINT32 diff)
{
- TRINITY_GUARD(ACE_Thread_Mutex, m_mutex);
+ std::lock_guard<std::mutex> lock(_lock);
++pending_requests;
@@ -83,7 +104,7 @@ bool MapUpdater::activated()
void MapUpdater::update_finished()
{
- TRINITY_GUARD(ACE_Thread_Mutex, m_mutex);
+ std::lock_guard<std::mutex> lock(_lock);
if (pending_requests == 0)
{
@@ -93,5 +114,5 @@ void MapUpdater::update_finished()
--pending_requests;
- m_condition.broadcast();
+ _condition.notify_all();
}
diff --git a/src/server/game/Maps/MapUpdater.h b/src/server/game/Maps/MapUpdater.h
index 89798026339..8461b53e992 100644
--- a/src/server/game/Maps/MapUpdater.h
+++ b/src/server/game/Maps/MapUpdater.h
@@ -1,8 +1,26 @@
+/*
+* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
+* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+*
+* 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 <http://www.gnu.org/licenses/>.
+*/
+
#ifndef _MAP_UPDATER_H_INCLUDED
#define _MAP_UPDATER_H_INCLUDED
-#include <ace/Thread_Mutex.h>
-#include <ace/Condition_Thread_Mutex.h>
+#include <mutex>
+#include <condition_variable>
#include "DelayExecutor.h"
@@ -30,8 +48,8 @@ class MapUpdater
private:
DelayExecutor m_executor;
- ACE_Thread_Mutex m_mutex;
- ACE_Condition_Thread_Mutex m_condition;
+ std::mutex _lock;
+ std::condition_variable _condition;
size_t pending_requests;
void update_finished();
diff --git a/src/server/game/Movement/MovementGenerator.h b/src/server/game/Movement/MovementGenerator.h
index f545f9fd314..5c74bef8d8c 100755
--- a/src/server/game/Movement/MovementGenerator.h
+++ b/src/server/game/Movement/MovementGenerator.h
@@ -92,5 +92,4 @@ struct MovementGeneratorFactory : public SelectableMovement
typedef FactoryHolder<MovementGenerator, MovementGeneratorType> MovementGeneratorCreator;
typedef FactoryHolder<MovementGenerator, MovementGeneratorType>::FactoryHolderRegistry MovementGeneratorRegistry;
-typedef FactoryHolder<MovementGenerator, MovementGeneratorType>::FactoryHolderRepository MovementGeneratorRepository;
#endif
diff --git a/src/server/game/PrecompiledHeaders/gamePCH.h b/src/server/game/PrecompiledHeaders/gamePCH.h
index 68f628430c4..d389c4b360c 100644
--- a/src/server/game/PrecompiledHeaders/gamePCH.h
+++ b/src/server/game/PrecompiledHeaders/gamePCH.h
@@ -1,9 +1,7 @@
//add here most rarely modified headers to speed up debug build compilation
-#include "WorldSocket.h" // must be first to make ACE happy with ACE includes in it
-
#include "Common.h"
-
+#include "WorldSocket.h"
#include "MapManager.h"
#include "Log.h"
#include "ObjectAccessor.h"
diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h
index 3422934fcd9..099a270e886 100644
--- a/src/server/game/Server/WorldSession.h
+++ b/src/server/game/Server/WorldSession.h
@@ -1010,7 +1010,7 @@ class WorldSession
AddonsList m_addonsList;
uint32 recruiterId;
bool isRecruiter;
- ACE_Based::LockedQueue<WorldPacket*, ACE_Thread_Mutex> _recvQueue;
+ LockedQueue<WorldPacket*> _recvQueue;
rbac::RBACData* _RBACData;
uint32 expireTime;
bool forceExit;
diff --git a/src/server/game/Server/WorldSocketMgr.cpp b/src/server/game/Server/WorldSocketMgr.cpp
index 7880552ffa1..3c1db3551d0 100644
--- a/src/server/game/Server/WorldSocketMgr.cpp
+++ b/src/server/game/Server/WorldSocketMgr.cpp
@@ -29,13 +29,13 @@
#include <ace/Reactor_Impl.h>
#include <ace/TP_Reactor.h>
#include <ace/Dev_Poll_Reactor.h>
-#include <ace/Guard_T.h>
#include <ace/Atomic_Op.h>
#include <ace/os_include/arpa/os_inet.h>
#include <ace/os_include/netinet/os_tcp.h>
#include <ace/os_include/sys/os_types.h>
#include <ace/os_include/sys/os_socket.h>
+#include <mutex>
#include <set>
#include "Log.h"
@@ -109,7 +109,7 @@ class ReactorRunnable : protected ACE_Task_Base
int AddSocket (WorldSocket* sock)
{
- TRINITY_GUARD(ACE_Thread_Mutex, m_NewSockets_Lock);
+ std::lock_guard<std::mutex> lock(newSocketsLock);
++m_Connections;
sock->AddReference();
@@ -130,7 +130,7 @@ class ReactorRunnable : protected ACE_Task_Base
void AddNewSockets()
{
- TRINITY_GUARD(ACE_Thread_Mutex, m_NewSockets_Lock);
+ std::lock_guard<std::mutex> lock(newSocketsLock);
if (m_NewSockets.empty())
return;
@@ -208,7 +208,7 @@ class ReactorRunnable : protected ACE_Task_Base
SocketSet m_Sockets;
SocketSet m_NewSockets;
- ACE_Thread_Mutex m_NewSockets_Lock;
+ std::mutex newSocketsLock;
};
WorldSocketMgr::WorldSocketMgr() :
diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp
index 8d39f553910..dea7dfa6819 100644
--- a/src/server/game/Weather/Weather.cpp
+++ b/src/server/game/Weather/Weather.cpp
@@ -94,7 +94,7 @@ bool Weather::ReGenerate()
// season source http://aa.usno.navy.mil/data/docs/EarthSeasons.html
time_t gtime = sWorld->GetGameTime();
struct tm ltime;
- ACE_OS::localtime_r(&gtime, &ltime);
+ localtime_r(&gtime, &ltime);
uint32 season = ((ltime.tm_yday - 78 + 365)/91)%4;
static char const* seasonName[WEATHER_SEASONS] = { "spring", "summer", "fall", "winter" };
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index b643d127c04..e5b207d9b46 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -1749,7 +1749,7 @@ void World::SetInitialWorldSettings()
//one second is 1000 -(tested on win system)
/// @todo Get rid of magic numbers
tm localTm;
- ACE_OS::localtime_r(&m_gameTime, &localTm);
+ localtime_r(&m_gameTime, &localTm);
mail_timer = ((((localTm.tm_hour + 20) % 24)* HOUR * IN_MILLISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval());
//1440
mail_timer_expires = ((DAY * IN_MILLISECONDS) / (m_timers[WUPDATE_AUCTIONS].GetInterval()));
@@ -2779,7 +2779,7 @@ void World::InitDailyQuestResetTime()
// FIX ME: client not show day start time
time_t curTime = time(NULL);
tm localTm;
- ACE_OS::localtime_r(&curTime, &localTm);
+ localtime_r(&curTime, &localTm);
localTm.tm_hour = 6;
localTm.tm_min = 0;
localTm.tm_sec = 0;
@@ -2813,7 +2813,7 @@ void World::InitRandomBGResetTime()
// generate time by config
time_t curTime = time(NULL);
tm localTm;
- ACE_OS::localtime_r(&curTime, &localTm);
+ localtime_r(&curTime, &localTm);
localTm.tm_hour = getIntConfig(CONFIG_RANDOM_BG_RESET_HOUR);
localTm.tm_min = 0;
localTm.tm_sec = 0;
@@ -2841,7 +2841,7 @@ void World::InitGuildResetTime()
// generate time by config
time_t curTime = time(NULL);
tm localTm;
- ACE_OS::localtime_r(&curTime, &localTm);
+ localtime_r(&curTime, &localTm);
localTm.tm_hour = getIntConfig(CONFIG_GUILD_RESET_HOUR);
localTm.tm_min = 0;
localTm.tm_sec = 0;
@@ -2926,7 +2926,7 @@ void World::ResetMonthlyQuests()
// generate time
time_t curTime = time(NULL);
tm localTm;
- ACE_OS::localtime_r(&curTime, &localTm);
+ localtime_r(&curTime, &localTm);
int month = localTm.tm_mon;
int year = localTm.tm_year;
diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h
index efd7570992a..f5c0dd1cb8f 100644
--- a/src/server/game/World/World.h
+++ b/src/server/game/World/World.h
@@ -810,7 +810,7 @@ class World
static int32 m_visibility_notify_periodInBGArenas;
// CLI command holder to be thread safe
- ACE_Based::LockedQueue<CliCommandHolder*, ACE_Thread_Mutex> cliCmdQueue;
+ LockedQueue<CliCommandHolder*> cliCmdQueue;
// next daily quests and random bg reset time
time_t m_NextDailyQuestReset;
@@ -824,7 +824,7 @@ class World
// sessions that are added async
void AddSession_(WorldSession* s);
- ACE_Based::LockedQueue<WorldSession*, ACE_Thread_Mutex> addSessQueue;
+ LockedQueue<WorldSession*> addSessQueue;
// used versions
std::string m_DBVersion;
diff --git a/src/server/scripts/Commands/cs_ban.cpp b/src/server/scripts/Commands/cs_ban.cpp
index afaf5f651bc..45875623b22 100644
--- a/src/server/scripts/Commands/cs_ban.cpp
+++ b/src/server/scripts/Commands/cs_ban.cpp
@@ -457,7 +457,7 @@ public:
{
time_t timeBan = time_t(fields2[0].GetUInt32());
tm tmBan;
- ACE_OS::localtime_r(&timeBan, &tmBan);
+ localtime_r(&timeBan, &tmBan);
if (fields2[0].GetUInt32() == fields2[1].GetUInt32())
{
@@ -469,7 +469,7 @@ public:
{
time_t timeUnban = time_t(fields2[1].GetUInt32());
tm tmUnban;
- ACE_OS::localtime_r(&timeUnban, &tmUnban);
+ localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
accountName.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
@@ -546,7 +546,7 @@ public:
{
time_t timeBan = time_t(banFields[0].GetUInt32());
tm tmBan;
- ACE_OS::localtime_r(&timeBan, &tmBan);
+ localtime_r(&timeBan, &tmBan);
if (banFields[0].GetUInt32() == banFields[1].GetUInt32())
{
@@ -558,7 +558,7 @@ public:
{
time_t timeUnban = time_t(banFields[1].GetUInt32());
tm tmUnban;
- ACE_OS::localtime_r(&timeUnban, &tmUnban);
+ localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
char_name.c_str(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
@@ -627,7 +627,7 @@ public:
Field* fields = result->Fetch();
time_t timeBan = time_t(fields[1].GetUInt32());
tm tmBan;
- ACE_OS::localtime_r(&timeBan, &tmBan);
+ localtime_r(&timeBan, &tmBan);
if (fields[1].GetUInt32() == fields[2].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
@@ -638,7 +638,7 @@ public:
{
time_t timeUnban = time_t(fields[2].GetUInt32());
tm tmUnban;
- ACE_OS::localtime_r(&timeUnban, &tmUnban);
+ localtime_r(&timeUnban, &tmUnban);
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
fields[0].GetCString(), tmBan.tm_year%100, tmBan.tm_mon+1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year%100, tmUnban.tm_mon+1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp
index f18f9b4499c..d0050a0d4fd 100644
--- a/src/server/scripts/Commands/cs_debug.cpp
+++ b/src/server/scripts/Commands/cs_debug.cpp
@@ -745,14 +745,14 @@ public:
if (item->GetOwnerGUID() != player->GetGUID())
{
- handler->PSendSysMessage("queue(" SIZEFMTD "): For the item with guid %d, the owner's guid (%d) and the player's guid (%d) don't match!", i, item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()), player->GetGUIDLow());
+ handler->PSendSysMessage("queue(%zu): For the item with guid %d, the owner's guid (%d) and the player's guid (%d) don't match!", i, item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()), player->GetGUIDLow());
error = true;
continue;
}
if (item->GetQueuePos() != i)
{
- handler->PSendSysMessage("queue(" SIZEFMTD "): For the item with guid %d, the queuepos doesn't match it's position in the queue!", i, item->GetGUIDLow());
+ handler->PSendSysMessage("queue(%zu): For the item with guid %d, the queuepos doesn't match it's position in the queue!", i, item->GetGUIDLow());
error = true;
continue;
}
@@ -764,14 +764,14 @@ public:
if (test == NULL)
{
- handler->PSendSysMessage("queue(" SIZEFMTD "): The bag(%d) and slot(%d) values for the item with guid %d are incorrect, the player doesn't have any item at that position!", i, item->GetBagSlot(), item->GetSlot(), item->GetGUIDLow());
+ handler->PSendSysMessage("queue(%zu): The bag(%d) and slot(%d) values for the item with guid %d are incorrect, the player doesn't have any item at that position!", i, item->GetBagSlot(), item->GetSlot(), item->GetGUIDLow());
error = true;
continue;
}
if (test != item)
{
- handler->PSendSysMessage("queue(" SIZEFMTD "): The bag(%d) and slot(%d) values for the item with guid %d are incorrect, an item which guid is %d is there instead!", i, item->GetBagSlot(), item->GetSlot(), item->GetGUIDLow(), test->GetGUIDLow());
+ handler->PSendSysMessage("queue(%zu): The bag(%d) and slot(%d) values for the item with guid %d are incorrect, an item which guid is %d is there instead!", i, item->GetBagSlot(), item->GetSlot(), item->GetGUIDLow(), test->GetGUIDLow());
error = true;
continue;
}
diff --git a/src/server/scripts/Commands/cs_gm.cpp b/src/server/scripts/Commands/cs_gm.cpp
index a2c0861c113..90fd0bdd71c 100644
--- a/src/server/scripts/Commands/cs_gm.cpp
+++ b/src/server/scripts/Commands/cs_gm.cpp
@@ -123,7 +123,7 @@ public:
bool first = true;
bool footer = false;
- TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
diff --git a/src/server/scripts/Commands/cs_mmaps.cpp b/src/server/scripts/Commands/cs_mmaps.cpp
index d89edd4d925..0be5994e8ed 100644
--- a/src/server/scripts/Commands/cs_mmaps.cpp
+++ b/src/server/scripts/Commands/cs_mmaps.cpp
@@ -98,7 +98,7 @@ public:
Movement::PointsArray const& pointPath = path.GetPath();
handler->PSendSysMessage("%s's path to %s:", target->GetName().c_str(), player->GetName().c_str());
handler->PSendSysMessage("Building: %s", useStraightPath ? "StraightPath" : "SmoothPath");
- handler->PSendSysMessage("Result: %s - Length: " SIZEFMTD " - Type: %u", (result ? "true" : "false"), pointPath.size(), path.GetPathType());
+ handler->PSendSysMessage("Result: %s - Length: %zu - Type: %u", (result ? "true" : "false"), pointPath.size(), path.GetPathType());
G3D::Vector3 const &start = path.GetStartPosition();
G3D::Vector3 const &end = path.GetEndPosition();
@@ -273,7 +273,7 @@ public:
if (!creatureList.empty())
{
- handler->PSendSysMessage("Found " SIZEFMTD " Creatures.", creatureList.size());
+ handler->PSendSysMessage("Found %zu Creatures.", creatureList.size());
uint32 paths = 0;
uint32 uStartTime = getMSTime();
diff --git a/src/server/scripts/Commands/cs_reset.cpp b/src/server/scripts/Commands/cs_reset.cpp
index d61c36c887f..279f9c2ef4c 100644
--- a/src/server/scripts/Commands/cs_reset.cpp
+++ b/src/server/scripts/Commands/cs_reset.cpp
@@ -297,7 +297,7 @@ public:
stmt->setUInt16(0, uint16(atLogin));
CharacterDatabase.Execute(stmt);
- TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
HashMapHolder<Player>::MapType const& plist = sObjectAccessor->GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
itr->second->SetAtLoginFlag(atLogin);
diff --git a/src/server/shared/Common.h b/src/server/shared/Common.h
index f49bbf0bada..8cab769ec8a 100644
--- a/src/server/shared/Common.h
+++ b/src/server/shared/Common.h
@@ -79,22 +79,12 @@
#include <sstream>
#include <algorithm>
-#include "Threading/LockedQueue.h"
-#include "Threading/Threading.h"
+#include "Debugging/Errors.h"
-#include <ace/Basic_Types.h>
-#include <ace/Guard_T.h>
-#include <ace/RW_Thread_Mutex.h>
-#include <ace/Thread_Mutex.h>
-#include <ace/OS_NS_time.h>
+#include "Threading/LockedQueue.h"
#if PLATFORM == PLATFORM_WINDOWS
-# include <ace/config-all.h>
-// XP winver - needed to compile with standard leak check in MemoryLeaks.h
-// uncomment later if needed
-//#define _WIN32_WINNT 0x0501
# include <ws2tcpip.h>
-//#undef WIN32_WINNT
#else
# include <sys/types.h>
# include <sys/ioctl.h>
@@ -123,8 +113,6 @@
inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
-#define atol(a) strtoul( a, NULL, 10)
-
#define STRINGIZE(a) #a
enum TimeConstants
@@ -187,20 +175,4 @@ typedef std::vector<std::string> StringVector;
#define MAX_QUERY_LEN 32*1024
-#define TRINITY_GUARD(MUTEX, LOCK) \
- ACE_Guard< MUTEX > TRINITY_GUARD_OBJECT (LOCK); \
- if (TRINITY_GUARD_OBJECT.locked() == 0) ASSERT(false);
-
-//! For proper implementation of multiple-read, single-write pattern, use
-//! ACE_RW_Mutex as underlying @MUTEX
-# define TRINITY_WRITE_GUARD(MUTEX, LOCK) \
- ACE_Write_Guard< MUTEX > TRINITY_GUARD_OBJECT (LOCK); \
- if (TRINITY_GUARD_OBJECT.locked() == 0) ASSERT(false);
-
-//! For proper implementation of multiple-read, single-write pattern, use
-//! ACE_RW_Mutex as underlying @MUTEX
-# define TRINITY_READ_GUARD(MUTEX, LOCK) \
- ACE_Read_Guard< MUTEX > TRINITY_GUARD_OBJECT (LOCK); \
- if (TRINITY_GUARD_OBJECT.locked() == 0) ASSERT(false);
-
#endif
diff --git a/src/server/shared/Configuration/Config.cpp b/src/server/shared/Configuration/Config.cpp
index 3f8997e6d55..9e0e57eb198 100644
--- a/src/server/shared/Configuration/Config.cpp
+++ b/src/server/shared/Configuration/Config.cpp
@@ -16,57 +16,41 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <algorithm>
+#include <mutex>
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/ini_parser.hpp>
#include "Config.h"
#include "Errors.h"
-// Defined here as it must not be exposed to end-users.
-bool ConfigMgr::GetValueHelper(const char* name, ACE_TString &result)
-{
- GuardType guard(_configLock);
-
- if (_config.get() == 0)
- return false;
-
- ACE_TString section_name;
- ACE_Configuration_Section_Key section_key;
- const ACE_Configuration_Section_Key &root_key = _config->root_section();
-
- int i = 0;
- while (_config->enumerate_sections(root_key, i, section_name) == 0)
- {
- _config->open_section(root_key, section_name.c_str(), 0, section_key);
- if (_config->get_string_value(section_key, name, result) == 0)
- return true;
- ++i;
- }
-
- return false;
-}
+using namespace boost::property_tree;
bool ConfigMgr::LoadInitial(char const* file)
{
ASSERT(file);
- GuardType guard(_configLock);
+ std::lock_guard<std::mutex> lock(_configLock);
_filename = file;
- _config.reset(new ACE_Configuration_Heap());
- if (_config->open() == 0)
- if (LoadData(_filename.c_str()))
- return true;
- _config.reset();
- return false;
-}
-
-bool ConfigMgr::LoadMore(char const* file)
-{
- ASSERT(file);
- ASSERT(_config);
+ try
+ {
+ ptree fullTree;
+ boost::property_tree::ini_parser::read_ini(file, fullTree);
- GuardType guard(_configLock);
+ // Since we're using only one section per config file, we skip the section and have direct property access
+ for (auto section : fullTree)
+ {
+ _config = section.second;
+ break;
+ }
+ }
+ catch (std::exception const& /*ex*/)
+ {
+ return false;
+ }
- return LoadData(file);
+ return true;
}
bool ConfigMgr::Reload()
@@ -74,78 +58,58 @@ bool ConfigMgr::Reload()
return LoadInitial(_filename.c_str());
}
-bool ConfigMgr::LoadData(char const* file)
+std::string ConfigMgr::GetStringDefault(const char* name, const std::string &def)
{
- ACE_Ini_ImpExp config_importer(*_config.get());
- if (config_importer.import_config(file) == 0)
- return true;
+ std::string value = _config.get<std::string>(ptree::path_type(name,'/'), def);
- return false;
-}
+ value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
-std::string ConfigMgr::GetStringDefault(const char* name, const std::string &def)
-{
- ACE_TString val;
- return GetValueHelper(name, val) ? val.c_str() : def;
+ return value;
}
bool ConfigMgr::GetBoolDefault(const char* name, bool def)
{
- ACE_TString val;
-
- if (!GetValueHelper(name, val))
+ try
+ {
+ std::string val = _config.get<std::string>(name);
+ val.erase(std::remove(val.begin(), val.end(), '"'), val.end());
+ return (val == "true" || val == "TRUE" || val == "yes" || val == "YES" || val == "1");
+ }
+ catch (std::exception const& /*ex*/)
+ {
return def;
-
- return (val == "true" || val == "TRUE" || val == "yes" || val == "YES" ||
- val == "1");
+ }
}
int ConfigMgr::GetIntDefault(const char* name, int def)
{
- ACE_TString val;
- return GetValueHelper(name, val) ? atoi(val.c_str()) : def;
+ return _config.get<int>(name, def);
}
float ConfigMgr::GetFloatDefault(const char* name, float def)
{
- ACE_TString val;
- return GetValueHelper(name, val) ? (float)atof(val.c_str()) : def;
+ return _config.get<float>(name, def);
}
std::string const& ConfigMgr::GetFilename()
{
- GuardType guard(_configLock);
+ std::lock_guard<std::mutex> lock(_configLock);
return _filename;
}
std::list<std::string> ConfigMgr::GetKeysByString(std::string const& name)
{
- GuardType guard(_configLock);
+ std::lock_guard<std::mutex> lock(_configLock);
std::list<std::string> keys;
- if (_config.get() == 0)
- return keys;
- ACE_TString section_name;
- ACE_Configuration_Section_Key section_key;
- const ACE_Configuration_Section_Key &root_key = _config->root_section();
-
- int i = 0;
- while (_config->enumerate_sections(root_key, i++, section_name) == 0)
+ for (const ptree::value_type& child : _config)
{
- _config->open_section(root_key, section_name.c_str(), 0, section_key);
-
- ACE_TString key_name;
- ACE_Configuration::VALUETYPE type;
- int j = 0;
- while (_config->enumerate_values(section_key, j++, key_name, type) == 0)
+ if (child.first.compare(0, name.length(), name) == 0)
{
- std::string temp = key_name.c_str();
-
- if (!temp.find(name))
- keys.push_back(temp);
+ keys.push_back(child.first);
}
}
-
+
return keys;
}
diff --git a/src/server/shared/Configuration/Config.h b/src/server/shared/Configuration/Config.h
index 4693b21a0c7..d05a083d166 100644
--- a/src/server/shared/Configuration/Config.h
+++ b/src/server/shared/Configuration/Config.h
@@ -21,18 +21,11 @@
#include <string>
#include <list>
-#include <ace/Singleton.h>
-#include <ace/Configuration_Import_Export.h>
-#include <ace/Thread_Mutex.h>
-#include <AutoPtr.h>
-
-typedef Trinity::AutoPtr<ACE_Configuration_Heap, ACE_Null_Mutex> Config;
+#include <mutex>
+#include <boost/property_tree/ptree.hpp>
class ConfigMgr
{
- friend class ACE_Singleton<ConfigMgr, ACE_Null_Mutex>;
- friend class ConfigLoader;
-
ConfigMgr() { }
~ConfigMgr() { }
@@ -40,13 +33,11 @@ public:
/// Method used only for loading main configuration files (authserver.conf and worldserver.conf)
bool LoadInitial(char const* file);
- /**
- * This method loads additional configuration files
- * It is recommended to use this method in WorldScript::OnConfigLoad hooks
- *
- * @return true if loading was successful
- */
- bool LoadMore(char const* file);
+ static ConfigMgr* instance()
+ {
+ static ConfigMgr *instance = new ConfigMgr();
+ return instance;
+ }
bool Reload();
@@ -59,20 +50,14 @@ public:
std::list<std::string> GetKeysByString(std::string const& name);
private:
- bool GetValueHelper(const char* name, ACE_TString &result);
- bool LoadData(char const* file);
-
- typedef ACE_Thread_Mutex LockType;
- typedef ACE_Guard<LockType> GuardType;
-
std::string _filename;
- Config _config;
- LockType _configLock;
+ boost::property_tree::ptree _config;
+ std::mutex _configLock;
ConfigMgr(ConfigMgr const&);
ConfigMgr& operator=(ConfigMgr const&);
};
-#define sConfigMgr ACE_Singleton<ConfigMgr, ACE_Null_Mutex>::instance()
+#define sConfigMgr ConfigMgr::instance()
#endif
diff --git a/src/server/shared/Cryptography/BigNumber.cpp b/src/server/shared/Cryptography/BigNumber.cpp
index 1f3fc96e28d..c5e0635c5ec 100644
--- a/src/server/shared/Cryptography/BigNumber.cpp
+++ b/src/server/shared/Cryptography/BigNumber.cpp
@@ -16,13 +16,11 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <ace/Guard_T.h>
-
#include "Cryptography/BigNumber.h"
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <algorithm>
-#include <ace/Auto_Ptr.h>
+#include <memory>
BigNumber::BigNumber()
: _bn(BN_new())
@@ -170,7 +168,7 @@ bool BigNumber::isZero() const
return BN_is_zero(_bn);
}
-ACE_Auto_Array_Ptr<uint8> BigNumber::AsByteArray(int32 minSize, bool littleEndian)
+std::unique_ptr<uint8[]> BigNumber::AsByteArray(int32 minSize, bool littleEndian)
{
int length = (minSize >= GetNumBytes()) ? minSize : GetNumBytes();
@@ -186,7 +184,7 @@ ACE_Auto_Array_Ptr<uint8> BigNumber::AsByteArray(int32 minSize, bool littleEndia
if (littleEndian)
std::reverse(array, array + length);
- ACE_Auto_Array_Ptr<uint8> ret(array);
+ std::unique_ptr<uint8[]> ret(array);
return ret;
}
diff --git a/src/server/shared/Cryptography/BigNumber.h b/src/server/shared/Cryptography/BigNumber.h
index dc553babec9..848b3da3e2d 100644
--- a/src/server/shared/Cryptography/BigNumber.h
+++ b/src/server/shared/Cryptography/BigNumber.h
@@ -19,8 +19,9 @@
#ifndef _AUTH_BIGNUMBER_H
#define _AUTH_BIGNUMBER_H
+#include <memory>
#include "Define.h"
-#include <ace/Auto_Ptr.h>
+
struct bignum_st;
@@ -87,7 +88,7 @@ class BigNumber
uint32 AsDword();
- ACE_Auto_Array_Ptr<uint8> AsByteArray(int32 minSize = 0, bool littleEndian = true);
+ std::unique_ptr<uint8[]> AsByteArray(int32 minSize = 0, bool littleEndian = true);
char * AsHexStr() const;
char * AsDecStr() const;
diff --git a/src/server/shared/Database/MySQLThreading.h b/src/server/shared/Database/MySQLThreading.h
index 0f6af8ace20..da234138879 100644
--- a/src/server/shared/Database/MySQLThreading.h
+++ b/src/server/shared/Database/MySQLThreading.h
@@ -23,31 +23,6 @@
class MySQL
{
public:
- /*! Create a thread on the MySQL server to mirrior the calling thread,
- initializes thread-specific variables and allows thread-specific
- operations without concurrence from other threads.
- This should only be called if multiple core threads are running
- on the same MySQL connection. Seperate MySQL connections implicitly
- create a mirror thread.
- */
- static void Thread_Init()
- {
- mysql_thread_init();
- TC_LOG_WARN("sql.sql", "Core thread with ID [" UI64FMTD "] initializing MySQL thread.",
- (uint64)ACE_Based::Thread::currentId());
- }
-
- /*! Shuts down MySQL thread and frees resources, should only be called
- when we terminate. MySQL threads and connections are not configurable
- during runtime.
- */
- static void Thread_End()
- {
- mysql_thread_end();
- TC_LOG_WARN("sql.sql", "Core thread with ID [" UI64FMTD "] shutting down MySQL thread.",
- (uint64)ACE_Based::Thread::currentId());
- }
-
static void Library_Init()
{
mysql_library_init(-1, NULL, NULL);
@@ -59,4 +34,4 @@ class MySQL
}
};
-#endif \ No newline at end of file
+#endif
diff --git a/src/server/shared/Define.h b/src/server/shared/Define.h
index e43853e5bb0..2258456e1a1 100644
--- a/src/server/shared/Define.h
+++ b/src/server/shared/Define.h
@@ -19,23 +19,26 @@
#ifndef TRINITY_DEFINE_H
#define TRINITY_DEFINE_H
-#include "CompilerDefs.h"
-
-#include <ace/Basic_Types.h>
-#include <ace/ACE_export.h>
+#if COMPILER_GNU == COMPILER_GNU
+# if !defined(__STDC_FORMAT_MACROS)
+# define __STDC_FORMAT_MACROS
+# endif
+#endif
#include <cstddef>
+#include <cinttypes>
+#include "CompilerDefs.h"
#define TRINITY_LITTLEENDIAN 0
#define TRINITY_BIGENDIAN 1
#if !defined(TRINITY_ENDIAN)
-# if defined (ACE_BIG_ENDIAN)
+# if defined (BOOST_BIG_ENDIAN)
# define TRINITY_ENDIAN TRINITY_BIGENDIAN
-# else //ACE_BYTE_ORDER != ACE_BIG_ENDIAN
+# else
# define TRINITY_ENDIAN TRINITY_LITTLEENDIAN
-# endif //ACE_BYTE_ORDER
-#endif //TRINITY_ENDIAN
+# endif
+#endif
#if PLATFORM == PLATFORM_WINDOWS
# define TRINITY_PATH_MAX MAX_PATH
@@ -70,21 +73,19 @@
# define ATTR_DEPRECATED
#endif //COMPILER == COMPILER_GNU
-#define UI64FMTD ACE_UINT64_FORMAT_SPECIFIER
-#define UI64LIT(N) ACE_UINT64_LITERAL(N)
-
-#define SI64FMTD ACE_INT64_FORMAT_SPECIFIER
-#define SI64LIT(N) ACE_INT64_LITERAL(N)
+#define UI64FMTD PRIu64
+#define UI64LIT(N) UINT64_C(N)
-#define SIZEFMTD ACE_SIZE_T_FORMAT_SPECIFIER
+#define SI64FMTD PRId64
+#define SI64LIT(N) INT64_C(N)
-typedef ACE_INT64 int64;
-typedef ACE_INT32 int32;
-typedef ACE_INT16 int16;
-typedef ACE_INT8 int8;
-typedef ACE_UINT64 uint64;
-typedef ACE_UINT32 uint32;
-typedef ACE_UINT16 uint16;
-typedef ACE_UINT8 uint8;
+typedef int64_t int64;
+typedef int32_t int32;
+typedef int16_t int16;
+typedef int8_t int8;
+typedef uint64_t uint64;
+typedef uint32_t uint32;
+typedef uint16_t uint16;
+typedef uint8_t uint8;
#endif //TRINITY_DEFINE_H
diff --git a/src/server/shared/Dynamic/FactoryHolder.h b/src/server/shared/Dynamic/FactoryHolder.h
index aee84ab151e..a009fd37a7e 100644
--- a/src/server/shared/Dynamic/FactoryHolder.h
+++ b/src/server/shared/Dynamic/FactoryHolder.h
@@ -30,15 +30,13 @@ class FactoryHolder
{
public:
typedef ObjectRegistry<FactoryHolder<T, Key >, Key > FactoryHolderRegistry;
- friend class ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex>;
- typedef ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex> FactoryHolderRepository;
FactoryHolder(Key k) : i_key(k) { }
virtual ~FactoryHolder() { }
inline Key key() const { return i_key; }
- void RegisterSelf(void) { FactoryHolderRepository::instance()->InsertItem(this, i_key); }
- void DeregisterSelf(void) { FactoryHolderRepository::instance()->RemoveItem(this, false); }
+ void RegisterSelf(void) { FactoryHolderRegistry::instance()->InsertItem(this, i_key); }
+ void DeregisterSelf(void) { FactoryHolderRegistry::instance()->RemoveItem(this, false); }
/// Abstract Factory create method
virtual T* Create(void *data = NULL) const = 0;
diff --git a/src/server/shared/Dynamic/ObjectRegistry.h b/src/server/shared/Dynamic/ObjectRegistry.h
index be7ce00ac05..e9e57415073 100644
--- a/src/server/shared/Dynamic/ObjectRegistry.h
+++ b/src/server/shared/Dynamic/ObjectRegistry.h
@@ -20,12 +20,10 @@
#define TRINITY_OBJECTREGISTRY_H
#include "Define.h"
-#include <ace/Singleton.h>
#include <string>
-#include <vector>
#include <map>
-#include <unordered_map>
+#include <vector>
/** ObjectRegistry holds all registry item of the same type
*/
@@ -33,7 +31,13 @@ template<class T, class Key = std::string>
class ObjectRegistry
{
public:
- typedef std::map<Key, T *> RegistryMapType;
+ typedef std::map<Key, T*> RegistryMapType;
+
+ static ObjectRegistry<T, Key>* instance()
+ {
+ static ObjectRegistry<T, Key>* instance = new ObjectRegistry<T, Key>();
+ return instance;
+ }
/// Returns a registry item
const T* GetRegistryItem(Key key) const
diff --git a/src/server/shared/Logging/Appender.cpp b/src/server/shared/Logging/Appender.cpp
index 718c3a406f1..2b38f9886c3 100644
--- a/src/server/shared/Logging/Appender.cpp
+++ b/src/server/shared/Logging/Appender.cpp
@@ -17,11 +17,12 @@
#include "Appender.h"
#include "Common.h"
+#include "Util.h"
std::string LogMessage::getTimeStr(time_t time)
{
tm aTm;
- ACE_OS::localtime_r(&time, &aTm);
+ localtime_r(&time, &aTm);
char buf[20];
snprintf(buf, 20, "%04d-%02d-%02d_%02d:%02d:%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
return std::string(buf);
diff --git a/src/server/shared/Logging/AppenderConsole.cpp b/src/server/shared/Logging/AppenderConsole.cpp
index 14d434e35b8..8102d3b6021 100644
--- a/src/server/shared/Logging/AppenderConsole.cpp
+++ b/src/server/shared/Logging/AppenderConsole.cpp
@@ -15,11 +15,15 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <sstream>
+#if PLATFORM == PLATFORM_WINDOWS
+ #include <windows.h>
+#endif
+
#include "AppenderConsole.h"
#include "Config.h"
#include "Util.h"
-#include <sstream>
AppenderConsole::AppenderConsole(uint8 id, std::string const& name, LogLevel level, AppenderFlags flags):
Appender(id, name, APPENDER_CONSOLE, level, flags), _colored(false)
diff --git a/src/server/shared/Logging/AppenderFile.cpp b/src/server/shared/Logging/AppenderFile.cpp
index f2532ad8bb8..3e79ac40c6f 100644
--- a/src/server/shared/Logging/AppenderFile.cpp
+++ b/src/server/shared/Logging/AppenderFile.cpp
@@ -45,7 +45,7 @@ AppenderFile::~AppenderFile()
void AppenderFile::_write(LogMessage const& message)
{
- bool exceedMaxSize = maxFileSize > 0 && (fileSize.value() + message.Size()) > maxFileSize;
+ bool exceedMaxSize = maxFileSize > 0 && (fileSize.load() + message.Size()) > maxFileSize;
if (dynamicName)
{
diff --git a/src/server/shared/Logging/AppenderFile.h b/src/server/shared/Logging/AppenderFile.h
index 1034b41f665..592742c2184 100644
--- a/src/server/shared/Logging/AppenderFile.h
+++ b/src/server/shared/Logging/AppenderFile.h
@@ -19,7 +19,7 @@
#define APPENDERFILE_H
#include "Appender.h"
-#include "ace/Atomic_Op.h"
+#include <atomic>
class AppenderFile: public Appender
{
@@ -38,7 +38,7 @@ class AppenderFile: public Appender
bool dynamicName;
bool backup;
uint64 maxFileSize;
- ACE_Atomic_Op<ACE_Thread_Mutex, uint64> fileSize;
+ std::atomic<uint64> fileSize;
};
#endif
diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp
index dc9bda62bfb..fd7aa84c0e9 100644
--- a/src/server/shared/Logging/Log.cpp
+++ b/src/server/shared/Logging/Log.cpp
@@ -283,9 +283,11 @@ void Log::write(LogMessage* msg) const
std::string Log::GetTimestampStr()
{
- time_t t = time(NULL);
- tm aTm;
- ACE_OS::localtime_r(&t, &aTm);
+ time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
+
+ std::tm aTm;
+ localtime_r(&tt, &aTm);
+
// YYYY year
// MM month (2 digits 01-12)
// DD day (2 digits 01-31)
diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h
index a118e6e8773..c3a47d14e9e 100644
--- a/src/server/shared/Logging/Log.h
+++ b/src/server/shared/Logging/Log.h
@@ -26,14 +26,11 @@
#include <unordered_map>
#include <string>
-#include <ace/Singleton.h>
#define LOGGER_ROOT "root"
class Log
{
- friend class ACE_Singleton<Log, ACE_Thread_Mutex>;
-
typedef std::unordered_map<std::string, Logger> LoggerMap;
private:
@@ -41,6 +38,12 @@ class Log
~Log();
public:
+ static Log* instance()
+ {
+ static Log* instance = new Log();
+ return instance;
+ }
+
void LoadFromConfig();
void Close();
bool ShouldLog(std::string const& type, LogLevel level) const;
@@ -117,7 +120,7 @@ inline void Log::outMessage(std::string const& filter, LogLevel level, const cha
va_end(ap);
}
-#define sLog ACE_Singleton<Log, ACE_Thread_Mutex>::instance()
+#define sLog Log::instance()
#if PLATFORM != PLATFORM_WINDOWS
#define TC_LOG_MESSAGE_BODY(filterType__, level__, ...) \
diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp
index f446592e922..0a911492f85 100644
--- a/src/server/shared/Packets/ByteBuffer.cpp
+++ b/src/server/shared/Packets/ByteBuffer.cpp
@@ -20,7 +20,6 @@
#include "Common.h"
#include "Log.h"
-#include <ace/Stack_Trace.h>
#include <sstream>
ByteBufferPositionException::ByteBufferPositionException(bool add, size_t pos,
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index 11e835566e9..81c6bcd977c 100644
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -22,8 +22,8 @@
#include "Define.h"
#include "Errors.h"
#include "ByteConverter.h"
+#include "Util.h"
-#include <ace/OS_NS_time.h>
#include <exception>
#include <list>
#include <map>
@@ -476,7 +476,7 @@ class ByteBuffer
void AppendPackedTime(time_t time)
{
tm lt;
- ACE_OS::localtime_r(&time, &lt);
+ localtime_r(&time, &lt);
append<uint32>((lt.tm_year - 100) << 24 | lt.tm_mon << 20 | (lt.tm_mday - 1) << 14 | lt.tm_wday << 11 | lt.tm_hour << 6 | lt.tm_min);
}
diff --git a/src/server/shared/Threading/DelayExecutor.cpp b/src/server/shared/Threading/DelayExecutor.cpp
index ba8a19429b2..0db45a8ff8f 100644
--- a/src/server/shared/Threading/DelayExecutor.cpp
+++ b/src/server/shared/Threading/DelayExecutor.cpp
@@ -6,7 +6,8 @@
DelayExecutor* DelayExecutor::instance()
{
- return ACE_Singleton<DelayExecutor, ACE_Thread_Mutex>::instance();
+ static DelayExecutor* instance = new DelayExecutor();
+ return instance;
}
DelayExecutor::DelayExecutor()
diff --git a/src/server/shared/Threading/LockedQueue.h b/src/server/shared/Threading/LockedQueue.h
index 5709724c9a2..bbd60cb7760 100644
--- a/src/server/shared/Threading/LockedQueue.h
+++ b/src/server/shared/Threading/LockedQueue.h
@@ -19,140 +19,126 @@
#ifndef LOCKEDQUEUE_H
#define LOCKEDQUEUE_H
-#include <ace/Guard_T.h>
-#include <ace/Thread_Mutex.h>
#include <deque>
-#include <assert.h>
-#include "Debugging/Errors.h"
+#include <mutex>
-namespace ACE_Based
+template <class T, typename StorageType = std::deque<T> >
+class LockedQueue
{
- template <class T, class LockType, typename StorageType=std::deque<T> >
- class LockedQueue
+ //! Lock access to the queue.
+ std::mutex _lock;
+
+ //! Storage backing the queue.
+ StorageType _queue;
+
+ //! Cancellation flag.
+ volatile bool _canceled;
+
+public:
+
+ //! Create a LockedQueue.
+ LockedQueue()
+ : _canceled(false)
{
- //! Lock access to the queue.
- LockType _lock;
+ }
- //! Storage backing the queue.
- StorageType _queue;
+ //! Destroy a LockedQueue.
+ virtual ~LockedQueue()
+ {
+ }
- //! Cancellation flag.
- volatile bool _canceled;
+ //! Adds an item to the queue.
+ void add(const T& item)
+ {
+ lock();
+
+ _queue.push_back(item);
- public:
+ unlock();
+ }
+
+ //! Gets the next result in the queue, if any.
+ bool next(T& result)
+ {
+ std::lock_guard<std::mutex> lock(_lock);
- //! Create a LockedQueue.
- LockedQueue()
- : _canceled(false)
- {
- }
+ if (_queue.empty())
+ return false;
- //! Destroy a LockedQueue.
- virtual ~LockedQueue()
- {
- }
-
- //! Adds an item to the queue.
- void add(const T& item)
- {
- lock();
-
- //ASSERT(!this->_canceled);
- // throw Cancellation_Exception();
-
- _queue.push_back(item);
-
- unlock();
- }
-
- //! Gets the next result in the queue, if any.
- bool next(T& result)
- {
- // ACE_Guard<LockType> g(this->_lock);
- ACE_GUARD_RETURN (LockType, g, this->_lock, false);
-
- if (_queue.empty())
- return false;
-
- //ASSERT (!_queue.empty() || !this->_canceled);
- // throw Cancellation_Exception();
- result = _queue.front();
- _queue.pop_front();
-
- return true;
- }
-
- template<class Checker>
- bool next(T& result, Checker& check)
- {
- ACE_Guard<LockType> g(this->_lock);
-
- if (_queue.empty())
- return false;
-
- result = _queue.front();
- if (!check.Process(result))
- return false;
-
- _queue.pop_front();
- return true;
- }
-
- //! Peeks at the top of the queue. Check if the queue is empty before calling! Remember to unlock after use if autoUnlock == false.
- T& peek(bool autoUnlock = false)
- {
- lock();
-
- T& result = _queue.front();
-
- if (autoUnlock)
- unlock();
-
- return result;
- }
-
- //! Cancels the queue.
- void cancel()
- {
- lock();
-
- _canceled = true;
-
- unlock();
- }
-
- //! Checks if the queue is cancelled.
- bool cancelled()
- {
- ACE_Guard<LockType> g(this->_lock);
- return _canceled;
- }
-
- //! Locks the queue for access.
- void lock()
- {
- this->_lock.acquire();
- }
-
- //! Unlocks the queue.
- void unlock()
- {
- this->_lock.release();
- }
-
- ///! Calls pop_front of the queue
- void pop_front()
- {
- ACE_GUARD (LockType, g, this->_lock);
- _queue.pop_front();
- }
-
- ///! Checks if we're empty or not with locks held
- bool empty()
- {
- ACE_GUARD_RETURN (LockType, g, this->_lock, false);
- return _queue.empty();
- }
- };
-}
+ result = _queue.front();
+ _queue.pop_front();
+
+ return true;
+ }
+
+ template<class Checker>
+ bool next(T& result, Checker& check)
+ {
+ std::lock_guard<std::mutex> lock(_lock);
+
+ if (_queue.empty())
+ return false;
+
+ result = _queue.front();
+ if (!check.Process(result))
+ return false;
+
+ _queue.pop_front();
+ return true;
+ }
+
+ //! Peeks at the top of the queue. Check if the queue is empty before calling! Remember to unlock after use if autoUnlock == false.
+ T& peek(bool autoUnlock = false)
+ {
+ lock();
+
+ T& result = _queue.front();
+
+ if (autoUnlock)
+ unlock();
+
+ return result;
+ }
+
+ //! Cancels the queue.
+ void cancel()
+ {
+ std::lock_guard<std::mutex> lock(_lock);
+
+ _canceled = true;
+ }
+
+ //! Checks if the queue is cancelled.
+ bool cancelled()
+ {
+ std::lock_guard<std::mutex> lock(_lock);
+ return _canceled;
+ }
+
+ //! Locks the queue for access.
+ void lock()
+ {
+ this->_lock.lock();
+ }
+
+ //! Unlocks the queue.
+ void unlock()
+ {
+ this->_lock.unlock();
+ }
+
+ ///! Calls pop_front of the queue
+ void pop_front()
+ {
+ std::lock_guard<std::mutex> lock(_lock);
+ _queue.pop_front();
+ }
+
+ ///! Checks if we're empty or not with locks held
+ bool empty()
+ {
+ std::lock_guard<std::mutex> lock(_lock);
+ return _queue.empty();
+ }
+};
#endif
diff --git a/src/server/shared/Threading/Threading.cpp b/src/server/shared/Threading/Threading.cpp
deleted file mode 100644
index f67a985943a..00000000000
--- a/src/server/shared/Threading/Threading.cpp
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#include "Threading.h"
-#include "Errors.h"
-#include <ace/OS_NS_unistd.h>
-#include <ace/Sched_Params.h>
-#include <vector>
-
-using namespace ACE_Based;
-
-ThreadPriority::ThreadPriority()
-{
- for (int i = Idle; i < MAXPRIORITYNUM; ++i)
- m_priority[i] = ACE_THR_PRI_OTHER_DEF;
-
- m_priority[Idle] = ACE_Sched_Params::priority_min(ACE_SCHED_OTHER);
- m_priority[Realtime] = ACE_Sched_Params::priority_max(ACE_SCHED_OTHER);
-
- std::vector<int> _tmp;
-
- ACE_Sched_Params::Policy _policy = ACE_SCHED_OTHER;
- ACE_Sched_Priority_Iterator pr_iter(_policy);
-
- while (pr_iter.more())
- {
- _tmp.push_back(pr_iter.priority());
- pr_iter.next();
- }
-
- ASSERT (!_tmp.empty());
-
- if (_tmp.size() >= MAXPRIORITYNUM)
- {
- const size_t max_pos = _tmp.size();
- size_t min_pos = 1;
- size_t norm_pos = 0;
- for (size_t i = 0; i < max_pos; ++i)
- {
- if (_tmp[i] == ACE_THR_PRI_OTHER_DEF)
- {
- norm_pos = i + 1;
- break;
- }
- }
-
- // since we have only 7(seven) values in enum Priority
- // and 3 we know already (Idle, Normal, Realtime) so
- // we need to split each list [Idle...Normal] and [Normal...Realtime]
- // into pieces
- const size_t _divider = 4;
- size_t _div = (norm_pos - min_pos) / _divider;
- if (_div == 0)
- _div = 1;
-
- min_pos = (norm_pos - 1);
-
- m_priority[Low] = _tmp[min_pos -= _div];
- m_priority[Lowest] = _tmp[min_pos -= _div ];
-
- _div = (max_pos - norm_pos) / _divider;
- if (_div == 0)
- _div = 1;
-
- min_pos = norm_pos - 1;
-
- m_priority[High] = _tmp[min_pos += _div];
- m_priority[Highest] = _tmp[min_pos += _div];
- }
-}
-
-int ThreadPriority::getPriority(Priority p) const
-{
- if (p < Idle)
- p = Idle;
-
- if (p > Realtime)
- p = Realtime;
-
- return m_priority[p];
-}
-
-#define THREADFLAG (THR_NEW_LWP | THR_SCHED_DEFAULT| THR_JOINABLE)
-
-Thread::Thread(): m_iThreadId(0), m_hThreadHandle(0), m_task(0)
-{
-
-}
-
-Thread::Thread(Runnable* instance): m_iThreadId(0), m_hThreadHandle(0), m_task(instance)
-{
- // register reference to m_task to prevent it deeltion until destructor
- if (m_task)
- m_task->incReference();
-
- bool _start = start();
- ASSERT (_start);
-}
-
-Thread::~Thread()
-{
- //Wait();
-
- // deleted runnable object (if no other references)
- if (m_task)
- m_task->decReference();
-}
-
-//initialize Thread's class static member
-Thread::ThreadStorage Thread::m_ThreadStorage;
-ThreadPriority Thread::m_TpEnum;
-
-bool Thread::start()
-{
- if (m_task == 0 || m_iThreadId != 0)
- return false;
-
- // incRef before spawing the thread, otherwise Thread::ThreadTask() might call decRef and delete m_task
- m_task->incReference();
-
- bool res = (ACE_Thread::spawn(&Thread::ThreadTask, (void*)m_task, THREADFLAG, &m_iThreadId, &m_hThreadHandle) == 0);
-
- if (!res)
- m_task->decReference();
-
- return res;
-}
-
-bool Thread::wait()
-{
- if (!m_hThreadHandle || !m_task)
- return false;
-
- ACE_THR_FUNC_RETURN _value = ACE_THR_FUNC_RETURN(-1);
- int _res = ACE_Thread::join(m_hThreadHandle, &_value);
-
- m_iThreadId = 0;
- m_hThreadHandle = 0;
-
- return (_res == 0);
-}
-
-void Thread::destroy()
-{
- if (!m_iThreadId || !m_task)
- return;
-
- if (ACE_Thread::kill(m_iThreadId, -1) != 0)
- return;
-
- m_iThreadId = 0;
- m_hThreadHandle = 0;
-
- // reference set at ACE_Thread::spawn
- m_task->decReference();
-}
-
-void Thread::suspend()
-{
- ACE_Thread::suspend(m_hThreadHandle);
-}
-
-void Thread::resume()
-{
- ACE_Thread::resume(m_hThreadHandle);
-}
-
-ACE_THR_FUNC_RETURN Thread::ThreadTask(void * param)
-{
- Runnable* _task = (Runnable*)param;
- _task->run();
-
- // task execution complete, free referecne added at
- _task->decReference();
-
- return (ACE_THR_FUNC_RETURN)0;
-}
-
-ACE_thread_t Thread::currentId()
-{
- return ACE_Thread::self();
-}
-
-ACE_hthread_t Thread::currentHandle()
-{
- ACE_hthread_t _handle;
- ACE_Thread::self(_handle);
-
- return _handle;
-}
-
-Thread * Thread::current()
-{
- Thread * _thread = m_ThreadStorage.ts_object();
- if (!_thread)
- {
- _thread = new Thread();
- _thread->m_iThreadId = Thread::currentId();
- _thread->m_hThreadHandle = Thread::currentHandle();
-
- Thread * _oldValue = m_ThreadStorage.ts_object(_thread);
- if (_oldValue)
- delete _oldValue;
- }
-
- return _thread;
-}
-
-void Thread::setPriority(Priority type)
-{
- int _priority = m_TpEnum.getPriority(type);
- int _ok = ACE_Thread::setprio(m_hThreadHandle, _priority);
- //remove this ASSERT in case you don't want to know is thread priority change was successful or not
- ASSERT (_ok == 0);
-}
-
-void Thread::Sleep(unsigned long msecs)
-{
- ACE_OS::sleep(ACE_Time_Value(0, 1000 * msecs));
-}
diff --git a/src/server/shared/Threading/Threading.h b/src/server/shared/Threading/Threading.h
deleted file mode 100644
index 9d416109e9f..00000000000
--- a/src/server/shared/Threading/Threading.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef THREADING_H
-#define THREADING_H
-
-#include <ace/Thread.h>
-#include <ace/TSS_T.h>
-#include <ace/Atomic_Op.h>
-#include <assert.h>
-
-namespace ACE_Based
-{
-
- class Runnable
- {
- public:
- virtual ~Runnable() { }
- virtual void run() = 0;
-
- void incReference() { ++m_refs; }
- void decReference()
- {
- if (!--m_refs)
- delete this;
- }
- private:
- ACE_Atomic_Op<ACE_Thread_Mutex, long> m_refs;
- };
-
- enum Priority
- {
- Idle,
- Lowest,
- Low,
- Normal,
- High,
- Highest,
- Realtime
- };
-
-#define MAXPRIORITYNUM (Realtime + 1)
-
- class ThreadPriority
- {
- public:
- ThreadPriority();
- int getPriority(Priority p) const;
-
- private:
- int m_priority[MAXPRIORITYNUM];
- };
-
- class Thread
- {
- public:
- Thread();
- explicit Thread(Runnable* instance);
- ~Thread();
-
- bool start();
- bool wait();
- void destroy();
-
- void suspend();
- void resume();
-
- void setPriority(Priority type);
-
- static void Sleep(unsigned long msecs);
- static ACE_thread_t currentId();
- static ACE_hthread_t currentHandle();
- static Thread * current();
-
- private:
- Thread(const Thread&);
- Thread& operator=(const Thread&);
-
- static ACE_THR_FUNC_RETURN ThreadTask(void * param);
-
- ACE_thread_t m_iThreadId;
- ACE_hthread_t m_hThreadHandle;
- Runnable* m_task;
-
- typedef ACE_TSS<Thread> ThreadStorage;
- //global object - container for Thread class representation of every thread
- static ThreadStorage m_ThreadStorage;
- //use this object to determine current OS thread priority values mapped to enum Priority{ }
- static ThreadPriority m_TpEnum;
- };
-
-}
-#endif
diff --git a/src/server/shared/Utilities/Timer.h b/src/server/shared/Utilities/Timer.h
index c809a59c20f..7c62de5f5ed 100644
--- a/src/server/shared/Utilities/Timer.h
+++ b/src/server/shared/Utilities/Timer.h
@@ -19,13 +19,15 @@
#ifndef TRINITY_TIMER_H
#define TRINITY_TIMER_H
-#include "ace/OS_NS_sys_time.h"
-#include "Common.h"
+#include <chrono>
+
+using namespace std::chrono;
inline uint32 getMSTime()
{
- static const ACE_Time_Value ApplicationStartTime = ACE_OS::gettimeofday();
- return (ACE_OS::gettimeofday() - ApplicationStartTime).msec();
+ static const system_clock::time_point ApplicationStartTime = system_clock::now();
+
+ return duration_cast<milliseconds>(system_clock::now() - ApplicationStartTime).count();
}
inline uint32 getMSTimeDiff(uint32 oldMSTime, uint32 newMSTime)
@@ -44,158 +46,158 @@ inline uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
struct IntervalTimer
{
- public:
-
- IntervalTimer()
- : _interval(0), _current(0)
- {
- }
-
- void Update(time_t diff)
- {
- _current += diff;
- if (_current < 0)
- _current = 0;
- }
-
- bool Passed()
- {
- return _current >= _interval;
- }
-
- void Reset()
- {
- if (_current >= _interval)
- _current %= _interval;
- }
-
- void SetCurrent(time_t current)
- {
- _current = current;
- }
-
- void SetInterval(time_t interval)
- {
- _interval = interval;
- }
-
- time_t GetInterval() const
- {
- return _interval;
- }
-
- time_t GetCurrent() const
- {
- return _current;
- }
-
- private:
-
- time_t _interval;
- time_t _current;
+public:
+
+ IntervalTimer()
+ : _interval(0), _current(0)
+ {
+ }
+
+ void Update(time_t diff)
+ {
+ _current += diff;
+ if (_current < 0)
+ _current = 0;
+ }
+
+ bool Passed()
+ {
+ return _current >= _interval;
+ }
+
+ void Reset()
+ {
+ if (_current >= _interval)
+ _current %= _interval;
+ }
+
+ void SetCurrent(time_t current)
+ {
+ _current = current;
+ }
+
+ void SetInterval(time_t interval)
+ {
+ _interval = interval;
+ }
+
+ time_t GetInterval() const
+ {
+ return _interval;
+ }
+
+ time_t GetCurrent() const
+ {
+ return _current;
+ }
+
+private:
+
+ time_t _interval;
+ time_t _current;
};
struct TimeTracker
{
- public:
+public:
- TimeTracker(time_t expiry)
- : i_expiryTime(expiry)
- {
- }
+ TimeTracker(time_t expiry)
+ : i_expiryTime(expiry)
+ {
+ }
- void Update(time_t diff)
- {
- i_expiryTime -= diff;
- }
+ void Update(time_t diff)
+ {
+ i_expiryTime -= diff;
+ }
- bool Passed() const
- {
- return i_expiryTime <= 0;
- }
+ bool Passed() const
+ {
+ return i_expiryTime <= 0;
+ }
- void Reset(time_t interval)
- {
- i_expiryTime = interval;
- }
+ void Reset(time_t interval)
+ {
+ i_expiryTime = interval;
+ }
- time_t GetExpiry() const
- {
- return i_expiryTime;
- }
+ time_t GetExpiry() const
+ {
+ return i_expiryTime;
+ }
- private:
+private:
- time_t i_expiryTime;
+ time_t i_expiryTime;
};
struct TimeTrackerSmall
{
- public:
+public:
- TimeTrackerSmall(uint32 expiry = 0)
- : i_expiryTime(expiry)
- {
- }
+ TimeTrackerSmall(uint32 expiry = 0)
+ : i_expiryTime(expiry)
+ {
+ }
- void Update(int32 diff)
- {
- i_expiryTime -= diff;
- }
+ void Update(int32 diff)
+ {
+ i_expiryTime -= diff;
+ }
- bool Passed() const
- {
- return i_expiryTime <= 0;
- }
+ bool Passed() const
+ {
+ return i_expiryTime <= 0;
+ }
- void Reset(uint32 interval)
- {
- i_expiryTime = interval;
- }
+ void Reset(uint32 interval)
+ {
+ i_expiryTime = interval;
+ }
- int32 GetExpiry() const
- {
- return i_expiryTime;
- }
+ int32 GetExpiry() const
+ {
+ return i_expiryTime;
+ }
- private:
+private:
- int32 i_expiryTime;
+ int32 i_expiryTime;
};
struct PeriodicTimer
{
- public:
+public:
- PeriodicTimer(int32 period, int32 start_time)
- : i_period(period), i_expireTime(start_time)
- {
- }
+ PeriodicTimer(int32 period, int32 start_time)
+ : i_period(period), i_expireTime(start_time)
+ {
+ }
- bool Update(const uint32 diff)
- {
- if ((i_expireTime -= diff) > 0)
- return false;
+ bool Update(const uint32 diff)
+ {
+ if ((i_expireTime -= diff) > 0)
+ return false;
- i_expireTime += i_period > int32(diff) ? i_period : diff;
- return true;
- }
+ i_expireTime += i_period > int32(diff) ? i_period : diff;
+ return true;
+ }
- void SetPeriodic(int32 period, int32 start_time)
- {
- i_expireTime = start_time;
- i_period = period;
- }
+ void SetPeriodic(int32 period, int32 start_time)
+ {
+ i_expireTime = start_time;
+ i_period = period;
+ }
- // Tracker interface
- void TUpdate(int32 diff) { i_expireTime -= diff; }
- bool TPassed() const { return i_expireTime <= 0; }
- void TReset(int32 diff, int32 period) { i_expireTime += period > diff ? period : diff; }
+ // Tracker interface
+ void TUpdate(int32 diff) { i_expireTime -= diff; }
+ bool TPassed() const { return i_expireTime <= 0; }
+ void TReset(int32 diff, int32 period) { i_expireTime += period > diff ? period : diff; }
- private:
+private:
- int32 i_period;
- int32 i_expireTime;
+ int32 i_period;
+ int32 i_expireTime;
};
#endif
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp
index 28bbe831a69..a65f54f87fc 100644
--- a/src/server/shared/Utilities/Util.cpp
+++ b/src/server/shared/Utilities/Util.cpp
@@ -21,42 +21,54 @@
#include "utf8.h"
#include "SFMT.h"
#include "Errors.h" // for ASSERT
-#include <ace/TSS_T.h>
+#include <boost/thread/tss.hpp>
-typedef ACE_TSS<SFMTRand> SFMTRandTSS;
-static SFMTRandTSS sfmtRand;
+static boost::thread_specific_ptr<SFMTRand> sfmtRand;
+
+static SFMTRand* GetRng()
+{
+ SFMTRand* rand = sfmtRand.get();
+
+ if (!rand)
+ {
+ rand = new SFMTRand();
+ sfmtRand.reset(rand);
+ }
+
+ return rand;
+}
int32 irand(int32 min, int32 max)
{
ASSERT(max >= min);
- return int32(sfmtRand->IRandom(min, max));
+ return int32(GetRng()->IRandom(min, max));
}
uint32 urand(uint32 min, uint32 max)
{
ASSERT(max >= min);
- return sfmtRand->URandom(min, max);
+ return GetRng()->URandom(min, max);
}
float frand(float min, float max)
{
ASSERT(max >= min);
- return float(sfmtRand->Random() * (max - min) + min);
+ return float(GetRng()->Random() * (max - min) + min);
}
int32 rand32()
{
- return int32(sfmtRand->BRandom());
+ return int32(GetRng()->BRandom());
}
double rand_norm(void)
{
- return sfmtRand->Random();
+ return GetRng()->Random();
}
double rand_chance(void)
{
- return sfmtRand->Random() * 100.0;
+ return GetRng()->Random() * 100.0;
}
Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserve)
@@ -127,6 +139,14 @@ void stripLineInvisibleChars(std::string &str)
}
+#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
+struct tm* localtime_r(const time_t* time, struct tm *result)
+{
+ localtime_s(result, time);
+ return result;
+}
+#endif
+
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
{
uint64 secs = timeInSecs % MINUTE;
@@ -216,7 +236,7 @@ uint32 TimeStringToSecs(const std::string& timestring)
std::string TimeToTimestampStr(time_t t)
{
tm aTm;
- ACE_OS::localtime_r(&t, &aTm);
+ localtime_r(&t, &aTm);
// YYYY year
// MM month (2 digits 01-12)
// DD day (2 digits 01-31)
@@ -239,21 +259,6 @@ bool IsIPAddress(char const* ipaddress)
return inet_addr(ipaddress) != INADDR_NONE;
}
-std::string GetAddressString(ACE_INET_Addr const& addr)
-{
- char buf[ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 16];
- addr.addr_to_string(buf, ACE_MAX_FULLY_QUALIFIED_NAME_LEN + 16);
- return buf;
-}
-
-bool IsIPAddrInNetwork(ACE_INET_Addr const& net, ACE_INET_Addr const& addr, ACE_INET_Addr const& subnetMask)
-{
- uint32 mask = subnetMask.get_ip_address();
- if ((net.get_ip_address() & mask) == (addr.get_ip_address() & mask))
- return true;
- return false;
-}
-
/// create PID file
uint32 CreatePIDFile(const std::string& filename)
{
diff --git a/src/server/shared/Utilities/Util.h b/src/server/shared/Utilities/Util.h
index 648edf39abe..c384a6eeaed 100644
--- a/src/server/shared/Utilities/Util.h
+++ b/src/server/shared/Utilities/Util.h
@@ -27,7 +27,6 @@
#include <vector>
#include <list>
#include <map>
-#include <ace/INET_Addr.h>
// Searcher for map of structs
template<typename T, class S> struct Finder
@@ -71,6 +70,8 @@ void stripLineInvisibleChars(std::string &src);
int32 MoneyStringToMoney(const std::string& moneyString);
+struct tm* localtime_r(const time_t* time, struct tm *result);
+
std::string secsToTimeString(uint64 timeInSecs, bool shortText = false, bool hoursOnly = false);
uint32 TimeStringToSecs(const std::string& timestring);
std::string TimeToTimestampStr(time_t t);
@@ -347,12 +348,6 @@ void vutf8printf(FILE* out, const char *str, va_list* ap);
bool IsIPAddress(char const* ipaddress);
-/// Checks if address belongs to the a network with specified submask
-bool IsIPAddrInNetwork(ACE_INET_Addr const& net, ACE_INET_Addr const& addr, ACE_INET_Addr const& subnetMask);
-
-/// Transforms ACE_INET_Addr address into string format "dotted_ip:port"
-std::string GetAddressString(ACE_INET_Addr const& addr);
-
uint32 CreatePIDFile(const std::string& filename);
std::string ByteArrayToHexStr(uint8 const* bytes, uint32 length, bool reverse = false);
diff --git a/src/server/worldserver/CMakeLists.txt b/src/server/worldserver/CMakeLists.txt
index 78a29dbedf6..c006e6c925c 100644
--- a/src/server/worldserver/CMakeLists.txt
+++ b/src/server/worldserver/CMakeLists.txt
@@ -178,6 +178,7 @@ target_link_libraries(worldserver
${OPENSSL_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
+ ${Boost_LIBRARIES}
)
if( WIN32 )
diff --git a/src/server/worldserver/CommandLine/CliRunnable.cpp b/src/server/worldserver/CommandLine/CliRunnable.cpp
index ac46b218305..295e63c696b 100644
--- a/src/server/worldserver/CommandLine/CliRunnable.cpp
+++ b/src/server/worldserver/CommandLine/CliRunnable.cpp
@@ -131,7 +131,7 @@ int kb_hit_return()
#endif
/// %Thread start
-void CliRunnable::run()
+void CliThread()
{
///- Display the list of available CLI functions then beep
//TC_LOG_INFO("server.worldserver", "");
diff --git a/src/server/worldserver/CommandLine/CliRunnable.h b/src/server/worldserver/CommandLine/CliRunnable.h
index 5510173973e..7ed3a44995f 100644
--- a/src/server/worldserver/CommandLine/CliRunnable.h
+++ b/src/server/worldserver/CommandLine/CliRunnable.h
@@ -23,12 +23,7 @@
#ifndef __CLIRUNNABLE_H
#define __CLIRUNNABLE_H
-/// Command Line Interface handling thread
-class CliRunnable : public ACE_Based::Runnable
-{
- public:
- void run() override;
-};
+void CliThread();
#endif
diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp
index 6e4214603cb..2a8fcdd431a 100644
--- a/src/server/worldserver/Master.cpp
+++ b/src/server/worldserver/Master.cpp
@@ -20,6 +20,8 @@
\ingroup Trinityd
*/
+#include <thread>
+
#include <ace/Sig_Handler.h>
#include "Common.h"
@@ -40,7 +42,6 @@
#include "TCSoap.h"
#include "Timer.h"
#include "Util.h"
-#include "AuthSocket.h"
#include "RealmList.h"
#include "BigNumber.h"
@@ -79,51 +80,35 @@ class WorldServerSignalHandler : public Trinity::SignalHandler
}
};
-class FreezeDetectorRunnable : public ACE_Based::Runnable
+void FreezeDetectorThread(uint32 delayTime)
{
-private:
- uint32 _loops;
- uint32 _lastChange;
- uint32 _delaytime;
-public:
- FreezeDetectorRunnable()
- {
- _loops = 0;
- _lastChange = 0;
- _delaytime = 0;
- }
+ if (!delayTime)
+ return;
- void SetDelayTime(uint32 t) { _delaytime = t; }
+ TC_LOG_INFO("server.worldserver", "Starting up anti-freeze thread (%u seconds max stuck time)...", delayTime / 1000);
+ uint32 loops = 0;
+ uint32 lastChange = 0;
- void run() override
+ while (!World::IsStopped())
{
- if (!_delaytime)
- return;
-
- TC_LOG_INFO("server.worldserver", "Starting up anti-freeze thread (%u seconds max stuck time)...", _delaytime/1000);
- _loops = 0;
- _lastChange = 0;
- while (!World::IsStopped())
+ std::this_thread::sleep_for(std::chrono::milliseconds(1000));
+ uint32 curtime = getMSTime();
+ // normal work
+ uint32 worldLoopCounter = World::m_worldLoopCounter.value();
+ if (loops != worldLoopCounter)
{
- ACE_Based::Thread::Sleep(1000);
- uint32 curtime = getMSTime();
- // normal work
- uint32 worldLoopCounter = World::m_worldLoopCounter.value();
- if (_loops != worldLoopCounter)
- {
- _lastChange = curtime;
- _loops = worldLoopCounter;
- }
- // possible freeze
- else if (getMSTimeDiff(_lastChange, curtime) > _delaytime)
- {
- TC_LOG_ERROR("server.worldserver", "World Thread hangs, kicking out server!");
- ASSERT(false);
- }
+ lastChange = curtime;
+ loops = worldLoopCounter;
+ }
+ // possible freeze
+ else if (getMSTimeDiff(lastChange, curtime) > delayTime)
+ {
+ TC_LOG_ERROR("server.worldserver", "World Thread hangs, kicking out server!");
+ ASSERT(false);
}
- TC_LOG_INFO("server.worldserver", "Anti-freeze thread exiting without problems.");
}
-};
+ TC_LOG_INFO("server.worldserver", "Anti-freeze thread exiting without problems.");
+}
/// Main function
int Master::Run()
@@ -183,10 +168,10 @@ int Master::Run()
#endif
///- Launch WorldRunnable thread
- ACE_Based::Thread worldThread(new WorldRunnable);
- worldThread.setPriority(ACE_Based::Highest);
- ACE_Based::Thread* cliThread = NULL;
+ std::thread worldThread(WorldThread);
+
+ std::thread* cliThread = nullptr;
#ifdef _WIN32
if (sConfigMgr->GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/)
@@ -195,10 +180,11 @@ int Master::Run()
#endif
{
///- Launch CliRunnable thread
- cliThread = new ACE_Based::Thread(new CliRunnable);
+ cliThread = new std::thread(CliThread);
}
- ACE_Based::Thread rarThread(new RARunnable);
+ // TODO C++11/Boost
+ // std::thread rarThread(RemoteAccessThread);
#if defined(_WIN32) || defined(__linux__)
@@ -269,22 +255,19 @@ int Master::Run()
#endif
//Start soap serving thread
- ACE_Based::Thread* soapThread = NULL;
+ std::thread* soapThread = nullptr;
if (sConfigMgr->GetBoolDefault("SOAP.Enabled", false))
{
- TCSoapRunnable* runnable = new TCSoapRunnable();
- runnable->SetListenArguments(sConfigMgr->GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetIntDefault("SOAP.Port", 7878)));
- soapThread = new ACE_Based::Thread(runnable);
+ soapThread = new std::thread(TCSoapThread, sConfigMgr->GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetIntDefault("SOAP.Port", 7878)));
}
+ std::thread* freezeDetectorThread = nullptr;
+
///- Start up freeze catcher thread
if (uint32 freezeDelay = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0))
{
- FreezeDetectorRunnable* fdr = new FreezeDetectorRunnable();
- fdr->SetDelayTime(freezeDelay * 1000);
- ACE_Based::Thread freezeThread(fdr);
- freezeThread.setPriority(ACE_Based::Highest);
+ freezeDetectorThread = new std::thread(FreezeDetectorThread, freezeDelay);
}
///- Launch the world listener socket
@@ -305,13 +288,12 @@ int Master::Run()
// when the main thread closes the singletons get unloaded
// since worldrunnable uses them, it will crash if unloaded after master
- worldThread.wait();
- rarThread.wait();
+ worldThread.join();
+ //rarThread.join();
- if (soapThread)
+ if (soapThread != nullptr)
{
- soapThread->wait();
- soapThread->destroy();
+ soapThread->join();
delete soapThread;
}
@@ -325,7 +307,7 @@ int Master::Run()
TC_LOG_INFO("server.worldserver", "Halting process...");
- if (cliThread)
+ if (cliThread != nullptr)
{
#ifdef _WIN32
@@ -364,17 +346,15 @@ int Master::Run()
DWORD numb;
WriteConsoleInput(hStdIn, b, 4, &numb);
- cliThread->wait();
-
- #else
-
- cliThread->destroy();
+ cliThread->join();
#endif
delete cliThread;
}
+ delete freezeDetectorThread;
+
// for some unknown reason, unloading scripts here and not in worldrunnable
// fixes a memory leak related to detaching threads from the module
//UnloadScriptingModule();
diff --git a/src/server/worldserver/PrecompiledHeaders/worldPCH.h b/src/server/worldserver/PrecompiledHeaders/worldPCH.h
index f94dd953bba..889e3855995 100644
--- a/src/server/worldserver/PrecompiledHeaders/worldPCH.h
+++ b/src/server/worldserver/PrecompiledHeaders/worldPCH.h
@@ -1,6 +1,5 @@
-#include "WorldSocket.h" // must be first to make ACE happy with ACE includes in it
-
#include "Common.h"
+#include "WorldSocket.h"
#include "World.h"
#include "Log.h"
#include "Database/DatabaseEnv.h"
diff --git a/src/server/worldserver/RemoteAccess/RARunnable.cpp b/src/server/worldserver/RemoteAccess/RARunnable.cpp
index 44b07163294..4efeb07ef25 100644
--- a/src/server/worldserver/RemoteAccess/RARunnable.cpp
+++ b/src/server/worldserver/RemoteAccess/RARunnable.cpp
@@ -33,29 +33,22 @@
#include "RASocket.h"
-RARunnable::RARunnable()
+
+void RemoteAccessThread()
{
- ACE_Reactor_Impl* imp;
+ ACE_Reactor_Impl* imp = nullptr;
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
imp = new ACE_Dev_Poll_Reactor();
- imp->max_notify_iterations (128);
- imp->restart (1);
+ imp->max_notify_iterations(128);
+ imp->restart(1);
#else
imp = new ACE_TP_Reactor();
- imp->max_notify_iterations (128);
+ imp->max_notify_iterations(128);
#endif
- m_Reactor = new ACE_Reactor (imp, 1);
-}
+ ACE_Reactor* reactor = new ACE_Reactor(imp, 1);
-RARunnable::~RARunnable()
-{
- delete m_Reactor;
-}
-
-void RARunnable::run()
-{
if (!sConfigMgr->GetBoolDefault("Ra.Enable", false))
return;
@@ -65,7 +58,7 @@ void RARunnable::run()
std::string stringIp = sConfigMgr->GetStringDefault("Ra.IP", "0.0.0.0");
ACE_INET_Addr listenAddress(raPort, stringIp.c_str());
- if (acceptor.open(listenAddress, m_Reactor) == -1)
+ if (acceptor.open(listenAddress, reactor) == -1)
{
TC_LOG_ERROR("server.worldserver", "Trinity RA can not bind to port %d on %s", raPort, stringIp.c_str());
return;
@@ -76,9 +69,12 @@ void RARunnable::run()
while (!World::IsStopped())
{
ACE_Time_Value interval(0, 100000);
- if (m_Reactor->run_reactor_event_loop(interval) == -1)
+ if (reactor->run_reactor_event_loop(interval) == -1)
break;
}
+ delete imp;
+ delete reactor;
+
TC_LOG_DEBUG("server.worldserver", "Trinity RA thread exiting");
}
diff --git a/src/server/worldserver/RemoteAccess/RARunnable.h b/src/server/worldserver/RemoteAccess/RARunnable.h
index 540ac762f30..a65df077f97 100644
--- a/src/server/worldserver/RemoteAccess/RARunnable.h
+++ b/src/server/worldserver/RemoteAccess/RARunnable.h
@@ -22,21 +22,7 @@
#ifndef _TRINITY_RARUNNABLE_H_
#define _TRINITY_RARUNNABLE_H_
-#include "Common.h"
-
-#include <ace/Reactor.h>
-
-class RARunnable : public ACE_Based::Runnable
-{
-public:
- RARunnable();
- virtual ~RARunnable();
- void run() override;
-
-private:
- ACE_Reactor* m_Reactor;
-
-};
+void RemoteAccessThread();
#endif /* _TRINITY_RARUNNABLE_H_ */
diff --git a/src/server/worldserver/TCSoap/TCSoap.cpp b/src/server/worldserver/TCSoap/TCSoap.cpp
index 1549019352d..3d242859ff2 100644
--- a/src/server/worldserver/TCSoap/TCSoap.cpp
+++ b/src/server/worldserver/TCSoap/TCSoap.cpp
@@ -22,7 +22,7 @@
#include "AccountMgr.h"
#include "Log.h"
-void TCSoapRunnable::run()
+void TCSoapThread(const std::string& host, uint16 port)
{
struct soap soap;
soap_init(&soap);
@@ -33,13 +33,13 @@ void TCSoapRunnable::run()
soap.accept_timeout = 3;
soap.recv_timeout = 5;
soap.send_timeout = 5;
- if (!soap_valid_socket(soap_bind(&soap, _host.c_str(), _port, 100)))
+ if (!soap_valid_socket(soap_bind(&soap, host.c_str(), port, 100)))
{
- TC_LOG_ERROR("network.soap", "Couldn't bind to %s:%d", _host.c_str(), _port);
+ TC_LOG_ERROR("network.soap", "Couldn't bind to %s:%d", host.c_str(), port);
exit(-1);
}
- TC_LOG_INFO("network.soap", "Bound to http://%s:%d", _host.c_str(), _port);
+ TC_LOG_INFO("network.soap", "Bound to http://%s:%d", host.c_str(), port);
while (!World::IsStopped())
{
@@ -57,7 +57,7 @@ void TCSoapRunnable::run()
soap_done(&soap);
}
-void TCSoapRunnable::process_message(ACE_Message_Block* mb)
+void process_message(ACE_Message_Block* mb)
{
ACE_TRACE (ACE_TEXT ("SOAPWorkingThread::process_message"));
diff --git a/src/server/worldserver/TCSoap/TCSoap.h b/src/server/worldserver/TCSoap/TCSoap.h
index 427d37ef0cc..937ceac6425 100644
--- a/src/server/worldserver/TCSoap/TCSoap.h
+++ b/src/server/worldserver/TCSoap/TCSoap.h
@@ -22,27 +22,9 @@
#include <ace/Semaphore.h>
#include <ace/Task.h>
-#include <Threading.h>
-class TCSoapRunnable : public ACE_Based::Runnable
-{
- public:
- TCSoapRunnable() : _port(0) { }
-
- void run() override;
-
- void SetListenArguments(const std::string& host, uint16 port)
- {
- _host = host;
- _port = port;
- }
-
- private:
- void process_message(ACE_Message_Block* mb);
-
- std::string _host;
- uint16 _port;
-};
+void process_message(ACE_Message_Block* mb);
+void TCSoapThread(const std::string& host, uint16 port);
class SOAPCommand
{
diff --git a/src/server/worldserver/WorldThread/WorldRunnable.cpp b/src/server/worldserver/WorldThread/WorldRunnable.cpp
index 476007f6ea0..7722492b5a8 100644
--- a/src/server/worldserver/WorldThread/WorldRunnable.cpp
+++ b/src/server/worldserver/WorldThread/WorldRunnable.cpp
@@ -20,6 +20,8 @@
\ingroup Trinityd
*/
+#include <thread>
+
#include "Common.h"
#include "ObjectAccessor.h"
#include "World.h"
@@ -40,7 +42,7 @@ extern int m_ServiceStatus;
#endif
/// Heartbeat for the World
-void WorldRunnable::run()
+void WorldThread()
{
uint32 realCurrTime = 0;
uint32 realPrevTime = getMSTime();
@@ -67,7 +69,8 @@ void WorldRunnable::run()
if (diff <= WORLD_SLEEP_CONST+prevSleepTime)
{
prevSleepTime = WORLD_SLEEP_CONST+prevSleepTime-diff;
- ACE_Based::Thread::Sleep(prevSleepTime);
+
+ std::this_thread::sleep_for(std::chrono::milliseconds(prevSleepTime));
}
else
prevSleepTime = 0;
diff --git a/src/server/worldserver/WorldThread/WorldRunnable.h b/src/server/worldserver/WorldThread/WorldRunnable.h
index dfc74dd1e3a..915bd5b580a 100644
--- a/src/server/worldserver/WorldThread/WorldRunnable.h
+++ b/src/server/worldserver/WorldThread/WorldRunnable.h
@@ -23,12 +23,7 @@
#ifndef __WORLDRUNNABLE_H
#define __WORLDRUNNABLE_H
-/// Heartbeat thread for the World
-class WorldRunnable : public ACE_Based::Runnable
-{
- public:
- void run() override;
-};
+void WorldThread();
#endif