summaryrefslogtreecommitdiff
path: root/src/map/quest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/quest.c')
-rw-r--r--src/map/quest.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/map/quest.c b/src/map/quest.c
index 0dbea56f8..ed8e5bd33 100644
--- a/src/map/quest.c
+++ b/src/map/quest.c
@@ -2,7 +2,7 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
+ * Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
@@ -81,6 +81,7 @@ int quest_pc_login(struct map_session_data *sd)
int i;
#endif
+ nullpo_retr(1, sd);
if(sd->avail_quests == 0)
return 1;
@@ -111,6 +112,7 @@ int quest_add(struct map_session_data *sd, int quest_id)
int n;
struct quest_db *qi = quest->db(quest_id);
+ nullpo_retr(-1, sd);
if( qi == &quest->dummy ) {
ShowError("quest_add: quest %d not found in DB.\n", quest_id);
return -1;
@@ -122,6 +124,7 @@ int quest_add(struct map_session_data *sd, int quest_id)
}
n = sd->avail_quests; // Insertion point
+ Assert_retr(-1, sd->avail_quests <= sd->num_quests);
sd->num_quests++;
sd->avail_quests++;
@@ -163,6 +166,7 @@ int quest_change(struct map_session_data *sd, int qid1, int qid2)
int i;
struct quest_db *qi = quest->db(qid2);
+ nullpo_retr(-1, sd);
if( qi == &quest->dummy ) {
ShowError("quest_change: quest %d not found in DB.\n", qid2);
return -1;
@@ -213,6 +217,7 @@ int quest_delete(struct map_session_data *sd, int quest_id)
{
int i;
+ nullpo_retr(-1, sd);
//Search for quest
ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id);
@@ -283,6 +288,7 @@ void quest_update_objective(struct map_session_data *sd, int mob_id)
{
int i,j;
+ nullpo_retv(sd);
for (i = 0; i < sd->avail_quests; i++) {
struct quest_db *qi = NULL;
@@ -316,7 +322,7 @@ void quest_update_objective(struct map_session_data *sd, int mob_id)
item.nameid = dropitem->nameid;
item.identify = itemdb->isidentified2(data);
item.amount = 1;
- if((temp = pc->additem(sd, &item, 1, LOG_TYPE_OTHER)) != 0) { // TODO: We might want a new log type here?
+ if((temp = pc->additem(sd, &item, 1, LOG_TYPE_QUEST)) != 0) { // TODO: We might want a new log type here?
// Failed to obtain the item
clif->additem(sd, 0, 0, temp);
}
@@ -338,6 +344,7 @@ int quest_update_status(struct map_session_data *sd, int quest_id, enum quest_st
{
int i;
+ nullpo_retr(-1, sd);
ARR_FIND(0, sd->avail_quests, i, sd->quest_log[i].quest_id == quest_id);
if( i == sd->avail_quests ) {
ShowError("quest_update_status: Character %d doesn't have quest %d.\n", sd->status.char_id, quest_id);
@@ -388,6 +395,7 @@ int quest_check(struct map_session_data *sd, int quest_id, enum quest_check_type
{
int i;
+ nullpo_retr(-1, sd);
ARR_FIND(0, sd->num_quests, i, sd->quest_log[i].quest_id == quest_id);
if (i == sd->num_quests)
return -1;
@@ -409,7 +417,7 @@ int quest_check(struct map_session_data *sd, int quest_id, enum quest_check_type
}
return 0;
default:
- ShowError("quest_check_quest: Unknown parameter %d",type);
+ ShowError("quest_check_quest: Unknown parameter %u", type);
break;
}
@@ -425,12 +433,13 @@ int quest_check(struct map_session_data *sd, int quest_id, enum quest_check_type
* @return The parsed quest entry.
* @retval NULL in case of errors.
*/
-struct quest_db *quest_read_db_sub(config_setting_t *cs, int n, const char *source)
+struct quest_db *quest_read_db_sub(struct config_setting_t *cs, int n, const char *source)
{
struct quest_db *entry = NULL;
- config_setting_t *t = NULL;
+ struct config_setting_t *t = NULL;
int i32 = 0, quest_id;
const char *str = NULL;
+ nullpo_retr(NULL, cs);
/*
* Id: Quest ID [int]
* Name: Quest Name [string]
@@ -477,7 +486,7 @@ struct quest_db *quest_read_db_sub(config_setting_t *cs, int n, const char *sour
for (i = 0; i < len && entry->objectives_count < MAX_QUEST_OBJECTIVES; i++) {
// Note: We ensure that objectives_count < MAX_QUEST_OBJECTIVES because
// quest_log (as well as the client) expect this maximum size.
- config_setting_t *tt = libconfig->setting_get_elem(t, i);
+ struct config_setting_t *tt = libconfig->setting_get_elem(t, i);
int mob_id = 0, count = 0;
if (!tt)
break;
@@ -496,7 +505,7 @@ struct quest_db *quest_read_db_sub(config_setting_t *cs, int n, const char *sour
if ((t=libconfig->setting_get_member(cs, "Drops")) && config_setting_is_list(t)) {
int i, len = libconfig->setting_length(t);
for (i = 0; i < len; i++) {
- config_setting_t *tt = libconfig->setting_get_elem(t, i);
+ struct config_setting_t *tt = libconfig->setting_get_elem(t, i);
int mob_id = 0, nameid = 0, rate = 0;
if (!tt)
break;
@@ -527,13 +536,16 @@ struct quest_db *quest_read_db_sub(config_setting_t *cs, int n, const char *sour
int quest_read_db(void)
{
char filepath[256];
- config_t quest_db_conf;
- config_setting_t *qdb = NULL, *q = NULL;
+ struct config_t quest_db_conf;
+ struct config_setting_t *qdb = NULL, *q = NULL;
int i = 0, count = 0;
const char *filename = "quest_db.conf";
- sprintf(filepath, "%s/%s", map->db_path, filename);
- if (libconfig->read_file(&quest_db_conf, filepath) || !(qdb = libconfig->setting_get_member(quest_db_conf.root, "quest_db"))) {
+ snprintf(filepath, 256, "%s/%s", map->db_path, filename);
+ if (!libconfig->load_file(&quest_db_conf, filepath))
+ return -1;
+
+ if ((qdb = libconfig->setting_get_member(quest_db_conf.root, "quest_db")) == NULL) {
ShowError("can't read %s\n", filepath);
return -1;
}