[Bug Fix] Fix Unescaped String in Client::GotoPlayer (#4373)

* [Bug Fix] Fix Unescaped String in Client::GotoPlayer

* Final

* Update client.cpp
This commit is contained in:
Alex King 2024-06-01 17:09:00 -04:00 committed by GitHub
parent 217a80ee76
commit 4ca724956b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 73 additions and 51 deletions

View File

@ -9170,29 +9170,32 @@ void Client::SetSecondaryWeaponOrnamentation(uint32 model_id)
* *
* @param player_name * @param player_name
*/ */
bool Client::GotoPlayer(std::string player_name) bool Client::GotoPlayer(const std::string& player_name)
{ {
const auto& l = CharacterDataRepository::GetWhere( const auto& l = CharacterDataRepository::GetWhere(
database, database,
fmt::format("name = '{}' AND last_login > (UNIX_TIMESTAMP() - 600) LIMIT 1", player_name) fmt::format(
"name = '{}' AND last_login > (UNIX_TIMESTAMP() - 600) LIMIT 1",
Strings::Escape(player_name)
)
); );
if (l.empty()) { if (l.empty()) {
return false; return false;
} }
const auto& c = l[0]; const auto& e = l.front();
if (c.zone_instance > 0 && !database.CheckInstanceExists(c.zone_instance)) { if (e.zone_instance > 0 && !database.CheckInstanceExists(e.zone_instance)) {
Message(Chat::Yellow, "Instance no longer exists..."); Message(Chat::Yellow, "Instance no longer exists...");
return false; return false;
} }
if (c.zone_instance > 0) { if (e.zone_instance > 0) {
database.AddClientToInstance(c.zone_instance, CharacterID()); database.AddClientToInstance(e.zone_instance, CharacterID());
} }
MovePC(c.zone_id, c.zone_instance, c.x, c.y, c.z, c.heading); MovePC(e.zone_id, e.zone_instance, e.x, e.y, e.z, e.heading);
return true; return true;
} }

View File

@ -258,7 +258,7 @@ public:
void SendChatLineBreak(uint16 color = Chat::White); void SendChatLineBreak(uint16 color = Chat::White);
bool GotoPlayer(std::string player_name); bool GotoPlayer(const std::string& player_name);
bool GotoPlayerGroup(const std::string& player_name); bool GotoPlayerGroup(const std::string& player_name);
bool GotoPlayerRaid(const std::string& player_name); bool GotoPlayerRaid(const std::string& player_name);

View File

@ -2,63 +2,82 @@
void command_goto(Client *c, const Seperator *sep) void command_goto(Client *c, const Seperator *sep)
{ {
std::string arg1 = sep->arg[1]; const uint16 arguments = sep->argnum;
std::string arg4 = sep->arg[4];
bool goto_via_target_no_args = sep->arg[1][0] == '\0' && c->GetTarget(); const bool goto_player = !sep->IsNumber(1) && sep->arg[1];
bool goto_via_player_name = !sep->IsNumber(1) && !arg1.empty(); const bool goto_position = sep->IsNumber(1) && sep->IsNumber(2) && sep->IsNumber(3);
bool goto_via_x_y_z = sep->IsNumber(1) && sep->IsNumber(2) && sep->IsNumber(3); const bool goto_target = !arguments && c->GetTarget();
if (goto_via_target_no_args) { if (!goto_player && !goto_position && !goto_target) {
c->MovePC( c->Message(Chat::White, "Usage: #goto [x y z] [h]");
zone->GetZoneID(), c->Message(Chat::White, "Usage: #goto [player_name]");
zone->GetInstanceID(), c->Message(Chat::White, "Usage: #goto (Target required)");
c->GetTarget()->GetX(), return;
c->GetTarget()->GetY(),
c->GetTarget()->GetZ(),
c->GetTarget()->GetHeading()
);
} }
else if (goto_via_player_name) {
/** if (goto_player) {
* Find them in zone first const std::string& name = sep->arg[1];
*/ Client* t = entity_list.GetClientByName(name.c_str());
const char *player_name = sep->arg[1]; if (t) {
std::string player_name_string = sep->arg[1];
Client *client = entity_list.GetClientByName(player_name);
if (client) {
c->MovePC( c->MovePC(
zone->GetZoneID(), zone->GetZoneID(),
zone->GetInstanceID(), zone->GetInstanceID(),
client->GetX(), t->GetX(),
client->GetY(), t->GetY(),
client->GetZ(), t->GetZ(),
client->GetHeading() t->GetHeading()
); );
c->Message(Chat::Yellow, "Goto player '%s' same zone", player_name_string.c_str()); c->Message(
Chat::White,
fmt::format(
"Going to player {} in the same zone.",
name
).c_str()
);
} else if (c->GotoPlayer(name)) {
c->Message(
Chat::White,
fmt::format(
"Going to player {} in a different zone.",
name
).c_str()
);
} else {
c->Message(
Chat::White,
fmt::format(
"Player {} could not be found.",
name
).c_str()
);
} }
else if (c->GotoPlayer(player_name_string)) { } else if (goto_position) {
c->Message(Chat::Yellow, "Goto player '%s' different zone", player_name_string.c_str()); const glm::vec4& position = glm::vec4(
}
else {
c->Message(Chat::Yellow, "Player '%s' not found", player_name_string.c_str());
}
}
else if (goto_via_x_y_z) {
c->MovePC(
zone->GetZoneID(),
zone->GetInstanceID(),
Strings::ToFloat(sep->arg[1]), Strings::ToFloat(sep->arg[1]),
Strings::ToFloat(sep->arg[2]), Strings::ToFloat(sep->arg[2]),
Strings::ToFloat(sep->arg[3]), Strings::ToFloat(sep->arg[3]),
(!arg4.empty() ? Strings::ToFloat(sep->arg[4]) : c->GetHeading()) sep->arg[4] && Strings::IsFloat(sep->arg[4]) ? Strings::ToFloat(sep->arg[1]) : c->GetHeading()
);
c->MovePC(
zone->GetZoneID(),
zone->GetInstanceID(),
position.x,
position.y,
position.z,
position.w
);
} else if (goto_target) {
Mob* t = c->GetTarget();
c->MovePC(
zone->GetZoneID(),
zone->GetInstanceID(),
t->GetX(),
t->GetY(),
t->GetZ(),
t->GetHeading()
); );
}
else {
c->Message(Chat::White, "Usage: #goto [x y z] [h]");
c->Message(Chat::White, "Usage: #goto [player_name]");
} }
} }