Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dep/g3dlite/source/debugAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void createErrorMessage(
if (NULL != formatMsg) {
realLastErr = formatMsg;
} else {
realLastErr = _T("Last error code does not exist.");
realLastErr = (LPTSTR)_T("Last error code does not exist.");
}

if (lastErr != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/Debugging/WheatyExceptionReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ PEXCEPTION_POINTERS pExceptionInfo)
// Given an exception code, returns a pointer to a static string with a
// description of the exception
//======================================================================
LPTSTR WheatyExceptionReport::GetExceptionString(DWORD dwCode)
LPCTSTR WheatyExceptionReport::GetExceptionString(DWORD dwCode)
{
#define EXCEPTION(x) case EXCEPTION_##x: return _T(#x);

Expand Down
2 changes: 1 addition & 1 deletion src/common/Debugging/WheatyExceptionReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class WheatyExceptionReport
static BOOL _GetProcessorName(TCHAR* sProcessorName, DWORD maxcount);

// Helper functions
static LPTSTR GetExceptionString(DWORD dwCode);
static LPCTSTR GetExceptionString(DWORD dwCode);
static BOOL GetLogicalAddress(PVOID addr, PTSTR szModule, DWORD len,
DWORD& section, DWORD_PTR& offset);

Expand Down
5 changes: 4 additions & 1 deletion src/common/Utilities/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ namespace Trinity
using type = find_type_end;
};

template<typename T>
struct type_identity { using type = T; };

template<template<typename...> typename Check, typename T1, typename... Ts>
struct find_type_if<Check, T1, Ts...> : std::conditional_t<Check<T1>::value, std::type_identity<T1>, find_type_if<Check, Ts...>>
struct find_type_if<Check, T1, Ts...> : std::conditional_t<Check<T1>::value, type_identity<T1>, find_type_if<Check, Ts...>>
{
};

Expand Down
4 changes: 2 additions & 2 deletions src/server/database/Database/FieldValueConverters.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class PrimitiveResultValueConverter : public BaseDatabaseResultValueConverter
};

template<>
class PrimitiveResultValueConverter<char const*, std::type_identity_t> : public BaseDatabaseResultValueConverter
class PrimitiveResultValueConverter<char const*, Trinity::type_identity> : public BaseDatabaseResultValueConverter
{
public:
uint8 GetUInt8(char const* /*data*/, uint32 /*size*/, QueryResultFieldMetadata const* meta) const override { LogTruncation("Field::GetUInt8", meta); return 0; }
Expand All @@ -109,7 +109,7 @@ class PrimitiveResultValueConverter<char const*, std::type_identity_t> : public
char const* GetCString(char const* data, uint32 /*size*/, QueryResultFieldMetadata const* /*meta*/) const override { return data; }
};

using StringResultValueConverter = PrimitiveResultValueConverter<char const*, std::type_identity_t>;
using StringResultValueConverter = PrimitiveResultValueConverter<char const*, Trinity::type_identity>;

