Fix some potential null pointer dereferences

I don't think there were any instances of these causing problems
but it's better to be safe than sorry.
This commit is contained in:
Michael Cook (mackal) 2014-01-14 02:38:49 -05:00
parent 4216627604
commit 53765ebc62

View File

@ -648,31 +648,31 @@ void QuestManager::repopzone() {
void QuestManager::settarget(const char *type, int target_id) { void QuestManager::settarget(const char *type, int target_id) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
Mob* tmp = nullptr; Mob* tmp = nullptr;
if (!strcasecmp(type,"npctype")) { if (!strcasecmp(type,"npctype"))
tmp = entity_list.GetMobByNpcTypeID(target_id); tmp = entity_list.GetMobByNpcTypeID(target_id);
} else if (!strcasecmp(type, "entity"))
else if (!strcasecmp(type, "entity")) {
tmp = entity_list.GetMob(target_id); tmp = entity_list.GetMob(target_id);
}
if(tmp != nullptr) { if (tmp != nullptr)
owner->SetTarget(tmp); owner->SetTarget(tmp);
}
} }
void QuestManager::follow(int entity_id, int distance) { void QuestManager::follow(int entity_id, int distance) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
owner->SetFollowID(entity_id); owner->SetFollowID(entity_id);
owner->SetFollowDistance(distance * distance); owner->SetFollowDistance(distance * distance);
} }
void QuestManager::sfollow() { void QuestManager::sfollow() {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (owner == nullptr || !owner->IsNPC())
return; return;
owner->SetFollowID(0); owner->SetFollowID(0);
} }
@ -1086,25 +1086,26 @@ void QuestManager::setallskill(int value) {
void QuestManager::attack(const char *client_name) { void QuestManager::attack(const char *client_name) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
Client* getclient = entity_list.GetClientByName(client_name); Client* getclient = entity_list.GetClientByName(client_name);
if(getclient && owner->IsAttackAllowed(getclient)) { if (getclient && owner->IsAttackAllowed(getclient))
owner->AddToHateList(getclient,1); owner->AddToHateList(getclient,1);
} else { else
owner->Say("I am unable to attack %s.", client_name); owner->Say("I am unable to attack %s.", client_name);
}
} }
void QuestManager::attacknpc(int npc_entity_id) { void QuestManager::attacknpc(int npc_entity_id) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
Mob *it = entity_list.GetMob(npc_entity_id); Mob *it = entity_list.GetMob(npc_entity_id);
if(it && owner->IsAttackAllowed(it)) { if (it && owner->IsAttackAllowed(it)) {
owner->AddToHateList(it,1); owner->AddToHateList(it,1);
} else { } else {
if(it) if (it)
owner->Say("I am unable to attack %s.", it->GetName()); owner->Say("I am unable to attack %s.", it->GetName());
else else
owner->Say("I am unable to locate NPC entity %i", npc_entity_id); owner->Say("I am unable to locate NPC entity %i", npc_entity_id);
@ -1113,13 +1114,14 @@ void QuestManager::attacknpc(int npc_entity_id) {
void QuestManager::attacknpctype(int npc_type_id) { void QuestManager::attacknpctype(int npc_type_id) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
Mob *it = entity_list.GetMobByNpcTypeID(npc_type_id); Mob *it = entity_list.GetMobByNpcTypeID(npc_type_id);
if(it && owner->IsAttackAllowed(it)) { if (it && owner->IsAttackAllowed(it)) {
owner->AddToHateList(it,1); owner->AddToHateList(it,1);
} else { } else {
if(it) if (it)
owner->Say("I am unable to attack %s.", it->GetName()); owner->Say("I am unable to attack %s.", it->GetName());
else else
owner->Say("I am unable to locate NPC type %i", npc_type_id); owner->Say("I am unable to locate NPC type %i", npc_type_id);
@ -1176,7 +1178,7 @@ void QuestManager::CreateGuild(const char *guild_name, const char *leader) {
uint32 tmp = guild_mgr.FindGuildByLeader(cid); uint32 tmp = guild_mgr.FindGuildByLeader(cid);
if (tmp != GUILD_NONE) { if (tmp != GUILD_NONE) {
sprintf(hString, "Guild Creation: Error: %s already is the leader of DB# %i '%s'.", leader, tmp, guild_mgr.GetGuildName(tmp)); sprintf(hString, "Guild Creation: Error: %s already is the leader of DB# %u '%s'.", leader, tmp, guild_mgr.GetGuildName(tmp));
worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", hString); worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", hString);
} }
else { else {
@ -1184,7 +1186,7 @@ void QuestManager::CreateGuild(const char *guild_name, const char *leader) {
if (gid == GUILD_NONE) if (gid == GUILD_NONE)
worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", "Guild Creation: Guild creation failed"); worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", "Guild Creation: Guild creation failed");
else { else {
sprintf(hString, "Guild Creation: Guild created: Leader: %i, number %i: %s", cid, gid, leader); sprintf(hString, "Guild Creation: Guild created: Leader: %u, number %u: %s", cid, gid, leader);
worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", hString); worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", hString);
if(!guild_mgr.SetGuild(cid, gid, GUILD_LEADER)) if(!guild_mgr.SetGuild(cid, gid, GUILD_LEADER))
worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", "Unable to set guild leader's guild in the database. Your going to have to run #guild set"); worldserver.SendEmoteMessage(0, 0, 80, 15, "%s", "Unable to set guild leader's guild in the database. Your going to have to run #guild set");
@ -1200,12 +1202,15 @@ void QuestManager::settime(uint8 new_hour, uint8 new_min) {
void QuestManager::itemlink(int item_id) { void QuestManager::itemlink(int item_id) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
const ItemInst* inst = database.CreateItem(item_id); if (initiator) {
char* link = 0; const ItemInst* inst = database.CreateItem(item_id);
if (initiator->MakeItemLink(link, inst)) char* link = 0;
initiator->Message(0, "%s tells you, %c%s%s%c", owner->GetCleanName(), 0x12, link, inst->GetItem()->Name, 0x12); if (initiator->MakeItemLink(link, inst))
safe_delete_array(link); initiator->Message(0, "%s tells you, %c%s%s%c", owner->GetCleanName(),
safe_delete(inst); 0x12, link, inst->GetItem()->Name, 0x12);
safe_delete_array(link);
safe_delete(inst);
}
} }
void QuestManager::signalwith(int npc_id, int signal_id, int wait_ms) { void QuestManager::signalwith(int npc_id, int signal_id, int wait_ms) {
@ -1486,36 +1491,41 @@ void QuestManager::rebind(int zoneid, float x, float y, float z) {
void QuestManager::start(int32 wp) { void QuestManager::start(int32 wp) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
owner->CastToNPC()->AssignWaypoints(wp); owner->CastToNPC()->AssignWaypoints(wp);
} }
void QuestManager::stop() { void QuestManager::stop() {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
owner->CastToNPC()->StopWandering(); owner->CastToNPC()->StopWandering();
} }
void QuestManager::pause(int duration) { void QuestManager::pause(int duration) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
owner->CastToNPC()->PauseWandering(duration); owner->CastToNPC()->PauseWandering(duration);
} }
void QuestManager::moveto(float x, float y, float z, float h, bool saveguardspot) { void QuestManager::moveto(float x, float y, float z, float h, bool saveguardspot) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
owner->CastToNPC()->MoveTo(x, y, z, h, saveguardspot); owner->CastToNPC()->MoveTo(x, y, z, h, saveguardspot);
} }
void QuestManager::resume() { void QuestManager::resume() {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
owner->CastToNPC()->ResumeWandering(); owner->CastToNPC()->ResumeWandering();
} }
@ -1539,22 +1549,21 @@ void QuestManager::addldonloss(int32 losses, uint32 theme) {
void QuestManager::setnexthpevent(int at) { void QuestManager::setnexthpevent(int at) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
owner->SetNextHPEvent( at ); if (owner)
owner->SetNextHPEvent(at);
} }
void QuestManager::setnextinchpevent(int at) { void QuestManager::setnextinchpevent(int at) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
owner->SetNextIncHPEvent( at ); if (owner)
owner->SetNextIncHPEvent(at);
} }
void QuestManager::respawn(int npc_type, int grid) { void QuestManager::respawn(int npc_type, int grid) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
//char tempa[100];
float x,y,z,h; float x,y,z,h;
if ( !owner )
return;
x = owner->GetX(); x = owner->GetX();
y = owner->GetY(); y = owner->GetY();
@ -1581,7 +1590,7 @@ void QuestManager::respawn(int npc_type, int grid) {
void QuestManager::set_proximity(float minx, float maxx, float miny, float maxy, float minz, float maxz) { void QuestManager::set_proximity(float minx, float maxx, float miny, float maxy, float minz, float maxz) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if (!owner || !owner->IsNPC())
return; return;
entity_list.AddProximity(owner->CastToNPC()); entity_list.AddProximity(owner->CastToNPC());
@ -1596,8 +1605,9 @@ void QuestManager::set_proximity(float minx, float maxx, float miny, float maxy,
void QuestManager::clear_proximity() { void QuestManager::clear_proximity() {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
if(!owner->IsNPC()) if(!owner || !owner->IsNPC())
return; return;
entity_list.RemoveProximity(owner->GetID()); entity_list.RemoveProximity(owner->GetID());
safe_delete(owner->CastToNPC()->proximity); safe_delete(owner->CastToNPC()->proximity);
} }
@ -1676,7 +1686,7 @@ void QuestManager::toggle_spawn_event(int event_id, bool enable, bool reset_base
bool QuestManager::has_zone_flag(int zone_id) { bool QuestManager::has_zone_flag(int zone_id) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
return(initiator->HasZoneFlag(zone_id)); return initiator ? initiator->HasZoneFlag(zone_id) : false;
} }
void QuestManager::set_zone_flag(int zone_id) { void QuestManager::set_zone_flag(int zone_id) {
@ -2757,7 +2767,7 @@ void QuestManager::enabletitle(int titleset) {
bool QuestManager::checktitle(int titleset) { bool QuestManager::checktitle(int titleset) {
QuestManagerCurrentQuestVars(); QuestManagerCurrentQuestVars();
return initiator->CheckTitle(titleset); return initiator ? initiator->CheckTitle(titleset) : false;
} }
void QuestManager::removetitle(int titleset) { void QuestManager::removetitle(int titleset) {