diff options
Diffstat (limited to 'src/server')
28 files changed, 187 insertions, 111 deletions
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 7d5dcac9d74..119c0395468 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -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); diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index f8dd51400d7..884bbbf4e4e 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -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); } diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index da6a6d6a903..53752bb220d 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -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) 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 1972a758b48..b8cddbc80cb 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -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) 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); + }); } } } |
