diff --git a/modules/renamer/cpp/renamer.cpp b/modules/renamer/cpp/renamer.cpp index 9c78f68b48b..3765b38d670 100644 --- a/modules/renamer/cpp/renamer.cpp +++ b/modules/renamer/cpp/renamer.cpp @@ -64,7 +64,7 @@ class RenamerModule : public CPPModule } std::string dataString; - for (auto [key, value] : zoneTable) + for (const auto& [key, value] : zoneTable) { auto entryTable = value.as(); diff --git a/src/common/lua.cpp b/src/common/lua.cpp index 121e208d5ec..645a22ac3c4 100644 --- a/src/common/lua.cpp +++ b/src/common/lua.cpp @@ -71,7 +71,7 @@ void lua_init() /** * @brief */ -std::string lua_to_string_depth(sol::object const& obj, std::size_t depth) +std::string lua_to_string_depth(const sol::object& obj, std::size_t depth) { switch (obj.get_type()) { @@ -203,7 +203,7 @@ void lua_print(sol::variadic_args va) ShowLua(lua_to_string(va).c_str()); } -std::string lua_fmt(std::string fmtStr, sol::variadic_args va) +std::string lua_fmt(const std::string& fmtStr, sol::variadic_args va) { fmt::dynamic_format_arg_store store; for (auto const& arg : va) diff --git a/src/common/lua.h b/src/common/lua.h index 5a68598d9c6..7467b1aa345 100644 --- a/src/common/lua.h +++ b/src/common/lua.h @@ -28,9 +28,9 @@ extern sol::state lua; void lua_init(); -auto lua_to_string_depth(sol::object const& obj, std::size_t depth) -> std::string; +auto lua_to_string_depth(const sol::object& obj, std::size_t depth) -> std::string; auto lua_to_string(sol::variadic_args va) -> std::string; void lua_print(sol::variadic_args va); -auto lua_fmt(std::string fmtStr, sol::variadic_args va) -> std::string; +auto lua_fmt(const std::string& fmtStr, sol::variadic_args va) -> std::string; #endif // _LUA_H diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 1c23d1ad715..2ed105b085e 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -96,11 +96,11 @@ namespace settings } // Scrape defaults into cpp's settingsMap - for (auto [outerKeyObj, outerValObj] : lua["xi"]["settings"].get()) + for (const auto& [outerKeyObj, outerValObj] : lua["xi"]["settings"].get()) { auto outerKey = outerKeyObj.as(); - for (auto [innerKeyObj, innerValObj] : outerValObj.as()) + for (const auto& [innerKeyObj, innerValObj] : outerValObj.as()) { auto innerKey = innerKeyObj.as(); auto key = to_upper(fmt::format("{}.{}", outerKey, innerKey)); @@ -161,11 +161,11 @@ namespace settings // Scrape user settings into cpp's settingsMap // This will overwrite the defaults, if user settings exist. Otherwise the // defaults will be left intact. - for (auto [outerKeyObj, outerValObj] : lua["xi"]["settings"].get()) + for (const auto& [outerKeyObj, outerValObj] : lua["xi"]["settings"].get()) { auto outerKey = outerKeyObj.as(); - for (auto [innerKeyObj, innerValObj] : outerValObj.as()) + for (const auto& [innerKeyObj, innerValObj] : outerValObj.as()) { auto innerKey = innerKeyObj.as(); auto key = to_upper(fmt::format("{}.{}", outerKey, innerKey)); @@ -210,7 +210,7 @@ namespace settings } // Push the consolidated defaults + user settings back up into xi.settings - for (auto [key, value] : settingsMap) + for (const auto& [key, value] : settingsMap) { auto parts = split(key, "."); auto outer = to_lower(parts[0]); @@ -226,7 +226,7 @@ namespace settings // lua.safe_script("require('settings/main'); require('settings/default/main'); print(xi.settings)"); } - void visit(std::function visitor) + void visit(const std::function& visitor) { for (auto& [key, value] : settingsMap) { diff --git a/src/common/settings.h b/src/common/settings.h index 8ab7c1c445f..1eb096ca234 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -169,7 +169,7 @@ namespace settings settingsMap[key] = SettingsVariant_t(value); } - void visit(std::function visitor); + void visit(const std::function& visitor); } // namespace settings #endif // _SETTINGS_H diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 8d59c3f3e8e..02075b3c100 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -373,7 +373,7 @@ using AccessControl = struct _access_control uint32 mask; }; -enum _aco +enum _aco : uint8 { ACO_DENY_ALLOW, ACO_ALLOW_DENY, diff --git a/src/common/sql.cpp b/src/common/sql.cpp index 942158f3ec8..8e625ce4641 100644 --- a/src/common/sql.cpp +++ b/src/common/sql.cpp @@ -87,6 +87,7 @@ SqlConnection::SqlConnection(const char* user, const char* passwd, const char* h // these members will be set up in SetupKeepalive(), they need to be init'd here to appease clang-tidy m_PingInterval = 0; m_LastPing = 0; + SetupKeepalive(); } diff --git a/src/common/sql.h b/src/common/sql.h index e12ba582aa2..69afea15bb5 100644 --- a/src/common/sql.h +++ b/src/common/sql.h @@ -262,7 +262,6 @@ class SqlConnection uint32 m_PingInterval; uint32 m_LastPing; - bool m_LatencyWarning; std::thread::id m_ThreadId; }; diff --git a/src/login/handler_session.cpp b/src/login/handler_session.cpp index 38ffe98d965..294c7b8c763 100644 --- a/src/login/handler_session.cpp +++ b/src/login/handler_session.cpp @@ -67,7 +67,7 @@ void handler_session::do_read() } else { - DebugSockets(fmt::format("async_read_some error in from IP {} ({}: {})", ipAddress, ec.value(), ec.message())); + DebugSockets(fmt::format("async_read_some error in handler_session from IP {} ({}: {})", ipAddress, ec.value(), ec.message())); handle_error(ec, self); } }); diff --git a/src/login/view_session.cpp b/src/login/view_session.cpp index 109c28a68c3..fd124f5d6af 100644 --- a/src/login/view_session.cpp +++ b/src/login/view_session.cpp @@ -192,7 +192,7 @@ void view_session::read_func() // Sanitize name & check for invalid characters std::string nameStr = db::escapeString(CharName); - for (auto letters : nameStr) + for (const auto& letters : nameStr) { if (!std::isalpha(letters)) { diff --git a/src/map/ability.h b/src/map/ability.h index 73c70adbff6..891cabccd1d 100644 --- a/src/map/ability.h +++ b/src/map/ability.h @@ -765,7 +765,7 @@ class CAbility std::string m_name; uint16 m_mobskillId; ACTIONTYPE m_actionType{}; - EFFECT m_cleanupEffect; + EFFECT m_cleanupEffect{}; }; /************************************************************************ diff --git a/src/map/ai/controllers/mob_controller.h b/src/map/ai/controllers/mob_controller.h index b9683f2f804..93122eb24a9 100644 --- a/src/map/ai/controllers/mob_controller.h +++ b/src/map/ai/controllers/mob_controller.h @@ -105,7 +105,7 @@ class CMobController : public CController time_point m_NeutralTime; time_point m_WaitTime; time_point m_mobHealTime; - FollowType m_followType; + FollowType m_followType = FollowType::None; bool m_firstSpell{ true }; time_point m_LastRoamScript{ time_point::min() }; diff --git a/src/map/ai/controllers/trust_controller.cpp b/src/map/ai/controllers/trust_controller.cpp index a2446fa8507..02b5a4f7d36 100644 --- a/src/map/ai/controllers/trust_controller.cpp +++ b/src/map/ai/controllers/trust_controller.cpp @@ -40,7 +40,7 @@ namespace { - enum TRUST_MOVEMENT_TYPE + enum TRUST_MOVEMENT_TYPE : int8 { // NOTE: If you need to add special movement types, add descending into the minus values. // : All of the positive values are taken for the ranged movement range. diff --git a/src/map/ai/helpers/targetfind.cpp b/src/map/ai/helpers/targetfind.cpp index f2a259906d2..fa699fb5589 100644 --- a/src/map/ai/helpers/targetfind.cpp +++ b/src/map/ai/helpers/targetfind.cpp @@ -46,6 +46,7 @@ CTargetFind::CTargetFind(CBattleEntity* PBattleEntity) , m_zone(0) , m_findType{} , m_findFlags(0) +, m_targetFlags(0) , m_conal(false) , m_scalar(0.0f) , m_APoint(nullptr) diff --git a/src/map/entities/baseentity.cpp b/src/map/entities/baseentity.cpp index 5d214e69a49..d30169c627c 100644 --- a/src/map/entities/baseentity.cpp +++ b/src/map/entities/baseentity.cpp @@ -202,7 +202,7 @@ void CBaseEntity::ResetLocalVars() m_localVars.clear(); } -uint32 CBaseEntity::GetLocalVar(std::string var) +uint32 CBaseEntity::GetLocalVar(const std::string& var) { return m_localVars[var]; } @@ -212,7 +212,7 @@ std::map& CBaseEntity::GetLocalVars() return m_localVars; } -void CBaseEntity::SetLocalVar(std::string var, uint32 val) +void CBaseEntity::SetLocalVar(const std::string& var, uint32 val) { m_localVars[var] = val; } diff --git a/src/map/entities/baseentity.h b/src/map/entities/baseentity.h index 55d41e58505..312a42252ca 100644 --- a/src/map/entities/baseentity.h +++ b/src/map/entities/baseentity.h @@ -287,8 +287,8 @@ class CBaseEntity void SendZoneUpdate(); void ResetLocalVars(); - uint32 GetLocalVar(std::string var); - void SetLocalVar(std::string var, uint32 val); + uint32 GetLocalVar(const std::string& var); + void SetLocalVar(const std::string& var, uint32 val); auto GetLocalVars() -> std::map&; // pre-tick update diff --git a/src/map/entities/charentity.h b/src/map/entities/charentity.h index c58f53c8add..84aa826f215 100644 --- a/src/map/entities/charentity.h +++ b/src/map/entities/charentity.h @@ -313,7 +313,7 @@ class CCharEntity : public CBattleEntity bool isSettingBazaarPrices; // Is setting bazaar prices (temporarily hide bazaar) bool isLinkDead; // Player is d/cing - SAVE_CONF playerConfig; // Various settings such as chat filter, display head flag, new adventurer, autotarget, etc. + SAVE_CONF playerConfig{}; // Various settings such as chat filter, display head flag, new adventurer, autotarget, etc. uint32 lastOnline{ 0 }; // UTC Unix Timestamp of the last time char zoned or logged out bool isNewPlayer() const; // Checks if new player bit is unset. diff --git a/src/map/guild.cpp b/src/map/guild.cpp index 188da167ff8..01cd09d25f6 100644 --- a/src/map/guild.cpp +++ b/src/map/guild.cpp @@ -63,8 +63,7 @@ void CGuild::updateGuildPointsPattern(uint8 pattern) { while (_sql->NextRow() == SQL_SUCCESS) { - m_GPItems[i].emplace_back( - GPItem_t(itemutils::GetItemPointer(_sql->GetUIntData(0)), _sql->GetUIntData(2), _sql->GetUIntData(1))); + m_GPItems[i].emplace_back(itemutils::GetItemPointer(_sql->GetUIntData(0)), _sql->GetUIntData(2), _sql->GetUIntData(1)); } } } diff --git a/src/map/job_points.cpp b/src/map/job_points.cpp index 979bd5b5f7b..314de2193f7 100644 --- a/src/map/job_points.cpp +++ b/src/map/job_points.cpp @@ -241,7 +241,7 @@ namespace jobpointutils break; } - currentGifts->emplace_back(CModifier(static_cast(gift.modId), gift.value)); + currentGifts->emplace_back(static_cast(gift.modId), gift.value); } PChar->addModifiers(currentGifts); diff --git a/src/map/lua/lua_baseentity.cpp b/src/map/lua/lua_baseentity.cpp index 1407cd79d43..7812de4398f 100644 --- a/src/map/lua/lua_baseentity.cpp +++ b/src/map/lua/lua_baseentity.cpp @@ -6774,7 +6774,7 @@ void CLuaBaseEntity::setMonstrosityData(sol::table table) // NOTE: This will populate m_PMonstrosity if it doesn't exist monstrosity::ReadMonstrosityData(PChar); - luautils::SetMonstrosityLuaTable(PChar, table); + luautils::SetMonstrosityLuaTable(PChar, std::move(table)); monstrosity::WriteMonstrosityData(PChar); @@ -7992,11 +7992,11 @@ void CLuaBaseEntity::triggerRoeEvent(uint8 eventNum, sol::object const& reqTable { if (kv.second.get_type() == sol::type::number) { - roeEventData.emplace_back(RoeDatagram(kv.first.as(), kv.second.as())); + roeEventData.emplace_back(kv.first.as(), kv.second.as()); } else if (kv.second.get_type() == sol::type::string) { - roeEventData.emplace_back(RoeDatagram(kv.first.as(), kv.second.as())); + roeEventData.emplace_back(kv.first.as(), kv.second.as()); } } } diff --git a/src/map/lua/luautils.cpp b/src/map/lua/luautils.cpp index a79e1ebecdd..ca4f4cffbe8 100644 --- a/src/map/lua/luautils.cpp +++ b/src/map/lua/luautils.cpp @@ -5451,7 +5451,7 @@ namespace luautils customMenuContext.erase(PChar->id); } - SendToDBoxReturnCode SendItemToDeliveryBox(std::string const& playerName, uint16 itemId, uint32 quantity, std::string senderText) + SendToDBoxReturnCode SendItemToDeliveryBox(const std::string& playerName, uint16 itemId, uint32 quantity, const std::string& senderText) { uint32 playerID = GetPlayerIDByName(playerName); if (playerID == 0) diff --git a/src/map/lua/luautils.h b/src/map/lua/luautils.h index dda123ac28c..2aeb85e8dcf 100644 --- a/src/map/lua/luautils.h +++ b/src/map/lua/luautils.h @@ -368,7 +368,7 @@ namespace luautils // Retrive the first itemId that matches a name uint16 GetItemIDByName(std::string const& name); - auto SendItemToDeliveryBox(std::string const& playerName, uint16 itemId, uint32 quantity, std::string senderText) -> SendToDBoxReturnCode; + auto SendItemToDeliveryBox(const std::string& playerName, uint16 itemId, uint32 quantity, const std::string& senderText) -> SendToDBoxReturnCode; std::optional GenerateDynamicEntity(CZone* PZone, CInstance* PInstance, sol::table table); diff --git a/src/map/monstrosity.cpp b/src/map/monstrosity.cpp index e11c32c06dd..28139470821 100644 --- a/src/map/monstrosity.cpp +++ b/src/map/monstrosity.cpp @@ -50,27 +50,27 @@ struct MonstrositySpeciesRow { - uint8 monstrosityId; - uint16 monstrositySpeciesCode; - std::string name; - JOBTYPE mjob; - JOBTYPE sjob; - uint8 size; - uint16 look; + uint8 monstrosityId{}; + uint16 monstrositySpeciesCode{}; + std::string name{}; + JOBTYPE mjob{}; + JOBTYPE sjob{}; + uint8 size{}; + uint16 look{}; }; struct MonstrosityInstinctRow { - uint16 monstrosityInstinctId; - uint8 cost; - std::string name; - std::vector mods; + uint16 monstrosityInstinctId{}; + uint8 cost{}; + std::string name{}; + std::vector mods{}; }; namespace { - std::unordered_map gMonstrositySpeciesMap; - std::unordered_map gMonstrosityInstinctMap; + std::unordered_map gMonstrositySpeciesMap{}; + std::unordered_map gMonstrosityInstinctMap{}; } // namespace monstrosity::MonstrosityData_t::MonstrosityData_t() diff --git a/src/map/packet_system.cpp b/src/map/packet_system.cpp index 79ed9479fd0..d7190ca0ab8 100644 --- a/src/map/packet_system.cpp +++ b/src/map/packet_system.cpp @@ -2393,7 +2393,7 @@ void SmallPacket0x04B(map_session_data_t* const PSession, CCharEntity* const PCh } else { - entries.push_back(FishingContestEntry()); // Safety if there is no pointer but we need to fill the vector + entries.emplace_back(FishingContestEntry{}); // Safety if there is no pointer but we need to fill the vector } } } diff --git a/src/map/packets/zone_in.cpp b/src/map/packets/zone_in.cpp index 3576db86a73..f674cd4677b 100644 --- a/src/map/packets/zone_in.cpp +++ b/src/map/packets/zone_in.cpp @@ -54,7 +54,7 @@ struct GP_SERV_POS_HEAD }; // PS2: SAVE_LOGIN_STATE -enum class SAVE_LOGIN_STATE : uint32_t +enum class SAVE_LOGIN_STATE : uint8 // Originally uint32_t, but changed to uint8 to appease Clang { SAVE_LOGIN_STATE_NONE = 0, SAVE_LOGIN_STATE_MYROOM = 1, diff --git a/src/map/spell.cpp b/src/map/spell.cpp index 5861969f36c..e43306ebbca 100644 --- a/src/map/spell.cpp +++ b/src/map/spell.cpp @@ -684,8 +684,8 @@ namespace spell return false; } - bool usable = false; - uint8 requirements; + bool usable = false; + uint8 requirements = 0; switch (PCaster->objtype) { diff --git a/src/map/utils/blueutils.cpp b/src/map/utils/blueutils.cpp index a2f74604a51..955719a4ca7 100644 --- a/src/map/utils/blueutils.cpp +++ b/src/map/utils/blueutils.cpp @@ -470,7 +470,7 @@ namespace blueutils if (add) { // Check all the eligible Blue Traits for conflicts - std::size_t j; + std::size_t j = 0; for (j = 0; j < traitsToAdd.size(); ++j) { auto iter = traitsToAdd.at(j); diff --git a/src/map/utils/charutils.cpp b/src/map/utils/charutils.cpp index ca7d2a95c0d..084e290c17d 100644 --- a/src/map/utils/charutils.cpp +++ b/src/map/utils/charutils.cpp @@ -679,7 +679,7 @@ namespace charutils PChar->profile.mhflag = rset->get("mhflag"); PChar->profile.title = rset->get("title"); - std::array bazaarMessageArray; + std::array bazaarMessageArray{}; db::extractFromBlob(rset, "bazaar_message", bazaarMessageArray); const char* bazaarMessageStr = reinterpret_cast(bazaarMessageArray.data()); if (bazaarMessageStr != nullptr) @@ -7164,7 +7164,7 @@ namespace charutils return 0; } - void forceSynthCritFail(std::string sourceFunction, CCharEntity* PChar) + void forceSynthCritFail(const std::string& sourceFunction, CCharEntity* PChar) { // NOTE: // Supposed non-losable items are reportedly lost if this condition is met: diff --git a/src/map/utils/charutils.h b/src/map/utils/charutils.h index d2b5f4bd8c8..dca32a5bd87 100644 --- a/src/map/utils/charutils.h +++ b/src/map/utils/charutils.h @@ -280,7 +280,7 @@ namespace charutils uint32 getCharIdFromName(std::string const& name); - void forceSynthCritFail(std::string sourceFunction, CCharEntity* PChar); + void forceSynthCritFail(const std::string& sourceFunction, CCharEntity* PChar); void removeCharFromZone(CCharEntity* PChar); }; // namespace charutils diff --git a/src/map/utils/instanceutils.cpp b/src/map/utils/instanceutils.cpp index 8646cee19d6..2c7afaf9b7b 100644 --- a/src/map/utils/instanceutils.cpp +++ b/src/map/utils/instanceutils.cpp @@ -119,7 +119,7 @@ namespace instanceutils void LoadInstance(uint16 instanceid, CCharEntity* PRequester) { - LoadQueue.push({ PRequester->id, instanceid }); + LoadQueue.emplace(PRequester->id, instanceid); } InstanceData_t GetInstanceData(uint16 instanceid) diff --git a/src/map/zone_entities.cpp b/src/map/zone_entities.cpp index eb8f4974e9b..c9e865bd741 100644 --- a/src/map/zone_entities.cpp +++ b/src/map/zone_entities.cpp @@ -909,7 +909,7 @@ void CZoneEntities::SpawnPCs(CCharEntity* PChar) (!spawnedCharacters.empty() && totalScore > spawnedCharacters.top().first)) { // Is nearby and should be considered as a candidate to be spawned - candidateCharacters.push(std::make_pair(totalScore, PCurrentChar)); + candidateCharacters.emplace(totalScore, PCurrentChar); if (candidateCharacters.size() > CHARACTER_SYNC_LIMIT_MAX) { candidateCharacters.pop(); @@ -1542,7 +1542,7 @@ void CZoneEntities::ZoneServer(time_point tick) it->second = nullptr; m_mobList.erase(it++); - dynamicTargIdsToDelete.emplace_back(std::make_pair(PMob->targid, server_clock::now())); + dynamicTargIdsToDelete.emplace_back(PMob->targid, server_clock::now()); destroy(PMob); continue; } @@ -1595,7 +1595,7 @@ void CZoneEntities::ZoneServer(time_point tick) } destroy(it->second); - dynamicTargIdsToDelete.emplace_back(std::make_pair(it->first, server_clock::now())); + dynamicTargIdsToDelete.emplace_back(it->first, server_clock::now()); m_npcList.erase(it++); continue; @@ -1630,7 +1630,7 @@ void CZoneEntities::ZoneServer(time_point tick) destroy(it->second); } - dynamicTargIdsToDelete.emplace_back(std::make_pair(it->first, server_clock::now())); + dynamicTargIdsToDelete.emplace_back(it->first, server_clock::now()); m_petList.erase(it++); continue; @@ -1687,7 +1687,7 @@ void CZoneEntities::ZoneServer(time_point tick) } destroy(it->second); - dynamicTargIdsToDelete.emplace_back(std::make_pair(it->first, server_clock::now())); + dynamicTargIdsToDelete.emplace_back(it->first, server_clock::now()); m_trustList.erase(it++); continue; diff --git a/src/search/search.cpp b/src/search/search.cpp index ff614ccf762..ea9e17cdbb9 100755 --- a/src/search/search.cpp +++ b/src/search/search.cpp @@ -121,7 +121,7 @@ shared_guarded> gIPAddressWhitelist; // Implement using getsockname and inet_ntop std::string socketToString(SOCKET socket) { - sockaddr_storage addr; + sockaddr_storage addr{}; socklen_t len = sizeof(addr); getsockname(socket, (sockaddr*)&addr, &len); @@ -598,7 +598,7 @@ std::string searchTypeToString(uint8 type) void TCPComm(SOCKET socket) { char clientIP[INET_ADDRSTRLEN]; - struct sockaddr_in addr; + struct sockaddr_in addr{}; socklen_t addr_len = sizeof(addr); if (getpeername(socket, (struct sockaddr*)&addr, &addr_len) == -1)