/src/map/intif.c
C | 2545 lines | 1951 code | 338 blank | 256 comment | 301 complexity | 7f38d21e6493c58c442ba3d115bf2f88 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.0
Large files files are truncated, but you can click here to view the full file
- /**
- * This file is part of Hercules.
- * http://herc.ws - http://github.com/HerculesWS/Hercules
- *
- * Copyright (C) 2012-2015 Hercules Dev Team
- * Copyright (C) Athena Dev Teams
- *
- * Hercules is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #define HERCULES_CORE
- #include "config/core.h" // GP_BOUND_ITEMS
- #include "intif.h"
- #include "map/atcommand.h"
- #include "map/battle.h"
- #include "map/chrif.h"
- #include "map/clif.h"
- #include "map/elemental.h"
- #include "map/guild.h"
- #include "map/homunculus.h"
- #include "map/log.h"
- #include "map/mail.h"
- #include "map/map.h"
- #include "map/mercenary.h"
- #include "map/party.h"
- #include "map/pc.h"
- #include "map/pet.h"
- #include "map/quest.h"
- #include "map/storage.h"
- #include "common/memmgr.h"
- #include "common/nullpo.h"
- #include "common/showmsg.h"
- #include "common/socket.h"
- #include "common/strlib.h"
- #include "common/timer.h"
- #include <fcntl.h>
- #include <signal.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- struct intif_interface intif_s;
- struct intif_interface *intif;
- #define inter_fd (chrif->fd) // alias
- //-----------------------------------------------------------------
- // Send to inter server
- 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)
- {
- 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);
- return 0;
- }
- int intif_request_petdata(int account_id,int char_id,int pet_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 14);
- WFIFOW(inter_fd,0) = 0x3081;
- WFIFOL(inter_fd,2) = account_id;
- WFIFOL(inter_fd,6) = char_id;
- WFIFOL(inter_fd,10) = pet_id;
- WFIFOSET(inter_fd,14);
- return 0;
- }
- int intif_save_petdata(int account_id,struct s_pet *p)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(p);
- WFIFOHEAD(inter_fd, sizeof(struct s_pet) + 8);
- WFIFOW(inter_fd,0) = 0x3082;
- WFIFOW(inter_fd,2) = sizeof(struct s_pet) + 8;
- WFIFOL(inter_fd,4) = account_id;
- memcpy(WFIFOP(inter_fd,8),p,sizeof(struct s_pet));
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 0;
- }
- int intif_delete_petdata(int pet_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3083;
- WFIFOL(inter_fd,2) = pet_id;
- WFIFOSET(inter_fd,6);
- return 1;
- }
- int intif_rename(struct map_session_data *sd, int type, char *name)
- {
- if (intif->CheckForCharServer())
- return 1;
- nullpo_ret(sd);
- nullpo_ret(name);
- WFIFOHEAD(inter_fd,NAME_LENGTH+12);
- WFIFOW(inter_fd,0) = 0x3006;
- WFIFOL(inter_fd,2) = sd->status.account_id;
- WFIFOL(inter_fd,6) = sd->status.char_id;
- WFIFOB(inter_fd,10) = type; //Type: 0 - PC, 1 - PET, 2 - HOM
- memcpy(WFIFOP(inter_fd,11),name, NAME_LENGTH);
- WFIFOSET(inter_fd,NAME_LENGTH+12);
- return 0;
- }
- // GM Send a message
- int intif_broadcast(const char* mes, size_t len, int type)
- {
- int lp = (type&BC_COLOR_MASK) ? 4 : 0;
- nullpo_ret(mes);
- Assert_ret(len < 32000);
- // Send to the local players
- clif->broadcast(NULL, mes, len, type, ALL_CLIENT);
- if (intif->CheckForCharServer())
- return 0;
- if (chrif->other_mapserver_count < 1)
- return 0; //No need to send.
- WFIFOHEAD(inter_fd, 16 + lp + len);
- WFIFOW(inter_fd,0) = 0x3000;
- WFIFOW(inter_fd,2) = 16 + lp + len;
- WFIFOL(inter_fd,4) = 0xFF000000; // 0xFF000000 color signals standard broadcast
- WFIFOW(inter_fd,8) = 0; // fontType not used with standard broadcast
- WFIFOW(inter_fd,10) = 0; // fontSize not used with standard broadcast
- WFIFOW(inter_fd,12) = 0; // fontAlign not used with standard broadcast
- WFIFOW(inter_fd,14) = 0; // fontY not used with standard broadcast
- if (type&BC_BLUE)
- WFIFOL(inter_fd,16) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
- else if (type&BC_WOE)
- WFIFOL(inter_fd,16) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
- memcpy(WFIFOP(inter_fd,16 + lp), mes, len);
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- return 0;
- }
- int intif_broadcast2(const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY)
- {
- nullpo_ret(mes);
- Assert_ret(len < 32000);
- // Send to the local players
- clif->broadcast2(NULL, mes, len, fontColor, fontType, fontSize, fontAlign, fontY, ALL_CLIENT);
- if (intif->CheckForCharServer())
- return 0;
- if (chrif->other_mapserver_count < 1)
- return 0; //No need to send.
- WFIFOHEAD(inter_fd, 16 + len);
- WFIFOW(inter_fd,0) = 0x3000;
- WFIFOW(inter_fd,2) = 16 + len;
- WFIFOL(inter_fd,4) = fontColor;
- WFIFOW(inter_fd,8) = fontType;
- WFIFOW(inter_fd,10) = fontSize;
- WFIFOW(inter_fd,12) = fontAlign;
- WFIFOW(inter_fd,14) = fontY;
- memcpy(WFIFOP(inter_fd,16), mes, len);
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- return 0;
- }
- /// 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)
- {
- char output[256];
- nullpo_ret(sd);
- nullpo_ret(message);
- // format the message for main broadcasting
- snprintf( output, sizeof(output), msg_txt(386), sd->status.name, message );
- // send the message using the inter-server broadcast service
- intif->broadcast2( output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0 );
- // log the chat message
- logs->chat( LOG_CHAT_MAINCHAT, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message );
- return 0;
- }
- // The transmission of Wisp/Page to inter-server (player not found on this server)
- int intif_wis_message(struct map_session_data *sd, char *nick, char *mes, size_t mes_len)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(sd);
- nullpo_ret(nick);
- nullpo_ret(mes);
- if (chrif->other_mapserver_count < 1) {
- //Character not found.
- clif->wis_end(sd->fd, 1);
- return 0;
- }
- WFIFOHEAD(inter_fd,mes_len + 52);
- WFIFOW(inter_fd,0) = 0x3001;
- WFIFOW(inter_fd,2) = mes_len + 52;
- memcpy(WFIFOP(inter_fd,4), sd->status.name, NAME_LENGTH);
- memcpy(WFIFOP(inter_fd,4+NAME_LENGTH), nick, NAME_LENGTH);
- memcpy(WFIFOP(inter_fd,4+2*NAME_LENGTH), mes, mes_len);
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- if (battle_config.etc_log)
- ShowInfo("intif_wis_message from %s to %s (message: '%s')\n", sd->status.name, nick, mes);
- return 0;
- }
- // The reply of Wisp/page
- int intif_wis_replay(int id, int flag)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,7);
- WFIFOW(inter_fd,0) = 0x3002;
- WFIFOL(inter_fd,2) = id;
- WFIFOB(inter_fd,6) = flag; // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target
- WFIFOSET(inter_fd,7);
- if (battle_config.etc_log)
- ShowInfo("intif_wis_replay: id: %d, flag:%d\n", id, flag);
- return 0;
- }
- // 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)
- {
- size_t mes_len;
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(wisp_name);
- nullpo_ret(mes);
- mes_len = strlen(mes) + 1; // + null
- WFIFOHEAD(inter_fd, mes_len + 32);
- WFIFOW(inter_fd,0) = 0x3003;
- WFIFOW(inter_fd,2) = mes_len + 32;
- memcpy(WFIFOP(inter_fd,4), wisp_name, NAME_LENGTH);
- WFIFOL(inter_fd,4+NAME_LENGTH) = permission;
- memcpy(WFIFOP(inter_fd,8+NAME_LENGTH), mes, mes_len);
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- if (battle_config.etc_log)
- ShowNotice("intif_wis_message_to_gm: from: '%s', required permission: %d, message: '%s'.\n", wisp_name, permission, mes);
- return 0;
- }
- //Request for saving registry values.
- int intif_saveregistry(struct map_session_data *sd) {
- DBIterator *iter;
- DBKey key;
- DBData *data;
- int plen = 0;
- size_t len;
- nullpo_ret(sd);
- if (intif->CheckForCharServer() || !sd->regs.vars)
- return -1;
- WFIFOHEAD(inter_fd, 60000 + 300);
- WFIFOW(inter_fd,0) = 0x3004;
- /* 0x2 = length (set later) */
- WFIFOL(inter_fd,4) = sd->status.account_id;
- WFIFOL(inter_fd,8) = sd->status.char_id;
- WFIFOW(inter_fd,12) = 0;/* count */
- plen = 14;
- iter = db_iterator(sd->regs.vars);
- for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
- const char *varname = NULL;
- struct script_reg_state *src = NULL;
- if( data->type != DB_DATA_PTR ) /* its a @number */
- continue;
- varname = script->get_str(script_getvarid(key.i64));
- if( varname[0] == '@' ) /* @string$ can get here, so we skip */
- continue;
- if (strlen(varname) > SCRIPT_VARNAME_LENGTH) {
- ShowError("Variable name too big: %s\n", varname);
- continue;
- }
- src = DB->data2ptr(data);
- /* no need! */
- if( !src->update )
- continue;
- src->update = false;
- len = strlen(varname)+1;
- WFIFOB(inter_fd, plen) = (unsigned char)len;/* won't be higher; the column size is 32 */
- plen += 1;
- safestrncpy((char*)WFIFOP(inter_fd,plen), varname, len);
- plen += len;
- WFIFOL(inter_fd, plen) = script_getvaridx(key.i64);
- plen += 4;
- if( src->type ) {
- struct script_reg_str *p = (struct script_reg_str *)src;
- WFIFOB(inter_fd, plen) = p->value ? 2 : 3;
- plen += 1;
- if( p->value ) {
- len = strlen(p->value)+1;
- WFIFOB(inter_fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */
- plen += 1;
- safestrncpy((char*)WFIFOP(inter_fd,plen), p->value, len);
- plen += len;
- } else {
- script->reg_destroy_single(sd,key.i64,&p->flag);
- }
- } else {
- struct script_reg_num *p = (struct script_reg_num *)src;
- WFIFOB(inter_fd, plen) = p->value ? 0 : 1;
- plen += 1;
- if( p->value ) {
- WFIFOL(inter_fd, plen) = p->value;
- plen += 4;
- } else {
- script->reg_destroy_single(sd,key.i64,&p->flag);
- }
- }
- WFIFOW(inter_fd,12) += 1;
- if( plen > 60000 ) {
- WFIFOW(inter_fd, 2) = plen;
- WFIFOSET(inter_fd, plen);
- /* prepare follow up */
- WFIFOHEAD(inter_fd, 60000 + 300);
- WFIFOW(inter_fd,0) = 0x3004;
- /* 0x2 = length (set later) */
- WFIFOL(inter_fd,4) = sd->status.account_id;
- WFIFOL(inter_fd,8) = sd->status.char_id;
- WFIFOW(inter_fd,12) = 0;/* count */
- plen = 14;
- }
- }
- dbi_destroy(iter);
- /* mark & go. */
- WFIFOW(inter_fd, 2) = plen;
- WFIFOSET(inter_fd, plen);
- sd->vars_dirty = false;
- return 0;
- }
- //Request the registries for this player.
- int intif_request_registry(struct map_session_data *sd, int flag)
- {
- nullpo_ret(sd);
- /* if char server ain't online it doesn't load, shouldn't we kill the session then? */
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3005;
- WFIFOL(inter_fd,2) = sd->status.account_id;
- WFIFOL(inter_fd,6) = sd->status.char_id;
- WFIFOB(inter_fd,10) = (flag&1) ? 1 : 0; //Request Acc Reg 2
- WFIFOB(inter_fd,11) = (flag&2) ? 1 : 0; //Request Acc Reg
- WFIFOB(inter_fd,12) = (flag&4) ? 1 : 0; //Request Char Reg
- WFIFOSET(inter_fd,13);
- return 0;
- }
- int intif_request_guild_storage(int account_id,int guild_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x3018;
- WFIFOL(inter_fd,2) = account_id;
- WFIFOL(inter_fd,6) = guild_id;
- WFIFOSET(inter_fd,10);
- return 0;
- }
- int intif_send_guild_storage(int account_id,struct guild_storage *gstor)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(gstor);
- WFIFOHEAD(inter_fd,sizeof(struct guild_storage)+12);
- WFIFOW(inter_fd,0) = 0x3019;
- WFIFOW(inter_fd,2) = (unsigned short)sizeof(struct guild_storage)+12;
- WFIFOL(inter_fd,4) = account_id;
- WFIFOL(inter_fd,8) = gstor->guild_id;
- memcpy( WFIFOP(inter_fd,12),gstor, sizeof(struct guild_storage) );
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 0;
- }
- // Party creation request
- int intif_create_party(struct party_member *member,char *name,int item,int item2)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(member);
- nullpo_ret(name);
- WFIFOHEAD(inter_fd,64);
- WFIFOW(inter_fd,0) = 0x3020;
- WFIFOW(inter_fd,2) = 30+sizeof(struct party_member);
- memcpy(WFIFOP(inter_fd,4),name, NAME_LENGTH);
- WFIFOB(inter_fd,28)= item;
- WFIFOB(inter_fd,29)= item2;
- memcpy(WFIFOP(inter_fd,30), member, sizeof(struct party_member));
- WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
- return 0;
- }
- // Party information request
- int intif_request_partyinfo(int party_id, int char_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x3021;
- WFIFOL(inter_fd,2) = party_id;
- WFIFOL(inter_fd,6) = char_id;
- WFIFOSET(inter_fd,10);
- return 0;
- }
- // Request to add a member to party
- int intif_party_addmember(int party_id,struct party_member *member)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(member);
- WFIFOHEAD(inter_fd,42);
- WFIFOW(inter_fd,0)=0x3022;
- WFIFOW(inter_fd,2)=8+sizeof(struct party_member);
- WFIFOL(inter_fd,4)=party_id;
- memcpy(WFIFOP(inter_fd,8),member,sizeof(struct party_member));
- WFIFOSET(inter_fd,WFIFOW(inter_fd, 2));
- return 1;
- }
- // Request to change party configuration (exp,item share)
- int intif_party_changeoption(int party_id,int account_id,int exp,int item)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,14);
- WFIFOW(inter_fd,0)=0x3023;
- WFIFOL(inter_fd,2)=party_id;
- WFIFOL(inter_fd,6)=account_id;
- WFIFOW(inter_fd,10)=exp;
- WFIFOW(inter_fd,12)=item;
- WFIFOSET(inter_fd,14);
- return 0;
- }
- // Request to leave party
- int intif_party_leave(int party_id,int account_id, int char_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,14);
- WFIFOW(inter_fd,0)=0x3024;
- WFIFOL(inter_fd,2)=party_id;
- WFIFOL(inter_fd,6)=account_id;
- WFIFOL(inter_fd,10)=char_id;
- WFIFOSET(inter_fd,14);
- return 0;
- }
- // Request keeping party for new map ??
- int intif_party_changemap(struct map_session_data *sd,int online) {
- int16 m, map_index;
- if (intif->CheckForCharServer())
- return 0;
- if(!sd)
- return 0;
- if( (m=map->mapindex2mapid(sd->mapindex)) >= 0 && map->list[m].instance_id >= 0 )
- map_index = map_id2index(map->list[m].instance_src_map);
- else
- map_index = sd->mapindex;
- WFIFOHEAD(inter_fd,19);
- WFIFOW(inter_fd,0)=0x3025;
- WFIFOL(inter_fd,2)=sd->status.party_id;
- WFIFOL(inter_fd,6)=sd->status.account_id;
- WFIFOL(inter_fd,10)=sd->status.char_id;
- WFIFOW(inter_fd,14)=map_index;
- WFIFOB(inter_fd,16)=online;
- WFIFOW(inter_fd,17)=sd->status.base_level;
- WFIFOSET(inter_fd,19);
- return 1;
- }
- // Request breaking party
- int intif_break_party(int party_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0)=0x3026;
- WFIFOL(inter_fd,2)=party_id;
- WFIFOSET(inter_fd,6);
- return 0;
- }
- // Sending party chat
- int intif_party_message(int party_id,int account_id,const char *mes,int len)
- {
- if (intif->CheckForCharServer())
- return 0;
- if (chrif->other_mapserver_count < 1)
- return 0; //No need to send.
- nullpo_ret(mes);
- Assert_ret(len > 0 && len < 32000);
- WFIFOHEAD(inter_fd,len + 12);
- WFIFOW(inter_fd,0)=0x3027;
- WFIFOW(inter_fd,2)=len+12;
- WFIFOL(inter_fd,4)=party_id;
- WFIFOL(inter_fd,8)=account_id;
- memcpy(WFIFOP(inter_fd,12),mes,len);
- WFIFOSET(inter_fd,len+12);
- return 0;
- }
- // Request a new leader for party
- int intif_party_leaderchange(int party_id,int account_id,int char_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,14);
- WFIFOW(inter_fd,0)=0x3029;
- WFIFOL(inter_fd,2)=party_id;
- WFIFOL(inter_fd,6)=account_id;
- WFIFOL(inter_fd,10)=char_id;
- WFIFOSET(inter_fd,14);
- return 0;
- }
- // Request a Guild creation
- int intif_guild_create(const char *name,const struct guild_member *master)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(master);
- nullpo_ret(name);
- WFIFOHEAD(inter_fd,sizeof(struct guild_member)+(8+NAME_LENGTH));
- WFIFOW(inter_fd,0)=0x3030;
- WFIFOW(inter_fd,2)=sizeof(struct guild_member)+(8+NAME_LENGTH);
- WFIFOL(inter_fd,4)=master->account_id;
- memcpy(WFIFOP(inter_fd,8),name,NAME_LENGTH);
- memcpy(WFIFOP(inter_fd,8+NAME_LENGTH),master,sizeof(struct guild_member));
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 0;
- }
- // Request Guild information
- int intif_guild_request_info(int guild_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3031;
- WFIFOL(inter_fd,2) = guild_id;
- WFIFOSET(inter_fd,6);
- return 0;
- }
- // Request to add member to the guild
- int intif_guild_addmember(int guild_id,struct guild_member *m)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(m);
- WFIFOHEAD(inter_fd,sizeof(struct guild_member)+8);
- WFIFOW(inter_fd,0) = 0x3032;
- WFIFOW(inter_fd,2) = sizeof(struct guild_member)+8;
- WFIFOL(inter_fd,4) = guild_id;
- memcpy(WFIFOP(inter_fd,8),m,sizeof(struct guild_member));
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 0;
- }
- // Request a new leader for guild
- int intif_guild_change_gm(int guild_id, const char* name, size_t len)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(name);
- Assert_ret(len > 0 && len < 32000);
- WFIFOHEAD(inter_fd, len + 8);
- WFIFOW(inter_fd, 0)=0x3033;
- WFIFOW(inter_fd, 2)=len+8;
- WFIFOL(inter_fd, 4)=guild_id;
- memcpy(WFIFOP(inter_fd,8),name,len);
- WFIFOSET(inter_fd,len+8);
- return 0;
- }
- // Request to leave guild
- int intif_guild_leave(int guild_id,int account_id,int char_id,int flag,const char *mes)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(mes);
- WFIFOHEAD(inter_fd, 55);
- WFIFOW(inter_fd, 0) = 0x3034;
- WFIFOL(inter_fd, 2) = guild_id;
- WFIFOL(inter_fd, 6) = account_id;
- WFIFOL(inter_fd,10) = char_id;
- WFIFOB(inter_fd,14) = flag;
- safestrncpy((char*)WFIFOP(inter_fd,15),mes,40);
- WFIFOSET(inter_fd,55);
- return 0;
- }
- //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,int class_)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 19);
- WFIFOW(inter_fd, 0) = 0x3035;
- WFIFOL(inter_fd, 2) = guild_id;
- WFIFOL(inter_fd, 6) = account_id;
- WFIFOL(inter_fd,10) = char_id;
- WFIFOB(inter_fd,14) = online;
- WFIFOW(inter_fd,15) = lv;
- WFIFOW(inter_fd,17) = class_;
- WFIFOSET(inter_fd,19);
- return 0;
- }
- //Guild disbanded notification
- int intif_guild_break(int guild_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 6);
- WFIFOW(inter_fd, 0) = 0x3036;
- WFIFOL(inter_fd, 2) = guild_id;
- WFIFOSET(inter_fd,6);
- return 0;
- }
- // Send a guild message
- int intif_guild_message(int guild_id,int account_id,const char *mes,int len)
- {
- if (intif->CheckForCharServer())
- return 0;
- if (chrif->other_mapserver_count < 1)
- return 0; //No need to send.
- nullpo_ret(mes);
- Assert_ret(len > 0 && len < 32000);
- WFIFOHEAD(inter_fd, len + 12);
- WFIFOW(inter_fd,0)=0x3037;
- WFIFOW(inter_fd,2)=len+12;
- WFIFOL(inter_fd,4)=guild_id;
- WFIFOL(inter_fd,8)=account_id;
- memcpy(WFIFOP(inter_fd,12),mes,len);
- WFIFOSET(inter_fd,len+12);
- return 0;
- }
- /**
- * 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)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(data);
- Assert_ret(len >= 0 && len < 32000);
- WFIFOHEAD(inter_fd, len + 10);
- WFIFOW(inter_fd,0)=0x3039;
- WFIFOW(inter_fd,2)=len+10;
- WFIFOL(inter_fd,4)=guild_id;
- WFIFOW(inter_fd,8)=type;
- memcpy(WFIFOP(inter_fd,10),data,len);
- WFIFOSET(inter_fd,len+10);
- return 0;
- }
- // 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)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(data);
- Assert_ret(len >= 0 && len < 32000);
- WFIFOHEAD(inter_fd, len + 18);
- WFIFOW(inter_fd, 0)=0x303a;
- WFIFOW(inter_fd, 2)=len+18;
- WFIFOL(inter_fd, 4)=guild_id;
- WFIFOL(inter_fd, 8)=account_id;
- WFIFOL(inter_fd,12)=char_id;
- WFIFOW(inter_fd,16)=type;
- memcpy(WFIFOP(inter_fd,18),data,len);
- WFIFOSET(inter_fd,len+18);
- return 0;
- }
- // Request a change of Guild title
- int intif_guild_position(int guild_id,int idx,struct guild_position *p)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(p);
- WFIFOHEAD(inter_fd, sizeof(struct guild_position)+12);
- WFIFOW(inter_fd,0)=0x303b;
- WFIFOW(inter_fd,2)=sizeof(struct guild_position)+12;
- WFIFOL(inter_fd,4)=guild_id;
- WFIFOL(inter_fd,8)=idx;
- memcpy(WFIFOP(inter_fd,12),p,sizeof(struct guild_position));
- WFIFOSET(inter_fd,WFIFOW(inter_fd,2));
- return 0;
- }
- // Request an update of Guildskill skill_id
- int intif_guild_skillup(int guild_id, uint16 skill_id, int account_id, int max)
- {
- if( intif->CheckForCharServer() )
- return 0;
- WFIFOHEAD(inter_fd, 18);
- WFIFOW(inter_fd, 0) = 0x303c;
- WFIFOL(inter_fd, 2) = guild_id;
- WFIFOL(inter_fd, 6) = skill_id;
- WFIFOL(inter_fd, 10) = account_id;
- WFIFOL(inter_fd, 14) = max;
- WFIFOSET(inter_fd, 18);
- return 0;
- }
- // Request a new guild relationship
- int intif_guild_alliance(int guild_id1,int guild_id2,int account_id1,int account_id2,int flag)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,19);
- WFIFOW(inter_fd, 0)=0x303d;
- WFIFOL(inter_fd, 2)=guild_id1;
- WFIFOL(inter_fd, 6)=guild_id2;
- WFIFOL(inter_fd,10)=account_id1;
- WFIFOL(inter_fd,14)=account_id2;
- WFIFOB(inter_fd,18)=flag;
- WFIFOSET(inter_fd,19);
- return 0;
- }
- // Request to change guild notice
- int intif_guild_notice(int guild_id,const char *mes1,const char *mes2)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(mes1);
- nullpo_ret(mes2);
- WFIFOHEAD(inter_fd,186);
- WFIFOW(inter_fd,0)=0x303e;
- WFIFOL(inter_fd,2)=guild_id;
- memcpy(WFIFOP(inter_fd,6),mes1,MAX_GUILDMES1);
- memcpy(WFIFOP(inter_fd,66),mes2,MAX_GUILDMES2);
- WFIFOSET(inter_fd,186);
- return 0;
- }
- // Request to change guild emblem
- int intif_guild_emblem(int guild_id,int len,const char *data)
- {
- if (intif->CheckForCharServer())
- return 0;
- if(guild_id<=0 || len<0 || len>2000)
- return 0;
- nullpo_ret(data);
- Assert_ret(len >= 0 && len < 32000);
- WFIFOHEAD(inter_fd,len + 12);
- WFIFOW(inter_fd,0)=0x303f;
- WFIFOW(inter_fd,2)=len+12;
- WFIFOL(inter_fd,4)=guild_id;
- WFIFOL(inter_fd,8)=0;
- memcpy(WFIFOP(inter_fd,12),data,len);
- WFIFOSET(inter_fd,len+12);
- return 0;
- }
- /**
- * Requests guild castles data from char-server.
- * @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)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(castle_ids);
- WFIFOHEAD(inter_fd, 4 + num * sizeof(int));
- WFIFOW(inter_fd, 0) = 0x3040;
- WFIFOW(inter_fd, 2) = 4 + num * sizeof(int);
- memcpy(WFIFOP(inter_fd, 4), castle_ids, num * sizeof(int));
- WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
- return 1;
- }
- // Request change castle guild owner and save data
- int intif_guild_castle_datasave(int castle_id,int index, int value)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,9);
- WFIFOW(inter_fd,0)=0x3041;
- WFIFOW(inter_fd,2)=castle_id;
- WFIFOB(inter_fd,4)=index;
- WFIFOL(inter_fd,5)=value;
- WFIFOSET(inter_fd,9);
- return 1;
- }
- //-----------------------------------------------------------------
- // Homunculus Packets send to Inter server [albator]
- //-----------------------------------------------------------------
- int intif_homunculus_create(int account_id, struct s_homunculus *sh)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(sh);
- WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
- WFIFOW(inter_fd,0) = 0x3090;
- WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
- WFIFOL(inter_fd,4) = account_id;
- memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- return 0;
- }
- bool intif_homunculus_requestload(int account_id, int homun_id) {
- if (intif->CheckForCharServer())
- return false;
- WFIFOHEAD(inter_fd, 10);
- WFIFOW(inter_fd,0) = 0x3091;
- WFIFOL(inter_fd,2) = account_id;
- WFIFOL(inter_fd,6) = homun_id;
- WFIFOSET(inter_fd, 10);
- return true;
- }
- int intif_homunculus_requestsave(int account_id, struct s_homunculus* sh)
- {
- if (intif->CheckForCharServer())
- return 0;
- nullpo_ret(sh);
- WFIFOHEAD(inter_fd, sizeof(struct s_homunculus)+8);
- WFIFOW(inter_fd,0) = 0x3092;
- WFIFOW(inter_fd,2) = sizeof(struct s_homunculus)+8;
- WFIFOL(inter_fd,4) = account_id;
- memcpy(WFIFOP(inter_fd,8),sh,sizeof(struct s_homunculus));
- WFIFOSET(inter_fd, WFIFOW(inter_fd,2));
- return 0;
- }
- int intif_homunculus_requestdelete(int homun_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd, 6);
- WFIFOW(inter_fd, 0) = 0x3093;
- WFIFOL(inter_fd,2) = homun_id;
- WFIFOSET(inter_fd,6);
- return 0;
- }
- //-----------------------------------------------------------------
- // Packets receive from inter server
- // Wisp/Page reception // rewritten by [Yor]
- void intif_parse_WisMessage(int fd) {
- struct map_session_data* sd;
- char *wisp_source;
- char name[NAME_LENGTH];
- int id, i;
- id=RFIFOL(fd,4);
- safestrncpy(name, (char*)RFIFOP(fd,32), NAME_LENGTH);
- sd = map->nick2sd(name);
- if(sd == NULL || strcmp(sd->status.name, name) != 0) {
- //Not found
- intif_wis_replay(id,1);
- return;
- }
- if(sd->state.ignoreAll) {
- intif_wis_replay(id, 2);
- return;
- }
- wisp_source = (char *) RFIFOP(fd,8); // speed up [Yor]
- for(i=0; i < MAX_IGNORE_LIST &&
- sd->ignore[i].name[0] != '\0' &&
- strcmp(sd->ignore[i].name, wisp_source) != 0
- ; i++);
- if (i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0') {
- //Ignored
- intif_wis_replay(id, 2);
- return;
- }
- //Success to send whisper.
- clif->wis_message(sd->fd, wisp_source, (char*)RFIFOP(fd,56),RFIFOW(fd,2)-56);
- intif_wis_replay(id,0); // success
- }
- // Wisp/page transmission result reception
- void intif_parse_WisEnd(int fd) {
- struct map_session_data* sd;
- if (battle_config.etc_log)
- ShowInfo("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd,2), RFIFOB(fd,26)); // flag: 0: success to send whisper, 1: target character is not logged in?, 2: ignored by target
- sd = map->nick2sd((char *)RFIFOP(fd,2));
- if (sd != NULL)
- clif->wis_end(sd->fd, RFIFOB(fd,26));
- return;
- }
- int mapif_parse_WisToGM_sub(struct map_session_data* sd,va_list va) {
- int permission = va_arg(va, int);
- char *wisp_name;
- char *message;
- int len;
- nullpo_ret(sd);
- if (!pc_has_permission(sd, permission))
- return 0;
- wisp_name = va_arg(va, char*);
- message = va_arg(va, char*);
- len = va_arg(va, int);
- clif->wis_message(sd->fd, wisp_name, message, len);
- return 1;
- }
- // Received wisp message from map-server via char-server for ALL gm
- // 0x3003/0x3803 <packet_len>.w <wispname>.24B <permission>.l <message>.?B
- void mapif_parse_WisToGM(int fd)
- {
- int permission, mes_len;
- char Wisp_name[NAME_LENGTH];
- char mbuf[255] = { 0 };
- char *message;
- mes_len = RFIFOW(fd,2) - 32;
- Assert_retv(mes_len > 0 && mes_len < 32000);
- message = (char *) (mes_len >= 255 ? (char *) aMalloc(mes_len) : mbuf);
- permission = RFIFOL(fd,28);
- safestrncpy(Wisp_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
- safestrncpy(message, (char*)RFIFOP(fd,32), mes_len);
- // information is sent to all online GM
- map->foreachpc(mapif_parse_WisToGM_sub, permission, Wisp_name, message, mes_len);
- if (message != mbuf)
- aFree(message);
- }
- // Request player registre
- void intif_parse_Registers(int fd)
- {
- int flag;
- struct map_session_data *sd;
- int account_id = RFIFOL(fd,4), char_id = RFIFOL(fd,8);
- struct auth_node *node = chrif->auth_check(account_id, char_id, ST_LOGIN);
- char type = RFIFOB(fd, 13);
- if (node)
- sd = node->sd;
- else { //Normally registries should arrive for in log-in chars.
- sd = map->id2sd(account_id);
- }
- if (!sd || sd->status.char_id != char_id) {
- return; //Character registry from another character.
- }
- flag = ( sd->vars_received&PRL_ACCG && sd->vars_received&PRL_ACCL && sd->vars_received&PRL_CHAR ) ? 0 : 1;
- switch (RFIFOB(fd,12)) {
- case 3: //Character Registry
- sd->vars_received |= PRL_CHAR;
- break;
- case 2: //Account Registry
- sd->vars_received |= PRL_ACCL;
- break;
- case 1: //Account2 Registry
- sd->vars_received |= PRL_ACCG;
- break;
- case 0:
- break;
- default:
- ShowError("intif_parse_Registers: Unrecognized type %d\n",RFIFOB(fd,12));
- return;
- }
- /* have it not complain about insertion of vars before loading, and not set those vars as new or modified */
- pc->reg_load = true;
- if (RFIFOW(fd, 14) != 0) {
- char key[SCRIPT_VARNAME_LENGTH+1];
- unsigned int index;
- int max = RFIFOW(fd, 14), cursor = 16, i;
- script->parser_current_file = "loading char/acc variables";//for script_add_str to refer to here in case errors occur
- /**
- * Vessel!char_reg_num_db
- *
- * str type
- * { keyLength(B), key(<keyLength>), index(L), valLength(B), val(<valLength>) }
- **/
- if (type) {
- char sval[254];
- for (i = 0; i < max; i++) {
- int len = RFIFOB(fd, cursor);
- safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), min((int)sizeof(key), len));
- cursor += len + 1;
- index = RFIFOL(fd, cursor);
- cursor += 4;
- len = RFIFOB(fd, cursor);
- safestrncpy(sval, (char*)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, (void*)sval, NULL);
- }
- /**
- * Vessel!
- *
- * int type
- * { keyLength(B), key(<keyLength>), index(L), value(L) }
- **/
- } else {
- for (i = 0; i < max; i++) {
- int ival;
- int len = RFIFOB(fd, cursor);
- safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), min((int)sizeof(key), len));
- cursor += len + 1;
- index = RFIFOL(fd, cursor);
- cursor += 4;
- ival = RFIFOL(fd, cursor);
- cursor += 4;
- script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (void*)h64BPTRSIZE(ival), NULL);
- }
- }
- script->parser_current_file = NULL;/* reset */
- }
- /* flag it back */
- pc->reg_load = false;
- if (flag && sd->vars_received&PRL_ACCG && sd->vars_received&PRL_ACCL && sd->vars_received&PRL_CHAR)
- pc->reg_received(sd); //Received all registry values, execute init scripts and what-not. [Skotlex]
- }
- void intif_parse_LoadGuildStorage(int fd)
- {
- struct guild_storage *gstor;
- struct map_session_data *sd;
- int guild_id, flag;
- guild_id = RFIFOL(fd,8);
- flag = RFIFOL(fd,12);
- if(guild_id <= 0)
- return;
- sd=map->id2sd( RFIFOL(fd,4) );
- if( flag ){ //If flag != 0, we attach a player and open the storage
- if(sd==NULL){
- ShowError("intif_parse_LoadGuildStorage: user not found %d\n",RFIFOL(fd,4));
- return;
- }
- }
- gstor=gstorage->ensure(guild_id);
- if(!gstor) {
- ShowWarning("intif_parse_LoadGuildStorage: error guild_id %d not exist\n",guild_id);
- return;
- }
- if (gstor->storage_status == 1) { // Already open.. lets ignore this update
- ShowWarning("intif_parse_LoadGuildStorage: storage received for a client already open (User %d:%d)\n", flag?sd->status.account_id:0, flag?sd->status.char_id:0);
- return;
- }
- if (gstor->dirty) { // Already have storage, and it has been modified and not saved yet! Exploit! [Skotlex]
- ShowWarning("intif_parse_LoadGuildStorage: received storage for an already modified non-saved storage! (User %d:%d)\n", flag?sd->status.account_id:0, flag?sd->status.char_id:0);
- return;
- }
- if (RFIFOW(fd,2)-13 != sizeof(struct guild_storage)) {
- ShowError("intif_parse_LoadGuildStorage: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd,2)-13, sizeof(struct guild_storage));
- gstor->storage_status = 0;
- return;
- }
- memcpy(gstor,RFIFOP(fd,13),sizeof(struct guild_storage));
- if( flag )
- gstorage->open(sd);
- }
- // ACK guild_storage saved
- void intif_parse_SaveGuildStorage(int fd)
- {
- gstorage->saved(/*RFIFOL(fd,2), */RFIFOL(fd,6));
- }
- // ACK party creation
- void intif_parse_PartyCreated(int fd)
- {
- if(battle_config.etc_log)
- ShowInfo("intif: party created by account %d\n\n", RFIFOL(fd,2));
- party->created(RFIFOL(fd,2), RFIFOL(fd,6),RFIFOB(fd,10),RFIFOL(fd,11), (char *)RFIFOP(fd,15));
- }
- // Receive party info
- void intif_parse_PartyInfo(int fd) {
- if (RFIFOW(fd,2) == 12) {
- ShowWarning("intif: party noinfo (char_id=%d party_id=%d)\n", RFIFOL(fd,4), RFIFOL(fd,8));
- party->recv_noinfo(RFIFOL(fd,8), RFIFOL(fd,4));
- return;
- }
- if (RFIFOW(fd,2) != 8+sizeof(struct party))
- ShowError("intif: party info: data size mismatch (char_id=%d party_id=%d packet_len=%d expected_len=%"PRIuS")\n",
- RFIFOL(fd,4), RFIFOL(fd,8), RFIFOW(fd,2), 8+sizeof(struct party));
- party->recv_info((struct party *)RFIFOP(fd,8), RFIFOL(fd,4));
- }
- // ACK adding party member
- void intif_parse_PartyMemberAdded(int fd)
- {
- if(battle_config.etc_log)
- ShowInfo("intif: party member added Party (%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
- party->member_added(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10), RFIFOB(fd, 14));
- }
- // ACK changing party option
- 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)
- {
- if(battle_config.etc_log)
- ShowInfo("intif: party member withdraw: Party(%d), Account(%d), Char(%d)\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
- party->member_withdraw(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
- }
- // ACK party break
- void intif_parse_PartyBroken(int fd) {
- party->broken(RFIFOL(fd,2));
- }
- // ACK party on new map
- 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) {
- party->recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
- }
- // ACK guild creation
- void intif_parse_GuildCreated(int fd) {
- guild->created(RFIFOL(fd,2),RFIFOL(fd,6));
- }
- // ACK guild infos
- void intif_parse_GuildInfo(int fd) {
- if (RFIFOW(fd,2) == 8) {
- ShowWarning("intif: guild noinfo %d\n",RFIFOL(fd,4));
- guild->recv_noinfo(RFIFOL(fd,4));
- return;
- }
- if (RFIFOW(fd,2)!=sizeof(struct guild)+4)
- ShowError("intif: guild info: data size mismatch - Gid: %d recv size: %d Expected size: %"PRIuS"\n",
- RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild)+4);
- guild->recv_info((struct guild *)RFIFOP(fd,4));
- }
- // ACK adding guild member
- void intif_parse_GuildMemberAdded(int fd) {
- if(battle_config.etc_log)
- ShowInfo("intif: guild member added %d %d %d %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) {
- guild->member_withdraw(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOB(fd,14),(char *)RFIFOP(fd,55),(char *)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));
- }
- // ACK guild break
- 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) {
- //int len = RFIFOW(fd,2) - 10;
- int guild_id = RFIFOL(fd,4);
- int type = RFIFOW(fd,8);
- //void* data = RFIFOP(fd,10);
- struct guild* g = guild->search(guild_id);
- if( g == NULL )
- return;
- switch(type) {
- case GBI_EXP: g->exp = RFIFOQ(fd,10); break;
- case GBI_GUILDLV: g->guild_lv = RFIFOW(fd,10); break;
- case GBI_SKILLPOINT: g->skill_point = RFIFOL(fd,10); break;
- case GBI_SKILLLV: {
- int idx, max;
- struct guild_skill *gs = (struct guild_skill *)RFIFOP(fd,10);
- idx = gs->id - GD_SKILLBASE;
- Assert_retv(idx >= 0 && idx < MAX_GUILDSKILL);
- max = guild->skill_get_max(gs->id);
- if( gs->lv > max )
- gs->lv = max;
- memcpy(&(g->skill[idx]), gs, sizeof(g->skill[idx]));
- break;
- }
- }
- }
- // 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) {
- //int len = RFIFOW(fd,2) - 18;
- int guild_id = RFIFOL(fd,4);
- int account_id = RFIFOL(fd,8);
- int char_id = RFIFOL(fd,12);
- int type = RFIFOW(fd,16);
- //void* data = RFIFOP(fd,18);
- struct guild* g;
- int idx;
- g = guild->search(guild_id);
- if( g == NULL )
- return;
- idx = guild->getindex(g,account_id,char_id);
- if( idx == -1 )
- return;
- switch( type ) {
- case GMI_POSITION: g->member[idx].position = RFIFOW(fd,18); guild->memberposition_changed(g,idx,RFIFOW(fd,18)); break;
- case GMI_EXP: g->member[idx].exp = RFIFOQ(fd,18); break;
- case GMI_HAIR: g->member[idx].hair = RFIFOW(fd,18); break;
- case GMI_HAIR_COLOR: g->member[idx].hair_color = RFIFOW(fd,18); break;
- case GMI_GENDER: g->member[idx].gender = RFIFOW(fd,18); break;
- case GMI_CLASS: g->member[idx].class_ = RFIFOW(fd,18); break;
- case GMI_LEVEL: g->member[idx].lv = RFIFOW(fd,18); break;
- }
- }
- // ACK change of guild title
- void intif_parse_GuildPosition(int fd) {
- if (RFIFOW(fd,2)!=sizeof(struct guild_position)+12)
- ShowError("intif: guild info: data size mismatch (%d) %d != %"PRIuS"\n",
- RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild_position)+12);
- guild->position_changed(RFIFOL(fd,4),RFIFOL(fd,8),(struct guild_position *)RFIFOP(fd,12));
- }
- // ACK change of guild skill update
- 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) {
- guild->allianceack(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),RFIFOL(fd,14),RFIFOB(fd,18),(char *) RFIFOP(fd,19),(char *) RFIFOP(fd,43));
- }
- // ACK change of guild notice
- void intif_parse_GuildNotice(int fd) {
- guild->notice_changed(RFIFOL(fd,2),(char *) RFIFOP(fd,6),(char *) RFIFOP(fd,66));
- }
- // ACK change of guild emblem
- void intif_parse_GuildEmblem(int fd) {
- guild->emblem_changed(RFIFOW(fd,2)-12,RFIFOL(fd,4),RFIFOL(fd,8), (char *)RFIFOP(fd,12));
- }
- // ACK guild message
- void intif_parse_GuildMessage(int fd) {
- guild->recv_message(RFIFOL(fd,4),RFIFOL(fd,8),(char *) RFIFOP(fd,12),RFIFOW(fd,2)-12);
- }
- // Reply guild castle data request
- void intif_parse_GuildCastleDataLoad(int fd) {
- guild->castledataloadack(RFIFOW(fd,2), (struct guild_castle *)RFIFOP(fd,4));
- }
- // ACK change of guildmaster
- 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) {
- pet->get_egg(RFIFOL(fd,2), RFIFOW(fd,6), RFIFOL(fd,8));
- }
- // ACK pet data
- void intif_parse_RecvPetData(int fd) {
- struct s_pet p;
- int len;
- len=RFIFOW(fd,2);
- if (sizeof(struct s_pet) != len-9) {
- if (battle_config.etc_log)
- ShowError("intif: pet data: data size mismatch %d != %"PRIuS"\n", len-9, sizeof(struct s_pet));
- } else {
- memcpy(&p,RFIFOP(fd,9),sizeof(struct s_pet));
- pet->recv_petdata(RFIFOL(fd,4),&p,RFIFOB(fd,8));
- }
- }
- /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
- // ACK pet save data
- 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) {
- if(RFIFOB(fd,2) == 1)
- ShowError("pet data delete failure\n");
- }
- // ACK changing name request, players,pets,homun
- void intif_parse_ChangeNameOk(int fd)
- {
- struct map_session_data *sd = NULL;
- if((sd=map->id2sd(RFIFOL(fd,2)))==NULL ||
- sd->status.char_id != RFIFOL(fd,6))
- return;
- switch (RFIFOB(fd,10)) {
- case 0: //Players [NOT SUPPORTED YET]
- break;
- case 1: //Pets
- pet->change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
- break;
- case 2: //Hom
- homun->change_name_ack(sd, (char*)RFIFOP(fd,12), RFIFOB(fd,11));
- break;
- }
- return;
- }
- //----------------------------------------------------------------
- // Homunculus recv packets [albator]
- void intif_parse_CreateHomunculus(int fd) {
- int len = RFIFOW(fd,2)-9;
- if (sizeof(struct s_homunculus) != len) {
- if (battle_config.etc_log)
- ShowError("intif: create homun data: data size mismatch %d != %"PRIuS"\n", len, sizeof(struct s_homunculus));
- return;
- }
- homun->recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8)) ;
- }
- void intif_parse_RecvHomunculusData(int fd) {
- int len = RFIFOW(fd,2)-9;
- if (sizeof(struct s_homunculus) != len) {
- if (battle_config.etc_log)
- ShowError("intif: homun data: data size mismatch %d != %"PRIuS"\n", len, sizeof(struct s_homunculus));
- return;
- }
- homun->recv_data(RFIFOL(fd,4), (struct s_homunculus*)RFIFOP(fd,9), RFIFOB(fd,8));
- }
- /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
- void intif_parse_SaveHomunculusOk(int fd) {
- if(RFIFOB(fd,6) != 1)
- ShowError("homunculus data save failure for account %d\n", RFIFOL(fd,2));
- }
- /* Really? Whats the point, shouldn't be sent when successful then [Ind] */
- void intif_parse_DeleteHomunculusOk(int fd) {
- if(RFIFOB(fd,2) != 1)
- ShowError("Homunculus data delete failure\n");
- }
- /**************************************
- 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)
- {
- nullpo_retv(sd);
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3060;
- WFIFOL(inter_fd,2) = sd->status.char_id;
- WFIFOSET(inter_fd,6);
- }
- /**
- * Parses the received quest log entries for a character from the inter server.
- *
- * Received in reply to the requests made by intif_request_questlog.
- *
- * @see intif_parse
- */
- 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);
- if (!sd) // User not online anymore
- return;
- sd->num_quests = sd->avail_quests = 0;
- if (num_received == 0) {
- if (sd->quest_log) {
- aFree(sd->quest_log);
- sd->quest_log = NULL;
- }
- } else {
- struct quest *received = (struct quest *)RFIFOP(fd, 8);
- int i, k = num_received;
- if (sd->quest_log) {
- RECREATE(sd->quest_log, struct quest, num_received);
- } else {
- CREATE(sd->quest_log, struct quest, num_received);
- }
- for (i = 0; i < num_received; i++) {
- if( quest->db(received[i].quest_id) == &quest->dummy ) {
- ShowError("intif_parse_QuestLog: quest %d not found in DB.\n", received[i].quest_id);
- continue;
- }
- if (received[i].state != Q_COMPLETE) {
- // Insert at the beginning
- memcpy(&sd->quest_log[sd->avail_quests++], &received[i], sizeof(struct quest));
- } else {
- // Insert at the end
- memcpy(&sd->quest_log[--k], &received[i], sizeof(struct quest));
- }
- sd->num_quests++;
- }
- if (sd->avail_quests < k) {
- // sd->avail_quests and k didn't meet in the middle: some entries were skipped
- if (k < num_received) // Move the entries at the end to fill the gap
- memmove(&sd->quest_log[k], &sd->quest_log[sd->avail_quests], sizeof(struct quest)*(num_received - k));
- sd->quest_log = aRealloc(sd->quest_log, sizeof(struct quest)*sd->num_quests);
- }
- }
- quest->pc_login(sd);
- }
- /**
- * Parses the quest log save ack for a character from the inter server.
- *
- * Received in reply to the requests made by intif_quest_save.
- *
- * @see intif_parse
- */
- void intif_parse_QuestSave(int fd) {
- int cid = RFIFOL(fd, 2);
- struct map_session_data *sd = map->id2sd(cid);
- if( !RFIFOB(fd, 6) )
- ShowError("intif_parse_QuestSave: Failed to save quest(s) for character %d!\n", cid);
- else if( sd )
- sd->save_quest = false;
- }
- /**
- * Requests to the inter server to save a character's quest log entries.
- *
- * @param sd Character's data
- * @return 0 in case of success, nonzero otherwise
- */
- int intif_quest_save(struct map_session_data *sd)
- {
- int len = sizeof(struct quest)*sd->num_quests + 8;
- if(intif->CheckForCharServer())
- return 1;
- WFIFOHEAD(inter_fd, len);
- WFIFOW(inter_fd,0) = 0x3061;
- WFIFOW(inter_fd,2) = len;
- WFIFOL(inter_fd,4) = sd->status.char_id;
- if( sd->num_quests )
- memcpy(WFIFOP(inter_fd,8), sd->quest_log, sizeof(struct quest)*sd->num_quests);
- WFIFOSET(inter_fd, len);
- return 0;
- }
- /*==========================================
- * MAIL SYSTEM
- * By Zephyrus
- *==========================================*/
- /*------------------------------------------
- * Inbox Request
- * flag: 0 Update Inbox | 1 OpenMail
- *------------------------------------------*/
- int intif_Mail_requestinbox(int char_id, unsigned char flag)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,7);
- WFIFOW(inter_fd,0) = 0x3048;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOB(inter_fd,6) = flag;
- WFIFOSET(inter_fd,7);
- return 0;
- }
- void intif_parse_MailInboxReceived(int fd) {
- struct map_session_data *sd;
- unsigned char flag = RFIFOB(fd,8);
- sd = map->charid2sd(RFIFOL(fd,4));
- if (sd == NULL) /** user is not online anymore and its ok (quest log also does this) **/
- return;
- if (RFIFOW(fd,2) - 9 != sizeof(struct mail_data)) {
- ShowError("intif_parse_MailInboxReceived: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd,2) - 9, sizeof(struct mail_data));
- return;
- }
- //FIXME: this operation is not safe [ultramage]
- memcpy(&sd->mail.inbox, RFIFOP(fd,9), sizeof(struct mail_data));
- sd->mail.changed = false; // cache is now in sync
- if (flag)
- clif->mail_refreshinbox(sd);
- else if( battle_config.mail_show_status && ( battle_config.mail_show_status == 1 || sd->mail.inbox.unread ) ) {
- char output[128];
- sprintf(output, msg_sd(sd,510), sd->mail.inbox.unchecked, sd->mail.inbox.unread + sd->mail.inbox.unchecked);
- clif_disp_onlyself(sd, output, strlen(output));
- }
- }
- /*------------------------------------------
- * Mail Read
- *------------------------------------------*/
- int intif_Mail_read(int mail_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,6);
- WFIFOW(inter_fd,0) = 0x3049;
- WFIFOL(inter_fd,2) = mail_id;
- WFIFOSET(inter_fd,6);
- return 0;
- }
- /*------------------------------------------
- * Get Attachment
- *------------------------------------------*/
- int intif_Mail_getattach(int char_id, int mail_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x304a;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOL(inter_fd,6) = mail_id;
- WFIFOSET(inter_fd, 10);
- return 0;
- }
- void intif_parse_MailGetAttach(int fd) {
- struct map_session_data *sd;
- struct item item;
- int zeny = RFIFOL(fd,8);
- Assert_retv(zeny >= 0);
- sd = map->charid2sd( RFIFOL(fd,4) );
- if (sd == NULL) {
- ShowError("intif_parse_MailGetAttach: char not found %d\n",RFIFOL(fd,4));
- return;
- }
- if (RFIFOW(fd,2) - 12 != sizeof(struct item)) {
- ShowError("intif_parse_MailGetAttach: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd,2) - 16, sizeof(struct item));
- return;
- }
- memcpy(&item, RFIFOP(fd,12), sizeof(struct item));
- mail->getattachment(sd, zeny, &item);
- }
- /*------------------------------------------
- * Delete Message
- *------------------------------------------*/
- int intif_Mail_delete(int char_id, int mail_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x304b;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOL(inter_fd,6) = mail_id;
- WFIFOSET(inter_fd,10);
- return 0;
- }
- void intif_parse_MailDelete(int fd) {
- struct map_session_data *sd;
- int char_id = RFIFOL(fd,2);
- int mail_id = RFIFOL(fd,6);
- bool failed = RFIFOB(fd,10);
- if ( (sd = map->charid2sd(char_id)) == NULL) {
- ShowError("intif_parse_MailDelete: char not found %d\n", char_id);
- return;
- }
- 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 Message
- *------------------------------------------*/
- int intif_Mail_return(int char_id, int mail_id)
- {
- if (intif->CheckForCharServer())
- return 0;
- WFIFOHEAD(inter_fd,10);
- WFIFOW(inter_fd,0) = 0x304c;
- WFIFOL(inter_fd,2) = char_id;
- WFIFOL(inter_fd,6) = mail_id;
- WFIFOSET(inter_fd,10);
- return 0;
- }
- 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);
- if( sd == NULL ) {
- ShowError("intif_parse_MailReturn: char not found %d\n",RFIFOL(fd,2));
- return;
- }
- 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--;
- }
- if( sd->mail.inbox.full )
- intif->Mail_requestinbox(sd->status.char_id, 1); // Free space is available for new mails
- }
- clif->mail_return(sd->fd, mail_id, fail);
- }
- /*---------------------------------------…
Large files files are truncated, but you can click here to view the full file