Skip to content

Commit

Permalink
Add logging, generate repo, poll owner online by account, remove db hits
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Feb 6, 2024
1 parent 3faecd1 commit 57f9ec5
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 52 deletions.
2 changes: 2 additions & 0 deletions common/eqemu_logsys.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ namespace Logs {
DataBuckets,
Zoning,
EqTime,
Corpses,
MaxCategoryID /* Don't Remove this */
};

Expand Down Expand Up @@ -239,6 +240,7 @@ namespace Logs {
"DataBuckets",
"Zoning",
"EqTime",
"Corpses",
};
}

Expand Down
10 changes: 10 additions & 0 deletions common/eqemu_logsys_log_aliases.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,16 @@
OutF(LogSys, Logs::Detail, Logs::EqTime, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)

#define LogCorpses(message, ...) do {\
if (LogSys.IsLogEnabled(Logs::General, Logs::Corpses))\
OutF(LogSys, Logs::General, Logs::Corpses, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)

#define LogCorpsesDetail(message, ...) do {\
if (LogSys.IsLogEnabled(Logs::Detail, Logs::Corpses))\
OutF(LogSys, Logs::Detail, Logs::Corpses, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
} while (0)

#define Log(debug_level, log_category, message, ...) do {\
if (LogSys.IsLogEnabled(debug_level, log_category))\
LogSys.Out(debug_level, log_category, __FILE__, __func__, __LINE__, message, ##__VA_ARGS__);\
Expand Down
35 changes: 17 additions & 18 deletions common/repositories/base/base_character_corpses_repository.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ class BaseCharacterCorpsesRepository {
e.wc_8 = 0;
e.wc_9 = 0;
e.rez_time = 0;
e.gm_exp = 0;
e.killed_by = 0;
e.rezzable = 1;
e.gm_exp = 0;
e.killed_by = 0;
e.rezzable = 0;

return e;
}
Expand Down Expand Up @@ -363,9 +363,9 @@ class BaseCharacterCorpsesRepository {
e.wc_8 = row[45] ? static_cast<uint32_t>(strtoul(row[45], nullptr, 10)) : 0;
e.wc_9 = row[46] ? static_cast<uint32_t>(strtoul(row[46], nullptr, 10)) : 0;
e.rez_time = row[47] ? static_cast<uint32_t>(strtoul(row[47], nullptr, 10)) : 0;
e.gm_exp = row[48] ? static_cast<uint32_t>(strtoul(row[48], nullptr, 10)) : 0;
e.killed_by = row[49] ? static_cast<uint32_t>(strtoul(row[49], nullptr, 10)) : 0;
e.rezzable = row[50] ? static_cast<uint8_t>(strtoul(row[50], nullptr, 10)) : 1;
e.gm_exp = row[48] ? static_cast<uint32_t>(strtoul(row[48], nullptr, 10)) : 0;
e.killed_by = row[49] ? static_cast<uint32_t>(strtoul(row[49], nullptr, 10)) : 0;
e.rezzable = row[50] ? static_cast<uint8_t>(strtoul(row[50], nullptr, 10)) : 0;

return e;
}
Expand Down Expand Up @@ -407,7 +407,7 @@ class BaseCharacterCorpsesRepository {
v.push_back(columns[6] + " = " + std::to_string(e.y));
v.push_back(columns[7] + " = " + std::to_string(e.z));
v.push_back(columns[8] + " = " + std::to_string(e.heading));
v.push_back(columns[9] + " = FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "UNIX_TIMESTAMP()") + ")");
v.push_back(columns[9] + " = FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "null") + ")");
v.push_back(columns[10] + " = " + std::to_string(e.guild_consent_id));
v.push_back(columns[11] + " = " + std::to_string(e.is_rezzed));
v.push_back(columns[12] + " = " + std::to_string(e.is_buried));
Expand Down Expand Up @@ -479,7 +479,7 @@ class BaseCharacterCorpsesRepository {
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "UNIX_TIMESTAMP()") + ")");
v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "null") + ")");
v.push_back(std::to_string(e.guild_consent_id));
v.push_back(std::to_string(e.is_rezzed));
v.push_back(std::to_string(e.is_buried));
Expand Down Expand Up @@ -559,7 +559,7 @@ class BaseCharacterCorpsesRepository {
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "UNIX_TIMESTAMP()") + ")");
v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "null") + ")");
v.push_back(std::to_string(e.guild_consent_id));
v.push_back(std::to_string(e.is_rezzed));
v.push_back(std::to_string(e.is_buried));
Expand Down Expand Up @@ -682,9 +682,9 @@ class BaseCharacterCorpsesRepository {
e.wc_8 = row[45] ? static_cast<uint32_t>(strtoul(row[45], nullptr, 10)) : 0;
e.wc_9 = row[46] ? static_cast<uint32_t>(strtoul(row[46], nullptr, 10)) : 0;
e.rez_time = row[47] ? static_cast<uint32_t>(strtoul(row[47], nullptr, 10)) : 0;
e.gm_exp = row[48] ? static_cast<uint32_t>(strtoul(row[48], nullptr, 10)) : 0;
e.killed_by = row[49] ? static_cast<uint32_t>(strtoul(row[49], nullptr, 10)) : 0;
e.rezzable = row[50] ? static_cast<uint8_t>(strtoul(row[50], nullptr, 10)) : 1;
e.gm_exp = row[48] ? static_cast<uint32_t>(strtoul(row[48], nullptr, 10)) : 0;
e.killed_by = row[49] ? static_cast<uint32_t>(strtoul(row[49], nullptr, 10)) : 0;
e.rezzable = row[50] ? static_cast<uint8_t>(strtoul(row[50], nullptr, 10)) : 0;

all_entries.push_back(e);
}
Expand Down Expand Up @@ -757,9 +757,9 @@ class BaseCharacterCorpsesRepository {
e.wc_8 = row[45] ? static_cast<uint32_t>(strtoul(row[45], nullptr, 10)) : 0;
e.wc_9 = row[46] ? static_cast<uint32_t>(strtoul(row[46], nullptr, 10)) : 0;
e.rez_time = row[47] ? static_cast<uint32_t>(strtoul(row[47], nullptr, 10)) : 0;
e.gm_exp = row[48] ? static_cast<uint32_t>(strtoul(row[48], nullptr, 10)) : 0;
e.killed_by = row[49] ? static_cast<uint32_t>(strtoul(row[49], nullptr, 10)) : 0;
e.rezzable = row[50] ? static_cast<uint8_t>(strtoul(row[50], nullptr, 10)) : 1;
e.gm_exp = row[48] ? static_cast<uint32_t>(strtoul(row[48], nullptr, 10)) : 0;
e.killed_by = row[49] ? static_cast<uint32_t>(strtoul(row[49], nullptr, 10)) : 0;
e.rezzable = row[50] ? static_cast<uint8_t>(strtoul(row[50], nullptr, 10)) : 0;

all_entries.push_back(e);
}
Expand Down Expand Up @@ -843,7 +843,7 @@ class BaseCharacterCorpsesRepository {
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "UNIX_TIMESTAMP()") + ")");
v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "null") + ")");
v.push_back(std::to_string(e.guild_consent_id));
v.push_back(std::to_string(e.is_rezzed));
v.push_back(std::to_string(e.is_buried));
Expand Down Expand Up @@ -916,7 +916,7 @@ class BaseCharacterCorpsesRepository {
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "UNIX_TIMESTAMP()") + ")");
v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "null") + ")");
v.push_back(std::to_string(e.guild_consent_id));
v.push_back(std::to_string(e.is_rezzed));
v.push_back(std::to_string(e.is_buried));
Expand Down Expand Up @@ -974,7 +974,6 @@ class BaseCharacterCorpsesRepository {

return (results.Success() ? results.RowsAffected() : 0);
}

};

