From 1013fd3227f78a0b02c121a36a6f66fdcbd75203 Mon Sep 17 00:00:00 2001 From: Inkfish Date: Fri, 21 Aug 2009 07:16:40 +0000 Subject: Fixed the wrong packet length makes client choke when add_quest packets are sent. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14019 54d463be-8e91-2dee-dedb-b68131a5f0ec --- Changelog-Trunk.txt | 1 + src/char_sql/int_quest.c | 41 +++++++++++++++++------------------------ src/map/clif.c | 2 +- src/map/intif.c | 24 +++--------------------- src/map/quest.c | 11 +++-------- 5 files changed, 25 insertions(+), 54 deletions(-) diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 98e67415a..ecb19550c 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -5,6 +5,7 @@ IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. 09/08/20 * Added bMagicHPGainValue and bMagicSPGainValue. [Inkfish] + * Fixed the wrong packet length makes client choke when add_quest packets are sent. [Inkfish] 09/08/18 * Some fixes for Heat [Inkfish] - Heat and other ground skills' activation won't cancel combo wait. (bugreport:3228) diff --git a/src/char_sql/int_quest.c b/src/char_sql/int_quest.c index 8c7a46e30..21eb68be5 100644 --- a/src/char_sql/int_quest.c +++ b/src/char_sql/int_quest.c @@ -59,19 +59,19 @@ int mapif_quests_fromsql(int char_id, struct quest questlog[]) } //Delete a quest -int mapif_quest_delete(int char_id, int quest_id) +bool mapif_quest_delete(int char_id, int quest_id) { if ( SQL_ERROR == Sql_Query(sql_handle, "DELETE FROM `%s` WHERE `quest_id` = '%d' AND `char_id` = '%d'", quest_db, quest_id, char_id) ) { Sql_ShowDebug(sql_handle); - return -1; + return false; } - return 1; + return true; } //Add a quest to a questlog -int mapif_quest_add(int char_id, struct quest qd) +bool mapif_quest_add(int char_id, struct quest qd) { StringBuf buf; @@ -81,16 +81,16 @@ int mapif_quest_add(int char_id, struct quest qd) if ( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { Sql_ShowDebug(sql_handle); - return -1; + return false; } StringBuf_Destroy(&buf); - return 1; + return true; } //Update a questlog -int mapif_quest_update(int char_id, struct quest qd) +bool mapif_quest_update(int char_id, struct quest qd) { StringBuf buf; @@ -100,12 +100,12 @@ int mapif_quest_update(int char_id, struct quest qd) if ( SQL_ERROR == Sql_QueryStr(sql_handle, StringBuf_Value(&buf)) ) { Sql_ShowDebug(sql_handle); - return -1; + return false; } StringBuf_Destroy(&buf); - return 1; + return true; } //Save quests @@ -114,8 +114,7 @@ int mapif_parse_quest_save(int fd) int i, j, num2, num1 = (RFIFOW(fd,2)-8)/sizeof(struct quest); int char_id = RFIFOL(fd,4); struct quest qd1[MAX_QUEST_DB],qd2[MAX_QUEST_DB]; - int buf[MAX_QUEST_DB]; - int count = 0; + bool success = true; memset(qd1, 0, sizeof(qd1)); memset(qd2, 0, sizeof(qd2)); @@ -128,7 +127,7 @@ int mapif_parse_quest_save(int fd) if( j < num2 ) // Update existed quests { // Only states and counts are changable. if( qd1[i].state != qd2[j].state || qd1[i].count[0] != qd2[j].count[0] || qd1[i].count[1] != qd2[j].count[1] || qd1[i].count[2] != qd2[j].count[2] ) - mapif_quest_update(char_id, qd1[i]); + success &= mapif_quest_update(char_id, qd1[i]); if( j < (--num2) ) { @@ -138,23 +137,17 @@ int mapif_parse_quest_save(int fd) } else // Add new quests - { - mapif_quest_add(char_id, qd1[i]); - - WBUFL(buf,count*4) = qd1[i].quest_id; - count++; - } + success &= mapif_quest_add(char_id, qd1[i]); } for( i = 0; i < num2; i++ ) // Quests not in qd1 but in qd2 are to be erased. - mapif_quest_delete(char_id, qd2[i].quest_id); + success &= mapif_quest_delete(char_id, qd2[i].quest_id); - WFIFOHEAD(fd,8+4*count); + WFIFOHEAD(fd,7); WFIFOW(fd,0) = 0x3861; - WFIFOW(fd,2) = 8+4*count; - WFIFOL(fd,4) = char_id; - memcpy(WFIFOP(fd,8), buf, count*4); - WFIFOSET(fd,WFIFOW(fd,2)); + WFIFOL(fd,2) = char_id; + WFIFOB(fd,6) = success?1:0; + WFIFOSET(fd,7); return 0; } diff --git a/src/map/clif.c b/src/map/clif.c index 2c5bf1234..14f7730ac 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -13433,7 +13433,7 @@ static int packetdb_readdb(void) 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0, 0, 4, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0,117, 6, 0, 7, 7, 22,191, 0, 0, 0, 0, 0, 0, + 0, 0, 0,107, 6, 0, 7, 7, 22,191, 0, 0, 0, 0, 0, 0, //#0x02C0 0, 0, 0, 0, 0, 30, 0, 0, 0, 3, 0, 65, 4, 71, 10, 0, 0, 0, 0, 0, 0, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 0, diff --git a/src/map/intif.c b/src/map/intif.c index 9b60d40c0..204fbe497 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -38,7 +38,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] - -1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] + -1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] -1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3870 Mercenaries [Zephyrus] 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] @@ -1365,26 +1365,8 @@ int intif_parse_questlog(int fd) int intif_parse_questsave(int fd) { - TBL_PC * sd = map_charid2sd(RFIFOL(fd, 4)); - int i,j; - int count = (RFIFOW(fd, 2) - 8) / 4; - - if( !sd ) - return -1; - - for( i = 0; i < count; i++ ) - { - int qid = RFIFOL(fd, 4*i+8); - - ARR_FIND(0, sd->avail_quests, j, sd->quest_log[j].quest_id == qid); - if(j == sd->avail_quests) //shouldn't happen - { - ShowError("intif_parse_questsave: Quest %d not found in your quest log!\n", qid); - continue; - } - //This packet can't go before 'close' and 'next'. That's weird and why I send it here. [Inkfish] - clif_send_quest_info(sd, &sd->quest_log[j]); - } + if( !RFIFOB(fd, 6) ) + ShowError("intif_parse_questsave: Failed to save quest(s) for character %d!\n", RFIFOL(fd, 2)); return 0; } diff --git a/src/map/quest.c b/src/map/quest.c index 9c1da6aa5..386a030b9 100644 --- a/src/map/quest.c +++ b/src/map/quest.c @@ -103,10 +103,10 @@ int quest_add(TBL_PC * sd, int quest_id) sd->num_quests++; sd->avail_quests++; + clif_send_quest_info(sd, &sd->quest_log[i]); + if( save_settings&64 ) chrif_save(sd,0); - else - intif_quest_save(sd); return 0; } @@ -151,11 +151,10 @@ int quest_change(TBL_PC * sd, int qid1, int qid2) sd->quest_log[i].num_objectives = count; clif_send_quest_delete(sd, qid1); + clif_send_quest_info(sd, &sd->quest_log[i]); if( save_settings&64 ) chrif_save(sd,0); - else - intif_quest_save(sd); return 0; } @@ -182,8 +181,6 @@ int quest_delete(TBL_PC * sd, int quest_id) if( save_settings&64 ) chrif_save(sd,0); - else - intif_quest_save(sd); return 0; } @@ -242,8 +239,6 @@ int quest_update_status(TBL_PC * sd, int quest_id, quest_state status) if( save_settings&64 ) chrif_save(sd,0); - else - intif_quest_save(sd); return 0; } -- cgit v1.2.3-60-g2f50