Merge commit '6c1e4bc20d68d9fb548eb4896bd8b84a4c3ec4ff' into 4.3.4

Conflicts:
	README.md
	sql/updates/world/2015_04_04_00_world.sql
	sql/updates/world/2015_04_04_01_world.sql
	sql/updates/world/2015_04_05_06_world_335.sql
	src/server/game/Battlegrounds/Battleground.cpp
	src/server/game/DataStores/DBCStores.cpp
	src/server/game/DataStores/DBCStructure.h
	src/server/game/DataStores/DBCfmt.h
	src/server/game/Entities/Object/Object.cpp
	src/server/game/Entities/Player/Player.cpp
	src/server/game/Entities/Player/Player.h
	src/server/game/Entities/Unit/Unit.cpp
	src/server/game/Handlers/CharacterHandler.cpp
	src/server/game/Server/WorldSession.cpp
	src/server/game/Server/WorldSocket.cpp
	src/server/game/Spells/Spell.cpp
	src/server/game/Spells/SpellInfo.cpp
	src/server/game/World/World.cpp
	src/server/scripts/Commands/cs_account.cpp
	src/tools/map_extractor/System.cpp
	src/tools/vmap4_extractor/adtfile.cpp
This commit is contained in:
Carbenium
2015-07-22 00:54:34 +02:00
181 changed files with 707 additions and 1014 deletions

View File

