mirror of
https://github.com/EQEmu/Server.git
synced 2026-11-23 04:37:16 +00:00
Small fixes: Titanium overflow, LDoN/alt-currency sell-back, hover respawn, duels (#5127)
This commit is contained in:
1 parent
a572b03f56
commit
3c2c684c9d
8 files changed
+142
-18
No files matched your search
+60
-3
@@ -464,6 +464,7 @@ void EntityList::MobProcess()
|
||||
Mob *mob = it->second;
|
||||
|
||||
size_t sz = mob_list.size();
|
||||
const uint32 erasures = mob_list_erasures;
|
||||
|
||||
static int old_client_count = 0;
|
||||
static Timer *mob_settle_timer = new Timer();
|
||||
@@ -527,7 +528,27 @@ void EntityList::MobProcess()
|
||||
|
||||
size_t a_sz = mob_list.size();
|
||||
|
||||
if (a_sz > sz) {
|
||||
if (erasures != mob_list_erasures) {
|
||||
// An entry was erased while this mob processed (a client re-keyed on respawn from hover, a mob
|
||||
// removed by a script or by a new NPC taking its name), so the iterator may point at a freed node.
|
||||
// Find our place again; if the mob itself is gone there is nothing left to clean up.
|
||||
auto found = mob_list.find(id);
|
||||
if (found == mob_list.end() || found->second != mob) {
|
||||
for (found = mob_list.begin(); found != mob_list.end(); ++found) {
|
||||
if (found->second == mob) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (found == mob_list.end()) {
|
||||
mob_dead = false;
|
||||
it = mob_list.begin();
|
||||
} else {
|
||||
id = found->first;
|
||||
it = std::next(found);
|
||||
}
|
||||
} else if (a_sz > sz) {
|
||||
//increased size can potentially screw with iterators so reset it to current value
|
||||
//if buckets are re-orderered we may skip a process here and there but since
|
||||
//process happens so often it shouldn't matter much
|
||||
@@ -1097,7 +1118,8 @@ Entity *EntityList::GetEntityEncounter(uint16 id)
|
||||
Entity *EntityList::GetID(uint16 get_id)
|
||||
{
|
||||
Entity *ent = 0;
|
||||
if ((ent = entity_list.GetEntityMob(get_id)) != 0)
|
||||
// skip a stale mob_list key left by a client hovering for respawn (its corpse owns this id now)
|
||||
if ((ent = entity_list.GetEntityMob(get_id)) != 0 && ent->GetID() == get_id)
|
||||
return ent;
|
||||
else if ((ent=entity_list.GetEntityDoor(get_id)) != 0)
|
||||
return ent;
|
||||
@@ -1153,7 +1175,10 @@ Mob *EntityList::GetMob(uint16 get_id)
|
||||
if (get_id == 0)
|
||||
return nullptr;
|
||||
|
||||
if ((ent = entity_list.GetEntityMob(get_id)))
|
||||
// A client hovering after death (Character:RespawnFromHover) stays in mob_list under its old id
|
||||
// with GetID() == 0, while its corpse takes that id. Skip the stale entry so the corpse is found
|
||||
// (otherwise targeting the corpse targets the dead player and rez fails with "only works on corpses").
|
||||
if ((ent = entity_list.GetEntityMob(get_id)) && ent->GetID() == get_id)
|
||||
return ent->CastToMob();
|
||||
else if ((ent = entity_list.GetEntityCorpse(get_id)))
|
||||
return ent->CastToMob();
|
||||
@@ -2643,6 +2668,7 @@ void EntityList::RemoveAllMobs()
|
||||
safe_delete(it->second);
|
||||
free_ids.push(it->first);
|
||||
it = mob_list.erase(it);
|
||||
mob_list_erasures++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2791,6 +2817,7 @@ bool EntityList::RemoveMob(uint16 delete_id)
|
||||
free_ids.push(it->first);
|
||||
}
|
||||
mob_list.erase(it);
|
||||
mob_list_erasures++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -2821,6 +2848,36 @@ bool EntityList::RemoveNPC(uint16 delete_id)
|
||||
* @param mob
|
||||
* @return
|
||||
*/
|
||||
// A client's id changes around a respawn-from-hover (Client::Death sets 0 and the corpse takes the old id,
|
||||
// ClearHover assigns a new one). Move its mob_list/client_list entries to the current id so lookups find it.
|
||||
void EntityList::ReKeyClient(Client *c)
|
||||
{
|
||||
if (!c || c->GetID() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto it = mob_list.begin(); it != mob_list.end(); ++it) {
|
||||
if (it->second == c) {
|
||||
if (it->first != c->GetID()) {
|
||||
mob_list.erase(it);
|
||||
mob_list_erasures++;
|
||||
mob_list[c->GetID()] = c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = client_list.begin(); it != client_list.end(); ++it) {
|
||||
if (it->second == c) {
|
||||
if (it->first != c->GetID()) {
|
||||
client_list.erase(it);
|
||||
client_list[c->GetID()] = c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool EntityList::RemoveMobFromCloseLists(Mob *mob)
|
||||
{
|
||||
uint16 entity_id = mob->GetID() > 0 ? mob->GetID() : mob->GetInitialId();
|
||||
|
||||
Reference in new issue
Block a user