diff options
-rw-r--r-- | src/char/char.c | 2 | ||||
-rw-r--r-- | src/char/int_auction.c | 20 | ||||
-rw-r--r-- | src/char/int_mail.c | 86 | ||||
-rw-r--r-- | src/char/int_mail.h | 21 | ||||
-rw-r--r-- | src/char/inter.c | 6 | ||||
-rw-r--r-- | src/char/mapif.c | 26 | ||||
-rw-r--r-- | src/char/mapif.h | 14 |
7 files changed, 121 insertions, 54 deletions
diff --git a/src/char/char.c b/src/char/char.c index 02504c786..82a3fade9 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -20,6 +20,7 @@ #include "int_elemental.h" #include "int_guild.h" #include "int_homun.h" +#include "int_mail.h" #include "int_mercenary.h" #include "int_party.h" #include "int_storage.h" @@ -6009,6 +6010,7 @@ void char_load_defaults(void) inter_elemental_defaults(); inter_guild_defaults(); inter_homunculus_defaults(); + inter_mail_defaults(); } void char_defaults(void) diff --git a/src/char/int_auction.c b/src/char/int_auction.c index 4ae4b8bc9..d0b37054d 100644 --- a/src/char/int_auction.c +++ b/src/char/int_auction.c @@ -144,12 +144,12 @@ static int inter_auction_end_timer(int tid, int64 tick, int id, intptr_t data) { { if( auction->buyer_id ) { - inter_mail_sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "Thanks, you won the auction!.", 0, &auction->item); + inter_mail->sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "Thanks, you won the auction!.", 0, &auction->item); mapif->auction_message(auction->buyer_id, 6); // You have won the auction - inter_mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Payment for your auction!.", auction->price, NULL); + inter_mail->sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Payment for your auction!.", auction->price, NULL); } else - inter_mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "No buyers have been found for your auction.", 0, &auction->item); + inter_mail->sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "No buyers have been found for your auction.", 0, &auction->item); ShowInfo("Auction End: id %u.\n", auction->auction_id); @@ -352,7 +352,7 @@ void mapif_parse_auction_cancel(int fd) return; } - inter_mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction canceled.", 0, &auction->item); + inter_mail->sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction canceled.", 0, &auction->item); inter_auction->delete_(auction); mapif->auction_cancel(fd, char_id, 0); // The auction has been canceled @@ -391,9 +391,9 @@ void mapif_parse_auction_close(int fd) } // Send Money to Seller - inter_mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction closed.", auction->price, NULL); + inter_mail->sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Auction closed.", auction->price, NULL); // Send Item to Buyer - inter_mail_sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "Auction winner.", 0, &auction->item); + inter_mail->sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "Auction winner.", 0, &auction->item); mapif->auction_message(auction->buyer_id, 6); // You have won the auction inter_auction->delete_(auction); @@ -432,11 +432,11 @@ void mapif_parse_auction_bid(int fd) { // Send Money back to the previous Buyer if( auction->buyer_id != char_id ) { - inter_mail_sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "Someone has placed a higher bid.", auction->price, NULL); + inter_mail->sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "Someone has placed a higher bid.", auction->price, NULL); mapif->auction_message(auction->buyer_id, 7); // You have failed to win the auction } else - inter_mail_sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "You have placed a higher bid.", auction->price, NULL); + inter_mail->sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "You have placed a higher bid.", auction->price, NULL); } auction->buyer_id = char_id; @@ -447,9 +447,9 @@ void mapif_parse_auction_bid(int fd) { // Automatic won the auction mapif->auction_bid(fd, char_id, bid - auction->buynow, 1); // You have successfully bid in the auction - inter_mail_sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "You have won the auction.", 0, &auction->item); + inter_mail->sendmail(0, "Auction Manager", auction->buyer_id, auction->buyer_name, "Auction", "You have won the auction.", 0, &auction->item); mapif->auction_message(char_id, 6); // You have won the auction - inter_mail_sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Payment for your auction!.", auction->buynow, NULL); + inter_mail->sendmail(0, "Auction Manager", auction->seller_id, auction->seller_name, "Auction", "Payment for your auction!.", auction->buynow, NULL); inter_auction->delete_(auction); return; diff --git a/src/char/int_mail.c b/src/char/int_mail.c index f0cf4ce7c..4bbac9855 100644 --- a/src/char/int_mail.c +++ b/src/char/int_mail.c @@ -21,6 +21,8 @@ #include "../common/strlib.h" #include "../common/timer.h" +struct inter_mail_interface inter_mail_s; + static int inter_mail_fromsql(int char_id, struct mail_data* md) { int i, j; @@ -202,7 +204,7 @@ static bool inter_mail_loadmessage(int mail_id, struct mail_message* msg) return true; } -void mapif_Mail_sendinbox(int fd, int char_id, unsigned char flag, struct mail_data *md) +void mapif_mail_sendinbox(int fd, int char_id, unsigned char flag, struct mail_data *md) { //FIXME: dumping the whole structure like this is unsafe [ultramage] WFIFOHEAD(fd, sizeof(struct mail_data) + 9); @@ -217,20 +219,20 @@ void mapif_Mail_sendinbox(int fd, int char_id, unsigned char flag, struct mail_d /*========================================== * Client Inbox Request *------------------------------------------*/ -static void mapif_parse_Mail_requestinbox(int fd) +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); + inter_mail->fromsql(char_id, &md); + mapif->mail_sendinbox(fd, char_id, flag, &md); } /*========================================== * Mark mail as 'Read' *------------------------------------------*/ -static void mapif_parse_Mail_read(int fd) +void mapif_parse_mail_read(int fd) { int mail_id = RFIFOL(fd,2); if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `status` = '%d' WHERE `id` = '%d'", mail_db, MAIL_READ, mail_id) ) @@ -263,7 +265,7 @@ static bool inter_mail_DeleteAttach(int mail_id) return true; } -void mapif_Mail_sendattach(int fd, int char_id, struct mail_message *msg) +void mapif_mail_sendattach(int fd, int char_id, struct mail_message *msg) { WFIFOHEAD(fd, sizeof(struct item) + 12); WFIFOW(fd,0) = 0x384a; @@ -274,12 +276,12 @@ void mapif_Mail_sendattach(int fd, int char_id, struct mail_message *msg) WFIFOSET(fd,WFIFOW(fd,2)); } -static void mapif_Mail_getattach(int fd, int char_id, int mail_id) +void mapif_mail_getattach(int fd, int char_id, int mail_id) { struct mail_message msg; memset(&msg, 0, sizeof(msg)); - if( !inter_mail_loadmessage(mail_id, &msg) ) + if( !inter_mail->loadmessage(mail_id, &msg) ) return; if( msg.dest_id != char_id ) @@ -291,21 +293,21 @@ static void mapif_Mail_getattach(int fd, int char_id, int mail_id) if( (msg.item.nameid < 1 || msg.item.amount < 1) && msg.zeny < 1 ) return; // No Attachment - if( !inter_mail_DeleteAttach(mail_id) ) + if( !inter_mail->DeleteAttach(mail_id) ) return; - mapif_Mail_sendattach(fd, char_id, &msg); + mapif->mail_sendattach(fd, char_id, &msg); } -static void mapif_parse_Mail_getattach(int fd) +void mapif_parse_mail_getattach(int fd) { - mapif_Mail_getattach(fd, RFIFOL(fd,2), RFIFOL(fd,6)); + mapif->mail_getattach(fd, RFIFOL(fd,2), RFIFOL(fd,6)); } /*========================================== * Delete Mail *------------------------------------------*/ -void mapif_Mail_delete(int fd, int char_id, int mail_id, bool failed) +void mapif_mail_delete(int fd, int char_id, int mail_id, bool failed) { WFIFOHEAD(fd,11); WFIFOW(fd,0) = 0x384b; @@ -315,7 +317,7 @@ void mapif_Mail_delete(int fd, int char_id, int mail_id, bool failed) WFIFOSET(fd,11); } -static void mapif_parse_Mail_delete(int fd) +void mapif_parse_mail_delete(int fd) { int char_id = RFIFOL(fd,2); int mail_id = RFIFOL(fd,6); @@ -325,13 +327,13 @@ static void mapif_parse_Mail_delete(int fd) Sql_ShowDebug(sql_handle); failed = true; } - mapif_Mail_delete(fd, char_id, mail_id, failed); + mapif->mail_delete(fd, char_id, mail_id, failed); } /*========================================== * Report New Mail to Map Server *------------------------------------------*/ -void mapif_Mail_new(struct mail_message *msg) +void mapif_mail_new(struct mail_message *msg) { unsigned char buf[74]; @@ -349,7 +351,7 @@ void mapif_Mail_new(struct mail_message *msg) /*========================================== * Return Mail *------------------------------------------*/ -static void mapif_Mail_return(int fd, int char_id, int mail_id, int new_mail) +void mapif_mail_return(int fd, int char_id, int mail_id, int new_mail) { WFIFOHEAD(fd,11); WFIFOW(fd,0) = 0x384c; @@ -359,14 +361,14 @@ static void mapif_Mail_return(int fd, int char_id, int mail_id, int new_mail) WFIFOSET(fd,11); } -static void mapif_parse_Mail_return(int fd) +void mapif_parse_mail_return(int fd) { int char_id = RFIFOL(fd,2); int mail_id = RFIFOL(fd,6); struct mail_message msg; int new_mail = 0; - if( inter_mail_loadmessage(mail_id, &msg) ) + if( inter_mail->loadmessage(mail_id, &msg) ) { if( msg.dest_id != char_id) return; @@ -389,18 +391,18 @@ static void mapif_parse_Mail_return(int fd) msg.status = MAIL_NEW; msg.timestamp = time(NULL); - new_mail = inter_mail_savemessage(&msg); - mapif_Mail_new(&msg); + new_mail = inter_mail->savemessage(&msg); + mapif->mail_new(&msg); } } - mapif_Mail_return(fd, char_id, mail_id, new_mail); + mapif->mail_return(fd, char_id, mail_id, new_mail); } /*========================================== * Send Mail *------------------------------------------*/ -static void mapif_Mail_send(int fd, struct mail_message* msg) +void mapif_mail_send(int fd, struct mail_message* msg) { int len = sizeof(struct mail_message) + 4; @@ -411,7 +413,7 @@ static void mapif_Mail_send(int fd, struct mail_message* msg) WFIFOSET(fd,len); } -static void mapif_parse_Mail_send(int fd) +void mapif_parse_mail_send(int fd) { struct mail_message msg; char esc_name[NAME_LENGTH*2+1]; @@ -442,10 +444,10 @@ static void mapif_parse_Mail_send(int fd) msg.status = MAIL_NEW; if( msg.dest_id > 0 ) - msg.id = inter_mail_savemessage(&msg); + msg.id = inter_mail->savemessage(&msg); - mapif_Mail_send(fd, &msg); // notify sender - mapif_Mail_new(&msg); // notify recipient + mapif->mail_send(fd, &msg); // notify sender + mapif->mail_new(&msg); // notify recipient } void inter_mail_sendmail(int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item) @@ -465,8 +467,8 @@ void inter_mail_sendmail(int send_id, const char* send_name, int dest_id, const msg.timestamp = time(NULL); - inter_mail_savemessage(&msg); - mapif_Mail_new(&msg); + inter_mail->savemessage(&msg); + mapif->mail_new(&msg); } /*========================================== @@ -476,12 +478,12 @@ int inter_mail_parse_frommap(int fd) { switch(RFIFOW(fd,0)) { - case 0x3048: mapif_parse_Mail_requestinbox(fd); break; - case 0x3049: mapif_parse_Mail_read(fd); break; - case 0x304a: mapif_parse_Mail_getattach(fd); break; - case 0x304b: mapif_parse_Mail_delete(fd); break; - case 0x304c: mapif_parse_Mail_return(fd); break; - case 0x304d: mapif_parse_Mail_send(fd); break; + case 0x3048: mapif->parse_mail_requestinbox(fd); break; + case 0x3049: mapif->parse_mail_read(fd); break; + case 0x304a: mapif->parse_mail_getattach(fd); break; + case 0x304b: mapif->parse_mail_delete(fd); break; + case 0x304c: mapif->parse_mail_return(fd); break; + case 0x304d: mapif->parse_mail_send(fd); break; default: return 0; } @@ -497,3 +499,17 @@ void inter_mail_sql_final(void) { return; } + +void inter_mail_defaults(void) +{ + inter_mail = &inter_mail_s; + + inter_mail->savemessage = inter_mail_savemessage; + inter_mail->DeleteAttach = inter_mail_DeleteAttach; + inter_mail->sendmail = inter_mail_sendmail; + inter_mail->parse_frommap = inter_mail_parse_frommap; + inter_mail->sql_init = inter_mail_sql_init; + inter_mail->sql_final = inter_mail_sql_final; + inter_mail->fromsql = inter_mail_fromsql; + inter_mail->loadmessage = inter_mail_loadmessage; +} diff --git a/src/char/int_mail.h b/src/char/int_mail.h index 490422c50..0a8449748 100644 --- a/src/char/int_mail.h +++ b/src/char/int_mail.h @@ -4,16 +4,25 @@ #ifndef CHAR_INT_MAIL_H #define CHAR_INT_MAIL_H +#include "../common/cbasetypes.h" + struct item; +struct mail_data; struct mail_message; -int inter_mail_parse_frommap(int fd); -void inter_mail_sendmail(int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item); +void inter_mail_defaults(void); -int inter_mail_sql_init(void); -void inter_mail_sql_final(void); +struct inter_mail_interface { + int (*sql_init) (void); + void (*sql_final) (void); + int (*parse_frommap) (int fd); + int (*fromsql) (int char_id, struct mail_data* md); + int (*savemessage) (struct mail_message* msg); + bool (*loadmessage) (int mail_id, struct mail_message* msg); + bool (*DeleteAttach) (int mail_id); + void (*sendmail) (int send_id, const char* send_name, int dest_id, const char* dest_name, const char* title, const char* body, int zeny, struct item *item); +}; -int inter_mail_savemessage(struct mail_message* msg); -void mapif_Mail_new(struct mail_message *msg); +struct inter_mail_interface *inter_mail; #endif /* CHAR_INT_MAIL_H */ diff --git a/src/char/inter.c b/src/char/inter.c index 8ee4da6fe..3f770efa4 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -1033,7 +1033,7 @@ int inter_init_sql(const char *file) inter_homunculus->sql_init(); inter_mercenary_sql_init(); inter_elemental->sql_init(); - inter_mail_sql_init(); + inter_mail->sql_init(); inter_auction->sql_init(); geoip_init(); @@ -1053,7 +1053,7 @@ void inter_final(void) inter_homunculus->sql_final(); inter_mercenary_sql_final(); inter_elemental->sql_final(); - inter_mail_sql_final(); + inter_mail->sql_final(); inter_auction->sql_final(); geoip_final(true); @@ -1460,7 +1460,7 @@ int inter_parse_frommap(int fd) || inter_homunculus->parse_frommap(fd) || inter_mercenary_parse_frommap(fd) || inter_elemental->parse_frommap(fd) - || inter_mail_parse_frommap(fd) + || inter_mail->parse_frommap(fd) || inter_auction->parse_frommap(fd) || inter_quest_parse_frommap(fd) ) diff --git a/src/char/mapif.c b/src/char/mapif.c index 6017b3d34..58b47a6e4 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -100,6 +100,19 @@ void mapif_parse_homunculus_delete(int fd, int homun_id); void mapif_parse_homunculus_load(int fd, int account_id, int homun_id); void mapif_parse_homunculus_save(int fd, int len, int account_id, struct s_homunculus* phd); void mapif_parse_homunculus_rename(int fd, int account_id, int char_id, char* 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_mail_getattach(int fd, int char_id, int mail_id); +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_defaults(void) { mapif = &mapif_s; @@ -185,4 +198,17 @@ void mapif_defaults(void) { mapif->parse_homunculus_load = mapif_parse_homunculus_load; mapif->parse_homunculus_save = mapif_parse_homunculus_save; mapif->parse_homunculus_rename = mapif_parse_homunculus_rename; + mapif->mail_sendinbox = mapif_mail_sendinbox; + mapif->parse_mail_requestinbox = mapif_parse_mail_requestinbox; + mapif->parse_mail_read = mapif_parse_mail_read; + mapif->mail_sendattach = mapif_mail_sendattach; + mapif->mail_getattach = mapif_mail_getattach; + mapif->parse_mail_getattach = mapif_parse_mail_getattach; + mapif->mail_delete = mapif_mail_delete; + mapif->parse_mail_delete = mapif_parse_mail_delete; + mapif->mail_new = mapif_mail_new; + mapif->mail_return = mapif_mail_return; + mapif->parse_mail_return = mapif_parse_mail_return; + mapif->mail_send = mapif_mail_send; + mapif->parse_mail_send = mapif_parse_mail_send; } diff --git a/src/char/mapif.h b/src/char/mapif.h index 4a61db3fd..ec177fcd1 100644 --- a/src/char/mapif.h +++ b/src/char/mapif.h @@ -9,6 +9,7 @@ struct s_elemental; struct s_homunculus; +struct mail_message; /* mapif interface */ struct mapif_interface { @@ -93,6 +94,19 @@ struct mapif_interface { void (*parse_homunculus_load) (int fd, int account_id, int homun_id); void (*parse_homunculus_save) (int fd, int len, int account_id, struct s_homunculus* phd); void (*parse_homunculus_rename) (int fd, int account_id, int char_id, char* name); + void (*mail_sendinbox) (int fd, int char_id, unsigned char flag, struct mail_data *md); + void (*parse_mail_requestinbox) (int fd); + void (*parse_mail_read) (int fd); + void (*mail_sendattach) (int fd, int char_id, struct mail_message *msg); + void (*mail_getattach) (int fd, int char_id, int mail_id); + void (*parse_mail_getattach) (int fd); + void (*mail_delete) (int fd, int char_id, int mail_id, bool failed); + void (*parse_mail_delete) (int fd); + void (*mail_new) (struct mail_message *msg); + void (*mail_return) (int fd, int char_id, int mail_id, int new_mail); + void (*parse_mail_return) (int fd); + void (*mail_send) (int fd, struct mail_message* msg); + void (*parse_mail_send) (int fd); } mapif_s; struct mapif_interface *mapif; |