aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Utilities/Util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared/Utilities/Util.cpp')
-rw-r--r--src/server/shared/Utilities/Util.cpp55
1 files changed, 30 insertions, 25 deletions
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp
index 4c54492f5ad..a68d836252d 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)
{