Logs::Spawns to LogSpawns

This commit is contained in:
Akkadius 2019-09-02 04:10:43 -05:00
parent 076d393f79
commit 3e4587cd57
3 changed files with 130 additions and 148 deletions

View File

@ -419,7 +419,7 @@ bool LoginServer::Connect()
[this](EQ::Net::ServertalkClient *client) { [this](EQ::Net::ServertalkClient *client) {
if (client) { if (client) {
LogInfo( LogInfo(
"Connected to Loginserver: {0}:{1}", "Connected to Loginserver: [{0}:{1}]",
LoginServerAddress, LoginServerAddress,
LoginServerPort LoginServerPort
); );
@ -436,7 +436,7 @@ bool LoginServer::Connect()
} }
else { else {
LogInfo( LogInfo(
"Could not connect to Loginserver: {0}:{1}", "Could not connect to Loginserver: [{0}:{1}]",
LoginServerAddress, LoginServerAddress,
LoginServerPort LoginServerPort
); );

View File

@ -154,17 +154,13 @@ bool Spawn2::Process() {
if (timer.Check()) { if (timer.Check()) {
timer.Disable(); timer.Disable();
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Timer has triggered", spawn2_id); LogSpawns("Spawn2 [{}]: Timer has triggered", spawn2_id);
//first check our spawn condition, if this isnt active //first check our spawn condition, if this isnt active
//then we reset the timer and try again next time. //then we reset the timer and try again next time.
if (condition_id != SC_AlwaysEnabled if (condition_id != SC_AlwaysEnabled
&& !zone->spawn_conditions.Check(condition_id, condition_min_value)) { && !zone->spawn_conditions.Check(condition_id, condition_min_value)) {
Log(Logs::Detail, LogSpawns("Spawn2 [{}]: spawning prevented by spawn condition [{}]", spawn2_id, condition_id);
Logs::Spawns,
"Spawn2 %d: spawning prevented by spawn condition %d",
spawn2_id,
condition_id);
Reset(); Reset();
return (true); return (true);
} }
@ -175,11 +171,7 @@ bool Spawn2::Process() {
} }
if (spawn_group == nullptr) { if (spawn_group == nullptr) {
Log(Logs::Detail, LogSpawns("Spawn2 [{}]: Unable to locate spawn group [{}]. Disabling", spawn2_id, spawngroup_id_);
Logs::Spawns,
"Spawn2 %d: Unable to locate spawn group %d. Disabling.",
spawn2_id,
spawngroup_id_);
return false; return false;
} }
@ -187,11 +179,7 @@ bool Spawn2::Process() {
//have the spawn group pick an NPC for us //have the spawn group pick an NPC for us
uint32 npcid = spawn_group->GetNPCType(); uint32 npcid = spawn_group->GetNPCType();
if (npcid == 0) { if (npcid == 0) {
Log(Logs::Detail, LogSpawns("Spawn2 [{}]: Spawn group [{}] did not yeild an NPC! not spawning", spawn2_id, spawngroup_id_);
Logs::Spawns,
"Spawn2 %d: Spawn group %d did not yeild an NPC! not spawning.",
spawn2_id,
spawngroup_id_);
Reset(); //try again later (why?) Reset(); //try again later (why?)
return (true); return (true);
@ -200,24 +188,14 @@ bool Spawn2::Process() {
//try to find our NPC type. //try to find our NPC type.
const NPCType *tmp = database.LoadNPCTypesData(npcid); const NPCType *tmp = database.LoadNPCTypesData(npcid);
if (tmp == nullptr) { if (tmp == nullptr) {
Log(Logs::Detail, LogSpawns("Spawn2 [{}]: Spawn group [{}] yeilded an invalid NPC type [{}]", spawn2_id, spawngroup_id_, npcid);
Logs::Spawns,
"Spawn2 %d: Spawn group %d yeilded an invalid NPC type %d",
spawn2_id,
spawngroup_id_,
npcid);
Reset(); //try again later Reset(); //try again later
return (true); return (true);
} }
if (tmp->unique_spawn_by_name) { if (tmp->unique_spawn_by_name) {
if (!entity_list.LimitCheckName(tmp->name)) { if (!entity_list.LimitCheckName(tmp->name)) {
Log(Logs::Detail, LogSpawns("Spawn2 [{}]: Spawn group [{}] yeilded NPC type [{}], which is unique and one already exists", spawn2_id, spawngroup_id_, npcid);
Logs::Spawns,
"Spawn2 %d: Spawn group %d yeilded NPC type %d, which is unique and one already exists.",
spawn2_id,
spawngroup_id_,
npcid);
timer.Start(5000); //try again in five seconds. timer.Start(5000); //try again in five seconds.
return (true); return (true);
} }
@ -225,13 +203,7 @@ bool Spawn2::Process() {
if (tmp->spawn_limit > 0) { if (tmp->spawn_limit > 0) {
if (!entity_list.LimitCheckType(npcid, tmp->spawn_limit)) { if (!entity_list.LimitCheckType(npcid, tmp->spawn_limit)) {
Log(Logs::Detail, LogSpawns("Spawn2 [{}]: Spawn group [{}] yeilded NPC type [{}], which is over its spawn limit ([{}])", spawn2_id, spawngroup_id_, npcid, tmp->spawn_limit);
Logs::Spawns,
"Spawn2 %d: Spawn group %d yeilded NPC type %d, which is over its spawn limit (%d)",
spawn2_id,
spawngroup_id_,
npcid,
tmp->spawn_limit);
timer.Start(5000); //try again in five seconds. timer.Start(5000); //try again in five seconds.
return (true); return (true);
} }
@ -287,9 +259,7 @@ bool Spawn2::Process() {
} }
if (zone->InstantGrids()) { if (zone->InstantGrids()) {
Log(Logs::Detail, LogSpawns("Spawn2 [{}]: Group [{}] spawned [{}] ([{}]) at ([{}], [{}], [{}])",
Logs::Spawns,
"Spawn2 %d: Group %d spawned %s (%d) at (%.3f, %.3f, %.3f).",
spawn2_id, spawn2_id,
spawngroup_id_, spawngroup_id_,
npc->GetName(), npc->GetName(),
@ -302,16 +272,15 @@ bool Spawn2::Process() {
LoadGrid(); LoadGrid();
} }
else { else {
Log(Logs::Detail, LogSpawns("Spawn2 [{}]: Group [{}] spawned [{}] ([{}]) at ([{}], [{}], [{}]). Grid loading delayed",
Logs::Spawns,
"Spawn2 %d: Group %d spawned %s (%d) at (%.3f, %.3f, %.3f). Grid loading delayed.",
spawn2_id, spawn2_id,
spawngroup_id_, spawngroup_id_,
tmp->name, tmp->name,
npcid, npcid,
x, x,
y, y,
z); z
);
} }
} }
@ -337,7 +306,7 @@ void Spawn2::LoadGrid() {
//dont set an NPC's grid until its loaded for them. //dont set an NPC's grid until its loaded for them.
npcthis->SetGrid(grid_); npcthis->SetGrid(grid_);
npcthis->AssignWaypoints(grid_); npcthis->AssignWaypoints(grid_);
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Loading grid %d for %s", spawn2_id, grid_, npcthis->GetName()); LogSpawns("Spawn2 [{}]: Loading grid [{}] for [{}]", spawn2_id, grid_, npcthis->GetName());
} }
/* /*
@ -347,21 +316,21 @@ void Spawn2::LoadGrid() {
void Spawn2::Reset() { void Spawn2::Reset() {
timer.Start(resetTimer()); timer.Start(resetTimer());
npcthis = nullptr; npcthis = nullptr;
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn reset, repop in %d ms", spawn2_id, timer.GetRemainingTime()); LogSpawns("Spawn2 [{}]: Spawn reset, repop in [{}] ms", spawn2_id, timer.GetRemainingTime());
} }
void Spawn2::Depop() { void Spawn2::Depop() {
timer.Disable(); timer.Disable();
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn reset, repop disabled", spawn2_id); LogSpawns("Spawn2 [{}]: Spawn reset, repop disabled", spawn2_id);
npcthis = nullptr; npcthis = nullptr;
} }
void Spawn2::Repop(uint32 delay) { void Spawn2::Repop(uint32 delay) {
if (delay == 0) { if (delay == 0) {
timer.Trigger(); timer.Trigger();
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn reset, repop immediately.", spawn2_id); LogSpawns("Spawn2 [{}]: Spawn reset, repop immediately", spawn2_id);
} else { } else {
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn reset for repop, repop in %d ms", spawn2_id, delay); LogSpawns("Spawn2 [{}]: Spawn reset for repop, repop in [{}] ms", spawn2_id, delay);
timer.Start(delay); timer.Start(delay);
} }
npcthis = nullptr; npcthis = nullptr;
@ -406,7 +375,7 @@ void Spawn2::ForceDespawn()
cur = despawnTimer(dtimer); cur = despawnTimer(dtimer);
} }
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn group %d set despawn timer to %d ms.", spawn2_id, spawngroup_id_, cur); LogSpawns("Spawn2 [{}]: Spawn group [{}] set despawn timer to [{}] ms", spawn2_id, spawngroup_id_, cur);
timer.Start(cur); timer.Start(cur);
} }
@ -427,7 +396,7 @@ void Spawn2::DeathReset(bool realdeath)
if(spawn2_id) if(spawn2_id)
{ {
database.UpdateRespawnTime(spawn2_id, zone->GetInstanceID(), (cur/1000)); database.UpdateRespawnTime(spawn2_id, zone->GetInstanceID(), (cur/1000));
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Spawn reset by death, repop in %d ms", spawn2_id, timer.GetRemainingTime()); LogSpawns("Spawn2 [{}]: Spawn reset by death, repop in [{}] ms", spawn2_id, timer.GetRemainingTime());
//store it to database too //store it to database too
} }
} }
@ -712,12 +681,12 @@ void Spawn2::SpawnConditionChanged(const SpawnCondition &c, int16 old_value) {
if(GetSpawnCondition() != c.condition_id) if(GetSpawnCondition() != c.condition_id)
return; return;
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Notified that our spawn condition %d has changed from %d to %d. Our min value is %d.", spawn2_id, c.condition_id, old_value, c.value, condition_min_value); LogSpawns("Spawn2 [{}]: Notified that our spawn condition [{}] has changed from [{}] to [{}]. Our min value is [{}]", spawn2_id, c.condition_id, old_value, c.value, condition_min_value);
bool old_state = (old_value >= condition_min_value); bool old_state = (old_value >= condition_min_value);
bool new_state = (c.value >= condition_min_value); bool new_state = (c.value >= condition_min_value);
if(old_state == new_state) { if(old_state == new_state) {
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Our threshold for this condition was not crossed. Doing nothing.", spawn2_id); LogSpawns("Spawn2 [{}]: Our threshold for this condition was not crossed. Doing nothing", spawn2_id);
return; //no change return; //no change
} }
@ -725,50 +694,50 @@ void Spawn2::SpawnConditionChanged(const SpawnCondition &c, int16 old_value) {
switch(c.on_change) { switch(c.on_change) {
case SpawnCondition::DoNothing: case SpawnCondition::DoNothing:
//that was easy. //that was easy.
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Our condition is now %s. Taking no action on existing spawn.", spawn2_id, new_state?"enabled":"disabled"); LogSpawns("Spawn2 [{}]: Our condition is now [{}]. Taking no action on existing spawn", spawn2_id, new_state?"enabled":"disabled");
break; break;
case SpawnCondition::DoDepop: case SpawnCondition::DoDepop:
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Our condition is now %s. Depoping our mob.", spawn2_id, new_state?"enabled":"disabled"); LogSpawns("Spawn2 [{}]: Our condition is now [{}]. Depoping our mob", spawn2_id, new_state?"enabled":"disabled");
if(npcthis != nullptr) if(npcthis != nullptr)
npcthis->Depop(false); //remove the current mob npcthis->Depop(false); //remove the current mob
Reset(); //reset our spawn timer Reset(); //reset our spawn timer
break; break;
case SpawnCondition::DoRepop: case SpawnCondition::DoRepop:
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Our condition is now %s. Forcing a repop.", spawn2_id, new_state?"enabled":"disabled"); LogSpawns("Spawn2 [{}]: Our condition is now [{}]. Forcing a repop", spawn2_id, new_state?"enabled":"disabled");
if(npcthis != nullptr) if(npcthis != nullptr)
npcthis->Depop(false); //remove the current mob npcthis->Depop(false); //remove the current mob
Repop(); //repop Repop(); //repop
break; break;
case SpawnCondition::DoRepopIfReady: case SpawnCondition::DoRepopIfReady:
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Our condition is now %s. Forcing a repop if repsawn timer is expired.", spawn2_id, new_state?"enabled":"disabled"); LogSpawns("Spawn2 [{}]: Our condition is now [{}]. Forcing a repop if repsawn timer is expired", spawn2_id, new_state?"enabled":"disabled");
if(npcthis != nullptr) { if(npcthis != nullptr) {
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Our npcthis is currently not null. The zone thinks it is %s. Forcing a depop.", spawn2_id, npcthis->GetName()); LogSpawns("Spawn2 [{}]: Our npcthis is currently not null. The zone thinks it is [{}]. Forcing a depop", spawn2_id, npcthis->GetName());
npcthis->Depop(false); //remove the current mob npcthis->Depop(false); //remove the current mob
npcthis = nullptr; npcthis = nullptr;
} }
if(new_state) { // only get repawn timer remaining when the SpawnCondition is enabled. if(new_state) { // only get repawn timer remaining when the SpawnCondition is enabled.
timer_remaining = database.GetSpawnTimeLeft(spawn2_id,zone->GetInstanceID()); timer_remaining = database.GetSpawnTimeLeft(spawn2_id,zone->GetInstanceID());
Log(Logs::Detail, Logs::Spawns,"Spawn2 %d: Our condition is now %s. The respawn timer_remaining is %d. Forcing a repop if it is <= 0.", spawn2_id, new_state?"enabled":"disabled", timer_remaining); LogSpawns("Spawn2 [{}]: Our condition is now [{}]. The respawn timer_remaining is [{}]. Forcing a repop if it is <= 0", spawn2_id, new_state?"enabled":"disabled", timer_remaining);
if(timer_remaining <= 0) if(timer_remaining <= 0)
Repop(); Repop();
} else { } else {
Log(Logs::Detail, Logs::Spawns,"Spawn2 %d: Our condition is now %s. Not checking respawn timer.", spawn2_id, new_state?"enabled":"disabled"); LogSpawns("Spawn2 [{}]: Our condition is now [{}]. Not checking respawn timer", spawn2_id, new_state?"enabled":"disabled");
} }
break; break;
default: default:
if(c.on_change < SpawnCondition::DoSignalMin) { if(c.on_change < SpawnCondition::DoSignalMin) {
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Our condition is now %s. Invalid on-change action %d.", spawn2_id, new_state?"enabled":"disabled", c.on_change); LogSpawns("Spawn2 [{}]: Our condition is now [{}]. Invalid on-change action [{}]", spawn2_id, new_state?"enabled":"disabled", c.on_change);
return; //unknown onchange action return; //unknown onchange action
} }
int signal_id = c.on_change - SpawnCondition::DoSignalMin; int signal_id = c.on_change - SpawnCondition::DoSignalMin;
Log(Logs::Detail, Logs::Spawns, "Spawn2 %d: Our condition is now %s. Signaling our mob with %d.", spawn2_id, new_state?"enabled":"disabled", signal_id); LogSpawns("Spawn2 [{}]: Our condition is now [{}]. Signaling our mob with [{}]", spawn2_id, new_state?"enabled":"disabled", signal_id);
if(npcthis != nullptr) if(npcthis != nullptr)
npcthis->SignalNPC(signal_id); npcthis->SignalNPC(signal_id);
} }
} }
void Zone::SpawnConditionChanged(const SpawnCondition &c, int16 old_value) { void Zone::SpawnConditionChanged(const SpawnCondition &c, int16 old_value) {
Log(Logs::Detail, Logs::Spawns, "Zone notified that spawn condition %d has changed from %d to %d. Notifying all spawn points.", c.condition_id, old_value, c.value); LogSpawns("Zone notified that spawn condition [{}] has changed from [{}] to [{}]. Notifying all spawn points", c.condition_id, old_value, c.value);
LinkedListIterator<Spawn2*> iterator(spawn2_list); LinkedListIterator<Spawn2*> iterator(spawn2_list);
@ -838,7 +807,7 @@ void SpawnConditionManager::Process() {
EQTime::AddMinutes(cevent.period, &cevent.next); EQTime::AddMinutes(cevent.period, &cevent.next);
std::string t; std::string t;
EQTime::ToString(&cevent.next, t); EQTime::ToString(&cevent.next, t);
Log(Logs::Detail, Logs::Spawns, "Event %d: Will trigger again in %d EQ minutes at %s.", cevent.id, cevent.period, t.c_str()); LogSpawns("Event [{}]: Will trigger again in [{}] EQ minutes at [{}]", cevent.id, cevent.period, t.c_str());
//save the next event time in the DB //save the next event time in the DB
UpdateDBEvent(cevent); UpdateDBEvent(cevent);
//find the next closest event timer. //find the next closest event timer.
@ -857,7 +826,7 @@ void SpawnConditionManager::ExecEvent(SpawnEvent &event, bool send_update) {
std::map<uint16, SpawnCondition>::iterator condi; std::map<uint16, SpawnCondition>::iterator condi;
condi = spawn_conditions.find(event.condition_id); condi = spawn_conditions.find(event.condition_id);
if(condi == spawn_conditions.end()) { if(condi == spawn_conditions.end()) {
Log(Logs::Detail, Logs::Spawns, "Event %d: Unable to find condition %d to execute on.", event.id, event.condition_id); LogSpawns("Event [{}]: Unable to find condition [{}] to execute on", event.id, event.condition_id);
return; //unable to find the spawn condition to operate on return; //unable to find the spawn condition to operate on
} }
@ -865,7 +834,7 @@ void SpawnConditionManager::ExecEvent(SpawnEvent &event, bool send_update) {
zone->zone_time.GetCurrentEQTimeOfDay(&tod); zone->zone_time.GetCurrentEQTimeOfDay(&tod);
if(event.strict && (event.next.hour != tod.hour || event.next.day != tod.day || event.next.month != tod.month || event.next.year != tod.year)) if(event.strict && (event.next.hour != tod.hour || event.next.day != tod.day || event.next.month != tod.month || event.next.year != tod.year))
{ {
Log(Logs::Detail, Logs::Spawns, "Event %d: Unable to execute. Condition is strict, and event time has already passed.", event.id); LogSpawns("Event [{}]: Unable to execute. Condition is strict, and event time has already passed", event.id);
return; return;
} }
@ -877,26 +846,26 @@ void SpawnConditionManager::ExecEvent(SpawnEvent &event, bool send_update) {
switch(event.action) { switch(event.action) {
case SpawnEvent::ActionSet: case SpawnEvent::ActionSet:
new_value = event.argument; new_value = event.argument;
Log(Logs::Detail, Logs::Spawns, "Event %d: Executing. Setting condition %d to %d.", event.id, event.condition_id, event.argument); LogSpawns("Event [{}]: Executing. Setting condition [{}] to [{}]", event.id, event.condition_id, event.argument);
break; break;
case SpawnEvent::ActionAdd: case SpawnEvent::ActionAdd:
new_value += event.argument; new_value += event.argument;
Log(Logs::Detail, Logs::Spawns, "Event %d: Executing. Adding %d to condition %d, yeilding %d.", event.id, event.argument, event.condition_id, new_value); LogSpawns("Event [{}]: Executing. Adding [{}] to condition [{}], yeilding [{}]", event.id, event.argument, event.condition_id, new_value);
break; break;
case SpawnEvent::ActionSubtract: case SpawnEvent::ActionSubtract:
new_value -= event.argument; new_value -= event.argument;
Log(Logs::Detail, Logs::Spawns, "Event %d: Executing. Subtracting %d from condition %d, yeilding %d.", event.id, event.argument, event.condition_id, new_value); LogSpawns("Event [{}]: Executing. Subtracting [{}] from condition [{}], yeilding [{}]", event.id, event.argument, event.condition_id, new_value);
break; break;
case SpawnEvent::ActionMultiply: case SpawnEvent::ActionMultiply:
new_value *= event.argument; new_value *= event.argument;
Log(Logs::Detail, Logs::Spawns, "Event %d: Executing. Multiplying condition %d by %d, yeilding %d.", event.id, event.condition_id, event.argument, new_value); LogSpawns("Event [{}]: Executing. Multiplying condition [{}] by [{}], yeilding [{}]", event.id, event.condition_id, event.argument, new_value);
break; break;
case SpawnEvent::ActionDivide: case SpawnEvent::ActionDivide:
new_value /= event.argument; new_value /= event.argument;
Log(Logs::Detail, Logs::Spawns, "Event %d: Executing. Dividing condition %d by %d, yeilding %d.", event.id, event.condition_id, event.argument, new_value); LogSpawns("Event [{}]: Executing. Dividing condition [{}] by [{}], yeilding [{}]", event.id, event.condition_id, event.argument, new_value);
break; break;
default: default:
Log(Logs::Detail, Logs::Spawns, "Event %d: Invalid event action type %d", event.id, event.action); LogSpawns("Event [{}]: Invalid event action type [{}]", event.id, event.action);
return; return;
} }
@ -966,7 +935,7 @@ bool SpawnConditionManager::LoadDBEvent(uint32 event_id, SpawnEvent &event, std:
std::string timeAsString; std::string timeAsString;
EQTime::ToString(&event.next, timeAsString); EQTime::ToString(&event.next, timeAsString);
Log(Logs::Detail, Logs::Spawns, "(LoadDBEvent) Loaded %s spawn event %d on condition %d with period %d, action %d, argument %d, strict %d. Will trigger at %s", event.enabled? "enabled": "disabled", event.id, event.condition_id, event.period, event.action, event.argument, event.strict, timeAsString.c_str()); LogSpawns("(LoadDBEvent) Loaded [{}] spawn event [{}] on condition [{}] with period [{}], action [{}], argument [{}], strict [{}]. Will trigger at [{}]", event.enabled? "enabled": "disabled", event.id, event.condition_id, event.period, event.action, event.argument, event.strict, timeAsString.c_str());
return true; return true;
} }
@ -993,7 +962,7 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
cond.on_change = (SpawnCondition::OnChange) atoi(row[1]); cond.on_change = (SpawnCondition::OnChange) atoi(row[1]);
spawn_conditions[cond.condition_id] = cond; spawn_conditions[cond.condition_id] = cond;
Log(Logs::Detail, Logs::Spawns, "Loaded spawn condition %d with value %d and on_change %d", cond.condition_id, cond.value, cond.on_change); LogSpawns("Loaded spawn condition [{}] with value [{}] and on_change [{}]", cond.condition_id, cond.value, cond.on_change);
} }
//load values //load values
@ -1022,33 +991,42 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
return false; return false;
} }
for (auto row = results.begin(); row != results.end(); ++row) { for (auto row = results.begin(); row != results.end(); ++row) {
SpawnEvent event; SpawnEvent event;
event.id = atoi(row[0]); event.id = atoi(row[0]);
event.condition_id = atoi(row[1]); event.condition_id = atoi(row[1]);
event.period = atoi(row[2]); event.period = atoi(row[2]);
if (event.period == 0) { if (event.period == 0) {
LogError("Refusing to load spawn event #[{}] because it has a period of 0\n", event.id); LogError("Refusing to load spawn event #[{}] because it has a period of 0\n", event.id);
continue; continue;
} }
event.next.minute = atoi(row[3]); event.next.minute = atoi(row[3]);
event.next.hour = atoi(row[4]); event.next.hour = atoi(row[4]);
event.next.day = atoi(row[5]); event.next.day = atoi(row[5]);
event.next.month = atoi(row[6]); event.next.month = atoi(row[6]);
event.next.year = atoi(row[7]); event.next.year = atoi(row[7]);
event.enabled = atoi(row[8])==0?false:true; event.enabled = atoi(row[8]) == 0 ? false : true;
event.action = (SpawnEvent::Action) atoi(row[9]); event.action = (SpawnEvent::Action) atoi(row[9]);
event.argument = atoi(row[10]); event.argument = atoi(row[10]);
event.strict = atoi(row[11])==0?false:true; event.strict = atoi(row[11]) == 0 ? false : true;
spawn_events.push_back(event); spawn_events.push_back(event);
Log(Logs::Detail, Logs::Spawns, "(LoadSpawnConditions) Loaded %s spawn event %d on condition %d with period %d, action %d, argument %d, strict %d", event.enabled? "enabled": "disabled", event.id, event.condition_id, event.period, event.action, event.argument, event.strict); LogSpawns(
} "(LoadSpawnConditions) Loaded [{}] spawn event [{}] on condition [{}] with period [{}], action [{}], argument [{}], strict [{}]",
event.enabled ? "enabled" : "disabled",
event.id,
event.condition_id,
event.period,
event.action,
event.argument,
event.strict
);
}
//now we need to catch up on events that happened while we were away //now we need to catch up on events that happened while we were away
//and use them to alter just the condition variables. //and use them to alter just the condition variables.
@ -1080,31 +1058,33 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
if(!cevent.enabled) if(!cevent.enabled)
continue; continue;
//watch for special case of all 0s, which means to reset next to now //watch for special case of all 0s, which means to reset next to now
if(cevent.next.year == 0 && cevent.next.month == 0 && cevent.next.day == 0 && cevent.next.hour == 0 && cevent.next.minute == 0) { if (cevent.next.year == 0 && cevent.next.month == 0 && cevent.next.day == 0 && cevent.next.hour == 0 &&
Log(Logs::Detail, Logs::Spawns, "Initial next trigger time set for spawn event %d", cevent.id); cevent.next.minute == 0) {
memcpy(&cevent.next, &tod, sizeof(cevent.next)); LogSpawns("Initial next trigger time set for spawn event [{}]", cevent.id);
//add one period memcpy(&cevent.next, &tod, sizeof(cevent.next));
EQTime::AddMinutes(cevent.period, &cevent.next); //add one period
//save it in the db. EQTime::AddMinutes(cevent.period, &cevent.next);
UpdateDBEvent(cevent); //save it in the db.
continue; //were done with this event. UpdateDBEvent(cevent);
} continue; //were done with this event.
}
bool ran = false; bool ran = false;
while(EQTime::IsTimeBefore(&tod, &cevent.next)) { while (EQTime::IsTimeBefore(&tod, &cevent.next)) {
Log(Logs::Detail, Logs::Spawns, "Catch up triggering on event %d", cevent.id); LogSpawns("Catch up triggering on event [{}]", cevent.id);
//this event has been triggered. //this event has been triggered.
//execute the event //execute the event
if(!cevent.strict || StrictCheck) if (!cevent.strict || StrictCheck) {
ExecEvent(cevent, false); ExecEvent(cevent, false);
}
//add the period of the event to the trigger time //add the period of the event to the trigger time
EQTime::AddMinutes(cevent.period, &cevent.next); EQTime::AddMinutes(cevent.period, &cevent.next);
ran = true; ran = true;
} }
//only write it out if the event actually ran //only write it out if the event actually ran
if(ran) if(ran)
UpdateDBEvent(cevent); //save the event in the DB UpdateDBEvent(cevent); //save the event in the DB
} }
@ -1136,10 +1116,10 @@ void SpawnConditionManager::FindNearestEvent() {
} }
} }
if (next_id == -1) { if (next_id == -1) {
Log(Logs::Detail, Logs::Spawns, "No spawn events enabled. Disabling next event."); LogSpawns("No spawn events enabled. Disabling next event");
} }
else { else {
Log(Logs::Detail, Logs::Spawns, "Next event determined to be event %d", next_id); LogSpawns("Next event determined to be event [{}]", next_id);
} }
} }
@ -1152,14 +1132,14 @@ void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance
std::map<uint16, SpawnCondition>::iterator condi; std::map<uint16, SpawnCondition>::iterator condi;
condi = spawn_conditions.find(condition_id); condi = spawn_conditions.find(condition_id);
if(condi == spawn_conditions.end()) { if(condi == spawn_conditions.end()) {
Log(Logs::Detail, Logs::Spawns, "Condition update received from world for %d, but we do not have that conditon.", condition_id); LogSpawns("Condition update received from world for [{}], but we do not have that conditon", condition_id);
return; //unable to find the spawn condition return; //unable to find the spawn condition
} }
SpawnCondition &cond = condi->second; SpawnCondition &cond = condi->second;
if(cond.value == new_value) { if(cond.value == new_value) {
Log(Logs::Detail, Logs::Spawns, "Condition update received from world for %d with value %d, which is what we already have.", condition_id, new_value); LogSpawns("Condition update received from world for [{}] with value [{}], which is what we already have", condition_id, new_value);
return; return;
} }
@ -1168,7 +1148,7 @@ void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance
//set our local value //set our local value
cond.value = new_value; cond.value = new_value;
Log(Logs::Detail, Logs::Spawns, "Condition update received from world for %d with value %d", condition_id, new_value); LogSpawns("Condition update received from world for [{}] with value [{}]", condition_id, new_value);
//now we have to test each spawn point to see if it changed. //now we have to test each spawn point to see if it changed.
zone->SpawnConditionChanged(cond, old_value); zone->SpawnConditionChanged(cond, old_value);
@ -1179,14 +1159,14 @@ void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance
std::map<uint16, SpawnCondition>::iterator condi; std::map<uint16, SpawnCondition>::iterator condi;
condi = spawn_conditions.find(condition_id); condi = spawn_conditions.find(condition_id);
if(condi == spawn_conditions.end()) { if(condi == spawn_conditions.end()) {
Log(Logs::Detail, Logs::Spawns, "Local Condition update requested for %d, but we do not have that conditon.", condition_id); LogSpawns("Local Condition update requested for [{}], but we do not have that conditon", condition_id);
return; //unable to find the spawn condition return; //unable to find the spawn condition
} }
SpawnCondition &cond = condi->second; SpawnCondition &cond = condi->second;
if(cond.value == new_value) { if(cond.value == new_value) {
Log(Logs::Detail, Logs::Spawns, "Local Condition update requested for %d with value %d, which is what we already have.", condition_id, new_value); LogSpawns("Local Condition update requested for [{}] with value [{}], which is what we already have", condition_id, new_value);
return; return;
} }
@ -1197,7 +1177,7 @@ void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance
//save it in the DB too //save it in the DB too
UpdateDBCondition(zone_short, instance_id, condition_id, new_value); UpdateDBCondition(zone_short, instance_id, condition_id, new_value);
Log(Logs::Detail, Logs::Spawns, "Local Condition update requested for %d with value %d", condition_id, new_value); LogSpawns("Local Condition update requested for [{}] with value [{}]", condition_id, new_value);
//now we have to test each spawn point to see if it changed. //now we have to test each spawn point to see if it changed.
zone->SpawnConditionChanged(cond, old_value); zone->SpawnConditionChanged(cond, old_value);
@ -1207,7 +1187,7 @@ void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance
//this is a remote spawn condition, update the DB and send //this is a remote spawn condition, update the DB and send
//an update packet to the zone if its up //an update packet to the zone if its up
Log(Logs::Detail, Logs::Spawns, "Remote spawn condition %d set to %d. Updating DB and notifying world.", condition_id, new_value); LogSpawns("Remote spawn condition [{}] set to [{}]. Updating DB and notifying world", condition_id, new_value);
UpdateDBCondition(zone_short, instance_id, condition_id, new_value); UpdateDBCondition(zone_short, instance_id, condition_id, new_value);
@ -1227,7 +1207,7 @@ void SpawnConditionManager::SetCondition(const char *zone_short, uint32 instance
void SpawnConditionManager::ReloadEvent(uint32 event_id) { void SpawnConditionManager::ReloadEvent(uint32 event_id) {
std::string zone_short_name; std::string zone_short_name;
Log(Logs::Detail, Logs::Spawns, "Requested to reload event %d from the database.", event_id); LogSpawns("Requested to reload event [{}] from the database", event_id);
//first look for the event in our local event list //first look for the event in our local event list
std::vector<SpawnEvent>::iterator cur,end; std::vector<SpawnEvent>::iterator cur,end;
@ -1240,7 +1220,7 @@ void SpawnConditionManager::ReloadEvent(uint32 event_id) {
//load the event into the old event slot //load the event into the old event slot
if(!LoadDBEvent(event_id, cevent, zone_short_name)) { if(!LoadDBEvent(event_id, cevent, zone_short_name)) {
//unable to find the event in the database... //unable to find the event in the database...
Log(Logs::Detail, Logs::Spawns, "Failed to reload event %d from the database.", event_id); LogSpawns("Failed to reload event [{}] from the database", event_id);
return; return;
} }
//sync up our nearest event //sync up our nearest event
@ -1253,7 +1233,7 @@ void SpawnConditionManager::ReloadEvent(uint32 event_id) {
SpawnEvent e; SpawnEvent e;
if(!LoadDBEvent(event_id, e, zone_short_name)) { if(!LoadDBEvent(event_id, e, zone_short_name)) {
//unable to find the event in the database... //unable to find the event in the database...
Log(Logs::Detail, Logs::Spawns, "Failed to reload event %d from the database.", event_id); LogSpawns("Failed to reload event [{}] from the database", event_id);
return; return;
} }
@ -1270,7 +1250,7 @@ void SpawnConditionManager::ReloadEvent(uint32 event_id) {
void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool strict, bool reset_base) { void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool strict, bool reset_base) {
Log(Logs::Detail, Logs::Spawns, "Request to %s spawn event %d %sresetting trigger time", enabled?"enable":"disable", event_id, reset_base?"":"without "); LogSpawns("Request to [{}] spawn event [{}] [{}]resetting trigger time", enabled?"enable":"disable", event_id, reset_base?"":"without ");
//first look for the event in our local event list //first look for the event in our local event list
std::vector<SpawnEvent>::iterator cur,end; std::vector<SpawnEvent>::iterator cur,end;
@ -1285,13 +1265,13 @@ void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool stri
cevent.enabled = enabled; cevent.enabled = enabled;
cevent.strict = strict; cevent.strict = strict;
if(reset_base) { if(reset_base) {
Log(Logs::Detail, Logs::Spawns, "Spawn event %d located in this zone. State set. Trigger time reset (period %d).", event_id, cevent.period); LogSpawns("Spawn event [{}] located in this zone. State set. Trigger time reset (period [{}])", event_id, cevent.period);
//start with the time now //start with the time now
zone->zone_time.GetCurrentEQTimeOfDay(&cevent.next); zone->zone_time.GetCurrentEQTimeOfDay(&cevent.next);
//advance the next time by our period //advance the next time by our period
EQTime::AddMinutes(cevent.period, &cevent.next); EQTime::AddMinutes(cevent.period, &cevent.next);
} else { } else {
Log(Logs::Detail, Logs::Spawns, "Spawn event %d located in this zone. State changed.", event_id); LogSpawns("Spawn event [{}] located in this zone. State changed", event_id);
} }
//save the event in the DB //save the event in the DB
@ -1300,7 +1280,7 @@ void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool stri
//sync up our nearest event //sync up our nearest event
FindNearestEvent(); FindNearestEvent();
} else { } else {
Log(Logs::Detail, Logs::Spawns, "Spawn event %d located in this zone but no change was needed.", event_id); LogSpawns("Spawn event [{}] located in this zone but no change was needed", event_id);
} }
//even if we dont change anything, we still found it //even if we dont change anything, we still found it
return; return;
@ -1319,24 +1299,24 @@ void SpawnConditionManager::ToggleEvent(uint32 event_id, bool enabled, bool stri
SpawnEvent e; SpawnEvent e;
std::string zone_short_name; std::string zone_short_name;
if(!LoadDBEvent(event_id, e, zone_short_name)) { if(!LoadDBEvent(event_id, e, zone_short_name)) {
Log(Logs::Detail, Logs::Spawns, "Unable to find spawn event %d in the database.", event_id); LogSpawns("Unable to find spawn event [{}] in the database", event_id);
//unable to find the event in the database... //unable to find the event in the database...
return; return;
} }
if(e.enabled == enabled && !reset_base) { if(e.enabled == enabled && !reset_base) {
Log(Logs::Detail, Logs::Spawns, "Spawn event %d is not located in this zone but no change was needed.", event_id); LogSpawns("Spawn event [{}] is not located in this zone but no change was needed", event_id);
return; //no changes. return; //no changes.
} }
e.enabled = enabled; e.enabled = enabled;
if(reset_base) { if(reset_base) {
Log(Logs::Detail, Logs::Spawns, "Spawn event %d is in zone %s. State set. Trigger time reset (period %d). Notifying world.", event_id, zone_short_name.c_str(), e.period); LogSpawns("Spawn event [{}] is in zone [{}]. State set. Trigger time reset (period [{}]). Notifying world", event_id, zone_short_name.c_str(), e.period);
//start with the time now //start with the time now
zone->zone_time.GetCurrentEQTimeOfDay(&e.next); zone->zone_time.GetCurrentEQTimeOfDay(&e.next);
//advance the next time by our period //advance the next time by our period
EQTime::AddMinutes(e.period, &e.next); EQTime::AddMinutes(e.period, &e.next);
} else { } else {
Log(Logs::Detail, Logs::Spawns, "Spawn event %d is in zone %s. State changed. Notifying world.", event_id, zone_short_name.c_str(), e.period); LogSpawns("Spawn event [{}] is in zone [{}]. State changed. Notifying world", event_id, zone_short_name.c_str(), e.period);
} }
//save the event in the DB //save the event in the DB
UpdateDBEvent(e); UpdateDBEvent(e);
@ -1361,7 +1341,7 @@ int16 SpawnConditionManager::GetCondition(const char *zone_short, uint32 instanc
condi = spawn_conditions.find(condition_id); condi = spawn_conditions.find(condition_id);
if(condi == spawn_conditions.end()) if(condi == spawn_conditions.end())
{ {
Log(Logs::Detail, Logs::Spawns, "Unable to find local condition %d in Get request.", condition_id); LogSpawns("Unable to find local condition [{}] in Get request", condition_id);
return(0); //unable to find the spawn condition return(0); //unable to find the spawn condition
} }
@ -1370,20 +1350,22 @@ int16 SpawnConditionManager::GetCondition(const char *zone_short, uint32 instanc
} }
//this is a remote spawn condition, grab it from the DB //this is a remote spawn condition, grab it from the DB
//load spawn conditions //load spawn conditions
std::string query = StringFormat("SELECT value FROM spawn_condition_values " std::string query = StringFormat(
"WHERE zone = '%s' AND instance_id = %u AND id = %d", "SELECT value FROM spawn_condition_values "
zone_short, instance_id, condition_id); "WHERE zone = '%s' AND instance_id = %u AND id = %d",
auto results = database.QueryDatabase(query); zone_short, instance_id, condition_id
if (!results.Success()) { );
Log(Logs::Detail, Logs::Spawns, "Unable to query remote condition %d from zone %s in Get request.", condition_id, zone_short); auto results = database.QueryDatabase(query);
return 0; //dunno a better thing to do... if (!results.Success()) {
} LogSpawns("Unable to query remote condition [{}] from zone [{}] in Get request", condition_id, zone_short);
return 0; //dunno a better thing to do...
}
if (results.RowCount() == 0) { if (results.RowCount() == 0) {
Log(Logs::Detail, Logs::Spawns, "Unable to load remote condition %d from zone %s in Get request.", condition_id, zone_short); LogSpawns("Unable to load remote condition [{}] from zone [{}] in Get request", condition_id, zone_short);
return 0; //dunno a better thing to do... return 0; //dunno a better thing to do...
} }
auto row = results.begin(); auto row = results.begin();

View File

@ -1203,7 +1203,7 @@ bool Zone::Process() {
EQEmu::InventoryProfile::CleanDirty(); EQEmu::InventoryProfile::CleanDirty();
Log(Logs::Detail, Logs::Spawns, "Running Zone::Process -> Spawn2::Process"); LogSpawns("Running Zone::Process -> Spawn2::Process");
iterator.Reset(); iterator.Reset();
while (iterator.MoreElements()) { while (iterator.MoreElements()) {