From 013e2c1710e3c7540f405b30c7d91cb711db32ae Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sat, 25 Nov 2023 06:32:30 -0300 Subject: [PATCH 1/4] fix: validations of "getPlayer" lua function If we do not validate getPlayer, a generalized warning will be returned across the distro, which makes it difficult to identify how to fix the problem. --- .../functions/core/game/bank_functions.cpp | 28 +++++++++------ .../functions/core/game/global_functions.cpp | 8 ++--- .../core/game/modal_window_functions.cpp | 4 +-- .../network/network_message_functions.cpp | 10 +++--- .../functions/creatures/npc/npc_functions.cpp | 14 +++++--- .../creatures/player/party_functions.cpp | 35 ++++++++++++++++--- .../creatures/player/player_functions.cpp | 19 +++++----- src/lua/functions/map/house_functions.cpp | 25 ++++++++++--- src/lua/functions/map/position_functions.cpp | 24 +++++++++---- 9 files changed, 117 insertions(+), 50 deletions(-) diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index 90e4fdecb5f..dd561c47a5a 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -7,7 +7,7 @@ int BankFunctions::luaBankCredit(lua_State* L) { // Bank.credit(playerOrGuild, amount) auto bank = getBank(L, 1); if (bank == nullptr) { - lua_pushnil(L); + reportErrorFunc("Bank is nullptr"); return 1; } uint64_t amount = getNumber(L, 2); @@ -19,7 +19,7 @@ int BankFunctions::luaBankDebit(lua_State* L) { // Bank.debit(playerOrGuild, amount) auto bank = getBank(L, 1); if (bank == nullptr) { - lua_pushnil(L); + reportErrorFunc("Bank is nullptr"); return 1; } uint64_t amount = getNumber(L, 2); @@ -31,7 +31,7 @@ int BankFunctions::luaBankBalance(lua_State* L) { // Bank.balance(playerOrGuild[, amount]]) auto bank = getBank(L, 1); if (bank == nullptr) { - lua_pushnil(L); + reportErrorFunc("Bank is nullptr"); return 1; } if (lua_gettop(L) == 1) { @@ -47,7 +47,7 @@ int BankFunctions::luaBankHasBalance(lua_State* L) { // Bank.hasBalance(playerOrGuild, amount) auto bank = getBank(L, 1); if (bank == nullptr) { - lua_pushnil(L); + reportErrorFunc("Bank is nullptr"); return 1; } uint64_t amount = getNumber(L, 2); @@ -60,13 +60,13 @@ int BankFunctions::luaBankTransfer(lua_State* L) { auto source = getBank(L, 1); if (source == nullptr) { g_logger().debug("BankFunctions::luaBankTransfer: source is null"); - lua_pushnil(L); + reportErrorFunc("Bank is nullptr"); return 1; } std::shared_ptr destination = getBank(L, 2); if (destination == nullptr) { g_logger().debug("BankFunctions::luaBankTransfer: destination is null"); - lua_pushnil(L); + reportErrorFunc("Bank is nullptr"); return 1; } uint64_t amount = getNumber(L, 3); @@ -78,12 +78,12 @@ int BankFunctions::luaBankTransferToGuild(lua_State* L) { // Bank.transfer(fromPlayerOrGuild, toGuild, amount) auto source = getBank(L, 1); if (source == nullptr) { - lua_pushnil(L); + reportErrorFunc("Source is nullptr"); return 1; } std::shared_ptr destination = getBank(L, 2, true /* isGuild */); if (destination == nullptr) { - lua_pushnil(L); + reportErrorFunc("Destination is nullptr"); return 1; } uint64_t amount = getNumber(L, 3); @@ -94,6 +94,11 @@ int BankFunctions::luaBankTransferToGuild(lua_State* L) { int BankFunctions::luaBankWithdraw(lua_State* L) { // Bank.withdraw(player, amount[, source = player]) auto player = getPlayer(L, 1); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + uint64_t amount = getNumber(L, 2); if (lua_gettop(L) == 2) { if (!player) { @@ -106,7 +111,7 @@ int BankFunctions::luaBankWithdraw(lua_State* L) { } auto source = getBank(L, 3); if (source == nullptr) { - lua_pushnil(L); + reportErrorFunc("Source is nullptr"); return 1; } pushBoolean(L, source->withdraw(player, amount)); @@ -117,10 +122,11 @@ int BankFunctions::luaBankDeposit(lua_State* L) { // Bank.deposit(player, amount[, destination = player]) auto player = getPlayer(L, 1); if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto bank = std::make_shared(player); + const auto bank = std::make_shared(player); uint64_t amount = 0; if (lua_isnumber(L, 2)) { amount = getNumber(L, 2); @@ -134,7 +140,7 @@ int BankFunctions::luaBankDeposit(lua_State* L) { } auto destination = getBank(L, 3); if (destination == nullptr) { - lua_pushnil(L); + reportErrorFunc("Destination is nullptr"); return 1; } pushBoolean(L, g_game().removeMoney(player, amount) && destination->credit(amount)); diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index 7d725b85bce..e2961e26215 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -741,16 +741,16 @@ int GlobalFunctions::luaDebugPrint(lua_State* L) { int GlobalFunctions::luaIsInWar(lua_State* L) { // isInWar(cid, target) - std::shared_ptr player = getPlayer(L, 1); + const auto &player = getPlayer(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + reportErrorFunc(fmt::format("{} - Player", getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND))); pushBoolean(L, false); return 1; } - std::shared_ptr targetPlayer = getPlayer(L, 2); + const auto &targetPlayer = getPlayer(L, 2); if (!targetPlayer) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + reportErrorFunc(fmt::format("{} - TargetPlayer", getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND))); pushBoolean(L, false); return 1; } diff --git a/src/lua/functions/core/game/modal_window_functions.cpp b/src/lua/functions/core/game/modal_window_functions.cpp index 11441993fa4..b775bdda6b6 100644 --- a/src/lua/functions/core/game/modal_window_functions.cpp +++ b/src/lua/functions/core/game/modal_window_functions.cpp @@ -204,9 +204,9 @@ int ModalWindowFunctions::luaModalWindowSetPriority(lua_State* L) { int ModalWindowFunctions::luaModalWindowSendToPlayer(lua_State* L) { // modalWindow:sendToPlayer(player) - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); if (!player) { - lua_pushnil(L); + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index a0f02631a1c..61567b1e1f0 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -289,12 +289,12 @@ int NetworkMessageFunctions::luaNetworkMessageSendToPlayer(lua_State* L) { } const auto &player = getPlayer(L, 2); - if (player) { - player->sendNetworkMessage(*message); - pushBoolean(L, true); - } else { + if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - lua_pushnil(L); + return 1; } + + player->sendNetworkMessage(*message); + pushBoolean(L, true); return 1; } diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index e0ae3c2bfaf..d6e63a5d52b 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -347,7 +347,7 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { return 1; } - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -360,7 +360,7 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { int NpcFunctions::luaNpcCloseShopWindow(lua_State* L) { // npc:closeShopWindow(player) - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -452,7 +452,13 @@ int NpcFunctions::luaNpcFollow(lua_State* L) { return 1; } - pushBoolean(L, npc->setFollowCreature(getPlayer(L, 2))); + auto player = getPlayer(L, 2); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + + pushBoolean(L, npc->setFollowCreature(player)); return 1; } @@ -478,7 +484,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { return 1; } - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index 6b5872d836e..a5f0e201b54 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -69,7 +69,12 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { int PartyFunctions::luaPartySetLeader(lua_State* L) { // party:setLeader(player) - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->passPartyLeadership(player)); @@ -139,7 +144,12 @@ int PartyFunctions::luaPartyGetInviteeCount(lua_State* L) { int PartyFunctions::luaPartyAddInvite(lua_State* L) { // party:addInvite(player) - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->invitePlayer(player)); @@ -151,7 +161,12 @@ int PartyFunctions::luaPartyAddInvite(lua_State* L) { int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { // party:removeInvite(player) - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->removeInvite(player)); @@ -163,7 +178,12 @@ int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { int PartyFunctions::luaPartyAddMember(lua_State* L) { // party:addMember(player) - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->joinParty(player)); @@ -175,7 +195,12 @@ int PartyFunctions::luaPartyAddMember(lua_State* L) { int PartyFunctions::luaPartyRemoveMember(lua_State* L) { // party:removeMember(player) - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + std::shared_ptr party = getUserdataShared(L, 1); if (party && player) { pushBoolean(L, party->leaveParty(player)); diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index f328f3369ef..3636f2f90e1 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -983,16 +983,17 @@ int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerSetMaxMana(lua_State* L) { // player:setMaxMana(maxMana) - std::shared_ptr player = getPlayer(L, 1); - if (player) { - player->manaMax = getNumber(L, 2); - player->mana = std::min(player->mana, player->manaMax); - g_game().addPlayerMana(player); - player->sendStats(); - pushBoolean(L, true); - } else { - lua_pushnil(L); + auto player = getPlayer(L, 1); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; } + + player->manaMax = getNumber(L, 2); + player->mana = std::min(player->mana, player->manaMax); + g_game().addPlayerMana(player); + player->sendStats(); + pushBoolean(L, true); return 1; } diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index e576b160323..f7ef82b5b70 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -368,7 +368,12 @@ int HouseFunctions::luaHouseCanEditAccessList(lua_State* L) { } uint32_t listId = getNumber(L, 2); - std::shared_ptr player = getPlayer(L, 3); + + auto player = getPlayer(L, 3); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } pushBoolean(L, house->canEditAccessList(listId, player)); return 1; @@ -415,7 +420,19 @@ int HouseFunctions::luaHouseKickPlayer(lua_State* L) { return 1; } - pushBoolean(L, house->kickPlayer(getPlayer(L, 2), getPlayer(L, 3))); + auto player = getPlayer(L, 2); + if (!player ) { + reportErrorFunc("Player is nullptr"); + return 1; + } + + auto targetPlayer = getPlayer(L, 3); + if (!targetPlayer) { + reportErrorFunc("Target player is nullptr"); + return 1; + } + + pushBoolean(L, house->kickPlayer(player, targetPlayer)); return 1; } @@ -427,9 +444,9 @@ int HouseFunctions::luaHouseIsInvited(lua_State* L) { return 1; } - std::shared_ptr player = getPlayer(L, 2); + auto player = getPlayer(L, 2); if (!player) { - lua_pushnil(L); + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } diff --git a/src/lua/functions/map/position_functions.cpp b/src/lua/functions/map/position_functions.cpp index f2d5b0e2873..b68d8501588 100644 --- a/src/lua/functions/map/position_functions.cpp +++ b/src/lua/functions/map/position_functions.cpp @@ -150,9 +150,13 @@ int PositionFunctions::luaPositionSendMagicEffect(lua_State* L) { // position:sendMagicEffect(magicEffect[, player = nullptr]) CreatureVector spectators; if (lua_gettop(L) >= 3) { - if (const auto &player = getPlayer(L, 3)) { - spectators.emplace_back(player); + const auto &player = getPlayer(L, 3); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; } + + spectators.emplace_back(player); } MagicEffectClasses magicEffect = getNumber(L, 2); @@ -177,9 +181,13 @@ int PositionFunctions::luaPositionRemoveMagicEffect(lua_State* L) { // position:removeMagicEffect(magicEffect[, player = nullptr]) CreatureVector spectators; if (lua_gettop(L) >= 3) { - if (const auto &player = getPlayer(L, 3)) { - spectators.emplace_back(player); + const auto &player = getPlayer(L, 3); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; } + + spectators.emplace_back(player); } MagicEffectClasses magicEffect = getNumber(L, 2); @@ -204,9 +212,13 @@ int PositionFunctions::luaPositionSendDistanceEffect(lua_State* L) { // position:sendDistanceEffect(positionEx, distanceEffect[, player = nullptr]) CreatureVector spectators; if (lua_gettop(L) >= 4) { - if (const auto &player = getPlayer(L, 4)) { - spectators.emplace_back(player); + const auto &player = getPlayer(L, 4); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; } + + spectators.emplace_back(player); } ShootType_t distanceEffect = getNumber(L, 3); From 12c90c60b4322c65f8bf8ef37c9e751edfe46016 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 25 Nov 2023 09:33:07 +0000 Subject: [PATCH 2/4] Code format - (Clang-format) --- src/lua/functions/map/house_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index f7ef82b5b70..51b3312b39c 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -421,7 +421,7 @@ int HouseFunctions::luaHouseKickPlayer(lua_State* L) { } auto player = getPlayer(L, 2); - if (!player ) { + if (!player) { reportErrorFunc("Player is nullptr"); return 1; } From fdff9bbdc2c69dfa3a6ea5253342b3b035558962 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sat, 25 Nov 2023 06:54:14 -0300 Subject: [PATCH 3/4] fix: revert --- src/lua/functions/core/game/bank_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index dd561c47a5a..a69db6e5558 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -125,8 +125,8 @@ int BankFunctions::luaBankDeposit(lua_State* L) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto bank = std::make_shared(player); + uint64_t amount = 0; if (lua_isnumber(L, 2)) { amount = getNumber(L, 2); From 5b9a55948e24d35c8b911f59959f971cc20e40dc Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Mon, 27 Nov 2023 23:39:36 -0300 Subject: [PATCH 4/4] fix: add const auto& --- src/lua/functions/core/game/bank_functions.cpp | 8 ++------ .../functions/core/game/modal_window_functions.cpp | 2 +- src/lua/functions/creatures/npc/npc_functions.cpp | 8 ++++---- .../functions/creatures/player/party_functions.cpp | 12 ++++++------ .../functions/creatures/player/player_functions.cpp | 2 +- src/lua/functions/map/house_functions.cpp | 6 +++--- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index a69db6e5558..f6732b8bf70 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -93,7 +93,7 @@ int BankFunctions::luaBankTransferToGuild(lua_State* L) { int BankFunctions::luaBankWithdraw(lua_State* L) { // Bank.withdraw(player, amount[, source = player]) - auto player = getPlayer(L, 1); + const auto &player = getPlayer(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; @@ -101,10 +101,6 @@ int BankFunctions::luaBankWithdraw(lua_State* L) { uint64_t amount = getNumber(L, 2); if (lua_gettop(L) == 2) { - if (!player) { - return 1; - } - const auto bank = std::make_shared(player); pushBoolean(L, bank->withdraw(player, amount)); return 1; @@ -120,7 +116,7 @@ int BankFunctions::luaBankWithdraw(lua_State* L) { int BankFunctions::luaBankDeposit(lua_State* L) { // Bank.deposit(player, amount[, destination = player]) - auto player = getPlayer(L, 1); + const auto &player = getPlayer(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; diff --git a/src/lua/functions/core/game/modal_window_functions.cpp b/src/lua/functions/core/game/modal_window_functions.cpp index b775bdda6b6..ee2cb7bd89f 100644 --- a/src/lua/functions/core/game/modal_window_functions.cpp +++ b/src/lua/functions/core/game/modal_window_functions.cpp @@ -204,7 +204,7 @@ int ModalWindowFunctions::luaModalWindowSetPriority(lua_State* L) { int ModalWindowFunctions::luaModalWindowSendToPlayer(lua_State* L) { // modalWindow:sendToPlayer(player) - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index d6e63a5d52b..d24ed978ac8 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -347,7 +347,7 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { return 1; } - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -360,7 +360,7 @@ int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { int NpcFunctions::luaNpcCloseShopWindow(lua_State* L) { // npc:closeShopWindow(player) - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); @@ -452,7 +452,7 @@ int NpcFunctions::luaNpcFollow(lua_State* L) { return 1; } - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; @@ -484,7 +484,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { return 1; } - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); pushBoolean(L, false); diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index a5f0e201b54..e16499870a6 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -69,14 +69,14 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { int PartyFunctions::luaPartySetLeader(lua_State* L) { // party:setLeader(player) - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } std::shared_ptr party = getUserdataShared(L, 1); - if (party && player) { + if (party) { pushBoolean(L, party->passPartyLeadership(player)); } else { lua_pushnil(L); @@ -144,7 +144,7 @@ int PartyFunctions::luaPartyGetInviteeCount(lua_State* L) { int PartyFunctions::luaPartyAddInvite(lua_State* L) { // party:addInvite(player) - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; @@ -161,7 +161,7 @@ int PartyFunctions::luaPartyAddInvite(lua_State* L) { int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { // party:removeInvite(player) - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; @@ -178,7 +178,7 @@ int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { int PartyFunctions::luaPartyAddMember(lua_State* L) { // party:addMember(player) - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; @@ -195,7 +195,7 @@ int PartyFunctions::luaPartyAddMember(lua_State* L) { int PartyFunctions::luaPartyRemoveMember(lua_State* L) { // party:removeMember(player) - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 3636f2f90e1..5b646264d95 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -983,7 +983,7 @@ int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerSetMaxMana(lua_State* L) { // player:setMaxMana(maxMana) - auto player = getPlayer(L, 1); + const auto &player = getPlayer(L, 1); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index 51b3312b39c..834382ae432 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -369,7 +369,7 @@ int HouseFunctions::luaHouseCanEditAccessList(lua_State* L) { uint32_t listId = getNumber(L, 2); - auto player = getPlayer(L, 3); + const auto &player = getPlayer(L, 3); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; @@ -420,7 +420,7 @@ int HouseFunctions::luaHouseKickPlayer(lua_State* L) { return 1; } - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc("Player is nullptr"); return 1; @@ -444,7 +444,7 @@ int HouseFunctions::luaHouseIsInvited(lua_State* L) { return 1; } - auto player = getPlayer(L, 2); + const auto &player = getPlayer(L, 2); if (!player) { reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1;