diff options
Diffstat (limited to 'src/map/intif.c')
-rw-r--r-- | src/map/intif.c | 955 |
1 files changed, 789 insertions, 166 deletions
diff --git a/src/map/intif.c b/src/map/intif.c index 10a9ea8a9..ed4c0e2d2 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -2,7 +2,7 @@ * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * - * Copyright (C) 2012-2016 Hercules Dev Team + * Copyright (C) 2012-2018 Hercules Dev Team * Copyright (C) Athena Dev Teams * * Hercules is free software: you can redistribute it and/or modify @@ -26,6 +26,7 @@ #include "map/atcommand.h" #include "map/battle.h" #include "map/chrif.h" +#include "map/clan.h" #include "map/clif.h" #include "map/elemental.h" #include "map/guild.h" @@ -38,7 +39,10 @@ #include "map/pc.h" #include "map/pet.h" #include "map/quest.h" +#include "map/rodex.h" #include "map/storage.h" +#include "map/achievement.h" + #include "common/memmgr.h" #include "common/nullpo.h" #include "common/showmsg.h" @@ -53,7 +57,7 @@ #include <string.h> #include <sys/types.h> -struct intif_interface intif_s; +static struct intif_interface intif_s; struct intif_interface *intif; #define inter_fd (chrif->fd) // alias @@ -61,37 +65,37 @@ struct intif_interface *intif; //----------------------------------------------------------------- // Send to inter server -int CheckForCharServer(void) +static int CheckForCharServer(void) { return ((chrif->fd <= 0) || sockt->session[chrif->fd] == NULL || sockt->session[chrif->fd]->wdata == NULL); } // pet -int intif_create_pet(int account_id,int char_id,short pet_class,short pet_lv,short pet_egg_id, - short pet_equip,short intimate,short hungry,char rename_flag,char incubate,char *pet_name) +static int intif_create_pet(int account_id, int char_id, short pet_class, short pet_lv, int pet_egg_id, + int pet_equip, short intimate, short hungry, char rename_flag, char incubate, char *pet_name) { if (intif->CheckForCharServer()) return 0; nullpo_ret(pet_name); - WFIFOHEAD(inter_fd, 24 + NAME_LENGTH); - WFIFOW(inter_fd,0) = 0x3080; - WFIFOL(inter_fd,2) = account_id; - WFIFOL(inter_fd,6) = char_id; - WFIFOW(inter_fd,10) = pet_class; - WFIFOW(inter_fd,12) = pet_lv; - WFIFOW(inter_fd,14) = pet_egg_id; - WFIFOW(inter_fd,16) = pet_equip; - WFIFOW(inter_fd,18) = intimate; - WFIFOW(inter_fd,20) = hungry; - WFIFOB(inter_fd,22) = rename_flag; - WFIFOB(inter_fd,23) = incubate; - memcpy(WFIFOP(inter_fd,24),pet_name,NAME_LENGTH); - WFIFOSET(inter_fd,24+NAME_LENGTH); + WFIFOHEAD(inter_fd, 28 + NAME_LENGTH); + WFIFOW(inter_fd, 0) = 0x3080; + WFIFOL(inter_fd, 2) = account_id; + WFIFOL(inter_fd, 6) = char_id; + WFIFOW(inter_fd, 10) = pet_class; + WFIFOW(inter_fd, 12) = pet_lv; + WFIFOL(inter_fd, 14) = pet_egg_id; + WFIFOL(inter_fd, 18) = pet_equip; + WFIFOW(inter_fd, 22) = intimate; + WFIFOW(inter_fd, 24) = hungry; + WFIFOB(inter_fd, 26) = rename_flag; + WFIFOB(inter_fd, 27) = incubate; + memcpy(WFIFOP(inter_fd, 28), pet_name, NAME_LENGTH); + WFIFOSET(inter_fd, 28 + NAME_LENGTH); return 0; } -int intif_request_petdata(int account_id,int char_id,int pet_id) +static int intif_request_petdata(int account_id, int char_id, int pet_id) { if (intif->CheckForCharServer()) return 0; @@ -105,7 +109,7 @@ int intif_request_petdata(int account_id,int char_id,int pet_id) return 0; } -int intif_save_petdata(int account_id,struct s_pet *p) +static int intif_save_petdata(int account_id, struct s_pet *p) { if (intif->CheckForCharServer()) return 0; @@ -120,7 +124,7 @@ int intif_save_petdata(int account_id,struct s_pet *p) return 0; } -int intif_delete_petdata(int pet_id) +static int intif_delete_petdata(int pet_id) { if (intif->CheckForCharServer()) return 0; @@ -132,7 +136,7 @@ int intif_delete_petdata(int pet_id) return 1; } -int intif_rename(struct map_session_data *sd, int type, const char *name) +static int intif_rename(struct map_session_data *sd, int type, const char *name) { if (intif->CheckForCharServer()) return 1; @@ -150,7 +154,7 @@ int intif_rename(struct map_session_data *sd, int type, const char *name) } // GM Send a message -int intif_broadcast(const char *mes, int len, int type) +static int intif_broadcast(const char *mes, int len, int type) { int lp = (type&BC_COLOR_MASK) ? 4 : 0; @@ -182,7 +186,7 @@ int intif_broadcast(const char *mes, int len, int type) return 0; } -int intif_broadcast2(const char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY) +static int intif_broadcast2(const char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY) { nullpo_ret(mes); Assert_ret(len < 32000); @@ -211,7 +215,7 @@ int intif_broadcast2(const char *mes, int len, unsigned int fontColor, short fon /// send a message using the main chat system /// <sd> the source of message /// <message> the message that was sent -int intif_main_message(struct map_session_data* sd, const char* message) +static int intif_main_message(struct map_session_data *sd, const char *message) { char output[256]; @@ -231,7 +235,7 @@ int intif_main_message(struct map_session_data* sd, const char* message) } // The transmission of Wisp/Page to inter-server (player not found on this server) -int intif_wis_message(struct map_session_data *sd, const char *nick, const char *mes, int mes_len) +static int intif_wis_message(struct map_session_data *sd, const char *nick, const char *mes, int mes_len) { if (intif->CheckForCharServer()) return 0; @@ -260,7 +264,7 @@ int intif_wis_message(struct map_session_data *sd, const char *nick, const char } // The reply of Wisp/page -int intif_wis_replay(int id, int flag) +static int intif_wis_replay(int id, int flag) { if (intif->CheckForCharServer()) return 0; @@ -277,7 +281,7 @@ int intif_wis_replay(int id, int flag) } // The transmission of GM only Wisp/Page from server to inter-server -int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes) +static int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes) { int mes_len; if (intif->CheckForCharServer()) @@ -302,7 +306,7 @@ int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes) } //Request for saving registry values. -int intif_saveregistry(struct map_session_data *sd) +static int intif_saveregistry(struct map_session_data *sd) { struct DBIterator *iter; union DBKey key; @@ -419,7 +423,7 @@ int intif_saveregistry(struct map_session_data *sd) } //Request the registries for this player. -int intif_request_registry(struct map_session_data *sd, int flag) +static int intif_request_registry(struct map_session_data *sd, int flag) { nullpo_ret(sd); @@ -439,7 +443,137 @@ int intif_request_registry(struct map_session_data *sd, int flag) return 0; } -int intif_request_guild_storage(int account_id,int guild_id) +//================================================================= +// Account Storage +//----------------------------------------------------------------- + +/** + * Request the inter-server for a character's storage data. + * @packet 0x3010 [out] <account_id>.L + * @param sd [in] pointer to session data. + */ +static void intif_request_account_storage(const struct map_session_data *sd) +{ + nullpo_retv(sd); + + /* Check for character server availability */ + if (intif->CheckForCharServer()) + return; + + WFIFOHEAD(inter_fd, 6); + WFIFOW(inter_fd, 0) = 0x3010; + WFIFOL(inter_fd, 2) = sd->status.account_id; + WFIFOSET(inter_fd, 6); +} + +/** + * Parse the reception of account storage from the inter-server. + * @packet 0x3805 [in] <packet_len>.W <account_id>.L <struct item[]>.P + * @param fd [in] file/socket descriptor. + */ +static void intif_parse_account_storage(int fd) +{ + int account_id = 0, payload_size = 0, storage_count = 0; + int i = 0; + struct map_session_data *sd = NULL; + + Assert_retv(fd > 0); + + payload_size = RFIFOW(fd, 2) - 8; + + if ((account_id = RFIFOL(fd, 4)) == 0 || (sd = map->id2sd(account_id)) == NULL) { + ShowError("intif_parse_account_storage: Session pointer was null for account id %d!\n", account_id); + return; + } + + if (sd->storage.received == true) { + ShowError("intif_parse_account_storage: Multiple calls from the inter-server received.\n"); + return; + } + + storage_count = (payload_size/sizeof(struct item)); + + VECTOR_ENSURE(sd->storage.item, storage_count, 1); + + sd->storage.aggregate = storage_count; // Total items in storage. + + for (i = 0; i < storage_count; i++) { + const struct item *it = RFIFOP(fd, 8 + i * sizeof(struct item)); + VECTOR_PUSH(sd->storage.item, *it); + } + + sd->storage.received = true; // Mark the storage state as received. + sd->storage.save = false; // Initialize the save flag as false. + + pc->checkitem(sd); // re-check remaining items. +} + +/** + * Send account storage information for saving. + * @packet 0x3011 [out] <packet_len>.W <account_id>.L <struct item[]>.P + * @param sd [in] pointer to session data. + */ +static void intif_send_account_storage(struct map_session_data *sd) +{ + int len = 0, i = 0, c = 0; + + nullpo_retv(sd); + + // Assert that at this point in the code, both flags are true. + Assert_retv(sd->storage.save == true); + Assert_retv(sd->storage.received == true); + + if (intif->CheckForCharServer()) + return; + + len = 8 + sd->storage.aggregate * sizeof(struct item); + + WFIFOHEAD(inter_fd, len); + + WFIFOW(inter_fd, 0) = 0x3011; + WFIFOW(inter_fd, 2) = (uint16) len; + WFIFOL(inter_fd, 4) = sd->status.account_id; + for (i = 0, c = 0; i < VECTOR_LENGTH(sd->storage.item); i++) { + if (VECTOR_INDEX(sd->storage.item, i).nameid == 0) + continue; + memcpy(WFIFOP(inter_fd, 8 + c * sizeof(struct item)), &VECTOR_INDEX(sd->storage.item, i), sizeof(struct item)); + c++; + } + + WFIFOSET(inter_fd, len); + + sd->storage.save = false; // Save request has been sent +} + +/** + * Parse acknowledgement packet for the saving of an account's storage. + * @packet 0x3808 [in] <account_id>.L <saved_flag>.B + * @param fd [in] file/socket descriptor. + */ +static void intif_parse_account_storage_save_ack(int fd) +{ + int account_id = RFIFOL(fd, 2); + uint8 saved = RFIFOB(fd, 6); + struct map_session_data *sd = NULL; + + Assert_retv(account_id > 0); + Assert_retv(fd > 0); + + if ((sd = map->id2sd(account_id)) == NULL) + return; // character is most probably offline. + + if (saved == 0) { + ShowError("intif_parse_account_storage_save_ack: Storage has not been saved! (AID: %d)\n", account_id); + sd->storage.save = true; // Flag it as unsaved, to re-attempt later + return; + } +} + +//================================================================= +// Guild Storage +//----------------------------------------------------------------- + +static int intif_request_guild_storage(int account_id, int guild_id) { if (intif->CheckForCharServer()) return 0; @@ -450,7 +584,7 @@ int intif_request_guild_storage(int account_id,int guild_id) WFIFOSET(inter_fd,10); return 0; } -int intif_send_guild_storage(int account_id,struct guild_storage *gstor) +static int intif_send_guild_storage(int account_id, struct guild_storage *gstor) { if (intif->CheckForCharServer()) return 0; @@ -466,7 +600,7 @@ int intif_send_guild_storage(int account_id,struct guild_storage *gstor) } // Party creation request -int intif_create_party(struct party_member *member, const char *name, int item, int item2) +static int intif_create_party(struct party_member *member, const char *name, int item, int item2) { if (intif->CheckForCharServer()) return 0; @@ -485,7 +619,7 @@ int intif_create_party(struct party_member *member, const char *name, int item, } // Party information request -int intif_request_partyinfo(int party_id, int char_id) +static int intif_request_partyinfo(int party_id, int char_id) { if (intif->CheckForCharServer()) return 0; @@ -498,7 +632,7 @@ int intif_request_partyinfo(int party_id, int char_id) } // Request to add a member to party -int intif_party_addmember(int party_id,struct party_member *member) +static int intif_party_addmember(int party_id, struct party_member *member) { if (intif->CheckForCharServer()) return 0; @@ -513,7 +647,7 @@ int intif_party_addmember(int party_id,struct party_member *member) } // Request to change party configuration (exp,item share) -int intif_party_changeoption(int party_id,int account_id,int exp,int item) +static int intif_party_changeoption(int party_id, int account_id, int exp, int item) { if (intif->CheckForCharServer()) return 0; @@ -528,7 +662,7 @@ int intif_party_changeoption(int party_id,int account_id,int exp,int item) } // Request to leave party -int intif_party_leave(int party_id,int account_id, int char_id) +static int intif_party_leave(int party_id, int account_id, int char_id) { if (intif->CheckForCharServer()) return 0; @@ -542,7 +676,8 @@ int intif_party_leave(int party_id,int account_id, int char_id) } // Request keeping party for new map ?? -int intif_party_changemap(struct map_session_data *sd,int online) { +static int intif_party_changemap(struct map_session_data *sd, int online) +{ int16 m, map_index; if (intif->CheckForCharServer()) @@ -568,7 +703,7 @@ int intif_party_changemap(struct map_session_data *sd,int online) { } // Request breaking party -int intif_break_party(int party_id) +static int intif_break_party(int party_id) { if (intif->CheckForCharServer()) return 0; @@ -580,7 +715,7 @@ int intif_break_party(int party_id) } // Sending party chat -int intif_party_message(int party_id,int account_id,const char *mes,int len) +static int intif_party_message(int party_id, int account_id, const char *mes, int len) { if (intif->CheckForCharServer()) return 0; @@ -601,7 +736,7 @@ int intif_party_message(int party_id,int account_id,const char *mes,int len) } // Request a new leader for party -int intif_party_leaderchange(int party_id,int account_id,int char_id) +static int intif_party_leaderchange(int party_id, int account_id, int char_id) { if (intif->CheckForCharServer()) return 0; @@ -614,8 +749,83 @@ int intif_party_leaderchange(int party_id,int account_id,int char_id) return 0; } +//========================= +// Clan System +//------------------------- + +/** + * Request clan member count + * + * @param clan_id Id of the clan to have members counted + * @param kick_interval Interval of the inactivity kick + */ +static int intif_clan_membercount(int clan_id, int kick_interval) +{ + if (intif->CheckForCharServer() || clan_id == 0 || kick_interval <= 0) + return 0; + + WFIFOHEAD(inter_fd, 10); + WFIFOW(inter_fd, 0) = 0x3044; + WFIFOL(inter_fd, 2) = clan_id; + WFIFOL(inter_fd, 6) = kick_interval; + WFIFOSET(inter_fd, 10); + return 1; +} + +static int intif_clan_kickoffline(int clan_id, int kick_interval) +{ + if (intif->CheckForCharServer() || clan_id == 0 || kick_interval <= 0) + return 0; + + WFIFOHEAD(inter_fd, 10); + WFIFOW(inter_fd, 0) = 0x3045; + WFIFOL(inter_fd, 2) = clan_id; + WFIFOL(inter_fd, 6) = kick_interval; + WFIFOSET(inter_fd, 10); + return 1; +} + +static void intif_parse_RecvClanMemberAction(int fd) +{ + struct clan *c; + int clan_id = RFIFOL(fd, 2); + int count = RFIFOL(fd, 6); + + if ((c = clan->search(clan_id)) == NULL) { + ShowError("intif_parse_RecvClanMemberAction: Received invalid clan_id '%d'\n", clan_id); + return; + } + + if (count < 0) { + ShowError("intif_parse_RecvClanMemberAction: Received invalid member count value '%d'\n", count); + return; + } + + c->received = true; + if (c->req_count_tid != INVALID_TIMER) { + timer->delete(c->req_count_tid, clan->request_membercount); + c->req_count_tid = INVALID_TIMER; + } + + c->member_count = count; + switch (c->req_state) { + case CLAN_REQ_AFTER_KICK: + if (c->req_kick_tid != INVALID_TIMER) { + timer->delete(c->req_kick_tid, clan->request_kickoffline); + c->req_kick_tid = INVALID_TIMER; + } + break; + case CLAN_REQ_RELOAD: + map->foreachpc(clan->rejoin); + break; + default: + break; + } + c->req_state = CLAN_REQ_NONE; +} + // Request a Guild creation -int intif_guild_create(const char *name,const struct guild_member *master) +static int intif_guild_create(const char *name, const struct guild_member *master) { if (intif->CheckForCharServer()) return 0; @@ -633,7 +843,7 @@ int intif_guild_create(const char *name,const struct guild_member *master) } // Request Guild information -int intif_guild_request_info(int guild_id) +static int intif_guild_request_info(int guild_id) { if (intif->CheckForCharServer()) return 0; @@ -645,7 +855,7 @@ int intif_guild_request_info(int guild_id) } // Request to add member to the guild -int intif_guild_addmember(int guild_id,struct guild_member *m) +static int intif_guild_addmember(int guild_id, struct guild_member *m) { if (intif->CheckForCharServer()) return 0; @@ -660,7 +870,7 @@ int intif_guild_addmember(int guild_id,struct guild_member *m) } // Request a new leader for guild -int intif_guild_change_gm(int guild_id, const char *name, int len) +static int intif_guild_change_gm(int guild_id, const char *name, int len) { if (intif->CheckForCharServer()) return 0; @@ -676,7 +886,7 @@ int intif_guild_change_gm(int guild_id, const char *name, int len) } // Request to leave guild -int intif_guild_leave(int guild_id,int account_id,int char_id,int flag,const char *mes) +static int intif_guild_leave(int guild_id, int account_id, int char_id, int flag, const char *mes) { if (intif->CheckForCharServer()) return 0; @@ -693,7 +903,7 @@ int intif_guild_leave(int guild_id,int account_id,int char_id,int flag,const cha } //Update request / Lv online status of the guild members -int intif_guild_memberinfoshort(int guild_id, int account_id, int char_id, int online, int lv, int16 class) +static int intif_guild_memberinfoshort(int guild_id, int account_id, int char_id, int online, int lv, int16 class) { if (intif->CheckForCharServer()) return 0; @@ -710,7 +920,7 @@ int intif_guild_memberinfoshort(int guild_id, int account_id, int char_id, int o } //Guild disbanded notification -int intif_guild_break(int guild_id) +static int intif_guild_break(int guild_id) { if (intif->CheckForCharServer()) return 0; @@ -722,7 +932,7 @@ int intif_guild_break(int guild_id) } // Send a guild message -int intif_guild_message(int guild_id,int account_id,const char *mes,int len) +static int intif_guild_message(int guild_id, int account_id, const char *mes, int len) { if (intif->CheckForCharServer()) return 0; @@ -747,7 +957,7 @@ int intif_guild_message(int guild_id,int account_id,const char *mes,int len) * Requests to change a basic guild information, it is parsed via mapif_parse_GuildBasicInfoChange * To see the information types that can be changed see mmo.h::guild_basic_info **/ -int intif_guild_change_basicinfo(int guild_id,int type,const void *data,int len) +static int intif_guild_change_basicinfo(int guild_id, int type, const void *data, int len) { if (intif->CheckForCharServer()) return 0; @@ -764,8 +974,7 @@ int intif_guild_change_basicinfo(int guild_id,int type,const void *data,int len) } // Request a change of Guild member information -int intif_guild_change_memberinfo(int guild_id,int account_id,int char_id, - int type,const void *data,int len) +static int intif_guild_change_memberinfo(int guild_id, int account_id, int char_id, int type, const void *data, int len) { if (intif->CheckForCharServer()) return 0; @@ -784,7 +993,7 @@ int intif_guild_change_memberinfo(int guild_id,int account_id,int char_id, } // Request a change of Guild title -int intif_guild_position(int guild_id,int idx,struct guild_position *p) +static int intif_guild_position(int guild_id, int idx, struct guild_position *p) { if (intif->CheckForCharServer()) return 0; @@ -800,7 +1009,7 @@ int intif_guild_position(int guild_id,int idx,struct guild_position *p) } // Request an update of Guildskill skill_id -int intif_guild_skillup(int guild_id, uint16 skill_id, int account_id, int max) +static int intif_guild_skillup(int guild_id, uint16 skill_id, int account_id, int max) { if( intif->CheckForCharServer() ) return 0; @@ -815,7 +1024,7 @@ int intif_guild_skillup(int guild_id, uint16 skill_id, int account_id, int max) } // Request a new guild relationship -int intif_guild_alliance(int guild_id1,int guild_id2,int account_id1,int account_id2,int flag) +static int intif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int account_id2, int flag) { if (intif->CheckForCharServer()) return 0; @@ -831,7 +1040,7 @@ int intif_guild_alliance(int guild_id1,int guild_id2,int account_id1,int account } // Request to change guild notice -int intif_guild_notice(int guild_id,const char *mes1,const char *mes2) +static int intif_guild_notice(int guild_id, const char *mes1, const char *mes2) { if (intif->CheckForCharServer()) return 0; @@ -847,7 +1056,7 @@ int intif_guild_notice(int guild_id,const char *mes1,const char *mes2) } // Request to change guild emblem -int intif_guild_emblem(int guild_id,int len,const char *data) +static int intif_guild_emblem(int guild_id, int len, const char *data) { if (intif->CheckForCharServer()) return 0; @@ -870,7 +1079,7 @@ int intif_guild_emblem(int guild_id,int len,const char *data) * @param num Number of castles, size of castle_ids array. * @param castle_ids Pointer to array of castle IDs. */ -int intif_guild_castle_dataload(int num, int *castle_ids) +static int intif_guild_castle_dataload(int num, int *castle_ids) { if (intif->CheckForCharServer()) return 0; @@ -884,7 +1093,7 @@ int intif_guild_castle_dataload(int num, int *castle_ids) } // Request change castle guild owner and save data -int intif_guild_castle_datasave(int castle_id,int index, int value) +static int intif_guild_castle_datasave(int castle_id, int index, int value) { if (intif->CheckForCharServer()) return 0; @@ -901,7 +1110,7 @@ int intif_guild_castle_datasave(int castle_id,int index, int value) // Homunculus Packets send to Inter server [albator] //----------------------------------------------------------------- -int intif_homunculus_create(int account_id, struct s_homunculus *sh) +static int intif_homunculus_create(int account_id, struct s_homunculus *sh) { if (intif->CheckForCharServer()) return 0; @@ -915,7 +1124,8 @@ int intif_homunculus_create(int account_id, struct s_homunculus *sh) return 0; } -bool intif_homunculus_requestload(int account_id, int homun_id) { +static bool intif_homunculus_requestload(int account_id, int homun_id) +{ if (intif->CheckForCharServer()) return false; WFIFOHEAD(inter_fd, 10); @@ -926,7 +1136,7 @@ bool intif_homunculus_requestload(int account_id, int homun_id) { return true; } -int intif_homunculus_requestsave(int account_id, struct s_homunculus* sh) +static int intif_homunculus_requestsave(int account_id, struct s_homunculus *sh) { if (intif->CheckForCharServer()) return 0; @@ -941,7 +1151,7 @@ int intif_homunculus_requestsave(int account_id, struct s_homunculus* sh) } -int intif_homunculus_requestdelete(int homun_id) +static int intif_homunculus_requestdelete(int homun_id) { if (intif->CheckForCharServer()) return 0; @@ -957,7 +1167,8 @@ int intif_homunculus_requestdelete(int homun_id) // Packets receive from inter server // Wisp/Page reception // rewritten by [Yor] -void intif_parse_WisMessage(int fd) { +static void intif_parse_WisMessage(int fd) +{ struct map_session_data* sd; const char *wisp_source; char name[NAME_LENGTH]; @@ -993,7 +1204,7 @@ void intif_parse_WisMessage(int fd) { } // Wisp/page transmission result reception -void intif_parse_WisEnd(int fd) +static void intif_parse_WisEnd(int fd) { struct map_session_data* sd; const char *playername = RFIFOP(fd, 2); @@ -1007,7 +1218,7 @@ void intif_parse_WisEnd(int fd) return; } -int intif_parse_WisToGM_sub(struct map_session_data *sd, va_list va) +static int intif_parse_WisToGM_sub(struct map_session_data *sd, va_list va) { int permission = va_arg(va, int); char *wisp_name; @@ -1026,7 +1237,7 @@ int intif_parse_WisToGM_sub(struct map_session_data *sd, va_list va) // Received wisp message from map-server via char-server for ALL gm // 0x3003/0x3803 <packet_len>.w <wispname>.24B <permission>.l <message>.?B -void intif_parse_WisToGM(int fd) +static void intif_parse_WisToGM(int fd) { int permission, mes_len; char Wisp_name[NAME_LENGTH]; @@ -1048,7 +1259,7 @@ void intif_parse_WisToGM(int fd) } // Request player registre -void intif_parse_Registers(int fd) +static void intif_parse_Registers(int fd) { int flag; struct map_session_data *sd; @@ -1114,7 +1325,7 @@ void intif_parse_Registers(int fd) safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len)); cursor += len + 1; - script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, sval, NULL); + script->set_reg(NULL,sd,reference_uid(script->add_variable(key), index), key, sval, NULL); } /** * Vessel! @@ -1136,7 +1347,7 @@ void intif_parse_Registers(int fd) ival = RFIFOL(fd, cursor); cursor += 4; - script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (const void *)h64BPTRSIZE(ival), NULL); + script->set_reg(NULL,sd,reference_uid(script->add_variable(key), index), key, (const void *)h64BPTRSIZE(ival), NULL); } } script->parser_current_file = NULL;/* reset */ @@ -1149,7 +1360,7 @@ void intif_parse_Registers(int fd) pc->reg_received(sd); //Received all registry values, execute init scripts and what-not. [Skotlex] } -void intif_parse_LoadGuildStorage(int fd) +static void intif_parse_LoadGuildStorage(int fd) { struct guild_storage *gstor; struct map_session_data *sd; @@ -1191,13 +1402,13 @@ void intif_parse_LoadGuildStorage(int fd) } // ACK guild_storage saved -void intif_parse_SaveGuildStorage(int fd) +static void intif_parse_SaveGuildStorage(int fd) { gstorage->saved(/*RFIFOL(fd,2), */RFIFOL(fd,6)); } // ACK party creation -void intif_parse_PartyCreated(int fd) +static void intif_parse_PartyCreated(int fd) { if(battle_config.etc_log) ShowInfo("intif: party created by account %u\n\n", RFIFOL(fd,2)); @@ -1205,7 +1416,8 @@ void intif_parse_PartyCreated(int fd) } // Receive party info -void intif_parse_PartyInfo(int fd) { +static void intif_parse_PartyInfo(int fd) +{ if (RFIFOW(fd,2) == 12) { ShowWarning("intif: party noinfo (char_id=%u party_id=%u)\n", RFIFOL(fd,4), RFIFOL(fd,8)); party->recv_noinfo(RFIFOL(fd,8), RFIFOL(fd,4)); @@ -1219,7 +1431,7 @@ void intif_parse_PartyInfo(int fd) { } // ACK adding party member -void intif_parse_PartyMemberAdded(int fd) +static void intif_parse_PartyMemberAdded(int fd) { if(battle_config.etc_log) ShowInfo("intif: party member added Party (%u), Account(%u), Char(%u)\n", RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); @@ -1227,13 +1439,13 @@ void intif_parse_PartyMemberAdded(int fd) } // ACK changing party option -void intif_parse_PartyOptionChanged(int fd) +static void intif_parse_PartyOptionChanged(int fd) { party->optionchanged(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOW(fd,10),RFIFOW(fd,12),RFIFOB(fd,14)); } // ACK member leaving party -void intif_parse_PartyMemberWithdraw(int fd) +static void intif_parse_PartyMemberWithdraw(int fd) { if(battle_config.etc_log) ShowInfo("intif: party member withdraw: Party(%u), Account(%u), Char(%u)\n", RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10)); @@ -1241,28 +1453,32 @@ void intif_parse_PartyMemberWithdraw(int fd) } // ACK party break -void intif_parse_PartyBroken(int fd) { +static void intif_parse_PartyBroken(int fd) +{ party->broken(RFIFOL(fd,2)); } // ACK party on new map -void intif_parse_PartyMove(int fd) +static void intif_parse_PartyMove(int fd) { party->recv_movemap(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOW(fd,14),RFIFOB(fd,16),RFIFOW(fd,17)); } // ACK party messages -void intif_parse_PartyMessage(int fd) { +static void intif_parse_PartyMessage(int fd) +{ party->recv_message(RFIFOL(fd,4), RFIFOL(fd,8), RFIFOP(fd,12), RFIFOW(fd,2)-12); } // ACK guild creation -void intif_parse_GuildCreated(int fd) { +static void intif_parse_GuildCreated(int fd) +{ guild->created(RFIFOL(fd,2),RFIFOL(fd,6)); } // ACK guild infos -void intif_parse_GuildInfo(int fd) { +static void intif_parse_GuildInfo(int fd) +{ if (RFIFOW(fd,2) == 8) { ShowWarning("intif: guild noinfo %u\n", RFIFOL(fd,4)); guild->recv_noinfo(RFIFOL(fd,4)); @@ -1275,30 +1491,35 @@ void intif_parse_GuildInfo(int fd) { } // ACK adding guild member -void intif_parse_GuildMemberAdded(int fd) { +static void intif_parse_GuildMemberAdded(int fd) +{ if(battle_config.etc_log) ShowInfo("intif: guild member added %u %u %u %d\n", RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOB(fd,14)); guild->member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14)); } // ACK member leaving guild -void intif_parse_GuildMemberWithdraw(int fd) { +static void intif_parse_GuildMemberWithdraw(int fd) +{ guild->member_withdraw(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOB(fd,14), RFIFOP(fd,55), RFIFOP(fd,15)); } // ACK guild member basic info -void intif_parse_GuildMemberInfoShort(int fd) { - guild->recv_memberinfoshort(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17)); +static void intif_parse_GuildMemberInfoShort(int fd) +{ + guild->recv_memberinfoshort(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),RFIFOW(fd,15),RFIFOW(fd,17),RFIFOL(fd,19)); } // ACK guild break -void intif_parse_GuildBroken(int fd) { +static void intif_parse_GuildBroken(int fd) +{ guild->broken(RFIFOL(fd,2),RFIFOB(fd,6)); } // basic guild info change notice // 0x3839 <packet len>.w <guild id>.l <type>.w <data>.?b -void intif_parse_GuildBasicInfoChanged(int fd) { +static void intif_parse_GuildBasicInfoChanged(int fd) +{ //int len = RFIFOW(fd,2) - 10; int guild_id = RFIFOL(fd,4); int type = RFIFOW(fd,8); @@ -1334,7 +1555,8 @@ void intif_parse_GuildBasicInfoChanged(int fd) { // guild member info change notice // 0x383a <packet len>.w <guild id>.l <account id>.l <char id>.l <type>.w <data>.?b -void intif_parse_GuildMemberInfoChanged(int fd) { +static void intif_parse_GuildMemberInfoChanged(int fd) +{ //int len = RFIFOW(fd,2) - 18; int guild_id = RFIFOL(fd,4); int account_id = RFIFOL(fd,8); @@ -1365,7 +1587,8 @@ void intif_parse_GuildMemberInfoChanged(int fd) { } // ACK change of guild title -void intif_parse_GuildPosition(int fd) { +static void intif_parse_GuildPosition(int fd) +{ if (RFIFOW(fd,2)!=sizeof(struct guild_position)+12) ShowError("intif: guild info: data size mismatch (%u) %d != %"PRIuS"\n", RFIFOL(fd,4), RFIFOW(fd,2), sizeof(struct guild_position) + 12); @@ -1373,47 +1596,56 @@ void intif_parse_GuildPosition(int fd) { } // ACK change of guild skill update -void intif_parse_GuildSkillUp(int fd) { +static void intif_parse_GuildSkillUp(int fd) +{ guild->skillupack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10)); } // ACK change of guild relationship -void intif_parse_GuildAlliance(int fd) { +static void intif_parse_GuildAlliance(int fd) +{ guild->allianceack(RFIFOL(fd,2), RFIFOL(fd,6), RFIFOL(fd,10), RFIFOL(fd,14), RFIFOB(fd,18), RFIFOP(fd,19), RFIFOP(fd,43)); } // ACK change of guild notice -void intif_parse_GuildNotice(int fd) { +static void intif_parse_GuildNotice(int fd) +{ guild->notice_changed(RFIFOL(fd,2), RFIFOP(fd,6), RFIFOP(fd,66)); } // ACK change of guild emblem -void intif_parse_GuildEmblem(int fd) { +static void intif_parse_GuildEmblem(int fd) +{ guild->emblem_changed(RFIFOW(fd,2)-12, RFIFOL(fd,4), RFIFOL(fd,8), RFIFOP(fd,12)); } // ACK guild message -void intif_parse_GuildMessage(int fd) { +static void intif_parse_GuildMessage(int fd) +{ guild->recv_message(RFIFOL(fd,4), RFIFOL(fd,8), RFIFOP(fd,12), RFIFOW(fd,2)-12); } // Reply guild castle data request -void intif_parse_GuildCastleDataLoad(int fd) { +static void intif_parse_GuildCastleDataLoad(int fd) +{ guild->castledataloadack(RFIFOW(fd,2), RFIFOP(fd,4)); } // ACK change of guildmaster -void intif_parse_GuildMasterChanged(int fd) { +static void intif_parse_GuildMasterChanged(int fd) +{ guild->gm_changed(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10)); } // Request pet creation -void intif_parse_CreatePet(int fd) { +static void intif_parse_CreatePet(int fd) +{ pet->get_egg(RFIFOL(fd,2), RFIFOW(fd,6), RFIFOL(fd,8)); } // ACK pet data -void intif_parse_RecvPetData(int fd) { +static void intif_parse_RecvPetData(int fd) +{ struct s_pet p; int len; len=RFIFOW(fd,2); @@ -1427,19 +1659,21 @@ void intif_parse_RecvPetData(int fd) { } /* Really? Whats the point, shouldn't be sent when successful then [Ind] */ // ACK pet save data -void intif_parse_SavePetOk(int fd) { +static void intif_parse_SavePetOk(int fd) +{ if(RFIFOB(fd,6) == 1) ShowError("pet data save failure\n"); } /* Really? Whats the point, shouldn't be sent when successful then [Ind] */ // ACK deleting pet -void intif_parse_DeletePetOk(int fd) { +static void intif_parse_DeletePetOk(int fd) +{ if(RFIFOB(fd,2) == 1) ShowError("pet data delete failure\n"); } // ACK changing name request, players,pets,homun -void intif_parse_ChangeNameOk(int fd) +static void intif_parse_ChangeNameOk(int fd) { struct map_session_data *sd = NULL; if((sd=map->id2sd(RFIFOL(fd,2)))==NULL || @@ -1462,7 +1696,8 @@ void intif_parse_ChangeNameOk(int fd) //---------------------------------------------------------------- // Homunculus recv packets [albator] -void intif_parse_CreateHomunculus(int fd) { +static void intif_parse_CreateHomunculus(int fd) +{ int len = RFIFOW(fd,2)-9; if (sizeof(struct s_homunculus) != len) { if (battle_config.etc_log) @@ -1472,7 +1707,8 @@ void intif_parse_CreateHomunculus(int fd) { homun->recv_data(RFIFOL(fd,4), RFIFOP(fd,9), RFIFOB(fd,8)) ; } -void intif_parse_RecvHomunculusData(int fd) { +static void intif_parse_RecvHomunculusData(int fd) +{ int len = RFIFOW(fd,2)-9; if (sizeof(struct s_homunculus) != len) { @@ -1484,29 +1720,122 @@ void intif_parse_RecvHomunculusData(int fd) { } /* Really? Whats the point, shouldn't be sent when successful then [Ind] */ -void intif_parse_SaveHomunculusOk(int fd) { +static void intif_parse_SaveHomunculusOk(int fd) +{ if(RFIFOB(fd,6) != 1) ShowError("homunculus data save failure for account %u\n", RFIFOL(fd,2)); } /* Really? Whats the point, shouldn't be sent when successful then [Ind] */ -void intif_parse_DeleteHomunculusOk(int fd) { +static void intif_parse_DeleteHomunculusOk(int fd) +{ if(RFIFOB(fd,2) != 1) ShowError("Homunculus data delete failure\n"); } -/************************************** +/*************************************** + * ACHIEVEMENT SYSTEM FUNCTIONS + ***************************************/ +/** + * Sends a request to the inter-server to load + * and send a character's achievement data. + * @packet [out] 0x3012 <char_id>.L + * @param sd pointer to map_session_data. + */ +static void intif_achievements_request(struct map_session_data *sd) +{ + nullpo_retv(sd); + + if (intif->CheckForCharServer()) + return; + + WFIFOHEAD(inter_fd, 6); + WFIFOW(inter_fd, 0) = 0x3012; + WFIFOL(inter_fd, 2) = sd->status.char_id; + WFIFOSET(inter_fd, 6); +} + +/** + * Handles reception of achievement data for a character from the inter-server. + * @packet [in] 0x3810 <packet_len>.W <char_id>.L <char_achievements[]>.P + * @param fd socket descriptor. + */ +static void intif_parse_achievements_load(int fd) +{ + int size = RFIFOW(fd, 2); + int char_id = RFIFOL(fd, 4); + int payload_count = (size - 8) / sizeof(struct achievement); + struct map_session_data *sd = map->charid2sd(char_id); + int i = 0; + + if (sd == NULL) { + ShowError("intif_parse_achievements_load: Parse request for achievements received but character is offline!\n"); + return; + } + + if (VECTOR_LENGTH(sd->achievement) > 0) { + ShowError("intif_parse_achievements_load: Achievements already loaded! Possible multiple calls from the inter-server received.\n"); + return; + } + + VECTOR_ENSURE(sd->achievement, payload_count, 1); + + for (i = 0; i < payload_count; i++) { + struct achievement t_ach = { 0 }; + + memcpy(&t_ach, RFIFOP(fd, 8 + i * sizeof(struct achievement)), sizeof(struct achievement)); -QUESTLOG SYSTEM FUNCTIONS + if (achievement->get(t_ach.id) == NULL) { + ShowError("intif_parse_achievements_load: Invalid Achievement %d received from character %d. Ignoring...\n", t_ach.id, char_id); + continue; + } + + VECTOR_PUSH(sd->achievement, t_ach); + } -***************************************/ + achievement->init_titles(sd); + clif->achievement_send_list(fd, sd); + sd->achievements_received = true; +} + +/** + * Send character's achievement data to the inter-server. + * @packet 0x3013 <packet_len>.W <char_id>.L <achievements[]>.P + * @param sd pointer to map session data. + */ +static void intif_achievements_save(struct map_session_data *sd) +{ + int packet_len = 0, payload_size = 0, i = 0; + + nullpo_retv(sd); + /* check for character server. */ + if (intif->CheckForCharServer()) + return; + /* Return if no data. */ + if (!(payload_size = VECTOR_LENGTH(sd->achievement) * sizeof(struct achievement))) + return; + + packet_len = payload_size + 8; + + WFIFOHEAD(inter_fd, packet_len); + WFIFOW(inter_fd, 0) = 0x3013; + WFIFOW(inter_fd, 2) = packet_len; + WFIFOL(inter_fd, 4) = sd->status.char_id; + for (i = 0; i < VECTOR_LENGTH(sd->achievement); i++) + memcpy(WFIFOP(inter_fd, 8 + i * sizeof(struct achievement)), &VECTOR_INDEX(sd->achievement, i), sizeof(struct achievement)); + WFIFOSET(inter_fd, packet_len); +} + +/************************************** + * QUESTLOG SYSTEM FUNCTIONS * + **************************************/ /** * Requests a character's quest log entries to the inter server. * * @param sd Character's data */ -void intif_request_questlog(struct map_session_data *sd) +static void intif_request_questlog(struct map_session_data *sd) { nullpo_retv(sd); WFIFOHEAD(inter_fd,6); @@ -1522,7 +1851,8 @@ void intif_request_questlog(struct map_session_data *sd) * * @see intif_parse */ -void intif_parse_QuestLog(int fd) { +static void intif_parse_QuestLog(int fd) +{ int char_id = RFIFOL(fd, 4), num_received = (RFIFOW(fd, 2)-8)/sizeof(struct quest); struct map_session_data *sd = map->charid2sd(char_id); @@ -1577,7 +1907,8 @@ void intif_parse_QuestLog(int fd) { * * @see intif_parse */ -void intif_parse_QuestSave(int fd) { +static void intif_parse_QuestSave(int fd) +{ int cid = RFIFOL(fd, 2); struct map_session_data *sd = map->id2sd(cid); @@ -1593,7 +1924,7 @@ void intif_parse_QuestSave(int fd) { * @param sd Character's data * @return 0 in case of success, nonzero otherwise */ -int intif_quest_save(struct map_session_data *sd) +static int intif_quest_save(struct map_session_data *sd) { int len = sizeof(struct quest)*sd->num_quests + 8; @@ -1620,7 +1951,7 @@ int intif_quest_save(struct map_session_data *sd) * Inbox Request * flag: 0 Update Inbox | 1 OpenMail *------------------------------------------*/ -int intif_Mail_requestinbox(int char_id, unsigned char flag) +static int intif_Mail_requestinbox(int char_id, unsigned char flag) { if (intif->CheckForCharServer()) return 0; @@ -1634,7 +1965,8 @@ int intif_Mail_requestinbox(int char_id, unsigned char flag) return 0; } -void intif_parse_MailInboxReceived(int fd) { +static void intif_parse_MailInboxReceived(int fd) +{ struct map_session_data *sd; unsigned char flag = RFIFOB(fd,8); @@ -1663,7 +1995,7 @@ void intif_parse_MailInboxReceived(int fd) { /*------------------------------------------ * Mail Read *------------------------------------------*/ -int intif_Mail_read(int mail_id) +static int intif_Mail_read(int mail_id) { if (intif->CheckForCharServer()) return 0; @@ -1678,7 +2010,7 @@ int intif_Mail_read(int mail_id) /*------------------------------------------ * Get Attachment *------------------------------------------*/ -int intif_Mail_getattach(int char_id, int mail_id) +static int intif_Mail_getattach(int char_id, int mail_id) { if (intif->CheckForCharServer()) return 0; @@ -1692,7 +2024,8 @@ int intif_Mail_getattach(int char_id, int mail_id) return 0; } -void intif_parse_MailGetAttach(int fd) { +static void intif_parse_MailGetAttach(int fd) +{ struct map_session_data *sd; struct item item; int zeny = RFIFOL(fd,8); @@ -1717,7 +2050,7 @@ void intif_parse_MailGetAttach(int fd) { /*------------------------------------------ * Delete Message *------------------------------------------*/ -int intif_Mail_delete(int char_id, int mail_id) +static int intif_Mail_delete(int char_id, int mail_id) { if (intif->CheckForCharServer()) return 0; @@ -1731,7 +2064,8 @@ int intif_Mail_delete(int char_id, int mail_id) return 0; } -void intif_parse_MailDelete(int fd) { +static void intif_parse_MailDelete(int fd) +{ struct map_session_data *sd; int char_id = RFIFOL(fd,2); int mail_id = RFIFOL(fd,6); @@ -1759,7 +2093,7 @@ void intif_parse_MailDelete(int fd) { /*------------------------------------------ * Return Message *------------------------------------------*/ -int intif_Mail_return(int char_id, int mail_id) +static int intif_Mail_return(int char_id, int mail_id) { if (intif->CheckForCharServer()) return 0; @@ -1773,7 +2107,8 @@ int intif_Mail_return(int char_id, int mail_id) return 0; } -void intif_parse_MailReturn(int fd) { +static void intif_parse_MailReturn(int fd) +{ struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2)); int mail_id = RFIFOL(fd,6); short fail = RFIFOB(fd,10); @@ -1800,7 +2135,7 @@ void intif_parse_MailReturn(int fd) { /*------------------------------------------ * Send Mail *------------------------------------------*/ -int intif_Mail_send(int account_id, struct mail_message *msg) +static int intif_Mail_send(int account_id, struct mail_message *msg) { int len = sizeof(struct mail_message) + 8; @@ -1818,7 +2153,8 @@ int intif_Mail_send(int account_id, struct mail_message *msg) return 1; } -void intif_parse_MailSend(int fd) { +static void intif_parse_MailSend(int fd) +{ struct mail_message msg; struct map_session_data *sd; bool fail; @@ -1844,7 +2180,8 @@ void intif_parse_MailSend(int fd) { } } -void intif_parse_MailNew(int fd) { +static void intif_parse_MailNew(int fd) +{ struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2)); int mail_id = RFIFOL(fd,6); const char *sender_name = RFIFOP(fd,10); @@ -1861,7 +2198,7 @@ void intif_parse_MailNew(int fd) { * AUCTION SYSTEM * By Zephyrus *==========================================*/ -int intif_Auction_requestlist(int char_id, short type, int price, const char* searchtext, short page) +static int intif_Auction_requestlist(int char_id, short type, int price, const char *searchtext, short page) { int len = NAME_LENGTH + 16; @@ -1882,7 +2219,8 @@ int intif_Auction_requestlist(int char_id, short type, int price, const char* se return 0; } -void intif_parse_AuctionResults(int fd) { +static void intif_parse_AuctionResults(int fd) +{ struct map_session_data *sd = map->charid2sd(RFIFOL(fd,4)); short count = RFIFOW(fd,8); short pages = RFIFOW(fd,10); @@ -1894,7 +2232,7 @@ void intif_parse_AuctionResults(int fd) { clif->auction_results(sd, count, pages, data); } -int intif_Auction_register(struct auction_data *auction) +static int intif_Auction_register(struct auction_data *auction) { int len = sizeof(struct auction_data) + 4; @@ -1911,7 +2249,8 @@ int intif_Auction_register(struct auction_data *auction) return 1; } -void intif_parse_AuctionRegister(int fd) { +static void intif_parse_AuctionRegister(int fd) +{ struct map_session_data *sd; struct auction_data auction; @@ -1938,7 +2277,7 @@ void intif_parse_AuctionRegister(int fd) { } } -int intif_Auction_cancel(int char_id, unsigned int auction_id) +static int intif_Auction_cancel(int char_id, unsigned int auction_id) { if( intif->CheckForCharServer() ) return 0; @@ -1952,7 +2291,8 @@ int intif_Auction_cancel(int char_id, unsigned int auction_id) return 0; } -void intif_parse_AuctionCancel(int fd) { +static void intif_parse_AuctionCancel(int fd) +{ struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2)); int result = RFIFOB(fd,6); @@ -1967,7 +2307,7 @@ void intif_parse_AuctionCancel(int fd) { } } -int intif_Auction_close(int char_id, unsigned int auction_id) +static int intif_Auction_close(int char_id, unsigned int auction_id) { if( intif->CheckForCharServer() ) return 0; @@ -1981,7 +2321,8 @@ int intif_Auction_close(int char_id, unsigned int auction_id) return 0; } -void intif_parse_AuctionClose(int fd) { +static void intif_parse_AuctionClose(int fd) +{ struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2)); unsigned char result = RFIFOB(fd,6); @@ -1996,7 +2337,7 @@ void intif_parse_AuctionClose(int fd) { } } -int intif_Auction_bid(int char_id, const char* name, unsigned int auction_id, int bid) +static int intif_Auction_bid(int char_id, const char *name, unsigned int auction_id, int bid) { int len = 16 + NAME_LENGTH; @@ -2016,7 +2357,8 @@ int intif_Auction_bid(int char_id, const char* name, unsigned int auction_id, in return 0; } -void intif_parse_AuctionBid(int fd) { +static void intif_parse_AuctionBid(int fd) +{ struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2)); int bid = RFIFOL(fd,6); unsigned char result = RFIFOB(fd,10); @@ -2035,7 +2377,8 @@ void intif_parse_AuctionBid(int fd) { } // Used to send 'You have won the auction' and 'You failed to won the auction' messages -void intif_parse_AuctionMessage(int fd) { +static void intif_parse_AuctionMessage(int fd) +{ struct map_session_data *sd = map->charid2sd(RFIFOL(fd,2)); unsigned char result = RFIFOB(fd,6); @@ -2048,7 +2391,7 @@ void intif_parse_AuctionMessage(int fd) { /*========================================== * Mercenary's System *------------------------------------------*/ -int intif_mercenary_create(struct s_mercenary *merc) +static int intif_mercenary_create(struct s_mercenary *merc) { int size = sizeof(struct s_mercenary) + 4; @@ -2064,7 +2407,8 @@ int intif_mercenary_create(struct s_mercenary *merc) return 0; } -void intif_parse_MercenaryReceived(int fd) { +static void intif_parse_MercenaryReceived(int fd) +{ int len = RFIFOW(fd,2) - 5; if (sizeof(struct s_mercenary) != len) { @@ -2076,7 +2420,7 @@ void intif_parse_MercenaryReceived(int fd) { mercenary->data_received(RFIFOP(fd,5), RFIFOB(fd,4)); } -int intif_mercenary_request(int merc_id, int char_id) +static int intif_mercenary_request(int merc_id, int char_id) { if (intif->CheckForCharServer()) return 0; @@ -2089,7 +2433,7 @@ int intif_mercenary_request(int merc_id, int char_id) return 0; } -int intif_mercenary_delete(int merc_id) +static int intif_mercenary_delete(int merc_id) { if (intif->CheckForCharServer()) return 0; @@ -2101,12 +2445,13 @@ int intif_mercenary_delete(int merc_id) return 0; } /* Really? Whats the point, shouldn't be sent when successful then [Ind] */ -void intif_parse_MercenaryDeleted(int fd) { +static void intif_parse_MercenaryDeleted(int fd) +{ if( RFIFOB(fd,2) != 1 ) ShowError("Mercenary data delete failure\n"); } -int intif_mercenary_save(struct s_mercenary *merc) +static int intif_mercenary_save(struct s_mercenary *merc) { int size = sizeof(struct s_mercenary) + 4; @@ -2122,7 +2467,8 @@ int intif_mercenary_save(struct s_mercenary *merc) return 0; } /* Really? Whats the point, shouldn't be sent when successful then [Ind] */ -void intif_parse_MercenarySaved(int fd) { +static void intif_parse_MercenarySaved(int fd) +{ if( RFIFOB(fd,2) != 1 ) ShowError("Mercenary data save failure\n"); } @@ -2130,7 +2476,7 @@ void intif_parse_MercenarySaved(int fd) { /*========================================== * Elemental's System *------------------------------------------*/ -int intif_elemental_create(struct s_elemental *ele) +static int intif_elemental_create(struct s_elemental *ele) { int size = sizeof(struct s_elemental) + 4; @@ -2146,7 +2492,8 @@ int intif_elemental_create(struct s_elemental *ele) return 0; } -void intif_parse_ElementalReceived(int fd) { +static void intif_parse_ElementalReceived(int fd) +{ int len = RFIFOW(fd,2) - 5; if (sizeof(struct s_elemental) != len) { @@ -2158,7 +2505,7 @@ void intif_parse_ElementalReceived(int fd) { elemental->data_received(RFIFOP(fd,5), RFIFOB(fd,4)); } -int intif_elemental_request(int ele_id, int char_id) +static int intif_elemental_request(int ele_id, int char_id) { if (intif->CheckForCharServer()) return 0; @@ -2171,7 +2518,7 @@ int intif_elemental_request(int ele_id, int char_id) return 0; } -int intif_elemental_delete(int ele_id) +static int intif_elemental_delete(int ele_id) { if (intif->CheckForCharServer()) return 0; @@ -2183,12 +2530,13 @@ int intif_elemental_delete(int ele_id) return 0; } /* Really? Whats the point, shouldn't be sent when successful then [Ind] */ -void intif_parse_ElementalDeleted(int fd) { +static void intif_parse_ElementalDeleted(int fd) +{ if( RFIFOB(fd,2) != 1 ) ShowError("Elemental data delete failure\n"); } -int intif_elemental_save(struct s_elemental *ele) +static int intif_elemental_save(struct s_elemental *ele) { int size = sizeof(struct s_elemental) + 4; @@ -2204,12 +2552,14 @@ int intif_elemental_save(struct s_elemental *ele) return 0; } /* Really? Whats the point, shouldn't be sent when successful then [Ind] */ -void intif_parse_ElementalSaved(int fd) { +static void intif_parse_ElementalSaved(int fd) +{ if( RFIFOB(fd,2) != 1 ) ShowError("Elemental data save failure\n"); } -void intif_request_accinfo( int u_fd, int aid, int group_lv, char* query ) { +static void intif_request_accinfo(int u_fd, int aid, int group_lv, char *query) +{ nullpo_retv(query); WFIFOHEAD(inter_fd,2 + 4 + 4 + 4 + NAME_LENGTH); @@ -2224,7 +2574,8 @@ void intif_request_accinfo( int u_fd, int aid, int group_lv, char* query ) { return; } -void intif_parse_MessageToFD(int fd) { +static void intif_parse_MessageToFD(int fd) +{ int u_fd = RFIFOL(fd,4); Assert_retv(sockt->session_is_valid(u_fd)); @@ -2245,7 +2596,8 @@ void intif_parse_MessageToFD(int fd) { /*========================================== * Item Bound System [Xantara][Mhalicot] *------------------------------------------*/ -void intif_itembound_req(int char_id,int aid,int guild_id) { +static void intif_itembound_req(int char_id, int aid, int guild_id) +{ #ifdef GP_BOUND_ITEMS struct guild_storage *gstor = idb_get(gstorage->db,guild_id); WFIFOHEAD(inter_fd,12); @@ -2260,7 +2612,8 @@ void intif_itembound_req(int char_id,int aid,int guild_id) { } //3856 -void intif_parse_Itembound_ack(int fd) { +static void intif_parse_Itembound_ack(int fd) +{ #ifdef GP_BOUND_ITEMS struct guild_storage *gstor; int guild_id = RFIFOW(fd,6); @@ -2270,11 +2623,243 @@ 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 +static 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; +} + +static void intif_parse_RequestRodexOpenInbox(int fd) +{ + struct map_session_data *sd; +#if PACKETVER < 20170419 + int8 opentype = RFIFOB(fd, 8); +#endif + int8 flag = RFIFOB(fd, 9); + int8 is_end = RFIFOB(fd, 10); + int is_first = RFIFOB(fd, 11); + int count = RFIFOL(fd, 12); +#if PACKETVER >= 20170419 + int64 mail_id = RFIFOQ(fd, 16); +#endif + int i, j; + + sd = map->charid2sd(RFIFOL(fd, 4)); + + if (sd == NULL) // user is not online anymore + return; + + if (is_first == false && sd->rodex.total == 0) { + ShowError("intif_parse_RodexInboxOpenReceived: mail list received in wrong order.\n"); + return; + } + + if (is_first) + sd->rodex.total = count; + else + sd->rodex.total += count; + + if (RFIFOW(fd, 2) - 24 != count * sizeof(struct rodex_message)) { + ShowError("intif_parse_RodexInboxOpenReceived: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd, 2) - 24, count * sizeof(struct rodex_message)); + return; + } + + if (flag == 0 && is_first) + VECTOR_CLEAR(sd->rodex.messages); + + for (i = 0, j = 24; 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 PACKETVER >= 20170419 + clif->rodex_send_mails_all(sd->fd, sd, mail_id); +#else + 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); +#endif + } +} + +/*------------------------------------------ + * Notifications + *------------------------------------------*/ +static 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; +} + +static 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 - receiver Read +/// 1 - user got Zeny +/// 2 - user got Items +/// 3 - delete +/// 4 - sender Read (returned mail) +static 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 + *------------------------------------------*/ +static 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; +} + +static 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 + *------------------------------------------*/ +static 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; +} + +static 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; + safestrncpy(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. // 1, 2 if there are not enough to return the length of the packet if the packet processing -int intif_parse(int fd) +static int intif_parse(int fd) { int packet_len, cmd; cmd = RFIFOW(fd,0); @@ -2306,8 +2891,11 @@ int intif_parse(int fd) case 0x3802: intif->pWisEnd(fd); break; case 0x3803: intif->pWisToGM(fd); break; case 0x3804: intif->pRegisters(fd); break; + case 0x3805: intif->pAccountStorage(fd); break; case 0x3806: intif->pChangeNameOk(fd); break; case 0x3807: intif->pMessageToFD(fd); break; + case 0x3808: intif->pAccountStorageSaveAck(fd); break; + case 0x3810: intif->pAchievementsLoad(fd); break; case 0x3818: intif->pLoadGuildStorage(fd); break; case 0x3819: intif->pSaveGuildStorage(fd); break; case 0x3820: intif->pPartyCreated(fd); break; @@ -2378,6 +2966,15 @@ 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; + + // Clan System + case 0x3858: intif->pRecvClanMemberAction(fd); break; default: ShowError("intif_parse : unknown packet %d %x\n",fd,RFIFOW(fd,0)); return 0; @@ -2388,22 +2985,23 @@ int intif_parse(int fd) } /*===================================== -* Default Functions : intif.h -* Generated by HerculesInterfaceMaker -* created by Susu -*-------------------------------------*/ -void intif_defaults(void) { + * Default Functions : intif.h + * Generated by HerculesInterfaceMaker + * created by Susu + *-------------------------------------*/ +void intif_defaults(void) +{ const int packet_len_table [INTIF_PACKET_LEN_TABLE_SIZE] = { - -1,-1,27,-1, -1, 0,37,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3800-0x380f - 0, 0, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810 + -1,-1,27,-1, -1,-1,37,-1, 7, 0, 0, 0, 0, 0, 0, 0, //0x3800-0x380f + -1, 0, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810 Achievements [Smokexyz/Hercules] 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 + 10,-1,15, 0, 79,23, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830 -1, 0, 0,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840 - -1,-1, 7, 7, 7,11, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus] itembound[Akinari] + -1,-1, 7, 7, 7,11, 8, 0, 10, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus] itembound[Akinari] Clan System[Murilo BiO] -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; @@ -2421,6 +3019,8 @@ void intif_defaults(void) { intif->wis_message_to_gm = intif_wis_message_to_gm; intif->saveregistry = intif_saveregistry; intif->request_registry = intif_request_registry; + intif->request_account_storage = intif_request_account_storage; + intif->send_account_storage = intif_send_account_storage; intif->request_guild_storage = intif_request_guild_storage; intif->send_guild_storage = intif_send_guild_storage; intif->create_party = intif_create_party; @@ -2483,12 +3083,24 @@ 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; + /* Clan System */ + intif->clan_kickoffline = intif_clan_kickoffline; + intif->clan_membercount = intif_clan_membercount; /* @accinfo */ intif->request_accinfo = intif_request_accinfo; /* */ intif->CheckForCharServer = CheckForCharServer; /* */ intif->itembound_req = intif_itembound_req; + /* Achievement System */ + intif->achievements_request = intif_achievements_request; + intif->achievements_save = intif_achievements_save; /* parse functions */ intif->pWisMessage = intif_parse_WisMessage; intif->pWisEnd = intif_parse_WisEnd; @@ -2497,6 +3109,8 @@ void intif_defaults(void) { intif->pRegisters = intif_parse_Registers; intif->pChangeNameOk = intif_parse_ChangeNameOk; intif->pMessageToFD = intif_parse_MessageToFD; + intif->pAccountStorage = intif_parse_account_storage; + intif->pAccountStorageSaveAck = intif_parse_account_storage_save_ack; intif->pLoadGuildStorage = intif_parse_LoadGuildStorage; intif->pSaveGuildStorage = intif_parse_SaveGuildStorage; intif->pPartyCreated = intif_parse_PartyCreated; @@ -2552,4 +3166,13 @@ 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; + /* Clan System */ + intif->pRecvClanMemberAction = intif_parse_RecvClanMemberAction; + /* Achievement System */ + intif->pAchievementsLoad = intif_parse_achievements_load; } |