From 7aa080caaf972fb89f7ba236f68a3fc2bc5cf385 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Mon, 2 Sep 2024 02:03:35 -0300 Subject: [PATCH 1/3] update --- src/creatures/combat/condition.cpp | 10 +- src/creatures/creature.cpp | 38 +++-- src/creatures/players/player.cpp | 5 +- src/game/game.cpp | 157 ++++++++++++------ src/game/scheduling/dispatcher.cpp | 8 +- src/game/scheduling/dispatcher.hpp | 6 +- .../functions/core/game/game_functions.cpp | 4 +- src/map/mapcache.cpp | 13 +- src/server/network/protocol/protocol.cpp | 16 +- src/server/network/protocol/protocolgame.cpp | 26 +-- src/server/network/protocol/protocollogin.cpp | 10 +- .../network/protocol/protocolstatus.cpp | 20 ++- src/server/signals.cpp | 10 +- 13 files changed, 201 insertions(+), 122 deletions(-) diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index c06d9a792d5..714969a2de1 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -2067,10 +2067,12 @@ bool ConditionFeared::executeCondition(std::shared_ptr creature, int32 } if (getFleePath(creature, currentPos, listDir)) { - g_dispatcher().addEvent([id = creature->getID(), listDir] { - g_game().forcePlayerAutoWalk(id, listDir); - }, - "ConditionFeared::executeCondition"); + g_dispatcher().addEvent( + [id = creature->getID(), listDir] { + g_game().forcePlayerAutoWalk(id, listDir); + }, + "Game::forcePlayerAutoWalk" + ); g_logger().debug("[ConditionFeared::executeCondition] Walking Scheduled"); } diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 6c15f6cf1fe..c1695d27dc1 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -251,17 +251,23 @@ void Creature::addEventWalk(bool firstStep) { return; } - g_dispatcher().context().tryAddEvent([ticks, self = getCreature()]() { - // Take first step right away, but still queue the next - if (ticks == 1) { - g_game().checkCreatureWalk(self->getID()); - } + g_dispatcher().context().tryAddEvent( + [ticks, self = getCreature()]() { + // Take first step right away, but still queue the next + if (ticks == 1) { + g_game().checkCreatureWalk(self->getID()); + } - self->eventWalk = g_dispatcher().scheduleEvent( - static_cast(ticks), - [creatureId = self->getID()] { g_game().checkCreatureWalk(creatureId); }, "Game::checkCreatureWalk" - ); - }); + self->eventWalk = g_dispatcher().scheduleEvent( + static_cast(ticks), + [creatureId = self->getID()] { + g_game().checkCreatureWalk(creatureId); + }, + "Game::checkCreatureWalk" + ); + }, + "Game::checkCreatureWalk" + ); } void Creature::stopEventWalk() { @@ -825,10 +831,12 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared auto isReachable = g_game().map.getPathMatching(player->getPosition(), dirList, FrozenPathingConditionCall(corpse->getPosition()), fpp); if (player->checkAutoLoot(monster->isRewardBoss()) && isReachable) { - g_dispatcher().addEvent([player, corpseContainer, corpsePosition = corpse->getPosition()] { - g_game().playerQuickLootCorpse(player, corpseContainer, corpsePosition); - }, - "Game::playerQuickLootCorpse"); + g_dispatcher().addEvent( + [player, corpseContainer, corpsePosition = corpse->getPosition()] { + g_game().playerQuickLootCorpse(player, corpseContainer, corpsePosition); + }, + "Game::playerQuickLootCorpse" + ); } } } @@ -1061,7 +1069,7 @@ void Creature::goToFollowCreature_async(std::function &&onComplete) { }); if (onComplete) { - g_dispatcher().context().addEvent(std::move(onComplete)); + g_dispatcher().context().addEvent(std::move(onComplete), "Creature::onThink"); } } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 45f5808d633..c0a5e266181 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -7841,9 +7841,8 @@ bool Player::canAutoWalk(const Position &toPosition, const std::function // Check if can walk to the toPosition and send event to use function std::vector listDir; if (getPathTo(toPosition, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([creatureId = getID(), listDir] { g_game().playerAutoWalk(creatureId, listDir); }, __FUNCTION__); - - std::shared_ptr task = createPlayerTask(delay, function, __FUNCTION__); + g_dispatcher().addEvent([creatureId = getID(), listDir] { g_game().playerAutoWalk(creatureId, listDir); }, "Game::playerAutoWalk"); + const auto &task = createPlayerTask(delay, function, "Player::canAutoWalk"); setNextWalkActionTask(task); return true; } else { diff --git a/src/game/game.cpp b/src/game/game.cpp index df1b401bf48..9ce1346d1fe 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1384,7 +1384,11 @@ void Game::playerMoveCreature(std::shared_ptr player, std::shared_ptrcanDoAction()) { const auto &task = createPlayerTask( - 600, [this, player, movingCreature, toTile, movingCreatureOrigPos] { playerMoveCreatureByID(player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); }, "Game::playerMoveCreatureByID" + 600, + [this, player, movingCreature, toTile, movingCreatureOrigPos] { + playerMoveCreatureByID(player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); + }, + "Game::playerMoveCreatureByID" ); player->setNextActionPushTask(task); @@ -1399,7 +1403,11 @@ void Game::playerMoveCreature(std::shared_ptr player, std::shared_ptrgetPathTo(movingCreatureOrigPos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); const auto &task = createPlayerTask( - 600, [this, player, movingCreature, toTile, movingCreatureOrigPos] { playerMoveCreatureByID(player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); }, "Game::playerMoveCreatureByID" + 600, + [this, player, movingCreature, toTile, movingCreatureOrigPos] { + playerMoveCreatureByID(player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); + }, + "Game::playerMoveCreatureByID" ); player->pushEvent(true); player->setNextActionPushTask(task); @@ -1596,8 +1604,9 @@ void Game::playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, void Game::playerMoveItem(std::shared_ptr player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder) { if (!player->canDoAction()) { uint32_t delay = player->getNextActionTime(); - std::shared_ptr task = createPlayerTask( - delay, [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { + const auto &task = createPlayerTask( + delay, + [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { playerMoveItemByPlayerID(playerId, fromPos, itemId, fromStackPos, toPos, count); }, "Game::playerMoveItemByPlayerID" @@ -1687,9 +1696,9 @@ void Game::playerMoveItem(std::shared_ptr player, const Position &fromPo std::vector listDir; if (player->getPathTo(item->getPosition(), listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { + const auto &task = createPlayerTask( + 400, + [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { playerMoveItemByPlayerID(playerId, fromPos, itemId, fromStackPos, toPos, count); }, "Game::playerMoveItemByPlayerID" @@ -1749,9 +1758,9 @@ void Game::playerMoveItem(std::shared_ptr player, const Position &fromPo std::vector listDir; if (player->getPathTo(walkPos, listDir, 0, 0, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId = player->getID(), itemPos, itemId, itemStackPos, toPos, count] { + const auto &task = createPlayerTask( + 400, + [this, playerId = player->getID(), itemPos, itemId, itemStackPos, toPos, count] { playerMoveItemByPlayerID(playerId, itemPos, itemId, itemStackPos, toPos, count); }, "Game::playerMoveItemByPlayerID" @@ -3674,9 +3683,12 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f std::vector listDir; if (player->getPathTo(walkToPos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId); }, "Game::playerUseItemEx" + const auto &task = createPlayerTask( + 400, + [this, playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId] { + playerUseItemEx(playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId); + }, + "Game::playerUseItemEx" ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3703,8 +3715,12 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f if (it.isRune() || it.type == ITEM_TYPE_POTION) { delay = player->getNextPotionActionTime(); } - std::shared_ptr task = createPlayerTask( - delay, [this, playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId); }, "Game::playerUseItemEx" + const auto &task = createPlayerTask( + delay, + [this, playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId] { + playerUseItemEx(playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId); + }, + "Game::playerUseItemEx" ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3788,9 +3804,12 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, "Game::playerUseItem" + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, index, itemId] { + playerUseItem(playerId, pos, stackPos, index, itemId); + }, + "Game::playerUseItem" ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3817,8 +3836,12 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo if (it.isRune() || it.type == ITEM_TYPE_POTION) { delay = player->getNextPotionActionTime(); } - std::shared_ptr task = createPlayerTask( - delay, [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, "Game::playerUseItem" + const auto &task = createPlayerTask( + delay, + [this, playerId, pos, stackPos, index, itemId] { + playerUseItem(playerId, pos, stackPos, index, itemId); + }, + "Game::playerUseItem" ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3945,9 +3968,9 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin std::vector listDir; if (player->getPathTo(walkToPos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, itemPos, itemStackPos, creatureId, itemId] { + const auto &task = createPlayerTask( + 400, + [this, playerId, itemPos, itemStackPos, creatureId, itemId] { playerUseWithCreature(playerId, itemPos, itemStackPos, creatureId, itemId); }, "Game::playerUseWithCreature" @@ -3977,10 +4000,13 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin if (it.isRune() || it.type == ITEM_TYPE_POTION) { delay = player->getNextPotionActionTime(); } - std::shared_ptr task = createPlayerTask( - delay, [this, playerId, fromPos, fromStackPos, creatureId, itemId] { playerUseWithCreature(playerId, fromPos, fromStackPos, creatureId, itemId); }, "Game::playerUseWithCreature" + const auto &task = createPlayerTask( + delay, + [this, playerId, fromPos, fromStackPos, creatureId, itemId] { + playerUseWithCreature(playerId, fromPos, fromStackPos, creatureId, itemId); + }, + "Game::playerUseWithCreature" ); - if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); } else { @@ -4106,9 +4132,9 @@ void Game::playerRotateItem(uint32_t playerId, const Position &pos, uint8_t stac std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, itemId] { + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, itemId] { playerRotateItem(playerId, pos, stackPos, itemId); }, "Game::playerRotateItem" @@ -4162,14 +4188,22 @@ void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, false)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task; + auto &task; if (isPodiumOfRenown) { task = createPlayerTask( - 400, [player, item, pos, itemId, stackPos] { player->sendPodiumWindow(item, pos, itemId, stackPos); }, "Game::playerConfigureShowOffSocket" + 400, + [player, item, pos, itemId, stackPos] { + player->sendPodiumWindow(item, pos, itemId, stackPos); + }, + "Game::sendPodiumWindow" ); } else { task = createPlayerTask( - 400, [player, item, pos, itemId, stackPos] { player->sendMonsterPodiumWindow(item, pos, itemId, stackPos); }, "Game::playerConfigureShowOffSocket" + 400, + [player, item, pos, itemId, stackPos] { + player->sendMonsterPodiumWindow(item, pos, itemId, stackPos); + }, + "Game::sendMonsterPodiumWindow" ); } player->setNextWalkActionTask(task); @@ -4223,8 +4257,12 @@ void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Pos std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, false)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos] { playerBrowseField(playerId, pos); }, "Game::playerBrowseField" + const auto &task = createPlayerTask( + 400, + [this, playerId, pos] { + playerBrowseField(playerId, pos); + }, + "Game::playerBrowseField" ); player->setNextWalkActionTask(task); } else { @@ -4364,9 +4402,12 @@ void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t st std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, itemId] { playerWrapableItem(playerId, pos, stackPos, itemId); }, "Game::playerWrapableItem" + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, itemId] { + playerWrapableItem(playerId, pos, stackPos, itemId); + }, + "Game::playerWrapableItem" ); player->setNextWalkActionTask(task); } else { @@ -4545,8 +4586,12 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos] { playerBrowseField(playerId, pos); }, "Game::playerBrowseField" + const auto &task = createPlayerTask( + 400, + [this, playerId, pos] { + playerBrowseField(playerId, pos); + }, + "Game::playerBrowseField" ); player->setNextWalkActionTask(task); } else { @@ -4808,9 +4853,12 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, tradePlayerId, itemId] { playerRequestTrade(playerId, pos, stackPos, tradePlayerId, itemId); }, "Game::playerRequestTrade" + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, tradePlayerId, itemId] { + playerRequestTrade(playerId, pos, stackPos, tradePlayerId, itemId); + }, + "Game::playerRequestTrade" ); player->setNextWalkActionTask(task); } else { @@ -5370,9 +5418,10 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item } if (!autoLoot && !player->canDoAction()) { - uint32_t delay = player->getNextActionTime(); - std::shared_ptr task = createPlayerTask( - delay, [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { + const uint32_t delay = player->getNextActionTime(); + const auto &task = createPlayerTask( + delay, + [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { playerQuickLoot(playerId, pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot); }, "Game::playerQuickLoot" @@ -5387,8 +5436,9 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 0, [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { + const auto &task = createPlayerTask( + 300, + [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { playerQuickLoot(playerId, pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot); }, "Game::playerQuickLoot" @@ -9479,8 +9529,12 @@ void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, con if (std::vector listDir; player->getPathTo(pos, listDir, 0, 1, true, false)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos] { playerBrowseField(playerId, pos); }, "Game::playerBrowseField" + const auto &task = createPlayerTask( + 400, + [this, playerId, pos] { + playerBrowseField(playerId, pos); + }, + "Game::playerBrowseField" ); player->setNextWalkActionTask(task); } else { @@ -9579,8 +9633,9 @@ void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t st if (std::vector listDir; player->getPathTo(pos, listDir, 0, 1, true, true)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - std::shared_ptr task = createPlayerTask( - 400, [this, playerId, pos, stackPos, itemId] { + const auto &task = createPlayerTask( + 400, + [this, playerId, pos, stackPos, itemId] { playerRotatePodium(playerId, pos, stackPos, itemId); }, "Game::playerRotatePodium" diff --git a/src/game/scheduling/dispatcher.cpp b/src/game/scheduling/dispatcher.cpp index dbbfc020be5..eaedaa86ac5 100644 --- a/src/game/scheduling/dispatcher.cpp +++ b/src/game/scheduling/dispatcher.cpp @@ -236,17 +236,17 @@ void Dispatcher::stopEvent(uint64_t eventId) { } } -void DispatcherContext::addEvent(std::function &&f) const { - g_dispatcher().addEvent(std::move(f), taskName); +void DispatcherContext::addEvent(std::function &&f, std::string_view context) const { + g_dispatcher().addEvent(std::move(f), context); } -void DispatcherContext::tryAddEvent(std::function &&f) const { +void DispatcherContext::tryAddEvent(std::function &&f, std::string_view context) const { if (!f) { return; } if (isAsync()) { - g_dispatcher().addEvent(std::move(f), taskName); + g_dispatcher().addEvent(std::move(f), context); } else { f(); } diff --git a/src/game/scheduling/dispatcher.hpp b/src/game/scheduling/dispatcher.hpp index 94b284c9316..b50346e4895 100644 --- a/src/game/scheduling/dispatcher.hpp +++ b/src/game/scheduling/dispatcher.hpp @@ -56,10 +56,10 @@ struct DispatcherContext { } // postpone the event - void addEvent(std::function &&f) const; + void addEvent(std::function &&f, std::string_view context) const; // if the context is async, the event will be postponed, if not, it will be executed immediately. - void tryAddEvent(std::function &&f) const; + void tryAddEvent(std::function &&f, std::string_view context) const; private: void reset() { @@ -70,7 +70,7 @@ struct DispatcherContext { DispatcherType type = DispatcherType::None; TaskGroup group = TaskGroup::ThreadPool; - std::string_view taskName = ""; + std::string_view taskName; friend class Dispatcher; }; diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 83ecd091850..8a731be05af 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -180,7 +180,7 @@ int GameFunctions::luaGameGetPlayers(lua_State* L) { int GameFunctions::luaGameLoadMap(lua_State* L) { // Game.loadMap(path) const std::string &path = getString(L, 1); - g_dispatcher().addEvent([path]() { g_game().loadMap(path); }, "GameFunctions::luaGameLoadMap"); + g_dispatcher().addEvent([path]() { g_game().loadMap(path); }, "Game::loadMap"); return 0; } @@ -188,7 +188,7 @@ int GameFunctions::luaGameloadMapChunk(lua_State* L) { // Game.loadMapChunk(path, position, remove) const std::string &path = getString(L, 1); const Position &position = getPosition(L, 2); - g_dispatcher().addEvent([path, position]() { g_game().loadMap(path, position); }, "GameFunctions::luaGameloadMapChunk"); + g_dispatcher().addEvent([path, position]() { g_game().loadMap(path, position); }, "Game::loadMap"); return 0; } diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index e6e2f79b806..099e5c2cd81 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -138,11 +138,14 @@ std::shared_ptr MapCache::getOrCreateTileFromCache(const std::unique_ptrsetFlag(static_cast(cachedTile->flags)); // add zone synchronously - g_dispatcher().context().tryAddEvent([tile, pos] { - for (const auto &zone : Zone::getZones(pos)) { - tile->addZone(zone); - } - }); + g_dispatcher().context().tryAddEvent( + [tile, pos] { + for (const auto &zone : Zone::getZones(pos)) { + tile->addZone(zone); + } + }, + "Zone::getZones" + ); floor->setTile(x, y, tile); diff --git a/src/server/network/protocol/protocol.cpp b/src/server/network/protocol/protocol.cpp index 255899f2f99..c1b2e37f5a6 100644 --- a/src/server/network/protocol/protocol.cpp +++ b/src/server/network/protocol/protocol.cpp @@ -44,13 +44,17 @@ bool Protocol::sendRecvMessageCallback(NetworkMessage &msg) { return false; } - g_dispatcher().addEvent([&msg, protocolWeak = std::weak_ptr(shared_from_this())]() { - if (auto protocol = protocolWeak.lock()) { - if (auto protocolConnection = protocol->getConnection()) { - protocol->parsePacket(msg); - protocolConnection->resumeWork(); + g_dispatcher().addEvent( + [&msg, protocolWeak = std::weak_ptr(shared_from_this())]() { + if (auto protocol = protocolWeak.lock()) { + if (auto protocolConnection = protocol->getConnection()) { + protocol->parsePacket(msg); + protocolConnection->resumeWork(); + } } - } }, "Protocol::sendRecvMessageCallback"); + }, + "Protocol::sendRecvMessageCallback" + ); return true; } diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 032b9b512d0..ed1df8857b1 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -5040,18 +5040,20 @@ void ProtocolGame::updateCoinBalance() { return; } - g_dispatcher().addEvent([playerId = player->getID()] { - const auto &threadPlayer = g_game().getPlayerByID(playerId); - if (threadPlayer && threadPlayer->getAccount()) { - const auto [coins, errCoin] = threadPlayer->getAccount()->getCoins(enumToValue(CoinType::Normal)); - const auto [transferCoins, errTCoin] = threadPlayer->getAccount()->getCoins(enumToValue(CoinType::Transferable)); - - threadPlayer->coinBalance = coins; - threadPlayer->coinTransferableBalance = transferCoins; - threadPlayer->sendCoinBalance(); - } - }, - "ProtocolGame::updateCoinBalance"); + g_dispatcher().addEvent( + [playerId = player->getID()] { + const auto &threadPlayer = g_game().getPlayerByID(playerId); + if (threadPlayer && threadPlayer->getAccount()) { + const auto [coins, errCoin] = threadPlayer->getAccount()->getCoins(enumToValue(CoinType::Normal)); + const auto [transferCoins, errTCoin] = threadPlayer->getAccount()->getCoins(enumToValue(CoinType::Transferable)); + + threadPlayer->coinBalance = coins; + threadPlayer->coinTransferableBalance = transferCoins; + threadPlayer->sendCoinBalance(); + } + }, + "ProtocolGame::updateCoinBalance" + ); } void ProtocolGame::sendMarketLeave() { diff --git a/src/server/network/protocol/protocollogin.cpp b/src/server/network/protocol/protocollogin.cpp index d6e9e3cb9f1..f59b4e63188 100644 --- a/src/server/network/protocol/protocollogin.cpp +++ b/src/server/network/protocol/protocollogin.cpp @@ -174,8 +174,10 @@ void ProtocolLogin::onRecvFirstMessage(NetworkMessage &msg) { return; } - g_dispatcher().addEvent([self = std::static_pointer_cast(shared_from_this()), accountDescriptor, password] { - self->getCharacterList(accountDescriptor, password); - }, - "ProtocolLogin::getCharacterList"); + g_dispatcher().addEvent( + [self = std::static_pointer_cast(shared_from_this()), accountDescriptor, password] { + self->getCharacterList(accountDescriptor, password); + }, + "ProtocolLogin::getCharacterList" + ); } diff --git a/src/server/network/protocol/protocolstatus.cpp b/src/server/network/protocol/protocolstatus.cpp index 15a3f74be07..a9deaaac12f 100644 --- a/src/server/network/protocol/protocolstatus.cpp +++ b/src/server/network/protocol/protocolstatus.cpp @@ -44,10 +44,12 @@ void ProtocolStatus::onRecvFirstMessage(NetworkMessage &msg) { // XML info protocol case 0xFF: { if (msg.getString(4) == "info") { - g_dispatcher().addEvent([self = std::static_pointer_cast(shared_from_this())] { - self->sendStatusString(); - }, - "ProtocolStatus::sendStatusString"); + g_dispatcher().addEvent( + [self = std::static_pointer_cast(shared_from_this())] { + self->sendStatusString(); + }, + "ProtocolStatus::sendStatusString" + ); return; } break; @@ -60,10 +62,12 @@ void ProtocolStatus::onRecvFirstMessage(NetworkMessage &msg) { if (requestedInfo & REQUEST_PLAYER_STATUS_INFO) { characterName = msg.getString(); } - g_dispatcher().addEvent([self = std::static_pointer_cast(shared_from_this()), requestedInfo, characterName] { - self->sendInfo(requestedInfo, characterName); - }, - "ProtocolStatus::sendInfo"); + g_dispatcher().addEvent( + [self = std::static_pointer_cast(shared_from_this()), requestedInfo, characterName] { + self->sendInfo(requestedInfo, characterName); + }, + "ProtocolStatus::sendInfo" + ); return; } diff --git a/src/server/signals.cpp b/src/server/signals.cpp index 626a918f677..265887ffbb6 100644 --- a/src/server/signals.cpp +++ b/src/server/signals.cpp @@ -54,21 +54,21 @@ void Signals::asyncWait() { void Signals::dispatchSignalHandler(int signal) { switch (signal) { case SIGINT: // Shuts the server down - g_dispatcher().addEvent(sigintHandler, "sigintHandler"); + g_dispatcher().addEvent(sigintHandler, "Signals::sigintHandler"); break; case SIGTERM: // Shuts the server down - g_dispatcher().addEvent(sigtermHandler, "sigtermHandler"); + g_dispatcher().addEvent(sigtermHandler, "Signals::sigtermHandler"); break; #ifndef _WIN32 case SIGHUP: // Reload config/data - g_dispatcher().addEvent(sighupHandler, "sighupHandler"); + g_dispatcher().addEvent(sighupHandler, "Signals::sighupHandler"); break; case SIGUSR1: // Saves game state - g_dispatcher().addEvent(sigusr1Handler, "sigusr1Handler"); + g_dispatcher().addEvent(sigusr1Handler, "Signals::sigusr1Handler"); break; #else case SIGBREAK: // Shuts the server down - g_dispatcher().addEvent(sigbreakHandler, "sigbreakHandler"); + g_dispatcher().addEvent(sigbreakHandler, "Signals::sigbreakHandler"); // hold the thread until other threads end inject().shutdown(); break; From 95b60cf82e043933acbdd4b84879042f556c9156 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Mon, 2 Sep 2024 02:17:06 -0300 Subject: [PATCH 2/3] Update game.cpp --- src/game/game.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 9ce1346d1fe..f7b22b0feae 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -4188,25 +4188,25 @@ void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, false)) { g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); - auto &task; if (isPodiumOfRenown) { - task = createPlayerTask( + const auto &task = createPlayerTask( 400, [player, item, pos, itemId, stackPos] { player->sendPodiumWindow(item, pos, itemId, stackPos); }, "Game::sendPodiumWindow" ); + player->setNextWalkActionTask(task); } else { - task = createPlayerTask( + const auto &task = createPlayerTask( 400, [player, item, pos, itemId, stackPos] { player->sendMonsterPodiumWindow(item, pos, itemId, stackPos); }, "Game::sendMonsterPodiumWindow" ); + player->setNextWalkActionTask(task); } - player->setNextWalkActionTask(task); } else { player->sendCancelMessage(RETURNVALUE_THEREISNOWAY); } From 7f28f7382a548256d3781c51b2858b81e7304e86 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Fri, 13 Sep 2024 01:47:31 -0300 Subject: [PATCH 3/3] update --- src/canary_server.cpp | 2 +- src/creatures/combat/condition.cpp | 2 +- src/creatures/creature.cpp | 10 +-- src/creatures/monsters/monster.cpp | 2 +- .../monsters/spawns/spawn_monster.cpp | 2 +- src/creatures/players/player.cpp | 15 ++-- src/database/databasetasks.cpp | 4 +- src/game/game.cpp | 84 +++++++++---------- .../functions/core/game/game_functions.cpp | 4 +- src/server/network/connection/connection.cpp | 4 +- src/server/network/protocol/protocol.cpp | 2 +- src/server/network/protocol/protocolgame.cpp | 4 +- src/server/network/protocol/protocollogin.cpp | 2 +- .../network/protocol/protocolstatus.cpp | 4 +- src/server/signals.cpp | 10 +-- 15 files changed, 76 insertions(+), 75 deletions(-) diff --git a/src/canary_server.cpp b/src/canary_server.cpp index cca280b69fa..f71fc71ba9a 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -123,7 +123,7 @@ int CanaryServer::run() { loaderStatus.notify_one(); }, - "CanaryServer::run" + __FUNCTION__ ); loaderStatus.wait(LoaderStatus::LOADING); diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index aba685915b0..b308c05a5bc 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -2099,7 +2099,7 @@ bool ConditionFeared::executeCondition(std::shared_ptr creature, int32 [id = creature->getID(), listDir] { g_game().forcePlayerAutoWalk(id, listDir); }, - "Game::forcePlayerAutoWalk" + __FUNCTION__ ); g_logger().debug("[ConditionFeared::executeCondition] Walking Scheduled"); diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 311e29598d6..56ed1770039 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -606,7 +606,7 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s if (followCreature && (creature == getCreature() || creature == followCreature)) { if (hasFollowPath) { isUpdatingPath = true; - g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, "Game::updateCreatureWalk"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, __FUNCTION__); } if (newPos.z != oldPos.z || !canSee(followCreature->getPosition())) { @@ -621,7 +621,7 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s } else { if (hasExtraSwing()) { // our target is moving lets see if we can get in hit - g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, "Game::checkCreatureAttack"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, __FUNCTION__); } if (newTile->getZoneType() != oldTile->getZoneType()) { @@ -835,7 +835,7 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared [player, corpseContainer, corpsePosition = corpse->getPosition()] { g_game().playerQuickLootCorpse(player, corpseContainer, corpsePosition); }, - "Game::playerQuickLootCorpse" + __FUNCTION__ ); } } @@ -880,7 +880,7 @@ void Creature::changeHealth(int32_t healthChange, bool sendHealthChange /* = tru g_game().addCreatureHealth(static_self_cast()); } if (health <= 0) { - g_dispatcher().addEvent([creatureId = getID()] { g_game().executeDeath(creatureId); }, "Game::executeDeath"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().executeDeath(creatureId); }, __FUNCTION__); } } @@ -1069,7 +1069,7 @@ void Creature::goToFollowCreature_async(std::function &&onComplete) { }); if (onComplete) { - g_dispatcher().context().addEvent(std::move(onComplete), "Creature::onThink"); + g_dispatcher().context().addEvent(std::move(onComplete), __FUNCTION__); } } diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 1a364ece2ba..4a6d07fe8d7 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -792,7 +792,7 @@ bool Monster::selectTarget(const std::shared_ptr &creature) { if (isHostile() || isSummon()) { if (setAttackedCreature(creature)) { - g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, "Game::checkCreatureAttack"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, __FUNCTION__); } } return setFollowCreature(creature); diff --git a/src/creatures/monsters/spawns/spawn_monster.cpp b/src/creatures/monsters/spawns/spawn_monster.cpp index 846068e67b7..93b381da061 100644 --- a/src/creatures/monsters/spawns/spawn_monster.cpp +++ b/src/creatures/monsters/spawns/spawn_monster.cpp @@ -226,7 +226,7 @@ void SpawnMonster::startup(bool delayed) { continue; } if (delayed) { - g_dispatcher().addEvent([this, spawnMonsterId, &sb, mType] { scheduleSpawn(spawnMonsterId, sb, mType, 0, true); }, "SpawnMonster::startup"); + g_dispatcher().addEvent([this, spawnMonsterId, &sb, mType] { scheduleSpawn(spawnMonsterId, sb, mType, 0, true); }, __FUNCTION__); } else { scheduleSpawn(spawnMonsterId, sb, mType, 0, true); } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 3983aeb5a43..8c49226b621 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -1946,7 +1946,7 @@ void Player::onCreatureMove(const std::shared_ptr &creature, const std const auto &followCreature = getFollowCreature(); if (hasFollowPath && (creature == followCreature || (creature.get() == this && followCreature))) { isUpdatingPath = false; - g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, "Game::updateCreatureWalk"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().updateCreatureWalk(creatureId); }, __FUNCTION__); } if (creature != getPlayer()) { @@ -4283,7 +4283,7 @@ bool Player::updateSaleShopList(std::shared_ptr item) { return true; } - g_dispatcher().addEvent([creatureId = getID()] { g_game().updatePlayerSaleItems(creatureId); }, "Game::updatePlayerSaleItems"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().updatePlayerSaleItems(creatureId); }, __FUNCTION__); scheduledSaleUpdate = true; return true; } @@ -4354,7 +4354,7 @@ bool Player::setAttackedCreature(std::shared_ptr creature) { } if (creature) { - g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, "Game::checkCreatureAttack"); + g_dispatcher().addEvent([creatureId = getID()] { g_game().checkCreatureAttack(creatureId); }, __FUNCTION__); } return true; } @@ -4416,7 +4416,8 @@ void Player::doAttacking(uint32_t) { const auto &task = createPlayerTask( std::max(SCHEDULER_MINTICKS, delay), - [playerId = getID()] { g_game().checkCreatureAttack(playerId); }, "Game::checkCreatureAttack" + [playerId = getID()] { g_game().checkCreatureAttack(playerId); }, + __FUNCTION__ ); if (!classicSpeed) { @@ -6785,7 +6786,7 @@ void Player::triggerTranscendance() { player->sendBasicData(); } }, - "Player::triggerTranscendance" + __FUNCTION__ ); g_dispatcher().scheduleEvent(task); @@ -7857,8 +7858,8 @@ bool Player::canAutoWalk(const Position &toPosition, const std::function // Check if can walk to the toPosition and send event to use function std::vector listDir; if (getPathTo(toPosition, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([creatureId = getID(), listDir] { g_game().playerAutoWalk(creatureId, listDir); }, "Game::playerAutoWalk"); - const auto &task = createPlayerTask(delay, function, "Player::canAutoWalk"); + g_dispatcher().addEvent([creatureId = getID(), listDir] { g_game().playerAutoWalk(creatureId, listDir); }, __FUNCTION__); + const auto &task = createPlayerTask(delay, function, __FUNCTION__); setNextWalkActionTask(task); return true; } else { diff --git a/src/database/databasetasks.cpp b/src/database/databasetasks.cpp index 06cfda93fc0..8a660f1c031 100644 --- a/src/database/databasetasks.cpp +++ b/src/database/databasetasks.cpp @@ -26,7 +26,7 @@ void DatabaseTasks::execute(const std::string &query, std::functiongetID(), movingCreature->getID(), movingCreature->getPosition(), tile->getPosition()); }, - "Game::playerMoveCreatureByID" + __FUNCTION__ ); player->setNextActionPushTask(task); } else { @@ -1389,7 +1389,7 @@ void Game::playerMoveCreature(std::shared_ptr player, std::shared_ptrgetID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); }, - "Game::playerMoveCreatureByID" + __FUNCTION__ ); player->setNextActionPushTask(task); @@ -1402,13 +1402,13 @@ void Game::playerMoveCreature(std::shared_ptr player, std::shared_ptr listDir; if (player->getPathTo(movingCreatureOrigPos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 600, [this, player, movingCreature, toTile, movingCreatureOrigPos] { playerMoveCreatureByID(player->getID(), movingCreature->getID(), movingCreatureOrigPos, toTile->getPosition()); }, - "Game::playerMoveCreatureByID" + __FUNCTION__ ); player->pushEvent(true); player->setNextActionPushTask(task); @@ -1614,7 +1614,7 @@ void Game::playerMoveItem(std::shared_ptr player, const Position &fromPo [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { playerMoveItemByPlayerID(playerId, fromPos, itemId, fromStackPos, toPos, count); }, - "Game::playerMoveItemByPlayerID" + __FUNCTION__ ); player->setNextActionTask(task); return; @@ -1700,13 +1700,13 @@ void Game::playerMoveItem(std::shared_ptr player, const Position &fromPo // need to walk to the item first before using it std::vector listDir; if (player->getPathTo(item->getPosition(), listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { playerMoveItemByPlayerID(playerId, fromPos, itemId, fromStackPos, toPos, count); }, - "Game::playerMoveItemByPlayerID" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -1762,13 +1762,13 @@ void Game::playerMoveItem(std::shared_ptr player, const Position &fromPo std::vector listDir; if (player->getPathTo(walkPos, listDir, 0, 0, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId = player->getID(), itemPos, itemId, itemStackPos, toPos, count] { playerMoveItemByPlayerID(playerId, itemPos, itemId, itemStackPos, toPos, count); }, - "Game::playerMoveItemByPlayerID" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -3687,13 +3687,13 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f std::vector listDir; if (player->getPathTo(walkToPos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, itemPos, itemStackPos, fromItemId, toPos, toStackPos, toItemId); }, - "Game::playerUseItemEx" + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3725,7 +3725,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f [this, playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId] { playerUseItemEx(playerId, fromPos, fromStackPos, fromItemId, toPos, toStackPos, toItemId); }, - "Game::playerUseItemEx" + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3808,13 +3808,13 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo if (ret == RETURNVALUE_TOOFARAWAY) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, - "Game::playerUseItem" + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3846,7 +3846,7 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo [this, playerId, pos, stackPos, index, itemId] { playerUseItem(playerId, pos, stackPos, index, itemId); }, - "Game::playerUseItem" + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -3972,13 +3972,13 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin std::vector listDir; if (player->getPathTo(walkToPos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, itemPos, itemStackPos, creatureId, itemId] { playerUseWithCreature(playerId, itemPos, itemStackPos, creatureId, itemId); }, - "Game::playerUseWithCreature" + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -4010,7 +4010,7 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin [this, playerId, fromPos, fromStackPos, creatureId, itemId] { playerUseWithCreature(playerId, fromPos, fromStackPos, creatureId, itemId); }, - "Game::playerUseWithCreature" + __FUNCTION__ ); if (it.isRune() || it.type == ITEM_TYPE_POTION) { player->setNextPotionActionTask(task); @@ -4136,13 +4136,13 @@ void Game::playerRotateItem(uint32_t playerId, const Position &pos, uint8_t stac if (pos.x != 0xFFFF && !Position::areInRange<1, 1, 0>(pos, player->getPosition())) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, pos, stackPos, itemId] { playerRotateItem(playerId, pos, stackPos, itemId); }, - "Game::playerRotateItem" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -4192,14 +4192,14 @@ void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, if (!Position::areInRange<1, 1, 0>(pos, player->getPosition())) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, false)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); if (isPodiumOfRenown) { const auto &task = createPlayerTask( 400, [player, item, pos, itemId, stackPos] { player->sendPodiumWindow(item, pos, itemId, stackPos); }, - "Game::sendPodiumWindow" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -4208,7 +4208,7 @@ void Game::playerConfigureShowOffSocket(uint32_t playerId, const Position &pos, [player, item, pos, itemId, stackPos] { player->sendMonsterPodiumWindow(item, pos, itemId, stackPos); }, - "Game::sendMonsterPodiumWindow" + __FUNCTION__ ); player->setNextWalkActionTask(task); } @@ -4261,13 +4261,13 @@ void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Pos if (!Position::areInRange<1, 1, 0>(pos, player->getPosition())) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, false)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, pos] { playerBrowseField(playerId, pos); }, - "Game::playerBrowseField" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -4406,13 +4406,13 @@ void Game::playerWrapableItem(uint32_t playerId, const Position &pos, uint8_t st if (pos.x != 0xFFFF && !Position::areInRange<1, 1, 0>(pos, player->getPosition())) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, pos, stackPos, itemId] { playerWrapableItem(playerId, pos, stackPos, itemId); }, - "Game::playerWrapableItem" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -4590,13 +4590,13 @@ void Game::playerBrowseField(uint32_t playerId, const Position &pos) { if (!Position::areInRange<1, 1>(playerPos, pos)) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, pos] { playerBrowseField(playerId, pos); }, - "Game::playerBrowseField" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -4857,13 +4857,13 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st if (!Position::areInRange<1, 1>(tradeItemPosition, playerPosition)) { std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, pos, stackPos, tradePlayerId, itemId] { playerRequestTrade(playerId, pos, stackPos, tradePlayerId, itemId); }, - "Game::playerRequestTrade" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -5429,7 +5429,7 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { playerQuickLoot(playerId, pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot); }, - "Game::playerQuickLoot" + __FUNCTION__ ); player->setNextActionTask(task); return; @@ -5440,13 +5440,13 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item // need to walk to the corpse first before looting it std::vector listDir; if (player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 300, [this, playerId = player->getID(), pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot] { playerQuickLoot(playerId, pos, itemId, stackPos, defaultItem, lootAllCorpses, autoLoot); }, - "Game::playerQuickLoot" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -5815,7 +5815,7 @@ void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { } player->setAttackedCreature(attackCreature); - g_dispatcher().addEvent([this, plyerId = player->getID()] { updateCreatureWalk(plyerId); }, "Game::updateCreatureWalk"); + g_dispatcher().addEvent([this, plyerId = player->getID()] { updateCreatureWalk(plyerId); }, __FUNCTION__); } void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { @@ -5825,7 +5825,7 @@ void Game::playerFollowCreature(uint32_t playerId, uint32_t creatureId) { } player->setAttackedCreature(nullptr); - g_dispatcher().addEvent([this, plyerId = player->getID()] { updateCreatureWalk(plyerId); }, "Game::updateCreatureWalk"); + g_dispatcher().addEvent([this, plyerId = player->getID()] { updateCreatureWalk(plyerId); }, __FUNCTION__); player->setFollowCreature(getCreatureByID(creatureId)); } @@ -9533,13 +9533,13 @@ void Game::playerSetMonsterPodium(uint32_t playerId, uint32_t monsterRaceId, con if (!Position::areInRange<1, 1, 0>(pos, player->getPosition())) { if (std::vector listDir; player->getPathTo(pos, listDir, 0, 1, true, false)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, pos] { playerBrowseField(playerId, pos); }, - "Game::playerBrowseField" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -9637,13 +9637,13 @@ void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t st if (pos.x != 0xFFFF && !Position::areInRange<1, 1, 0>(pos, player->getPosition())) { if (std::vector listDir; player->getPathTo(pos, listDir, 0, 1, true, true)) { - g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, "Game::playerAutoWalk"); + g_dispatcher().addEvent([this, playerId = player->getID(), listDir] { playerAutoWalk(playerId, listDir); }, __FUNCTION__); const auto &task = createPlayerTask( 400, [this, playerId, pos, stackPos, itemId] { playerRotatePodium(playerId, pos, stackPos, itemId); }, - "Game::playerRotatePodium" + __FUNCTION__ ); player->setNextWalkActionTask(task); } else { @@ -10162,7 +10162,7 @@ uint32_t Game::makeFiendishMonster(uint32_t forgeableMonsterId /* = 0*/, bool cr auto schedulerTask = createPlayerTask( finalTime, [this, monster] { updateFiendishMonsterStatus(monster->getID(), monster->getName()); }, - "Game::updateFiendishMonsterStatus" + __FUNCTION__ ); forgeMonsterEventIds[monster->getID()] = g_dispatcher().scheduleEvent(schedulerTask); return monster->getID(); diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 8e720f79d22..83544ded535 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -180,7 +180,7 @@ int GameFunctions::luaGameGetPlayers(lua_State* L) { int GameFunctions::luaGameLoadMap(lua_State* L) { // Game.loadMap(path) const std::string &path = getString(L, 1); - g_dispatcher().addEvent([path]() { g_game().loadMap(path); }, "Game::loadMap"); + g_dispatcher().addEvent([path]() { g_game().loadMap(path); }, __FUNCTION__); return 0; } @@ -188,7 +188,7 @@ int GameFunctions::luaGameloadMapChunk(lua_State* L) { // Game.loadMapChunk(path, position, remove) const std::string &path = getString(L, 1); const Position &position = getPosition(L, 2); - g_dispatcher().addEvent([path, position]() { g_game().loadMap(path, position); }, "Game::loadMap"); + g_dispatcher().addEvent([path, position]() { g_game().loadMap(path, position); }, __FUNCTION__); return 0; } diff --git a/src/server/network/connection/connection.cpp b/src/server/network/connection/connection.cpp index 3072384420d..a3782d56cba 100644 --- a/src/server/network/connection/connection.cpp +++ b/src/server/network/connection/connection.cpp @@ -62,7 +62,7 @@ void Connection::close(bool force) { connectionState = CONNECTION_STATE_CLOSED; if (protocol) { - g_dispatcher().addEvent([protocol = protocol] { protocol->release(); }, "Protocol::release", std::chrono::milliseconds(CONNECTION_WRITE_TIMEOUT * 1000).count()); + g_dispatcher().addEvent([protocol = protocol] { protocol->release(); }, __FUNCTION__, std::chrono::milliseconds(CONNECTION_WRITE_TIMEOUT * 1000).count()); } if (messageQueue.empty() || force) { @@ -98,7 +98,7 @@ void Connection::closeSocket() { void Connection::accept(Protocol_ptr protocolPtr) { connectionState = CONNECTION_STATE_IDENTIFYING; protocol = std::move(protocolPtr); - g_dispatcher().addEvent([protocol = protocol] { protocol->onConnect(); }, "Protocol::onConnect", std::chrono::milliseconds(CONNECTION_WRITE_TIMEOUT * 1000).count()); + g_dispatcher().addEvent([protocol = protocol] { protocol->onConnect(); }, __FUNCTION__, std::chrono::milliseconds(CONNECTION_WRITE_TIMEOUT * 1000).count()); acceptInternal(false); } diff --git a/src/server/network/protocol/protocol.cpp b/src/server/network/protocol/protocol.cpp index c1b2e37f5a6..c40ead17ab0 100644 --- a/src/server/network/protocol/protocol.cpp +++ b/src/server/network/protocol/protocol.cpp @@ -53,7 +53,7 @@ bool Protocol::sendRecvMessageCallback(NetworkMessage &msg) { } } }, - "Protocol::sendRecvMessageCallback" + __FUNCTION__ ); return true; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index ed1df8857b1..d8cdda05f45 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -859,7 +859,7 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage &msg) { return; } - g_dispatcher().addEvent([self = getThis(), characterName, accountId, operatingSystem] { self->login(characterName, accountId, operatingSystem); }, "ProtocolGame::login"); + g_dispatcher().addEvent([self = getThis(), characterName, accountId, operatingSystem] { self->login(characterName, accountId, operatingSystem); }, __FUNCTION__); } void ProtocolGame::onConnect() { @@ -5052,7 +5052,7 @@ void ProtocolGame::updateCoinBalance() { threadPlayer->sendCoinBalance(); } }, - "ProtocolGame::updateCoinBalance" + __FUNCTION__ ); } diff --git a/src/server/network/protocol/protocollogin.cpp b/src/server/network/protocol/protocollogin.cpp index f59b4e63188..f8c68634f64 100644 --- a/src/server/network/protocol/protocollogin.cpp +++ b/src/server/network/protocol/protocollogin.cpp @@ -178,6 +178,6 @@ void ProtocolLogin::onRecvFirstMessage(NetworkMessage &msg) { [self = std::static_pointer_cast(shared_from_this()), accountDescriptor, password] { self->getCharacterList(accountDescriptor, password); }, - "ProtocolLogin::getCharacterList" + __FUNCTION__ ); } diff --git a/src/server/network/protocol/protocolstatus.cpp b/src/server/network/protocol/protocolstatus.cpp index a9deaaac12f..f9ec878eda9 100644 --- a/src/server/network/protocol/protocolstatus.cpp +++ b/src/server/network/protocol/protocolstatus.cpp @@ -48,7 +48,7 @@ void ProtocolStatus::onRecvFirstMessage(NetworkMessage &msg) { [self = std::static_pointer_cast(shared_from_this())] { self->sendStatusString(); }, - "ProtocolStatus::sendStatusString" + __FUNCTION__ ); return; } @@ -66,7 +66,7 @@ void ProtocolStatus::onRecvFirstMessage(NetworkMessage &msg) { [self = std::static_pointer_cast(shared_from_this()), requestedInfo, characterName] { self->sendInfo(requestedInfo, characterName); }, - "ProtocolStatus::sendInfo" + __FUNCTION__ ); return; diff --git a/src/server/signals.cpp b/src/server/signals.cpp index 265887ffbb6..ae71d833c93 100644 --- a/src/server/signals.cpp +++ b/src/server/signals.cpp @@ -54,21 +54,21 @@ void Signals::asyncWait() { void Signals::dispatchSignalHandler(int signal) { switch (signal) { case SIGINT: // Shuts the server down - g_dispatcher().addEvent(sigintHandler, "Signals::sigintHandler"); + g_dispatcher().addEvent(sigintHandler, __FUNCTION__); break; case SIGTERM: // Shuts the server down - g_dispatcher().addEvent(sigtermHandler, "Signals::sigtermHandler"); + g_dispatcher().addEvent(sigtermHandler, __FUNCTION__); break; #ifndef _WIN32 case SIGHUP: // Reload config/data - g_dispatcher().addEvent(sighupHandler, "Signals::sighupHandler"); + g_dispatcher().addEvent(sighupHandler, __FUNCTION__); break; case SIGUSR1: // Saves game state - g_dispatcher().addEvent(sigusr1Handler, "Signals::sigusr1Handler"); + g_dispatcher().addEvent(sigusr1Handler, __FUNCTION__); break; #else case SIGBREAK: // Shuts the server down - g_dispatcher().addEvent(sigbreakHandler, "Signals::sigbreakHandler"); + g_dispatcher().addEvent(sigbreakHandler, __FUNCTION__); // hold the thread until other threads end inject().shutdown(); break;