diff options
author | Haru <haru@dotalux.com> | 2018-06-25 01:10:48 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2018-06-30 01:51:12 +0200 |
commit | d9ac8282fc89aa3eb2f4946940889c22c22bc0df (patch) | |
tree | 54e774d1f5b83bfeee00d9247ba334c078e2fb81 | |
parent | ed92fbc689ac441d0e42c3e332620f8410206e55 (diff) | |
download | hercules-d9ac8282fc89aa3eb2f4946940889c22c22bc0df.tar.gz hercules-d9ac8282fc89aa3eb2f4946940889c22c22bc0df.tar.bz2 hercules-d9ac8282fc89aa3eb2f4946940889c22c22bc0df.tar.xz hercules-d9ac8282fc89aa3eb2f4946940889c22c22bc0df.zip |
Move mapif functions from int_rodex.c to mapif.c and fix some return types
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | src/char/int_rodex.c | 171 | ||||
-rw-r--r-- | src/char/mapif.c | 181 | ||||
-rw-r--r-- | src/char/mapif.h | 18 |
3 files changed, 181 insertions, 189 deletions
diff --git a/src/char/int_rodex.c b/src/char/int_rodex.c index 8494c6427..ddd019bb8 100644 --- a/src/char/int_rodex.c +++ b/src/char/int_rodex.c @@ -347,101 +347,6 @@ int64 inter_rodex_savemessage(struct rodex_message* msg) } /*========================================== - * Inbox Request - *------------------------------------------*/ -void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int count, int64 mail_id, struct rodex_maillist *mails) -{ - int per_packet = (UINT16_MAX - 24) / sizeof(struct rodex_message); - int sent = 0; - bool is_first = true; - nullpo_retv(mails); - Assert_retv(char_id > 0); - Assert_retv(count >= 0); - Assert_retv(mail_id >= 0); - - do { - int i = 24, j, size, limit; - int to_send = count - sent; - bool is_last = true; - - if (to_send <= per_packet) { - size = to_send * sizeof(struct rodex_message) + 24; - limit = to_send; - is_last = true; - } else { - limit = min(to_send, per_packet); - if (limit != to_send) { - is_last = false; - } - size = limit * sizeof(struct rodex_message) + 24; - } - - WFIFOHEAD(fd, size); - WFIFOW(fd, 0) = 0x3895; - WFIFOW(fd, 2) = size; - WFIFOL(fd, 4) = char_id; - WFIFOB(fd, 8) = opentype; - WFIFOB(fd, 9) = flag; - WFIFOB(fd, 10) = is_last; - WFIFOB(fd, 11) = is_first; - WFIFOL(fd, 12) = limit; - WFIFOQ(fd, 16) = mail_id; - 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); -} - -void mapif_parse_rodex_requestinbox(int fd) -{ - int count; - int char_id = RFIFOL(fd,2); - int account_id = RFIFOL(fd, 6); - int8 flag = RFIFOB(fd, 10); - int8 opentype = RFIFOB(fd, 11); - int64 mail_id = RFIFOQ(fd, 12); - struct rodex_maillist mails = { 0 }; - - VECTOR_INIT(mails); - if (flag == 0) - count = inter_rodex->fromsql(char_id, account_id, opentype, 0, &mails); - else - count = inter_rodex->fromsql(char_id, account_id, opentype, mail_id, &mails); - mapif->rodex_sendinbox(fd, char_id, opentype, flag, count, mail_id, &mails); - VECTOR_CLEAR(mails); -} - -/*========================================== -* Checks if there are new mails -*------------------------------------------*/ -void mapif_rodex_sendhasnew(int fd, int char_id, bool has_new) -{ - Assert_retv(char_id > 0); - - WFIFOHEAD(fd, 7); - WFIFOW(fd, 0) = 0x3896; - WFIFOL(fd, 2) = char_id; - WFIFOB(fd, 6) = has_new; - WFIFOSET(fd, 7); -} - -void mapif_parse_rodex_checkhasnew(int fd) -{ - int char_id = RFIFOL(fd, 2); - int account_id = RFIFOL(fd, 6); - bool has_new; - - Assert_retv(account_id >= START_ACCOUNT_NUM && account_id <= END_ACCOUNT_NUM); - Assert_retv(char_id >= START_CHAR_NUM); - - has_new = inter_rodex->hasnew(char_id, account_id); - mapif->rodex_sendhasnew(fd, char_id, has_new); -} - -/*========================================== * Update/Delete mail *------------------------------------------*/ bool inter_rodex_updatemail(int64 mail_id, int8 flag) @@ -485,82 +390,6 @@ bool inter_rodex_updatemail(int64 mail_id, int8 flag) } /*========================================== - * Update/Delete mail - *------------------------------------------*/ -void mapif_parse_rodex_updatemail(int fd) -{ - int64 mail_id = RFIFOL(fd, 2); - int8 flag = RFIFOB(fd, 10); - - inter_rodex->updatemail(mail_id, flag); -} - -/*========================================== - * Send Mail - *------------------------------------------*/ -void mapif_rodex_send(int fd, int sender_id, int receiver_id, int receiver_accountid, bool result) -{ - Assert_retv(sender_id >= 0); - Assert_retv(receiver_id + receiver_accountid > 0); - - WFIFOHEAD(fd,15); - WFIFOW(fd,0) = 0x3897; - WFIFOL(fd,2) = sender_id; - WFIFOL(fd,6) = receiver_id; - WFIFOL(fd,10) = receiver_accountid; - WFIFOB(fd,14) = result; - WFIFOSET(fd,15); -} - -void mapif_parse_rodex_send(int fd) -{ - struct rodex_message msg = { 0 }; - - if (RFIFOW(fd,2) != 4 + sizeof(struct rodex_message)) - return; - - memcpy(&msg, RFIFOP(fd,4), sizeof(struct rodex_message)); - if (msg.receiver_id > 0 || msg.receiver_accountid > 0) - msg.id = inter_rodex->savemessage(&msg); - - mapif->rodex_send(fd, msg.sender_id, msg.receiver_id, msg.receiver_accountid, msg.id > 0 ? true : false); -} - -/*------------------------------------------ - * Check Player - *------------------------------------------*/ -void mapif_rodex_checkname(int fd, int reqchar_id, int target_char_id, short target_class, int target_level, char *name) -{ - nullpo_retv(name); - Assert_retv(reqchar_id > 0); - Assert_retv(target_char_id >= 0); - - WFIFOHEAD(fd, 16 + NAME_LENGTH); - WFIFOW(fd, 0) = 0x3898; - WFIFOL(fd, 2) = reqchar_id; - WFIFOL(fd, 6) = target_char_id; - WFIFOW(fd, 10) = target_class; - WFIFOL(fd, 12) = target_level; - safestrncpy(WFIFOP(fd, 16), name, NAME_LENGTH); - WFIFOSET(fd, 16 + NAME_LENGTH); -} - -void mapif_parse_rodex_checkname(int fd) -{ - int reqchar_id = RFIFOL(fd, 2); - char name[NAME_LENGTH]; - int target_char_id, target_level; - short target_class; - - safestrncpy(name, RFIFOP(fd, 6), NAME_LENGTH); - - if (inter_rodex->checkname(name, &target_char_id, &target_class, &target_level) == true) - mapif->rodex_checkname(fd, reqchar_id, target_char_id, target_class, target_level, name); - else - mapif->rodex_checkname(fd, reqchar_id, 0, 0, 0, name); -} - -/*========================================== * Packets From Map Server *------------------------------------------*/ int inter_rodex_parse_frommap(int fd) diff --git a/src/char/mapif.c b/src/char/mapif.c index cb2cb381f..60f2dcbb3 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -1632,15 +1632,178 @@ int mapif_parse_quest_load(int fd) } /* RoDEX */ -int mapif_parse_rodex_requestinbox(int fd); -void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int count, int64 mail_id, struct rodex_maillist *mails); -int mapif_parse_rodex_checkhasnew(int fd); -void mapif_rodex_sendhasnew(int fd, int char_id, bool has_new); -int mapif_parse_rodex_updatemail(int fd); -int mapif_parse_rodex_send(int fd); -void mapif_rodex_send(int fd, int sender_id, int receiver_id, int receiver_accountid, bool result); -int mapif_parse_rodex_checkname(int fd); -void mapif_rodex_checkname(int fd, int reqchar_id, int target_char_id, short target_class, int target_level, char *name); + +/*========================================== + * Inbox Request + *------------------------------------------*/ +void mapif_parse_rodex_requestinbox(int fd) +{ + int count; + int char_id = RFIFOL(fd,2); + int account_id = RFIFOL(fd, 6); + int8 flag = RFIFOB(fd, 10); + int8 opentype = RFIFOB(fd, 11); + int64 mail_id = RFIFOQ(fd, 12); + struct rodex_maillist mails = { 0 }; + + VECTOR_INIT(mails); + if (flag == 0) + count = inter_rodex->fromsql(char_id, account_id, opentype, 0, &mails); + else + count = inter_rodex->fromsql(char_id, account_id, opentype, mail_id, &mails); + mapif->rodex_sendinbox(fd, char_id, opentype, flag, count, mail_id, &mails); + VECTOR_CLEAR(mails); +} + +void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int count, int64 mail_id, struct rodex_maillist *mails) +{ + int per_packet = (UINT16_MAX - 24) / sizeof(struct rodex_message); + int sent = 0; + bool is_first = true; + nullpo_retv(mails); + Assert_retv(char_id > 0); + Assert_retv(count >= 0); + Assert_retv(mail_id >= 0); + + do { + int i = 24, j, size, limit; + int to_send = count - sent; + bool is_last = true; + + if (to_send <= per_packet) { + size = to_send * sizeof(struct rodex_message) + 24; + limit = to_send; + is_last = true; + } else { + limit = min(to_send, per_packet); + if (limit != to_send) { + is_last = false; + } + size = limit * sizeof(struct rodex_message) + 24; + } + + WFIFOHEAD(fd, size); + WFIFOW(fd, 0) = 0x3895; + WFIFOW(fd, 2) = size; + WFIFOL(fd, 4) = char_id; + WFIFOB(fd, 8) = opentype; + WFIFOB(fd, 9) = flag; + WFIFOB(fd, 10) = is_last; + WFIFOB(fd, 11) = is_first; + WFIFOL(fd, 12) = limit; + WFIFOQ(fd, 16) = mail_id; + 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); +} + +/*========================================== + * Checks if there are new mails + *------------------------------------------*/ +void mapif_parse_rodex_checkhasnew(int fd) +{ + int char_id = RFIFOL(fd, 2); + int account_id = RFIFOL(fd, 6); + bool has_new; + + Assert_retv(account_id >= START_ACCOUNT_NUM && account_id <= END_ACCOUNT_NUM); + Assert_retv(char_id >= START_CHAR_NUM); + + has_new = inter_rodex->hasnew(char_id, account_id); + mapif->rodex_sendhasnew(fd, char_id, has_new); +} + +void mapif_rodex_sendhasnew(int fd, int char_id, bool has_new) +{ + Assert_retv(char_id > 0); + + WFIFOHEAD(fd, 7); + WFIFOW(fd, 0) = 0x3896; + WFIFOL(fd, 2) = char_id; + WFIFOB(fd, 6) = has_new; + WFIFOSET(fd, 7); +} + +/*========================================== + * Update/Delete mail + *------------------------------------------*/ +void mapif_parse_rodex_updatemail(int fd) +{ + int64 mail_id = RFIFOL(fd, 2); + int8 flag = RFIFOB(fd, 10); + + inter_rodex->updatemail(mail_id, flag); +} + +/*========================================== + * Send Mail + *------------------------------------------*/ +void mapif_parse_rodex_send(int fd) +{ + struct rodex_message msg = { 0 }; + + if (RFIFOW(fd,2) != 4 + sizeof(struct rodex_message)) + return; + + memcpy(&msg, RFIFOP(fd,4), sizeof(struct rodex_message)); + if (msg.receiver_id > 0 || msg.receiver_accountid > 0) + msg.id = inter_rodex->savemessage(&msg); + + mapif->rodex_send(fd, msg.sender_id, msg.receiver_id, msg.receiver_accountid, msg.id > 0 ? true : false); +} + +void mapif_rodex_send(int fd, int sender_id, int receiver_id, int receiver_accountid, bool result) +{ + Assert_retv(sender_id >= 0); + Assert_retv(receiver_id + receiver_accountid > 0); + + WFIFOHEAD(fd,15); + WFIFOW(fd,0) = 0x3897; + WFIFOL(fd,2) = sender_id; + WFIFOL(fd,6) = receiver_id; + WFIFOL(fd,10) = receiver_accountid; + WFIFOB(fd,14) = result; + WFIFOSET(fd,15); +} + +/*------------------------------------------ + * Check Player + *------------------------------------------*/ +void mapif_parse_rodex_checkname(int fd) +{ + int reqchar_id = RFIFOL(fd, 2); + char name[NAME_LENGTH]; + int target_char_id, target_level; + short target_class; + + safestrncpy(name, RFIFOP(fd, 6), NAME_LENGTH); + + if (inter_rodex->checkname(name, &target_char_id, &target_class, &target_level) == true) + mapif->rodex_checkname(fd, reqchar_id, target_char_id, target_class, target_level, name); + else + mapif->rodex_checkname(fd, reqchar_id, 0, 0, 0, name); +} + +void mapif_rodex_checkname(int fd, int reqchar_id, int target_char_id, short target_class, int target_level, char *name) +{ + nullpo_retv(name); + Assert_retv(reqchar_id > 0); + Assert_retv(target_char_id >= 0); + + WFIFOHEAD(fd, 16 + NAME_LENGTH); + WFIFOW(fd, 0) = 0x3898; + WFIFOL(fd, 2) = reqchar_id; + WFIFOL(fd, 6) = target_char_id; + WFIFOW(fd, 10) = target_class; + WFIFOL(fd, 12) = target_level; + safestrncpy(WFIFOP(fd, 16), name, NAME_LENGTH); + WFIFOSET(fd, 16 + NAME_LENGTH); +} + int mapif_load_guild_storage(int fd,int account_id,int guild_id, char flag); int mapif_save_guild_storage_ack(int fd, int account_id, int guild_id, int fail); int mapif_parse_LoadGuildStorage(int fd); diff --git a/src/char/mapif.h b/src/char/mapif.h index 659513797..6b88fd885 100644 --- a/src/char/mapif.h +++ b/src/char/mapif.h @@ -154,15 +154,15 @@ struct mapif_interface { int (*parse_quest_save) (int fd); void (*send_quests) (int fd, int char_id, struct quest *tmp_questlog, int num_quests); int (*parse_quest_load) (int fd); - int(*parse_rodex_requestinbox) (int fd); - void(*rodex_sendinbox) (int fd, int char_id, int8 opentype, int8 flag, int count, int64 mail_id, struct rodex_maillist *mails); - int(*parse_rodex_checkhasnew) (int fd); - void(*rodex_sendhasnew) (int fd, int char_id, bool has_new); - int(*parse_rodex_updatemail) (int fd); - int(*parse_rodex_send) (int fd); - void(*rodex_send) (int fd, int sender_id, int receiver_id, int receiver_accountid, bool result); - int(*parse_rodex_checkname) (int fd); - void(*rodex_checkname) (int fd, int reqchar_id, int target_char_id, short target_class, int target_level, char *name); + void (*parse_rodex_requestinbox) (int fd); + void (*rodex_sendinbox) (int fd, int char_id, int8 opentype, int8 flag, int count, int64 mail_id, struct rodex_maillist *mails); + void (*parse_rodex_checkhasnew) (int fd); + void (*rodex_sendhasnew) (int fd, int char_id, bool has_new); + void (*parse_rodex_updatemail) (int fd); + void (*parse_rodex_send) (int fd); + void (*rodex_send) (int fd, int sender_id, int receiver_id, int receiver_accountid, bool result); + void (*parse_rodex_checkname) (int fd); + void (*rodex_checkname) (int fd, int reqchar_id, int target_char_id, short target_class, int target_level, char *name); int (*load_guild_storage) (int fd, int account_id, int guild_id, char flag); int (*save_guild_storage_ack) (int fd, int account_id, int guild_id, int fail); int (*parse_LoadGuildStorage) (int fd); |