diff options
author | zephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-10-27 06:34:04 +0000 |
---|---|---|
committer | zephyrus <zephyrus@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-10-27 06:34:04 +0000 |
commit | 4ecca0e292aafef33fe168d59c1a4e013cc0cda6 (patch) | |
tree | 2650049dac1a64dc378a304c0f203380cfdd0cc8 /src/map | |
parent | 70d0ca7c1690136a8407bbe78dc4b9686a96c539 (diff) | |
download | hercules-4ecca0e292aafef33fe168d59c1a4e013cc0cda6.tar.gz hercules-4ecca0e292aafef33fe168d59c1a4e013cc0cda6.tar.bz2 hercules-4ecca0e292aafef33fe168d59c1a4e013cc0cda6.tar.xz hercules-4ecca0e292aafef33fe168d59c1a4e013cc0cda6.zip |
- Improvements to the mail system.
- Added a sql patch, renaming "read_flag" column to "status" on the mail db.
- Need more testing.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11583 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/clif.c | 215 | ||||
-rw-r--r-- | src/map/clif.h | 8 | ||||
-rw-r--r-- | src/map/intif.c | 117 | ||||
-rw-r--r-- | src/map/mail.c | 48 | ||||
-rw-r--r-- | src/map/mail.h | 5 | ||||
-rw-r--r-- | src/map/map.h | 1 |
6 files changed, 214 insertions, 180 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index 1b4a7bdf4..3dadc7e87 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -11301,6 +11301,77 @@ void clif_parse_AutoRevive(int fd, struct map_session_data *sd) *==========================================*/ /*------------------------------------------ + * Reply to an Attachment operation + * 0 : From inventory to Attachment OK + * 1 : Fail to set the attachment + * 2 : Weight Problems (when get the attachment) + *------------------------------------------*/ +void clif_Mail_attachment(int fd, unsigned char flag) +{ + WFIFOHEAD(fd,packet_len(0x245)); + WFIFOW(fd,0) = 0x245; + WFIFOB(fd,2) = flag; + WFIFOSET(fd,packet_len(0x245)); +} + +/*------------------------------------------ + * Send Mail ack + * 0 : Message Send Ok + * 1 : Destination char not found + *------------------------------------------*/ +void clif_Mail_send(int fd, bool fail) +{ + WFIFOHEAD(fd,packet_len(0x249)); + WFIFOW(fd,0) = 0x249; + WFIFOB(fd,2) = fail; + WFIFOSET(fd,packet_len(0x249)); +} + +/*------------------------------------------ + * Delete Mail ack + * 0 : Delete ok + * 1 : Delete failed + *------------------------------------------*/ +void clif_Mail_delete(int fd, int mail_id, short fail) +{ + WFIFOHEAD(fd, packet_len(0x257)); + WFIFOW(fd,0) = 0x257; + WFIFOL(fd,2) = mail_id; + WFIFOW(fd,6) = fail; + WFIFOSET(fd, packet_len(0x257)); +} + +/*------------------------------------------ + * Return Mail ack + * 0 : Mail returned to the sender + * 1 : The mail does not exist + *------------------------------------------*/ +void clif_Mail_return(int fd, int mail_id, short fail) +{ + WFIFOHEAD(fd,packet_len(0x274)); + WFIFOW(fd,0) = 0x274; + WFIFOL(fd,2) = mail_id; + WFIFOW(fd,6) = fail; + WFIFOSET(fd,packet_len(0x274)); +} + +/*------------------------------------------ + * You have New Mail + *------------------------------------------*/ +void clif_Mail_new(struct map_session_data *sd, int mail_id, const char *sender, const char *title) +{ + int fd = sd->fd; + sd->mail.inbox.changed = true; + + WFIFOHEAD(fd,packet_len(0x24a)); + WFIFOW(fd,0) = 0x24a; + WFIFOL(fd,2) = mail_id; + memcpy(WFIFOP(fd,6), sender, NAME_LENGTH); + memcpy(WFIFOP(fd,30), title, MAIL_TITLE_LENGTH); + WFIFOSET(fd,packet_len(0x24a)); +} + +/*------------------------------------------ * Opens Mail Window on Client *------------------------------------------*/ void clif_Mail_openmail(int fd) @@ -11331,25 +11402,26 @@ void clif_Mail_refreshinbox(struct map_session_data *sd) { msg = &md->msg[i]; if (msg->id < 1) - continue; // Deleted Message + continue; WFIFOL(fd,8+73*j) = msg->id; memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH); - WFIFOB(fd,52+73*j) = msg->read; + WFIFOB(fd,52+73*j) = (msg->status == MAIL_UNREAD); memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH); WFIFOL(fd,77+73*j) = msg->timestamp; j++; } WFIFOSET(fd,len); } + /*------------------------------------------ * Client Request Inbox List *------------------------------------------*/ void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd) { struct mail_data *md; - nullpo_retv(sd); + md = &sd->mail.inbox; if( md->amount < MAIL_MAX_INBOX && (md->full || md->changed) ) @@ -11371,6 +11443,7 @@ void clif_Mail_read(struct map_session_data *sd, int mail_id) ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id); if( i == MAIL_MAX_INBOX ) { + clif_Mail_return(sd->fd, mail_id, 1); // Mail don't exists ShowWarning("clif_parse_Mail_read: account %d trying to read a message not the inbox.\n", sd->status.account_id); return; } @@ -11397,36 +11470,26 @@ void clif_Mail_read(struct map_session_data *sd, int mail_id) WFIFOL(fd,72) = 0; WFIFOL(fd,76) = msg->zeny; - if (item->nameid) + if( item->nameid && (data = itemdb_search(item->nameid)) != NULL ) { WFIFOL(fd,80) = item->amount; - if ((data = itemdb_search(item->nameid)) != NULL) - WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid; - else - ShowWarning("clif_parse_Mail_read: Invalid attachment on message %d.\n", msg->id); - + WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid; WFIFOW(fd,86) = data->type; - } - else - { - WFIFOL(fd,80) = 0; - WFIFOW(fd,84) = 0; - WFIFOW(fd,86) = 0; + WFIFOB(fd,88) = item->identify; + WFIFOB(fd,89) = item->attribute; + WFIFOB(fd,90) = item->refine; + WFIFOW(fd,91) = item->card[0]; + WFIFOW(fd,93) = item->card[1]; + WFIFOW(fd,95) = item->card[2]; + WFIFOW(fd,97) = item->card[3]; } - WFIFOB(fd,88) = item->identify; - WFIFOB(fd,89) = item->attribute; - WFIFOB(fd,90) = item->refine; - WFIFOW(fd,91) = item->card[0]; - WFIFOW(fd,93) = item->card[1]; - WFIFOW(fd,95) = item->card[2]; - WFIFOW(fd,97) = item->card[3]; WFIFOB(fd,99) = (unsigned char)msg_len; safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len); WFIFOSET(fd,len); - if (!msg->read) { - msg->read = 1; + if (msg->status == MAIL_UNREAD) { + msg->status = MAIL_READED; intif_Mail_read(mail_id); clif_parse_Mail_refreshinbox(fd, sd); } @@ -11465,10 +11528,7 @@ void clif_parse_Mail_getattach(int fd, struct map_session_data *sd) weight = data->weight * sd->mail.inbox.msg[i].item.amount; if (weight > sd->max_weight - sd->weight) { - WFIFOHEAD(fd,packet_len(0x245)); - WFIFOW(fd,0) = 0x245; - WFIFOB(fd,2) = 2; - WFIFOSET(fd,packet_len(0x245)); + clif_Mail_attachment(fd, 2); return; } } @@ -11477,39 +11537,12 @@ void clif_parse_Mail_getattach(int fd, struct map_session_data *sd) memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item)); clif_Mail_read(sd, mail_id); - // Send the request for Char Server to delete the attachment - // If it is done, the client will receive it. intif_Mail_getattach(sd->status.char_id, mail_id); } /*------------------------------------------ * Delete Message *------------------------------------------*/ -void clif_Mail_delete(struct map_session_data *sd, int mail_id, bool failed) -{ - int fd = sd->fd; - - if( !failed ) - { - int i; - ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id); - if( i < MAIL_MAX_INBOX ) - { - memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message)); - sd->mail.inbox.amount--; - } - - if( sd->mail.inbox.full ) - intif_Mail_requestinbox(sd->status.char_id, 1); // Reload the Mail Inbox - } - - WFIFOHEAD(fd, packet_len(0x257)); - WFIFOW(fd,0) = 0x257; - WFIFOL(fd,2) = mail_id; - WFIFOW(fd,6) = failed; - WFIFOSET(fd, packet_len(0x257)); -} - void clif_parse_Mail_delete(int fd, struct map_session_data *sd) { int i, mail_id = RFIFOL(fd,2); @@ -11522,25 +11555,13 @@ void clif_parse_Mail_delete(int fd, struct map_session_data *sd) if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 ) { - clif_Mail_delete(sd, mail_id, 1); + clif_Mail_delete(sd->fd, mail_id, 1); return; } intif_Mail_delete(sd->status.char_id, mail_id); } } -/*------------------------------------------ - * You have Mail Message - *------------------------------------------*/ -void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title) -{ - WFIFOHEAD(fd,packet_len(0x24a)); - WFIFOW(fd,0) = 0x24a; - WFIFOL(fd,2) = mail_id; - memcpy(WFIFOP(fd,6), sender, NAME_LENGTH); - memcpy(WFIFOP(fd,30), title, MAIL_TITLE_LENGTH); - WFIFOSET(fd,packet_len(0x24a)); -} /*------------------------------------------ * Return Mail Message @@ -11553,38 +11574,8 @@ void clif_parse_Mail_return(int fd, struct map_session_data *sd) ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id); if (i < MAIL_MAX_INBOX) intif_Mail_return(sd->status.char_id, mail_id); -} - -void clif_Mail_return(struct map_session_data *sd, int mail_id, int new_mail) -{ - int fd = sd->fd; - - if (new_mail > 0) - { - int i; - ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id); - if (i < MAIL_MAX_INBOX) - { - struct map_session_data *rd = map_charid2sd(sd->mail.inbox.msg[i].send_id); - if (rd) - { - char title[MAIL_TITLE_LENGTH]; - snprintf(title, MAIL_TITLE_LENGTH, "RE:%s", sd->mail.inbox.msg[i].title); - - rd->mail.inbox.changed = 1; - clif_Mail_new(rd->fd, new_mail, sd->status.name, title); - } - - memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message)); - sd->mail.inbox.amount--; - } - } - - WFIFOHEAD(fd,packet_len(0x274)); - WFIFOW(fd,0) = 0x274; - WFIFOL(fd,2) = mail_id; - WFIFOW(fd,6) = (new_mail > 0)?0:1; - WFIFOSET(fd,packet_len(0x274)); + else + clif_Mail_return(sd->fd, mail_id, 1); } /*------------------------------------------ @@ -11594,7 +11585,7 @@ void clif_parse_Mail_setattach(int fd, struct map_session_data *sd) { int idx = RFIFOW(fd,2); int amount = RFIFOL(fd,4); - char flag; + unsigned char flag; nullpo_retv(sd); if (idx < 0 || amount < 0) @@ -11602,12 +11593,7 @@ void clif_parse_Mail_setattach(int fd, struct map_session_data *sd) flag = mail_setitem(sd, idx, amount); if (flag > -1) - { - WFIFOHEAD(fd,packet_len(0x245)); - WFIFOW(fd,0) = 0x245; - WFIFOB(fd,2) = flag; - WFIFOSET(fd,packet_len(0x245)); - } + clif_Mail_attachment(fd,flag); } /*------------------------------------------ @@ -11624,16 +11610,6 @@ void clif_parse_Mail_winopen(int fd, struct map_session_data *sd) mail_removezeny(sd, 0); } -/*------------------------------------------ - * Send Mail - *------------------------------------------*/ -void clif_Mail_send(int fd, unsigned char flag) -{ - WFIFOHEAD(fd,packet_len(0x249)); - WFIFOW(fd,0) = 0x249; - WFIFOB(fd,2) = flag; - WFIFOSET(fd,packet_len(0x249)); -} /// S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B void clif_parse_Mail_send(int fd, struct map_session_data *sd) @@ -11642,6 +11618,9 @@ void clif_parse_Mail_send(int fd, struct map_session_data *sd) int body_len; nullpo_retv(sd); + if( sd->state.trading ) + return; + if( RFIFOW(fd,2) < 69 ) { ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id); return; @@ -11681,7 +11660,7 @@ void clif_parse_Mail_send(int fd, struct map_session_data *sd) msg.timestamp = (int)mail_calctimes(); intif_Mail_send(sd->status.account_id, &msg); - sd->cansendmail_tick = gettick() + 1000; // 5 Seconds flood Protection + sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection } #endif diff --git a/src/map/clif.h b/src/map/clif.h index a3bc84d74..1bcaa5499 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -386,10 +386,10 @@ int do_init_clif(void); // MAIL SYSTEM void clif_Mail_openmail(int fd); void clif_Mail_read(struct map_session_data *sd, int mail_id); -void clif_Mail_delete(struct map_session_data *sd, int mail_id, bool failed); -void clif_Mail_return(struct map_session_data *sd, int mail_id, int new_mail); -void clif_Mail_send(int fd, unsigned char flag); -void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title); +void clif_Mail_delete(int fd, int mail_id, short fail); +void clif_Mail_return(int fd, int mail_id, short fail); +void clif_Mail_send(int fd, bool fail); +void clif_Mail_new(struct map_session_data *sd, int mail_id, const char *sender, const char *title); void clif_Mail_refreshinbox(struct map_session_data *sd); #endif diff --git a/src/map/intif.c b/src/map/intif.c index 702ab244a..211edfe2d 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -34,7 +34,7 @@ static const int packet_len_table[]={ -1, 7, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810 39,-1,15,15, 14,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820 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, 0,-1,11, 14,-1, 0, 0, //0x3840 + 9, 9,-1,14, 0, 0, 0, 0, -1,74,-1,11, 11,10, 0, 0, //0x3840 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1538,7 +1538,7 @@ int intif_Mail_getattach(int char_id, int mail_id) int intif_parse_Mail_getattach(int fd) { struct map_session_data *sd; - struct item *item; + struct item item; int zeny = RFIFOL(fd,8); sd = map_charid2sd( RFIFOL(fd,4) ); @@ -1566,12 +1566,9 @@ int intif_parse_Mail_getattach(int fd) clif_updatestatus(sd, SP_ZENY); } - item = (struct item*)aCalloc(sizeof(struct item), 1); - memcpy(item, RFIFOP(fd,12), sizeof(struct item)); - if (item->nameid > 0 && item->amount > 0) - pc_additem(sd, item, item->amount); - - aFree(item); + memcpy(&item, RFIFOP(fd,12), sizeof(struct item)); + if (item.nameid > 0 && item.amount > 0) + pc_additem(sd, &item, item.amount); return 0; } @@ -1609,7 +1606,21 @@ int intif_parse_Mail_delete(int fd) if (sd->state.finalsave) return 1; - clif_Mail_delete(sd, mail_id, failed); + if (!failed) + { + int i; + ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id); + if( i < MAIL_MAX_INBOX ) + { + memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message)); + sd->mail.inbox.amount--; + } + + if( sd->mail.inbox.full ) + intif_Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails + } + + clif_Mail_delete(sd->fd, mail_id, failed); return 0; } /*------------------------------------------ @@ -1632,19 +1643,31 @@ int intif_Mail_return(int char_id, int mail_id) int intif_parse_Mail_return(int fd) { struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2)); - int mail_id = RFIFOL(fd,6), new_mail = RFIFOL(fd,10); + int mail_id = RFIFOL(fd,6); + short fail = RFIFOB(fd,10); - if (sd == NULL) + if( sd == NULL ) { if (battle_config.error_log) ShowError("intif_parse_Mail_return: char not found %d\n",RFIFOL(fd,2)); return 1; } - if (sd->state.finalsave) + if( sd->state.finalsave ) return 1; - clif_Mail_return(sd, mail_id, new_mail); + if( !fail ) + { + int i; + ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id); + if (i < MAIL_MAX_INBOX) + { + memset(&sd->mail.inbox.msg[i], 0, sizeof(struct mail_message)); + sd->mail.inbox.amount--; + } + } + + clif_Mail_return(sd->fd, mail_id, fail); return 0; } /*------------------------------------------ @@ -1669,44 +1692,49 @@ int intif_Mail_send(int account_id, struct mail_message *msg) int intif_parse_Mail_send(int fd) { - struct map_session_data* sd = map_charid2sd(RFIFOL(fd,4)); - int mail_id = RFIFOL(fd,8); - int dest_id = RFIFOL(fd,12); - struct map_session_data* rd; + struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2)); + int mail_id = RFIFOL(fd,6); + bool fail = false; - if( mail_id == 0 ) - {// nick->charid lookup failed, no such char - // Return the items to the owner - mail_removeitem(sd, 0); - mail_removezeny(sd, 0); - clif_Mail_send(sd->fd, 1); // failed - return 0; - } + if( mail_id > 0 ) + { + if( sd == NULL ) + fail = true; - if( sd == NULL ) - {// original sender disconnected, item cannot be deleted! - if( battle_config.error_log ) - ShowError("intif_parse_Mail_send: char not found %d\n",RFIFOL(fd,2)); + if( !mail_checkattach(sd) ) + { + fail = true; - // the best thing we can do at this point is requesting removal of the mail with the duped item - intif_Mail_delete(dest_id, mail_id); - return 0; - } + mail_removeitem(sd, 0); + mail_removezeny(sd, 0); + } + + WFIFOHEAD(inter_fd,7); + WFIFOW(inter_fd,0) = 0x304e; + WFIFOL(inter_fd,2) = mail_id; + WFIFOB(inter_fd,6) = fail; + WFIFOSET(inter_fd,7); - // physically delete the item - mail_removeitem(sd, 1); - mail_removezeny(sd, 1); - clif_Mail_send(sd->fd, 0); // success + clif_Mail_send(sd->fd, fail); + } + else + clif_Mail_send(sd->fd, true); + + return 0; +} - // notify recipient about new mail - rd = map_charid2sd(dest_id); - if( rd != NULL ) +int intif_parse_Mail_new(int fd) +{ + struct map_session_data *sd = map_charid2sd(RFIFOL(fd,2)); + if( sd != NULL ) { - char title[MAIL_TITLE_LENGTH]; - memcpy(title, RFIFOP(fd,16), RFIFOW(fd,2) - 16); + char sender_name[NAME_LENGTH], title[MAIL_TITLE_LENGTH]; + int mail_id = RFIFOL(fd,6); + + safestrncpy(sender_name, RFIFOP(fd,10), NAME_LENGTH); + safestrncpy(title, RFIFOP(fd,34), MAIL_TITLE_LENGTH); - rd->mail.inbox.changed = 1; - clif_Mail_new(rd->fd, mail_id, sd->status.name, title); + clif_Mail_new(sd, mail_id, sender_name, title); } return 0; @@ -1787,6 +1815,7 @@ int intif_parse(int fd) // Mail System #ifndef TXT_ONLY case 0x3848: intif_parse_Mail_inboxreceived(fd); break; + case 0x3849: intif_parse_Mail_new(fd); break; case 0x384a: intif_parse_Mail_getattach(fd); break; case 0x384b: intif_parse_Mail_delete(fd); break; case 0x384c: intif_parse_Mail_return(fd); break; diff --git a/src/map/mail.c b/src/map/mail.c index 371e11f8e..59f7037e6 100644 --- a/src/map/mail.c +++ b/src/map/mail.c @@ -31,6 +31,7 @@ int mail_removeitem(struct map_session_data *sd, short flag) clif_additem(sd, sd->mail.index, sd->mail.amount, 0); } + sd->mail.nameid = 0; sd->mail.index = 0; sd->mail.amount = 0; return 1; @@ -49,10 +50,8 @@ int mail_removezeny(struct map_session_data *sd, short flag) return 1; } -char mail_setitem(struct map_session_data *sd, int idx, int amount) +unsigned char mail_setitem(struct map_session_data *sd, int idx, int amount) { - nullpo_retr(-1,sd); - if (idx == 0) { // Zeny Transfer if (amount < 0) @@ -69,15 +68,15 @@ char mail_setitem(struct map_session_data *sd, int idx, int amount) mail_removeitem(sd, 0); if( idx < 0 || idx > MAX_INVENTORY ) - return 2; + return 1; if( amount < 0 || amount > sd->status.inventory[idx].amount ) - return 2; - if( itemdb_isdropable(&sd->status.inventory[idx], pc_isGM(sd)) == 0 ) - return 2; + return 1; + if( !itemdb_isdropable(&sd->status.inventory[idx], pc_isGM(sd)) ) + return 1; sd->mail.index = idx; + sd->mail.nameid = sd->status.inventory[idx].nameid; sd->mail.amount = amount; - clif_delitem(sd, idx, amount); return 0; @@ -86,7 +85,7 @@ char mail_setitem(struct map_session_data *sd, int idx, int amount) return -1; } -int mail_getattach(struct map_session_data *sd, struct mail_message *msg) +bool mail_getattach(struct map_session_data *sd, struct mail_message *msg) { int n; @@ -94,13 +93,16 @@ int mail_getattach(struct map_session_data *sd, struct mail_message *msg) nullpo_retr(0,msg); if( sd->mail.zeny < 0 || sd->mail.zeny > sd->status.zeny ) - return 0; + return false; n = sd->mail.index; if( sd->mail.amount ) { + if( sd->status.inventory[n].nameid != sd->mail.nameid ) + return false; + if( sd->status.inventory[n].amount < sd->mail.amount ) - return 0; + return false; memcpy(&msg->item, &sd->status.inventory[n], sizeof(struct item)); msg->item.amount = sd->mail.amount; @@ -108,7 +110,29 @@ int mail_getattach(struct map_session_data *sd, struct mail_message *msg) msg->zeny = sd->mail.zeny; - return 1; + return true; +} + +bool mail_checkattach(struct map_session_data *sd) +{ + nullpo_retr(false,sd); + + if( sd->mail.zeny > 0 && sd->status.zeny < sd->status.zeny ) + return false; + + if( sd->mail.amount > 0 ) + { + if( sd->status.inventory[sd->mail.index].nameid != sd->mail.nameid ) + return false; + + if( sd->status.inventory[sd->mail.index].amount < sd->mail.amount ) + return false; + } + + mail_removeitem(sd,1); + mail_removezeny(sd,1); + + return true; } int mail_openmail(struct map_session_data *sd) diff --git a/src/map/mail.h b/src/map/mail.h index 1f05edfce..1228f5772 100644 --- a/src/map/mail.h +++ b/src/map/mail.h @@ -10,8 +10,9 @@ time_t mail_calctimes(void); int mail_removeitem(struct map_session_data *sd, short flag); int mail_removezeny(struct map_session_data *sd, short flag); -char mail_setitem(struct map_session_data *sd, int idx, int amount); -int mail_getattach(struct map_session_data *sd, struct mail_message *msg); +unsigned char mail_setitem(struct map_session_data *sd, int idx, int amount); +bool mail_getattach(struct map_session_data *sd, struct mail_message *msg); +bool mail_checkattach(struct map_session_data *sd); int mail_openmail(struct map_session_data *sd); #endif /* _MAIL_H_ */ diff --git a/src/map/map.h b/src/map/map.h index cb866bbb8..41856d51b 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -803,6 +803,7 @@ struct map_session_data { // Mail System [Zephyrus] struct { + short nameid; int index, amount, zeny; struct mail_data inbox; } mail; |