diff options
author | shennetsind <ind@henn.et> | 2013-12-04 11:36:31 -0200 |
---|---|---|
committer | shennetsind <ind@henn.et> | 2013-12-04 11:36:31 -0200 |
commit | 2350c7e6a28630c0157ebca7e41f96b7716e79ce (patch) | |
tree | 2114c6ed441588450b01473e3896d620e513eaac /src/map/intif.c | |
parent | 85023b1aad64d2b3b5d5ff53e1704abe0e689aa9 (diff) | |
parent | fdd8d1556526abcfbc95263aa3b0a651e7f4cf0a (diff) | |
download | hercules-2350c7e6a28630c0157ebca7e41f96b7716e79ce.tar.gz hercules-2350c7e6a28630c0157ebca7e41f96b7716e79ce.tar.bz2 hercules-2350c7e6a28630c0157ebca7e41f96b7716e79ce.tar.xz hercules-2350c7e6a28630c0157ebca7e41f96b7716e79ce.zip |
Merge branch 'master' of https://github.com/HerculesWS/Hercules
Diffstat (limited to 'src/map/intif.c')
-rw-r--r-- | src/map/intif.c | 100 |
1 files changed, 66 insertions, 34 deletions
diff --git a/src/map/intif.c b/src/map/intif.c index 36ae753db..8fdc8e3a3 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -1311,50 +1311,79 @@ QUESTLOG SYSTEM FUNCTIONS ***************************************/ -int intif_request_questlog(TBL_PC *sd) -{ +/** + * Requests a character's quest log entries to the inter server. + * + * @param sd Character's data + */ +void 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; } +/** + * Parses the received quest log entries for a character from the inter server. + * + * Received in reply to the requests made by intif_request_questlog. + * + * @see intif_parse + */ void intif_parse_QuestLog(int fd) { - int char_id = RFIFOL(fd, 4); - int i; - TBL_PC * sd = map->charid2sd(char_id); + int char_id = RFIFOL(fd, 4), num_received = (RFIFOW(fd, 2)-8)/sizeof(struct quest); + TBL_PC *sd = map->charid2sd(char_id); - //User not online anymore - if(!sd) + if (!sd) // User not online anymore return; - sd->avail_quests = sd->num_quests = (RFIFOW(fd, 2)-8)/sizeof(struct quest); - - memset(&sd->quest_log, 0, sizeof(sd->quest_log)); - - for( i = 0; i < sd->num_quests; i++ ) - { - memcpy(&sd->quest_log[i], RFIFOP(fd, i*sizeof(struct quest)+8), sizeof(struct quest)); - - sd->quest_index[i] = quest->search_db(sd->quest_log[i].quest_id); - - if( sd->quest_index[i] < 0 ) - { - ShowError("intif_parse_QuestLog: quest %d not found in DB.\n",sd->quest_log[i].quest_id); - sd->avail_quests--; - sd->num_quests--; - i--; - continue; + if (num_received == 0) { + if (sd->quest_log) { + aFree(sd->quest_log); + sd->quest_log = NULL; + } + sd->num_quests = sd->avail_quests = 0; + } else { + struct quest *received = (struct quest *)RFIFOP(fd, 8); + int i, k = num_received; + if (sd->quest_log) { + RECREATE(sd->quest_log, struct quest, num_received); + } else { + CREATE(sd->quest_log, struct quest, num_received); } - if( sd->quest_log[i].state == Q_COMPLETE ) - sd->avail_quests--; + for (i = 0; i < num_received; i++) { + if( quest->db(received[i].quest_id) == &quest->dummy ) { + ShowError("intif_parse_QuestLog: quest %d not found in DB.\n", received[i].quest_id); + continue; + } + if (received->state != Q_COMPLETE) { + // Insert at the beginning + memcpy(&sd->quest_log[sd->avail_quests++], &received[i], sizeof(struct quest)); + } else { + // Insert at the end + memcpy(&sd->quest_log[--k], &received[i], sizeof(struct quest)); + } + sd->num_quests++; + } + if (sd->avail_quests < k) { + // sd->avail_quests and k didn't meet in the middle: some entries were skipped + if (k < num_received) // Move the entries at the end to fill the gap + memmove(&sd->quest_log[k], &sd->quest_log[sd->avail_quests], sizeof(struct quest)*(num_received - k)); + sd->quest_log = aRealloc(sd->quest_log, sizeof(struct quest)*sd->num_quests); + } } quest->pc_login(sd); } +/** + * Parses the quest log save ack for a character from the inter server. + * + * Received in reply to the requests made by intif_quest_save. + * + * @see intif_parse + */ void intif_parse_QuestSave(int fd) { int cid = RFIFOL(fd, 2); TBL_PC *sd = map->id2sd(cid); @@ -1365,21 +1394,24 @@ void intif_parse_QuestSave(int fd) { sd->save_quest = false; } -int intif_quest_save(TBL_PC *sd) -{ - int len; +/** + * Requests to the inter server to save a character's quest log entries. + * + * @param sd Character's data + * @return 0 in case of success, nonzero otherwise + */ +int intif_quest_save(TBL_PC *sd) { + int len = sizeof(struct quest)*sd->num_quests + 8; if(intif->CheckForCharServer()) - return 0; - - len = sizeof(struct quest)*sd->num_quests + 8; + return 1; WFIFOHEAD(inter_fd, len); WFIFOW(inter_fd,0) = 0x3061; WFIFOW(inter_fd,2) = len; WFIFOL(inter_fd,4) = sd->status.char_id; if( sd->num_quests ) - memcpy(WFIFOP(inter_fd,8), &sd->quest_log, sizeof(struct quest)*sd->num_quests); + memcpy(WFIFOP(inter_fd,8), sd->quest_log, sizeof(struct quest)*sd->num_quests); WFIFOSET(inter_fd, len); return 0; |