mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-30 21:57:01 +01:00
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
This commit is contained in:
@@ -4,25 +4,20 @@
|
||||
**/
|
||||
/*
|
||||
Copyright (C) 2004-2007 Anders Hedstrom
|
||||
|
||||
This library is made available under the terms of the GNU GPL.
|
||||
|
||||
If you would like to use this library in a closed-source application,
|
||||
a separate license agreement is available. For information about
|
||||
the closed-source license agreement for the C++ sockets library,
|
||||
please visit http://www.alhem.net/Sockets/license.html and/or
|
||||
email license@alhem.net.
|
||||
|
||||
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, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
@@ -40,12 +35,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include <map>
|
||||
|
||||
#ifdef SOCKETS_NAMESPACE
|
||||
namespace SOCKETS_NAMESPACE {
|
||||
#endif
|
||||
|
||||
|
||||
// defines for the random number generator
|
||||
#define TWIST_IA 397
|
||||
#define TWIST_IB (TWIST_LEN - TWIST_IA)
|
||||
@@ -55,7 +48,6 @@ namespace SOCKETS_NAMESPACE {
|
||||
#define TWIST(b,i,j) ((b)[i] & UMASK) | ((b)[j] & LMASK)
|
||||
#define MAGIC_TWIST(s) (((s) & 1) * MATRIX_A)
|
||||
|
||||
|
||||
// statics
|
||||
std::string Utility::m_host;
|
||||
bool Utility::m_local_resolved = false;
|
||||
@@ -68,7 +60,6 @@ std::string Utility::m_local_addr6;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
std::string Utility::base64(const std::string& str_in)
|
||||
{
|
||||
std::string str;
|
||||
@@ -77,7 +68,6 @@ std::string Utility::base64(const std::string& str_in)
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::base64d(const std::string& str_in)
|
||||
{
|
||||
std::string str;
|
||||
@@ -86,7 +76,6 @@ std::string Utility::base64d(const std::string& str_in)
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::l2string(long l)
|
||||
{
|
||||
std::string str;
|
||||
@@ -96,7 +85,6 @@ std::string Utility::l2string(long l)
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::bigint2string(uint64_t l)
|
||||
{
|
||||
std::string str;
|
||||
@@ -114,7 +102,6 @@ std::string Utility::bigint2string(uint64_t l)
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
uint64_t Utility::atoi64(const std::string& str)
|
||||
{
|
||||
uint64_t l = 0;
|
||||
@@ -125,7 +112,6 @@ uint64_t Utility::atoi64(const std::string& str)
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
unsigned int Utility::hex2unsigned(const std::string& str)
|
||||
{
|
||||
unsigned int r = 0;
|
||||
@@ -136,7 +122,6 @@ unsigned int Utility::hex2unsigned(const std::string& str)
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Encode string per RFC1738 URL encoding rules
|
||||
* tnx rstaveley
|
||||
@@ -167,7 +152,6 @@ static char hex[] = "0123456789ABCDEF";
|
||||
return dst;
|
||||
} // rfc1738_encode
|
||||
|
||||
|
||||
/*
|
||||
* Decode string per RFC1738 URL encoding rules
|
||||
* tnx rstaveley
|
||||
@@ -198,7 +182,6 @@ std::string Utility::rfc1738_decode(const std::string& src)
|
||||
return dst;
|
||||
} // rfc1738_decode
|
||||
|
||||
|
||||
bool Utility::isipv4(const std::string& str)
|
||||
{
|
||||
int dots = 0;
|
||||
@@ -216,7 +199,6 @@ bool Utility::isipv4(const std::string& str)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Utility::isipv6(const std::string& str)
|
||||
{
|
||||
size_t qc = 0;
|
||||
@@ -256,7 +238,6 @@ bool Utility::isipv6(const std::string& str)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Utility::u2ip(const std::string& str, ipaddr_t& l)
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
@@ -265,7 +246,6 @@ bool Utility::u2ip(const std::string& str, ipaddr_t& l)
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
#ifdef IPPROTO_IPV6
|
||||
bool Utility::u2ip(const std::string& str, struct in6_addr& l)
|
||||
@@ -278,7 +258,6 @@ bool Utility::u2ip(const std::string& str, struct in6_addr& l)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
void Utility::l2ip(const ipaddr_t ip, std::string& str)
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
@@ -288,7 +267,6 @@ void Utility::l2ip(const ipaddr_t ip, std::string& str)
|
||||
Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), str, NI_NUMERICHOST);
|
||||
}
|
||||
|
||||
|
||||
void Utility::l2ip(const in_addr& ip, std::string& str)
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
@@ -298,7 +276,6 @@ void Utility::l2ip(const in_addr& ip, std::string& str)
|
||||
Utility::reverse( (struct sockaddr *)&sa, sizeof(sa), str, NI_NUMERICHOST);
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
#ifdef IPPROTO_IPV6
|
||||
void Utility::l2ip(const struct in6_addr& ip, std::string& str,bool mixed)
|
||||
@@ -347,7 +324,6 @@ void Utility::l2ip(const struct in6_addr& ip, std::string& str,bool mixed)
|
||||
str = slask;
|
||||
}
|
||||
|
||||
|
||||
int Utility::in6_addr_compare(in6_addr a,in6_addr b)
|
||||
{
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
@@ -362,11 +338,9 @@ int Utility::in6_addr_compare(in6_addr a,in6_addr b)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
void Utility::ResolveLocal()
|
||||
{
|
||||
char h[256];
|
||||
|
||||
// get local hostname and translate into ip-address
|
||||
*h = 0;
|
||||
gethostname(h,255);
|
||||
@@ -391,7 +365,6 @@ void Utility::ResolveLocal()
|
||||
m_local_resolved = true;
|
||||
}
|
||||
|
||||
|
||||
const std::string& Utility::GetLocalHostname()
|
||||
{
|
||||
if (!m_local_resolved)
|
||||
@@ -401,7 +374,6 @@ const std::string& Utility::GetLocalHostname()
|
||||
return m_host;
|
||||
}
|
||||
|
||||
|
||||
ipaddr_t Utility::GetLocalIP()
|
||||
{
|
||||
if (!m_local_resolved)
|
||||
@@ -411,7 +383,6 @@ ipaddr_t Utility::GetLocalIP()
|
||||
return m_ip;
|
||||
}
|
||||
|
||||
|
||||
const std::string& Utility::GetLocalAddress()
|
||||
{
|
||||
if (!m_local_resolved)
|
||||
@@ -421,7 +392,6 @@ const std::string& Utility::GetLocalAddress()
|
||||
return m_addr;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
#ifdef IPPROTO_IPV6
|
||||
const struct in6_addr& Utility::GetLocalIP6()
|
||||
@@ -433,7 +403,6 @@ const struct in6_addr& Utility::GetLocalIP6()
|
||||
return m_local_ip6;
|
||||
}
|
||||
|
||||
|
||||
const std::string& Utility::GetLocalAddress6()
|
||||
{
|
||||
if (!m_local_resolved)
|
||||
@@ -445,7 +414,6 @@ const std::string& Utility::GetLocalAddress6()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
void Utility::SetEnv(const std::string& var,const std::string& value)
|
||||
{
|
||||
#if (defined(SOLARIS8) || defined(SOLARIS))
|
||||
@@ -469,7 +437,6 @@ void Utility::SetEnv(const std::string& var,const std::string& value)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::Sa2String(struct sockaddr *sa)
|
||||
{
|
||||
#ifdef ENABLE_IPV6
|
||||
@@ -495,7 +462,6 @@ std::string Utility::Sa2String(struct sockaddr *sa)
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
void Utility::GetTime(struct timeval *p)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@@ -511,7 +477,6 @@ void Utility::GetTime(struct timeval *p)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::auto_ptr<SocketAddress> Utility::CreateAddress(struct sockaddr *sa,socklen_t sa_len)
|
||||
{
|
||||
switch (sa -> sa_family)
|
||||
@@ -538,7 +503,6 @@ std::auto_ptr<SocketAddress> Utility::CreateAddress(struct sockaddr *sa,socklen_
|
||||
return std::auto_ptr<SocketAddress>(NULL);
|
||||
}
|
||||
|
||||
|
||||
bool Utility::u2ip(const std::string& host, struct sockaddr_in& sa, int ai_flags)
|
||||
{
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
@@ -631,7 +595,6 @@ bool Utility::u2ip(const std::string& host, struct sockaddr_in& sa, int ai_flags
|
||||
#endif // NO_GETADDRINFO
|
||||
}
|
||||
|
||||
|
||||
#ifdef ENABLE_IPV6
|
||||
#ifdef IPPROTO_IPV6
|
||||
bool Utility::u2ip(const std::string& host, struct sockaddr_in6& sa, int ai_flags)
|
||||
@@ -747,14 +710,12 @@ bool Utility::u2ip(const std::string& host, struct sockaddr_in6& sa, int ai_flag
|
||||
#endif // IPPROTO_IPV6
|
||||
#endif // ENABLE_IPV6
|
||||
|
||||
|
||||
bool Utility::reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostname, int flags)
|
||||
{
|
||||
std::string service;
|
||||
return Utility::reverse(sa, sa_len, hostname, service, flags);
|
||||
}
|
||||
|
||||
|
||||
bool Utility::reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostname, std::string& service, int flags)
|
||||
{
|
||||
hostname = "";
|
||||
@@ -870,7 +831,6 @@ bool Utility::reverse(struct sockaddr *sa, socklen_t sa_len, std::string& hostna
|
||||
#endif // NO_GETADDRINFO
|
||||
}
|
||||
|
||||
|
||||
bool Utility::u2service(const std::string& name, int& service, int ai_flags)
|
||||
{
|
||||
#ifdef NO_GETADDRINFO
|
||||
@@ -903,7 +863,6 @@ bool Utility::u2service(const std::string& name, int& service, int ai_flags)
|
||||
#endif // NO_GETADDRINFO
|
||||
}
|
||||
|
||||
|
||||
unsigned long Utility::ThreadID()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
@@ -913,7 +872,6 @@ unsigned long Utility::ThreadID()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::ToLower(const std::string& str)
|
||||
{
|
||||
std::string r;
|
||||
@@ -927,7 +885,6 @@ std::string Utility::ToLower(const std::string& str)
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::ToUpper(const std::string& str)
|
||||
{
|
||||
std::string r;
|
||||
@@ -941,7 +898,6 @@ std::string Utility::ToUpper(const std::string& str)
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::ToString(double d)
|
||||
{
|
||||
char tmp[100];
|
||||
@@ -949,14 +905,12 @@ std::string Utility::ToString(double d)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
unsigned long Utility::Rnd()
|
||||
{
|
||||
static Utility::Rng generator( (unsigned long)time(NULL) );
|
||||
return generator.Get();
|
||||
}
|
||||
|
||||
|
||||
Utility::Rng::Rng(unsigned long seed) : m_value( 0 )
|
||||
{
|
||||
m_tmp[0]= seed & 0xffffffffUL;
|
||||
@@ -966,7 +920,6 @@ Utility::Rng::Rng(unsigned long seed) : m_value( 0 )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned long Utility::Rng::Get()
|
||||
{
|
||||
unsigned long val = m_tmp[m_value];
|
||||
@@ -987,14 +940,11 @@ unsigned long Utility::Rng::Get()
|
||||
}
|
||||
unsigned long s = TWIST(m_tmp, TWIST_LEN - 1, 0);
|
||||
m_tmp[TWIST_LEN - 1] = m_tmp[TWIST_IA - 1] ^ (s >> 1) ^ MAGIC_TWIST(s);
|
||||
|
||||
m_value = 0;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
#ifdef SOCKETS_NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user