@@ -84,6 +84,8 @@ include_directories(
${VALGRIND_INCLUDE_DIR}
)
GroupSources(${CMAKE_CURRENT_SOURCE_DIR})
add_library(shared STATIC
${shared_STAT_SRCS}
${shared_STAT_PCH_SRC}

View File

@@ -21,7 +21,6 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include "Config.h"
#include "Errors.h"
using namespace boost::property_tree;

View File

@@ -17,7 +17,6 @@
*/
#include "ARC4.h"
#include <openssl/sha.h>
ARC4::ARC4(uint8 len) : m_ctx()
{

View File

@@ -18,7 +18,6 @@
#include "Cryptography/BigNumber.h"
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <cstring>
#include <algorithm>
#include <memory>

View File

@@ -18,8 +18,6 @@
#include "DatabaseEnv.h"
#include "DatabaseWorker.h"
#include "SQLOperation.h"
#include "MySQLConnection.h"
#include "MySQLThreading.h"
#include "ProducerConsumerQueue.h"
DatabaseWorker::DatabaseWorker(ProducerConsumerQueue<SQLOperation*>* newQueue, MySQLConnection* connection)

View File

@@ -28,6 +28,7 @@
#include "QueryResult.h"
#include "QueryHolder.h"
#include "AdhocStatement.h"
#include "StringFormat.h"
#include <mysqld_error.h>
#include <memory>
@@ -170,18 +171,13 @@ class DatabaseWorkerPool
//! Enqueues a one-way SQL operation in string format -with variable args- that will be executed asynchronously.
//! This method should only be used for queries that are only executed once, e.g during startup.
void PExecute(const char* sql, ...)
template<typename... Args>
void PExecute(const char* sql, Args const&... args)
{
if (!sql)
return;
va_list ap;
char szQuery[MAX_QUERY_LEN];
va_start(ap, sql);
vsnprintf(szQuery, MAX_QUERY_LEN, sql, ap);
va_end(ap);
Execute(szQuery);
Execute(Trinity::StringFormat(sql, args...).c_str());
}
//! Enqueues a one-way SQL operation in prepared statement format that will be executed asynchronously.
@@ -210,18 +206,13 @@ class DatabaseWorkerPool
//! Directly executes a one-way SQL operation in string format -with variable args-, that will block the calling thread until finished.
//! This method should only be used for queries that are only executed once, e.g during startup.
void DirectPExecute(const char* sql, ...)
template<typename... Args>
void DirectPExecute(const char* sql, Args const&... args)
{
if (!sql)
return;
va_list ap;
char szQuery[MAX_QUERY_LEN];
va_start(ap, sql);
vsnprintf(szQuery, MAX_QUERY_LEN, sql, ap);
va_end(ap);
return DirectExecute(szQuery);
DirectExecute(Trinity::StringFormat(sql, args...).c_str());
}
//! Directly executes a one-way SQL operation in prepared statement format, that will block the calling thread until finished.
@@ -260,34 +251,24 @@ class DatabaseWorkerPool
//! Directly executes an SQL query in string format -with variable args- that will block the calling thread until finished.
//! Returns reference counted auto pointer, no need for manual memory management in upper level code.
QueryResult PQuery(const char* sql, T* conn, ...)
template<typename... Args>
QueryResult PQuery(const char* sql, T* conn, Args const&... args)
{
if (!sql)
return QueryResult(NULL);
va_list ap;
char szQuery[MAX_QUERY_LEN];
va_start(ap, conn);
vsnprintf(szQuery, MAX_QUERY_LEN, sql, ap);
va_end(ap);
return Query(szQuery, conn);
return Query(Trinity::StringFormat(sql, args...).c_str(), conn);
}
//! Directly executes an SQL query in string format -with variable args- that will block the calling thread until finished.
//! Returns reference counted auto pointer, no need for manual memory management in upper level code.
QueryResult PQuery(const char* sql, ...)
template<typename... Args>
QueryResult PQuery(const char* sql, Args const&... args)
{
if (!sql)
return QueryResult(NULL);
va_list ap;
char szQuery[MAX_QUERY_LEN];
va_start(ap, sql);
vsnprintf(szQuery, MAX_QUERY_LEN, sql, ap);
va_end(ap);
return Query(szQuery);
return Query(Trinity::StringFormat(sql, args...).c_str());
}
//! Directly executes an SQL query in prepared format that will block the calling thread until finished.
@@ -328,15 +309,10 @@ class DatabaseWorkerPool
//! Enqueues a query in string format -with variable args- that will set the value of the QueryResultFuture return object as soon as the query is executed.
//! The return value is then processed in ProcessQueryCallback methods.
QueryResultFuture AsyncPQuery(const char* sql, ...)
template<typename... Args>
QueryResultFuture AsyncPQuery(const char* sql, Args const&... args)
{
va_list ap;
char szQuery[MAX_QUERY_LEN];
va_start(ap, sql);
vsnprintf(szQuery, MAX_QUERY_LEN, sql, ap);
va_end(ap);
return AsyncQuery(szQuery);
return AsyncQuery(Trinity::StringFormat(sql, args...).c_str());
}
//! Enqueues a query in prepared format that will set the value of the PreparedQueryResultFuture return object as soon as the query is executed.

View File

@@ -22,11 +22,9 @@
#include <winsock2.h>
#endif
#include <mysql.h>
#include <mysqld_error.h>
#include <errmsg.h>
#include "MySQLConnection.h"
#include "MySQLThreading.h"
#include "QueryResult.h"
#include "SQLOperation.h"
#include "PreparedStatement.h"

View File

@@ -40,29 +40,6 @@ bool SQLQueryHolder::SetQuery(size_t index, const char *sql)
return true;
}
bool SQLQueryHolder::SetPQuery(size_t index, const char *format, ...)
{
if (!format)
{
TC_LOG_ERROR("sql.sql", "Query (index: %u) is empty.", uint32(index));
return false;
}
va_list ap;
char szQuery [MAX_QUERY_LEN];
va_start(ap, format);
int res = vsnprintf(szQuery, MAX_QUERY_LEN, format, ap);
va_end(ap);
if (res == -1)
{
TC_LOG_ERROR("sql.sql", "SQL Query truncated (and not execute) for format: %s", format);
return false;
}
return SetQuery(index, szQuery);
}
bool SQLQueryHolder::SetPreparedQuery(size_t index, PreparedStatement* stmt)
{
if (m_queries.size() <= index)

View File

@@ -29,8 +29,9 @@ class SQLQueryHolder
public:
SQLQueryHolder() { }
~SQLQueryHolder();
bool SetQuery(size_t index, const char *sql);
bool SetPQuery(size_t index, const char *format, ...) ATTR_PRINTF(3, 4);
bool SetQuery(size_t index, const char* sql);
template<typename... Args>
bool SetPQuery(size_t index, const char* sql, Args const&... args) { return SetQuery(index, Trinity::StringFormat(sql, args...).c_str()); }
bool SetPreparedQuery(size_t index, PreparedStatement* stmt);
void SetSize(size_t size);
QueryResult GetResult(size_t index);

View File

@@ -30,17 +30,6 @@ void Transaction::Append(const char* sql)
m_queries.push_back(data);
}
void Transaction::PAppend(const char* sql, ...)
{
va_list ap;
char szQuery [MAX_QUERY_LEN];
va_start(ap, sql);
vsnprintf(szQuery, MAX_QUERY_LEN, sql, ap);
va_end(ap);
Append(szQuery);
}
//- Append a prepared statement to the transaction
void Transaction::Append(PreparedStatement* stmt)
{

View File

@@ -19,6 +19,7 @@
#define _TRANSACTION_H
#include "SQLOperation.h"
#include "StringFormat.h"
//- Forward declare (don't include header to prevent circular includes)
class PreparedStatement;
@@ -38,7 +39,8 @@ class Transaction
void Append(PreparedStatement* statement);
void Append(const char* sql);
void PAppend(const char* sql, ...);
template<typename... Args>
void PAppend(const char* sql, Args const&... args) { Append(Trinity::StringFormat(sql, args...).c_str()); }
size_t GetSize() const { return m_queries.size(); }

View File

@@ -47,12 +47,12 @@ class ObjectRegistry
}
/// Inserts a registry item
bool InsertItem(T *obj, Key key, bool override = false)
bool InsertItem(T *obj, Key key, bool _override = false)
{
typename RegistryMapType::iterator iter = i_registeredObjects.find(key);
if ( iter != i_registeredObjects.end() )
{
if ( !override )
if ( !_override )
return false;
delete iter->second;
i_registeredObjects.erase(iter);

View File

@@ -25,7 +25,6 @@
#include "AppenderDB.h"
#include "LogOperation.h"
#include <cstdarg>
#include <cstdio>
#include <sstream>

View File

@@ -64,7 +64,7 @@ class Log
template<typename... Args>
inline void outMessage(std::string const& filter, LogLevel const level, const char* fmt, Args const&... args)
{
write(std::move(std::unique_ptr<LogMessage>(new LogMessage(level, filter, std::move(Trinity::StringFormat(fmt, args...))))));
write(std::unique_ptr<LogMessage>(new LogMessage(level, filter, Trinity::StringFormat(fmt, args...))));
}
template<typename... Args>

View File

@@ -62,7 +62,7 @@ public:
return false;
#ifndef TC_SOCKET_USE_IOCP
std::unique_lock<std::mutex> guard(_writeLock, std::try_to_lock);
std::unique_lock<std::mutex> guard(_writeLock);
if (!guard)
return true;
@@ -140,6 +140,8 @@ public:
if (shutdownError)
TC_LOG_DEBUG("network", "Socket::CloseSocket: %s errored when shutting down socket: %i (%s)", GetRemoteIpAddress().to_string().c_str(),
shutdownError.value(), shutdownError.message().c_str());
OnClose();
}
/// Marks the socket for closing after write buffer becomes empty
@@ -148,6 +150,8 @@ public:
MessageBuffer& GetReadBuffer() { return _readBuffer; }
protected:
virtual void OnClose() { }
virtual void ReadHandler() = 0;
bool AsyncProcessQueue(std::unique_lock<std::mutex>&)

View File

@@ -26,7 +26,6 @@
#include <iostream>
#include <unordered_map>
#include <boost/process.hpp>
#include <boost/process/mitigate.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/system/system_error.hpp>
@@ -240,11 +239,19 @@ bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool)
[&](Path const& file) { DBUpdater<T>::ApplyFile(pool, file); },
[&](std::string const& query) -> QueryResult { return DBUpdater<T>::Retrieve(pool, query); });
uint32 const count = updateFetcher.Update(
sConfigMgr->GetBoolDefault("Updates.Redundancy", true),
sConfigMgr->GetBoolDefault("Updates.AllowRehash", true),
sConfigMgr->GetBoolDefault("Updates.ArchivedRedundancy", false),
sConfigMgr->GetIntDefault("Updates.CleanDeadRefMaxCount", 3));
uint32 count;
try
{
count = updateFetcher.Update(
sConfigMgr->GetBoolDefault("Updates.Redundancy", true),
sConfigMgr->GetBoolDefault("Updates.AllowRehash", true),
sConfigMgr->GetBoolDefault("Updates.ArchivedRedundancy", false),
sConfigMgr->GetIntDefault("Updates.CleanDeadRefMaxCount", 3));
}
catch (UpdateException&)
{
return false;
}
if (!count)
TC_LOG_INFO("sql.updates", ">> %s database is up-to-date!", DBUpdater<T>::GetTableName().c_str());
@@ -299,7 +306,14 @@ bool DBUpdater<T>::Populate(DatabaseWorkerPool<T>& pool)
// Update database
TC_LOG_INFO("sql.updates", ">> Applying \'%s\'...", base.generic_string().c_str());
ApplyFile(pool, base);
try
{
ApplyFile(pool, base);
}
catch (UpdateException&)
{
return false;
}
TC_LOG_INFO("sql.updates", ">> Done!");
return true;

