diff options
author | Haru <haru@dotalux.com> | 2018-06-24 21:55:04 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2018-06-30 01:51:10 +0200 |
commit | bc7e7be46de608fb695e6e324dd76fb6c2a91eea (patch) | |
tree | 3e39c746ae8c19023820e1ce45ad0024cae6c8d7 /src/char/mapif.c | |
parent | ebfed84acca20677b0b44391c4dca345e92f5829 (diff) | |
download | hercules-bc7e7be46de608fb695e6e324dd76fb6c2a91eea.tar.gz hercules-bc7e7be46de608fb695e6e324dd76fb6c2a91eea.tar.bz2 hercules-bc7e7be46de608fb695e6e324dd76fb6c2a91eea.tar.xz hercules-bc7e7be46de608fb695e6e324dd76fb6c2a91eea.zip |
Move mapif functions from int_mail.c to mapif.c
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/char/mapif.c')
-rw-r--r-- | src/char/mapif.c | 167 |
1 files changed, 155 insertions, 12 deletions
diff --git a/src/char/mapif.c b/src/char/mapif.c index 3b8186ab2..b137fc448 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -973,18 +973,161 @@ void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, const ch mapif->homunculus_renamed(fd, account_id, char_id, result, name); } -void mapif_mail_sendinbox(int fd, int char_id, unsigned char flag, struct mail_data *md); -void mapif_parse_mail_requestinbox(int fd); -void mapif_parse_mail_read(int fd); -void mapif_mail_sendattach(int fd, int char_id, struct mail_message *msg); -void mapif_parse_mail_getattach(int fd); -void mapif_mail_delete(int fd, int char_id, int mail_id, bool failed); -void mapif_parse_mail_delete(int fd); -void mapif_mail_new(struct mail_message *msg); -void mapif_mail_return(int fd, int char_id, int mail_id, int new_mail); -void mapif_parse_mail_return(int fd); -void mapif_mail_send(int fd, struct mail_message* msg); -void mapif_parse_mail_send(int fd); +void mapif_mail_sendinbox(int fd, int char_id, unsigned char flag, struct mail_data *md) +{ + nullpo_retv(md); + //FIXME: dumping the whole structure like this is unsafe [ultramage] + WFIFOHEAD(fd, sizeof(struct mail_data) + 9); + WFIFOW(fd, 0) = 0x3848; + WFIFOW(fd, 2) = sizeof(struct mail_data) + 9; + WFIFOL(fd, 4) = char_id; + WFIFOB(fd, 8) = flag; + memcpy(WFIFOP(fd, 9),md,sizeof(struct mail_data)); + WFIFOSET(fd,WFIFOW(fd, 2)); +} + +/*========================================== + * Client Inbox Request + *------------------------------------------*/ +void mapif_parse_mail_requestinbox(int fd) +{ + int char_id = RFIFOL(fd, 2); + unsigned char flag = RFIFOB(fd, 6); + struct mail_data md; + memset(&md, 0, sizeof(md)); + inter_mail->fromsql(char_id, &md); + mapif->mail_sendinbox(fd, char_id, flag, &md); +} + +/*========================================== + * Mark mail as 'Read' + *------------------------------------------*/ +void mapif_parse_mail_read(int fd) +{ + int mail_id = RFIFOL(fd, 2); + inter_mail->mark_read(mail_id); +} + +void mapif_mail_sendattach(int fd, int char_id, struct mail_message *msg) +{ + nullpo_retv(msg); + WFIFOHEAD(fd, sizeof(struct item) + 12); + WFIFOW(fd, 0) = 0x384a; + WFIFOW(fd, 2) = sizeof(struct item) + 12; + WFIFOL(fd, 4) = char_id; + WFIFOL(fd, 8) = (msg->zeny > 0) ? msg->zeny : 0; + memcpy(WFIFOP(fd, 12), &msg->item, sizeof(struct item)); + WFIFOSET(fd,WFIFOW(fd, 2)); +} + +void mapif_parse_mail_getattach(int fd) +{ + struct mail_message msg = { 0 }; + int char_id = RFIFOL(fd, 2); + int mail_id = RFIFOL(fd, 6); + + if (!inter_mail->get_attachment(char_id, mail_id, &msg)) + return; + + mapif->mail_sendattach(fd, char_id, &msg); +} + +/*========================================== + * Delete Mail + *------------------------------------------*/ +void mapif_mail_delete(int fd, int char_id, int mail_id, bool failed) +{ + WFIFOHEAD(fd, 11); + WFIFOW(fd, 0) = 0x384b; + WFIFOL(fd, 2) = char_id; + WFIFOL(fd, 6) = mail_id; + WFIFOB(fd, 10) = failed; + WFIFOSET(fd, 11); +} + +void mapif_parse_mail_delete(int fd) +{ + int char_id = RFIFOL(fd, 2); + int mail_id = RFIFOL(fd, 6); + bool failed = !inter_mail->delete(char_id, mail_id); + mapif->mail_delete(fd, char_id, mail_id, failed); +} + +/*========================================== + * Report New Mail to Map Server + *------------------------------------------*/ +void mapif_mail_new(struct mail_message *msg) +{ + unsigned char buf[74]; + + if (msg == NULL || msg->id == 0) + return; + + WBUFW(buf, 0) = 0x3849; + WBUFL(buf, 2) = msg->dest_id; + WBUFL(buf, 6) = msg->id; + memcpy(WBUFP(buf, 10), msg->send_name, NAME_LENGTH); + memcpy(WBUFP(buf, 34), msg->title, MAIL_TITLE_LENGTH); + mapif->sendall(buf, 74); +} + +/*========================================== + * Return Mail + *------------------------------------------*/ +void mapif_mail_return(int fd, int char_id, int mail_id, int new_mail) +{ + WFIFOHEAD(fd, 11); + WFIFOW(fd, 0) = 0x384c; + WFIFOL(fd, 2) = char_id; + WFIFOL(fd, 6) = mail_id; + WFIFOB(fd, 10) = (new_mail == 0); + WFIFOSET(fd, 11); +} + +void mapif_parse_mail_return(int fd) +{ + int char_id = RFIFOL(fd, 2); + int mail_id = RFIFOL(fd, 6); + int new_mail = 0; + + if (!inter_mail->return_message(char_id, mail_id, &new_mail)) + return; + + mapif->mail_return(fd, char_id, mail_id, new_mail); +} + +/*========================================== + * Send Mail + *------------------------------------------*/ +void mapif_mail_send(int fd, struct mail_message* msg) +{ + int len = sizeof(struct mail_message) + 4; + + nullpo_retv(msg); + WFIFOHEAD(fd, len); + WFIFOW(fd, 0) = 0x384d; + WFIFOW(fd, 2) = len; + memcpy(WFIFOP(fd, 4), msg, sizeof(struct mail_message)); + WFIFOSET(fd,len); +} + +void mapif_parse_mail_send(int fd) +{ + struct mail_message msg; + int account_id = 0; + + if (RFIFOW(fd, 2) != 8 + sizeof(struct mail_message)) + return; + + account_id = RFIFOL(fd, 4); + memcpy(&msg, RFIFOP(fd, 8), sizeof(struct mail_message)); + + inter_mail->send(account_id, &msg); + + mapif->mail_send(fd, &msg); // notify sender + mapif->mail_new(&msg); // notify recipient +} + bool mapif_mercenary_create(struct s_mercenary *merc); bool mapif_mercenary_save(const struct s_mercenary *merc); bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc); |