mirror of
https://github.com/mangosfour/server.git
synced 2025-12-27 19:37:04 +00:00
Merge commit 'origin/master' into 320
Conflicts: src/game/MovementHandler.cpp
This commit is contained in:
commit
fec1a1954c
27 changed files with 439 additions and 253 deletions
|
|
@ -27,15 +27,16 @@
|
|||
class ByteBufferException
|
||||
{
|
||||
public:
|
||||
ByteBufferException(bool add, size_t pos, size_t esize, size_t size):add(add), pos(pos), esize(esize), size(size)
|
||||
ByteBufferException(bool _add, size_t _pos, size_t _esize, size_t _size)
|
||||
: add(_add), pos(_pos), esize(_esize), size(_size)
|
||||
{
|
||||
PrintPosError();
|
||||
}
|
||||
|
||||
void PrintPosError() const
|
||||
{
|
||||
sLog.outError("ERROR: Attempted to %s in ByteBuffer (pos: %lu size: %lu) value with size: %lu",(add ? "put" : "get"),(unsigned long)pos, (unsigned long)size, (unsigned long)esize);
|
||||
|
||||
sLog.outError("ERROR: Attempted to %s in ByteBuffer (pos: " SIZEFMTD " size: "SIZEFMTD") value with size: " SIZEFMTD,
|
||||
(add ? "put" : "get"), pos, size, esize);
|
||||
}
|
||||
private:
|
||||
bool add;
|
||||
|
|
@ -262,22 +263,6 @@ class ByteBuffer
|
|||
template<typename T>
|
||||
void read_skip() { read_skip(sizeof(T)); }
|
||||
|
||||
template<typename T1, typename T2>
|
||||
void read_skip2() { read_skip(sizeof(T1)+sizeof(T2)); }
|
||||
|
||||
template<>
|
||||
void read_skip<char*>()
|
||||
{
|
||||
uint8 size = read<uint8>();
|
||||
read_skip(size);
|
||||
}
|
||||
|
||||
template<>
|
||||
void read_skip<char const*>() { read_skip<char*>(); }
|
||||
|
||||
template<>
|
||||
void read_skip<std::string>() { read_skip<char*>(); }
|
||||
|
||||
void read_skip(size_t skip)
|
||||
{
|
||||
if(_rpos + skip > size())
|
||||
|
|
@ -512,7 +497,8 @@ class ByteBuffer
|
|||
std::vector<uint8> _storage;
|
||||
};
|
||||
|
||||
template <typename T> ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v)
|
||||
template <typename T>
|
||||
inline ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v)
|
||||
{
|
||||
b << (uint32)v.size();
|
||||
for (typename std::vector<T>::iterator i = v.begin(); i != v.end(); ++i)
|
||||
|
|
@ -522,7 +508,8 @@ template <typename T> ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v)
|
|||
return b;
|
||||
}
|
||||
|
||||
template <typename T> ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v)
|
||||
template <typename T>
|
||||
inline ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v)
|
||||
{
|
||||
uint32 vsize;
|
||||
b >> vsize;
|
||||
|
|
@ -536,7 +523,8 @@ template <typename T> ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v)
|
|||
return b;
|
||||
}
|
||||
|
||||
template <typename T> ByteBuffer &operator<<(ByteBuffer &b, std::list<T> v)
|
||||
template <typename T>
|
||||
inline ByteBuffer &operator<<(ByteBuffer &b, std::list<T> v)
|
||||
{
|
||||
b << (uint32)v.size();
|
||||
for (typename std::list<T>::iterator i = v.begin(); i != v.end(); ++i)
|
||||
|
|
@ -546,7 +534,8 @@ template <typename T> ByteBuffer &operator<<(ByteBuffer &b, std::list<T> v)
|
|||
return b;
|
||||
}
|
||||
|
||||
template <typename T> ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v)
|
||||
template <typename T>
|
||||
inline ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v)
|
||||
{
|
||||
uint32 vsize;
|
||||
b >> vsize;
|
||||
|
|
@ -560,7 +549,8 @@ template <typename T> ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v)
|
|||
return b;
|
||||
}
|
||||
|
||||
template <typename K, typename V> ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m)
|
||||
template <typename K, typename V>
|
||||
inline ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m)
|
||||
{
|
||||
b << (uint32)m.size();
|
||||
for (typename std::map<K, V>::iterator i = m.begin(); i != m.end(); ++i)
|
||||
|
|
@ -570,7 +560,8 @@ template <typename K, typename V> ByteBuffer &operator<<(ByteBuffer &b, std::map
|
|||
return b;
|
||||
}
|
||||
|
||||
template <typename K, typename V> ByteBuffer &operator>>(ByteBuffer &b, std::map<K, V> &m)
|
||||
template <typename K, typename V>
|
||||
inline ByteBuffer &operator>>(ByteBuffer &b, std::map<K, V> &m)
|
||||
{
|
||||
uint32 msize;
|
||||
b >> msize;
|
||||
|
|
@ -584,4 +575,23 @@ template <typename K, typename V> ByteBuffer &operator>>(ByteBuffer &b, std::map
|
|||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void ByteBuffer::read_skip<char*>()
|
||||
{
|
||||
std::string temp;
|
||||
*this >> temp;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void ByteBuffer::read_skip<char const*>()
|
||||
{
|
||||
read_skip<char*>();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void ByteBuffer::read_skip<std::string>()
|
||||
{
|
||||
read_skip<char*>();
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -369,7 +369,11 @@ void Log::outString( const char * str, ... )
|
|||
if(m_includeTime)
|
||||
outTime();
|
||||
|
||||
UTF8PRINTF(stdout,str,);
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, str);
|
||||
vutf8printf(stdout, str, &ap);
|
||||
va_end(ap);
|
||||
|
||||
if(m_colored)
|
||||
ResetColor(true);
|
||||
|
|
@ -379,7 +383,6 @@ void Log::outString( const char * str, ... )
|
|||
{
|
||||
outTimestamp(logfile);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vfprintf(logfile, str, ap);
|
||||
fprintf(logfile, "\n" );
|
||||
|
|
@ -401,7 +404,11 @@ void Log::outError( const char * err, ... )
|
|||
if(m_includeTime)
|
||||
outTime();
|
||||
|
||||
UTF8PRINTF(stderr,err,);
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, err);
|
||||
vutf8printf(stderr, err, &ap);
|
||||
va_end(ap);
|
||||
|
||||
if(m_colored)
|
||||
ResetColor(false);
|
||||
|
|
@ -412,7 +419,6 @@ void Log::outError( const char * err, ... )
|
|||
outTimestamp(logfile);
|
||||
fprintf(logfile, "ERROR:" );
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, err);
|
||||
vfprintf(logfile, err, ap);
|
||||
va_end(ap);
|
||||
|
|
@ -434,7 +440,11 @@ void Log::outErrorDb( const char * err, ... )
|
|||
if(m_includeTime)
|
||||
outTime();
|
||||
|
||||
UTF8PRINTF(stderr,err,);
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, err);
|
||||
vutf8printf(stderr, err, &ap);
|
||||
va_end(ap);
|
||||
|
||||
if(m_colored)
|
||||
ResetColor(false);
|
||||
|
|
@ -446,7 +456,6 @@ void Log::outErrorDb( const char * err, ... )
|
|||
outTimestamp(logfile);
|
||||
fprintf(logfile, "ERROR:" );
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, err);
|
||||
vfprintf(logfile, err, ap);
|
||||
va_end(ap);
|
||||
|
|
@ -483,7 +492,10 @@ void Log::outBasic( const char * str, ... )
|
|||
if(m_includeTime)
|
||||
outTime();
|
||||
|
||||
UTF8PRINTF(stdout,str,);
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vutf8printf(stdout, str, &ap);
|
||||
va_end(ap);
|
||||
|
||||
if(m_colored)
|
||||
ResetColor(true);
|
||||
|
|
@ -518,7 +530,10 @@ void Log::outDetail( const char * str, ... )
|
|||
if(m_includeTime)
|
||||
outTime();
|
||||
|
||||
UTF8PRINTF(stdout,str,);
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vutf8printf(stdout, str, &ap);
|
||||
va_end(ap);
|
||||
|
||||
if(m_colored)
|
||||
ResetColor(true);
|
||||
|
|
@ -527,12 +542,14 @@ void Log::outDetail( const char * str, ... )
|
|||
}
|
||||
if(logfile && m_logFileLevel > 1)
|
||||
{
|
||||
va_list ap;
|
||||
outTimestamp(logfile);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vfprintf(logfile, str, ap);
|
||||
fprintf(logfile, "\n" );
|
||||
va_end(ap);
|
||||
|
||||
fprintf(logfile, "\n" );
|
||||
fflush(logfile);
|
||||
}
|
||||
|
||||
|
|
@ -548,7 +565,10 @@ void Log::outDebugInLine( const char * str, ... )
|
|||
if(m_colored)
|
||||
SetColor(true,m_colors[LogDebug]);
|
||||
|
||||
UTF8PRINTF(stdout,str,);
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vutf8printf(stdout, str, &ap);
|
||||
va_end(ap);
|
||||
|
||||
if(m_colored)
|
||||
ResetColor(true);
|
||||
|
|
@ -574,7 +594,10 @@ void Log::outDebug( const char * str, ... )
|
|||
if(m_includeTime)
|
||||
outTime();
|
||||
|
||||
UTF8PRINTF(stdout,str,);
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vutf8printf(stdout, str, &ap);
|
||||
va_end(ap);
|
||||
|
||||
if(m_colored)
|
||||
ResetColor(true);
|
||||
|
|
@ -609,7 +632,10 @@ void Log::outCommand( uint32 account, const char * str, ... )
|
|||
if(m_includeTime)
|
||||
outTime();
|
||||
|
||||
UTF8PRINTF(stdout,str,);
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vutf8printf(stdout, str, &ap);
|
||||
va_end(ap);
|
||||
|
||||
if(m_colored)
|
||||
ResetColor(true);
|
||||
|
|
@ -691,7 +717,11 @@ void Log::outMenu( const char * str, ... )
|
|||
if(m_includeTime)
|
||||
outTime();
|
||||
|
||||
UTF8PRINTF(stdout,str,);
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, str);
|
||||
vutf8printf(stdout, str, &ap);
|
||||
va_end(ap);
|
||||
|
||||
ResetColor(true);
|
||||
|
||||
|
|
@ -699,7 +729,6 @@ void Log::outMenu( const char * str, ... )
|
|||
{
|
||||
outTimestamp(logfile);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vfprintf(logfile, str, ap);
|
||||
va_end(ap);
|
||||
|
|
|
|||
|
|
@ -135,12 +135,8 @@ uint32 TimeStringToSecs(const std::string& timestring)
|
|||
{
|
||||
if(isdigit(*itr))
|
||||
{
|
||||
std::string str; //very complicated typecast char->const char*; is there no better way?
|
||||
str += *itr;
|
||||
const char* tmp = str.c_str();
|
||||
|
||||
buffer*=10;
|
||||
buffer+=atoi(tmp);
|
||||
buffer+= (*itr)-'0';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -419,3 +415,29 @@ bool Utf8FitTo(const std::string& str, std::wstring search)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
void utf8printf(FILE *out, const char *str, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, str);
|
||||
vutf8printf(stdout, str, &ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void vutf8printf(FILE *out, const char *str, va_list* ap)
|
||||
{
|
||||
#if PLATFORM == PLATFORM_WINDOWS
|
||||
char temp_buf[32*1024];
|
||||
wchar_t wtemp_buf[32*1024];
|
||||
|
||||
size_t temp_len = vsnprintf(temp_buf, 32*1024, str, *ap);
|
||||
|
||||
size_t wtemp_len = 32*1024-1;
|
||||
Utf8toWStr(temp_buf, temp_len, wtemp_buf, wtemp_len);
|
||||
|
||||
CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], wtemp_len+1);
|
||||
fprintf(out, temp_buf);
|
||||
#else
|
||||
vfprintf(out, str, *ap);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,32 +283,8 @@ std::wstring GetMainPartOfName(std::wstring wname, uint32 declension);
|
|||
bool utf8ToConsole(const std::string& utf8str, std::string& conStr);
|
||||
bool consoleToUtf8(const std::string& conStr,std::string& utf8str);
|
||||
bool Utf8FitTo(const std::string& str, std::wstring search);
|
||||
|
||||
#if PLATFORM == PLATFORM_WINDOWS
|
||||
#define UTF8PRINTF(OUT,FRM,RESERR) \
|
||||
{ \
|
||||
char temp_buf[32*1024]; \
|
||||
va_list ap; \
|
||||
va_start(ap, FRM); \
|
||||
size_t temp_len = vsnprintf(temp_buf,32*1024,FRM,ap); \
|
||||
va_end(ap); \
|
||||
\
|
||||
wchar_t wtemp_buf[32*1024]; \
|
||||
size_t wtemp_len = 32*1024-1; \
|
||||
if(!Utf8toWStr(temp_buf,temp_len,wtemp_buf,wtemp_len)) \
|
||||
return RESERR; \
|
||||
CharToOemBuffW(&wtemp_buf[0],&temp_buf[0],wtemp_len+1);\
|
||||
fprintf(OUT,temp_buf); \
|
||||
}
|
||||
#else
|
||||
#define UTF8PRINTF(OUT,FRM,RESERR) \
|
||||
{ \
|
||||
va_list ap; \
|
||||
va_start(ap, FRM); \
|
||||
vfprintf(OUT, FRM, ap ); \
|
||||
va_end(ap); \
|
||||
}
|
||||
#endif
|
||||
void utf8printf(FILE *out, const char *str, ...);
|
||||
void vutf8printf(FILE *out, const char *str, va_list* ap);
|
||||
|
||||
bool IsIPAddress(char const* ipaddress);
|
||||
uint32 CreatePIDFile(const std::string& filename);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "8383"
|
||||
#define REVISION_NR "8396"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue