From 02a755111f9a707cc7fdef81772c74b1d10242b1 Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 14 Apr 2008 02:32:24 +0000 Subject: Some more updates to the quest log system. It has been completely moved to the inter server instead of the char server. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12584 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/char_sql/char.c | 34 +----------------- src/char_sql/int_quest.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++- src/char_sql/inter.c | 2 +- 3 files changed, 94 insertions(+), 35 deletions(-) (limited to 'src/char_sql') 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 #include +//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