diff options
author | Inkfish <Inkfish@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-07-25 20:55:35 +0000 |
---|---|---|
committer | Inkfish <Inkfish@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2009-07-25 20:55:35 +0000 |
commit | 34b37179c0895f0b0acc4377bf2bfe5edfcff9ce (patch) | |
tree | d650d9bc108404fa0949d5ec2754d96cde31926b /src/char_sql | |
parent | a93b8b9c2537bd8359d647ae23e90d084d019535 (diff) | |
download | hercules-34b37179c0895f0b0acc4377bf2bfe5edfcff9ce.tar.gz hercules-34b37179c0895f0b0acc4377bf2bfe5edfcff9ce.tar.bz2 hercules-34b37179c0895f0b0acc4377bf2bfe5edfcff9ce.tar.xz hercules-34b37179c0895f0b0acc4377bf2bfe5edfcff9ce.zip |
Rewrote Quest Log system.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@13959 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/char_sql')
-rw-r--r-- | src/char_sql/char.c | 5 | ||||
-rw-r--r-- | src/char_sql/char.h | 1 | ||||
-rw-r--r-- | src/char_sql/int_quest.c | 115 | ||||
-rw-r--r-- | src/char_sql/inter.c | 2 |
4 files changed, 62 insertions, 61 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c index d0e5643cc..fe9025935 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -58,8 +58,7 @@ char mail_db[256] = "mail"; // MAIL SYSTEM char auction_db[256] = "auction"; // Auctions System char friend_db[256] = "friends"; char hotkey_db[256] = "hotkey"; -char quest_db[256] = "quest"; -char quest_obj_db[256] = "quest_objective"; +char quest_db[256] = "questlog"; //If your code editor is having problems syntax highlighting this file, uncomment this and RECOMMENT IT BEFORE COMPILING //#undef TXT_SQL_CONVERT @@ -3639,8 +3638,6 @@ void sql_config_read(const char* cfgName) strcpy(hotkey_db,w2); else if(!strcmpi(w1,"quest_db")) strcpy(quest_db,w2); - else if(!strcmpi(w1,"quest_obj_db")) - strcpy(quest_obj_db, w2); #ifndef TXT_SQL_CONVERT else if(!strcmpi(w1,"db_path")) strcpy(db_path,w2); diff --git a/src/char_sql/char.h b/src/char_sql/char.h index 33c4544b2..a40340cfb 100644 --- a/src/char_sql/char.h +++ b/src/char_sql/char.h @@ -59,7 +59,6 @@ extern char pet_db[256]; extern char mail_db[256]; extern char auction_db[256]; extern char quest_db[256]; -extern char quest_obj_db[256]; extern int db_use_sqldbs; // added for sql item_db read for char server [Valaris] diff --git a/src/char_sql/int_quest.c b/src/char_sql/int_quest.c index 53c2d3cda..5c59a5ba0 100644 --- a/src/char_sql/int_quest.c +++ b/src/char_sql/int_quest.c @@ -20,10 +20,8 @@ //Load entire questlog for a character int mapif_quests_fromsql(int char_id, struct quest questlog[]) { - - int count, i, j, num; + int i; struct quest tmp_quest; - struct quest_objective tmp_quest_objective; SqlStmt * stmt; stmt = SqlStmt_Malloc(sql_handle); @@ -34,42 +32,29 @@ int mapif_quests_fromsql(int char_id, struct quest questlog[]) } memset(&tmp_quest, 0, sizeof(struct quest)); - memset(&tmp_quest_objective, 0, sizeof(struct quest_objective)); - if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `quest_id`, `state` FROM `%s` WHERE `char_id`=? LIMIT %d", quest_db, MAX_QUEST) + if( SQL_ERROR == SqlStmt_Prepare(stmt, "SELECT `quest_id`, `state`, `time`, `mob1`, `count1`, `mob2`, `count2`, `mob3`, `count3` 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, 1, SQLDT_INT, &tmp_quest.state, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 2, SQLDT_UINT, &tmp_quest.time, 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 3, SQLDT_INT, &tmp_quest.mob[0], 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 4, SQLDT_INT, &tmp_quest.count[0], 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 5, SQLDT_INT, &tmp_quest.mob[1], 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 6, SQLDT_INT, &tmp_quest.count[1], 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 7, SQLDT_INT, &tmp_quest.mob[2], 0, NULL, NULL) + || SQL_ERROR == SqlStmt_BindColumn(stmt, 8, SQLDT_INT, &tmp_quest.count[2], 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)); + questlog[i].num_objectives = (!questlog[i].mob[0] ? 0 : !questlog[i].mob[1] ? 1 : !questlog[i].mob[2] ? 2 : 3); } - 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; - - } SqlStmt_Free(stmt); - return count; + return i; } //Delete a quest @@ -86,12 +71,6 @@ int mapif_parse_quest_delete(int fd) success = false; } - if ( success && SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_obj_db, quest_id, char_id) ) - { - Sql_ShowDebug(sql_handle); - success = false; - } - WFIFOHEAD(fd,11); WFIFOW(fd,0) = 0x3862; WFIFOL(fd,2) = char_id; @@ -111,13 +90,11 @@ int mapif_parse_quest_add(int fd) bool success = true; int char_id = RFIFOL(fd,4); struct quest qd; - int i; memcpy(&qd, RFIFOP(fd,8), RFIFOW(fd,2)-8); StringBuf_Init(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`) VALUES ('%d', '%d', '%d')", quest_db, qd.quest_id, char_id, qd.state); - + StringBuf_Printf(&buf, "INSERT INTO `%s`(`quest_id`, `char_id`, `state`, `time`, `mob1`, `count1`, `mob2`, `count2`, `mob3`, `count3`) VALUES ('%d', '%d', '%d','%d', '%d', '%d', '%d', '%d', '%d', '%d')", quest_db, qd.quest_id, char_id, qd.state, qd.time, qd.mob[0], qd.count[0], qd.mob[1], qd.count[1], qd.mob[2], qd.count[2]); if ( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { @@ -125,22 +102,41 @@ int mapif_parse_quest_add(int fd) success = false; } - for(i=0; i<qd.num_objectives && success; i++) - { + WFIFOHEAD(fd,11); + WFIFOW(fd,0) = 0x3861; + WFIFOL(fd,2) = char_id; + WFIFOL(fd,6) = qd.quest_id; + WFIFOB(fd,10) = success?1:0; + WFIFOSET(fd,11); - StringBuf_Clear(&buf); - StringBuf_Printf(&buf, "INSERT INTO `%s`(`quest_id`, `char_id`, `num`, `name`, `count`) VALUES ('%d', '%d', '%d', '%s', '%d')", - quest_obj_db, qd.quest_id, char_id, i, qd.objectives[i].name, qd.objectives[i].count); + StringBuf_Destroy(&buf); - if ( success && SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) - { - Sql_ShowDebug(sql_handle); - success = false; - } + return 0; + +} + +//Update a questlog +int mapif_parse_quest_update(int fd) +{ + + StringBuf buf; + bool success = true; + int char_id = RFIFOL(fd,4); + struct quest qd; + + memcpy(&qd, RFIFOP(fd,8), RFIFOW(fd,2)-8); + + StringBuf_Init(&buf); + StringBuf_Printf(&buf, "UPDATE `%s` SET `state`='%d', `count1`='%d', `count2`='%d', `count3`='%d' WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, qd.state, qd.count[0], qd.count[1], qd.count[2], qd.quest_id, char_id); + + if ( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) + { + Sql_ShowDebug(sql_handle); + success = false; } WFIFOHEAD(fd,11); - WFIFOW(fd,0) = 0x3861; + WFIFOW(fd,0) = 0x3863; WFIFOL(fd,2) = char_id; WFIFOL(fd,6) = qd.quest_id; WFIFOB(fd,10) = success?1:0; @@ -155,14 +151,12 @@ 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; + int num_quests, i, num_complete = 0; + int complete[MAX_QUEST]; - for(i=0; i<MAX_QUEST; i++) - { - memset(&tmp_questlog[i], 0, sizeof(struct quest)); - } + memset(tmp_questlog, 0, sizeof(tmp_questlog)); + memset(complete, 0, sizeof(complete)); num_quests = mapif_quests_fromsql(char_id, tmp_questlog); @@ -171,11 +165,21 @@ int mapif_send_quests(int fd, int char_id) WFIFOW(fd,2) = num_quests*sizeof(struct quest)+8; WFIFOL(fd,4) = char_id; - for(i=0; i<num_quests; i++) + //Active and inactive quests + for( i = 0; i < num_quests; i++ ) { - memcpy(WFIFOP(fd,i*sizeof(struct quest)+8), &tmp_questlog[i], sizeof(struct quest)); + if( tmp_questlog[i].state == Q_COMPLETE ) + { + complete[num_complete++] = i; + continue; + } + memcpy(WFIFOP(fd,(i-num_complete)*sizeof(struct quest)+8), &tmp_questlog[i], sizeof(struct quest)); } + // Completed quests + for( i = num_quests - num_complete; i < num_quests; i++ ) + memcpy(WFIFOP(fd,i*sizeof(struct quest)+8), &tmp_questlog[complete[i-num_quests+num_complete]], sizeof(struct quest)); + WFIFOSET(fd,num_quests*sizeof(struct quest)+8); return 0; @@ -196,6 +200,7 @@ int inter_quest_parse_frommap(int fd) case 0x3060: mapif_parse_loadquestrequest(fd); break; case 0x3061: mapif_parse_quest_add(fd); break; case 0x3062: mapif_parse_quest_delete(fd); break; + case 0x3063: mapif_parse_quest_update(fd); break; default: return 0; } diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c index 5c8d30c54..5b61ab281 100644 --- a/src/char_sql/inter.c +++ b/src/char_sql/inter.c @@ -51,7 +51,7 @@ int inter_recv_packet_length[] = { -1, 6,-1,-1, 55,19, 6,-1, 14,-1,-1,-1, 18,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] - 6,-1,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin] + 6,-1,10,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3060- Quest system [Kevin] [Inkfish] -1,10, 6,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3070- Mercenary packets [Zephyrus] 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] |