From eb51550109767dfee3d5612fc7095d84b4a19f74 Mon Sep 17 00:00:00 2001 From: Aeadoin <109764533+Aeadoin@users.noreply.github.com> Date: Sat, 25 Mar 2023 20:32:30 -0400 Subject: [PATCH] [Cleanup] Cleanup Strings::ToInt uses. (#3142) * [Cleanup] Cleanup Strings::ToInt uses. * fix for conversion * remove != 0 * cleanup --- common/database.cpp | 2 +- common/database_conversions.cpp | 6 +++--- common/events/player_events.h | 2 +- common/shareddb.cpp | 8 ++++---- loginserver/database.cpp | 10 +++++----- zone/aa.cpp | 20 ++++++++++---------- zone/aa_ability.h | 2 +- zone/aa_rank.h | 2 +- zone/aa_rank_effects.h | 2 +- zone/bot.cpp | 4 ++-- zone/zoning.cpp | 2 +- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/common/database.cpp b/common/database.cpp index a25667995f..43854172cc 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -812,7 +812,7 @@ uint32 Database::GetAccountIDByChar(const char* charname, uint32* oCharID) { auto row = results.begin(); - uint32 accountId = Strings::ToInt(row[0]); + uint32 accountId = Strings::ToUnsignedInt(row[0]); if (oCharID) *oCharID = Strings::ToUnsignedInt(row[1]); diff --git a/common/database_conversions.cpp b/common/database_conversions.cpp index d78e43fff8..69c432f996 100644 --- a/common/database_conversions.cpp +++ b/common/database_conversions.cpp @@ -499,7 +499,7 @@ bool Database::CheckDatabaseConvertPPDeblob(){ ExtendedProfile_Struct* e_pp; uint32 pplen = 0; uint32 i; - int character_id = 0; + uint32 character_id = 0; int account_id = 0; int number_of_characters = 0; int printppdebug = 0; /* Prints Player Profile */ @@ -929,12 +929,12 @@ bool Database::CheckDatabaseConvertPPDeblob(){ for (auto row = results.begin(); row != results.end(); ++row) { char_iter_count++; - squery = StringFormat("SELECT `id`, `profile`, `name`, `level`, `account_id`, `firstlogon`, `lfg`, `lfp`, `mailkey`, `xtargets`, `inspectmessage`, `extprofile` FROM `character_` WHERE `id` = %i", Strings::ToInt(row[0])); + squery = StringFormat("SELECT `id`, `profile`, `name`, `level`, `account_id`, `firstlogon`, `lfg`, `lfp`, `mailkey`, `xtargets`, `inspectmessage`, `extprofile` FROM `character_` WHERE `id` = %i", Strings::ToUnsignedInt(row[0])); auto results2 = QueryDatabase(squery); auto row2 = results2.begin(); pp = (Convert::PlayerProfile_Struct*)row2[1]; e_pp = (ExtendedProfile_Struct*)row2[11]; - character_id = Strings::ToInt(row[0]); + character_id = Strings::ToUnsignedInt(row[0]); account_id = Strings::ToInt(row2[4]); /* Convert some data from the character_ table that is still relevant */ firstlogon = Strings::ToUnsignedInt(row2[5]); diff --git a/common/events/player_events.h b/common/events/player_events.h index c87872e880..bec940473e 100644 --- a/common/events/player_events.h +++ b/common/events/player_events.h @@ -384,7 +384,7 @@ namespace PlayerEvent { }; struct AAPurchasedEvent { - int32 aa_id; + uint32 aa_id; int32 aa_cost; int32 aa_previous_id; int32 aa_next_id; diff --git a/common/shareddb.cpp b/common/shareddb.cpp index 75448e1fcd..a225010096 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -964,10 +964,10 @@ void SharedDatabase::LoadItems(void *data, uint32 size, int32 items, uint32 max_ // Flags item.ArtifactFlag = Strings::ToBool(row[ItemField::artifactflag]); - item.Attuneable = !disable_attuneable && Strings::ToInt(row[ItemField::attuneable]) != 0; - item.BenefitFlag = Strings::ToBool(row[ItemField::benefitflag]) != 0; - item.FVNoDrop = Strings::ToInt(row[ItemField::fvnodrop]) != 0; - item.Magic = Strings::ToBool(row[ItemField::magic]) != 0; + item.Attuneable = !disable_attuneable && Strings::ToBool(row[ItemField::attuneable]); + item.BenefitFlag = Strings::ToBool(row[ItemField::benefitflag]); + item.FVNoDrop = Strings::ToBool(row[ItemField::fvnodrop]); + item.Magic = Strings::ToBool(row[ItemField::magic]); item.NoDrop = disable_no_drop ? static_cast(255) : static_cast(Strings::ToUnsignedInt(row[ItemField::nodrop])); item.NoPet = !disable_no_pet && Strings::ToBool(row[ItemField::nopet]); item.NoRent = disable_no_rent ? static_cast(255) : static_cast(Strings::ToUnsignedInt(row[ItemField::norent])); diff --git a/loginserver/database.cpp b/loginserver/database.cpp index 08c5855a3e..d388211af9 100644 --- a/loginserver/database.cpp +++ b/loginserver/database.cpp @@ -32,7 +32,7 @@ Database::Database( user.c_str(), pass.c_str(), name.c_str(), - Strings::ToInt(port), + Strings::ToUnsignedInt(port), &errnum, errbuf ) @@ -93,7 +93,7 @@ bool Database::GetLoginDataFromAccountInfo( auto row = results.begin(); - id = Strings::ToInt(row[0]); + id = Strings::ToUnsignedInt(row[0]); password = row[1]; LogDebug( @@ -145,7 +145,7 @@ bool Database::GetLoginTokenDataFromToken( } if (strcmp(row[2], "login_server_id") == 0) { - db_account_id = Strings::ToInt(row[3]); + db_account_id = Strings::ToUnsignedInt(row[3]); found_login_id = true; continue; } @@ -373,7 +373,7 @@ Database::DbWorldRegistration Database::GetWorldRegistration( r.server_list_type = Strings::ToInt(row[3]); r.is_server_trusted = Strings::ToInt(row[2]) > 0; r.server_list_description = row[4]; - r.server_admin_id = Strings::ToInt(row[5]); + r.server_admin_id = Strings::ToUnsignedInt(row[5]); if (r.server_admin_id <= 0) { return r; @@ -513,7 +513,7 @@ bool Database::CreateWorldRegistration( auto row = results.begin(); - id = Strings::ToInt(row[0]); + id = Strings::ToUnsignedInt(row[0]); auto insert_query = fmt::format( "INSERT INTO login_world_servers SET id = {0}, long_name = '{1}', short_name = '{2}', last_ip_address = '{3}', \n" "login_server_list_type_id = 3, login_server_admin_id = {4}, is_server_trusted = 0, tag_description = ''", diff --git a/zone/aa.cpp b/zone/aa.cpp index 66b5f7b0f9..f147c78ed5 100644 --- a/zone/aa.cpp +++ b/zone/aa.cpp @@ -1448,9 +1448,9 @@ bool ZoneDatabase::LoadAlternateAdvancement(Client *c) { int i = 0; for(auto row = results.begin(); row != results.end(); ++row) { - uint32 aa = Strings::ToInt(row[0]); - uint32 value = Strings::ToInt(row[1]); - uint32 charges = Strings::ToInt(row[2]); + uint32 aa = Strings::ToUnsignedInt(row[0]); + uint32 value = Strings::ToUnsignedInt(row[1]); + uint32 charges = Strings::ToUnsignedInt(row[2]); auto rank = zone->GetAlternateAdvancementRank(aa); if(!rank) { @@ -1775,7 +1775,7 @@ bool ZoneDatabase::LoadAlternateAdvancementAbilities(std::unordered_mapid = Strings::ToInt(row[0]); + ability->id = Strings::ToUnsignedInt(row[0]); ability->name = row[1]; ability->category = Strings::ToInt(row[2]); //EQ client has classes left shifted by one bit for some odd reason @@ -1786,8 +1786,8 @@ bool ZoneDatabase::LoadAlternateAdvancementAbilities(std::unordered_mapstatus = Strings::ToInt(row[7]); ability->type = Strings::ToInt(row[8]); ability->charges = Strings::ToInt(row[9]); - ability->grant_only = Strings::ToInt(row[10]) != 0 ? true : false; - ability->reset_on_death = Strings::ToInt(row[11]) != 0 ? true : false; + ability->grant_only = Strings::ToBool(row[10]); + ability->reset_on_death = Strings::ToBool(row[11]); ability->first_rank_id = Strings::ToInt(row[12]); ability->first = nullptr; @@ -1814,7 +1814,7 @@ bool ZoneDatabase::LoadAlternateAdvancementAbilities(std::unordered_mapid = Strings::ToInt(row[0]); + rank->id = Strings::ToUnsignedInt(row[0]); rank->upper_hotkey_sid = Strings::ToInt(row[1]); rank->lower_hotkey_sid = Strings::ToInt(row[2]); rank->title_sid = Strings::ToInt(row[3]); @@ -1846,8 +1846,8 @@ bool ZoneDatabase::LoadAlternateAdvancementAbilities(std::unordered_mapIDFile) > 2) - ns->spawn.equipment.Primary.Material = Strings::ToInt(&item->IDFile[2]); + ns->spawn.equipment.Primary.Material = Strings::ToUnsignedInt(&item->IDFile[2]); ns->spawn.equipment_tint.Primary.Color = GetEquipmentColor(EQ::textures::weaponPrimary); @@ -3475,7 +3475,7 @@ void Bot::FillSpawnStruct(NewSpawn_Struct* ns, Mob* ForWho) { if(item) { if(strlen(item->IDFile) > 2) - ns->spawn.equipment.Secondary.Material = Strings::ToInt(&item->IDFile[2]); + ns->spawn.equipment.Secondary.Material = Strings::ToUnsignedInt(&item->IDFile[2]); ns->spawn.equipment_tint.Secondary.Color = GetEquipmentColor(EQ::textures::weaponSecondary); } diff --git a/zone/zoning.cpp b/zone/zoning.cpp index 560e35758e..3a41ecb1dc 100644 --- a/zone/zoning.cpp +++ b/zone/zoning.cpp @@ -1262,7 +1262,7 @@ bool Client::CanEnterZone(const std::string& zone_short_name, int16 instance_ver return false; } - if (!z->flag_needed.empty() && Strings::IsNumber(z->flag_needed) && Strings::ToInt(z->flag_needed) == 1) { + if (!z->flag_needed.empty() && Strings::IsNumber(z->flag_needed) && Strings::ToBool(z->flag_needed)) { if (Admin() < minStatusToIgnoreZoneFlags && !HasZoneFlag(z->zoneidnumber)) { LogInfo( "Character [{}] does not have the flag to be in this zone [{}]!",