[Targeting] Fix bug when using /tar on invalid target (#3407)

* [Targetting] Fix bug when using /tar on invalid target

* Removed instrumentation.
This commit is contained in:
Paul Coene 2023-06-17 17:53:59 -04:00 committed by GitHub
parent 0cf454dc29
commit 1100668f21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14414,6 +14414,46 @@ void Client::Handle_OP_SwapSpell(const EQApplicationPacket *app)
}
void Client::Handle_OP_TargetCommand(const EQApplicationPacket *app)
{
if (app->size != sizeof(ClientTarget_Struct)) {
LogError("OP size error: OP_TargetCommand expected:[{}] got:[{}]", sizeof(ClientTarget_Struct), app->size);
return;
}
// Locate and cache new target
ClientTarget_Struct* ct = (ClientTarget_Struct*)app->pBuffer;
bool can_target=false;
Mob *nt = entity_list.GetMob(ct->new_target);
if (nt) {
if (GetGM() || (!nt->IsInvisible(this) && (DistanceSquared(m_Position, nt->GetPosition()) <= TARGETING_RANGE*TARGETING_RANGE))) {
if (nt->GetBodyType() == BT_NoTarget2 ||
nt->GetBodyType() == BT_Special ||
nt->GetBodyType() == BT_NoTarget) {
can_target = false;
}
else {
can_target = true;
}
}
}
if (can_target) {
QueuePacket(app);
}
else {
MessageString(Chat::Red, DONT_SEE_TARGET);
auto outapp = new EQApplicationPacket(OP_TargetReject, sizeof(TargetReject_Struct));
outapp->pBuffer[0] = 0x2f;
outapp->pBuffer[1] = 0x01;
outapp->pBuffer[4] = 0x0d;
QueuePacket(outapp);
safe_delete(outapp);
}
}
void Client::Handle_OP_TargetMouse(const EQApplicationPacket *app)
{
if (app->size != sizeof(ClientTarget_Struct)) {
LogError("OP size error: OP_TargetMouse expected:[{}] got:[{}]", sizeof(ClientTarget_Struct), app->size);
@ -14510,157 +14550,108 @@ void Client::Handle_OP_TargetCommand(const EQApplicationPacket *app)
if (g && g->HasRole(this, RolePuller))
g->SetGroupPullerTarget(GetTarget());
// For /target, send reject or success packet
if (app->GetOpcode() == OP_TargetCommand) {
if (GetTarget() && !GetTarget()->CastToMob()->IsInvisible(this) && (DistanceSquared(m_Position, GetTarget()->GetPosition()) <= TARGETING_RANGE*TARGETING_RANGE || GetGM())) {
if (GetTarget()->GetBodyType() == BT_NoTarget2 || GetTarget()->GetBodyType() == BT_Special
|| GetTarget()->GetBodyType() == BT_NoTarget)
{
//Targeting something we shouldn't with /target
//but the client allows this without MQ so you don't flag it
auto outapp = new EQApplicationPacket(OP_TargetReject, sizeof(TargetReject_Struct));
outapp->pBuffer[0] = 0x2f;
outapp->pBuffer[1] = 0x01;
outapp->pBuffer[4] = 0x0d;
if (GetTarget())
{
SetTarget(nullptr);
}
QueuePacket(outapp);
safe_delete(outapp);
return;
}
QueuePacket(app);
GetTarget()->IsTargeted(1);
SendHPUpdate();
}
else
{
auto outapp = new EQApplicationPacket(OP_TargetReject, sizeof(TargetReject_Struct));
outapp->pBuffer[0] = 0x2f;
outapp->pBuffer[1] = 0x01;
outapp->pBuffer[4] = 0x0d;
if (GetTarget())
{
SetTarget(nullptr);
}
QueuePacket(outapp);
safe_delete(outapp);
}
}
else
if (GetTarget())
{
if (GetTarget())
if (GetGM())
{
if (GetGM())
{
GetTarget()->IsTargeted(1);
return;
}
else if (RuleB(Character, AllowMQTarget))
{
GetTarget()->IsTargeted(1);
return;
}
else if (cheat_manager.GetExemptStatus(Assist)) {
GetTarget()->IsTargeted(1);
cheat_manager.SetExemptStatus(Assist, false);
return;
}
else if (GetTarget()->IsClient())
{
//make sure this client is in our raid/group
GetTarget()->IsTargeted(1);
return;
}
else if (GetTarget()->GetBodyType() == BT_NoTarget2 || GetTarget()->GetBodyType() == BT_Special
|| GetTarget()->GetBodyType() == BT_NoTarget)
{
auto message = fmt::format(
"[{}] attempting to target something untargetable [{}] bodytype [{}]",
GetName(),
GetTarget()->GetName(),
(int) GetTarget()->GetBodyType()
);
RecordPlayerEventLog(PlayerEvent::POSSIBLE_HACK, PlayerEvent::PossibleHackEvent{.message = message});
GetTarget()->IsTargeted(1);
return;
}
else if (RuleB(Character, AllowMQTarget))
{
GetTarget()->IsTargeted(1);
return;
}
else if (cheat_manager.GetExemptStatus(Assist)) {
GetTarget()->IsTargeted(1);
cheat_manager.SetExemptStatus(Assist, false);
return;
}
else if (GetTarget()->IsClient())
{
//make sure this client is in our raid/group
GetTarget()->IsTargeted(1);
return;
}
else if (GetTarget()->GetBodyType() == BT_NoTarget2 || GetTarget()->GetBodyType() == BT_Special
|| GetTarget()->GetBodyType() == BT_NoTarget)
{
auto message = fmt::format(
"[{}] attempting to target something untargetable [{}] bodytype [{}]",
GetName(),
GetTarget()->GetName(),
(int) GetTarget()->GetBodyType()
);
RecordPlayerEventLog(PlayerEvent::POSSIBLE_HACK, PlayerEvent::PossibleHackEvent{.message = message});
SetTarget((Mob*)nullptr);
return;
}
else if (cheat_manager.GetExemptStatus(Port)) {
GetTarget()->IsTargeted(1);
return;
}
else if (cheat_manager.GetExemptStatus(Sense)) {
GetTarget()->IsTargeted(1);
cheat_manager.SetExemptStatus(Sense, false);
return;
}
else if (IsXTarget(GetTarget()))
SetTarget((Mob*)nullptr);
return;
}
else if (cheat_manager.GetExemptStatus(Port)) {
GetTarget()->IsTargeted(1);
return;
}
else if (cheat_manager.GetExemptStatus(Sense)) {
GetTarget()->IsTargeted(1);
cheat_manager.SetExemptStatus(Sense, false);
return;
}
else if (IsXTarget(GetTarget()))
{
GetTarget()->IsTargeted(1);
return;
}
else if (GetTarget()->IsPetOwnerClient())
{
GetTarget()->IsTargeted(1);
return;
}
else if (GetBindSightTarget())
{
if (DistanceSquared(GetBindSightTarget()->GetPosition(), GetTarget()->GetPosition()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip))
{
GetTarget()->IsTargeted(1);
return;
}
else if (GetTarget()->IsPetOwnerClient())
{
GetTarget()->IsTargeted(1);
return;
}
else if (GetBindSightTarget())
{
if (DistanceSquared(GetBindSightTarget()->GetPosition(), GetTarget()->GetPosition()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip))
if (DistanceSquared(m_Position, GetTarget()->GetPosition()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip))
{
if (DistanceSquared(m_Position, GetTarget()->GetPosition()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip))
{
auto message = fmt::format(
"[{}] attempting to target something beyond the clip plane of {:.2f} "
"units, from ({:.2f}, {:.2f}, {:.2f}) to {} ({:.2f}, {:.2f}, "
"{:.2f})",
GetName(),
(zone->newzone_data.maxclip * zone->newzone_data.maxclip), GetX(),
GetY(), GetZ(), GetTarget()->GetName(), GetTarget()->GetX(),
GetTarget()->GetY(), GetTarget()->GetZ());
auto message = fmt::format(
"[{}] attempting to target something beyond the clip plane of {:.2f} "
"units, from ({:.2f}, {:.2f}, {:.2f}) to {} ({:.2f}, {:.2f}, "
"{:.2f})",
GetName(),
(zone->newzone_data.maxclip * zone->newzone_data.maxclip), GetX(),
GetY(), GetZ(), GetTarget()->GetName(), GetTarget()->GetX(),
GetTarget()->GetY(), GetTarget()->GetZ());
RecordPlayerEventLog(PlayerEvent::POSSIBLE_HACK, PlayerEvent::PossibleHackEvent{.message = message});
SetTarget(nullptr);
return;
}
RecordPlayerEventLog(PlayerEvent::POSSIBLE_HACK, PlayerEvent::PossibleHackEvent{.message = message});
SetTarget(nullptr);
return;
}
}
else if (DistanceSquared(m_Position, GetTarget()->GetPosition()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip))
{
auto message = fmt::format(
"{} attempting to target something beyond the clip plane of {:.2f} "
"units, from ({:.2f}, {:.2f}, {:.2f}) to {} ({:.2f}, {:.2f}, {:.2f})",
GetName(),
(zone->newzone_data.maxclip * zone->newzone_data.maxclip),
GetX(),
GetY(),
GetZ(),
GetTarget()->GetName(),
GetTarget()->GetX(),
GetTarget()->GetY(),
GetTarget()->GetZ()
);
RecordPlayerEventLog(PlayerEvent::POSSIBLE_HACK, PlayerEvent::PossibleHackEvent{.message = message});
SetTarget(nullptr);
return;
}
GetTarget()->IsTargeted(1);
}
else if (DistanceSquared(m_Position, GetTarget()->GetPosition()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip))
{
auto message = fmt::format(
"{} attempting to target something beyond the clip plane of {:.2f} "
"units, from ({:.2f}, {:.2f}, {:.2f}) to {} ({:.2f}, {:.2f}, {:.2f})",
GetName(),
(zone->newzone_data.maxclip * zone->newzone_data.maxclip),
GetX(),
GetY(),
GetZ(),
GetTarget()->GetName(),
GetTarget()->GetX(),
GetTarget()->GetY(),
GetTarget()->GetZ()
);
RecordPlayerEventLog(PlayerEvent::POSSIBLE_HACK, PlayerEvent::PossibleHackEvent{.message = message});
SetTarget(nullptr);
return;
}
GetTarget()->IsTargeted(1);
}
return;
}
void Client::Handle_OP_TargetMouse(const EQApplicationPacket *app)
{
Handle_OP_TargetCommand(app);
}
void Client::Handle_OP_TaskHistoryRequest(const EQApplicationPacket *app)
{