summaryrefslogtreecommitdiff
path: root/src/char/int_quest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/char/int_quest.c')
-rw-r--r--src/char/int_quest.c114
1 files changed, 29 insertions, 85 deletions
diff --git a/src/char/int_quest.c b/src/char/int_quest.c
index cf93db51e..4269b3da1 100644
--- a/src/char/int_quest.c
+++ b/src/char/int_quest.c
@@ -2,8 +2,8 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
- * Copyright (C) Athena Dev Teams
+ * Copyright (C) 2012-2020 Hercules Dev Team
+ * Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -37,7 +37,7 @@
#include <stdio.h>
#include <stdlib.h>
-struct inter_quest_interface inter_quest_s;
+static struct inter_quest_interface inter_quest_s;
struct inter_quest_interface *inter_quest;
/**
@@ -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)
+static struct quest *inter_quest_fromsql(int char_id, int *count)
{
struct quest *questlog = NULL;
struct quest tmp_quest;
@@ -56,6 +56,7 @@ struct quest *mapif_quests_fromsql(int char_id, int *count)
StringBuf buf;
int i;
int sqlerror = SQL_SUCCESS;
+ int quest_state = 0;
if (!count)
return NULL;
@@ -77,11 +78,11 @@ struct quest *mapif_quests_fromsql(int char_id, int *count)
memset(&tmp_quest, 0, sizeof(struct quest));
if (SQL_ERROR == SQL->StmtPrepareStr(stmt, StrBuf->Value(&buf))
- || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, 0)
+ || SQL_ERROR == SQL->StmtBindParam(stmt, 0, SQLDT_INT, &char_id, sizeof char_id)
|| SQL_ERROR == SQL->StmtExecute(stmt)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL)
- || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UINT, &tmp_quest.time, 0, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, sizeof tmp_quest.quest_id, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 1, SQLDT_INT, &quest_state, sizeof quest_state, NULL, NULL)
+ || SQL_ERROR == SQL->StmtBindColumn(stmt, 2, SQLDT_UINT, &tmp_quest.time, sizeof tmp_quest.time, NULL, NULL)
) {
sqlerror = SQL_ERROR;
}
@@ -89,7 +90,7 @@ struct quest *mapif_quests_fromsql(int char_id, int *count)
StrBuf->Destroy(&buf);
for (i = 0; sqlerror != SQL_ERROR && i < MAX_QUEST_OBJECTIVES; i++) { // Stop on the first error
- sqlerror = SQL->StmtBindColumn(stmt, 3+i, SQLDT_INT, &tmp_quest.count[i], 0, NULL, NULL);
+ sqlerror = SQL->StmtBindColumn(stmt, 3+i, SQLDT_INT, &tmp_quest.count[i], sizeof tmp_quest.count[i], NULL, NULL);
}
if (sqlerror == SQL_ERROR) {
@@ -105,9 +106,10 @@ struct quest *mapif_quests_fromsql(int char_id, int *count)
questlog = (struct quest *)aCalloc(*count, sizeof(struct quest));
while (SQL_SUCCESS == SQL->StmtNextRow(stmt)) {
+ tmp_quest.state = quest_state;
if (i >= *count) // Sanity check, should never happen
break;
- memcpy(&questlog[i++], &tmp_quest, sizeof(tmp_quest));
+ questlog[i++] = tmp_quest;
}
if (i < *count) {
// Should never happen. Compact array
@@ -127,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)
+static 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);
@@ -144,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)
+static bool inter_quest_add(int char_id, struct quest qd)
{
StringBuf buf;
int i;
@@ -176,13 +178,13 @@ 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)
+static bool inter_quest_update(int char_id, struct quest qd)
{
StringBuf buf;
int i;
StrBuf->Init(&buf);
- StrBuf->Printf(&buf, "UPDATE `%s` SET `state`='%u'", quest_db, qd.state);
+ StrBuf->Printf(&buf, "UPDATE `%s` SET `state`='%u', `time`='%u'", quest_db, qd.state, qd.time);
for (i = 0; i < MAX_QUEST_OBJECTIVES; i++) {
StrBuf->Printf(&buf, ", `count%d`='%d'", i+1, qd.count[i]);
}
@@ -198,34 +200,13 @@ bool mapif_quest_update(int char_id, struct quest qd)
return true;
}
-void mapif_quest_save_ack(int fd, int char_id, bool success)
+static bool inter_quest_save(int char_id, const struct quest *new_qd, int new_n)
{
- WFIFOHEAD(fd,7);
- WFIFOW(fd,0) = 0x3861;
- WFIFOL(fd,2) = char_id;
- WFIFOB(fd,6) = success?1:0;
- 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)
-{
- 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 );
@@ -235,7 +216,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
@@ -244,59 +225,17 @@ 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);
- // Send ack
- mapif->quest_save_ack(fd, char_id, success);
-
- return 0;
-}
-
-void mapif_send_quests(int fd, int char_id, struct quest *tmp_questlog, int num_quests)
-{
- WFIFOHEAD(fd,num_quests*sizeof(struct quest)+8);
- WFIFOW(fd,0) = 0x3860;
- WFIFOW(fd,2) = num_quests*sizeof(struct quest)+8;
- WFIFOL(fd,4) = char_id;
-
- if (num_quests > 0) {
- nullpo_retv(tmp_questlog);
- memcpy(WFIFOP(fd,8), tmp_questlog, sizeof(struct quest)*num_quests);
- }
-
- WFIFOSET(fd,num_quests*sizeof(struct quest)+8);
-}
-
-/**
- * Sends questlog to the map server
- *
- * Note: Completed quests (state == Q_COMPLETE) are guaranteed to be sent last
- * and the map server relies on this behavior (once the first Q_COMPLETE quest,
- * all of them are considered to be Q_COMPLETE)
- *
- * @see inter_parse_frommap
- */
-int mapif_parse_quest_load(int fd)
-{
- int char_id = RFIFOL(fd,2);
- struct quest *tmp_questlog = NULL;
- int num_quests;
-
- tmp_questlog = mapif->quests_fromsql(char_id, &num_quests);
- mapif->send_quests(fd, char_id, tmp_questlog, num_quests);
-
- if (tmp_questlog)
- aFree(tmp_questlog);
-
- return 0;
+ return success;
}
/**
@@ -304,7 +243,7 @@ int mapif_parse_quest_load(int fd)
*
* @see inter_parse_frommap
*/
-int inter_quest_parse_frommap(int fd)
+static int inter_quest_parse_frommap(int fd)
{
switch(RFIFOW(fd,0)) {
case 0x3060: mapif->parse_quest_load(fd); break;
@@ -320,4 +259,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;
}