summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char_sql/char.c34
-rw-r--r--src/char_sql/int_quest.c93
-rw-r--r--src/char_sql/inter.c2
-rw-r--r--src/common/mmo.h2
-rw-r--r--src/map/chrif.c1
-rw-r--r--src/map/intif.c43
-rw-r--r--src/map/intif.h1
-rw-r--r--src/map/pc.c6
-rw-r--r--src/map/quest.c17
9 files changed, 133 insertions, 66 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index 8a7a2ebd9..d4cde63e6 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -902,7 +902,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
char t_msg[128] = "";
struct mmo_charstatus* cp;
StringBuf buf;
- SqlStmt* stmt, *stmt2;
+ SqlStmt* stmt;
char last_map[MAP_NAME_LENGTH_EXT];
char save_map[MAP_NAME_LENGTH_EXT];
char point_map[MAP_NAME_LENGTH_EXT];
@@ -1112,38 +1112,6 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
memcpy(&p->friends[i], &tmp_friend, sizeof(tmp_friend));
strcat(t_msg, " friends");
- //read quests
- //`quests` (`quest_id`, `char_id`, `state`)
- if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT q.`quest_id`, q.`state` FROM `%s` q", quest_db)
- || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0)
- || SQL_ERROR == SqlStmt_Execute(stmt)
- || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL)
- || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL) )
- SqlStmt_ShowDebug(stmt);
-
- stmt2 = SqlStmt_Malloc(sql_handle);
-
- for( i = 0; i < MAX_QUEST && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i )
- {
- memcpy(&p->quest_log[i], &tmp_quest, sizeof(tmp_quest));
-
- //`quest_objectives`
- if( SQL_ERROR == SqlStmt_Prepare(stmt2, "SELECT q.`count`, q.`name` FROM `%s` q", quest_obj_db)
- || SQL_ERROR == SqlStmt_BindParam(stmt2, 0, SQLDT_INT, &tmp_quest.quest_id, 0)
- || SQL_ERROR == SqlStmt_Execute(stmt2)
- || SQL_ERROR == SqlStmt_BindColumn(stmt2, 0, SQLDT_INT, &tmp_quest_obj.count, 0, NULL, NULL)
- || SQL_ERROR == SqlStmt_BindColumn(stmt2, 1, SQLDT_STRING, &tmp_quest_obj.name, NAME_LENGTH, NULL, NULL) )
- SqlStmt_ShowDebug(stmt2);
-
- for( j = 0; j < MAX_QUEST_OBJECTIVES && SQL_SUCCESS == SqlStmt_NextRow(stmt2); ++j )
- memcpy(&p->quest_log[i].objectives[j], &tmp_quest_obj, sizeof(tmp_quest_obj));
- p->quest_log[i].num_objectives = j;
- }
- p->num_quests = i;
- strcat(t_msg, " quests");
-
- SqlStmt_Free(stmt2);
-
#ifdef HOTKEY_SAVING
//read hotkeys
//`hotkey` (`char_id`, `hotkey`, `type`, `itemskill_id`, `skill_lvl`
diff --git a/src/char_sql/int_quest.c b/src/char_sql/int_quest.c
index 49fb1533b..3c3e5446d 100644
--- a/src/char_sql/int_quest.c
+++ b/src/char_sql/int_quest.c
@@ -17,7 +17,61 @@
#include <string.h>
#include <stdlib.h>
+//Load entire questlog for a character
+int mapif_quests_fromsql(int char_id, struct quest questlog[])
+{
+
+ int count, i, j, num;
+ struct quest tmp_quest;
+ struct quest_objective tmp_quest_objective;
+ SqlStmt * stmt;
+
+ stmt = SqlStmt_Malloc(sql_handle);
+ if( stmt == NULL )
+ {
+ SqlStmt_ShowDebug(stmt);
+ return 0;
+ }
+
+ if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `quest_id`, `state` FROM `%s` WHERE `char_id`=? LIMIT %d", quest_db, MAX_QUEST)
+ || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0)
+ || SQL_ERROR == SqlStmt_Execute(stmt)
+ || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &tmp_quest.quest_id, 0, NULL, NULL)
+ || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL) )
+ //|| SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_INT, &tmp_quest.time, 0, NULL, NULL)
+ SqlStmt_ShowDebug(stmt);
+
+ for( i = 0; i < MAX_QUEST && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++i )
+ {
+ memcpy(&questlog[i], &tmp_quest, sizeof(tmp_quest));
+ }
+ count = i;
+
+ for( i = 0; i < count; ++i )
+ {
+
+ if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `num`, `name`, `count` FROM `%s` WHERE `char_id`=? AND `quest_id`=? LIMIT %d", quest_obj_db, MAX_QUEST_OBJECTIVES)
+ || SQL_ERROR == SqlStmt_BindParam(stmt, 0, SQLDT_INT, &char_id, 0)
+ || SQL_ERROR == SqlStmt_BindParam(stmt, 1, SQLDT_INT, &questlog[i].quest_id, 0)
+ || SQL_ERROR == SqlStmt_Execute(stmt)
+ || SQL_ERROR == SqlStmt_BindColumn(stmt, 0, SQLDT_INT, &num, 0, NULL, NULL)
+ || SQL_ERROR == SqlStmt_BindColumn(stmt, 1, SQLDT_STRING, &tmp_quest_objective.name, NAME_LENGTH, NULL, NULL)
+ || SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_INT, &tmp_quest_objective.count, 0, NULL, NULL) )
+ SqlStmt_ShowDebug(stmt);
+
+ for( j = 0; j < MAX_QUEST && SQL_SUCCESS == SqlStmt_NextRow(stmt); ++j )
+ {
+ memcpy(&questlog[i].objectives[num], &tmp_quest_objective, sizeof(struct quest_objective));
+ }
+ questlog[i].num_objectives = j;
+ }
+
+
+ return count;
+}
+
+//Delete a quest
int mapif_parse_quest_delete(int fd)
{
@@ -48,7 +102,7 @@ int mapif_parse_quest_delete(int fd)
}
-
+//Add a quest to a questlog
int mapif_parse_quest_add(int fd)
{
@@ -97,11 +151,48 @@ int mapif_parse_quest_add(int fd)
}
+//Send questlog to map server
+int mapif_send_quests(int fd, int char_id)
+{
+
+ struct quest tmp_questlog[MAX_QUEST];
+ int num_quests, i;
+
+ for(i=0; i<MAX_QUEST; i++)
+ {
+ memset(&tmp_questlog[i], 0, sizeof(struct quest));
+ }
+
+ num_quests = mapif_quests_fromsql(char_id, tmp_questlog);
+
+ 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;
+
+ for(i=0; i<num_quests; i++)
+ {
+ memcpy(WFIFOP(fd,i*sizeof(struct quest)+8), &tmp_questlog[i], sizeof(struct quest));
+ }
+
+ WFIFOSET(fd,num_quests*sizeof(struct quest)+8);
+
+ return 0;
+}
+
+//Map server requesting a character's quest log
+int mapif_parse_loadquestrequest(int fd)
+{
+ mapif_send_quests(fd, RFIFOL(fd,2));
+ return 0;
+}
+
int inter_quest_parse_frommap(int fd)
{
switch(RFIFOW(fd,0))
{
+ case 0x3060: mapif_parse_loadquestrequest(fd); break;
case 0x3061: mapif_parse_quest_add(fd); break;
case 0x3062: mapif_parse_quest_delete(fd); break;
default:
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index 8e1c466a4..d11d7ee95 100644
--- a/src/char_sql/inter.c
+++ b/src/char_sql/inter.c
@@ -57,7 +57,7 @@ int inter_recv_packet_length[] = {
-1, 6,-1,-1, 55,19, 6,-1, 14,-1,-1,-1, 14,19,186,-1, // 3030-
5, 9, 0, 0, 0, 0, 0, 0, 7, 6,10,10, 10,-1, 0, 0, // 3040-
-1,-1,10,10, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3050- Auction System [Zephyrus]
- -1,-1,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin]
+ 6,-1,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin]
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3070-
48,14,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3080-
-1,10,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3090- Homunculus packets [albator]
diff --git a/src/common/mmo.h b/src/common/mmo.h
index b3e5f6e48..70e7f103d 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -265,8 +265,6 @@ struct mmo_charstatus {
struct point last_point,save_point,memo_point[MAX_MEMOPOINTS];
struct item inventory[MAX_INVENTORY],cart[MAX_CART];
struct skill skill[MAX_SKILL];
- int num_quests;
- struct quest quest_log[MAX_QUEST];
struct s_friend friends[MAX_FRIENDS]; //New friend system [Skotlex]
#ifdef HOTKEY_SAVING
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 7fbff78e4..2ce7dcf4a 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -600,7 +600,6 @@ void chrif_authok(int fd)
{ //Auth Ok
if (pc_authok(sd, login_id2, expiration_time, status))
{
- chrif_char_online(sd);
return;
}
} else { //Auth Failed
diff --git a/src/map/intif.c b/src/map/intif.c
index 0ce0aa8c1..2d9b1894c 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -37,7 +37,7 @@ static const int packet_len_table[]={
10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
9, 9,-1,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840
-1,-1, 7, 7, 7,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus]
- 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin]
+ -1,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin]
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3880
-1,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator]
@@ -1405,6 +1405,36 @@ QUESTLOG SYSTEM FUNCTIONS
***************************************/
+int intif_request_questlog(TBL_PC *sd)
+{
+ WFIFOHEAD(inter_fd,6);
+ WFIFOW(inter_fd,0) = 0x3060;
+ WFIFOL(inter_fd,2) = sd->status.char_id;
+ WFIFOSET(inter_fd,6);
+ return 0;
+}
+
+int intif_parse_questlog(int fd)
+{
+
+ int num_quests = (RFIFOB(fd, 2)-8)/sizeof(struct quest);
+ int char_id = RFIFOL(fd, 4);
+ int i;
+ TBL_PC * sd = map_charid2sd(char_id);
+
+ //User not online anymore
+ if(!sd)
+ return 0;
+
+ for(i=0; i<num_quests; i++)
+ {
+ memcpy(&sd->quest_log[i], RFIFOP(fd, i*sizeof(struct quest)+8), sizeof(struct quest));
+ }
+ sd->num_quests = num_quests;
+
+ return 0;
+}
+
int intif_parse_questDelete(int fd)
{
quest_delete_ack(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10));
@@ -1434,17 +1464,15 @@ int intif_parse_questAdd(int fd)
int intif_quest_add(int char_id, struct quest * qd)
{
- int sSize = sizeof(struct quest);
-
if(CheckForCharServer())
return 0;
- WFIFOHEAD(inter_fd, sSize + 8);
+ WFIFOHEAD(inter_fd, sizeof(struct quest) + 8);
WFIFOW(inter_fd,0) = 0x3061;
- WFIFOW(inter_fd,2) = sSize + 8;
+ WFIFOW(inter_fd,2) = sizeof(struct quest) + 8;
WFIFOL(inter_fd,4) = char_id;
- memcpy(WFIFOP(inter_fd,8), qd, sSize);
- WFIFOSET(inter_fd, sSize + 8);
+ memcpy(WFIFOP(inter_fd,8), qd, sizeof(struct quest));
+ WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
return 0;
}
@@ -1992,6 +2020,7 @@ int intif_parse(int fd)
case 0x3843: intif_parse_GuildMasterChanged(fd); break;
//Quest system
+ case 0x3860: intif_parse_questlog(fd); break;
case 0x3861: intif_parse_questAdd(fd); break;
case 0x3862: intif_parse_questDelete(fd); break;
diff --git a/src/map/intif.h b/src/map/intif.h
index 1827ec00a..c4fe34f20 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -76,6 +76,7 @@ int intif_homunculus_requestsave(int account_id, struct s_homunculus* sh);
int intif_homunculus_requestdelete(int homun_id);
/******QUEST SYTEM*******/
+int intif_request_questlog(struct map_session_data * sd);
int intif_quest_delete(int char_id, int quest_id);
int intif_quest_add(int char_id, struct quest * qd);
diff --git a/src/map/pc.c b/src/map/pc.c
index 32f102b6e..5fc764cb1 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -374,7 +374,6 @@ int pc_makesavestatus(struct map_session_data *sd)
memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
}
- quest_make_savedata(sd);
return 0;
}
@@ -866,9 +865,6 @@ bool pc_authok(struct map_session_data *sd, int login_id2, time_t expiration_tim
clif_wis_message(sd->fd, wisp_server_name, tmpstr, strlen(tmpstr)+1);
}
- //Get quest data out of char dat
- quest_load_info(sd, st);
-
// Request all registries (auth is considered completed whence they arrive)
intif_request_registry(sd,7);
return true;
@@ -982,6 +978,8 @@ int pc_reg_received(struct map_session_data *sd)
intif_Mail_requestinbox(sd->status.char_id, 0); // MAIL SYSTEM - Request Mail Inbox
#endif
+ intif_request_questlog(sd);
+
if (!sd->state.connect_new && sd->fd)
{ //Character already loaded map! Gotta trigger LoadEndAck manually.
sd->state.connect_new = 1;
diff --git a/src/map/quest.c b/src/map/quest.c
index 25c879105..51082532f 100644
--- a/src/map/quest.c
+++ b/src/map/quest.c
@@ -190,20 +190,3 @@ int quest_update_status(TBL_PC * sd, int quest_id, bool status)
return 0;
}
-
-int quest_load_info(TBL_PC * sd, struct mmo_charstatus * st)
-{
- sd->num_quests = st->num_quests;
- memcpy(sd->quest_log, st->quest_log, sizeof(st->quest_log));
-
- return 0;
-}
-
-int quest_make_savedata(TBL_PC * sd)
-{
- sd->status.num_quests = sd->num_quests;
- memcpy(sd->status.quest_log, sd->quest_log, sizeof(sd->quest_log));
-
- return 0;
-}
-