summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2018-06-25 00:47:42 +0200
committerHaru <haru@dotalux.com>2018-06-30 01:51:12 +0200
commit7772ec2ad36d01b7a73ab320ac740eb99f7eafbf (patch)
treed1b7b991bfd5272259b615b94d9f240db5a59fa4
parent401b579bb064c180a5e17196fcd5b420bc3d49ee (diff)
downloadhercules-7772ec2ad36d01b7a73ab320ac740eb99f7eafbf.tar.gz
hercules-7772ec2ad36d01b7a73ab320ac740eb99f7eafbf.tar.bz2
hercules-7772ec2ad36d01b7a73ab320ac740eb99f7eafbf.tar.xz
hercules-7772ec2ad36d01b7a73ab320ac740eb99f7eafbf.zip
Move some non-mapif functionality from the mapif interface to the inter_quest interface
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r--src/char/int_quest.c61
-rw-r--r--src/char/int_quest.h6
-rw-r--r--src/char/mapif.c8
-rw-r--r--src/char/mapif.h4
4 files changed, 44 insertions, 35 deletions
diff --git a/src/char/int_quest.c b/src/char/int_quest.c
index f967e5cfb..7b89ddf01 100644
--- a/src/char/int_quest.c
+++ b/src/char/int_quest.c
@@ -48,7 +48,7 @@ struct inter_quest_interface *inter_quest;
* @return Array of found entries. It has *count entries, and it is care of the
* caller to aFree() it afterwards.
*/
-struct quest *mapif_quests_fromsql(int char_id, int *count)
+struct quest *inter_quest_fromsql(int char_id, int *count)
{
struct quest *questlog = NULL;
struct quest tmp_quest;
@@ -129,7 +129,7 @@ struct quest *mapif_quests_fromsql(int char_id, int *count)
* @param quest_id Quest ID
* @return false in case of errors, true otherwise
*/
-bool mapif_quest_delete(int char_id, int quest_id)
+bool inter_quest_delete(int char_id, int quest_id)
{
if (SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, quest_id, char_id)) {
Sql_ShowDebug(inter->sql_handle);
@@ -146,7 +146,7 @@ bool mapif_quest_delete(int char_id, int quest_id)
* @param qd Quest data
* @return false in case of errors, true otherwise
*/
-bool mapif_quest_add(int char_id, struct quest qd)
+bool inter_quest_add(int char_id, struct quest qd)
{
StringBuf buf;
int i;
@@ -178,7 +178,7 @@ bool mapif_quest_add(int char_id, struct quest qd)
* @param qd Quest data
* @return false in case of errors, true otherwise
*/
-bool mapif_quest_update(int char_id, struct quest qd)
+bool inter_quest_update(int char_id, struct quest qd)
{
StringBuf buf;
int i;
@@ -209,25 +209,13 @@ void mapif_quest_save_ack(int fd, int char_id, bool success)
WFIFOSET(fd,7);
}
-/**
- * Handles the save request from mapserver for a character's questlog.
- *
- * Received quests are saved, and an ack is sent back to the map server.
- *
- * @see inter_parse_frommap
- */
-int mapif_parse_quest_save(int fd)
+bool inter_quest_save(int char_id, const struct quest *new_qd, int new_n)
{
- int i, j, k, old_n, new_n = (RFIFOW(fd,2)-8)/sizeof(struct quest);
- int char_id = RFIFOL(fd,4);
+ int i, j, k, old_n;
struct quest *old_qd = NULL;
- const struct quest *new_qd = NULL;
bool success = true;
- if (new_n > 0)
- new_qd = RFIFOP(fd,8);
-
- old_qd = mapif->quests_fromsql(char_id, &old_n);
+ old_qd = inter_quest->fromsql(char_id, &old_n);
for (i = 0; i < new_n; i++) {
ARR_FIND( 0, old_n, j, new_qd[i].quest_id == old_qd[j].quest_id );
@@ -237,7 +225,7 @@ int mapif_parse_quest_save(int fd)
// Only states and counts are changeable.
ARR_FIND( 0, MAX_QUEST_OBJECTIVES, k, new_qd[i].count[k] != old_qd[j].count[k] );
if (k != MAX_QUEST_OBJECTIVES || new_qd[i].state != old_qd[j].state)
- success &= mapif->quest_update(char_id, new_qd[i]);
+ success &= inter_quest->update(char_id, new_qd[i]);
if (j < (--old_n)) {
// Compact array
@@ -246,16 +234,38 @@ int mapif_parse_quest_save(int fd)
}
} else {
// Add new quests
- success &= mapif->quest_add(char_id, new_qd[i]);
+ success &= inter_quest->add(char_id, new_qd[i]);
}
}
for (i = 0; i < old_n; i++) // Quests not in new_qd but in old_qd are to be erased.
- success &= mapif->quest_delete(char_id, old_qd[i].quest_id);
+ success &= inter_quest->delete(char_id, old_qd[i].quest_id);
if (old_qd)
aFree(old_qd);
+ return success;
+}
+
+/**
+ * Handles the save request from mapserver for a character's questlog.
+ *
+ * Received quests are saved, and an ack is sent back to the map server.
+ *
+ * @see inter_parse_frommap
+ */
+int mapif_parse_quest_save(int fd)
+{
+ int num = (RFIFOW(fd, 2) - 8) / sizeof(struct quest);
+ int char_id = RFIFOL(fd, 4);
+ const struct quest *qd = NULL;
+ bool success;
+
+ if (num > 0)
+ qd = RFIFOP(fd,8);
+
+ success = inter_quest->save(char_id, qd, num);
+
// Send ack
mapif->quest_save_ack(fd, char_id, success);
@@ -292,7 +302,7 @@ int mapif_parse_quest_load(int fd)
struct quest *tmp_questlog = NULL;
int num_quests;
- tmp_questlog = mapif->quests_fromsql(char_id, &num_quests);
+ tmp_questlog = inter_quest->fromsql(char_id, &num_quests);
mapif->send_quests(fd, char_id, tmp_questlog, num_quests);
if (tmp_questlog)
@@ -322,4 +332,9 @@ void inter_quest_defaults(void)
inter_quest = &inter_quest_s;
inter_quest->parse_frommap = inter_quest_parse_frommap;
+ inter_quest->fromsql = inter_quest_fromsql;
+ inter_quest->delete = inter_quest_delete;
+ inter_quest->add = inter_quest_add;
+ inter_quest->update = inter_quest_update;
+ inter_quest->save = inter_quest_save;
}
diff --git a/src/char/int_quest.h b/src/char/int_quest.h
index 6f34645bf..e71afc561 100644
--- a/src/char/int_quest.h
+++ b/src/char/int_quest.h
@@ -28,6 +28,12 @@
**/
struct inter_quest_interface {
int (*parse_frommap) (int fd);
+
+ struct quest *(*fromsql) (int char_id, int *count);
+ bool (*delete) (int char_id, int quest_id);
+ bool (*add) (int char_id, struct quest qd);
+ bool (*update) (int char_id, struct quest qd);
+ bool (*save) (int char_id, const struct quest *new_qd, int new_n);
};
#ifdef HERCULES_CORE
diff --git a/src/char/mapif.c b/src/char/mapif.c
index cba79de22..6eb608204 100644
--- a/src/char/mapif.c
+++ b/src/char/mapif.c
@@ -1556,10 +1556,6 @@ int mapif_parse_DeletePet(int fd)
return 0;
}
-struct quest *mapif_quests_fromsql(int char_id, int *count);
-bool mapif_quest_delete(int char_id, int quest_id);
-bool mapif_quest_add(int char_id, struct quest qd);
-bool mapif_quest_update(int char_id, struct quest qd);
void mapif_quest_save_ack(int fd, int char_id, bool success);
int mapif_parse_quest_save(int fd);
void mapif_send_quests(int fd, int char_id, struct quest *tmp_questlog, int num_quests);
@@ -1756,10 +1752,6 @@ void mapif_defaults(void) {
mapif->parse_LoadPet = mapif_parse_LoadPet;
mapif->parse_SavePet = mapif_parse_SavePet;
mapif->parse_DeletePet = mapif_parse_DeletePet;
- mapif->quests_fromsql = mapif_quests_fromsql;
- mapif->quest_delete = mapif_quest_delete;
- mapif->quest_add = mapif_quest_add;
- mapif->quest_update = mapif_quest_update;
mapif->quest_save_ack = mapif_quest_save_ack;
mapif->parse_quest_save = mapif_parse_quest_save;
mapif->send_quests = mapif_send_quests;
diff --git a/src/char/mapif.h b/src/char/mapif.h
index 862cb5fc5..659513797 100644
--- a/src/char/mapif.h
+++ b/src/char/mapif.h
@@ -150,10 +150,6 @@ struct mapif_interface {
int (*parse_LoadPet) (int fd);
int (*parse_SavePet) (int fd);
int (*parse_DeletePet) (int fd);
- struct quest *(*quests_fromsql) (int char_id, int *count);
- bool (*quest_delete) (int char_id, int quest_id);
- bool (*quest_add) (int char_id, struct quest qd);
- bool (*quest_update) (int char_id, struct quest qd);
void (*quest_save_ack) (int fd, int char_id, bool success);
int (*parse_quest_save) (int fd);
void (*send_quests) (int fd, int char_id, struct quest *tmp_questlog, int num_quests);