From 101f3ab0d123733c12218e4cf4b87a2392d97001 Mon Sep 17 00:00:00 2001 From: Guilherme Guiguer Menaldo Date: Thu, 28 Dec 2017 13:07:26 -0200 Subject: Fixed rodex loading mails when it requires multiple packets. --- src/char/int_rodex.c | 20 ++++++++++++-------- src/map/intif.c | 17 +++++++++++------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/char/int_rodex.c b/src/char/int_rodex.c index f5d036991..b7314e726 100644 --- a/src/char/int_rodex.c +++ b/src/char/int_rodex.c @@ -346,27 +346,28 @@ int64 inter_rodex_savemessage(struct rodex_message* msg) *------------------------------------------*/ void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int count, struct rodex_maillist *mails) { - int per_packet = (UINT16_MAX - 15) / sizeof(struct rodex_message); + int per_packet = (UINT16_MAX - 16) / sizeof(struct rodex_message); int sent = 0; + bool is_first = true; nullpo_retv(mails); Assert_retv(char_id > 0); Assert_retv(count >= 0); do { - int i = 15, j, size, limit; + int i = 16, j, size, limit; + int to_send = count - sent; bool is_last = true; - if (count <= per_packet) { - size = count * sizeof(struct rodex_message) + 15; - limit = count; + if (to_send <= per_packet) { + size = to_send * sizeof(struct rodex_message) + 16; + limit = to_send; is_last = true; } else { - int to_send = count - sent; limit = min(to_send, per_packet); if (limit != to_send) { is_last = false; } - size = limit * sizeof(struct rodex_message) + 15; + size = limit * sizeof(struct rodex_message) + 16; } WFIFOHEAD(fd, size); @@ -376,11 +377,14 @@ void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int co WFIFOB(fd, 8) = opentype; WFIFOB(fd, 9) = flag; WFIFOB(fd, 10) = is_last; - WFIFOL(fd, 11) = count; + WFIFOB(fd, 11) = is_first; + WFIFOL(fd, 12) = limit; for (j = 0; j < limit; ++j, ++sent, i += sizeof(struct rodex_message)) { memcpy(WFIFOP(fd, i), &VECTOR_INDEX(*mails, sent), sizeof(struct rodex_message)); } WFIFOSET(fd, size); + + is_first = false; } while (sent < count); } diff --git a/src/map/intif.c b/src/map/intif.c index 60edc8d8b..338e3a1ea 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -2438,7 +2438,8 @@ void intif_parse_RequestRodexOpenInbox(int fd) #endif int8 flag = RFIFOB(fd, 9); int8 is_end = RFIFOB(fd, 10); - int count = RFIFOL(fd, 11); + int is_first = RFIFOB(fd, 11); + int count = RFIFOL(fd, 12); int i, j; sd = map->charid2sd(RFIFOL(fd, 4)); @@ -2446,16 +2447,20 @@ void intif_parse_RequestRodexOpenInbox(int fd) if (sd == NULL) // user is not online anymore return; - sd->rodex.total = count; - if (RFIFOW(fd, 2) - 15 != sd->rodex.total * sizeof(struct rodex_message)) { - ShowError("intif_parse_RodexInboxOpenReceived: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd, 2) - 15, sd->rodex.total * sizeof(struct rodex_message)); + if (is_first) + sd->rodex.total = count; + else + sd->rodex.total += count; + + if (RFIFOW(fd, 2) - 16 != count * sizeof(struct rodex_message)) { + ShowError("intif_parse_RodexInboxOpenReceived: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd, 2) - 16, count * sizeof(struct rodex_message)); return; } - if (flag == 0) + if (flag == 0 && is_first) VECTOR_CLEAR(sd->rodex.messages); - for (i = 0, j = 15; i < count; ++i, j += sizeof(struct rodex_message)) { + for (i = 0, j = 16; i < count; ++i, j += sizeof(struct rodex_message)) { struct rodex_message msg = { 0 }; VECTOR_ENSURE(sd->rodex.messages, 1, 1); memcpy(&msg, RFIFOP(fd, j), sizeof(struct rodex_message)); -- cgit v1.2.3-70-g09d2 From 09163dc60143ae8427d25fb8e9863adba986bb72 Mon Sep 17 00:00:00 2001 From: Guilherme Guiguer Menaldo Date: Thu, 28 Dec 2017 17:27:00 -0200 Subject: Added an extra check --- src/map/intif.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/map/intif.c b/src/map/intif.c index 338e3a1ea..be6b75d96 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -2447,6 +2447,11 @@ void intif_parse_RequestRodexOpenInbox(int fd) if (sd == NULL) // user is not online anymore return; + if (is_first == false && sd->rodex.total == 0) { + ShowError("intif_parse_RodexInboxOpenReceived: mail list received in wrong order.\n"); + return; + } + if (is_first) sd->rodex.total = count; else -- cgit v1.2.3-70-g09d2