mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-17 03:08:26 +00:00
[Bots] Remove Bot Groups Functionality (#3165)
* [Bots] Remove Bot Groups Functionality * in-class initializers for member variables.
This commit is contained in:
+1
-517
@@ -2204,523 +2204,6 @@ bool BotDatabase::SaveOwnerOption(const uint32 owner_id, const std::pair<size_t,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Bot bot-group functions */
|
||||
bool BotDatabase::QueryBotGroupExistence(const std::string& group_name)
|
||||
{
|
||||
if (group_name.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT `group_name` FROM `bot_groups` WHERE `group_name` = '{}' LIMIT 1",
|
||||
group_name
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadBotGroupIDByBotGroupName(const std::string& group_name, uint32& botgroup_id)
|
||||
{
|
||||
if (group_name.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT `groups_index` FROM `bot_groups` WHERE `group_name` = '{}' LIMIT 1",
|
||||
Strings::Escape(group_name)
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
botgroup_id = Strings::ToUnsignedInt(row[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadBotGroupIDByLeaderID(const uint32 leader_id, uint32& botgroup_id)
|
||||
{
|
||||
if (!leader_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT `groups_index` FROM `bot_groups` WHERE `group_leader_id` = {} LIMIT 1",
|
||||
leader_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
botgroup_id = Strings::ToUnsignedInt(row[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadBotGroupIDByMemberID(const uint32 member_id, uint32& botgroup_id)
|
||||
{
|
||||
if (!member_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT `groups_index` FROM `bot_group_members` WHERE `bot_id` = {} LIMIT 1",
|
||||
member_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
botgroup_id = Strings::ToUnsignedInt(row[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadLeaderIDByBotGroupName(const std::string& group_name, uint32& leader_id)
|
||||
{
|
||||
if (group_name.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT `group_leader_id` FROM `bot_groups` WHERE `group_name` = '{}' LIMIT 1",
|
||||
group_name
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
leader_id = Strings::ToUnsignedInt(row[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadLeaderIDByBotGroupID(const uint32 group_id, uint32& leader_id)
|
||||
{
|
||||
if (!group_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT `group_leader_id` FROM `bot_groups` WHERE `groups_index` = {} LIMIT 1",
|
||||
group_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
leader_id = Strings::ToUnsignedInt(row[0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadBotGroupNameByBotGroupID(const uint32 group_id, std::string& botgroup_name)
|
||||
{
|
||||
if (!group_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT `group_name` FROM `bot_groups` WHERE `groups_index` = {} LIMIT 1",
|
||||
group_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
botgroup_name = row[0];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadBotGroupNameByLeaderID(const uint32 leader_id, std::string& botgroup_name)
|
||||
{
|
||||
if (!leader_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT `group_name` FROM `bot_groups` WHERE `group_leader_id` = {} LIMIT 1",
|
||||
leader_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
botgroup_name = row[0];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::CreateBotGroup(const std::string& group_name, const uint32 leader_id)
|
||||
{
|
||||
if (group_name.empty() || !leader_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (QueryBotGroupExistence(group_name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"INSERT INTO `bot_groups` (`group_leader_id`, `group_name`) VALUES ({}, '{}')",
|
||||
leader_id,
|
||||
group_name
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
DeleteBotGroup(leader_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto botgroup_id = results.LastInsertedID();
|
||||
if (!botgroup_id) {
|
||||
DeleteBotGroup(leader_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"INSERT INTO `bot_group_members` (`groups_index`, `bot_id`) VALUES ({}, {})",
|
||||
botgroup_id,
|
||||
leader_id
|
||||
);
|
||||
|
||||
results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
RemoveMemberFromBotGroup(leader_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::DeleteBotGroup(const uint32 leader_id)
|
||||
{
|
||||
if (!leader_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 botgroup_id = 0;
|
||||
if (!LoadBotGroupIDByLeaderID(leader_id, botgroup_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!botgroup_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"DELETE FROM `bot_group_members` WHERE `groups_index` = {}",
|
||||
botgroup_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success() || !results.RowsAffected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"DELETE FROM `bot_groups` WHERE `groups_index` = {}",
|
||||
botgroup_id
|
||||
);
|
||||
|
||||
results = database.QueryDatabase(query);
|
||||
if (!results.Success() || !results.RowsAffected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::AddMemberToBotGroup(const uint32 leader_id, const uint32 member_id)
|
||||
{
|
||||
if (!leader_id || !member_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 botgroup_id = 0;
|
||||
if (!LoadBotGroupIDByLeaderID(leader_id, botgroup_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!botgroup_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"INSERT INTO `bot_group_members` (`groups_index`, `bot_id`) VALUES ({}, {})",
|
||||
botgroup_id,
|
||||
member_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
RemoveMemberFromBotGroup(member_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::RemoveMemberFromBotGroup(const uint32 member_id)
|
||||
{
|
||||
if (!member_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 botgroup_id = 0;
|
||||
if (!LoadBotGroupIDByLeaderID(member_id, botgroup_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (botgroup_id) {
|
||||
return DeleteBotGroup(member_id);
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"DELETE FROM `bot_group_members` WHERE `bot_id` = {}",
|
||||
member_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadBotGroupIDForLoadBotGroup(const uint32 owner_id, std::string_view group_name, uint32& botgroup_id)
|
||||
{
|
||||
if (!owner_id || group_name.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT bg.groups_index, group_name FROM "
|
||||
"bot_groups bg INNER JOIN bot_group_members bgm "
|
||||
"ON bg.groups_index = bgm.groups_index "
|
||||
"WHERE bgm.bot_id IN "
|
||||
"(SELECT bot_id FROM bot_data WHERE owner_id = {})",
|
||||
owner_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto row : results) {
|
||||
if (!group_name.compare(row[1])) {
|
||||
botgroup_id = Strings::ToUnsignedInt(row[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadBotGroup(const std::string& group_name, std::map<uint32, std::list<uint32>>& member_list)
|
||||
{
|
||||
if (group_name.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 botgroup_id = 0;
|
||||
if (!LoadBotGroupIDByBotGroupName(group_name, botgroup_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!botgroup_id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT `bot_id` FROM `bot_group_members` WHERE `groups_index` = {} LIMIT 6",
|
||||
botgroup_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto row : results) {
|
||||
member_list[botgroup_id].push_back(Strings::ToUnsignedInt(row[0]));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadBotGroupsListByOwnerID(const uint32 owner_id, std::list<std::pair<std::string, uint32>>& botgroups_list)
|
||||
{
|
||||
if (!owner_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT DISTINCT(group_name), group_leader_id FROM "
|
||||
"bot_groups bg INNER JOIN bot_group_members bgm "
|
||||
"ON bg.groups_index = bgm.groups_index "
|
||||
"WHERE bgm.bot_id IN "
|
||||
"(SELECT bot_id FROM bot_data WHERE owner_id = {})",
|
||||
owner_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto row : results) {
|
||||
botgroups_list.push_back(std::pair<std::string, uint32>(row[0], Strings::ToUnsignedInt(row[1])));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::IsBotGroupAutoSpawn(const std::string& botgroup_name)
|
||||
{
|
||||
if (botgroup_name.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"SELECT group_name FROM bot_groups WHERE group_name = '{}' AND auto_spawn = 1",
|
||||
botgroup_name
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.RowCount() || !results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::ToggleBotGroupAutoSpawn(const uint32 group_id)
|
||||
{
|
||||
if (!group_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
"UPDATE bot_groups SET auto_spawn = 1 - auto_spawn WHERE groups_index = {}",
|
||||
group_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success() || !results.RowsAffected()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BotDatabase::LoadAutoSpawnBotGroupsByOwnerID(const uint32 owner_id, std::list<std::pair<uint32,std::string>>& group_list)
|
||||
{
|
||||
if (!owner_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
query = fmt::format(
|
||||
SQL(
|
||||
SELECT group_leader_id, group_name FROM bot_groups WHERE groups_index IN (
|
||||
SELECT groups_index FROM bot_group_members WHERE bot_id IN (
|
||||
SELECT bot_id FROM bot_data WHERE owner_id = {}
|
||||
)
|
||||
) AND auto_spawn = 1
|
||||
),
|
||||
owner_id
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!results.RowCount()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto row : results) {
|
||||
group_list.push_back(
|
||||
std::pair<uint32,std::string>(Strings::ToUnsignedInt(row[0]), row[1])
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Bot owner group functions */
|
||||
// added owner ID to this function to fix groups with mulitple players grouped with bots.
|
||||
bool BotDatabase::LoadGroupedBotsByGroupID(const uint32 owner_id, const uint32 group_id, std::list<uint32>& group_list)
|
||||
@@ -3238,3 +2721,4 @@ const char* BotDatabase::fail::DeleteAllHealRotations() { return "Failed to dele
|
||||
|
||||
/* fail::Bot miscellaneous functions */
|
||||
const char* BotDatabase::fail::GetBotNameByID() { return "Failed to get bot name by bot ID"; }
|
||||
const char* BotDatabase::fail::LoadGroupedBotsByGroupID() { return "Failed to load grouped bots by group ID."; }
|
||||
|
||||
Reference in New Issue
Block a user