aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared')
-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
24 files changed, 391 insertions, 838 deletions
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);