mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-11 16:51:29 +00:00
[Crash] Stability Fixes (#2489)
* Input sanitation for #zone * Update zone.cpp * Update clientlist.cpp * Test * Test * Remove logging, revert /who all code * Remove log * Update clientlist.cpp
This commit is contained in:
parent
bbbebdd346
commit
7092183103
@ -82,22 +82,6 @@ const char *ZoneStore::GetZoneName(uint32 zone_id, bool error_unknown)
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
LogInfo(
|
||||
"[GetZoneName] Failed to get zone name by zone_id [{}] error_unknown [{}] printing stack",
|
||||
zone_id,
|
||||
(error_unknown ? "true" : "false")
|
||||
);
|
||||
|
||||
|
||||
// print stack when invalid input
|
||||
if (zone_id == 0) {
|
||||
backward::StackTrace st;
|
||||
backward::TraceResolver e = {};
|
||||
st.load_here(32);
|
||||
backward::Printer p;
|
||||
p.print(st);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -118,12 +102,6 @@ const char *ZoneStore::GetZoneLongName(uint32 zone_id, bool error_unknown)
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
LogInfo(
|
||||
"[GetZoneLongName] Failed to get zone long name by zone_id [{}] error_unknown [{}]",
|
||||
zone_id,
|
||||
(error_unknown ? "true" : "false")
|
||||
);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -196,6 +174,17 @@ ZoneRepository::Zone *ZoneStore::GetZone(const char *in_zone_name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ZoneRepository::Zone *ZoneStore::GetZone(std::string in_zone_name)
|
||||
{
|
||||
for (auto &z: m_zones) {
|
||||
if (z.short_name == in_zone_name) {
|
||||
return &z;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const std::vector<ZoneRepository::Zone> &ZoneStore::GetZones() const
|
||||
{
|
||||
return m_zones;
|
||||
|
||||
@ -35,6 +35,7 @@ public:
|
||||
|
||||
ZoneRepository::Zone *GetZone(uint32 zone_id, int version = 0);
|
||||
ZoneRepository::Zone *GetZone(const char *in_zone_name);
|
||||
ZoneRepository::Zone *GetZone(std::string in_zone_name);
|
||||
uint32 GetZoneID(const char *in_zone_name);
|
||||
uint32 GetZoneID(std::string zone_name);
|
||||
std::string GetZoneName(uint32 zone_id);
|
||||
|
||||
@ -8,5 +8,14 @@ void WorldserverCLI::TestCommand(int argc, char **argv, argh::parser &cmd, std::
|
||||
return;
|
||||
}
|
||||
|
||||
zone_store.GetZoneName(0, false);
|
||||
zone_store.LoadZones(database);
|
||||
|
||||
const char* zonename = ZoneName(0);
|
||||
if (zonename == 0) {
|
||||
LogInfo("Zone name is 0");
|
||||
}
|
||||
if (zonename == nullptr) {
|
||||
LogInfo("Zone name is nullptr");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -686,8 +686,8 @@ void ClientList::SendWhoAll(uint32 fromid,const char* to, int16 admin, Who_All_S
|
||||
int idx=-1;
|
||||
while(iterator.MoreElements()) {
|
||||
cle = iterator.GetData();
|
||||
|
||||
const char* tmpZone = ZoneName(cle->zone());
|
||||
|
||||
if (
|
||||
(cle->Online() >= CLE_Status::Zoning) &&
|
||||
(!cle->GetGM() || cle->Anon() != 1 || admin >= cle->Admin()) &&
|
||||
|
||||
@ -8,9 +8,38 @@ void command_zone(Client *c, const Seperator *sep)
|
||||
return;
|
||||
}
|
||||
|
||||
std::string zone_identifier = sep->arg[1];
|
||||
// input: (first arg)
|
||||
// zone identifier can be a string of a zone name or its ID
|
||||
std::string zone_input = sep->arg[1];
|
||||
uint32 zone_id = 0;
|
||||
|
||||
if (Strings::IsNumber(zone_identifier) && zone_identifier == "0") {
|
||||
// if input is id
|
||||
if (Strings::IsNumber(zone_input)) {
|
||||
zone_id = std::stoi(zone_input);
|
||||
|
||||
// validate
|
||||
if (!GetZone(zone_id)) {
|
||||
c->Message(Chat::White, fmt::format("Could not find zone by id [{}]", zone_id).c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// validate
|
||||
if (!zone_store.GetZone(zone_input)) {
|
||||
c->Message(Chat::White, fmt::format("Could not find zone by short_name [{}]", zone_input).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// validate we got id
|
||||
zone_id = ZoneID(zone_input);
|
||||
if (zone_id == 0) {
|
||||
c->Message(Chat::White, fmt::format("Could not find zone id by short_name [{}]", zone_input).c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// if zone identifier is a number and the id is 0, send to safe coordinates of the local zone
|
||||
if (Strings::IsNumber(zone_input) && zone_id == 0) {
|
||||
c->Message(Chat::White, "Sending you to the safe coordinates of this zone.");
|
||||
|
||||
c->MovePC(
|
||||
@ -24,23 +53,7 @@ void command_zone(Client *c, const Seperator *sep)
|
||||
return;
|
||||
}
|
||||
|
||||
auto zone_id = (
|
||||
sep->IsNumber(1) ?
|
||||
std::stoul(zone_identifier) :
|
||||
ZoneID(zone_identifier)
|
||||
);
|
||||
auto zone_short_name = ZoneName(zone_id);
|
||||
if (!zone_id || !zone_short_name) {
|
||||
c->Message(
|
||||
Chat::White,
|
||||
fmt::format(
|
||||
"No zones were found matching '{}'.",
|
||||
zone_identifier
|
||||
).c_str()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// status checking
|
||||
auto min_status = content_db.GetMinStatus(zone_id, 0);
|
||||
if (c->Admin() < min_status) {
|
||||
c->Message(Chat::White, "Your status is not high enough to go to this zone.");
|
||||
@ -54,12 +67,18 @@ void command_zone(Client *c, const Seperator *sep)
|
||||
}
|
||||
#endif
|
||||
|
||||
auto x = sep->IsNumber(2) ? std::stof(sep->arg[2]) : 0.0f;
|
||||
auto y = sep->IsNumber(3) ? std::stof(sep->arg[3]) : 0.0f;
|
||||
auto z = sep->IsNumber(4) ? std::stof(sep->arg[4]) : 0.0f;
|
||||
auto zone_mode = sep->IsNumber(2) ? ZoneSolicited : ZoneToSafeCoords;
|
||||
// fetch zone data
|
||||
auto zd = GetZoneVersionWithFallback(zone_id, 0);
|
||||
if (zone_id == 0) {
|
||||
c->Message(Chat::White, fmt::format("Failed to find zone with fallback [{}]", zone_id).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto zd = GetZone(zone_id);
|
||||
// coordinates
|
||||
auto x = sep->IsNumber(2) ? std::stof(sep->arg[2]) : 0.0f;
|
||||
auto y = sep->IsNumber(3) ? std::stof(sep->arg[3]) : 0.0f;
|
||||
auto z = sep->IsNumber(4) ? std::stof(sep->arg[4]) : 0.0f;
|
||||
auto zone_mode = sep->IsNumber(2) ? ZoneSolicited : ZoneToSafeCoords;
|
||||
|
||||
c->MovePC(
|
||||
zone_id,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user