PDA

View Full Version : 2/05 code - bots crash zone on death


Nibiuno
02-07-2015, 01:36 PM
Updated my test server to the 02/05 RoF2 code. Fixed the SQL issues and view table issue, but now the bots crash the zone on death.

Kingly_Krab
02-07-2015, 01:56 PM
Bots have always had issues, would you mind posting the crash logs if you have any?

Nibiuno
02-07-2015, 10:50 PM
edit: fixing logging and will post

The bot dies, it's removed from the group, and the zone crashes.

When the bot is respawned after you log back in, it spawns at 20%, so it is logging that it died.

Nibiuno
02-07-2015, 11:46 PM
[02-06-2015 :: 21:54:58] [Crash] f:\dd\vctools\crt_bld\SELF_X86\crt\src\INTEL\strle n.asm (69): strlen
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\mob.cpp (2856): Mob::GetCleanName
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\bot.cpp (5918): Bot::Death
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\attack.cpp (3588): Mob::CommonDamage
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\bot.cpp (6004): Bot::Damage
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\spell_effects.cpp (281): Mob::SpellEffect
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\bot.cpp (9075): Bot::SpellEffect
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\spells.cpp (3734): Mob::SpellOnTarget
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\effects.cpp (911): EntityList::AESpell
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\beacon.cpp (99): Beacon::Process
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\entity.cpp (526): EntityList::BeaconProcess
[02-06-2015 :: 21:54:58] [Crash] g:\eq2\source\zone\net.cpp (427): main
[02-06-2015 :: 21:54:58] [Crash] f:\dd\vctools\crt_bld\self_x86\crt\src\crt0.c (241): __tmainCRTStartup

Nibiuno
02-08-2015, 01:20 AM
Well, it's something in this section of bot.cpp causing it to crash. I removed it and it's not crashing anymore.

Group *g = GetGroup();
if(g) {
for(int i=0; i<MAX_GROUP_MEMBERS; i++) {
if(g->members[i]) {
if(g->members[i] == this) {
// If the leader dies, make the next bot the leader
// and reset all bots followid
if(g->IsLeader(g->members[i])) {
if(g->members[i+1]) {
g->SetLeader(g->members[i+1]);
g->members[i+1]->SetFollowID(g->members[i]->GetFollowID());
for(int j=0; j<MAX_GROUP_MEMBERS; j++) {
if(g->members[j] && (g->members[j] != g->members[i+1])) {
g->members[j]->SetFollowID(g->members[i+1]->GetID());
}
}
}
}

// delete from group data
RemoveBotFromGroup(this, g);

// if group members exist below this one, move
// them all up one slot in the group list
int j = i+1;
for(; j<MAX_GROUP_MEMBERS; j++) {
if(g->members[j]) {
g->members[j-1] = g->members[j];
strcpy(g->membername[j-1], g->members[j]->GetCleanName());
g->membername[j][0] = '\0';
memset(g->membername[j], 0, 64);
g->members[j] = nullptr;
}
}

// update the client group
EQApplicationPacket* outapp = new EQApplicationPacket(OP_GroupUpdate, sizeof(GroupJoin_Struct));
GroupJoin_Struct* gu = (GroupJoin_Struct*)outapp->pBuffer;
gu->action = groupActLeave;
strcpy(gu->membername, GetCleanName());
if(g) {
for(int k=0; k<MAX_GROUP_MEMBERS; k++) {
if(g->members[k] && g->members[k]->IsClient())
g->members[k]->CastToClient()->QueuePacket(outapp);
}
}
safe_delete(outapp);

// now that's done, lets see if all we have left is the client
// and we can clean up the clients raid group and group
/*if(GetBotRaidID()) {
BotRaids* br = entity_list.GetBotRaidByMob(this);
if(br) {
if(this == br->botmaintank) {
br->botmaintank = nullptr;
}
if(this == br->botsecondtank) {
br->botsecondtank = nullptr;
}
}
if(g->GroupCount() == 0) {
uint32 gid = g->GetID();
if(br) {
br->RemoveEmptyBotGroup();
}
entity_list.RemoveGroup(gid);
}
if(br && (br->RaidBotGroupsCount() == 1)) {
br->RemoveClientGroup(br->GetRaidBotLeader());
}
if(br && (br->RaidBotGroupsCount() == 0)) {
br->DisbandBotRaid();
}
}*/
}
}
}
}

Nibiuno
02-08-2015, 11:39 PM
They also crash the zone when disbanded, but not when you use #bot camp.

So, not that I can fix it after trying for two days, but it's something to do with the group code when you disband. Bots are crashing the zone when they are disbanded if it would disband the group - if it is just you and the bot in the group.

The zone does not crash if you disband a bot and have a merc or someone else in the group.

