aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared')
-rw-r--r--src/server/shared/CMakeLists.txt1
-rw-r--r--src/server/shared/DataStores/DBCFileLoader.cpp6
-rw-r--r--src/server/shared/Database/DatabaseWorkerPool.h3
-rw-r--r--src/server/shared/Database/Implementation/CharacterDatabase.cpp2
-rw-r--r--src/server/shared/Database/Implementation/WorldDatabase.cpp2
-rw-r--r--src/server/shared/Database/MySQLConnection.cpp3
-rw-r--r--src/server/shared/Debugging/WheatyExceptionReport.cpp2
-rw-r--r--src/server/shared/Define.h7
-rw-r--r--src/server/shared/Networking/Socket.h52
-rw-r--r--src/server/shared/Networking/SocketMgr.h2
-rw-r--r--src/server/shared/Packets/ByteBuffer.h3
-rw-r--r--src/server/shared/Threading/ProcessPriority.h2
-rw-r--r--src/server/shared/Utilities/ServiceWin32.cpp3
-rw-r--r--src/server/shared/Utilities/Util.cpp16
-rw-r--r--src/server/shared/Utilities/Util.h7
15 files changed, 59 insertions, 52 deletions
diff --git a/src/server/shared/CMakeLists.txt b/src/server/shared/CMakeLists.txt
index a61248f01ea..7a02e415d69 100644
--- a/src/server/shared/CMakeLists.txt
+++ b/src/server/shared/CMakeLists.txt
@@ -77,6 +77,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/server/game/Entities/Object
${MYSQL_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
+ ${VALGRIND_INCLUDE_DIR}
)
add_library(shared STATIC
diff --git a/src/server/shared/DataStores/DBCFileLoader.cpp b/src/server/shared/DataStores/DBCFileLoader.cpp
index d027d7539ad..1b7d34464f6 100644
--- a/src/server/shared/DataStores/DBCFileLoader.cpp
+++ b/src/server/shared/DataStores/DBCFileLoader.cpp
@@ -112,11 +112,9 @@ bool DBCFileLoader::Load(const char* filename, const char* fmt)
DBCFileLoader::~DBCFileLoader()
{
- if (data)
- delete [] data;
+ delete[] data;
- if (fieldsOffset)
- delete [] fieldsOffset;
+ delete[] fieldsOffset;
}
DBCFileLoader::Record DBCFileLoader::getRecord(size_t id)
diff --git a/src/server/shared/Database/DatabaseWorkerPool.h b/src/server/shared/Database/DatabaseWorkerPool.h
index 5548e44c925..61385d92437 100644
--- a/src/server/shared/Database/DatabaseWorkerPool.h
+++ b/src/server/shared/Database/DatabaseWorkerPool.h
@@ -76,13 +76,12 @@ class DatabaseWorkerPool
bool Open(const std::string& infoString, uint8 async_threads, uint8 synch_threads)
{
- bool res = true;
_connectionInfo = new MySQLConnectionInfo(infoString);
TC_LOG_INFO("sql.driver", "Opening DatabasePool '%s'. Asynchronous connections: %u, synchronous connections: %u.",
GetDatabaseName(), async_threads, synch_threads);
- res = OpenConnections(IDX_ASYNC, async_threads);
+ bool res = OpenConnections(IDX_ASYNC, async_threads);
if (!res)
return res;
diff --git a/src/server/shared/Database/Implementation/CharacterDatabase.cpp b/src/server/shared/Database/Implementation/CharacterDatabase.cpp
index aa584d026fb..328a64dc5b3 100644
--- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp
+++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp
@@ -34,7 +34,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_INS_CHARACTER_BAN, "INSERT INTO character_banned VALUES (?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()+?, ?, ?, 1)", CONNECTION_ASYNC);
PrepareStatement(CHAR_UPD_CHARACTER_BAN, "UPDATE character_banned SET active = 0 WHERE guid = ? AND active != 0", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_CHARACTER_BAN, "DELETE cb FROM character_banned cb INNER JOIN characters c ON c.guid = cb.guid WHERE c.account = ?", CONNECTION_ASYNC);
- PrepareStatement(CHAR_SEL_BANINFO, "SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate, banreason, bannedby FROM character_banned WHERE guid = ? ORDER BY bandate ASC", CONNECTION_SYNCH);
+ PrepareStatement(CHAR_SEL_BANINFO, "SELECT bandate, unbandate-bandate, active, unbandate, banreason, bannedby FROM character_banned WHERE guid = ? ORDER BY bandate ASC", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_GUID_BY_NAME_FILTER, "SELECT guid, name FROM characters WHERE name LIKE CONCAT('%%', ?, '%%')", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_BANINFO_LIST, "SELECT bandate, unbandate, bannedby, banreason FROM character_banned WHERE guid = ? ORDER BY unbandate", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_BANNED_NAME, "SELECT characters.name FROM characters, character_banned WHERE character_banned.guid = ? AND character_banned.guid = characters.guid", CONNECTION_SYNCH);
diff --git a/src/server/shared/Database/Implementation/WorldDatabase.cpp b/src/server/shared/Database/Implementation/WorldDatabase.cpp
index f5d9913bc5b..e83901c8557 100644
--- a/src/server/shared/Database/Implementation/WorldDatabase.cpp
+++ b/src/server/shared/Database/Implementation/WorldDatabase.cpp
@@ -25,7 +25,7 @@ void WorldDatabaseConnection::DoPrepareStatements()
PrepareStatement(WORLD_SEL_QUEST_POOLS, "SELECT entry, pool_entry FROM pool_quest", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_CRELINKED_RESPAWN, "DELETE FROM linked_respawn WHERE guid = ?", CONNECTION_ASYNC);
PrepareStatement(WORLD_REP_CREATURE_LINKED_RESPAWN, "REPLACE INTO linked_respawn (guid, linkedGuid) VALUES (?, ?)", CONNECTION_ASYNC);
- PrepareStatement(WORLD_SEL_CREATURE_TEXT, "SELECT entry, groupid, id, text, type, language, probability, emote, duration, sound, BroadcastTextID FROM creature_text", CONNECTION_SYNCH);
+ PrepareStatement(WORLD_SEL_CREATURE_TEXT, "SELECT entry, groupid, id, text, type, language, probability, emote, duration, sound, BroadcastTextId, TextRange FROM creature_text", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_SMART_SCRIPTS, "SELECT entryorguid, source_type, id, link, event_type, event_phase_mask, event_chance, event_flags, event_param1, event_param2, event_param3, event_param4, action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, target_type, target_param1, target_param2, target_param3, target_x, target_y, target_z, target_o FROM smart_scripts ORDER BY entryorguid, source_type, id, link", CONNECTION_SYNCH);
PrepareStatement(WORLD_SEL_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z FROM waypoints ORDER BY entry, pointid", CONNECTION_SYNCH);
PrepareStatement(WORLD_DEL_GAMEOBJECT, "DELETE FROM gameobject WHERE guid = ?", CONNECTION_ASYNC);
diff --git a/src/server/shared/Database/MySQLConnection.cpp b/src/server/shared/Database/MySQLConnection.cpp
index abdf2a2cc3c..24290009625 100644
--- a/src/server/shared/Database/MySQLConnection.cpp
+++ b/src/server/shared/Database/MySQLConnection.cpp
@@ -57,8 +57,7 @@ m_connectionFlags(CONNECTION_ASYNC)
MySQLConnection::~MySQLConnection()
{
- if (m_worker)
- delete m_worker;
+ delete m_worker;
for (size_t i = 0; i < m_stmts.size(); ++i)
delete m_stmts[i];
diff --git a/src/server/shared/Debugging/WheatyExceptionReport.cpp b/src/server/shared/Debugging/WheatyExceptionReport.cpp
index 2eb456ddd02..e9f4f9ca9ac 100644
--- a/src/server/shared/Debugging/WheatyExceptionReport.cpp
+++ b/src/server/shared/Debugging/WheatyExceptionReport.cpp
@@ -1043,7 +1043,7 @@ bool logChildren)
offset, bHandled, Name, "", false, false);
// Set Value back to an empty string since the Array object itself has no value, only its elements have
- symbolDetails.top().Value = "";
+ symbolDetails.top().Value.clear();
DWORD elementsCount;
if (SymGetTypeInfo(m_hProcess, modBase, dwTypeIndex, TI_GET_COUNT, &elementsCount))
diff --git a/src/server/shared/Define.h b/src/server/shared/Define.h
index c33c8222ebb..075dd39002f 100644
--- a/src/server/shared/Define.h
+++ b/src/server/shared/Define.h
@@ -31,6 +31,11 @@
# if !defined(_GLIBCXX_USE_NANOSLEEP)
# define _GLIBCXX_USE_NANOSLEEP
# endif
+# if defined(HELGRIND)
+# include <valgrind/helgrind.h>
+# define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(A) ANNOTATE_HAPPENS_BEFORE(A)
+# define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(A) ANNOTATE_HAPPENS_AFTER(A)
+# endif
#endif
#include <cstddef>
@@ -88,6 +93,8 @@
#define SI64FMTD "%" PRId64
#define SI64LIT(N) INT64_C(N)
+#define SZFMTD "%" PRIuPTR
+
typedef int64_t int64;
typedef int32_t int32;
typedef int16_t int16;
diff --git a/src/server/shared/Networking/Socket.h b/src/server/shared/Networking/Socket.h
index 6aa7974b1c1..d3e29ceaaea 100644
--- a/src/server/shared/Networking/Socket.h
+++ b/src/server/shared/Networking/Socket.h
@@ -34,6 +34,7 @@
using boost::asio::ip::tcp;
#define READ_BLOCK_SIZE 4096
+#define TC_SOCKET_USE_IOCP BOOST_ASIO_HAS_IOCP
template<class T>
class Socket : public std::enable_shared_from_this<T>
@@ -58,11 +59,15 @@ public:
if (!IsOpen())
return false;
-#ifndef BOOST_ASIO_HAS_IOCP
+#ifndef TC_SOCKET_USE_IOCP
+ std::unique_lock<std::mutex> guard(_writeLock, std::try_to_lock);
+ if (!guard)
+ return true;
+
if (_isWritingAsync || (!_writeBuffer.GetActiveSize() && _writeQueue.empty()))
return true;
- for (; WriteHandler(boost::system::error_code(), 0);)
+ for (; WriteHandler(guard);)
;
#endif
@@ -113,10 +118,10 @@ public:
{
_writeQueue.push(std::move(buffer));
-#ifdef BOOST_ASIO_HAS_IOCP
+#ifdef TC_SOCKET_USE_IOCP
AsyncProcessQueue(guard);
#else
- (void)guard;
+ (void)guard;
#endif
}
@@ -145,24 +150,25 @@ protected:
bool AsyncProcessQueue(std::unique_lock<std::mutex>&)
{
if (_isWritingAsync)
- return true;
+ return false;
_isWritingAsync = true;
-
-#ifdef BOOST_ASIO_HAS_IOCP
+
+#ifdef TC_SOCKET_USE_IOCP
MessageBuffer& buffer = _writeQueue.front();
_socket.async_write_some(boost::asio::buffer(buffer.GetReadPointer(), buffer.GetActiveSize()), std::bind(&Socket<T>::WriteHandler,
this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
#else
- _socket.async_write_some(boost::asio::null_buffers(), std::bind(&Socket<T>::WriteHandler, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
+ _socket.async_write_some(boost::asio::null_buffers(), std::bind(&Socket<T>::WriteHandlerWrapper,
+ this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
#endif
- return true;
+ return false;
}
std::mutex _writeLock;
std::queue<MessageBuffer> _writeQueue;
-#ifndef BOOST_ASIO_HAS_IOCP
+#ifndef TC_SOCKET_USE_IOCP
MessageBuffer _writeBuffer;
#endif
@@ -179,7 +185,7 @@ private:
ReadHandler();
}
-#ifdef BOOST_ASIO_HAS_IOCP
+#ifdef TC_SOCKET_USE_IOCP
void WriteHandler(boost::system::error_code error, std::size_t transferedBytes)
{
@@ -203,12 +209,15 @@ private:
#else
- bool WriteHandler(boost::system::error_code /*error*/, std::size_t /*transferedBytes*/)
+ void WriteHandlerWrapper(boost::system::error_code /*error*/, std::size_t /*transferedBytes*/)
{
- std::unique_lock<std::mutex> guard(_writeLock, std::try_to_lock);
- if (!guard)
- return false;
+ std::unique_lock<std::mutex> guard(_writeLock);
+ _isWritingAsync = false;
+ WriteHandler(guard);
+ }
+ bool WriteHandler(std::unique_lock<std::mutex>& guard)
+ {
if (!IsOpen())
return false;
@@ -229,7 +238,7 @@ private:
}
else if (bytesWritten == 0)
return false;
- else if (bytesWritten < bytesToSend) //now n > 0
+ else if (bytesWritten < bytesToSend)
{
_writeBuffer.ReadCompleted(bytesWritten);
_writeBuffer.Normalize();
@@ -245,10 +254,7 @@ private:
bool HandleQueue(std::unique_lock<std::mutex>& guard)
{
if (_writeQueue.empty())
- {
- _isWritingAsync = false;
return false;
- }
MessageBuffer& queuedMessage = _writeQueue.front();
@@ -277,13 +283,7 @@ private:
}
_writeQueue.pop();
- if (_writeQueue.empty())
- {
- _isWritingAsync = false;
- return false;
- }
-
- return true;
+ return !_writeQueue.empty();
}
#endif
diff --git a/src/server/shared/Networking/SocketMgr.h b/src/server/shared/Networking/SocketMgr.h
index 47bd7794a4c..dbe2b8ec902 100644
--- a/src/server/shared/Networking/SocketMgr.h
+++ b/src/server/shared/Networking/SocketMgr.h
@@ -97,7 +97,7 @@ public:
int32 GetNetworkThreadCount() const { return _threadCount; }
protected:
- SocketMgr() : _threads(nullptr), _threadCount(1)
+ SocketMgr() : _acceptor(nullptr), _threads(nullptr), _threadCount(1)
{
}
diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h
index 046fdc0c8e9..3d44c975c96 100644
--- a/src/server/shared/Packets/ByteBuffer.h
+++ b/src/server/shared/Packets/ByteBuffer.h
@@ -32,6 +32,7 @@
#include <cstring>
#include <time.h>
#include <cmath>
+#include <type_traits>
#include <boost/asio/buffer.hpp>
class MessageBuffer;
@@ -113,12 +114,14 @@ class ByteBuffer
template <typename T> void append(T value)
{
+ static_assert(std::is_fundamental<T>::value, "append(compound)");
EndianConvert(value);
append((uint8 *)&value, sizeof(value));
}
template <typename T> void put(size_t pos, T value)
{
+ static_assert(std::is_fundamental<T>::value, "append(compound)");
EndianConvert(value);
put(pos, (uint8 *)&value, sizeof(value));
}
diff --git a/src/server/shared/Threading/ProcessPriority.h b/src/server/shared/Threading/ProcessPriority.h
index 23238c94ace..6446820e32d 100644
--- a/src/server/shared/Threading/ProcessPriority.h
+++ b/src/server/shared/Threading/ProcessPriority.h
@@ -26,7 +26,7 @@
#define PROCESS_HIGH_PRIORITY -15 // [-20, 19], default is 0
#endif
-void SetProcessPriority(const std::string logChannel)
+void SetProcessPriority(const std::string& logChannel)
{
// Suppresses Mac OS X Warning since logChannel isn't used.
#if PLATFORM_APPLE
diff --git a/src/server/shared/Utilities/ServiceWin32.cpp b/src/server/shared/Utilities/ServiceWin32.cpp
index ecf403423f7..6e5309d70d7 100644
--- a/src/server/shared/Utilities/ServiceWin32.cpp
+++ b/src/server/shared/Utilities/ServiceWin32.cpp
@@ -204,7 +204,8 @@ void WINAPI ServiceMain(DWORD argc, char *argv[])
GetModuleFileName(0, path, sizeof(path)/sizeof(path[0]));
- for (i = 0; i < std::strlen(path); i++)
+ size_t pathLen = std::strlen(path);
+ for (i = 0; i < pathLen; i++)
{
if (path[i] == '\\') last_slash = i;
}
diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp
index f2c02510ed4..e577797d3e0 100644
--- a/src/server/shared/Utilities/Util.cpp
+++ b/src/server/shared/Utilities/Util.cpp
@@ -294,7 +294,7 @@ size_t utf8length(std::string& utf8str)
}
catch(std::exception)
{
- utf8str = "";
+ utf8str.clear();
return 0;
}
}
@@ -316,7 +316,7 @@ void utf8truncate(std::string& utf8str, size_t len)
}
catch(std::exception)
{
- utf8str = "";
+ utf8str.clear();
}
}
@@ -360,7 +360,7 @@ bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr)
}
catch(std::exception)
{
- wstr = L"";
+ wstr.clear();
return false;
}
@@ -383,14 +383,14 @@ bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str)
}
catch(std::exception)
{
- utf8str = "";
+ utf8str.clear();
return false;
}
return true;
}
-bool WStrToUtf8(std::wstring wstr, std::string& utf8str)
+bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str)
{
try
{
@@ -406,7 +406,7 @@ bool WStrToUtf8(std::wstring wstr, std::string& utf8str)
}
catch(std::exception)
{
- utf8str = "";
+ utf8str.clear();
return false;
}
@@ -415,7 +415,7 @@ bool WStrToUtf8(std::wstring wstr, std::string& utf8str)
typedef wchar_t const* const* wstrlist;
-std::wstring GetMainPartOfName(std::wstring wname, uint32 declension)
+std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension)
{
// supported only Cyrillic cases
if (wname.size() < 1 || !isCyrillicCharacter(wname[0]) || declension > 5)
@@ -492,7 +492,7 @@ bool consoleToUtf8(const std::string& conStr, std::string& utf8str)
#endif
}
-bool Utf8FitTo(const std::string& str, std::wstring search)
+bool Utf8FitTo(const std::string& str, std::wstring const& search)
{
std::wstring temp;
diff --git a/src/server/shared/Utilities/Util.h b/src/server/shared/Utilities/Util.h
index 20c17b14023..d88ad3be8e1 100644
--- a/src/server/shared/Utilities/Util.h
+++ b/src/server/shared/Utilities/Util.h
@@ -147,7 +147,7 @@ inline bool Utf8toWStr(const std::string& utf8str, wchar_t* wstr, size_t& wsize)
return Utf8toWStr(utf8str.c_str(), utf8str.size(), wstr, wsize);
}
-bool WStrToUtf8(std::wstring wstr, std::string& utf8str);
+bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str);
// size==real string size
bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str);
@@ -331,11 +331,11 @@ inline void wstrToLower(std::wstring& str)
std::transform( str.begin(), str.end(), str.begin(), wcharToLower );
}
-std::wstring GetMainPartOfName(std::wstring wname, uint32 declension);
+std::wstring GetMainPartOfName(std::wstring const& 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);
+bool Utf8FitTo(const std::string& str, std::wstring const& search);
void utf8printf(FILE* out, const char *str, ...);
void vutf8printf(FILE* out, const char *str, va_list* ap);
@@ -876,7 +876,6 @@ class EventMap
*/
EventStore _eventMap;
-
/**
* @name _lastEvent
* @brief Stores information on the most recently executed event