/** * Send map-servers fames ranking lists * Defaut fame list are 32B, (id+point+names) * S <len>.W <len bs + alchi>.W <len bs>.W <smith_rank>?B <alchi_rank>?B <taek_rank>?B * @param fd: fd to send packet too (map-serv) if -1 send to all * @return : 0 success */ int chmapif_send_fame_list(int fd){ int i, len = 8; unsigned char buf[32000]; WBUFW(buf,0) = 0x2b1b; for(i = 0; i < fame_list_size_smith && smith_fame_list[i].id; i++) { memcpy(WBUFP(buf, len), &smith_fame_list[i], sizeof(struct fame_list)); len += sizeof(struct fame_list); } // add blacksmith's block length WBUFW(buf, 6) = len; for(i = 0; i < fame_list_size_chemist && chemist_fame_list[i].id; i++) { memcpy(WBUFP(buf, len), &chemist_fame_list[i], sizeof(struct fame_list)); len += sizeof(struct fame_list); } // add alchemist's block length WBUFW(buf, 4) = len; for(i = 0; i < fame_list_size_taekwon && taekwon_fame_list[i].id; i++) { memcpy(WBUFP(buf, len), &taekwon_fame_list[i], sizeof(struct fame_list)); len += sizeof(struct fame_list); } // add total packet length WBUFW(buf, 2) = len; if (fd != -1) chmapif_send(fd, buf, len); else chmapif_sendall(buf, len); return 0; }
// ギルド告知変更通知 int mapif_guild_notice(struct guild *g) { unsigned char buf[186]; WBUFW(buf,0) = 0x383e; WBUFL(buf,2) = g->guild_id; memcpy(WBUFP(buf,6), g->mes1, 60); memcpy(WBUFP(buf,66), g->mes2, 120); mapif_sendall(buf, 186); return 0; }
// Wis sending int mapif_wis_message(struct WisData *wd) { unsigned char buf[2048]; if (wd->len > 2047-56) wd->len = 2047-56; //Force it to fit to avoid crashes. [Skotlex] WBUFW(buf, 0) = 0x3801; WBUFW(buf, 2) = 56 +wd->len; WBUFL(buf, 4) = wd->id; memcpy(WBUFP(buf, 8), wd->src, NAME_LENGTH); memcpy(WBUFP(buf,32), wd->dst, NAME_LENGTH); memcpy(WBUFP(buf,56), wd->msg, wd->len); wd->count = mapif_sendall(buf,WBUFW(buf,2)); return 0; }
/*========================================== * Report New Mail to Map Server *------------------------------------------*/ void mapif_Mail_new(struct mail_message *msg) { unsigned char buf[74]; if( !msg || !msg->id ) return; WBUFW(buf,0) = 0x3849; WBUFL(buf,2) = msg->dest_id; WBUFL(buf,6) = msg->id; memcpy(WBUFP(buf,10), msg->send_name, NAME_LENGTH); memcpy(WBUFP(buf,34), msg->title, MAIL_TITLE_LENGTH); mapif_sendall(buf, 74); }
// Wis送信 int mapif_wis_message(struct WisList *wl) { unsigned char buf[1024]; WBUFW(buf, 0)=0x3801; WBUFW(buf, 2)=6 + 48 +wl->len; WBUFW(buf, 4)=wl->id; memcpy(WBUFP(buf, 6),wl->src,24); memcpy(WBUFP(buf,30),wl->dst,24); memcpy(WBUFP(buf,54),wl->msg,wl->len); wl->count = mapif_sendall(buf,WBUFW(buf,2)); // printf("inter server wis: %d %d %ld\n", wl->id, wl->count, wl->tick); return 0; }
/** * This function is called when the map-serv initialise is chrif interface. * Map-serv sent us his map indexes so we can transfert a player from a map-serv to another when necessary * We reply by sending back the char_serv_wisp_name fame list and * @param fd: wich fd to parse from * @param id: wich map_serv id * @return : 0 not enough data received, 1 success */ int chmapif_parse_getmapname(int fd, int id){ int j = 0, i = 0; if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2)) return 0; //Retain what map-index that map-serv contains memset(map_server[id].map, 0, sizeof(map_server[id].map)); for(i = 4; i < RFIFOW(fd,2); i += 4) { map_server[id].map[j] = RFIFOW(fd,i); j++; } ShowStatus("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n", id, j, CONVIP(map_server[id].ip), map_server[id].port); ShowStatus("Map-server %d loading complete.\n", id); // send name for wisp to player WFIFOHEAD(fd, 3 + NAME_LENGTH); WFIFOW(fd,0) = 0x2afb; WFIFOB(fd,2) = 0; //0 succes, 1:failure memcpy(WFIFOP(fd,3), charserv_config.wisp_server_name, NAME_LENGTH); WFIFOSET(fd,3+NAME_LENGTH); chmapif_send_fame_list(fd); //Send fame list. { int x; if (j == 0) { ShowWarning("Map-server %d has NO maps.\n", id); } else { unsigned char buf[16384]; // Transmitting maps information to the other map-servers WBUFW(buf,0) = 0x2b04; WBUFW(buf,2) = j * 4 + 10; WBUFL(buf,4) = htonl(map_server[id].ip); WBUFW(buf,8) = htons(map_server[id].port); memcpy(WBUFP(buf,10), RFIFOP(fd,4), j * 4); chmapif_sendallwos(fd, buf, WBUFW(buf,2)); } // Transmitting the maps of the other map-servers to the new map-server for(x = 0; x < ARRAYLENGTH(map_server); x++) { if (map_server[x].fd > 0 && x != id) { WFIFOHEAD(fd,10 +4*ARRAYLENGTH(map_server[x].map)); WFIFOW(fd,0) = 0x2b04; WFIFOL(fd,4) = htonl(map_server[x].ip); WFIFOW(fd,8) = htons(map_server[x].port); j = 0; for(i = 0; i < ARRAYLENGTH(map_server[x].map); i++) if (map_server[x].map[i]) WFIFOW(fd,10+(j++)*4) = map_server[x].map[i]; if (j > 0) { WFIFOW(fd,2) = j * 4 + 10; WFIFOSET(fd,WFIFOW(fd,2)); } } } } RFIFOSKIP(fd,RFIFOW(fd,2)); return 1; }
// 脱退/追放通知 int mapif_guild_leaved(int guild_id, int account_id, int char_id, int flag, const char *name, const char *mes) { unsigned char buf[79]; WBUFW(buf, 0) = 0x3834; WBUFL(buf, 2) = guild_id; WBUFL(buf, 6) = account_id; WBUFL(buf,10) = char_id; WBUFB(buf,14) = flag; memcpy(WBUFP(buf,15), mes, 40); memcpy(WBUFP(buf,55), name, NAME_LENGTH); mapif_sendall(buf, 55+NAME_LENGTH); // mapif_sendall(buf, 79); ShowInfo("Character left guild (Guild %d, %d - %s: %s)\n", guild_id, account_id, name, mes); return 0; }
inline void WBUF_ZERO(uint8_t *p, size_t pos, size_t len) { uint8_t *b = static_cast<uint8_t *>(WBUFP(p, pos)); uint8_t *e = b + len; std::fill(b, e, '\0'); }
// Received wisp message from map-server for ALL gm (just copy the message and resends it to ALL map-servers) int mapif_parse_WisToGM (int fd) { unsigned char buf[2048]; // 0x3003/0x3803 <packet_len>.w <wispname>.24B <min_gm_level>.w <message>.?B memcpy (WBUFP (buf, 0), RFIFOP (fd, 0), RFIFOW (fd, 2)); WBUFW (buf, 0) = 0x3803; mapif_sendall (buf, RFIFOW (fd, 2)); return 0; }
inline void WBUF_STRING(uint8_t *p, size_t pos, XString s, size_t len) { char *const begin = static_cast<char *>(WBUFP(p, pos)); char *const end = begin + len; char *const mid = std::copy(s.begin(), s.end(), begin); std::fill(mid, end, '\0'); }
// Wis sending result int mapif_wis_end (struct WisData *wd, int flag) { unsigned char buf[27]; WBUFW (buf, 0) = 0x3802; memcpy (WBUFP (buf, 2), wd->src, 24); WBUFB (buf, 26) = flag; mapif_send (wd->fd, buf, 27); return 0; }
/** * Parse received item broadcast and sends it to all connected map-serves * ZI 3009 <cmd>.W <len>.W <nameid>.W <source>.W <type>.B <name>.24B <srcname>.24B * IZ 3809 <cmd>.W <len>.W <nameid>.W <source>.W <type>.B <name>.24B <srcname>.24B * @param fd * @return **/ int mapif_parse_broadcast_item(int fd) { unsigned char buf[9 + NAME_LENGTH*2]; memcpy(WBUFP(buf, 0), RFIFOP(fd, 0), RFIFOW(fd,2)); WBUFW(buf, 0) = 0x3809; chmapif_sendallwos(fd, buf, RFIFOW(fd,2)); return 0; }
// ギルド同盟/敵対通知 int mapif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int account_id2, int flag, const char *name1, const char *name2) { unsigned char buf[67]; WBUFW(buf, 0) = 0x383d; WBUFL(buf, 2) = guild_id1; WBUFL(buf, 6) = guild_id2; WBUFL(buf,10) = account_id1; WBUFL(buf,14) = account_id2; WBUFB(buf,18) = flag; memcpy(WBUFP(buf,19), name1, NAME_LENGTH); memcpy(WBUFP(buf,19+NAME_LENGTH), name2, NAME_LENGTH); mapif_sendall(buf,19+2*NAME_LENGTH); /* memcpy(WBUFP(buf,43), name2, NAME_LENGTH); mapif_sendall(buf, 67); */ return 0; }
// GMメッセージ送信 int mapif_GMmessage(unsigned char *mes,int len) { unsigned char buf[len]; WBUFW(buf,0)=0x3800; WBUFW(buf,2)=len; memcpy(WBUFP(buf,4),mes,len-4); mapif_sendall(buf,len); // printf("inter server: GM:%d %s\n",len,mes); return 0; }
int mapif_account_reg(int fd,unsigned char *src) { // unsigned char buf[WBUFW(src,2)]; <- Hey, can this really be done? [Skotlex] unsigned char *buf = aCalloc(1,WBUFW(src,2)); // [Lance] - Skot... Dynamic allocation is better :D memcpy(WBUFP(buf,0),src,WBUFW(src,2)); WBUFW(buf, 0)=0x3804; mapif_sendallwos(fd, buf, WBUFW(buf,2)); aFree(buf); return 0; }
// Wis送信結果 int mapif_wis_end(struct WisList *wl,int flag) { unsigned char buf[32]; WBUFW(buf, 0)=0x3802; memcpy(WBUFP(buf, 2),wl->src,24); WBUFB(buf,26)=flag; mapif_send(wl->fd,buf,27); // printf("inter server wis_end %d\n",flag); return 0; }
// ギルド基本情報変更通知 int mapif_guild_basicinfochanged(int guild_id, int type, const void *data, int len) { unsigned char buf[2048]; WBUFW(buf,0) = 0x3839; WBUFW(buf,2) = len+10; WBUFL(buf,4) = guild_id; WBUFW(buf,8) = type; memcpy(WBUFP(buf,10),data,len); mapif_sendall(buf,len+10); return 0; }
// パーティ内発言 int mapif_party_message(int party_id,int account_id,char *mes,int len, int sfd) { unsigned char buf[512]; WBUFW(buf,0)=0x3827; WBUFW(buf,2)=len+12; WBUFL(buf,4)=party_id; WBUFL(buf,8)=account_id; memcpy(WBUFP(buf,12),mes,len); mapif_sendallwos(sfd, buf,len+12); return 0; }
// パーティ脱退通知 int mapif_party_leaved(int party_id,int account_id,char *name) { unsigned char buf[64]; WBUFW(buf,0)=0x3824; WBUFL(buf,2)=party_id; WBUFL(buf,6)=account_id; memcpy(WBUFP(buf,10),name,24); mapif_sendall(buf,34); printf("int_party: party leaved %d %d %s\n",party_id,account_id,name); return 0; }
/** * Send some misc info to new map-server. * - Server name for whisper name * - Default map * HZ 0x2afb <size>.W <status>.B <name>.24B <mapname>.11B <map_x>.W <map_y>.W * @param fd **/ static void chmapif_send_misc(int fd) { uint16 offs = 5; unsigned char buf[45]; memset(buf, '\0', sizeof(buf)); WBUFW(buf, 0) = 0x2afb; // 0 succes, 1:failure WBUFB(buf, 4) = 0; // Send name for wisp to player memcpy(WBUFP(buf, 5), charserv_config.wisp_server_name, NAME_LENGTH); // Default map memcpy(WBUFP(buf, (offs+=NAME_LENGTH)), charserv_config.default_map, MAP_NAME_LENGTH); // 29 WBUFW(buf, (offs+=MAP_NAME_LENGTH)) = charserv_config.default_map_x; // 41 WBUFW(buf, (offs+=2)) = charserv_config.default_map_y; // 43 offs+=2; // Length WBUFW(buf, 2) = offs; chmapif_send(fd, buf, offs); }
// GM message sending int mapif_GMmessage(unsigned char *mes, int len, unsigned long color, int sfd) { unsigned char buf[2048]; if (len > 2048) len = 2047; //Make it fit to avoid crashes. [Skotlex] WBUFW(buf, 0) = 0x3800; WBUFW(buf, 2) = len; WBUFL(buf, 4) = color; memcpy(WBUFP(buf, 8), mes, len-8); mapif_sendallwos(sfd, buf, len); return 0; }
// パ?ティ情報まとめ送り static void mapif_party_info(int fd, struct party* p, int char_id) { unsigned char buf[8 + sizeof(struct party)]; WBUFW(buf,0) = 0x3821; WBUFW(buf,2) = 8 + sizeof(struct party); WBUFL(buf,4) = char_id; memcpy(WBUFP(buf,8), p, sizeof(struct party)); if (fd < 0) mapif_sendall(buf, WBUFW(buf,2)); else mapif_send(fd, buf, WBUFW(buf,2)); }
// ギルド内発言 int mapif_guild_message(int guild_id, int account_id, char *mes, int len, int sfd) { unsigned char buf[2048]; WBUFW(buf,0) = 0x3837; WBUFW(buf,2) = len + 12; WBUFL(buf,4) = guild_id; WBUFL(buf,8) = account_id; memcpy(WBUFP(buf,12), mes, len); mapif_sendallwos(sfd, buf, len + 12); return 0; }
// パーティ内発言 int mapif_party_message(int party_id,int account_id,const char *mes,size_t len) { unsigned char buf[512]; WBUFW(buf,0)=0x3827; WBUFW(buf,2)=(unsigned short)(len+12); WBUFL(buf,4)=party_id; WBUFL(buf,8)=account_id; memcpy(WBUFP(buf,12),mes,len); mapif_sendall(buf,len+12); return 0; }
// パーティマップ更新通知 int mapif_party_membermoved(struct party *p,int idx) { unsigned char buf[32]; WBUFW(buf,0)=0x3825; WBUFL(buf,2)=p->party_id; WBUFL(buf,6)=p->member[idx].account_id; memcpy(WBUFP(buf,10),p->member[idx].map,16); WBUFB(buf,26)=p->member[idx].online; WBUFW(buf,27)=p->member[idx].lv; mapif_sendall(buf,29); return 0; }
// GM message sending int mapif_GMmessage(unsigned char *mes, int len, unsigned long color, int sfd) { unsigned char buf[2048]; if (len > 2048) len = 2047; //Make it fit to avoid crashes. [Skotlex] WBUFW(buf, 0) = 0x3800; WBUFW(buf, 2) = len; WBUFL(buf, 4) = color; memcpy(WBUFP(buf, 8), mes, len-8); mapif_sendallwos(sfd, buf, len); // ShowNotice("\033[1;34m inter server: GM[len:%d] - '%s' \033[0m\n", len, mes); return 0; }
// ギルド役職変更通知 int mapif_guild_position(struct guild *g, int idx) { unsigned char buf[2048]; WBUFW(buf,0) = 0x383b; WBUFW(buf,2) = sizeof(struct guild_position) + 12; WBUFL(buf,4) = g->guild_id; WBUFL(buf,8) = idx; memcpy(WBUFP(buf,12), &g->position[idx], sizeof(struct guild_position)); mapif_sendall(buf, WBUFW(buf,2)); return 0; }
// ギルドエンブレム変更通知 int mapif_guild_emblem(struct guild *g) { unsigned char buf[2048]; WBUFW(buf,0) = 0x383f; WBUFW(buf,2) = g->emblem_len + 12; WBUFL(buf,4) = g->guild_id; WBUFL(buf,8) = g->emblem_id; memcpy(WBUFP(buf,12), g->emblem_data, g->emblem_len); mapif_sendall(buf, WBUFW(buf,2)); return 0; }
//Withdrawal notification party int mapif_party_withdraw(int party_id, uint32 account_id, uint32 char_id, char *name, enum e_party_member_withdraw type) { unsigned char buf[15+NAME_LENGTH]; WBUFW(buf,0) = 0x3824; WBUFL(buf,2) = party_id; WBUFL(buf,6) = account_id; WBUFL(buf,10) = char_id; memcpy(WBUFP(buf,14), name, NAME_LENGTH); WBUFB(buf,14+NAME_LENGTH) = type; chmapif_sendall(buf,15+NAME_LENGTH); return 0; }
// ギルドメンバ情報変更通知 int mapif_guild_memberinfochanged(int guild_id, int account_id, int char_id, int type, const void *data, int len) { unsigned char buf[4096]; WBUFW(buf, 0) = 0x383a; WBUFW(buf, 2) = len + 18; WBUFL(buf, 4) = guild_id; WBUFL(buf, 8) = account_id; WBUFL(buf,12) = char_id; WBUFW(buf,16) = type; memcpy(WBUFP(buf,18), data, len); mapif_sendall(buf,len+18); return 0; }