Core/Misc: Minor code modernization - kill std::bind

(cherry picked from commit 78bcc3f52a)
This commit is contained in:
Shauren
2023-12-08 20:27:41 +01:00
committed by funjoker
parent c8e87e59e0
commit a18e3ef20a
31 changed files with 342 additions and 230 deletions
+1 -1
View File
@@ -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
{
+17 -8
View File
@@ -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
+137 -110
View File
@@ -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
+28 -10
View File
@@ -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);
});
}
}
}
@@ -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;
}
+10 -10
View File
@@ -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));
}
+1 -1
View File
@@ -80,7 +80,7 @@ namespace Battlenet
struct GameAccountInfo
{
void LoadResult(Field* fields);
void LoadResult(Field const* fields);
uint32 Id;
std::string Name;
@@ -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;
}
+4 -1
View File
@@ -8160,7 +8160,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);
+9 -6
View File
@@ -8985,15 +8985,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);
}
+16 -4
View File
@@ -1554,7 +1554,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)
@@ -1745,7 +1748,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)
@@ -2015,7 +2021,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)
@@ -2605,7 +2614,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)
+13 -4
View File
@@ -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)
+1 -1
View File
@@ -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
+4 -1
View File
@@ -3466,7 +3466,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)
@@ -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:
@@ -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:
@@ -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
@@ -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()
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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]))
@@ -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() { }
+4 -1
View File
@@ -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()
+2 -2
View File
@@ -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); }
+22 -10
View File
@@ -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();
+9 -6
View File
@@ -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();
});
}
}
+7 -26
View File
@@ -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
+8 -2
View File
@@ -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);
});
}
}
}