Core/Commands: Prevent crash upon using .pinfo on characters in unknown areas

Closes #2784
This commit is contained in:
leak
2011-08-30 13:13:59 +02:00
parent 3be7485020
commit d498a5b68f

View File

@@ -408,21 +408,31 @@ bool ChatHandler::HandlePInfoCommand(const char* args)
// Add map, zone, subzone and phase to output
int locale = GetSessionDbcLocale();
std::string areaName = "<unknown>";
std::string zoneName = "";
MapEntry const* map = sMapStore.LookupEntry(mapId);
AreaTableEntry const* area = GetAreaEntryByAreaID(areaId);
AreaTableEntry const* zone = NULL;
if (area)
{
areaName = area->area_name[locale];
AreaTableEntry const* zone = GetAreaEntryByAreaID(area->zone);
if (zone)
zoneName = zone->area_name[locale];
}
if (target)
{
if (AreaTableEntry const* zone = GetAreaEntryByAreaID(area->zone))
PSendSysMessage(LANG_PINFO_MAP_ONLINE, map->name[locale], zone->area_name[locale], area->area_name[locale], phase);
if (!zoneName.empty())
PSendSysMessage(LANG_PINFO_MAP_ONLINE, map->name[locale], zoneName.c_str(), areaName.c_str(), phase);
else
PSendSysMessage(LANG_PINFO_MAP_ONLINE, map->name[locale], area->area_name[locale], "--", phase);
PSendSysMessage(LANG_PINFO_MAP_ONLINE, map->name[locale], areaName.c_str(), "<unknown>", phase);
}
else
PSendSysMessage(LANG_PINFO_MAP_OFFLINE, map->name[locale], area->area_name[locale]);
PSendSysMessage(LANG_PINFO_MAP_OFFLINE, map->name[locale], areaName.c_str());
return true;
}