aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/Metric/Metric.cpp2
-rw-r--r--src/common/Utilities/TaskScheduler.cpp25
-rw-r--r--src/common/Utilities/TaskScheduler.h247
-rw-r--r--src/server/bnetserver/Main.cpp38
-rw-r--r--src/server/bnetserver/REST/LoginRESTService.cpp2
-rw-r--r--src/server/bnetserver/Server/Session.cpp20
-rw-r--r--src/server/bnetserver/Server/Session.h2
-rw-r--r--src/server/bnetserver/Server/SessionManager.cpp2
-rw-r--r--src/server/game/Entities/Player/Player.cpp5
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp15
-rw-r--r--src/server/game/Handlers/CharacterHandler.cpp20
-rw-r--r--src/server/game/Server/WorldSocket.cpp17
-rw-r--r--src/server/game/Server/WorldSocket.h2
-rw-r--r--src/server/game/World/World.cpp5
-rw-r--r--src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_garr.cpp6
-rw-r--r--src/server/scripts/EasternKingdoms/Karazhan/boss_midnight.cpp12
-rw-r--r--src/server/scripts/Northrend/VioletHold/boss_cyanigosa.cpp6
-rw-r--r--src/server/scripts/Northrend/VioletHold/boss_erekem.cpp6
-rw-r--r--src/server/scripts/Northrend/VioletHold/boss_ichoron.cpp6
-rw-r--r--src/server/scripts/Northrend/VioletHold/boss_lavanthor.cpp6
-rw-r--r--src/server/scripts/Northrend/VioletHold/boss_moragg.cpp6
-rw-r--r--src/server/scripts/Northrend/VioletHold/boss_xevozz.cpp6
-rw-r--r--src/server/scripts/Northrend/VioletHold/boss_zuramat.cpp6
-rw-r--r--src/server/scripts/Northrend/VioletHold/instance_violet_hold.cpp5
-rw-r--r--src/server/scripts/Northrend/VioletHold/violet_hold.cpp6
-rw-r--r--src/server/scripts/World/npc_guard.cpp5
-rw-r--r--src/server/shared/Networking/AsyncAcceptor.h4
-rw-r--r--src/server/shared/Networking/Socket.h32
-rw-r--r--src/server/shared/Realm/RealmList.cpp15
-rw-r--r--src/server/shared/Realm/RealmList.h33
-rw-r--r--src/server/worldserver/Main.cpp10
31 files changed, 342 insertions, 230 deletions
diff --git a/src/common/Metric/Metric.cpp b/src/common/Metric/Metric.cpp
index 0dc8e11ae80..e4bc948a8fa 100644
--- a/src/common/Metric/Metric.cpp
+++ b/src/common/Metric/Metric.cpp
@@ -226,7 +226,7 @@ void Metric::ScheduleSend()
if (_enabled)
{
_batchTimer->expires_from_now(boost::posix_time::seconds(_updateInterval));
- _batchTimer->async_wait(std::bind(&Metric::SendBatch, this));
+ _batchTimer->async_wait([this](boost::system::error_code const&){ SendBatch(); });
}
else
{
diff --git a/src/common/Utilities/TaskScheduler.cpp b/src/common/Utilities/TaskScheduler.cpp
index 8a5feffd12c..60eb9284713 100644
--- a/src/common/Utilities/TaskScheduler.cpp
+++ b/src/common/Utilities/TaskScheduler.cpp
@@ -31,7 +31,7 @@ TaskScheduler& TaskScheduler::Update(success_t const& callback/* = nullptr*/)
return *this;
}
-TaskScheduler& TaskScheduler::Update(size_t const milliseconds, success_t const& callback/* = nullptr*/)
+TaskScheduler& TaskScheduler::Update(size_t milliseconds, success_t const& callback/* = nullptr*/)
{
return Update(std::chrono::milliseconds(milliseconds), callback);
}
@@ -50,7 +50,7 @@ TaskScheduler& TaskScheduler::CancelAll()
return *this;
}
-TaskScheduler& TaskScheduler::CancelGroup(group_t const group)
+TaskScheduler& TaskScheduler::CancelGroup(group_t group)
{
_task_holder.RemoveIf([group](TaskContainer const& task) -> bool
{
@@ -61,8 +61,8 @@ TaskScheduler& TaskScheduler::CancelGroup(group_t const group)
TaskScheduler& TaskScheduler::CancelGroupsOf(std::vector<group_t> const& groups)
{
- std::for_each(groups.begin(), groups.end(),
- std::bind(&TaskScheduler::CancelGroup, this, std::placeholders::_1));
+ for (group_t group : groups)
+ CancelGroup(group);
return *this;
}
@@ -200,22 +200,31 @@ TaskScheduler::repeated_t TaskContext::GetRepeatCounter() const
TaskContext& TaskContext::Async(std::function<void()> const& callable)
{
- return Dispatch(std::bind(&TaskScheduler::Async, std::placeholders::_1, callable));
+ return Dispatch([&](TaskScheduler& scheduler) -> TaskScheduler&
+ {
+ return scheduler.Async(callable);
+ });
}
TaskContext& TaskContext::CancelAll()
{
- return Dispatch(std::mem_fn(&TaskScheduler::CancelAll));
+ return Dispatch(&TaskScheduler::CancelAll);
}
TaskContext& TaskContext::CancelGroup(TaskScheduler::group_t const group)
{
- return Dispatch(std::bind(&TaskScheduler::CancelGroup, std::placeholders::_1, group));
+ return Dispatch([=](TaskScheduler& scheduler) -> TaskScheduler&
+ {
+ return scheduler.CancelGroup(group);
+ });
}
TaskContext& TaskContext::CancelGroupsOf(std::vector<TaskScheduler::group_t> const& groups)
{
- return Dispatch(std::bind(&TaskScheduler::CancelGroupsOf, std::placeholders::_1, std::cref(groups)));
+ return Dispatch([&](TaskScheduler& scheduler) -> TaskScheduler&
+ {
+ return scheduler.CancelGroupsOf(groups);
+ });
}
void TaskContext::AssertOnConsumed() const
diff --git a/src/common/Utilities/TaskScheduler.h b/src/common/Utilities/TaskScheduler.h
index e76e6f1c45e..2ebd3e57b37 100644
--- a/src/common/Utilities/TaskScheduler.h
+++ b/src/common/Utilities/TaskScheduler.h
@@ -15,8 +15,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _TASK_SCHEDULER_H_
-#define _TASK_SCHEDULER_H_
+#ifndef TRINITYCORE_TASK_SCHEDULER_H
+#define TRINITYCORE_TASK_SCHEDULER_H
#include "Duration.h"
#include "Optional.h"
@@ -94,6 +94,8 @@ class TC_COMMON_API TaskScheduler
// Move Assign
Task& operator= (Task&& right) = delete;
+ ~Task() = default;
+
// Order tasks by its end
std::weak_ordering operator<=> (Task const& other) const
{
@@ -181,6 +183,8 @@ public:
TaskScheduler& operator= (TaskScheduler const&) = delete;
TaskScheduler& operator= (TaskScheduler&&) = delete;
+ ~TaskScheduler() = default;
+
/// Sets a validator which is asked if tasks are allowed to be executed.
template<typename P>
TaskScheduler& SetValidator(P&& predicate)
@@ -198,12 +202,12 @@ public:
/// Update the scheduler with a difftime in ms.
/// Calls the optional callback on successfully finish.
- TaskScheduler& Update(size_t const milliseconds, success_t const& callback = nullptr);
+ TaskScheduler& Update(size_t milliseconds, success_t const& callback = nullptr);
/// Update the scheduler with a difftime.
/// Calls the optional callback on successfully finish.
- template<class _Rep, class _Period>
- TaskScheduler& Update(std::chrono::duration<_Rep, _Period> difftime,
+ template<class Rep, class Period>
+ TaskScheduler& Update(std::chrono::duration<Rep, Period> difftime,
success_t const& callback = nullptr)
{
_now += difftime;
@@ -217,39 +221,39 @@ public:
/// Schedule an event with a fixed rate.
/// Never call this from within a task context! Use TaskContext::Schedule instead!
- template<class _Rep, class _Period>
- TaskScheduler& Schedule(std::chrono::duration<_Rep, _Period> time,
+ template<class Rep, class Period>
+ TaskScheduler& Schedule(std::chrono::duration<Rep, Period> time,
task_handler_t task)
{
- return ScheduleAt(_now, time, std::move(task));
+ return this->ScheduleAt(_now, time, std::move(task));
}
/// Schedule an event with a fixed rate.
/// Never call this from within a task context! Use TaskContext::Schedule instead!
- template<class _Rep, class _Period>
- TaskScheduler& Schedule(std::chrono::duration<_Rep, _Period> time,
+ template<class Rep, class Period>
+ TaskScheduler& Schedule(std::chrono::duration<Rep, Period> time,
group_t const group, task_handler_t task)
{
- return ScheduleAt(_now, time, group, std::move(task));
+ return this->ScheduleAt(_now, time, group, std::move(task));
}
/// Schedule an event with a randomized rate between min and max rate.
/// Never call this from within a task context! Use TaskContext::Schedule instead!
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
- TaskScheduler& Schedule(std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max, task_handler_t task)
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
+ TaskScheduler& Schedule(std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max, task_handler_t task)
{
- return Schedule(randtime(min, max), std::move(task));
+ return this->Schedule(::randtime(min, max), std::move(task));
}
/// Schedule an event with a fixed rate.
/// Never call this from within a task context! Use TaskContext::Schedule instead!
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
- TaskScheduler& Schedule(std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max, group_t const group,
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
+ TaskScheduler& Schedule(std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max, group_t const group,
task_handler_t task)
{
- return Schedule(randtime(min, max), group, std::move(task));
+ return this->Schedule(::randtime(min, max), group, std::move(task));
}
/// Cancels all tasks.
@@ -258,15 +262,15 @@ public:
/// Cancel all tasks of a single group.
/// Never call this from within a task context! Use TaskContext::CancelGroup instead!
- TaskScheduler& CancelGroup(group_t const group);
+ TaskScheduler& CancelGroup(group_t group);
/// Cancels all groups in the given std::vector.
/// Hint: Use std::initializer_list for this: "{1, 2, 3, 4}"
TaskScheduler& CancelGroupsOf(std::vector<group_t> const& groups);
/// Delays all tasks with the given duration.
- template<class _Rep, class _Period>
- TaskScheduler& DelayAll(std::chrono::duration<_Rep, _Period> duration)
+ template<class Rep, class Period>
+ TaskScheduler& DelayAll(std::chrono::duration<Rep, Period> duration)
{
_task_holder.ModifyIf([&duration](TaskContainer const& task) -> bool
{
@@ -277,16 +281,16 @@ public:
}
/// Delays all tasks with a random duration between min and max.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
- TaskScheduler& DelayAll(std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max)
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
+ TaskScheduler& DelayAll(std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max)
{
- return DelayAll(randtime(min, max));
+ return this->DelayAll(::randtime(min, max));
}
/// Delays all tasks of a group with the given duration.
- template<class _Rep, class _Period>
- TaskScheduler& DelayGroup(group_t const group, std::chrono::duration<_Rep, _Period> duration)
+ template<class Rep, class Period>
+ TaskScheduler& DelayGroup(group_t const group, std::chrono::duration<Rep, Period> duration)
{
_task_holder.ModifyIf([&duration, group](TaskContainer const& task) -> bool
{
@@ -302,17 +306,17 @@ public:
}
/// Delays all tasks of a group with a random duration between min and max.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
TaskScheduler& DelayGroup(group_t const group,
- std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max)
+ std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max)
{
- return DelayGroup(group, randtime(min, max));
+ return this->DelayGroup(group, ::randtime(min, max));
}
/// Reschedule all tasks with a given duration.
- template<class _Rep, class _Period>
- TaskScheduler& RescheduleAll(std::chrono::duration<_Rep, _Period> duration)
+ template<class Rep, class Period>
+ TaskScheduler& RescheduleAll(std::chrono::duration<Rep, Period> duration)
{
auto const end = _now + duration;
_task_holder.ModifyIf([end](TaskContainer const& task) -> bool
@@ -324,16 +328,16 @@ public:
}
/// Reschedule all tasks with a random duration between min and max.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
- TaskScheduler& RescheduleAll(std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max)
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
+ TaskScheduler& RescheduleAll(std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max)
{
- return RescheduleAll(randtime(min, max));
+ return this->RescheduleAll(::randtime(min, max));
}
/// Reschedule all tasks of a group with the given duration.
- template<class _Rep, class _Period>
- TaskScheduler& RescheduleGroup(group_t const group, std::chrono::duration<_Rep, _Period> duration)
+ template<class Rep, class Period>
+ TaskScheduler& RescheduleGroup(group_t const group, std::chrono::duration<Rep, Period> duration)
{
auto const end = _now + duration;
_task_holder.ModifyIf([end, group](TaskContainer const& task) -> bool
@@ -350,33 +354,33 @@ public:
}
/// Reschedule all tasks of a group with a random duration between min and max.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
TaskScheduler& RescheduleGroup(group_t const group,
- std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max)
+ std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max)
{
- return RescheduleGroup(group, randtime(min, max));
+ return this->RescheduleGroup(group, ::randtime(min, max));
}
private:
/// Insert a new task to the enqueued tasks.
TaskScheduler& InsertTask(TaskContainer task);
- template<class _Rep, class _Period>
+ template<class Rep, class Period>
TaskScheduler& ScheduleAt(timepoint_t end,
- std::chrono::duration<_Rep, _Period> time, task_handler_t task)
+ std::chrono::duration<Rep, Period> time, task_handler_t task)
{
return InsertTask(TaskContainer(new Task(end + time, time, std::move(task))));
}
/// Schedule an event with a fixed rate.
/// Never call this from within a task context! Use TaskContext::schedule instead!
- template<class _Rep, class _Period>
+ template<class Rep, class Period>
TaskScheduler& ScheduleAt(timepoint_t end,
- std::chrono::duration<_Rep, _Period> time,
+ std::chrono::duration<Rep, Period> time,
group_t const group, task_handler_t task)
{
- static repeated_t const DEFAULT_REPEATED = 0;
+ static constexpr repeated_t DEFAULT_REPEATED = 0;
return InsertTask(TaskContainer(new Task(end + time, time, group, DEFAULT_REPEATED, std::move(task))));
}
@@ -407,7 +411,7 @@ public:
// Construct from task and owner
explicit TaskContext(TaskScheduler::TaskContainer&& task, std::weak_ptr<TaskScheduler>&& owner)
- : _task(std::move(task)), _owner(owner), _consumed(std::make_shared<bool>(false)) { }
+ : _task(std::move(task)), _owner(std::move(owner)), _consumed(std::make_shared<bool>(false)) { }
// Copy construct
TaskContext(TaskContext const& right)
@@ -418,23 +422,31 @@ public:
: _task(std::move(right._task)), _owner(std::move(right._owner)), _consumed(std::move(right._consumed)) { }
// Copy assign
- TaskContext& operator= (TaskContext const& right)
+ TaskContext& operator=(TaskContext const& right)
{
- _task = right._task;
- _owner = right._owner;
- _consumed = right._consumed;
+ if (this != &right)
+ {
+ _task = right._task;
+ _owner = right._owner;
+ _consumed = right._consumed;
+ }
return *this;
}
// Move assign
- TaskContext& operator= (TaskContext&& right) noexcept
+ TaskContext& operator=(TaskContext&& right) noexcept
{
- _task = std::move(right._task);
- _owner = std::move(right._owner);
- _consumed = std::move(right._consumed);
+ if (this != &right)
+ {
+ _task = std::move(right._task);
+ _owner = std::move(right._owner);
+ _consumed = std::move(right._consumed);
+ }
return *this;
}
+ ~TaskContext() = default;
+
/// Returns true if the owner was deallocated and this context has expired.
bool IsExpired() const;
@@ -454,8 +466,8 @@ public:
/// std::chrono::seconds(5) for example.
/// This will consume the task context, its not possible to repeat the task again
/// from the same task context!
- template<class _Rep, class _Period>
- TaskContext& Repeat(std::chrono::duration<_Rep, _Period> duration)
+ template<class Rep, class Period>
+ TaskContext& Repeat(std::chrono::duration<Rep, Period> duration)
{
AssertOnConsumed();
@@ -464,7 +476,10 @@ public:
_task->_end += duration;
_task->_repeated += 1;
(*_consumed) = true;
- return Dispatch(std::bind(&TaskScheduler::InsertTask, std::placeholders::_1, _task));
+ return this->Dispatch([this](TaskScheduler& scheduler) -> TaskScheduler&
+ {
+ return scheduler.InsertTask(_task);
+ });
}
/// Repeats the event with the same duration.
@@ -479,11 +494,11 @@ public:
/// std::chrono::seconds(5) for example.
/// This will consume the task context, its not possible to repeat the task again
/// from the same task context!
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
- TaskContext& Repeat(std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max)
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
+ TaskContext& Repeat(std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max)
{
- return Repeat(randtime(min, max));
+ return this->Repeat(::randtime(min, max));
}
/// Schedule a callable function that is executed at the next update tick from within the context.
@@ -494,14 +509,14 @@ public:
/// Its possible that the new event is executed immediately!
/// Use TaskScheduler::Async to create a task
/// which will be called at the next update tick.
- template<class _Rep, class _Period>
- TaskContext& Schedule(std::chrono::duration<_Rep, _Period> time,
+ template<class Rep, class Period>
+ TaskContext& Schedule(std::chrono::duration<Rep, Period> time,
TaskScheduler::task_handler_t task)
{
auto const end = _task->_end;
- return Dispatch([end, time, task = std::move(task)](TaskScheduler& scheduler) -> TaskScheduler&
+ return this->Dispatch([end, time, task = std::move(task)](TaskScheduler& scheduler) -> TaskScheduler&
{
- return scheduler.ScheduleAt<_Rep, _Period>(end, time, std::move(task));
+ return scheduler.ScheduleAt<Rep, Period>(end, time, std::move(task));
});
}
@@ -509,14 +524,14 @@ public:
/// Its possible that the new event is executed immediately!
/// Use TaskScheduler::Async to create a task
/// which will be called at the next update tick.
- template<class _Rep, class _Period>
- TaskContext& Schedule(std::chrono::duration<_Rep, _Period> time,
+ template<class Rep, class Period>
+ TaskContext& Schedule(std::chrono::duration<Rep, Period> time,
TaskScheduler::group_t const group, TaskScheduler::task_handler_t task)
{
auto const end = _task->_end;
- return Dispatch([end, time, group, task = std::move(task)](TaskScheduler& scheduler) -> TaskScheduler&
+ return this->Dispatch([end, time, group, task = std::move(task)](TaskScheduler& scheduler) -> TaskScheduler&
{
- return scheduler.ScheduleAt<_Rep, _Period>(end, time, group, std::move(task));
+ return scheduler.ScheduleAt<Rep, Period>(end, time, group, std::move(task));
});
}
@@ -524,23 +539,23 @@ public:
/// Its possible that the new event is executed immediately!
/// Use TaskScheduler::Async to create a task
/// which will be called at the next update tick.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
- TaskContext& Schedule(std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max, TaskScheduler::task_handler_t task)
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
+ TaskContext& Schedule(std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max, TaskScheduler::task_handler_t task)
{
- return Schedule(randtime(min, max), std::move(task));
+ return this->Schedule(::randtime(min, max), std::move(task));
}
/// Schedule an event with a randomized rate between min and max rate from within the context.
/// Its possible that the new event is executed immediately!
/// Use TaskScheduler::Async to create a task
/// which will be called at the next update tick.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
- TaskContext& Schedule(std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max, TaskScheduler::group_t const group,
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
+ TaskContext& Schedule(std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max, TaskScheduler::group_t const group,
TaskScheduler::task_handler_t task)
{
- return Schedule(randtime(min, max), group, std::move(task));
+ return this->Schedule(::randtime(min, max), group, std::move(task));
}
/// Cancels all tasks from within the context.
@@ -554,65 +569,77 @@ public:
TaskContext& CancelGroupsOf(std::vector<TaskScheduler::group_t> const& groups);
/// Delays all tasks with the given duration from within the context.
- template<class _Rep, class _Period>
- TaskContext& DelayAll(std::chrono::duration<_Rep, _Period> duration)
+ template<class Rep, class Period>
+ TaskContext& DelayAll(std::chrono::duration<Rep, Period> duration)
{
- return Dispatch(std::bind(&TaskScheduler::DelayAll<_Rep, _Period>, std::placeholders::_1, duration));
+ return this->Dispatch([=](TaskScheduler& scheduler) -> TaskScheduler&
+ {
+ return scheduler.DelayAll(duration);
+ });
}
/// Delays all tasks with a random duration between min and max from within the context.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
- TaskContext& DelayAll(std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max)
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
+ TaskContext& DelayAll(std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max)
{
- return DelayAll(randtime(min, max));
+ return this->DelayAll(::randtime(min, max));
}
/// Delays all tasks of a group with the given duration from within the context.
- template<class _Rep, class _Period>
- TaskContext& DelayGroup(TaskScheduler::group_t const group, std::chrono::duration<_Rep, _Period> duration)
+ template<class Rep, class Period>
+ TaskContext& DelayGroup(TaskScheduler::group_t const group, std::chrono::duration<Rep, Period> duration)
{
- return Dispatch(std::bind(&TaskScheduler::DelayGroup<_Rep, _Period>, std::placeholders::_1, group, duration));
+ return this->Dispatch([=](TaskScheduler& scheduler) -> TaskScheduler&
+ {
+ return scheduler.DelayGroup(group, duration);
+ });
}
/// Delays all tasks of a group with a random duration between min and max from within the context.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
TaskContext& DelayGroup(TaskScheduler::group_t const group,
- std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max)
+ std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max)
{
- return DelayGroup(group, randtime(min, max));
+ return this->DelayGroup(group, ::randtime(min, max));
}
/// Reschedule all tasks with the given duration.
- template<class _Rep, class _Period>
- TaskContext& RescheduleAll(std::chrono::duration<_Rep, _Period> duration)
+ template<class Rep, class Period>
+ TaskContext& RescheduleAll(std::chrono::duration<Rep, Period> duration)
{
- return Dispatch(std::bind(&TaskScheduler::RescheduleAll, std::placeholders::_1, duration));
+ return this->Dispatch([=](TaskScheduler& scheduler) -> TaskScheduler&
+ {
+ return scheduler.RescheduleAll(duration);
+ });
}
/// Reschedule all tasks with a random duration between min and max.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
- TaskContext& RescheduleAll(std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max)
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
+ TaskContext& RescheduleAll(std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max)
{
- return RescheduleAll(randtime(min, max));
+ return this->RescheduleAll(::randtime(min, max));
}
/// Reschedule all tasks of a group with the given duration.
- template<class _Rep, class _Period>
- TaskContext& RescheduleGroup(TaskScheduler::group_t const group, std::chrono::duration<_Rep, _Period> duration)
+ template<class Rep, class Period>
+ TaskContext& RescheduleGroup(TaskScheduler::group_t const group, std::chrono::duration<Rep, Period> duration)
{
- return Dispatch(std::bind(&TaskScheduler::RescheduleGroup<_Rep, _Period>, std::placeholders::_1, group, duration));
+ return this->Dispatch([=](TaskScheduler& scheduler) -> TaskScheduler&
+ {
+ return scheduler.RescheduleGroup(group, duration);
+ });
}
/// Reschedule all tasks of a group with a random duration between min and max.
- template<class _RepLeft, class _PeriodLeft, class _RepRight, class _PeriodRight>
+ template<class RepLeft, class PeriodLeft, class RepRight, class PeriodRight>
TaskContext& RescheduleGroup(TaskScheduler::group_t const group,
- std::chrono::duration<_RepLeft, _PeriodLeft> min,
- std::chrono::duration<_RepRight, _PeriodRight> max)
+ std::chrono::duration<RepLeft, PeriodLeft> min,
+ std::chrono::duration<RepRight, PeriodRight> max)
{
- return RescheduleGroup(group, randtime(min, max));
+ return this->RescheduleGroup(group, ::randtime(min, max));
}
private:
@@ -623,4 +650,4 @@ private:
void Invoke();
};
-#endif /// _TASK_SCHEDULER_H_
+#endif /// TRINITYCORE_TASK_SCHEDULER_H
diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp
index afa8ed940c3..e1168a1a90b 100644
--- a/src/server/bnetserver/Main.cpp
+++ b/src/server/bnetserver/Main.cpp
@@ -236,7 +236,10 @@ int main(int argc, char** argv)
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
signals.add(SIGBREAK);
#endif
- signals.async_wait(std::bind(&SignalHandler, std::weak_ptr<Trinity::Asio::IoContext>(ioContext), std::placeholders::_1, std::placeholders::_2));
+ signals.async_wait([ioContextRef = std::weak_ptr(ioContext)](boost::system::error_code const& error, int signalNumber) mutable
+ {
+ SignalHandler(std::move(ioContextRef), error, signalNumber);
+ });
// Set process priority according to configuration settings
SetProcessPriority("server.bnetserver", sConfigMgr->GetIntDefault(CONFIG_PROCESSOR_AFFINITY, 0), sConfigMgr->GetBoolDefault(CONFIG_HIGH_PRIORITY, false));
@@ -245,12 +248,18 @@ int main(int argc, char** argv)
int32 dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
std::shared_ptr<Trinity::Asio::DeadlineTimer> dbPingTimer = std::make_shared<Trinity::Asio::DeadlineTimer>(*ioContext);
dbPingTimer->expires_from_now(boost::posix_time::minutes(dbPingInterval));
- dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr<Trinity::Asio::DeadlineTimer>(dbPingTimer), dbPingInterval, std::placeholders::_1));
+ dbPingTimer->async_wait([timerRef = std::weak_ptr(dbPingTimer), dbPingInterval](boost::system::error_code const& error) mutable
+ {
+ KeepDatabaseAliveHandler(std::move(timerRef), dbPingInterval, error);
+ });
int32 banExpiryCheckInterval = sConfigMgr->GetIntDefault("BanExpiryCheckInterval", 60);
std::shared_ptr<Trinity::Asio::DeadlineTimer> banExpiryCheckTimer = std::make_shared<Trinity::Asio::DeadlineTimer>(*ioContext);
banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(banExpiryCheckInterval));
- banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr<Trinity::Asio::DeadlineTimer>(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1));
+ banExpiryCheckTimer->async_wait([timerRef = std::weak_ptr(banExpiryCheckTimer), banExpiryCheckInterval](boost::system::error_code const& error) mutable
+ {
+ BanExpiryHandler(std::move(timerRef), banExpiryCheckInterval, error);
+ });
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
std::shared_ptr<Trinity::Asio::DeadlineTimer> serviceStatusWatchTimer;
@@ -258,10 +267,10 @@ int main(int argc, char** argv)
{
serviceStatusWatchTimer = std::make_shared<Trinity::Asio::DeadlineTimer>(*ioContext);
serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1));
- serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher,
- std::weak_ptr<Trinity::Asio::DeadlineTimer>(serviceStatusWatchTimer),
- std::weak_ptr<Trinity::Asio::IoContext>(ioContext),
- std::placeholders::_1));
+ serviceStatusWatchTimer->async_wait([timerRef = std::weak_ptr(serviceStatusWatchTimer), ioContextRef = std::weak_ptr(ioContext)](boost::system::error_code const& error) mutable
+ {
+ ServiceStatusWatcher(std::move(timerRef), std::move(ioContextRef), error);
+ });
}
#endif
@@ -320,7 +329,10 @@ void KeepDatabaseAliveHandler(std::weak_ptr<Trinity::Asio::DeadlineTimer> dbPing
LoginDatabase.KeepAlive();
dbPingTimer->expires_from_now(boost::posix_time::minutes(dbPingInterval));
- dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, dbPingTimerRef, dbPingInterval, std::placeholders::_1));
+ dbPingTimer->async_wait([timerRef = std::move(dbPingTimerRef), dbPingInterval](boost::system::error_code const& error) mutable
+ {
+ KeepDatabaseAliveHandler(std::move(timerRef), dbPingInterval, error);
+ });
}
}
}
@@ -336,7 +348,10 @@ void BanExpiryHandler(std::weak_ptr<Trinity::Asio::DeadlineTimer> banExpiryCheck
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_BNET_EXPIRED_ACCOUNT_BANNED));
banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(banExpiryCheckInterval));
- banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, banExpiryCheckTimerRef, banExpiryCheckInterval, std::placeholders::_1));
+ banExpiryCheckTimer->async_wait([timerRef = std::move(banExpiryCheckTimerRef), banExpiryCheckInterval](boost::system::error_code const& error) mutable
+ {
+ BanExpiryHandler(std::move(timerRef), banExpiryCheckInterval, error);
+ });
}
}
}
@@ -355,7 +370,10 @@ void ServiceStatusWatcher(std::weak_ptr<Trinity::Asio::DeadlineTimer> serviceSta
else if (std::shared_ptr<Trinity::Asio::DeadlineTimer> serviceStatusWatchTimer = serviceStatusWatchTimerRef.lock())
{
serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1));
- serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher, serviceStatusWatchTimerRef, ioContext, std::placeholders::_1));
+ serviceStatusWatchTimer->async_wait([timerRef = std::move(serviceStatusWatchTimerRef), ioContextRef = std::move(ioContextRef)](boost::system::error_code const& error) mutable
+ {
+ ServiceStatusWatcher(std::move(timerRef), std::move(ioContextRef), error);
+ });
}
}
}
diff --git a/src/server/bnetserver/REST/LoginRESTService.cpp b/src/server/bnetserver/REST/LoginRESTService.cpp
index 0aa8ac8fb0d..6141dc702f9 100644
--- a/src/server/bnetserver/REST/LoginRESTService.cpp
+++ b/src/server/bnetserver/REST/LoginRESTService.cpp
@@ -124,7 +124,7 @@ bool LoginRESTService::Start(Trinity::Asio::IoContext* ioContext)
_loginTicketDuration = sConfigMgr->GetIntDefault("LoginREST.TicketDuration", 3600);
- _thread = std::thread(std::bind(&LoginRESTService::Run, this));
+ _thread = std::thread(&LoginRESTService::Run, this);
return true;
}
diff --git a/src/server/bnetserver/Server/Session.cpp b/src/server/bnetserver/Server/Session.cpp
index 95c46418a7d..ea5256ed635 100644
--- a/src/server/bnetserver/Server/Session.cpp
+++ b/src/server/bnetserver/Server/Session.cpp
@@ -47,7 +47,7 @@ void Battlenet::Session::AccountInfo::LoadResult(PreparedQueryResult result)
IsBanned = fields[6].GetUInt64() != 0;
IsPermanenetlyBanned = fields[7].GetUInt64() != 0;
- static uint32 const GameAccountFieldsOffset = 8;
+ static constexpr uint32 GameAccountFieldsOffset = 8;
do
{
@@ -56,7 +56,7 @@ void Battlenet::Session::AccountInfo::LoadResult(PreparedQueryResult result)
} while (result->NextRow());
}
-void Battlenet::Session::GameAccountInfo::LoadResult(Field* fields)
+void Battlenet::Session::GameAccountInfo::LoadResult(Field const* fields)
{
// a.id, a.username, ab.unbandate, ab.unbandate = ab.bandate, aa.SecurityLevel
Id = fields[0].GetUInt32();
@@ -74,18 +74,17 @@ void Battlenet::Session::GameAccountInfo::LoadResult(Field* fields)
}
Battlenet::Session::Session(boost::asio::ip::tcp::socket&& socket) : BattlenetSocket(std::move(socket)), _accountInfo(new AccountInfo()), _gameAccountInfo(nullptr), _locale(),
- _os(), _build(0), _ipCountry(), _authed(false), _requestToken(0)
+ _os(), _build(0), _timezoneOffset(0min), _ipCountry(), _clientSecret(), _authed(false), _requestToken(0)
{
_headerLengthBuffer.Resize(2);
}
-Battlenet::Session::~Session()
-{
-}
+Battlenet::Session::~Session() = default;
void Battlenet::Session::AsyncHandshake()
{
- underlying_stream().async_handshake(boost::asio::ssl::stream_base::server, std::bind(&Session::HandshakeHandler, shared_from_this(), std::placeholders::_1));
+ underlying_stream().async_handshake(boost::asio::ssl::stream_base::server,
+ [sess = shared_from_this()](boost::system::error_code const& error) { sess->HandshakeHandler(error); });
}
void Battlenet::Session::Start()
@@ -99,7 +98,8 @@ void Battlenet::Session::Start()
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_INFO);
stmt->setString(0, ip_address);
- _queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&Battlenet::Session::CheckIpCallback, this, std::placeholders::_1)));
+ _queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt)
+ .WithPreparedCallback([sess = shared_from_this()](PreparedQueryResult result) { sess->CheckIpCallback(std::move(result)); }));
}
void Battlenet::Session::CheckIpCallback(PreparedQueryResult result)
@@ -429,10 +429,10 @@ uint32 Battlenet::Session::VerifyWebCredentials(std::string const& webCredential
logonResult.set_error_code(0);
logonResult.mutable_account_id()->set_low(_accountInfo->Id);
logonResult.mutable_account_id()->set_high(UI64LIT(0x100000000000000));
- for (auto itr = _accountInfo->GameAccounts.begin(); itr != _accountInfo->GameAccounts.end(); ++itr)
+ for (auto const& [id, gameAccountInfo] : accountInfo->GameAccounts)
{
EntityId* gameAccountId = logonResult.add_game_account_id();
- gameAccountId->set_low(itr->second.Id);
+ gameAccountId->set_low(gameAccountInfo.Id);
gameAccountId->set_high(UI64LIT(0x200000200576F57));
}
diff --git a/src/server/bnetserver/Server/Session.h b/src/server/bnetserver/Server/Session.h
index 01167d38a0b..6d22c202615 100644
--- a/src/server/bnetserver/Server/Session.h
+++ b/src/server/bnetserver/Server/Session.h
@@ -80,7 +80,7 @@ namespace Battlenet
struct GameAccountInfo
{
- void LoadResult(Field* fields);
+ void LoadResult(Field const* fields);
uint32 Id;
std::string Name;
diff --git a/src/server/bnetserver/Server/SessionManager.cpp b/src/server/bnetserver/Server/SessionManager.cpp
index dd5f73a788f..6e07fcecff1 100644
--- a/src/server/bnetserver/Server/SessionManager.cpp
+++ b/src/server/bnetserver/Server/SessionManager.cpp
@@ -17,7 +17,6 @@
#include "SessionManager.h"
#include "DatabaseEnv.h"
-#include "SRP6.h"
#include "Util.h"
bool Battlenet::SessionManager::StartNetwork(Trinity::Asio::IoContext& ioContext, std::string const& bindIp, uint16 port, int threadCount)
@@ -25,7 +24,6 @@ bool Battlenet::SessionManager::StartNetwork(Trinity::Asio::IoContext& ioContext
if (!BaseSocketMgr::StartNetwork(ioContext, bindIp, port, threadCount))
return false;
- _acceptor->SetSocketFactory(std::bind(&BaseSocketMgr::GetSocketForAccept, this));
_acceptor->AsyncAcceptWithCallback<&OnSocketAccept>();
return true;
}
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index b3258b28756..e3c4a072202 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -8294,7 +8294,10 @@ void Player::UpdateWeaponDependentCritAuras(WeaponAttackType attackType)
}
float amount = 0.0f;
- amount += GetTotalAuraModifier(SPELL_AURA_MOD_WEAPON_CRIT_PERCENT, std::bind(&Unit::CheckAttackFitToAuraRequirement, this, attackType, std::placeholders::_1));
+ amount += GetTotalAuraModifier(SPELL_AURA_MOD_WEAPON_CRIT_PERCENT, [this, attackType](AuraEffect const* aurEff)
+ {
+ return CheckAttackFitToAuraRequirement(attackType, aurEff);
+ });
// these auras don't have item requirement (only Combat Expertise in 3.3.5a)
amount += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PCT);
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 5b6c1001385..b3cadc6f091 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -9013,15 +9013,18 @@ void Unit::UpdateDamagePctDoneMods(WeaponAttackType attackType)
}
factor *= GetTotalAuraMultiplier(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE, [attackType, this](AuraEffect const* aurEff) -> bool
- {
- if (!(aurEff->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL))
- return false;
+ {
+ if (!(aurEff->GetMiscValue() & SPELL_SCHOOL_MASK_NORMAL))
+ return false;
- return CheckAttackFitToAuraRequirement(attackType, aurEff);
- });
+ return CheckAttackFitToAuraRequirement(attackType, aurEff);
+ });
if (attackType == OFF_ATTACK)
- factor *= GetTotalAuraMultiplier(SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT, std::bind(&Unit::CheckAttackFitToAuraRequirement, this, attackType, std::placeholders::_1));
+ factor *= GetTotalAuraModifier(SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT, [this, attackType](AuraEffect const* aurEff)
+ {
+ return CheckAttackFitToAuraRequirement(attackType, aurEff);
+ });
SetStatPctModifier(unitMod, TOTAL_PCT, factor);
}
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp
index d499ba13c11..65da654793a 100644
--- a/src/server/game/Handlers/CharacterHandler.cpp
+++ b/src/server/game/Handlers/CharacterHandler.cpp
@@ -1619,7 +1619,10 @@ void WorldSession::HandleCharRenameOpcode(WorldPackets::Character::CharacterRena
stmt->setString(1, request.RenameInfo->NewName);
_queryProcessor.AddCallback(CharacterDatabase.AsyncQuery(stmt)
- .WithPreparedCallback(std::bind(&WorldSession::HandleCharRenameCallBack, this, request.RenameInfo, std::placeholders::_1)));
+ .WithPreparedCallback([this, renameInfo = std::move(request.RenameInfo)](PreparedQueryResult result) mutable
+ {
+ HandleCharRenameCallBack(std::move(renameInfo), std::move(result));
+ }));
}
void WorldSession::HandleCharRenameCallBack(std::shared_ptr<WorldPackets::Character::CharacterRenameInfo> renameInfo, PreparedQueryResult result)
@@ -1810,7 +1813,10 @@ void WorldSession::HandleCharCustomizeOpcode(WorldPackets::Character::CharCustom
stmt->setUInt64(0, packet.CustomizeInfo->CharGUID.GetCounter());
_queryProcessor.AddCallback(CharacterDatabase.AsyncQuery(stmt)
- .WithPreparedCallback(std::bind(&WorldSession::HandleCharCustomizeCallback, this, packet.CustomizeInfo, std::placeholders::_1)));
+ .WithPreparedCallback([this, customizeInfo = std::move(packet.CustomizeInfo)](PreparedQueryResult result) mutable
+ {
+ HandleCharCustomizeCallback(std::move(customizeInfo), std::move(result));
+ }));
}
void WorldSession::HandleCharCustomizeCallback(std::shared_ptr<WorldPackets::Character::CharCustomizeInfo> customizeInfo, PreparedQueryResult result)
@@ -2084,7 +2090,10 @@ void WorldSession::HandleCharRaceOrFactionChangeOpcode(WorldPackets::Character::
stmt->setUInt64(0, packet.RaceOrFactionChangeInfo->Guid.GetCounter());
_queryProcessor.AddCallback(CharacterDatabase.AsyncQuery(stmt)
- .WithPreparedCallback(std::bind(&WorldSession::HandleCharRaceOrFactionChangeCallback, this, packet.RaceOrFactionChangeInfo, std::placeholders::_1)));
+ .WithPreparedCallback([this, factionChangeInfo = std::move(packet.RaceOrFactionChangeInfo)](PreparedQueryResult result) mutable
+ {
+ HandleCharRaceOrFactionChangeCallback(std::move(factionChangeInfo), std::move(result));
+ }));
}
void WorldSession::HandleCharRaceOrFactionChangeCallback(std::shared_ptr<WorldPackets::Character::CharRaceOrFactionChangeInfo> factionChangeInfo, PreparedQueryResult result)
@@ -2674,7 +2683,10 @@ void WorldSession::HandleGetUndeleteCooldownStatus(WorldPackets::Character::GetU
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_LAST_CHAR_UNDELETE);
stmt->setUInt32(0, GetBattlenetAccountId());
- _queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&WorldSession::HandleUndeleteCooldownStatusCallback, this, std::placeholders::_1)));
+ _queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback([this](PreparedQueryResult result)
+ {
+ HandleUndeleteCooldownStatusCallback(std::move(result));
+ }));
}
void WorldSession::HandleUndeleteCooldownStatusCallback(PreparedQueryResult result)
diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp
index 0161974879a..d4317cf5e14 100644
--- a/src/server/game/Server/WorldSocket.cpp
+++ b/src/server/game/Server/WorldSocket.cpp
@@ -81,7 +81,10 @@ void WorldSocket::Start()
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_INFO);
stmt->setString(0, ip_address);
- _queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&WorldSocket::CheckIpCallback, this, std::placeholders::_1)));
+ _queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback([self = shared_from_this()](PreparedQueryResult result)
+ {
+ self->CheckIpCallback(std::move(result));
+ }));
}
void WorldSocket::CheckIpCallback(PreparedQueryResult result)
@@ -117,7 +120,7 @@ void WorldSocket::CheckIpCallback(PreparedQueryResult result)
QueuePacket(std::move(initializer));
}
-void WorldSocket::InitializeHandler(boost::system::error_code error, std::size_t transferedBytes)
+void WorldSocket::InitializeHandler(boost::system::error_code const& error, std::size_t transferedBytes)
{
if (error)
{
@@ -879,7 +882,10 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth::
if (wardenActive)
_worldSession->InitWarden(_sessionKey);
- _queryProcessor.AddCallback(_worldSession->LoadPermissionsAsync().WithPreparedCallback(std::bind(&WorldSocket::LoadSessionPermissionsCallback, this, std::placeholders::_1)));
+ _queryProcessor.AddCallback(_worldSession->LoadPermissionsAsync().WithPreparedCallback([this](PreparedQueryResult result)
+ {
+ LoadSessionPermissionsCallback(std::move(result));
+ }));
AsyncRead();
}
@@ -908,7 +914,10 @@ void WorldSocket::HandleAuthContinuedSession(std::shared_ptr<WorldPackets::Auth:
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_CONTINUED_SESSION);
stmt->setUInt32(0, accountId);
- _queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&WorldSocket::HandleAuthContinuedSessionCallback, this, authSession, std::placeholders::_1)));
+ _queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback([this, authSession = std::move(authSession)](PreparedQueryResult result) mutable
+ {
+ HandleAuthContinuedSessionCallback(std::move(authSession), std::move(result));
+ }));
}
void WorldSocket::HandleAuthContinuedSessionCallback(std::shared_ptr<WorldPackets::Auth::AuthContinuedSession> authSession, PreparedQueryResult result)
diff --git a/src/server/game/Server/WorldSocket.h b/src/server/game/Server/WorldSocket.h
index dbd0019562a..2cf288bbd7b 100644
--- a/src/server/game/Server/WorldSocket.h
+++ b/src/server/game/Server/WorldSocket.h
@@ -128,7 +128,7 @@ protected:
ReadDataHandlerResult ReadDataHandler();
private:
void CheckIpCallback(PreparedQueryResult result);
- void InitializeHandler(boost::system::error_code error, std::size_t transferedBytes);
+ void InitializeHandler(boost::system::error_code const& error, std::size_t transferedBytes);
/// writes network.opcode log
/// accessing WorldSession is not threadsafe, only do it when holding _worldSessionLock
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index ddb921ef3d1..def1608d7cb 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -3471,7 +3471,10 @@ void World::UpdateRealmCharCount(uint32 accountId)
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_COUNT);
stmt->setUInt32(0, accountId);
- _queryProcessor.AddCallback(CharacterDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&World::_UpdateRealmCharCount, this, std::placeholders::_1)));
+ _queryProcessor.AddCallback(CharacterDatabase.AsyncQuery(stmt).WithPreparedCallback([this](PreparedQueryResult result)
+ {
+ _UpdateRealmCharCount(std::move(result));
+ }));
}
void World::_UpdateRealmCharCount(PreparedQueryResult resultCharCount)
diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_garr.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_garr.cpp
index 4738485ad65..8df147209ec 100644
--- a/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_garr.cpp
+++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/MoltenCore/boss_garr.cpp
@@ -145,8 +145,10 @@ struct npc_firesworn : public ScriptedAI
if (!UpdateVictim())
return;
- _scheduler.Update(diff,
- std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
+ _scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
private:
diff --git a/src/server/scripts/EasternKingdoms/Karazhan/boss_midnight.cpp b/src/server/scripts/EasternKingdoms/Karazhan/boss_midnight.cpp
index bda652002c2..89616f3566a 100644
--- a/src/server/scripts/EasternKingdoms/Karazhan/boss_midnight.cpp
+++ b/src/server/scripts/EasternKingdoms/Karazhan/boss_midnight.cpp
@@ -219,8 +219,10 @@ public:
if (!UpdateVictim() && _phase != PHASE_NONE)
return;
- scheduler.Update(diff,
- std::bind(&BossAI::DoMeleeAttackIfReady, this));
+ scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
void SpellHit(WorldObject* /*caster*/, SpellInfo const* spellInfo) override
@@ -368,8 +370,10 @@ public:
if (!UpdateVictim() || _phase == PHASE_MOUNTED)
return;
- scheduler.Update(diff,
- std::bind(&BossAI::DoMeleeAttackIfReady, this));
+ scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
private:
diff --git a/src/server/scripts/Northrend/VioletHold/boss_cyanigosa.cpp b/src/server/scripts/Northrend/VioletHold/boss_cyanigosa.cpp
index 3fa94370f6a..1ae2ca29064 100644
--- a/src/server/scripts/Northrend/VioletHold/boss_cyanigosa.cpp
+++ b/src/server/scripts/Northrend/VioletHold/boss_cyanigosa.cpp
@@ -72,8 +72,10 @@ struct boss_cyanigosa : public BossAI
if (!UpdateVictim())
return;
- scheduler.Update(diff,
- std::bind(&BossAI::DoMeleeAttackIfReady, this));
+ scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
void ScheduleTasks() override
diff --git a/src/server/scripts/Northrend/VioletHold/boss_erekem.cpp b/src/server/scripts/Northrend/VioletHold/boss_erekem.cpp
index 3d0d871ac27..59a18ef1f67 100644
--- a/src/server/scripts/Northrend/VioletHold/boss_erekem.cpp
+++ b/src/server/scripts/Northrend/VioletHold/boss_erekem.cpp
@@ -265,8 +265,10 @@ struct npc_erekem_guard : public ScriptedAI
if (!UpdateVictim())
return;
- scheduler.Update(diff,
- std::bind(&ScriptedAI::DoMeleeAttackIfReady, this));
+ scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
void ScheduledTasks()
diff --git a/src/server/scripts/Northrend/VioletHold/boss_ichoron.cpp b/src/server/scripts/Northrend/VioletHold/boss_ichoron.cpp
index c162e65c498..faa9c08fbc3 100644
--- a/src/server/scripts/Northrend/VioletHold/boss_ichoron.cpp
+++ b/src/server/scripts/Northrend/VioletHold/boss_ichoron.cpp
@@ -193,8 +193,10 @@ struct boss_ichoron : public BossAI
_isFrenzy = true;
}
- scheduler.Update(diff,
- std::bind(&BossAI::DoMeleeAttackIfReady, this));
+ scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
void ScheduleTasks() override
diff --git a/src/server/scripts/Northrend/VioletHold/boss_lavanthor.cpp b/src/server/scripts/Northrend/VioletHold/boss_lavanthor.cpp
index 4a7705bb984..aa3c2a49329 100644
--- a/src/server/scripts/Northrend/VioletHold/boss_lavanthor.cpp
+++ b/src/server/scripts/Northrend/VioletHold/boss_lavanthor.cpp
@@ -53,8 +53,10 @@ struct boss_lavanthor : public BossAI
if (!UpdateVictim())
return;
- scheduler.Update(diff,
- std::bind(&BossAI::DoMeleeAttackIfReady, this));
+ scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
void ScheduleTasks() override
diff --git a/src/server/scripts/Northrend/VioletHold/boss_moragg.cpp b/src/server/scripts/Northrend/VioletHold/boss_moragg.cpp
index b8afac4505a..974360cda3a 100644
--- a/src/server/scripts/Northrend/VioletHold/boss_moragg.cpp
+++ b/src/server/scripts/Northrend/VioletHold/boss_moragg.cpp
@@ -61,8 +61,10 @@ struct boss_moragg : public BossAI
if (!UpdateVictim())
return;
- scheduler.Update(diff,
- std::bind(&BossAI::DoMeleeAttackIfReady, this));
+ scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
void ScheduleTasks() override
diff --git a/src/server/scripts/Northrend/VioletHold/boss_xevozz.cpp b/src/server/scripts/Northrend/VioletHold/boss_xevozz.cpp
index 65499d61b49..727f5a33072 100644
--- a/src/server/scripts/Northrend/VioletHold/boss_xevozz.cpp
+++ b/src/server/scripts/Northrend/VioletHold/boss_xevozz.cpp
@@ -128,8 +128,10 @@ struct boss_xevozz : public BossAI
if (!UpdateVictim())
return;
- scheduler.Update(diff,
- std::bind(&BossAI::DoMeleeAttackIfReady, this));
+ scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
void ScheduleTasks() override
diff --git a/src/server/scripts/Northrend/VioletHold/boss_zuramat.cpp b/src/server/scripts/Northrend/VioletHold/boss_zuramat.cpp
index 98425811c25..cd5f79f0861 100644
--- a/src/server/scripts/Northrend/VioletHold/boss_zuramat.cpp
+++ b/src/server/scripts/Northrend/VioletHold/boss_zuramat.cpp
@@ -116,8 +116,10 @@ struct boss_zuramat : public BossAI
if (!UpdateVictim())
return;
- scheduler.Update(diff,
- std::bind(&BossAI::DoMeleeAttackIfReady, this));
+ scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
void ScheduleTasks() override
diff --git a/src/server/scripts/Northrend/VioletHold/instance_violet_hold.cpp b/src/server/scripts/Northrend/VioletHold/instance_violet_hold.cpp
index 933114916cf..bc68f6b08d3 100644
--- a/src/server/scripts/Northrend/VioletHold/instance_violet_hold.cpp
+++ b/src/server/scripts/Northrend/VioletHold/instance_violet_hold.cpp
@@ -398,7 +398,10 @@ class instance_violet_hold : public InstanceMapScript
DoUpdateWorldState(WORLD_STATE_VH_SHOW, 1);
WaveCount = 1;
- Scheduler.Async(std::bind(&instance_violet_hold_InstanceMapScript::AddWave, this));
+ Scheduler.Async([this]
+ {
+ AddWave();
+ });
for (uint8 i = 0; i < ActivationCrystalCount; ++i)
if (GameObject* crystal = instance->GetGameObject(ActivationCrystalGUIDs[i]))
diff --git a/src/server/scripts/Northrend/VioletHold/violet_hold.cpp b/src/server/scripts/Northrend/VioletHold/violet_hold.cpp
index 626042068f5..16553c78709 100644
--- a/src/server/scripts/Northrend/VioletHold/violet_hold.cpp
+++ b/src/server/scripts/Northrend/VioletHold/violet_hold.cpp
@@ -920,8 +920,10 @@ struct violet_hold_trashAI : public EscortAI
if (!UpdateVictim())
return;
- _scheduler.Update(diff,
- std::bind(&EscortAI::DoMeleeAttackIfReady, this));
+ _scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
virtual void ScheduledTasks() { }
diff --git a/src/server/scripts/World/npc_guard.cpp b/src/server/scripts/World/npc_guard.cpp
index 565f80a676f..879fef3e95e 100644
--- a/src/server/scripts/World/npc_guard.cpp
+++ b/src/server/scripts/World/npc_guard.cpp
@@ -205,7 +205,10 @@ struct npc_guard_shattrath_faction : public GuardAI
if (!UpdateVictim())
return;
- _scheduler.Update(diff, std::bind(&GuardAI::DoMeleeAttackIfReady, this));
+ _scheduler.Update(diff, [this]
+ {
+ DoMeleeAttackIfReady();
+ });
}
void ScheduleVanish()
diff --git a/src/server/shared/Networking/AsyncAcceptor.h b/src/server/shared/Networking/AsyncAcceptor.h
index 24a5c7d4b0e..7f1cb34204c 100644
--- a/src/server/shared/Networking/AsyncAcceptor.h
+++ b/src/server/shared/Networking/AsyncAcceptor.h
@@ -34,7 +34,7 @@ public:
AsyncAcceptor(Trinity::Asio::IoContext& ioContext, std::string const& bindIp, uint16 port) :
_acceptor(ioContext), _endpoint(Trinity::Net::make_address(bindIp), port),
- _socket(ioContext), _closed(false), _socketFactory(std::bind(&AsyncAcceptor::DefeaultSocketFactory, this))
+ _socket(ioContext), _closed(false), _socketFactory([this] { return DefeaultSocketFactory(); })
{
}
@@ -114,7 +114,7 @@ public:
_acceptor.close(err);
}
- void SetSocketFactory(std::function<std::pair<boost::asio::ip::tcp::socket*, uint32>()> func) { _socketFactory = func; }
+ void SetSocketFactory(std::function<std::pair<boost::asio::ip::tcp::socket*, uint32>()> func) { _socketFactory = std::move(func); }
private:
std::pair<boost::asio::ip::tcp::socket*, uint32> DefeaultSocketFactory() { return std::make_pair(&_socket, 0); }
diff --git a/src/server/shared/Networking/Socket.h b/src/server/shared/Networking/Socket.h
index 2856fcfeb35..a996ecb2cbe 100644
--- a/src/server/shared/Networking/Socket.h
+++ b/src/server/shared/Networking/Socket.h
@@ -112,10 +112,13 @@ public:
_readBuffer.Normalize();
_readBuffer.EnsureFreeSpace();
_socket.async_read_some(boost::asio::buffer(_readBuffer.GetWritePointer(), _readBuffer.GetRemainingSpace()),
- std::bind(&Socket<T, Stream>::ReadHandlerInternal, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
+ [self = this->shared_from_this()](boost::system::error_code const& error, size_t transferredBytes)
+ {
+ self->ReadHandlerInternal(error, transferredBytes);
+ });
}
- void AsyncReadWithCallback(void (T::*callback)(boost::system::error_code, std::size_t))
+ void AsyncReadWithCallback(void (T::*callback)(boost::system::error_code const&, std::size_t))
{
if (!IsOpen())
return;
@@ -123,7 +126,10 @@ public:
_readBuffer.Normalize();
_readBuffer.EnsureFreeSpace();
_socket.async_read_some(boost::asio::buffer(_readBuffer.GetWritePointer(), _readBuffer.GetRemainingSpace()),
- std::bind(callback, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
+ [self = this->shared_from_this(), callback](boost::system::error_code const& error, size_t transferredBytes)
+ {
+ (self.get()->*callback)(error, transferredBytes);
+ });
}
void QueuePacket(MessageBuffer&& buffer)
@@ -170,11 +176,17 @@ protected:
#ifdef TC_SOCKET_USE_IOCP
MessageBuffer& buffer = _writeQueue.front();
- _socket.async_write_some(boost::asio::buffer(buffer.GetReadPointer(), buffer.GetActiveSize()), std::bind(&Socket<T, Stream>::WriteHandler,
- this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
+ _socket.async_write_some(boost::asio::buffer(buffer.GetReadPointer(), buffer.GetActiveSize()),
+ [self = this->shared_from_this()](boost::system::error_code const& error, std::size_t transferedBytes)
+ {
+ self->WriteHandler(error, transferedBytes);
+ });
#else
- _socket.async_write_some(boost::asio::null_buffers(), std::bind(&Socket<T, Stream>::WriteHandlerWrapper,
- this->shared_from_this(), std::placeholders::_1, std::placeholders::_2));
+ _socket.async_write_some(boost::asio::null_buffers(),
+ [self = this->shared_from_this()](boost::system::error_code const& error, std::size_t transferedBytes)
+ {
+ self->WriteHandlerWrapper(error, transferedBytes);
+ });
#endif
return false;
@@ -195,7 +207,7 @@ protected:
}
private:
- void ReadHandlerInternal(boost::system::error_code error, size_t transferredBytes)
+ void ReadHandlerInternal(boost::system::error_code const& error, size_t transferredBytes)
{
if (error)
{
@@ -209,7 +221,7 @@ private:
#ifdef TC_SOCKET_USE_IOCP
- void WriteHandler(boost::system::error_code error, std::size_t transferedBytes)
+ void WriteHandler(boost::system::error_code const& error, std::size_t transferedBytes)
{
if (!error)
{
@@ -229,7 +241,7 @@ private:
#else
- void WriteHandlerWrapper(boost::system::error_code /*error*/, std::size_t /*transferedBytes*/)
+ void WriteHandlerWrapper(boost::system::error_code const& /*error*/, std::size_t /*transferedBytes*/)
{
_isWritingAsync = false;
HandleQueue();
diff --git a/src/server/shared/Realm/RealmList.cpp b/src/server/shared/Realm/RealmList.cpp
index 779bb6fca09..d4a9938476b 100644
--- a/src/server/shared/Realm/RealmList.cpp
+++ b/src/server/shared/Realm/RealmList.cpp
@@ -53,7 +53,7 @@ void RealmList::Initialize(Trinity::Asio::IoContext& ioContext, uint32 updateInt
LoadBuildInfo();
// Get the content of the realmlist table in the database
- UpdateRealms(boost::system::error_code());
+ UpdateRealms();
}
void RealmList::Close()
@@ -113,11 +113,8 @@ void RealmList::UpdateRealm(Realm& realm, Battlenet::RealmHandle const& id, uint
realm.Port = port;
}
-void RealmList::UpdateRealms(boost::system::error_code const& error)
+void RealmList::UpdateRealms()
{
- if (error)
- return;
-
TC_LOG_DEBUG("realmlist", "Updating Realm List...");
LoginDatabasePreparedStatement *stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_REALMLIST);
@@ -207,7 +204,13 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
if (_updateInterval)
{
_updateTimer->expires_from_now(boost::posix_time::seconds(_updateInterval));
- _updateTimer->async_wait(std::bind(&RealmList::UpdateRealms, this, std::placeholders::_1));
+ _updateTimer->async_wait([this](boost::system::error_code const& error)
+ {
+ if (error)
+ return;
+
+ UpdateRealms();
+ });
}
}
diff --git a/src/server/shared/Realm/RealmList.h b/src/server/shared/Realm/RealmList.h
index a1262d7e913..7e85cbcfd38 100644
--- a/src/server/shared/Realm/RealmList.h
+++ b/src/server/shared/Realm/RealmList.h
@@ -39,35 +39,15 @@ struct RealmBuildInfo
std::array<uint8, 16> Mac64AuthSeed;
};
-namespace boost
+namespace bgs::protocol::game_utilities::v1
{
- namespace system
- {
- class error_code;
- }
+class ClientResponse;
+class GetAllValuesForAttributeResponse;
}
-namespace bgs
+namespace JSON::RealmList
{
- namespace protocol
- {
- namespace game_utilities
- {
- namespace v1
- {
- class ClientResponse;
- class GetAllValuesForAttributeResponse;
- }
- }
- }
-}
-
-namespace JSON
-{
- namespace RealmList
- {
- class RealmListUpdates;
- }
+class RealmListUpdates;
}
/// Storage object for the list of realms on the server
@@ -99,7 +79,7 @@ private:
RealmList();
void LoadBuildInfo();
- void UpdateRealms(boost::system::error_code const& error);
+ void UpdateRealms();
void UpdateRealm(Realm& realm, Battlenet::RealmHandle const& id, uint32 build, std::string const& name,
boost::asio::ip::address&& address, boost::asio::ip::address&& localAddr,
uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population);
@@ -114,4 +94,5 @@ private:
};
#define sRealmList RealmList::Instance()
+
#endif
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp
index 4ba4a8de9c4..1695294f13b 100644
--- a/src/server/worldserver/Main.cpp
+++ b/src/server/worldserver/Main.cpp
@@ -104,7 +104,10 @@ public:
static void Start(std::shared_ptr<FreezeDetector> const& freezeDetector)
{
freezeDetector->_timer.expires_from_now(boost::posix_time::seconds(5));
- freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, std::weak_ptr<FreezeDetector>(freezeDetector), std::placeholders::_1));
+ freezeDetector->_timer.async_wait([freezeDetectorRef = std::weak_ptr(freezeDetector)](boost::system::error_code const& error) mutable
+ {
+ Handler(std::move(freezeDetectorRef), error);
+ });
}
static void Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, boost::system::error_code const& error);
@@ -596,7 +599,10 @@ void FreezeDetector::Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, bo
}
freezeDetector->_timer.expires_from_now(boost::posix_time::seconds(1));
- freezeDetector->_timer.async_wait(std::bind(&FreezeDetector::Handler, freezeDetectorRef, std::placeholders::_1));
+ freezeDetector->_timer.async_wait([freezeDetectorRef = std::move(freezeDetectorRef)](boost::system::error_code const& error) mutable
+ {
+ Handler(std::move(freezeDetectorRef), error);
+ });
}
}
}