rencro
02-09-2015, 08:56 PM
Heres a hack to get around the crashing at dismiss of bot, also this will now dismiss single bots if you are grouped with more than one via the "disband" button, which hasnt been working for a while, although this is a bit hacky and a more permanent fix is still needed. (also introduces a new bug based on group leadership)

in client_packet.cpp in function:
void Client::Handle_OP_GroupDisband(const EQApplicationPacket *app)

at about line 6463 where the #ifdef Bots, replace the #ifdef bots with this section


#ifdef BOTS
// this block is necessary to allow more control over controlling how bots are zoned or camped.
if (Bot::GroupHasBot(group)) {
if (group->IsLeader(this)) {
Mob* tempMember = GetTarget();
if (tempMember->IsBot()) {
Bot::ProcessBotGroupDisband(this, std::string(tempMember->GetCleanName()));
return;
}
}
}
#endif


As for the crashing on bot death in a 2 person group, it is crashing on this line:

strcpy(g->membername[j-1], g->members[j]->GetCleanName());

Im still working through breakpoints and narrowing down a temp fix at least.

Nibiuno
02-09-2015, 11:01 PM
That fixed it!

Thank you so much, I suck at c++ and spent like 15 hours getting nowhere trying everything I could. My servers been crashing off and on all day due to this, going to patch it tomorrow morning.

edit: I see what you mean about a group leadership bug. It can cause people to have bots get stuck in the group. Looks like deleting the info out of group_id and group_leaders resolves it, so going to see if I can add a delete query for those tables as part of it.

Nibiuno
02-11-2015, 12:25 AM
A side effect is this sometimes causes a bot that was disbanded to rejoin after zoning, even if two other bots are out, and the bot restriction is set to 2 bots.

rencro
02-14-2015, 12:51 AM
Well, been trying to isolate exactly why memory in g->membername is being corrupted, causing groupcount to assume you have a six person group, but its slow going, have stepped through the code many times now but cant pin it down.

For now, you could put a check in place to clean up the corrupted memory and allow the rest of the function to proceed as normal, but again, we need to find out why the memory is being written with garbage during this process.

