[Sync] Project sync

This commit is contained in:
Antz 2014-10-11 08:28:58 +01:00 committed by Antz
parent f1c9e0f94b
commit 86690df496
22 changed files with 1731 additions and 385 deletions

View file

@ -52,12 +52,24 @@ class ObjectGuid;
class ByteBufferException
{
public:
/**
* @brief
*
* @param _add
* @param _pos
* @param _esize
* @param _size
*/
ByteBufferException(bool _add, size_t _pos, size_t _esize, size_t _size)
: add(_add), pos(_pos), esize(_esize), size(_size)
{
PrintPosError();
}
/**
* @brief
*
*/
void PrintPosError() const
{
char const* traceStr;
@ -76,10 +88,10 @@ class ByteBufferException
traceStr ? "\n" : "", traceStr ? traceStr : "");
}
private:
bool add;
size_t pos;
size_t esize;
size_t size;
bool add; /**< TODO */
size_t pos; /**< TODO */
size_t esize; /**< TODO */
size_t size; /**< TODO */
};
class BitStream
@ -124,11 +136,23 @@ class BitStream
};
template<class T>
/**
* @brief
*
*/
struct Unused
{
/**
* @brief
*
*/
Unused() {}
};
/**
* @brief
*
*/
class ByteBuffer
{
public:
@ -152,6 +176,10 @@ class ByteBuffer
{
}
/**
* @brief
*
*/
void clear()
{
_storage.clear();
@ -325,68 +353,132 @@ class ByteBuffer
put(pos, (uint8*)&value, sizeof(value));
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(uint8 value)
{
append<uint8>(value);
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(uint16 value)
{
append<uint16>(value);
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(uint32 value)
{
append<uint32>(value);
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(uint64 value)
{
append<uint64>(value);
return *this;
}
// signed as in 2e complement
/**
* @brief signed as in 2e complement
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(int8 value)
{
append<int8>(value);
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(int16 value)
{
append<int16>(value);
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(int32 value)
{
append<int32>(value);
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(int64 value)
{
append<int64>(value);
return *this;
}
// floating points
/**
* @brief floating points
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(float value)
{
append<float>(value);
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(double value)
{
append<double>(value);
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(const std::string& value)
{
append((uint8 const*)value.c_str(), value.length());
@ -394,6 +486,12 @@ class ByteBuffer
return *this;
}
/**
* @brief
*
* @param str
* @return ByteBuffer &operator
*/
ByteBuffer& operator<<(const char* str)
{
append((uint8 const*)str, str ? strlen(str) : 0);
@ -401,73 +499,144 @@ class ByteBuffer
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(bool& value)
{
value = read<char>() > 0 ? true : false;
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(uint8& value)
{
value = read<uint8>();
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(uint16& value)
{
value = read<uint16>();
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(uint32& value)
{
value = read<uint32>();
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(uint64& value)
{
value = read<uint64>();
return *this;
}
// signed as in 2e complement
/**
* @brief signed as in 2e complement
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(int8& value)
{
value = read<int8>();
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(int16& value)
{
value = read<int16>();
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(int32& value)
{
value = read<int32>();
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(int64& value)
{
value = read<int64>();
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(float& value)
{
value = read<float>();
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(double& value)
{
value = read<double>();
return *this;
}
/**
* @brief
*
* @param value
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(std::string& value)
{
value.clear();
@ -475,13 +644,19 @@ class ByteBuffer
{
char c = read<char>();
if (c == 0)
break;
{ break; }
value += c;
}
return *this;
}
template<class T>
/**
* @brief
*
* @param
* @return ByteBuffer &operator >>
*/
ByteBuffer& operator>>(Unused<T> const&)
{
return read_skip<T>();
@ -501,8 +676,19 @@ class ByteBuffer
return _storage[pos];
}
/**
* @brief
*
* @return size_t
*/
size_t rpos() const { return _rpos; }
/**
* @brief
*
* @param rpos_
* @return size_t
*/
size_t rpos(size_t rpos_)
{
_rpos = rpos_;
@ -516,6 +702,12 @@ class ByteBuffer
size_t wpos() const { return _wpos; }
/**
* @brief
*
* @param wpos_
* @return size_t
*/
size_t wpos(size_t wpos_)
{
_wpos = wpos_;
@ -539,6 +731,11 @@ class ByteBuffer
return *this;
}
/**
* @brief
*
* @return T
*/
template <typename T> T read()
{
ResetBitReader();
@ -547,10 +744,16 @@ class ByteBuffer
return r;
}
/**
* @brief
*
* @param pos
* @return T
*/
template <typename T> T read(size_t pos) const
{
if(pos + sizeof(T) > size())
throw ByteBufferException(false, pos, sizeof(T), size());
if (pos + sizeof(T) > size())
{ throw ByteBufferException(false, pos, sizeof(T), size()); }
T val = *((T const*)&_storage[pos]);
EndianConvert(val);
return val;
@ -567,15 +770,20 @@ class ByteBuffer
return *this;
}
/**
* @brief
*
* @return uint64
*/
uint64 readPackGUID()
{
uint64 guid = 0;
uint8 guidmark = 0;
(*this) >> guidmark;
for(int i = 0; i < 8; ++i)
for (int i = 0; i < 8; ++i)
{
if(guidmark & (uint8(1) << i))
if (guidmark & (uint8(1) << i))
{
uint8 bit;
(*this) >> bit;

View file

@ -1,3 +1,26 @@
# This code is part of MaNGOS. Contributor & Copyright details are in AUTHORS/THANKS.
#
# ***** BEGIN GPL LICENSE BLOCK *****
#
# 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
#
# ***** END GPL LICENSE BLOCK *****
#
# World of Warcraft, and all World of Warcraft or Warcraft art, images,
# and lore are copyrighted by Blizzard Entertainment, Inc.
set(LIBRARY_NAME shared)
set(SRC_GRP_AUTH

View file

@ -57,7 +57,7 @@ LocaleConstant GetLocaleByName(const std::string& name)
{
for (LocaleNameStr const* itr = &fullLocaleNameList[0]; itr->name; ++itr)
if (name == itr->name)
return itr->locale;
{ return itr->locale; }
return LOCALE_enUS; // including enGB case
}

View file

@ -103,6 +103,10 @@
// Old ACE versions (pre-ACE-5.5.4) not have this type (add for allow use at Unix side external old ACE versions)
#if PLATFORM != PLATFORM_WINDOWS
# ifndef ACE_OFF_T
/**
* @brief
*
*/
typedef off_t ACE_OFF_T;
# endif
#endif
@ -154,6 +158,12 @@ typedef off_t ACE_OFF_T;
#define SIZEFMTD ACE_SIZE_T_FORMAT_SPECIFIER
/**
* @brief
*
* @param f
* @return float
*/
inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
#define atol(a) strtoul( a, NULL, 10)
@ -169,6 +179,10 @@ inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
#define PAIR32_HIPART(x) (uint16)((uint32(x) >> 16) & 0x0000FFFF)
#define PAIR32_LOPART(x) (uint16)(uint32(x) & 0x0000FFFF)
/**
* @brief
*
*/
enum TimeConstants
{
MINUTE = 60,
@ -180,6 +194,10 @@ enum TimeConstants
IN_MILLISECONDS = 1000
};
/**
* @brief
*
*/
enum AccountTypes
{
SEC_PLAYER = 0,
@ -189,7 +207,10 @@ enum AccountTypes
SEC_CONSOLE = 4 // must be always last in list, accounts must have less security level always also
};
// Used in mangosd/realmd
/**
* @brief Used in mangosd/realmd
*
*/
enum RealmFlags
{
REALM_FLAG_NONE = 0x00,
@ -203,6 +224,10 @@ enum RealmFlags
REALM_FLAG_FULL = 0x80
};
/**
* @brief
*
*/
enum LocaleConstant
{
LOCALE_enUS = 0, // also enGB
@ -218,20 +243,35 @@ enum LocaleConstant
#define MAX_LOCALE 9
/**
* @brief
*
* @param name
* @return LocaleConstant
*/
LocaleConstant GetLocaleByName(const std::string& name);
extern char const* localeNames[MAX_LOCALE];
extern char const* localeNames[MAX_LOCALE]; /**< TODO */
/**
* @brief
*
*/
struct LocaleNameStr
{
char const* name;
LocaleConstant locale;
char const* name; /**< TODO */
LocaleConstant locale; /**< TODO */
};
// used for iterate all names including alternative
extern LocaleNameStr const fullLocaleNameList[];
extern LocaleNameStr const fullLocaleNameList[]; /**< used for iterate all names including alternative */
// operator new[] based version of strdup() function! Release memory by using operator delete[] !
/**
* @brief operator new[] based version of strdup() function! Release memory by using operator delete[] !
*
* @param source
* @return char
*/
inline char* mangos_strdup(const char* source)
{
char* dest = new char[strlen(source) + 1];

View file

@ -38,39 +38,39 @@
#ifdef HAVE_ACE_STACK_TRACE_H
// Normal assert.
#define WPError(CONDITION) \
if (!(CONDITION)) \
{ \
ACE_Stack_Trace st; \
printf("%s:%i: Error: Assertion in %s failed: %s\nStack Trace:\n%s", \
__FILE__, __LINE__, __FUNCTION__, STRINGIZE(CONDITION), st.c_str()); \
assert(STRINGIZE(CONDITION) && 0); \
}
if (!(CONDITION)) \
{ \
ACE_Stack_Trace st; \
printf("%s:%i: Error: Assertion in %s failed: %s\nStack Trace:\n%s", \
__FILE__, __LINE__, __FUNCTION__, STRINGIZE(CONDITION), st.c_str()); \
assert(STRINGIZE(CONDITION) && 0); \
}
// Just warn.
#define WPWarning(CONDITION) \
if (!(CONDITION)) \
{ \
ACE_Stack_Trace st; \
printf("%s:%i: Warning: Assertion in %s failed: %s\nStack Trace:\n%s",\
__FILE__, __LINE__, __FUNCTION__, STRINGIZE(CONDITION), st.c_str()); \
}
if (!(CONDITION)) \
{ \
ACE_Stack_Trace st; \
printf("%s:%i: Warning: Assertion in %s failed: %s\nStack Trace:\n%s",\
__FILE__, __LINE__, __FUNCTION__, STRINGIZE(CONDITION), st.c_str()); \
}
#else
// Normal assert.
#define WPError(CONDITION) \
if (!(CONDITION)) \
{ \
printf("%s:%i: Error: Assertion in %s failed: %s", \
__FILE__, __LINE__, __FUNCTION__, STRINGIZE(CONDITION)); \
assert(STRINGIZE(CONDITION) && 0); \
}
if (!(CONDITION)) \
{ \
printf("%s:%i: Error: Assertion in %s failed: %s", \
__FILE__, __LINE__, __FUNCTION__, STRINGIZE(CONDITION)); \
assert(STRINGIZE(CONDITION) && 0); \
}
// Just warn.
#define WPWarning(CONDITION) \
if (!(CONDITION)) \
{ \
printf("%s:%i: Warning: Assertion in %s failed: %s",\
__FILE__, __LINE__, __FUNCTION__, STRINGIZE(CONDITION)); \
}
if (!(CONDITION)) \
{ \
printf("%s:%i: Warning: Assertion in %s failed: %s",\
__FILE__, __LINE__, __FUNCTION__, STRINGIZE(CONDITION)); \
}
#endif
#ifdef MANGOS_DEBUG

View file

@ -33,45 +33,61 @@
namespace ACE_Based
{
template <class T, class LockType, typename StorageType = std::deque<T> >
template < class T, class LockType, typename StorageType = std::deque<T> >
/**
* @brief
*
*/
class LockedQueue
{
//! Lock access to the queue.
LockType _lock;
LockType _lock; /**< Lock access to the queue. */
//! Storage backing the queue.
StorageType _queue;
StorageType _queue; /**< Storage backing the queue. */
//! Cancellation flag.
/*volatile*/ bool _canceled;
/*volatile*/ bool _canceled; /**< Cancellation flag. */
public:
//! Create a LockedQueue.
/**
* @brief Create a LockedQueue.
*
*/
LockedQueue()
: _canceled(false)
{
}
//! Destroy a LockedQueue.
/**
* @brief Destroy a LockedQueue.
*
*/
virtual ~LockedQueue()
{
}
//! Adds an item to the queue.
/**
* @brief Adds an item to the queue.
*
* @param item
*/
void add(const T& item)
{
ACE_Guard<LockType> g(this->_lock);
_queue.push_back(item);
}
//! Gets the next result in the queue, if any.
/**
* @brief Gets the next result in the queue, if any.
*
* @param result
* @return bool
*/
bool next(T& result)
{
ACE_GUARD_RETURN(LockType, g, this->_lock, false);
if (_queue.empty())
return false;
{ return false; }
result = _queue.front();
_queue.pop_front();
@ -80,22 +96,33 @@ namespace ACE_Based
}
template<class Checker>
/**
* @brief
*
* @param result
* @param check
* @return bool
*/
bool next(T& result, Checker& check)
{
ACE_GUARD_RETURN(LockType, g, this->_lock, false);
if (_queue.empty())
return false;
{ return false; }
result = _queue.front();
if (!check.Process(result))
return false;
{ return false; }
_queue.pop_front();
return true;
}
//! Peeks at the top of the queue. Remember to unlock after use.
/**
* @brief Peeks at the top of the queue. Remember to unlock after use.
*
* @return T
*/
T& peek()
{
lock();
@ -105,33 +132,50 @@ namespace ACE_Based
return result;
}
//! Cancels the queue.
/**
* @brief Cancels the queue.
*
*/
void cancel()
{
ACE_Guard<LockType> g(this->_lock);
_canceled = true;
}
//! Checks if the queue is cancelled.
/**
* @brief Checks if the queue is cancelled.
*
* @return bool
*/
bool cancelled()
{
ACE_Guard<LockType> g(this->_lock);
return _canceled;
}
//! Locks the queue for access.
/**
* @brief Locks the queue for access.
*
*/
void lock()
{
this->_lock.acquire();
}
//! Unlocks the queue.
/**
* @brief Unlocks the queue.
*
*/
void unlock()
{
this->_lock.release();
}
///! Checks if we're empty or not with locks held
/**
* @brief Checks if we're empty or not with locks held
*
* @return bool
*/
bool empty()
{
ACE_Guard<LockType> g(this->_lock);

View file

@ -96,14 +96,14 @@ void Log::InitColors(const std::string& str)
ss >> color[i];
if (!ss)
return;
{ return; }
if (color[i] < 0 || color[i] >= Color_count)
return;
{ return; }
}
for (int i = 0; i < LogType_count; ++i)
m_colors[i] = Color(color[i]);
{ m_colors[i] = Color(color[i]); }
m_colored = true;
}
@ -199,9 +199,9 @@ void Log::SetLogLevel(char* level)
int32 newLevel = atoi((char*)level);
if (newLevel < LOG_LVL_MINIMAL)
newLevel = LOG_LVL_MINIMAL;
{ newLevel = LOG_LVL_MINIMAL; }
else if (newLevel > LOG_LVL_DEBUG)
newLevel = LOG_LVL_DEBUG;
{ newLevel = LOG_LVL_DEBUG; }
m_logLevel = LogLevel(newLevel);
@ -213,9 +213,9 @@ void Log::SetLogFileLevel(char* level)
int32 newLevel = atoi((char*)level);
if (newLevel < LOG_LVL_MINIMAL)
newLevel = LOG_LVL_MINIMAL;
{ newLevel = LOG_LVL_MINIMAL; }
else if (newLevel > LOG_LVL_DEBUG)
newLevel = LOG_LVL_DEBUG;
{ newLevel = LOG_LVL_DEBUG; }
m_logFileLevel = LogLevel(newLevel);
@ -229,7 +229,7 @@ void Log::Initialize()
if (!m_logsDir.empty())
{
if ((m_logsDir.at(m_logsDir.length() - 1) != '/') && (m_logsDir.at(m_logsDir.length() - 1) != '\\'))
m_logsDir.append("/");
{ m_logsDir.append("/"); }
}
m_logsTimestamp = "_" + GetTimestampStr();
@ -239,7 +239,7 @@ void Log::Initialize()
m_gmlog_per_account = sConfig.GetBoolDefault("GmLogPerAccount", false);
if (!m_gmlog_per_account)
gmLogfile = openLogFile("GMLogFile", "GmLogTimestamp", "a");
{ gmLogfile = openLogFile("GMLogFile", "GmLogTimestamp", "a"); }
else
{
// GM log settings for per account case
@ -252,7 +252,7 @@ void Log::Initialize()
if (dot_pos != m_gmlog_filename_format.npos)
{
if (m_gmlog_timestamp)
m_gmlog_filename_format.insert(dot_pos, m_logsTimestamp);
{ m_gmlog_filename_format.insert(dot_pos, m_logsTimestamp); }
m_gmlog_filename_format.insert(dot_pos, "_#%u");
}
@ -261,7 +261,7 @@ void Log::Initialize()
m_gmlog_filename_format += "_#%u";
if (m_gmlog_timestamp)
m_gmlog_filename_format += m_logsTimestamp;
{ m_gmlog_filename_format += m_logsTimestamp; }
}
m_gmlog_filename_format = m_logsDir + m_gmlog_filename_format;
@ -284,7 +284,7 @@ void Log::Initialize()
for (int i = 0; i < LOG_FILTER_COUNT; ++i)
if (*logFilterData[i].name)
if (sConfig.GetBoolDefault(logFilterData[i].configName, logFilterData[i].defaultState))
m_logFilter |= (1 << i);
{ m_logFilter |= (1 << i); }
// Char log settings
m_charLog_Dump = sConfig.GetBoolDefault("CharLogDump", false);
@ -294,15 +294,15 @@ FILE* Log::openLogFile(char const* configFileName, char const* configTimeStampFl
{
std::string logfn = sConfig.GetStringDefault(configFileName, "");
if (logfn.empty())
return NULL;
{ return NULL; }
if (configTimeStampFlag && sConfig.GetBoolDefault(configTimeStampFlag, false))
{
size_t dot_pos = logfn.find_last_of(".");
if (dot_pos != logfn.npos)
logfn.insert(dot_pos, m_logsTimestamp);
{ logfn.insert(dot_pos, m_logsTimestamp); }
else
logfn += m_logsTimestamp;
{ logfn += m_logsTimestamp; }
}
return fopen((m_logsDir + logfn).c_str(), mode);
@ -311,7 +311,7 @@ FILE* Log::openLogFile(char const* configFileName, char const* configTimeStampFl
FILE* Log::openGmlogPerAccount(uint32 account)
{
if (m_gmlog_filename_format.empty())
return NULL;
{ return NULL; }
char namebuf[MANGOS_PATH_MAX];
snprintf(namebuf, MANGOS_PATH_MAX, m_gmlog_filename_format.c_str(), account);
@ -362,7 +362,7 @@ std::string Log::GetTimestampStr()
void Log::outString()
{
if (m_includeTime)
outTime();
{ outTime(); }
printf("\n");
if (logfile)
{
@ -377,13 +377,13 @@ void Log::outString()
void Log::outString(const char* str, ...)
{
if (!str)
return;
{ return; }
if (m_colored)
SetColor(true, m_colors[LogNormal]);
{ SetColor(true, m_colors[LogNormal]); }
if (m_includeTime)
outTime();
{ outTime(); }
va_list ap;
@ -392,7 +392,7 @@ void Log::outString(const char* str, ...)
va_end(ap);
if (m_colored)
ResetColor(true);
{ ResetColor(true); }
printf("\n");
@ -414,13 +414,13 @@ void Log::outString(const char* str, ...)
void Log::outError(const char* err, ...)
{
if (!err)
return;
{ return; }
if (m_colored)
SetColor(false, m_colors[LogError]);
{ SetColor(false, m_colors[LogError]); }
if (m_includeTime)
outTime();
{ outTime(); }
va_list ap;
@ -429,7 +429,7 @@ void Log::outError(const char* err, ...)
va_end(ap);
if (m_colored)
ResetColor(false);
{ ResetColor(false); }
fprintf(stderr, "\n");
if (logfile)
@ -451,7 +451,7 @@ void Log::outError(const char* err, ...)
void Log::outErrorDb()
{
if (m_includeTime)
outTime();
{ outTime(); }
fprintf(stderr, "\n");
@ -475,13 +475,13 @@ void Log::outErrorDb()
void Log::outErrorDb(const char* err, ...)
{
if (!err)
return;
{ return; }
if (m_colored)
SetColor(false, m_colors[LogError]);
{ SetColor(false, m_colors[LogError]); }
if (m_includeTime)
outTime();
{ outTime(); }
va_list ap;
@ -490,7 +490,7 @@ void Log::outErrorDb(const char* err, ...)
va_end(ap);
if (m_colored)
ResetColor(false);
{ ResetColor(false); }
fprintf(stderr, "\n");
@ -526,7 +526,7 @@ void Log::outErrorDb(const char* err, ...)
void Log::outErrorEventAI()
{
if (m_includeTime)
outTime();
{ outTime(); }
fprintf(stderr, "\n");
@ -550,13 +550,13 @@ void Log::outErrorEventAI()
void Log::outErrorEventAI(const char* err, ...)
{
if (!err)
return;
{ return; }
if (m_colored)
SetColor(false, m_colors[LogError]);
{ SetColor(false, m_colors[LogError]); }
if (m_includeTime)
outTime();
{ outTime(); }
va_list ap;
@ -565,7 +565,7 @@ void Log::outErrorEventAI(const char* err, ...)
va_end(ap);
if (m_colored)
ResetColor(false);
{ ResetColor(false); }
fprintf(stderr, "\n");
@ -601,15 +601,15 @@ void Log::outErrorEventAI(const char* err, ...)
void Log::outBasic(const char* str, ...)
{
if (!str)
return;
{ return; }
if (m_logLevel >= LOG_LVL_BASIC)
{
if (m_colored)
SetColor(true, m_colors[LogDetails]);
{ SetColor(true, m_colors[LogDetails]); }
if (m_includeTime)
outTime();
{ outTime(); }
va_list ap;
va_start(ap, str);
@ -617,7 +617,7 @@ void Log::outBasic(const char* str, ...)
va_end(ap);
if (m_colored)
ResetColor(true);
{ ResetColor(true); }
printf("\n");
}
@ -639,15 +639,15 @@ void Log::outBasic(const char* str, ...)
void Log::outDetail(const char* str, ...)
{
if (!str)
return;
{ return; }
if (m_logLevel >= LOG_LVL_DETAIL)
{
if (m_colored)
SetColor(true, m_colors[LogDetails]);
{ SetColor(true, m_colors[LogDetails]); }
if (m_includeTime)
outTime();
{ outTime(); }
va_list ap;
va_start(ap, str);
@ -655,7 +655,7 @@ void Log::outDetail(const char* str, ...)
va_end(ap);
if (m_colored)
ResetColor(true);
{ ResetColor(true); }
printf("\n");
}
@ -679,15 +679,15 @@ void Log::outDetail(const char* str, ...)
void Log::outDebug(const char* str, ...)
{
if (!str)
return;
{ return; }
if (m_logLevel >= LOG_LVL_DEBUG)
{
if (m_colored)
SetColor(true, m_colors[LogDebug]);
{ SetColor(true, m_colors[LogDebug]); }
if (m_includeTime)
outTime();
{ outTime(); }
va_list ap;
va_start(ap, str);
@ -695,7 +695,7 @@ void Log::outDebug(const char* str, ...)
va_end(ap);
if (m_colored)
ResetColor(true);
{ ResetColor(true); }
printf("\n");
}
@ -719,15 +719,15 @@ void Log::outDebug(const char* str, ...)
void Log::outCommand(uint32 account, const char* str, ...)
{
if (!str)
return;
{ return; }
if (m_logLevel >= LOG_LVL_DETAIL)
{
if (m_colored)
SetColor(true, m_colors[LogDetails]);
{ SetColor(true, m_colors[LogDetails]); }
if (m_includeTime)
outTime();
{ outTime(); }
va_list ap;
va_start(ap, str);
@ -735,7 +735,7 @@ void Log::outCommand(uint32 account, const char* str, ...)
va_end(ap);
if (m_colored)
ResetColor(true);
{ ResetColor(true); }
printf("\n");
}
@ -781,7 +781,7 @@ void Log::outCommand(uint32 account, const char* str, ...)
void Log::outChar(const char* str, ...)
{
if (!str)
return;
{ return; }
if (charLogfile)
{
@ -798,7 +798,7 @@ void Log::outChar(const char* str, ...)
void Log::outErrorScriptLib()
{
if (m_includeTime)
outTime();
{ outTime(); }
fprintf(stderr, "\n");
@ -806,9 +806,9 @@ void Log::outErrorScriptLib()
{
outTimestamp(logfile);
if (m_scriptLibName)
fprintf(logfile, "<%s ERROR:> ", m_scriptLibName);
{ fprintf(logfile, "<%s ERROR:> ", m_scriptLibName); }
else
fprintf(logfile, "<Scripting Library ERROR>: ");
{ fprintf(logfile, "<Scripting Library ERROR>: "); }
fflush(logfile);
}
@ -825,13 +825,13 @@ void Log::outErrorScriptLib()
void Log::outErrorScriptLib(const char* err, ...)
{
if (!err)
return;
{ return; }
if (m_colored)
SetColor(false, m_colors[LogError]);
{ SetColor(false, m_colors[LogError]); }
if (m_includeTime)
outTime();
{ outTime(); }
va_list ap;
@ -840,7 +840,7 @@ void Log::outErrorScriptLib(const char* err, ...)
va_end(ap);
if (m_colored)
ResetColor(false);
{ ResetColor(false); }
fprintf(stderr, "\n");
@ -848,9 +848,9 @@ void Log::outErrorScriptLib(const char* err, ...)
{
outTimestamp(logfile);
if (m_scriptLibName)
fprintf(logfile, "<%s ERROR>: ", m_scriptLibName);
{ fprintf(logfile, "<%s ERROR>: ", m_scriptLibName); }
else
fprintf(logfile, "<Scripting Library ERROR>: ");
{ fprintf(logfile, "<Scripting Library ERROR>: "); }
va_start(ap, err);
vfprintf(logfile, err, ap);
@ -879,7 +879,7 @@ void Log::outErrorScriptLib(const char* err, ...)
void Log::outWorldPacketDump(uint32 socket, uint32 opcode, char const* opcodeName, ByteBuffer const* packet, bool incoming)
{
if (!worldLogfile)
return;
{ return; }
ACE_GUARD(ACE_Thread_Mutex, GuardObj, m_worldLogMtx);
@ -893,7 +893,7 @@ void Log::outWorldPacketDump(uint32 socket, uint32 opcode, char const* opcodeNam
while (p < packet->size())
{
for (size_t j = 0; j < 16 && p < packet->size(); ++j)
fprintf(worldLogfile, "%.2X ", (*packet)[p++]);
{ fprintf(worldLogfile, "%.2X ", (*packet)[p++]); }
fprintf(worldLogfile, "\n");
}
@ -914,7 +914,7 @@ void Log::outCharDump(const char* str, uint32 account_id, uint32 guid, const cha
void Log::outRALog(const char* str, ...)
{
if (!str)
return;
{ return; }
if (raLogfile)
{
@ -958,7 +958,7 @@ void Log::setScriptLibraryErrorFile(char const* fname, char const* libName)
m_scriptLibName = libName;
if (scriptErrLogFile)
fclose(scriptErrLogFile);
{ fclose(scriptErrLogFile); }
if (!fname)
{
@ -974,7 +974,7 @@ void Log::setScriptLibraryErrorFile(char const* fname, char const* libName)
void outstring_log(const char* str, ...)
{
if (!str)
return;
{ return; }
char buf[256];
va_list ap;
@ -988,7 +988,7 @@ void outstring_log(const char* str, ...)
void detail_log(const char* str, ...)
{
if (!str)
return;
{ return; }
char buf[256];
va_list ap;
@ -1002,7 +1002,7 @@ void detail_log(const char* str, ...)
void debug_log(const char* str, ...)
{
if (!str)
return;
{ return; }
char buf[256];
va_list ap;
@ -1016,7 +1016,7 @@ void debug_log(const char* str, ...)
void error_log(const char* str, ...)
{
if (!str)
return;
{ return; }
char buf[256];
va_list ap;
@ -1030,7 +1030,7 @@ void error_log(const char* str, ...)
void error_db_log(const char* str, ...)
{
if (!str)
return;
{ return; }
char buf[256];
va_list ap;
@ -1049,7 +1049,7 @@ void setScriptLibraryErrorFile(char const* fname, char const* libName)
void script_error_log(const char* str, ...)
{
if (!str)
return;
{ return; }
char buf[256];
va_list ap;

View file

@ -31,15 +31,22 @@
class Config;
class ByteBuffer;
/**
* @brief various levels for logging
*
*/
enum LogLevel
{
LOG_LVL_MINIMAL = 0, // unconditional and errors
LOG_LVL_MINIMAL = 0,
LOG_LVL_BASIC = 1,
LOG_LVL_DETAIL = 2,
LOG_LVL_DEBUG = 3
};
// bitmask (not forgot update logFilterData content)
/**
* @brief bitmask (not forgot update logFilterData content)
*
*/
enum LogFilters
{
LOG_FILTER_TRANSPORT_MOVES = 0x000001, // 0 any related to transport moves
@ -66,15 +73,23 @@ enum LogFilters
#define LOG_FILTER_COUNT 20
/**
* @brief
*
*/
struct LogFilterData
{
char const* name;
char const* configName;
bool defaultState;
char const* name; /**< TODO */
char const* configName; /**< TODO */
bool defaultState; /**< TODO */
};
extern LogFilterData logFilterData[LOG_FILTER_COUNT];
extern LogFilterData logFilterData[LOG_FILTER_COUNT]; /**< TODO */
/**
* @brief
*
*/
enum Color
{
BLACK,
@ -94,135 +109,324 @@ enum Color
WHITE
};
const int Color_count = int(WHITE) + 1;
const int Color_count = int(WHITE) + 1; /**< TODO */
/**
* @brief
*
*/
class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Thread_Mutex> >
{
friend class MaNGOS::OperatorNew<Log>;
/**
* @brief
*
*/
Log();
/**
* @brief
*
*/
~Log()
{
if (logfile != NULL)
fclose(logfile);
{ fclose(logfile); }
logfile = NULL;
if (gmLogfile != NULL)
fclose(gmLogfile);
{ fclose(gmLogfile); }
gmLogfile = NULL;
if (charLogfile != NULL)
fclose(charLogfile);
{ fclose(charLogfile); }
charLogfile = NULL;
if (dberLogfile != NULL)
fclose(dberLogfile);
{ fclose(dberLogfile); }
dberLogfile = NULL;
if (eventAiErLogfile != NULL)
fclose(eventAiErLogfile);
{ fclose(eventAiErLogfile); }
eventAiErLogfile = NULL;
if (scriptErrLogFile != NULL)
fclose(scriptErrLogFile);
{ fclose(scriptErrLogFile); }
scriptErrLogFile = NULL;
if (raLogfile != NULL)
fclose(raLogfile);
{ fclose(raLogfile); }
raLogfile = NULL;
if (worldLogfile != NULL)
fclose(worldLogfile);
{ fclose(worldLogfile); }
worldLogfile = NULL;
}
public:
/**
* @brief
*
*/
void Initialize();
/**
* @brief
*
* @param init_str
*/
void InitColors(const std::string& init_str);
/**
* @brief
*
* @param account
* @param str...
*/
void outCommand(uint32 account, const char* str, ...) ATTR_PRINTF(3, 4);
void outString(); // any log level
// any log level
/**
* @brief any log level
*
*/
void outString();
/**
* @brief any log level
*
* @param str...
*/
void outString(const char* str, ...) ATTR_PRINTF(2, 3);
// any log level
/**
* @brief any log level
*
* @param err...
*/
void outError(const char* err, ...) ATTR_PRINTF(2, 3);
// log level >= 1
/**
* @brief log level >= 1
*
* @param str...
*/
void outBasic(const char* str, ...) ATTR_PRINTF(2, 3);
// log level >= 2
/**
* @brief log level >= 2
*
* @param str...
*/
void outDetail(const char* str, ...) ATTR_PRINTF(2, 3);
// log level >= 3
/**
* @brief log level >= 3
*
* @param str...
*/
void outDebug(const char* str, ...) ATTR_PRINTF(2, 3);
void outErrorDb(); // any log level
// any log level
/**
* @brief any log level
*
*/
void outErrorDb();
/**
* @brief any log level
*
* @param str...
*/
void outErrorDb(const char* str, ...) ATTR_PRINTF(2, 3);
// any log level
/**
* @brief any log level
*
* @param str...
*/
void outChar(const char* str, ...) ATTR_PRINTF(2, 3);
void outErrorEventAI(); // any log level
// any log level
/**
* @brief any log level
*
*/
void outErrorEventAI();
/**
* @brief any log level
*
* @param str...
*/
void outErrorEventAI(const char* str, ...) ATTR_PRINTF(2, 3);
void outErrorScriptLib(); // any log level
// any log level
/**
* @brief any log level
*
*/
void outErrorScriptLib();
/**
* @brief any log level
*
* @param str...
*/
void outErrorScriptLib(const char* str, ...) ATTR_PRINTF(2, 3);
/**
* @brief any log level
*
* @param socket
* @param opcode
* @param opcodeName
* @param packet
* @param incoming
*/
void outWorldPacketDump(uint32 socket, uint32 opcode, char const* opcodeName, ByteBuffer const* packet, bool incoming);
// any log level
/**
* @brief any log level
*
* @param str
* @param account_id
* @param guid
* @param name
*/
void outCharDump(const char* str, uint32 account_id, uint32 guid, const char* name);
/**
* @brief
*
* @param str...
*/
void outRALog(const char* str, ...) ATTR_PRINTF(2, 3);
/**
* @brief
*
* @return uint32
*/
uint32 GetLogLevel() const { return m_logLevel; }
/**
* @brief
*
* @param Level
*/
void SetLogLevel(char* Level);
/**
* @brief
*
* @param Level
*/
void SetLogFileLevel(char* Level);
/**
* @brief
*
* @param stdout_stream
* @param color
*/
void SetColor(bool stdout_stream, Color color);
/**
* @brief
*
* @param stdout_stream
*/
void ResetColor(bool stdout_stream);
/**
* @brief
*
*/
void outTime();
/**
* @brief
*
* @param file
*/
static void outTimestamp(FILE* file);
/**
* @brief
*
* @return std::string
*/
static std::string GetTimestampStr();
/**
* @brief
*
* @param filter
* @return bool
*/
bool HasLogFilter(uint32 filter) const { return m_logFilter & filter; }
void SetLogFilter(LogFilters filter, bool on) { if (on) m_logFilter |= filter; else m_logFilter &= ~filter; }
/**
* @brief
*
* @param filter
* @param on
*/
void SetLogFilter(LogFilters filter, bool on) { if (on) { m_logFilter |= filter; } else { m_logFilter &= ~filter; } }
/**
* @brief
*
* @param loglvl
* @return bool
*/
bool HasLogLevelOrHigher(LogLevel loglvl) const { return m_logLevel >= loglvl || (m_logFileLevel >= loglvl && logfile); }
/**
* @brief
*
* @return bool
*/
bool IsOutCharDump() const { return m_charLog_Dump; }
/**
* @brief
*
* @return bool
*/
bool IsIncludeTime() const { return m_includeTime; }
/**
* @brief
*
*/
static void WaitBeforeContinueIfNeed();
// Set filename for scriptlibrary error output
/**
* @brief Set filename for scriptlibrary error output
*
* @param fname
* @param libName
*/
void setScriptLibraryErrorFile(char const* fname, char const* libName);
private:
/**
* @brief
*
* @param configFileName
* @param configTimeStampFlag
* @param mode
* @return FILE
*/
FILE* openLogFile(char const* configFileName, char const* configTimeStampFlag, char const* mode);
/**
* @brief
*
* @param account
* @return FILE
*/
FILE* openGmlogPerAccount(uint32 account);
FILE* raLogfile;
FILE* logfile;
FILE* gmLogfile;
FILE* charLogfile;
FILE* dberLogfile;
FILE* eventAiErLogfile;
FILE* scriptErrLogFile;
FILE* worldLogfile;
ACE_Thread_Mutex m_worldLogMtx;
FILE* raLogfile; /**< TODO */
FILE* logfile; /**< TODO */
FILE* gmLogfile; /**< TODO */
FILE* charLogfile; /**< TODO */
FILE* dberLogfile; /**< TODO */
FILE* eventAiErLogfile; /**< TODO */
FILE* scriptErrLogFile; /**< TODO */
FILE* worldLogfile; /**< TODO */
ACE_Thread_Mutex m_worldLogMtx; /**< TODO */
// log/console control
LogLevel m_logLevel;
LogLevel m_logFileLevel;
bool m_colored;
bool m_includeTime;
Color m_colors[4];
uint32 m_logFilter;
LogLevel m_logLevel; /**< log/console control */
LogLevel m_logFileLevel; /**< TODO */
bool m_colored; /**< TODO */
bool m_includeTime; /**< TODO */
Color m_colors[4]; /**< TODO */
uint32 m_logFilter; /**< TODO */
// cache values for after initilization use (like gm log per account case)
std::string m_logsDir;
std::string m_logsTimestamp;
std::string m_logsDir; /**< TODO */
std::string m_logsTimestamp; /**< TODO */
// char log control
bool m_charLog_Dump;
bool m_charLog_Dump; /**< TODO */
// gm log control
bool m_gmlog_per_account;
std::string m_gmlog_filename_format;
bool m_gmlog_per_account; /**< TODO */
std::string m_gmlog_filename_format; /**< TODO */
char const* m_scriptLibName;
char const* m_scriptLibName; /**< TODO */
};
#define sLog MaNGOS::Singleton<Log>::Instance()
@ -272,13 +476,48 @@ class Log : public MaNGOS::Singleton<Log, MaNGOS::ClassLevelLockable<Log, ACE_Th
#define ERROR_DB_STRICT_LOG(...) \
ERROR_DB_FILTER_LOG(LOG_FILTER_DB_STRICTED_CHECK, __VA_ARGS__)
// primary for script library
/**
* @brief primary for script library
*
* @param str...
*/
void MANGOS_DLL_SPEC outstring_log(const char* str, ...) ATTR_PRINTF(1, 2);
/**
* @brief
*
* @param str...
*/
void MANGOS_DLL_SPEC detail_log(const char* str, ...) ATTR_PRINTF(1, 2);
/**
* @brief
*
* @param str...
*/
void MANGOS_DLL_SPEC debug_log(const char* str, ...) ATTR_PRINTF(1, 2);
/**
* @brief
*
* @param str...
*/
void MANGOS_DLL_SPEC error_log(const char* str, ...) ATTR_PRINTF(1, 2);
/**
* @brief
*
* @param str...
*/
void MANGOS_DLL_SPEC error_db_log(const char* str, ...) ATTR_PRINTF(1, 2);
/**
* @brief
*
* @param fname
* @param libName
*/
void MANGOS_DLL_SPEC setScriptLibraryErrorFile(char const* fname, char const* libName);
/**
* @brief
*
* @param str...
*/
void MANGOS_DLL_SPEC script_error_log(const char* str, ...) ATTR_PRINTF(1, 2);
#endif

View file

@ -16,7 +16,10 @@
*
* 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.
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#include "Config/Config.h"
@ -86,9 +89,12 @@ void startDaemon(uint32_t timeout)
exit(EXIT_FAILURE);
}
freopen("/dev/null", "rt", stdin);
freopen("/dev/null", "wt", stdout);
freopen("/dev/null", "wt", stderr);
if (!freopen("/dev/null", "rt", stdin))
exit(EXIT_FAILURE);
if (!freopen("/dev/null", "wt", stdout))
exit(EXIT_FAILURE);
if (!freopen("/dev/null", "wt", stderr))
exit(EXIT_FAILURE);
}
void stopDaemon()

View file

@ -25,6 +25,19 @@
#include "Common.h"
#include "Log.h"
/**
* @brief
*
* @param timeout
*/
void startDaemon(uint32_t timeout = 10);
/**
* @brief
*
*/
void stopDaemon();
/**
* @brief
*
*/
void detachDaemon();

View file

@ -56,7 +56,7 @@ BarGoLink::BarGoLink(uint64 row_count)
BarGoLink::~BarGoLink()
{
if (!m_showOutput)
return;
{ return; }
printf("\n");
fflush(stdout);
@ -70,14 +70,14 @@ void BarGoLink::init(int row_count)
num_rec = row_count;
if (!m_showOutput)
return;
{ return; }
#ifdef _WIN32
printf("\x3D");
#else
printf("[");
#endif
for (int i = 0; i < indic_len; ++i) printf(empty);
for (int i = 0; i < indic_len; ++i) { printf(empty); }
#ifdef _WIN32
printf("\x3D 0%%\r\x3D");
#else
@ -89,11 +89,11 @@ void BarGoLink::init(int row_count)
void BarGoLink::step()
{
if (!m_showOutput)
return;
{ return; }
int i, n;
if (num_rec == 0) return;
if (num_rec == 0) { return; }
++rec_no;
n = rec_no * indic_len / num_rec;
if (n != rec_pos)
@ -103,8 +103,8 @@ void BarGoLink::step()
#else
printf("\r[");
#endif
for (i = 0; i < n; ++i) printf(full);
for (; i < indic_len; ++i) printf(empty);
for (i = 0; i < n; ++i) { printf(full); }
for (; i < indic_len; ++i) { printf(empty); }
float percent = (((float)n / (float)indic_len) * 100);
#ifdef _WIN32
printf("\x3D %i%% \r\x3D", (int)percent);

View file

@ -21,33 +21,61 @@
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#ifndef MANGOSSERVER_PROGRESSBAR_H
#define MANGOSSERVER_PROGRESSBAR_H
#include "Platform/Define.h"
/**
* @brief
*
*/
class MANGOS_DLL_SPEC BarGoLink
{
public: // constructors
public:
/**
* @brief constructors
*
* @param row_count
*/
explicit BarGoLink(int row_count);
explicit BarGoLink(uint32 row_count); // row_count < ACE_INT32_MAX
explicit BarGoLink(uint64 row_count); // row_count < ACE_INT32_MAX
/**
* @brief
*
*/
~BarGoLink();
public: // modifiers
public:
/**
* @brief modifiers
*
*/
void step();
/**
* @brief
*
* @param on
*/
static void SetOutputState(bool on);
private:
/**
* @brief
*
* @param row_count
*/
void init(int row_count);
static bool m_showOutput; // not recommended change with existed active bar
static char const* const empty;
static char const* const full;
static bool m_showOutput; /**< not recommended change with existed active bar */
static char const* const empty; /**< TODO */
static char const* const full; /**< TODO */
int rec_no;
int rec_pos;
int num_rec;
int indic_len;
int rec_no; /**< TODO */
int rec_pos; /**< TODO */
int num_rec; /**< TODO */
int indic_len; /**< TODO */
};
#endif

View file

@ -16,7 +16,10 @@
*
* 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.
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#ifdef WIN32
@ -27,6 +30,11 @@
#include <windows.h>
#include <winsvc.h>
// stupid ACE define
#ifdef main
#undef main
#endif
#if !defined(WINADVAPI)
#if !defined(_ADVAPI32_)
#define WINADVAPI DECLSPEC_IMPORT
@ -159,7 +167,7 @@ bool WinServiceUninstall()
if (QueryServiceStatus(service, &serviceStatus2))
{
if (serviceStatus2.dwCurrentState == SERVICE_STOPPED)
DeleteService(service);
{ DeleteService(service); }
}
CloseServiceHandle(service);
@ -197,10 +205,10 @@ void WINAPI ServiceControlHandler(DWORD controlCode)
default:
if (controlCode >= 128 && controlCode <= 255)
// user defined control code
break;
{ break; }
else
// unrecognized control code
break;
{ break; }
}
SetServiceStatus(serviceStatusHandle, &serviceStatus);
@ -228,7 +236,7 @@ void WINAPI ServiceMain(DWORD argc, char* argv[])
for (i = 0; i < std::strlen(path); ++i)
{
if (path[i] == '\\') last_slash = i;
if (path[i] == '\\') { last_slash = i; }
}
path[last_slash] = 0;

View file

@ -16,7 +16,10 @@
*
* 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.
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#ifdef WIN32

View file

@ -33,7 +33,7 @@ using namespace ACE_Based;
ThreadPriority::ThreadPriority()
{
for (int i = Idle; i < MAXPRIORITYNUM; ++i)
m_priority[i] = ACE_THR_PRI_OTHER_DEF;
{ 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);
@ -68,11 +68,11 @@ ThreadPriority::ThreadPriority()
// 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 ¹ piesces
// into pieces
const size_t _divider = 4;
size_t _div = (norm_pos - min_pos) / _divider;
if (_div == 0)
_div = 1;
{ _div = 1; }
min_pos = (norm_pos - 1);
@ -81,7 +81,7 @@ ThreadPriority::ThreadPriority()
_div = (max_pos - norm_pos) / _divider;
if (_div == 0)
_div = 1;
{ _div = 1; }
min_pos = norm_pos - 1;
@ -93,10 +93,10 @@ ThreadPriority::ThreadPriority()
int ThreadPriority::getPriority(Priority p) const
{
if (p < Idle)
p = Idle;
{ p = Idle; }
if (p > Realtime)
p = Realtime;
{ p = Realtime; }
return m_priority[p];
}
@ -115,7 +115,7 @@ Thread::Thread(Runnable* instance) : m_iThreadId(0), m_hThreadHandle(0), m_task(
{
// register reference to m_task to prevent it deeltion until destructor
if (m_task)
m_task->incReference();
{ m_task->incReference(); }
bool _start = start();
MANGOS_ASSERT(_start);
@ -127,7 +127,7 @@ Thread::~Thread()
// deleted runnable object (if no other references)
if (m_task)
m_task->decReference();
{ m_task->decReference(); }
}
// initialize Thread's class static member
@ -137,12 +137,12 @@ ThreadPriority Thread::m_TpEnum;
bool Thread::start()
{
if (m_task == 0 || m_iThreadId != 0)
return false;
{ return false; }
bool res = (ACE_Thread::spawn(&Thread::ThreadTask, (void*)m_task, THREADFLAG, &m_iThreadId, &m_hThreadHandle) == 0);
if (res)
m_task->incReference();
{ m_task->incReference(); }
return res;
}
@ -150,7 +150,7 @@ bool Thread::start()
bool Thread::wait()
{
if (!m_hThreadHandle || !m_task)
return false;
{ return false; }
ACE_THR_FUNC_RETURN _value = ACE_THR_FUNC_RETURN(-1);
int _res = ACE_Thread::join(m_hThreadHandle, &_value);
@ -164,10 +164,10 @@ bool Thread::wait()
void Thread::destroy()
{
if (!m_iThreadId || !m_task)
return;
{ return; }
if (ACE_Thread::kill(m_iThreadId, -1) != 0)
return;
{ return; }
m_iThreadId = 0;
m_hThreadHandle = 0;

View file

@ -32,22 +32,46 @@
namespace ACE_Based
{
/**
* @brief
*
*/
class Runnable
{
public:
/**
* @brief
*
*/
virtual ~Runnable() {}
/**
* @brief
*
*/
virtual void run() = 0;
/**
* @brief
*
*/
void incReference() { ++m_refs; }
/**
* @brief
*
*/
void decReference()
{
if (!--m_refs)
delete this;
{ delete this; }
}
private:
ACE_Atomic_Op<ACE_Thread_Mutex, long> m_refs;
ACE_Atomic_Op<ACE_Thread_Mutex, long> m_refs; /**< TODO */
};
/**
* @brief
*
*/
enum Priority
{
Idle,
@ -56,57 +80,154 @@ namespace ACE_Based
Normal,
High,
Highest,
Realtime,
Realtime
};
#define MAXPRIORITYNUM (Realtime + 1)
/**
* @brief
*
*/
class ThreadPriority
{
public:
/**
* @brief
*
*/
ThreadPriority();
/**
* @brief
*
* @param p
* @return int
*/
int getPriority(Priority p) const;
private:
int m_priority[MAXPRIORITYNUM];
int m_priority[MAXPRIORITYNUM]; /**< TODO */
};
/**
* @brief
*
*/
class Thread
{
public:
/**
* @brief
*
*/
Thread();
/**
* @brief
*
* @param instance
*/
explicit Thread(Runnable* instance);
/**
* @brief
*
*/
~Thread();
/**
* @brief
*
* @return bool
*/
bool start();
/**
* @brief
*
* @return bool
*/
bool wait();
/**
* @brief
*
*/
void destroy();
/**
* @brief
*
*/
void suspend();
/**
* @brief
*
*/
void resume();
/**
* @brief
*
* @param type
*/
void setPriority(Priority type);
/**
* @brief
*
* @param msecs
*/
static void Sleep(unsigned long msecs);
/**
* @brief
*
* @return ACE_thread_t
*/
static ACE_thread_t currentId();
/**
* @brief
*
* @return ACE_hthread_t
*/
static ACE_hthread_t currentHandle();
/**
* @brief
*
* @return Thread
*/
static Thread* current();
private:
/**
* @brief
*
* @param
*/
Thread(const Thread&);
/**
* @brief
*
* @param
* @return Thread &operator
*/
Thread& operator=(const Thread&);
/**
* @brief
*
* @param param
* @return ACE_THR_FUNC_RETURN
*/
static ACE_THR_FUNC_RETURN ThreadTask(void* param);
ACE_thread_t m_iThreadId;
ACE_hthread_t m_hThreadHandle;
Runnable* m_task;
ACE_thread_t m_iThreadId; /**< TODO */
ACE_hthread_t m_hThreadHandle; /**< TODO */
Runnable* m_task; /**< TODO */
/**
* @brief
*
*/
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;
static ThreadStorage m_ThreadStorage; /**< global object - container for Thread class representation of every thread */
static ThreadPriority m_TpEnum; /**< use this object to determine current OS thread priority values mapped to enum Priority{} */
};
}
#endif

View file

@ -28,14 +28,28 @@
#include "Common.h"
#include <ace/OS_NS_sys_time.h>
/**
* @brief
*
*/
class WorldTimer
{
public:
// get current server time
/**
* @brief get current server time
*
* @return uint32
*/
static uint32 getMSTime();
// get time difference between two timestamps
/**
* @brief get time difference between two timestamps
*
* @param oldMSTime
* @param newMSTime
* @return uint32
*/
static inline uint32 getMSTimeDiff(const uint32& oldMSTime, const uint32& newMSTime)
{
if (oldMSTime > newMSTime)
@ -49,103 +63,271 @@ class WorldTimer
return newMSTime - oldMSTime;
}
// get last world tick time
/**
* @brief get last world tick time
*
* @return uint32
*/
static MANGOS_DLL_SPEC uint32 tickTime();
// get previous world tick time
/**
* @brief get previous world tick time
*
* @return uint32
*/
static MANGOS_DLL_SPEC uint32 tickPrevTime();
// tick world timer
/**
* @brief tick world timer
*
* @return uint32
*/
static MANGOS_DLL_SPEC uint32 tick();
private:
/**
* @brief
*
*/
WorldTimer();
/**
* @brief
*
* @param
*/
WorldTimer(const WorldTimer&);
// analogue to getMSTime() but it persists m_SystemTickTime
/**
* @brief analogue to getMSTime() but it persists m_SystemTickTime
*
* @param savetime
* @return uint32
*/
static uint32 getMSTime_internal(bool savetime = false);
static MANGOS_DLL_SPEC uint32 m_iTime;
static MANGOS_DLL_SPEC uint32 m_iPrevTime;
static MANGOS_DLL_SPEC uint32 m_iTime; /**< TODO */
static MANGOS_DLL_SPEC uint32 m_iPrevTime; /**< TODO */
};
/**
* @brief
*
*/
class IntervalTimer
{
public:
/**
* @brief
*
*/
IntervalTimer() : _interval(0), _current(0) {}
/**
* @brief
*
* @param diff
*/
void Update(time_t diff)
{
_current += diff;
if (_current < 0)
_current = 0;
{ _current = 0; }
}
/**
* @brief
*
* @return bool
*/
bool Passed() const { return _current >= _interval; }
/**
* @brief
*
*/
void Reset()
{
if (_current >= _interval)
_current -= _interval;
{ _current -= _interval; }
}
/**
* @brief
*
* @param current
*/
void SetCurrent(time_t current) { _current = current; }
/**
* @brief
*
* @param interval
*/
void SetInterval(time_t interval) { _interval = interval; }
/**
* @brief
*
* @return time_t
*/
time_t GetInterval() const { return _interval; }
/**
* @brief
*
* @return time_t
*/
time_t GetCurrent() const { return _current; }
private:
time_t _interval;
time_t _current;
time_t _interval; /**< TODO */
time_t _current; /**< TODO */
};
/**
* @brief
*
*/
class ShortIntervalTimer
{
public:
/**
* @brief
*
*/
ShortIntervalTimer() : _interval(0), _current(0) {}
/**
* @brief
*
* @param diff
*/
void Update(uint32 diff)
{
_current += diff;
}
/**
* @brief
*
* @return bool
*/
bool Passed() const { return _current >= _interval; }
/**
* @brief
*
*/
void Reset()
{
if (_current >= _interval)
_current -= _interval;
{ _current -= _interval; }
}
/**
* @brief
*
* @param current
*/
void SetCurrent(uint32 current) { _current = current; }
/**
* @brief
*
* @param interval
*/
void SetInterval(uint32 interval) { _interval = interval; }
/**
* @brief
*
* @return uint32
*/
uint32 GetInterval() const { return _interval; }
/**
* @brief
*
* @return uint32
*/
uint32 GetCurrent() const { return _current; }
private:
uint32 _interval;
uint32 _current;
uint32 _interval; /**< TODO */
uint32 _current; /**< TODO */
};
/**
* @brief
*
*/
struct TimeTracker
{
public:
/**
* @brief
*
* @param expiry
*/
TimeTracker(time_t expiry) : i_expiryTime(expiry) {}
/**
* @brief
*
* @param diff
*/
void Update(time_t diff) { i_expiryTime -= diff; }
/**
* @brief
*
* @return bool
*/
bool Passed() const { return (i_expiryTime <= 0); }
/**
* @brief
*
* @param interval
*/
void Reset(time_t interval) { i_expiryTime = interval; }
/**
* @brief
*
* @return time_t
*/
time_t GetExpiry() const { return i_expiryTime; }
private:
time_t i_expiryTime;
time_t i_expiryTime; /**< TODO */
};
/**
* @brief
*
*/
struct ShortTimeTracker
{
public:
/**
* @brief
*
* @param expiry
*/
ShortTimeTracker(int32 expiry = 0) : i_expiryTime(expiry) {}
/**
* @brief
*
* @param diff
*/
void Update(int32 diff) { i_expiryTime -= diff; }
/**
* @brief
*
* @return bool
*/
bool Passed() const { return (i_expiryTime <= 0); }
/**
* @brief
*
* @param interval
*/
void Reset(int32 interval) { i_expiryTime = interval; }
/**
* @brief
*
* @return int32
*/
int32 GetExpiry() const { return i_expiryTime; }
private:
int32 i_expiryTime;
int32 i_expiryTime; /**< TODO */
};
#endif

View file

@ -122,7 +122,7 @@ Tokens StrSplit(const std::string& src, const std::string& sep)
{
if (sep.find(*i) != std::string::npos)
{
if (s.length()) r.push_back(s);
if (s.length()) { r.push_back(s); }
s = "";
}
else
@ -130,14 +130,14 @@ Tokens StrSplit(const std::string& src, const std::string& sep)
s += *i;
}
}
if (s.length()) r.push_back(s);
if (s.length()) { r.push_back(s); }
return r;
}
uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index)
{
if (index >= data.size())
return 0;
{ return 0; }
return (uint32)atoi(data[index].c_str());
}
@ -186,15 +186,15 @@ void stripLineInvisibleChars(std::string& str)
else
{
if (wpos != pos)
str[wpos++] = str[pos];
{ str[wpos++] = str[pos]; }
else
++wpos;
{ ++wpos; }
space = false;
}
}
if (wpos < str.size())
str.erase(wpos, str.size());
{ str.erase(wpos, str.size()); }
}
std::string secsToTimeString(time_t timeInSecs, bool shortText, bool hoursOnly)
@ -206,15 +206,15 @@ std::string secsToTimeString(time_t timeInSecs, bool shortText, bool hoursOnly)
std::ostringstream ss;
if (days)
ss << days << (shortText ? "d" : " Day(s) ");
{ ss << days << (shortText ? "d" : " Day(s) "); }
if (hours || hoursOnly)
ss << hours << (shortText ? "h" : " Hour(s) ");
{ ss << hours << (shortText ? "h" : " Hour(s) "); }
if (!hoursOnly)
{
if (minutes)
ss << minutes << (shortText ? "m" : " Minute(s) ");
{ ss << minutes << (shortText ? "m" : " Minute(s) "); }
if (secs || (!days && !hours && !minutes))
ss << secs << (shortText ? "s" : " Second(s).");
{ ss << secs << (shortText ? "s" : " Second(s)."); }
}
return ss.str();
@ -300,7 +300,7 @@ std::string MoneyToString(uint64 money)
bool IsIPAddress(char const* ipaddress)
{
if (!ipaddress)
return false;
{ return false; }
// Let the big boys do it.
// Drawback: all valid ip address formats are recognized e.g.: 12.23,121234,0xABCD)
@ -312,7 +312,7 @@ uint32 CreatePIDFile(const std::string& filename)
{
FILE* pid_file = fopen(filename.c_str(), "w");
if (pid_file == NULL)
return 0;
{ return 0; }
#ifdef WIN32
DWORD pid = GetCurrentProcessId();
@ -345,7 +345,7 @@ void utf8truncate(std::string& utf8str, size_t len)
{
size_t wlen = utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size());
if (wlen <= len)
return;
{ return; }
std::wstring wstr;
wstr.resize(wlen);
@ -368,7 +368,7 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
if (len > wsize)
{
if (wsize > 0)
wstr[0] = L'\0';
{ wstr[0] = L'\0'; }
wsize = 0;
return false;
}
@ -380,7 +380,7 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
catch (std::exception)
{
if (wsize > 0)
wstr[0] = L'\0';
{ wstr[0] = L'\0'; }
wsize = 0;
return false;
}
@ -396,7 +396,7 @@ bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr)
wstr.resize(len);
if (len)
utf8::utf8to16(utf8str.c_str(), utf8str.c_str() + utf8str.size(), &wstr[0]);
{ utf8::utf8to16(utf8str.c_str(), utf8str.c_str() + utf8str.size(), &wstr[0]); }
}
catch (std::exception)
{
@ -453,7 +453,7 @@ std::wstring GetMainPartOfName(std::wstring wname, uint32 declension)
{
// supported only Cyrillic cases
if (wname.size() < 1 || !isCyrillicCharacter(wname[0]) || declension > 5)
return wname;
{ return wname; }
// Important: end length must be <= MAX_INTERNAL_PLAYER_NAME-MAX_PLAYER_NAME (3 currently)
@ -489,7 +489,7 @@ std::wstring GetMainPartOfName(std::wstring wname, uint32 declension)
size_t len = size_t((*itr)[-1]); // get length from string size field
if (wname.substr(wname.size() - len, len) == *itr)
return wname.substr(0, wname.size() - len);
{ return wname.substr(0, wname.size() - len); }
}
return wname;
@ -500,7 +500,7 @@ bool utf8ToConsole(const std::string& utf8str, std::string& conStr)
#if PLATFORM == PLATFORM_WINDOWS
std::wstring wstr;
if (!Utf8toWStr(utf8str, wstr))
return false;
{ return false; }
conStr.resize(wstr.size());
CharToOemBuffW(&wstr[0], &conStr[0], wstr.size());
@ -532,13 +532,13 @@ bool Utf8FitTo(const std::string& str, std::wstring search)
std::wstring temp;
if (!Utf8toWStr(str, temp))
return false;
{ return false; }
// converting to lower case
wstrToLower(temp);
if (temp.find(search) == std::wstring::npos)
return false;
{ return false; }
return true;
}
@ -579,9 +579,9 @@ void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result)
unsigned char nibble = 0x0F & (bytes[i] >> ((1 - j) * 4));
char encodedNibble;
if (nibble < 0x0A)
encodedNibble = '0' + nibble;
{ encodedNibble = '0' + nibble; }
else
encodedNibble = 'A' + nibble - 0x0A;
{ encodedNibble = 'A' + nibble - 0x0A; }
ss << encodedNibble;
}
}

View file

@ -30,311 +30,627 @@
#include <string>
#include <vector>
/**
* @brief
*
*/
typedef std::vector<std::string> Tokens;
/**
* @brief
*
* @param src
* @param sep
* @return Tokens
*/
Tokens StrSplit(const std::string& src, const std::string& sep);
/**
* @brief
*
* @param data
* @param index
* @return uint32
*/
uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index);
/**
* @brief
*
* @param data
* @param index
* @return float
*/
float GetFloatValueFromArray(Tokens const& data, uint16 index);
float NormalizeOrientation(float o);
/**
* @brief
*
* @param src
*/
void stripLineInvisibleChars(std::string& src);
/**
* @brief
*
* @param timeInSecs
* @param shortText
* @param hoursOnly
* @return std::string
*/
std::string secsToTimeString(time_t timeInSecs, bool shortText = false, bool hoursOnly = false);
/**
* @brief
*
* @param timestring
* @return uint32
*/
uint32 TimeStringToSecs(const std::string& timestring);
/**
* @brief
*
* @param t
* @return std::string
*/
std::string TimeToTimestampStr(time_t t);
time_t timeBitFieldsToSecs(uint32 packedDate);
std::string MoneyToString(uint64 money);
/**
* @brief
*
* @param secs
* @return uint32
*/
inline uint32 secsToTimeBitFields(time_t secs)
{
tm* lt = localtime(&secs);
return (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;
}
/* Return a random number in the range min..max; (max-min) must be smaller than 32768. */
/**
* @brief Return a random number in the range min..max; (max-min) must be smaller than 32768.
*
* @param min
* @param max
* @return int32
*/
MANGOS_DLL_SPEC int32 irand(int32 min, int32 max);
/* Return a random number in the range min..max (inclusive). For reliable results, the difference
* between max and min should be less than RAND32_MAX. */
/**
* @brief Return a random number in the range min..max (inclusive).
*
* For reliable results, the difference between max and min should be less than
* RAND32_MAX.
*
* @param min
* @param max
* @return uint32
*/
MANGOS_DLL_SPEC uint32 urand(uint32 min, uint32 max);
/* Return a random number in the range min..max (inclusive). */
/**
* @brief Return a random number in the range min..max (inclusive).
*
* @param min
* @param max
* @return float
*/
MANGOS_DLL_SPEC float frand(float min, float max);
/* Return a random number in the range 0 .. RAND32_MAX. */
/**
* @brief Return a random number in the range 0 .. RAND32_MAX.
*
* @return int32
*/
MANGOS_DLL_SPEC int32 rand32();
/* Return a random double from 0.0 to 1.0 (exclusive). Floats support only 7 valid decimal digits.
* A double supports up to 15 valid decimal digits and is used internally (RAND32_MAX has 10 digits).
* With an FPU, there is usually no difference in performance between float and double. */
/**
* @brief Return a random double from 0.0 to 1.0 (exclusive).
*
* Floats support only 7 valid decimal digits. A double supports up to 15 valid
* decimaldigits and is used internally (RAND32_MAX has 10 digits). With an FPU
* there is usually no difference in performance between float and double.
*
* @return double
*/
MANGOS_DLL_SPEC double rand_norm(void);
/**
* @brief
*
* @return float
*/
MANGOS_DLL_SPEC float rand_norm_f(void);
/* Return a random double from 0.0 to 99.9999999999999. Floats support only 7 valid decimal digits.
* A double supports up to 15 valid decimal digits and is used internaly (RAND32_MAX has 10 digits).
* With an FPU, there is usually no difference in performance between float and double. */
/**
* @brief Return a random double from 0.0 to 99.9999999999999.
*
* Floats support only 7 valid decimal digits. A double supports up to 15 valid
* decimal digits and is used internaly (RAND32_MAX has 10 digits). With an FPU
* there is usually no difference in performance between float and double.
*
* @return double
*/
MANGOS_DLL_SPEC double rand_chance(void);
/**
* @brief
*
* @return float
*/
MANGOS_DLL_SPEC float rand_chance_f(void);
/* Return true if a random roll fits in the specified chance (range 0-100). */
/**
* @brief Return true if a random roll gets above the given chance
*
* ie: if the given value is 0 the chance to succeed is also 0 which gives false
* as the return value at all cases. On the other hand, giving 100 as the chance
* will make sure that we always succeed
*
* @param chance How big the chance to succeed is. Value between 0.0f-100.0f
* @return bool Return true if a random roll fits in the specified chance (range 0-100).
*/
inline bool roll_chance_f(float chance)
{
return chance > rand_chance();
}
/* Return true if a random roll fits in the specified chance (range 0-100). */
/**
* @brief Return true if a random roll fits in the specified chance (range 0-100).
*
* @param chance
* @return bool
*/
inline bool roll_chance_i(int chance)
{
return chance > irand(0, 99);
}
/**
* @brief
*
* @param var
* @param val
* @param apply
*/
inline void ApplyModUInt32Var(uint32& var, int32 val, bool apply)
{
int32 cur = var;
cur += (apply ? val : -val);
if (cur < 0)
cur = 0;
{ cur = 0; }
var = cur;
}
/**
* @brief
*
* @param var
* @param val
* @param apply
*/
inline void ApplyModFloatVar(float& var, float val, bool apply)
{
var += (apply ? val : -val);
if (var < 0)
var = 0;
{ var = 0; }
}
/**
* @brief
*
* @param var
* @param val
* @param apply
*/
inline void ApplyPercentModFloatVar(float& var, float val, bool apply)
{
if (val == -100.0f) // prevent set var to zero
val = -99.99f;
{ val = -99.99f; }
var *= (apply ? (100.0f + val) / 100.0f : 100.0f / (100.0f + val));
}
/**
* @brief
*
* @param utf8str
* @param wstr
* @return bool
*/
bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr);
// in wsize==max size of buffer, out wsize==real string size
/**
* @brief
*
* @param utf8str
* @param csize
* @param wstr
* @param wsize
* @return bool
*/
bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize);
/**
* @brief
*
* @param utf8str
* @param wstr
* @param wsize
* @return bool
*/
inline bool Utf8toWStr(const std::string& utf8str, wchar_t* wstr, size_t& wsize)
{
return Utf8toWStr(utf8str.c_str(), utf8str.size(), wstr, wsize);
}
/**
* @brief
*
* @param wstr
* @param utf8str
* @return bool
*/
bool WStrToUtf8(std::wstring wstr, std::string& utf8str);
// size==real string size
/**
* @brief
*
* @param wstr
* @param size
* @param utf8str
* @return bool
*/
bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str);
/**
* @brief
*
* @param utf8str
* @return size_t
*/
size_t utf8length(std::string& utf8str); // set string to "" if invalid utf8 sequence
/**
* @brief
*
* @param utf8str
* @param len
*/
void utf8truncate(std::string& utf8str, size_t len);
/**
* @brief
*
* @param wchar
* @return bool
*/
inline bool isBasicLatinCharacter(wchar_t wchar)
{
if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
return true;
{ return true; }
if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
return true;
{ return true; }
return false;
}
/**
* @brief
*
* @param wchar
* @return bool
*/
inline bool isExtendedLatinCharacter(wchar_t wchar)
{
if (isBasicLatinCharacter(wchar))
return true;
{ return true; }
if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
return true;
{ return true; }
if (wchar >= 0x00D8 && wchar <= 0x00DF) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
return true;
{ return true; }
if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
return true;
{ return true; }
if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
return true;
{ return true; }
if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
return true;
{ return true; }
if (wchar >= 0x0100 && wchar <= 0x012F) // LATIN CAPITAL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK
return true;
{ return true; }
if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
return true;
{ return true; }
return false;
}
/**
* @brief
*
* @param wchar
* @return bool
*/
inline bool isCyrillicCharacter(wchar_t wchar)
{
if (wchar >= 0x0410 && wchar <= 0x044F) // CYRILLIC CAPITAL LETTER A - CYRILLIC SMALL LETTER YA
return true;
{ return true; }
if (wchar == 0x0401 || wchar == 0x0451) // CYRILLIC CAPITAL LETTER IO, CYRILLIC SMALL LETTER IO
return true;
{ return true; }
return false;
}
/**
* @brief
*
* @param wchar
* @return bool
*/
inline bool isEastAsianCharacter(wchar_t wchar)
{
if (wchar >= 0x1100 && wchar <= 0x11F9) // Hangul Jamo
return true;
{ return true; }
if (wchar >= 0x3041 && wchar <= 0x30FF) // Hiragana + Katakana
return true;
{ return true; }
if (wchar >= 0x3131 && wchar <= 0x318E) // Hangul Compatibility Jamo
return true;
{ return true; }
if (wchar >= 0x31F0 && wchar <= 0x31FF) // Katakana Phonetic Ext.
return true;
{ return true; }
if (wchar >= 0x3400 && wchar <= 0x4DB5) // CJK Ideographs Ext. A
return true;
{ return true; }
if (wchar >= 0x4E00 && wchar <= 0x9FC3) // Unified CJK Ideographs
return true;
{ return true; }
if (wchar >= 0xAC00 && wchar <= 0xD7A3) // Hangul Syllables
return true;
{ return true; }
if (wchar >= 0xFF01 && wchar <= 0xFFEE) // Halfwidth forms
return true;
{ return true; }
return false;
}
/**
* @brief
*
* @param c
* @return bool
*/
inline bool isWhiteSpace(char c)
{
return ::isspace(int(c)) != 0;
}
/**
* @brief
*
* @param wchar
* @return bool
*/
inline bool isNumeric(wchar_t wchar)
{
return (wchar >= L'0' && wchar <= L'9');
}
/**
* @brief
*
* @param c
* @return bool
*/
inline bool isNumeric(char c)
{
return (c >= '0' && c <= '9');
}
/**
* @brief
*
* @param wchar
* @return bool
*/
inline bool isNumericOrSpace(wchar_t wchar)
{
return isNumeric(wchar) || wchar == L' ';
}
/**
* @brief
*
* @param str
* @return bool
*/
inline bool isNumeric(char const* str)
{
for (char const* c = str; *c; ++c)
if (!isNumeric(*c))
return false;
{ return false; }
return true;
}
/**
* @brief
*
* @param str
* @return bool
*/
inline bool isNumeric(std::string const& str)
{
for (std::string::const_iterator itr = str.begin(); itr != str.end(); ++itr)
if (!isNumeric(*itr))
return false;
{ return false; }
return true;
}
/**
* @brief
*
* @param str
* @return bool
*/
inline bool isNumeric(std::wstring const& str)
{
for (std::wstring::const_iterator itr = str.begin(); itr != str.end(); ++itr)
if (!isNumeric(*itr))
return false;
{ return false; }
return true;
}
/**
* @brief
*
* @param wstr
* @param numericOrSpace
* @return bool
*/
inline bool isBasicLatinString(std::wstring wstr, bool numericOrSpace)
{
for (size_t i = 0; i < wstr.size(); ++i)
if (!isBasicLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
return false;
{ return false; }
return true;
}
/**
* @brief
*
* @param wstr
* @param numericOrSpace
* @return bool
*/
inline bool isExtendedLatinString(std::wstring wstr, bool numericOrSpace)
{
for (size_t i = 0; i < wstr.size(); ++i)
if (!isExtendedLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
return false;
{ return false; }
return true;
}
/**
* @brief
*
* @param wstr
* @param numericOrSpace
* @return bool
*/
inline bool isCyrillicString(std::wstring wstr, bool numericOrSpace)
{
for (size_t i = 0; i < wstr.size(); ++i)
if (!isCyrillicCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
return false;
{ return false; }
return true;
}
/**
* @brief
*
* @param wstr
* @param numericOrSpace
* @return bool
*/
inline bool isEastAsianString(std::wstring wstr, bool numericOrSpace)
{
for (size_t i = 0; i < wstr.size(); ++i)
if (!isEastAsianCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
return false;
{ return false; }
return true;
}
/**
* @brief
*
* @param str
*/
inline void strToUpper(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), toupper);
}
/**
* @brief
*
* @param str
*/
inline void strToLower(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), tolower);
}
/**
* @brief
*
* @param wchar
* @return wchar_t
*/
inline wchar_t wcharToUpper(wchar_t wchar)
{
if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
return wchar_t(uint16(wchar) - 0x0020);
{ return wchar_t(uint16(wchar) - 0x0020); }
if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
return wchar_t(0x1E9E);
{ return wchar_t(0x1E9E); }
if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
return wchar_t(uint16(wchar) - 0x0020);
{ return wchar_t(uint16(wchar) - 0x0020); }
if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
return wchar_t(uint16(wchar) - 0x0020);
{ return wchar_t(uint16(wchar) - 0x0020); }
if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1)
{
if (wchar % 2 == 1)
return wchar_t(uint16(wchar) - 0x0001);
{ return wchar_t(uint16(wchar) - 0x0001); }
}
if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
return wchar_t(uint16(wchar) - 0x0020);
{ return wchar_t(uint16(wchar) - 0x0020); }
if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
return wchar_t(0x0401);
{ return wchar_t(0x0401); }
return wchar;
}
/**
* @brief
*
* @param wchar
* @return wchar_t
*/
inline wchar_t wcharToUpperOnlyLatin(wchar_t wchar)
{
return isBasicLatinCharacter(wchar) ? wcharToUpper(wchar) : wchar;
}
/**
* @brief
*
* @param wchar
* @return wchar_t
*/
inline wchar_t wcharToLower(wchar_t wchar)
{
if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
return wchar_t(uint16(wchar) + 0x0020);
{ return wchar_t(uint16(wchar) + 0x0020); }
if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
return wchar_t(uint16(wchar) + 0x0020);
{ return wchar_t(uint16(wchar) + 0x0020); }
if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
return wchar_t(uint16(wchar) + 0x0020);
{ return wchar_t(uint16(wchar) + 0x0020); }
if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0)
{
if (wchar % 2 == 0)
return wchar_t(uint16(wchar) + 0x0001);
{ return wchar_t(uint16(wchar) + 0x0001); }
}
if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
return wchar_t(0x00DF);
{ return wchar_t(0x00DF); }
if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO
return wchar_t(0x0451);
{ return wchar_t(0x0451); }
if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA
return wchar_t(uint16(wchar) + 0x0020);
{ return wchar_t(uint16(wchar) + 0x0020); }
return wchar;
}
/**
* @brief
*
* @param str
*/
inline void wstrToUpper(std::wstring& str)
{
std::transform(str.begin(), str.end(), str.begin(), wcharToUpper);
}
/**
* @brief
*
* @param str
*/
inline void wstrToLower(std::wstring& str)
{
std::transform(str.begin(), str.end(), str.begin(), wcharToLower);
@ -342,14 +658,67 @@ inline void wstrToLower(std::wstring& str)
std::wstring GetMainPartOfName(std::wstring wname, uint32 declension);
/**
* @brief
*
* @param utf8str
* @param conStr
* @return bool
*/
bool utf8ToConsole(const std::string& utf8str, std::string& conStr);
/**
* @brief
*
* @param conStr
* @param utf8str
* @return bool
*/
bool consoleToUtf8(const std::string& conStr, std::string& utf8str);
/**
* @brief
*
* @param str
* @param search
* @return bool
*/
bool Utf8FitTo(const std::string& str, std::wstring search);
/**
* @brief
*
* @param out
* @param str...
*/
void utf8printf(FILE* out, const char* str, ...);
/**
* @brief
*
* @param out
* @param str
* @param ap
*/
void vutf8printf(FILE* out, const char* str, va_list* ap);
/**
* @brief
*
* @param ipaddress
* @return bool
*/
bool IsIPAddress(char const* ipaddress);
/**
* @brief
*
* @param filename
* @return uint32
*/
uint32 CreatePIDFile(const std::string& filename);
/**
* @brief
*
* @param bytes
* @param arrayLen
* @param result
*/
void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result);
#endif

View file

@ -61,7 +61,7 @@ WheatyExceptionReport::WheatyExceptionReport() // Constructor
WheatyExceptionReport::~WheatyExceptionReport()
{
if (m_previousFilter)
SetUnhandledExceptionFilter(m_previousFilter);
{ SetUnhandledExceptionFilter(m_previousFilter); }
}
//===========================================================
@ -74,7 +74,7 @@ LONG WINAPI WheatyExceptionReport::WheatyUnhandledExceptionFilter(
GetModuleFileName(0, module_folder_name, MAX_PATH);
TCHAR* pos = _tcsrchr(module_folder_name, '\\');
if (!pos)
return 0;
{ return 0; }
pos[0] = '\0';
++pos;
@ -83,7 +83,7 @@ LONG WINAPI WheatyExceptionReport::WheatyUnhandledExceptionFilter(
if (!CreateDirectory(crash_folder_path, NULL))
{
if (GetLastError() != ERROR_ALREADY_EXISTS)
return 0;
{ return 0; }
}
SYSTEMTIME systime;
@ -110,34 +110,34 @@ LONG WINAPI WheatyExceptionReport::WheatyUnhandledExceptionFilter(
}
if (m_previousFilter)
return m_previousFilter(pExceptionInfo);
{ return m_previousFilter(pExceptionInfo); }
else
return EXCEPTION_EXECUTE_HANDLER/*EXCEPTION_CONTINUE_SEARCH*/;
{ return EXCEPTION_EXECUTE_HANDLER/*EXCEPTION_CONTINUE_SEARCH*/; }
}
BOOL WheatyExceptionReport::_GetProcessorName(TCHAR* sProcessorName, DWORD maxcount)
{
if (!sProcessorName)
return FALSE;
{ return FALSE; }
HKEY hKey;
LONG lRet;
lRet = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"),
0, KEY_QUERY_VALUE, &hKey);
if (lRet != ERROR_SUCCESS)
return FALSE;
{ return FALSE; }
TCHAR szTmp[2048];
DWORD cntBytes = sizeof(szTmp);
lRet = ::RegQueryValueEx(hKey, _T("ProcessorNameString"), NULL, NULL,
(LPBYTE)szTmp, &cntBytes);
if (lRet != ERROR_SUCCESS)
return FALSE;
{ return FALSE; }
::RegCloseKey(hKey);
sProcessorName[0] = '\0';
// Skip spaces
TCHAR* psz = szTmp;
while (iswspace(*psz))
++psz;
{ ++psz; }
_tcsncpy(sProcessorName, psz, maxcount);
return TRUE;
}
@ -154,7 +154,7 @@ BOOL WheatyExceptionReport::_GetWindowsVersion(TCHAR* szVersion, DWORD cntMax)
{
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (!::GetVersionEx((OSVERSIONINFO*)&osvi))
return FALSE;
{ return FALSE; }
}
*szVersion = _T('\0');
TCHAR wszTmp[128];
@ -167,21 +167,21 @@ BOOL WheatyExceptionReport::_GetWindowsVersion(TCHAR* szVersion, DWORD cntMax)
{
default: // 2
if (osvi.wProductType == VER_NT_WORKSTATION)
_tcsncat(szVersion, _T("Windows 8 "), cntMax);
{ _tcsncat(szVersion, _T("Windows 8 "), cntMax); }
else
_tcsncat(szVersion, _T("Windows Server 2012 "), cntMax);
{ _tcsncat(szVersion, _T("Windows Server 2012 "), cntMax); }
break;
case 1:
if (osvi.wProductType == VER_NT_WORKSTATION)
_tcsncat(szVersion, _T("Windows 7 "), cntMax);
{ _tcsncat(szVersion, _T("Windows 7 "), cntMax); }
else
_tcsncat(szVersion, _T("Windows Server 2008 R2 "), cntMax);
{ _tcsncat(szVersion, _T("Windows Server 2008 R2 "), cntMax); }
break;
case 0:
if (osvi.wProductType == VER_NT_WORKSTATION)
_tcsncat(szVersion, _T("Windows Vista "), cntMax);
{ _tcsncat(szVersion, _T("Windows Vista "), cntMax); }
else
_tcsncat(szVersion, _T("Windows Server 2008 "), cntMax);
{ _tcsncat(szVersion, _T("Windows Server 2008 "), cntMax); }
break;
}
break;
@ -235,9 +235,9 @@ void WheatyExceptionReport::PrintSystemInfo()
SystemInfo.dwNumberOfProcessors, MemoryStatus.dwTotalPhys / 0x400, MemoryStatus.dwAvailPhys / 0x400, MemoryStatus.dwTotalPageFile / 0x400);
if (_GetWindowsVersion(sString, countof(sString)))
_tprintf(_T("\r\n*** Operation System ***\r\n%s\r\n"), sString);
{ _tprintf(_T("\r\n*** Operation System ***\r\n%s\r\n"), sString); }
else
_tprintf(_T("\r\n*** Operation System:\r\n<unknown>\r\n"));
{ _tprintf(_T("\r\n*** Operation System:\r\n<unknown>\r\n")); }
}
//===========================================================================
@ -251,7 +251,7 @@ void WheatyExceptionReport::printTracesForAllThreads()
// Take a snapshot of all running threads
hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hThreadSnap == INVALID_HANDLE_VALUE)
return;
{ return; }
// Fill in the size of the structure before using it.
te32.dwSize = sizeof(THREADENTRY32);
@ -456,12 +456,12 @@ BOOL WheatyExceptionReport::GetLogicalAddress(
MEMORY_BASIC_INFORMATION mbi;
if (!VirtualQuery(addr, &mbi, sizeof(mbi)))
return FALSE;
{ return FALSE; }
DWORD_PTR hMod = (DWORD_PTR)mbi.AllocationBase;
if (!GetModuleFileName((HMODULE)hMod, szModule, len))
return FALSE;
{ return FALSE; }
// Point to the DOS header in memory
PIMAGE_DOS_HEADER pDosHdr = (PIMAGE_DOS_HEADER)hMod;
@ -476,8 +476,8 @@ BOOL WheatyExceptionReport::GetLogicalAddress(
// Iterate through the section table, looking for the one that encompasses
// the linear address.
for (unsigned i = 0;
i < pNtHdr->FileHeader.NumberOfSections;
++i, ++pSection)
i < pNtHdr->FileHeader.NumberOfSections;
++i, ++pSection)
{
DWORD_PTR sectionStart = pSection->VirtualAddress;
DWORD_PTR sectionEnd = sectionStart
@ -561,9 +561,9 @@ void WheatyExceptionReport::WriteStackDetails(
SymFunctionTableAccess64,
SymGetModuleBase64,
0))
break;
{ break; }
if (0 == sf.AddrFrame.Offset) // Basic sanity check to make sure
break; // the frame is OK. Bail if not.
{ break; } // the frame is OK. Bail if not.
#ifdef _M_IX86
_tprintf(_T("%08X %08X "), sf.AddrPC.Offset, sf.AddrFrame.Offset);
#endif
@ -577,10 +577,10 @@ void WheatyExceptionReport::WriteStackDetails(
// Get the name of the function for this stack frame entry
CSymbolInfoPackage sip;
if (SymFromAddr(
m_hProcess, // Process handle of the current process
sf.AddrPC.Offset, // Symbol address
&symDisplacement, // Address of the variable that will receive the displacement
&sip.si)) // Address of the SYMBOL_INFO structure (inside "sip" object)
m_hProcess, // Process handle of the current process
sf.AddrPC.Offset, // Symbol address
&symDisplacement, // Address of the variable that will receive the displacement
&sip.si)) // Address of the SYMBOL_INFO structure (inside "sip" object)
{
_tprintf(_T("%hs+%I64X"), sip.si.Name, symDisplacement);
}
@ -642,10 +642,10 @@ WheatyExceptionReport::EnumerateSymbolsCallback(
__try
{
if (FormatSymbolValue(pSymInfo, (STACKFRAME*)UserContext,
szBuffer, sizeof(szBuffer)))
_tprintf(_T("\t%s\r\n"), szBuffer);
szBuffer, sizeof(szBuffer)))
{ _tprintf(_T("\t%s\r\n"), szBuffer); }
}
__except (1)
__except(1)
{
_tprintf(_T("punting on symbol %s\r\n"), pSymInfo->Name);
}
@ -668,13 +668,13 @@ bool WheatyExceptionReport::FormatSymbolValue(
// Indicate if the variable is a local or parameter
if (pSym->Flags & IMAGEHLP_SYMBOL_INFO_PARAMETER)
pszCurrBuffer += sprintf(pszCurrBuffer, "Parameter ");
{ pszCurrBuffer += sprintf(pszCurrBuffer, "Parameter "); }
else if (pSym->Flags & IMAGEHLP_SYMBOL_INFO_LOCAL)
pszCurrBuffer += sprintf(pszCurrBuffer, "Local ");
{ pszCurrBuffer += sprintf(pszCurrBuffer, "Local "); }
// If it's a function, don't do anything.
if (pSym->Tag == 5) // SymTagFunction from CVCONST.H from the DIA SDK
return false;
{ return false; }
DWORD_PTR pVariable = 0; // Will point to the variable's data in memory
@ -754,7 +754,7 @@ char* WheatyExceptionReport::DumpTypeIndex(
&dwChildrenCount);
if (!dwChildrenCount) // If no children, we're done
return pszCurrBuffer;
{ return pszCurrBuffer; }
// Prepare to get an array of "TypeIds", representing each of the children.
// SymGetTypeInfo(TI_FINDCHILDREN) expects more memory than just a
@ -783,7 +783,7 @@ char* WheatyExceptionReport::DumpTypeIndex(
{
// Add appropriate indentation level (since this routine is recursive)
for (unsigned j = 0; j <= nestingLevel + 1; ++j)
pszCurrBuffer += sprintf(pszCurrBuffer, "\t");
{ pszCurrBuffer += sprintf(pszCurrBuffer, "\t"); }
// Recurse for each of the child types
bool bHandled2;
@ -840,9 +840,9 @@ char* WheatyExceptionReport::FormatOutputValue(char* pszCurrBuffer,
{
// Format appropriately (assuming it's a 1, 2, or 4 bytes (!!!)
if (length == 1)
pszCurrBuffer += sprintf(pszCurrBuffer, " = %X", *(PBYTE)pAddress);
{ pszCurrBuffer += sprintf(pszCurrBuffer, " = %X", *(PBYTE)pAddress); }
else if (length == 2)
pszCurrBuffer += sprintf(pszCurrBuffer, " = %X", *(PWORD)pAddress);
{ pszCurrBuffer += sprintf(pszCurrBuffer, " = %X", *(PWORD)pAddress); }
else if (length == 4)
{
if (basicType == btFloat)
@ -861,7 +861,7 @@ char* WheatyExceptionReport::FormatOutputValue(char* pszCurrBuffer,
*(PDWORD)pAddress);
}
else
pszCurrBuffer += sprintf(pszCurrBuffer, " = %X", *(PDWORD)pAddress);
{ pszCurrBuffer += sprintf(pszCurrBuffer, " = %X", *(PDWORD)pAddress); }
}
else if (length == 8)
{

View file

@ -1,3 +1,27 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2014 MaNGOS project <http://getmangos.eu>
*
* 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
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#ifndef _WHEATYEXCEPTIONREPORT_
#define _WHEATYEXCEPTIONREPORT_

View file

@ -31,19 +31,42 @@
// Note: m_opcode and size stored in platfom dependent format
// ignore endianess until send, and converted at receive
/**
* @brief
*
*/
class WorldPacket : public ByteBuffer
{
public:
// just container for later use
WorldPacket() : ByteBuffer(0), m_opcode(MSG_NULL_ACTION)
/**
* @brief just container for later use
*
*/
WorldPacket() : ByteBuffer(0), m_opcode(MSG_NULL_ACTION)
{
}
/**
* @brief
*
* @param opcode
* @param res
*/
explicit WorldPacket(Opcodes opcode, size_t res = 200) : ByteBuffer(res), m_opcode(opcode) { }
// copy constructor
WorldPacket(const WorldPacket& packet) : ByteBuffer(packet), m_opcode(packet.m_opcode)
/**
* @brief copy constructor
*
* @param packet
*/
WorldPacket(const WorldPacket& packet) : ByteBuffer(packet), m_opcode(packet.m_opcode)
{
}
/**
* @brief
*
* @param opcode
* @param newres
*/
void Initialize(Opcodes opcode, size_t newres = 200)
{
clear();
@ -51,8 +74,23 @@ class WorldPacket : public ByteBuffer
m_opcode = opcode;
}
/**
* @brief
*
* @return uint16
*/
Opcodes GetOpcode() const { return m_opcode; }
/**
* @brief
*
* @param opcode
*/
void SetOpcode(Opcodes opcode) { m_opcode = opcode; }
/**
* @brief
*
* @return const char
*/
inline const char* GetOpcodeName() const { return LookupOpcodeName(m_opcode); }
protected: