spawn combine save crashes, reports wrong location id

Fixed spawn combine save, was previously crashing (RemoveSpawn called multiple times) and also giving the wrong spawn location id as well (in the message output to the client)

Fixes #54
This commit is contained in:
Image 2020-03-21 07:42:40 -04:00
parent cc25e4f3d1
commit 7d6de27e1f
4 changed files with 17 additions and 12 deletions

View file

@ -3084,8 +3084,9 @@ bool WorldDatabase::SaveSpawnInfo(Spawn* spawn){
return true;
}
bool WorldDatabase::SaveCombinedSpawnLocation(ZoneServer* zone, Spawn* in_spawn, const char* name){
int32 WorldDatabase::SaveCombinedSpawnLocation(ZoneServer* zone, Spawn* in_spawn, const char* name){
vector<Spawn*>* spawns = in_spawn->GetSpawnGroup();
uint32 spawnLocationID = 0;
if(spawns && spawns->size() > 0){
vector<Spawn*>::iterator itr;
map<Spawn*, int32>::iterator freq_itr;
@ -3096,11 +3097,12 @@ bool WorldDatabase::SaveCombinedSpawnLocation(ZoneServer* zone, Spawn* in_spawn,
float y_offset = GetSpawnLocationPlacementOffsetY(in_spawn->GetSpawnLocationID());
float z_offset = GetSpawnLocationPlacementOffsetZ(in_spawn->GetSpawnLocationID());
int32 spawn_location_id = GetNextSpawnLocation();
spawnLocationID = spawn_location_id;
if(!name)
name = "Combine SpawnGroup Generated";
if(!CreateNewSpawnLocation(spawn_location_id, name)){
safe_delete(spawns);
return false;
return 0;
}
for(itr = spawns->begin();itr!=spawns->end();itr++){
spawn = *itr;
@ -3125,7 +3127,7 @@ bool WorldDatabase::SaveCombinedSpawnLocation(ZoneServer* zone, Spawn* in_spawn,
int8 percent = (freq_itr->second*100)/total;
if(!SaveSpawnEntry(freq_itr->first, name, percent, x_offset, y_offset, z_offset, freq_itr->first == in_spawn, false)){
safe_delete(spawns);
return false;
return 0;
}
}
for(itr=spawns->begin();itr!=spawns->end();itr++){
@ -3136,9 +3138,9 @@ bool WorldDatabase::SaveCombinedSpawnLocation(ZoneServer* zone, Spawn* in_spawn,
}
else{
safe_delete(spawns);
return false;
return 0;
}
return true;
return spawnLocationID;
}
bool WorldDatabase::SaveSpawnEntry(Spawn* spawn, const char* spawn_location_name, int8 percent, float x_offset, float y_offset, float z_offset, bool save_zonespawn, bool create_spawnlocation){

View file

@ -221,7 +221,7 @@ public:
void ResetDatabase();
void EnableConstraints();
void DisableConstraints();
bool SaveCombinedSpawnLocation(ZoneServer* zone, Spawn* spawn, const char* name);
int32 SaveCombinedSpawnLocation(ZoneServer* zone, Spawn* spawn, const char* name);
int32 ProcessSpawnLocations(ZoneServer* zone, const char* sql_query, int8 type);
int32 LoadSpawnLocationGroupAssociations(ZoneServer* zone);
int32 LoadSpawnLocationGroups(ZoneServer* zone);

View file

@ -5173,17 +5173,20 @@ void Client::SaveCombineSpawns(const char* name){
return;
}
int32 count = spawns->size();
safe_delete(spawns);
int32 spawnLocationID = 0;
if(count == 1)
SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
else if(database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)){
Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, combine_spawn->GetSpawnLocationID());
GetCurrentZone()->RemoveSpawn(false, combine_spawn);
else if((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0){
Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
// we remove the spawn inside SaveCombinedSpawnLocation
//GetCurrentZone()->RemoveSpawn(false, combine_spawn);
}
else
SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
combine_spawn = 0;
safe_delete(spawns);
combine_spawn = 0;
}
bool Client::AddItem(int32 item_id, int16 quantity){

View file

@ -217,7 +217,7 @@ MYSQL_RES* Query::RunQuery2(string in_query, QUERY_TYPE type){
#if defined WORLD && defined _DEBUG
if (type == Q_UPDATE || type == Q_INSERT || type == Q_DELETE || type == Q_REPLACE)
{
char* filteredTables[] = { " characters", " character_", " `character_", " statistics", " variables", " char_colors", " `guild_", " bugs" };
char* filteredTables[] = { " characters", " character_", " `character_", " statistics", " variables", " char_colors", " `guild", " bugs" };
bool match = false;
for (int i = 0; i < sizeof(filteredTables) / sizeof(filteredTables[0]); i++)