#endif //EQEMU_BASE_CHARACTER_CORPSES_REPOSITORY_H
10 changes: 7 additions & 3 deletions world/zoneserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,10 +1433,14 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) {
}

auto o = (ServerIsOwnerOnline_Struct*) pack->pBuffer;
auto cle = client_list.FindCharacter(o->name);
auto cle = client_list.FindCLEByAccountID(o->account_id);

o->online = cle ? 1 : 0;


if (o->online) {
LogCorpsesDetail("ServerOP_IsOwnerOnline account_id [{}] found to be online, sending online update to zone_id [{}]", o->account_id, o->zone_id);
}

auto zs = zoneserver_list.FindByZoneID(o->zone_id);
if (zs) {
zs->SendPacket(pack);
Expand Down
45 changes: 19 additions & 26 deletions zone/corpse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ Corpse::Corpse(uint32 in_dbid, uint32 in_charid, const char* in_charname, LootIt
corpse_rez_timer.Disable();
SetRezTimer();

for (int i = 0; i < MAX_LOOTERS; i++){
allowed_looters[i] = 0;
for (int & allowed_looter : allowed_looters){
allowed_looter = 0;
}

SetPlayerKillItemID(0);
Expand Down Expand Up @@ -1033,8 +1033,8 @@ bool Corpse::Process() {
}

if (corpse_delay_timer.Check()) {
for (int i = 0; i < MAX_LOOTERS; i++) {
allowed_looters[i] = 0;
for (int & allowed_looter : allowed_looters) {
allowed_looter = 0;
}
corpse_delay_timer.Disable();
return true;
Expand All @@ -1045,7 +1045,7 @@ bool Corpse::Process() {
corpse_graveyard_timer.Disable();
return false;
}

//Player is offline. If rez timer is enabled, disable it and save corpse.
if (rezzable) {
if (!is_owner_online) {
Expand Down Expand Up @@ -1989,7 +1989,7 @@ bool Corpse::Summon(Client* client, bool spell, bool CheckDistance) {
void Corpse::CompleteResurrection(bool timer_expired)
{
rez_time = corpse_rez_timer.GetRemainingTime();

if (timer_expired) {
rez_time = 0;
rezzable = false; // Players can no longer rez this corpse.
Expand Down Expand Up @@ -2212,26 +2212,19 @@ void Corpse::SetRezTimer(bool initial_timer)

void Corpse::CheckIsOwnerOnline()
{
Client* client = entity_list.GetClientByCharID(GetCharID());

if (!client) {
uint32 account_id = database.GetAccountIDByChar(GetCharID());
client = entity_list.GetClientByAccID(account_id);

if (!client) {
// Client is not in the corpse's zone, send a packet to world to have it check.
auto pack = new ServerPacket(ServerOP_IsOwnerOnline, sizeof(ServerIsOwnerOnline_Struct));
ServerIsOwnerOnline_Struct* online = (ServerIsOwnerOnline_Struct*)pack->pBuffer;
strncpy(online->name, GetOwnerName(), sizeof(online->name));
online->corpse_id = GetID();
online->zone_id = zone->GetZoneID();
online->online = 0;
online->account_id = account_id;
worldserver.SendPacket(pack);
safe_delete(pack);
} else {
SetOwnerOnline(true);
}
Client* c = entity_list.GetClientByCharID(GetCharID());
if (!c) {
// Client is not in the corpse's zone, send a packet to world to have it check.
auto pack = new ServerPacket(ServerOP_IsOwnerOnline, sizeof(ServerIsOwnerOnline_Struct));
auto *o = (ServerIsOwnerOnline_Struct *) pack->pBuffer;
strncpy(o->name, GetOwnerName(), sizeof(o->name));
o->corpse_id = GetID();
o->zone_id = zone->GetZoneID();
o->online = 0;
o->account_id = c->AccountID();
worldserver.SendPacket(pack);
safe_delete(pack);
LogCorpsesDetail("Sent IsOwnerOnline packet to world for [{}]", GetName());
} else {
SetOwnerOnline(true);
}
Expand Down
10 changes: 5 additions & 5 deletions zone/worldserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1276,11 +1276,11 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
break;
}

Corpse* corpse = entity_list.GetCorpseByID(o->corpse_id);
if (corpse && o->online == 1) {
corpse->SetOwnerOnline(true);
} else if (corpse) {
corpse->SetOwnerOnline(false);
Corpse* c = entity_list.GetCorpseByID(o->corpse_id);
if (c && o->online) {
c->SetOwnerOnline(true);
} else if (c) {
c->SetOwnerOnline(false);
}
}
break;
Expand Down

0 comments on commit 57f9ec5

Please sign in to comment.