Small fixes: Titanium overflow, LDoN/alt-currency sell-back, hover respawn, duels (#5127)

This commit is contained in:
straps-eq authored and GitHub committed 2026-11-10 23:48:17 -08:00
1 parent a572b03f56
commit 3c2c684c9d
8 files changed
+142 -18

No files matched your search

+2 -1
View File
@@ -3948,7 +3948,8 @@ std::unique_ptr<EQApplicationPacket> MessageComponent::InterruptSpellOther(Mob*
auto ic = reinterpret_cast<InterruptCast_Struct*>(outapp->pBuffer);
ic->messageid = ResolveID(message);
ic->spawnid = spawn_id;
strcpy(ic->message, spell_link);
// the buffer is sized for the caster name; copying the spell link overflowed it
strcpy(ic->message, name);
return outapp;
}
+6
View File
@@ -2096,6 +2096,12 @@ bool Client::Death(Mob* killer_mob, int64 damage, int32 spell, EQ::skills::Skill
}
}
// Other mobs' close lists hold this client under its current id, which the corpse takes over.
// Drop those entries now: after a hover respawn the client gets a new id, so they would never
// be removed and dangle once the client leaves (crash in Mob::IsCloseToBanker).
entity_list.RemoveMobFromCloseLists(this);
m_close_mobs.clear();
entity_list.AddCorpse(new_corpse, GetID());
SetID(0);
+3
View File
@@ -953,6 +953,8 @@ public:
inline uint32 GetDuelTarget() const { return duel_target; }
inline bool IsDueling() const { return duelaccepted; }
inline void SetDuelTarget(uint32 set_id) { duel_target = set_id; }
inline bool IsDuelChallenger() const { return duel_challenger; }
inline void SetDuelChallenger(bool v) { duel_challenger = v; }
inline void SetDueling(bool duel) { duelaccepted = duel; }
// use this one instead
void MemSpell(int32 spell_id, int slot, bool update_client = true);
@@ -2050,6 +2052,7 @@ private:
bool guild_dirty{ true }; //used to control add/delete opcodes due to client bug in Ti thru RoF2
bool GuildBanker;
uint16 duel_target;
bool duel_challenger = false; // the side that sent the pending OP_RequestDuel
bool duelaccepted;
std::vector<uint32> keyring;
bool tellsoff; // GM /toggle
+51 -13
View File
@@ -2315,12 +2315,9 @@ void Client::Handle_OP_AdventureMerchantSell(const EQApplicationPacket *app)
}
// 06/11/2016 This formula matches RoF2 client side calculation.
uint32 price = EQ::Clamp(
price,
EQ::ClampUpper(
(item->LDoNPrice + 1) * item->LDoNSellBackRate / 100,
item->LDoNPrice
),
// (clamping the uninitialised price itself could refund the full LDoNPrice)
uint32 price = EQ::ClampUpper(
(item->LDoNPrice + 1) * item->LDoNSellBackRate / 100,
item->LDoNPrice
);
@@ -2854,7 +2851,13 @@ void Client::Handle_OP_AltCurrencySell(const EQApplicationPacket *app)
}
DeleteItemInInventory(sell->slot_id, sell->charges);
cost *= sell->charges;
// Handle_OP_AltCurrencyPurchase hands out MaxCharges units for one price, so a stack
// sells back pro rata (multiply first so small prices don't truncate to 0)
if (item->MaxCharges > 1) {
cost = cost * sell->charges / item->MaxCharges;
} else {
cost *= sell->charges;
}
}
sell->cost = cost;
@@ -6013,7 +6016,12 @@ void Client::Handle_OP_DuelDecline(const EQApplicationPacket *app)
Entity* entity = entity_list.GetID(ds->target_id);
Entity* initiator = entity_list.GetID(ds->entity_id);
if (!entity->IsClient() || !initiator->IsClient()) {
if (!entity || !initiator || !entity->IsClient() || !initiator->IsClient()) {
return;
}
// a decline must not cancel a duel that is already in progress
if (entity->CastToClient()->IsDueling() || initiator->CastToClient()->IsDueling()) {
return;
}
@@ -6021,11 +6029,8 @@ void Client::Handle_OP_DuelDecline(const EQApplicationPacket *app)
entity->CastToClient()->SetDueling(false);
initiator->CastToClient()->SetDuelTarget(0);
initiator->CastToClient()->SetDueling(false);
if (GetID() == initiator->GetID()) {
entity->CastToClient()->MessageString(Chat::NPCQuestSay, DUEL_DECLINE, initiator->GetName());
} else {
initiator->CastToClient()->MessageString(Chat::NPCQuestSay, DUEL_DECLINE, entity->GetName());
}
Client* other = (GetID() == initiator->GetID()) ? entity->CastToClient() : initiator->CastToClient();
other->MessageString(Chat::NPCQuestSay, DUEL_DECLINE, GetName());
return;
}
@@ -13602,6 +13607,32 @@ void Client::Handle_OP_RequestDuel(const EQApplicationPacket *app)
ds->duel_initiator = ds->duel_target;
ds->duel_target = duel;
Entity* entity = entity_list.GetID(ds->duel_target);
if (!entity) {
safe_delete(outapp);
return;
}
// The challenged player may answer with /duel, which sends OP_RequestDuel back to the challenger
// (no OP_DuelAccept follows). Only the challenged side's request is an accept; the challenger
// repeating /duel must not start the duel for the other player.
if (
GetID() != ds->duel_target &&
entity->IsClient() &&
!IsDueling() &&
!entity->CastToClient()->IsDueling() &&
!IsDuelChallenger() &&
entity->CastToClient()->IsDuelChallenger() &&
GetDuelTarget() == entity->GetID() &&
entity->CastToClient()->GetDuelTarget() == GetID()
) {
safe_delete(outapp);
EQApplicationPacket accept(OP_DuelAccept, sizeof(Duel_Struct));
auto as = (Duel_Struct *) accept.pBuffer;
as->duel_initiator = entity->GetID();
as->duel_target = GetID();
Handle_OP_DuelAccept(&accept);
return;
}
if (
GetID() != ds->duel_target &&
@@ -13628,6 +13659,8 @@ void Client::Handle_OP_RequestDuel(const EQApplicationPacket *app)
) {
SetDuelTarget(ds->duel_target);
entity->CastToClient()->SetDuelTarget(GetID());
SetDuelChallenger(true);
entity->CastToClient()->SetDuelChallenger(false);
ds->duel_target = ds->duel_initiator;
entity->CastToClient()->FastQueuePacket(&outapp);
entity->CastToClient()->SetDueling(false);
@@ -13662,6 +13695,11 @@ void Client::Handle_OP_RespawnWindow(const EQApplicationPacket *app)
}
char *Buffer = (char *)app->pBuffer;
// ignore repeat clicks after the player has already respawned
if (!IsHoveringForRespawn()) {
return;
}
uint32 Option = VARSTRUCT_DECODE_TYPE(uint32, Buffer);
HandleRespawnFromHover(Option);
}
+12 -1
View File
@@ -2242,6 +2242,10 @@ void Client::HandleRespawnFromHover(uint32 Option)
FastQueuePacket(&outapp);
// Client::SetMaxHP does nothing while dead is set, and ClearHover only clears it below,
// so the respawn kept the death HP and the client bled out again.
dead = false;
CalcBonuses();
RestoreHealth();
RestoreMana();
@@ -2287,7 +2291,13 @@ void Client::HandleRespawnFromHover(uint32 Option)
Save();
MovePC(chosen->zone_id, chosen->instance_id, chosen->x, chosen->y, chosen->z, chosen->heading, 1);
// The bind choice goes through the normal death-to-bind path, which sends OP_ZonePlayerToBind:
// that packet is what closes the respawn window on newer clients.
if (Option == 0 || default_to_bind) {
MovePC(chosen->zone_id, chosen->instance_id, chosen->x, chosen->y, chosen->z, chosen->heading, 1, ZoneToBindPoint);
} else {
MovePC(chosen->zone_id, chosen->instance_id, chosen->x, chosen->y, chosen->z, chosen->heading, 1);
}
}
safe_delete(default_to_bind);
@@ -2297,6 +2307,7 @@ void Client::ClearHover()
{
// Our Entity ID is currently zero, set in Client::Death
SetID(entity_list.GetFreeID());
entity_list.ReKeyClient(this);
auto outapp = new EQApplicationPacket(OP_ZoneEntry, sizeof(ServerZoneEntry_Struct));
ServerZoneEntry_Struct* sze = (ServerZoneEntry_Struct*)outapp->pBuffer;
+60 -3
View File
@@ -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();
+2
View File
@@ -545,6 +545,7 @@ public:
inline const std::unordered_map<uint16, NPC *> &GetNPCList() { return npc_list; }
inline const std::unordered_map<uint16, Merc *> &GetMercList() { return merc_list; }
inline const std::unordered_map<uint16, Client *> &GetClientList() { return client_list; }
void ReKeyClient(Client *c);
inline const std::unordered_map<uint16, Bot*> &GetBotList() { return bot_list; }
std::vector<Bot *> GetBotListByCharacterID(uint32 character_id, uint8 class_id = Class::None);
std::vector<Bot *> GetBotListByClientName(std::string client_name, uint8 class_id = Class::None);
@@ -599,6 +600,7 @@ private:
std::unordered_map<uint16, Client *> client_list;
std::unordered_map<uint16, Mob *> mob_list;
uint32 mob_list_erasures = 0; // bumped on every mob_list erase, so MobProcess can tell its iterator may be stale
std::unordered_map<uint16, NPC *> npc_list;
std::unordered_map<uint16, Merc *> merc_list;
std::unordered_map<uint16, Corpse *> corpse_list;
+6
View File
@@ -298,6 +298,12 @@ void Mob::DoSpecialAttackDamage(Mob *who, EQ::skills::SkillType skill, int32 bas
DoAttack(who, my_hit);
// a riposte can kill the attacker inside DoAttack (NPC::Attack guards the same way);
// going on sent OP_Damage with source id 0
if (HasDied() || !GetID()) {
return;
}
who->AddToHateList(this, hate, 0);
who->Damage(this, my_hit.damage_done, SPELL_UNKNOWN, skill, false);