[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) 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)) { if (app->size != sizeof(ClientTarget_Struct)) {
LogError("OP size error: OP_TargetMouse expected:[{}] got:[{}]", sizeof(ClientTarget_Struct), app->size); LogError("OP size error: OP_TargetMouse expected:[{}] got:[{}]", sizeof(ClientTarget_Struct), app->size);
@ -14510,48 +14550,6 @@ void Client::Handle_OP_TargetCommand(const EQApplicationPacket *app)
if (g && g->HasRole(this, RolePuller)) if (g && g->HasRole(this, RolePuller))
g->SetGroupPullerTarget(GetTarget()); 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())
@ -14652,15 +14650,8 @@ void Client::Handle_OP_TargetCommand(const EQApplicationPacket *app)
GetTarget()->IsTargeted(1); GetTarget()->IsTargeted(1);
} }
}
return; return;
} }
void Client::Handle_OP_TargetMouse(const EQApplicationPacket *app)
{
Handle_OP_TargetCommand(app);
}
void Client::Handle_OP_TaskHistoryRequest(const EQApplicationPacket *app) void Client::Handle_OP_TaskHistoryRequest(const EQApplicationPacket *app)
{ {