SaveBotGroup converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-09-03 17:43:18 -07:00
parent 6410f52c9c
commit 36325226eb

View File

@ -4681,41 +4681,43 @@ std::list<SpawnedBotsList> Bot::ListSpawnedBots(uint32 characterID, std::string*
} }
void Bot::SaveBotGroup(Group* botGroup, std::string botGroupName, std::string* errorMessage) { void Bot::SaveBotGroup(Group* botGroup, std::string botGroupName, std::string* errorMessage) {
if(botGroup && !botGroupName.empty()) { if(!botGroup || botGroupName.empty())
char errbuf[MYSQL_ERRMSG_SIZE]; return;
char *query = 0;
Mob* tempGroupLeader = botGroup->GetLeader(); Mob* tempGroupLeader = botGroup->GetLeader();
if(tempGroupLeader->IsBot()) { if(!tempGroupLeader->IsBot())
uint32 botGroupId = 0; return;
uint32 botGroupId = 0;
uint32 botGroupLeaderBotId = tempGroupLeader->CastToBot()->GetBotID(); uint32 botGroupLeaderBotId = tempGroupLeader->CastToBot()->GetBotID();
if(!database.RunQuery(query, MakeAnyLenString(&query, "INSERT into botgroup (BotGroupLeaderBotId, BotGroupName) values (%u, '%s')", botGroupLeaderBotId, botGroupName.c_str()), errbuf, 0, 0, &botGroupId)) { std::string query = StringFormat("INSERT INTO botgroup (BotGroupLeaderBotId, BotGroupName) "
*errorMessage = std::string(errbuf); "VALUES (%u, '%s')", botGroupLeaderBotId, botGroupName.c_str());
auto results = database.QueryDatabase(query);
if(!results.Success()) {
*errorMessage = std::string(results.ErrorMessage());
return;
} }
else {
if(botGroupId > 0) {
for(int counter = 0; counter < botGroup->GroupCount(); counter++) {
Mob* tempBot = botGroup->members[counter];
if(tempBot && tempBot->IsBot()) { if(botGroupId == 0)
return;
for(int groupMemberIndex = 0; groupMemberIndex < botGroup->GroupCount(); groupMemberIndex++) {
Mob* tempBot = botGroup->members[groupMemberIndex];
if(!tempBot || !tempBot->IsBot())
continue;
uint32 botGroupMemberBotId = tempBot->CastToBot()->GetBotID(); uint32 botGroupMemberBotId = tempBot->CastToBot()->GetBotID();
safe_delete_array(query); query = StringFormat("INSERT INTO botgroupmembers (BotGroupId, BotId) "
"VALUES (%u, %u)", botGroupId, botGroupMemberBotId);
if(!database.RunQuery(query, MakeAnyLenString(&query, "INSERT into botgroupmembers (BotGroupId, BotId) values (%u, %u)", botGroupId, botGroupMemberBotId), errbuf)) { results = database.QueryDatabase(query);
*errorMessage = std::string(errbuf); if(!results.Success())
} *errorMessage = std::string(results.ErrorMessage());
}
}
}
} }
safe_delete_array(query);
}
}
} }
void Bot::DeleteBotGroup(std::string botGroupName, std::string* errorMessage) { void Bot::DeleteBotGroup(std::string botGroupName, std::string* errorMessage) {