From 544da439e81ff78ec102b754e16b6cc0a28a6d0a Mon Sep 17 00:00:00 2001 From: KirieZ Date: Sun, 30 Jul 2017 13:45:41 -0300 Subject: Implementation of RoDEX --- src/map/intif.c | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 231 insertions(+), 1 deletion(-) (limited to 'src/map/intif.c') diff --git a/src/map/intif.c b/src/map/intif.c index 61d2e3633..de862b4dd 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -38,6 +38,7 @@ #include "map/pc.h" #include "map/pet.h" #include "map/quest.h" +#include "map/rodex.h" #include "map/storage.h" #include "common/memmgr.h" #include "common/nullpo.h" @@ -2399,6 +2400,218 @@ void intif_parse_Itembound_ack(int fd) { gstor->lock = 0; //Unlock now that operation is completed #endif } + +/*========================================== +* RoDEX System +*==========================================*/ + +/*------------------------------------------ + * Mail List + *------------------------------------------*/ + +// Rodex Inbox Request +// char_id: char_id +// account_id: account_id (used by account mail) +// flag: 0 - Open/Refresh ; 1 = Next Page +int intif_rodex_requestinbox(int char_id, int account_id, int8 flag, int8 opentype, int64 mail_id) +{ + if (intif->CheckForCharServer()) + return 0; + + WFIFOHEAD(inter_fd, 20); + WFIFOW(inter_fd, 0) = 0x3095; + WFIFOL(inter_fd, 2) = char_id; + WFIFOL(inter_fd, 6) = account_id; + WFIFOL(inter_fd, 10) = flag; + WFIFOB(inter_fd, 11) = opentype; + WFIFOQ(inter_fd, 12) = mail_id; + WFIFOSET(inter_fd, 20); + + return 0; +} + +void intif_parse_RequestRodexOpenInbox(int fd) +{ + struct map_session_data *sd; + int8 opentype = RFIFOB(fd, 8); + int8 flag = RFIFOB(fd, 9); + int8 is_end = RFIFOB(fd, 10); + int count = RFIFOL(fd, 11); + int i, j; + + sd = map->charid2sd(RFIFOL(fd, 4)); + + 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)); + return; + } + + if (flag == 0) + VECTOR_CLEAR(sd->rodex.messages); + + for (i = 0, j = 15; 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)); + VECTOR_PUSH(sd->rodex.messages, msg); + } + + if (is_end == true) { + if (flag == 0) + clif->rodex_send_maillist(sd->fd, sd, opentype, VECTOR_LENGTH(sd->rodex.messages) - 1); + else + clif->rodex_send_refresh(sd->fd, sd, opentype, count); + } +} + +/*------------------------------------------ + * Notifications + *------------------------------------------*/ +int intif_rodex_hasnew(struct map_session_data *sd) +{ + nullpo_retr(0, sd); + + if (intif->CheckForCharServer()) + return 0; + + WFIFOHEAD(inter_fd, 10); + WFIFOW(inter_fd, 0) = 0x3096; + WFIFOL(inter_fd, 2) = sd->status.char_id; + WFIFOL(inter_fd, 6) = sd->status.account_id; + WFIFOSET(inter_fd, 10); + + return 0; +} + +void intif_parse_RodexNotifications(int fd) +{ + struct map_session_data *sd; + bool has_messages; + + sd = map->charid2sd(RFIFOL(fd, 2)); + has_messages = RFIFOB(fd, 6); + + if (sd == NULL) // user is not online anymore + return; + + clif->rodex_icon(sd->fd, has_messages); +} + +/*------------------------------------------ + * Update Mail + *------------------------------------------*/ + +/// Updates a mail +/// flag: +/// 0 - user Read +/// 1 - user got Zeny +/// 2 - user got Items +/// 3 - delete +int intif_rodex_updatemail(int64 mail_id, int8 flag) +{ + if (intif->CheckForCharServer()) + return 0; + + WFIFOHEAD(inter_fd, 11); + WFIFOW(inter_fd, 0) = 0x3097; + WFIFOQ(inter_fd, 2) = mail_id; + WFIFOB(inter_fd, 10) = flag; + WFIFOSET(inter_fd, 11); + + return 0; +} + +/*------------------------------------------ + * Send Mail + *------------------------------------------*/ +int intif_rodex_sendmail(struct rodex_message *msg) +{ + if (intif->CheckForCharServer()) + return 0; + + nullpo_retr(0, msg); + + WFIFOHEAD(inter_fd, 4 + sizeof(struct rodex_message)); + WFIFOW(inter_fd, 0) = 0x3098; + WFIFOW(inter_fd, 2) = 4 + sizeof(struct rodex_message); + memcpy(WFIFOP(inter_fd, 4), msg, sizeof(struct rodex_message)); + WFIFOSET(inter_fd, 4 + sizeof(struct rodex_message)); + + return 0; +} + +void intif_parse_RodexSendMail(int fd) +{ + struct map_session_data *ssd = NULL, *rsd = NULL; + int sender_id = RFIFOL(fd, 2); + int receiver_id = RFIFOL(fd, 6); + int receiver_accountid = RFIFOL(fd, 10); + + if (sender_id > 0) + ssd = map->charid2sd(sender_id); + + if (receiver_id > 0) + rsd = map->charid2sd(receiver_id); + else if (receiver_accountid > 0) + rsd = map->id2sd(receiver_accountid); + + rodex->send_mail_result(ssd, rsd, RFIFOL(fd, 14)); +} + +/*------------------------------------------ + * Check Player + *------------------------------------------*/ +int intif_rodex_checkname(struct map_session_data *sd, const char *name) +{ + if (intif->CheckForCharServer()) + return 0; + + nullpo_retr(0, sd); + nullpo_retr(0, name); + + WFIFOHEAD(inter_fd, 6 + NAME_LENGTH); + WFIFOW(inter_fd, 0) = 0x3099; + WFIFOL(inter_fd, 2) = sd->status.char_id; + safestrncpy(WFIFOP(inter_fd, 6), name, NAME_LENGTH); + WFIFOSET(inter_fd, 6 + NAME_LENGTH); + + return 0; +} + +void intif_parse_RodexCheckName(int fd) +{ + struct map_session_data *sd = NULL; + int reqchar_id = RFIFOL(fd, 2); + int target_char_id = RFIFOL(fd, 6); + short target_class = RFIFOW(fd, 10); + int target_level = RFIFOL(fd, 12); + char name[NAME_LENGTH]; + + safestrncpy(name, RFIFOP(inter_fd, 16), NAME_LENGTH); + + if (reqchar_id <= 0) + return; + + sd = map->charid2sd(reqchar_id); + + if (sd == NULL) // User is not online anymore + return; + + if (target_char_id == 0) { + clif->rodex_checkname_result(sd, 0, 0, 0, name); + return; + } + + sd->rodex.tmp.receiver_id = target_char_id; + strncpy(sd->rodex.tmp.receiver_name, name, NAME_LENGTH); + + clif->rodex_checkname_result(sd, target_char_id, target_class, target_level, name); +} + //----------------------------------------------------------------- // Communication from the inter server // Return a 0 (false) if there were any errors. @@ -2509,6 +2722,12 @@ int intif_parse(int fd) case 0x3891: intif->pRecvHomunculusData(fd); break; case 0x3892: intif->pSaveHomunculusOk(fd); break; case 0x3893: intif->pDeleteHomunculusOk(fd); break; + + // RoDEX + case 0x3895: intif->pRequestRodexOpenInbox(fd); break; + case 0x3896: intif->pRodexHasNew(fd); break; + case 0x3897: intif->pRodexSendMail(fd); break; + case 0x3898: intif->pRodexCheckName(fd); break; default: ShowError("intif_parse : unknown packet %d %x\n",fd,RFIFOW(fd,0)); return 0; @@ -2534,7 +2753,7 @@ void intif_defaults(void) { -1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish] -1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 3, 3, 0, //0x3870 Mercenaries [Zephyrus] / Elemental [pakpil] 12,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3880 - -1,-1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator] + -1,-1, 7, 3, 0,-1, 7, 15,16 + NAME_LENGTH, 0, 0, 0, 0, 0, 0, 0, //0x3890 Homunculus [albator] / RoDEX [KirieZ] }; intif = &intif_s; @@ -2616,6 +2835,12 @@ void intif_defaults(void) { intif->elemental_request = intif_elemental_request; intif->elemental_delete = intif_elemental_delete; intif->elemental_save = intif_elemental_save; + // RoDEX + intif->rodex_requestinbox = intif_rodex_requestinbox; + intif->rodex_checkhasnew = intif_rodex_hasnew; + intif->rodex_updatemail = intif_rodex_updatemail; + intif->rodex_sendmail = intif_rodex_sendmail; + intif->rodex_checkname = intif_rodex_checkname; /* @accinfo */ intif->request_accinfo = intif_request_accinfo; /* */ @@ -2687,4 +2912,9 @@ void intif_defaults(void) { intif->pRecvHomunculusData = intif_parse_RecvHomunculusData; intif->pSaveHomunculusOk = intif_parse_SaveHomunculusOk; intif->pDeleteHomunculusOk = intif_parse_DeleteHomunculusOk; + /* RoDEX */ + intif->pRequestRodexOpenInbox = intif_parse_RequestRodexOpenInbox; + intif->pRodexHasNew = intif_parse_RodexNotifications; + intif->pRodexSendMail = intif_parse_RodexSendMail; + intif->pRodexCheckName = intif_parse_RodexCheckName; } -- cgit v1.2.3-60-g2f50