[Bug Fix] Fix Bot Creation Issue (#4235)

# Notes
- Creating bots was failing because were checking for `false` on `Database::CheckUsedName()` in `BotDatabase::QueryNameAvailability`.
- `Database::CheckUsedName()` is now `Database::IsNameUsed()` and checks for both bots and character name usages.
- We were checking for `false` which was always happening when there were no entries for the supplied name, meaning we were never allowed to create a bot.
This commit is contained in:
Alex King
2024-04-02 02:12:08 -04:00
committed by GitHub
parent d7a8fb8691
commit dc48c45421
6 changed files with 27 additions and 34 deletions
+20 -3
View File
@@ -74,6 +74,7 @@
#include "repositories/zone_repository.h"
#include "zone_store.h"
#include "repositories/merchantlist_temp_repository.h"
#include "repositories/bot_data_repository.h"
extern Client client;
@@ -915,15 +916,31 @@ bool Database::UpdateName(const std::string& old_name, const std::string& new_na
return CharacterDataRepository::UpdateOne(*this, e);
}
bool Database::CheckUsedName(const std::string& name)
bool Database::IsNameUsed(const std::string& name)
{
return !CharacterDataRepository::GetWhere(
if (RuleB(Bots, Enabled)) {
const auto& bot_data = BotDataRepository::GetWhere(
*this,
fmt::format(
"`name` = '{}'",
Strings::Escape(name)
)
);
if (!bot_data.empty()) {
return true;
}
}
const auto& character_data = CharacterDataRepository::GetWhere(
*this,
fmt::format(
"`name` = '{}'",
Strings::Escape(name)
)
).empty();
);
return !character_data.empty();
}
uint32 Database::GetServerType()