class NotImplementedResultValueConverter : public BaseDatabaseResultValueConverter
{
Expand Down
6 changes: 3 additions & 3 deletions src/server/database/Database/MySQLConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ void MySQLConnection::StartWorkerThread(Trinity::Asio::IoContext* context)
{
boost::asio::executor_work_guard executorWorkGuard = boost::asio::make_work_guard(context->get_executor()); // construct guard before thread starts running

m_workerThread = std::make_unique<WorkerThread>(WorkerThread{
.ThreadHandle = std::thread([context] { context->run(); }),
.WorkGuard = std::move(executorWorkGuard)
m_workerThread = std::make_unique<WorkerThread>(WorkerThread{
std::thread([context] { context->run(); }),
std::move(executorWorkGuard)
});
}

Expand Down
19 changes: 9 additions & 10 deletions src/server/database/Database/MySQLPreparedStatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,16 @@ void MySQLPreparedStatement::SetParameter(uint8 index, SystemTimePoint value)
delete param->length;
param->length = new unsigned long(len);

std::chrono::year_month_day ymd(time_point_cast<std::chrono::days>(value));
std::chrono::hh_mm_ss hms(duration_cast<std::chrono::microseconds>(value - std::chrono::sys_days(ymd)));

time_t tt = std::chrono::system_clock::to_time_t(value);
tm* t = gmtime(&tt);
MYSQL_TIME* time = reinterpret_cast<MYSQL_TIME*>(static_cast<char*>(param->buffer));
time->year = static_cast<int32>(ymd.year());
time->month = static_cast<uint32>(ymd.month());
time->day = static_cast<uint32>(ymd.day());
time->hour = hms.hours().count();
time->minute = hms.minutes().count();
time->second = hms.seconds().count();
time->second_part = hms.subseconds().count();
time->year = t->tm_year + 1900;
time->month = t->tm_mon + 1;
time->day = t->tm_mday;
time->hour = t->tm_hour;
time->minute = t->tm_min;
time->second = t->tm_sec;
time->second_part = 0;
}

void MySQLPreparedStatement::SetParameter(uint8 index, std::string const& value)
Expand Down
37 changes: 29 additions & 8 deletions src/server/database/Database/QueryCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,36 @@ bool QueryCallback::InvokeIfReady()
return false;
};

return std::visit([&]<typename Result>(std::future<Result>&& future)
struct Visitor
{
if (future.valid() && future.wait_for(0s) == std::future_status::ready)
QueryCallback& self;
std::function<bool()>& checkStateAndReturnCompletion;

bool operator()(std::future<QueryResult>&& future)
{
std::future<Result> f(std::move(future));
std::function<void(QueryCallback&, Result)> cb(std::get<std::function<void(QueryCallback&, Result)>>(std::move(_callbacks.front())));
cb(*this, f.get());
return checkStateAndReturnCompletion();
if (future.valid() && future.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
std::future<QueryResult> f(std::move(future));
std::function<void(QueryCallback&, QueryResult)> cb(std::get<std::function<void(QueryCallback&, QueryResult)>>(std::move(self._callbacks.front())));
cb(self, f.get());
return checkStateAndReturnCompletion();
}
return false;
}
return false;
}, std::move(_query));

bool operator()(std::future<PreparedQueryResult>&& future)
{
if (future.valid() && future.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
std::future<PreparedQueryResult> f(std::move(future));
std::function<void(QueryCallback&, PreparedQueryResult)> cb(std::get<std::function<void(QueryCallback&, PreparedQueryResult)>>(std::move(self._callbacks.front())));
cb(self, f.get());
return checkStateAndReturnCompletion();
}
return false;
}
};
std::function<bool()> checkFn = checkStateAndReturnCompletion;
Visitor v{*this, checkFn};
return std::visit(v, std::move(_query));
}
25 changes: 19 additions & 6 deletions src/server/database/Database/QueryResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,26 @@ class DateResultValueConverter : public BaseDatabaseResultValueConverter
switch (source.time_type)
{
case MYSQL_TIMESTAMP_DATE:
return sys_days(year(source.year) / month(source.month) / day(source.day));
{
std::tm t = {};
t.tm_year = source.year - 1900;
t.tm_mon = source.month - 1;
t.tm_mday = source.day;
time_t tt = mktime(&t);
return std::chrono::system_clock::from_time_t(tt);
}
case MYSQL_TIMESTAMP_DATETIME:
return sys_days(year(source.year) / month(source.month) / day(source.day))
+ hours(source.hour)
+ minutes(source.minute)
+ seconds(source.second)
+ microseconds(source.second_part);
{
std::tm t = {};
t.tm_year = source.year - 1900;
t.tm_mon = source.month - 1;
t.tm_mday = source.day;
t.tm_hour = source.hour;
t.tm_min = source.minute;
t.tm_sec = source.second;
time_t tt = mktime(&t);
return std::chrono::system_clock::from_time_t(tt) + std::chrono::microseconds(source.second_part);
}
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28729,7 +28729,7 @@ void Player::SendGarrisonInfo() const
{
garrisonInfo.Plots.push_back(&plot->PacketInfo);
if (plot->BuildingInfo.PacketInfo)
garrisonInfo.Buildings.push_back(std::to_address(plot->BuildingInfo.PacketInfo));
garrisonInfo.Buildings.push_back(plot->BuildingInfo.PacketInfo.has_value() ? &(*plot->BuildingInfo.PacketInfo) : nullptr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Handlers/PetHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ void WorldSession::HandlePetRename(WorldPackets::Pet::PetRename& packet)
ObjectGuid petguid = packet.RenameData.PetGUID;

std::string name = packet.RenameData.NewName;
DeclinedName const* declinedname = std::to_address(packet.RenameData.DeclinedNames);
DeclinedName const* declinedname = packet.RenameData.DeclinedNames.has_value() ? &(*packet.RenameData.DeclinedNames) : nullptr;

Pet* pet = ObjectAccessor::GetPet(*_player, petguid);
// check it!
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4470,10 +4470,10 @@ void Spell::EffectCharge(SpellEffIndex effIndex)
{
//unitTarget->GetContactPoint(m_caster, pos.m_positionX, pos.m_positionY, pos.m_positionZ);
Position pos = unitTarget->GetFirstCollisionPosition(unitTarget->GetObjectSize(), unitTarget->GetRelativeAngle(m_caster));
m_caster->GetMotionMaster()->MoveCharge(pos.m_positionX, pos.m_positionY, pos.m_positionZ, speed, EVENT_CHARGE, false, unitTarget, std::to_address(spellEffectExtraData));
m_caster->GetMotionMaster()->MoveCharge(pos.m_positionX, pos.m_positionY, pos.m_positionZ, speed, EVENT_CHARGE, false, unitTarget, spellEffectExtraData ? &(*spellEffectExtraData) : nullptr);
}
else
m_caster->GetMotionMaster()->MoveCharge(*m_preGeneratedPath, speed, unitTarget, std::to_address(spellEffectExtraData));
m_caster->GetMotionMaster()->MoveCharge(*m_preGeneratedPath, speed, unitTarget, spellEffectExtraData ? &(*spellEffectExtraData) : nullptr);
}

if (effectHandleMode == SPELL_EFFECT_HANDLE_HIT_TARGET)
Expand Down
5 changes: 3 additions & 2 deletions src/server/scripts/Draenor/Highmaul/boss_the_butcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

# include "highmaul.h"
#include "highmaul.h"
#include <random>

Position const g_MaggotSpawnPos[eHighmaulDatas::MaxMaggotToKill] =
{
Expand Down Expand Up @@ -400,7 +401,7 @@ class boss_the_butcher : public CreatureScript
if (action == eAction::MaggotKilled)
{
std::vector<uint8> l_Indexes = { 0, 1, 2, 3, 4, 5 };
std::random_shuffle(l_Indexes.begin(), l_Indexes.end());
std::shuffle(l_Indexes.begin(), l_Indexes.end(), std::mt19937{std::random_device{}()});

for (uint8 l_I : l_Indexes)
{
Expand Down
4 changes: 3 additions & 1 deletion src/server/scripts/Northrend/Nexus/Oculus/boss_urom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ EndScriptData */
#include "oculus.h"
#include "ScriptedCreature.h"
#include "SpellInfo.h"
#include "ScriptMgr.h"
#include <random>

enum Spells
{
Expand Down Expand Up @@ -102,7 +104,7 @@ class boss_urom : public CreatureScript
for (uint8 i = 0; i < 3; ++i)
group[i] = i;

std::random_shuffle(group, group + 3);
std::shuffle(group, group + 3, std::mt19937{std::random_device{}()});
}

void Initialize()
Expand Down