View File

@@ -27,7 +27,7 @@
class UpdateFetcher
{
using Path = boost::filesystem::path;
typedef boost::filesystem::path Path;
public:
UpdateFetcher(Path const& updateDirectory,
@@ -53,6 +53,9 @@ private:
struct AppliedFileEntry
{
AppliedFileEntry(std::string const& name_, std::string const& hash_, State state_, uint64 timestamp_)
: name(name_), hash(hash_), state(state_), timestamp(timestamp_) { }
std::string const name;
std::string const hash;
@@ -79,12 +82,14 @@ private:
struct DirectoryEntry
{
DirectoryEntry(Path const& path_, State state_) : path(path_), state(state_) { }
Path const path;
State const state;
};
using LocaleFileEntry = std::pair<Path, State>;
typedef std::pair<Path, State> LocaleFileEntry;
struct PathCompare
{
@@ -94,11 +99,11 @@ private:
}
};
using LocaleFileStorage = std::set<LocaleFileEntry, PathCompare>;
using HashToFileNameStorage = std::unordered_map<std::string, std::string>;
using AppliedFileStorage = std::unordered_map<std::string, AppliedFileEntry>;
using DirectoryStorage = std::vector<UpdateFetcher::DirectoryEntry>;
using SQLUpdate = std::shared_ptr<std::string>;
typedef std::set<LocaleFileEntry, PathCompare> LocaleFileStorage;
typedef std::unordered_map<std::string, std::string> HashToFileNameStorage;
typedef std::unordered_map<std::string, AppliedFileEntry> AppliedFileStorage;
typedef std::vector<UpdateFetcher::DirectoryEntry> DirectoryStorage;
typedef std::shared_ptr<std::string> SQLUpdate;
LocaleFileStorage GetFileList() const;
void FillFileListRecursively(Path const& path, LocaleFileStorage& storage, State const state, uint32 const depth) const;

View File

@@ -255,7 +255,7 @@ bool WinServiceRun()
if (!StartServiceCtrlDispatcher(serviceTable))
{
TC_LOG_ERROR("server.worldserver", "StartService Failed. Error [%u]", ::GetLastError());
TC_LOG_ERROR("server.worldserver", "StartService Failed. Error [%u]", uint32(::GetLastError()));
return false;
}
return true;