bot.cpp
bool Bot::Death(Mob *killerMob, int32 damage, uint16 spell_id, SkillUseTypes attack_skill) {
about line 5909 if you have no custom code, such as the bot melee fix, ect.

// delete from group data
RemoveBotFromGroup(this, g);

// if group members exist below this one, move
// them all up one slot in the group list
int j = i+1;
for(; j<MAX_GROUP_MEMBERS; j++) {
if(g->members[j]) {

Replace with

// delete from group data
RemoveBotFromGroup(this, g);

// if group members exist below this one, move
// them all up one slot in the group list
if(g->GroupCount() == 6) {
for(int x=0; x<MAX_GROUP_MEMBERS; x++) {
g->membername[x][0] = '\0';
memset(g->membername[x], 0, 64);
g->members[x] = nullptr;
}
}
int j = i+1;
for(; j<MAX_GROUP_MEMBERS; j++) {
if(g->members[j]) {


I tested with me(client) and 5 bots and killed each bot off one at a time with #damage 2000 and memory looks good as each bot is taken out of the group, but on the last bot, the memory at g->membername gets overwritten with garbage, leading to a crash in the strcpy phase. This little work around cleans up that memory.

I'll keep plugging away as time permits, but seems only you and me are seeing this issue which seems odd?

rencro
02-15-2015, 03:47 PM
nevermind

/10char

Nibiuno
02-15-2015, 09:05 PM
I think were probably the only two people on the new code using bots - it seems most people with bots are still on older code, so Im guessing that's why.

Im going to try your code after I patch Imperium tomorrow and Ill let you know what feedback I get later this week.

Glad youre working on it, its beyond my ability to fix.

vsab
02-16-2015, 03:27 AM
If you're fixing bots, submit pull requests on Github :)

Nibiuno
02-16-2015, 11:08 PM
Still crashing on some types of group disbands, trying to figure out what else.

Nibiuno
02-19-2015, 11:36 AM
Last bot crash issue is if you disband a bot from the group using the above fixes, then do a #bot camp on it after it's out of your group, the zone crashes.

Nibiuno
02-20-2015, 12:57 PM
Fixed the zone crash issue when if you disband a single bot, it crashes. For some reason the RemoveBotFromGroup is causing it (or this function getting the tempBot value, idk). Commenting it out still lets the bot disband, just prevents the crashing, so I have no idea what its supposed to be doing.
// Processes a group disband request from a Client for a Bot.
void Bot::ProcessBotGroupDisband(Client* c, std::string botName) {
if(c) {
Bot* tempBot = 0;

if(botName.empty())
tempBot = GetFirstBotInGroup(c->GetGroup());
else
tempBot = GetBotByBotClientOwnerAndBotName(c, botName);
// MOD ZEPHYR - stop bot disband
//RemoveBotFromGroup(tempBot, c->GetGroup());
// END MOD
}
}

rencro
02-24-2015, 01:44 PM
I dont see the #bot camp issue you are seeing, but I did notice before you had taken out big chunks of code to isolate issues, so here is my Bot::Death function completely as it is on my build from bot.cpp


bool Bot::Death(Mob *killerMob, int32 damage, uint16 spell_id, SkillUseTypes attack_skill) {
if(!NPC::Death(killerMob, damage, spell_id, attack_skill))
return false;

Save();

Mob *give_exp = hate_list.GetDamageTopOnHateList(this);
Client *give_exp_client = nullptr;

if(give_exp && give_exp->IsClient())
give_exp_client = give_exp->CastToClient();

bool IsLdonTreasure = (this->GetClass() == LDON_TREASURE);

if(entity_list.GetCorpseByID(GetID()))
entity_list.GetCorpseByID(GetID())->Depop();

Group *g = GetGroup();
if(g) {
for(int i=0; i<MAX_GROUP_MEMBERS; i++) {
if(g->members[i]) {
if(g->members[i] == this) {
// If the leader dies, make the next bot the leader
// and reset all bots followid
if(g->IsLeader(g->members[i])) {
if(g->members[i+1]) {
g->SetLeader(g->members[i+1]);
g->members[i+1]->SetFollowID(g->members[i]->GetFollowID());
for(int j=0; j<MAX_GROUP_MEMBERS; j++) {
if(g->members[j] && (g->members[j] != g->members[i+1])) {
g->members[j]->SetFollowID(g->members[i+1]->GetID());
}
}
}
}

// delete from group data
RemoveBotFromGroup(this, g);

// if group members exist below this one, move
// them all up one slot in the group list
if(g->GroupCount() == 6) {
for(int x=0; x<MAX_GROUP_MEMBERS; x++) {
g->membername[x][0] = '\0';
memset(g->membername[x], 0, 64);
g->members[x] = nullptr;
}
}
int j = i+1;
for(; j<MAX_GROUP_MEMBERS; j++) {
if(g->members[j]) {
// Log.Out(Logs::General, Logs::Status, "group count is: %d", g->GroupCount());
g->members[j-1] = g->members[j];
strcpy(g->membername[j-1], g->members[j]->GetCleanName());
g->membername[j][0] = '\0';
memset(g->membername[j], 0, 64);
g->members[j] = nullptr;
}
}
// update the client group
EQApplicationPacket* outapp = new EQApplicationPacket(OP_GroupUpdate, sizeof(GroupJoin_Struct));
GroupJoin_Struct* gu = (GroupJoin_Struct*)outapp->pBuffer;
gu->action = groupActLeave;
strcpy(gu->membername, GetCleanName());
if(g) {
for(int k=0; k<MAX_GROUP_MEMBERS; k++) {
if(g->members[k] && g->members[k]->IsClient())
g->members[k]->CastToClient()->QueuePacket(outapp);
}
}
safe_delete(outapp);

// now that's done, lets see if all we have left is the client
// and we can clean up the clients raid group and group
/*if(GetBotRaidID()) {
BotRaids* br = entity_list.GetBotRaidByMob(this);
if(br) {
if(this == br->botmaintank) {
br->botmaintank = nullptr;
}
if(this == br->botsecondtank) {
br->botsecondtank = nullptr;
}
}
if(g->GroupCount() == 0) {
uint32 gid = g->GetID();
if(br) {
br->RemoveEmptyBotGroup();
}
entity_list.RemoveGroup(gid);
}
if(br && (br->RaidBotGroupsCount() == 1)) {
br->RemoveClientGroup(br->GetRaidBotLeader());
}
if(br && (br->RaidBotGroupsCount() == 0)) {
br->DisbandBotRaid();
}
}*/
}
}
}
}

if(GetInHealRotation()) {
GetHealRotationLeader()->RemoveHealRotationMember(this);
}

entity_list.RemoveBot(this->GetID());

return true;
}

Nibiuno
02-25-2015, 01:05 PM
It wasnt bot camp - I just updated to the newest code to test. Its when you spawn 2 bots, and group with them - then you #bot camp one bot, and then hit disband.

The zone crashes everytime I hit disband after camping one bot. That last change I posted fixes it for some reason.

rencro
02-25-2015, 06:08 PM
Sorry, I cannot replicate this issue at all, by chance when you pulled new code or have been updating, did you not re-apply(or merge) Client::Handle_OP_GroupDisband ?

Here is my diff to the latest code, this has some forum related fixes as well from http://www.eqemulator.org/forums/showthread.php?t=39013 and http://www.eqemulator.org/forums/showthread.php?t=38996


diff --git a/zone/bot.cpp b/zone/bot.cpp
index 1b1da0b..d29c4ff 100644
--- a/zone/bot.cpp
+++ b/zone/bot.cpp
@@ -1379,6 +1379,26 @@ int32 Bot::GenerateBaseHitPoints()
int new_base_hp = 0;
uint32 lm = GetClassLevelFactor();
uint32 Post255;
+
+ if ((GetSTA() - 255) / 2 > 0)
+ Post255 = (GetSTA() - 255) / 2;
+ else
+ Post255 = 0;
+
+ new_base_hp = (5) + (GetLevel()*lm / 10) + (((GetSTA() - Post255)*GetLevel()*lm / 3000)) + ((Post255*GetLevel())*lm / 6000);
+
+ this->base_hp = new_base_hp;
+
+ return new_base_hp;
+}
+
+/*
+int32 Bot::GenerateBaseHitPoints()
+{
+ // Calc Base Hit Points
+ int new_base_hp = 0;
+ uint32 lm = GetClassLevelFactor();
+ uint32 Post255;
uint32 NormalSTA = GetSTA();

if(GetOwner() && GetOwner()->CastToClient() && GetOwner()->CastToClient()->GetClientVersion() >= ClientVersion::SoD && RuleB(Character, SoDClientUseSoDHPManaEnd))
@@ -1422,7 +1442,7 @@ int32 Bot::GenerateBaseHitPoints()

return new_base_hp;
}
-
+*/
void Bot::GenerateAABonuses(StatBonuses* newbon) {
// General AA bonus
uint8 botClass = GetClass();
@@ -4662,6 +4682,7 @@ void Bot::SaveBotGroup(Group* botGroup, std::string botGroupName, std::string* e
return;
}

+ botGroupId = GetBotGroupIdByBotGroupName(botGroupName.c_str(), errorMessage);
if(botGroupId == 0)
return;

@@ -5911,9 +5932,17 @@ bool Bot::Death(Mob *killerMob, int32 damage, uint16 spell_id, SkillUseTypes att

// if group members exist below this one, move
// them all up one slot in the group list
+ if(g->GroupCount() == 6) {
+ for(int x=0; x<MAX_GROUP_MEMBERS; x++) {
+ g->membername[x][0] = '\0';
+ memset(g->membername[x], 0, 64);
+ g->members[x] = nullptr;
+ }
+ }
int j = i+1;
for(; j<MAX_GROUP_MEMBERS; j++) {
if(g->members[j]) {
+// Log.Out(Logs::General, Logs::Status, "group count is: %d", g->GroupCount());
g->members[j-1] = g->members[j];
strcpy(g->membername[j-1], g->members[j]->GetCleanName());
g->membername[j][0] = '\0';
@@ -5921,7 +5950,6 @@ bool Bot::Death(Mob *killerMob, int32 damage, uint16 spell_id, SkillUseTypes att
g->members[j] = nullptr;
}
}
-
// update the client group
EQApplicationPacket* outapp = new EQApplicationPacket(OP_GroupUpdate, sizeof(GroupJoin_Struct));
GroupJoin_Struct* gu = (GroupJoin_Struct*)outapp->pBuffer;
diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp
index 5ff2052..00d2cc3 100644
--- a/zone/client_packet.cpp
+++ b/zone/client_packet.cpp
@@ -6343,16 +6343,11 @@ void Client::Handle_OP_GroupDisband(const EQApplicationPacket *app)
// this block is necessary to allow more control over controlling how bots are zoned or camped.
if (Bot::GroupHasBot(group)) {
if (group->IsLeader(this)) {
- if ((GetTarget() == 0 || GetTarget() == this) || (group->GroupCount() < 3)) {
- Bot::ProcessBotGroupDisband(this, std::string());
- }
- else {
- Mob* tempMember = entity_list.GetMob(gd->name2);
- if (tempMember) {
- if (tempMember->IsBot())
- Bot::ProcessBotGroupDisband(this, std::string(tempMember->GetCleanName()));
+ Mob* tempMember = GetTarget();
+ if (tempMember->IsBot()) {
+ Bot::ProcessBotGroupDisband(this, std::string(tempMember->GetCleanName()));
+ return;
}
- }
}
}
#endif

jpyou127
05-22-2015, 11:19 PM
Not sure if anyone is still looking at this, but it happens for me on a brand new build as of today. When a Bot dies or is targeted and disbanded from a group it crashes the zone. Only thing I have done is recompile in "bot.cpp" with a fix for the HP/no attack issue as well as add appropriate lines in the "botbuffs" to fix the missing columns.

I have not tried to recompile any of these fixes above.