It seems #bot delete fails if the bot has pets because the BotDelete function in bots.cpp does not delete the foreign keys relationships related to BotPets, BotPetBuffs, and BotPetInventories.
I fixed this:
Code:
Index: bot.cpp
===================================================================
--- bot.cpp (revision 2506)
+++ bot.cpp (working copy)
@@ -4249,6 +4250,8 @@
if(this->GetBotID() > 0) {
char* Query = 0;
char TempErrorMessageBuffer[MYSQL_ERRMSG_SIZE];
+ MYSQL_RES* DatasetResult;
+ MYSQL_ROW DataRow;
// TODO: These queries need to be ran together as a transaction.. ie, if one or more fail then they all will fail to commit to the database.
@@ -4258,6 +4261,31 @@
else
TempCounter++;
+ uint32 pet_id;
+ if(database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT BotPetsId FROM botpets WHERE BotId = '%u'", this->GetBotID()), TempErrorMessageBuffer, &DatasetResult)) {
+ while(DataRow = mysql_fetch_row(DatasetResult)) {
+ pet_id= atoi(DataRow[0]);
+ }
+ }
+
+ if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM botpetinventory WHERE BotPetsId = '%u'", pet_id), TempErrorMessageBuffer)) {
+ *errorMessage = std::string(TempErrorMessageBuffer);
+ }
+ else
+ TempCounter++;
+
+ if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM botpetbuffs WHERE BotPetsId = '%u'", pet_id), TempErrorMessageBuffer)) {
+ *errorMessage = std::string(TempErrorMessageBuffer);
+ }
+ else
+ TempCounter++;
+
+ if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM botpets WHERE BotId = '%u'", this->GetBotID()), TempErrorMessageBuffer)) {
+ *errorMessage = std::string(TempErrorMessageBuffer);
+ }
+ else
+ TempCounter++;
+
if(!database.RunQuery(Query, MakeAnyLenString(&Query, "DELETE FROM botbuffs WHERE botid = '%u'", this->GetBotID()), TempErrorMessageBuffer)) {
*errorMessage = std::string(TempErrorMessageBuffer);
}
@@ -4276,7 +4304,7 @@
else
TempCounter++;
- if(TempCounter == 4)
+ if(TempCounter == 7)
Result = true;
}