mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-28 17:37:18 +00:00
more name checks and add proper soft deletes to bots
This commit is contained in:
@@ -349,14 +349,25 @@ public:
|
||||
int bot_data_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
std::string query;
|
||||
|
||||
if (RuleB(Bots, BotSoftDeletes)) {
|
||||
query = fmt::format(
|
||||
"UPDATE {} SET name = SUBSTRING(CONCAT(name, '-deleted-', UNIX_TIMESTAMP()), 1, 64) WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
bot_data_id
|
||||
);
|
||||
}
|
||||
else {
|
||||
query = fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
bot_data_id
|
||||
)
|
||||
);
|
||||
}
|
||||
auto results = db.QueryDatabase(query);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
+11
-9
@@ -1328,25 +1328,27 @@ bool Bot::IsValidName()
|
||||
|
||||
bool Bot::IsValidName(std::string& name)
|
||||
{
|
||||
if (name.empty() || name.length() < 4 || name.length() > 15) {
|
||||
if (name.empty()) { // can't be empty
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isupper(name[0])) {
|
||||
if (islower(name[0])) { // capitalize first letter if not
|
||||
name[0] = toupper(name[0]);
|
||||
}
|
||||
|
||||
if (!EQ::ValueWithin(name.size(), 4, 15)) { // must be between 4 and 15 characters
|
||||
return false;
|
||||
}
|
||||
|
||||
for (char c : name.substr(1)) {
|
||||
if (c == '_') {
|
||||
if (std::any_of(name.begin(), name.end(), [](char c) { return c == ' ' || c == '_'; })) { // cannot contain spaces or _
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isalpha(c)) {
|
||||
if (!RuleB(Bots, AllowCamelCaseNames)) {
|
||||
for (int i = 1; i < name.size(); ++i) {
|
||||
if (isupper(name[i])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!RuleB(Bots, AllowCamelCaseNames) && !islower(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1450,11 +1452,11 @@ bool Bot::DeleteBot()
|
||||
if (!database.botdb.DeleteBotBlockedBuffs(GetBotID())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!database.botdb.DeleteBot(GetBotID())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -186,6 +186,7 @@ bool BotDatabase::QueryNameAvailablity(const std::string& bot_name, bool& availa
|
||||
if (
|
||||
bot_name.empty() ||
|
||||
bot_name.size() > 60 ||
|
||||
!database.CheckNameFilter(bot_name) ||
|
||||
database.IsNameUsed(bot_name)
|
||||
) {
|
||||
return false;
|
||||
@@ -246,6 +247,8 @@ bool BotDatabase::LoadBotsList(const uint32 owner_id, std::list<BotsAvailableLis
|
||||
SELECT `account_id` FROM `character_data` WHERE `id` = {}
|
||||
)
|
||||
)
|
||||
AND
|
||||
`name` NOT LIKE '%-deleted-%'
|
||||
),
|
||||
owner_id
|
||||
)
|
||||
@@ -272,7 +275,7 @@ bool BotDatabase::LoadBotsList(const uint32 owner_id, std::list<BotsAvailableLis
|
||||
const auto& l = BotDataRepository::GetWhere(
|
||||
database,
|
||||
fmt::format(
|
||||
"`owner_id` = {}",
|
||||
"`owner_id` = {} AND `name` NOT LIKE '%-deleted-%'",
|
||||
owner_id
|
||||
)
|
||||
);
|
||||
@@ -319,7 +322,7 @@ bool BotDatabase::LoadBotID(const std::string& bot_name, uint32& bot_id, uint8&
|
||||
const auto& l = BotDataRepository::GetWhere(
|
||||
database,
|
||||
fmt::format(
|
||||
"`name` = '{}' LIMIT 1",
|
||||
"`name` = '{}' AND `name` NOT LIKE '%-deleted-%' LIMIT 1",
|
||||
Strings::Escape(bot_name)
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user