From 83db3bbee4e19e7426a32ee89ad6c2d8e48260f2 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Tue, 18 Jun 2013 20:03:57 -0700 Subject: Also poison memcpy, memmove, and memset --- src/map/intif.cpp | 202 +++++++++++++++++++++++------------------------------- 1 file changed, 86 insertions(+), 116 deletions(-) (limited to 'src/map/intif.cpp') diff --git a/src/map/intif.cpp b/src/map/intif.cpp index 1010047..9e9d2e1 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -18,7 +18,8 @@ #include "../poison.hpp" static -const int packet_len_table[] = { +const int packet_len_table[] = +{ -1, -1, 27, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 7, 0, 0, 0, 0, 0, 0, -1, 11, 0, 0, 0, 0, 0, 0, 35, -1, 11, 15, 34, 29, 7, -1, 0, 0, 0, 0, 0, 0, 0, 0, @@ -35,40 +36,36 @@ const int packet_len_table[] = { // inter serverへの送信 // Message for all GMs on all map servers -void intif_GMmessage(const_string mes, int flag) +void intif_GMmessage(const_string mes) { - int lp = (flag & 0x10) ? 8 : 4; WFIFOW(char_fd, 0) = 0x3000; - WFIFOW(char_fd, 2) = lp + mes.size() + 1; - WFIFOL(char_fd, 4) = 0x65756c62; - memcpy(WFIFOP(char_fd, lp), mes.data(), mes.size()); - WFIFOB(char_fd, lp + mes.size()) = '\0'; + size_t len = mes.size() + 1; + WFIFOW(char_fd, 2) = 4 + len; + WFIFO_STRING(char_fd, 4, mes.data(), len); WFIFOSET(char_fd, WFIFOW(char_fd, 2)); } // The transmission of Wisp/Page to inter-server (player not found on this server) -int intif_wis_message(dumb_ptr sd, const char *nick, const char *mes, - int mes_len) +void intif_wis_message(dumb_ptr sd, const char *nick, const char *mes) { - nullpo_ret(sd); + nullpo_retv(sd); + size_t mes_len = strlen(mes) + 1; WFIFOW(char_fd, 0) = 0x3001; WFIFOW(char_fd, 2) = mes_len + 52; - memcpy(WFIFOP(char_fd, 4), sd->status.name, 24); - memcpy(WFIFOP(char_fd, 28), nick, 24); - memcpy(WFIFOP(char_fd, 52), mes, mes_len); + WFIFO_STRING(char_fd, 4, sd->status.name, 24); + WFIFO_STRING(char_fd, 28, nick, 24); + WFIFO_STRING(char_fd, 52, mes, mes_len); WFIFOSET(char_fd, WFIFOW(char_fd, 2)); if (battle_config.etc_log) PRINTF("intif_wis_message from %s to %s (message: '%s')\n", sd->status.name, nick, mes); - - return 0; } // The reply of Wisp/page static -int intif_wis_replay(int id, int flag) +void intif_wis_replay(int id, int flag) { WFIFOW(char_fd, 0) = 0x3002; WFIFOL(char_fd, 2) = id; @@ -77,129 +74,112 @@ int intif_wis_replay(int id, int flag) if (battle_config.etc_log) PRINTF("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(const char *Wisp_name, int min_gm_level, const char *mes, - int mes_len) +void intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char *mes) { + size_t mes_len = strlen(mes) + 1; WFIFOW(char_fd, 0) = 0x3003; WFIFOW(char_fd, 2) = mes_len + 30; - memcpy(WFIFOP(char_fd, 4), Wisp_name, 24); + WFIFO_STRING(char_fd, 4, Wisp_name, 24); WFIFOW(char_fd, 28) = min_gm_level; - memcpy(WFIFOP(char_fd, 30), mes, mes_len); + WFIFO_STRING(char_fd, 30, mes, mes_len); WFIFOSET(char_fd, WFIFOW(char_fd, 2)); if (battle_config.etc_log) PRINTF("intif_wis_message_to_gm: from: '%s', min level: %d, message: '%s'.\n", Wisp_name, min_gm_level, mes); - - return 0; } // アカウント変数送信 -int intif_saveaccountreg(dumb_ptr sd) +void intif_saveaccountreg(dumb_ptr sd) { int j, p; - nullpo_ret(sd); + nullpo_retv(sd); WFIFOW(char_fd, 0) = 0x3004; WFIFOL(char_fd, 4) = sd->bl_id; for (j = 0, p = 8; j < sd->status.account_reg_num; j++, p += 36) { - memcpy(WFIFOP(char_fd, p), sd->status.account_reg[j].str, 32); + WFIFO_STRING(char_fd, p, sd->status.account_reg[j].str, 32); WFIFOL(char_fd, p + 32) = sd->status.account_reg[j].value; } WFIFOW(char_fd, 2) = p; WFIFOSET(char_fd, p); - return 0; } // アカウント変数要求 -int intif_request_accountreg(dumb_ptr sd) +void intif_request_accountreg(dumb_ptr sd) { - nullpo_ret(sd); + nullpo_retv(sd); WFIFOW(char_fd, 0) = 0x3005; WFIFOL(char_fd, 2) = sd->bl_id; WFIFOSET(char_fd, 6); - return 0; } // 倉庫データ要求 -int intif_request_storage(int account_id) +void intif_request_storage(int account_id) { WFIFOW(char_fd, 0) = 0x3010; WFIFOL(char_fd, 2) = account_id; WFIFOSET(char_fd, 6); - return 0; } // 倉庫データ送信 -int intif_send_storage(struct storage *stor) +void intif_send_storage(struct storage *stor) { - nullpo_ret(stor); + nullpo_retv(stor); WFIFOW(char_fd, 0) = 0x3011; WFIFOW(char_fd, 2) = sizeof(struct storage) + 8; WFIFOL(char_fd, 4) = stor->account_id; - memcpy(WFIFOP(char_fd, 8), stor, sizeof(struct storage)); + WFIFO_STRUCT(char_fd, 8, *stor); WFIFOSET(char_fd, WFIFOW(char_fd, 2)); - return 0; } // パーティ作成要求 -int intif_create_party(dumb_ptr sd, const char *name) +void intif_create_party(dumb_ptr sd, const char *name) { - nullpo_ret(sd); + nullpo_retv(sd); WFIFOW(char_fd, 0) = 0x3020; WFIFOL(char_fd, 2) = sd->status.account_id; - memcpy(WFIFOP(char_fd, 6), name, 24); - memcpy(WFIFOP(char_fd, 30), sd->status.name, 24); - memcpy(WFIFOP(char_fd, 54), sd->bl_m->name, 16); + WFIFO_STRING(char_fd, 6, name, 24); + WFIFO_STRING(char_fd, 30, sd->status.name, 24); + WFIFO_STRING(char_fd, 54, sd->bl_m->name_, 16); WFIFOW(char_fd, 70) = sd->status.base_level; WFIFOSET(char_fd, 72); -// if(battle_config.etc_log) -// PRINTF("intif: create party\n"); - return 0; } // パーティ情報要求 -int intif_request_partyinfo(int party_id) +void intif_request_partyinfo(int party_id) { WFIFOW(char_fd, 0) = 0x3021; WFIFOL(char_fd, 2) = party_id; WFIFOSET(char_fd, 6); -// if(battle_config.etc_log) -// PRINTF("intif: request party info\n"); - return 0; } // パーティ追加要求 -int intif_party_addmember(int party_id, int account_id) +void intif_party_addmember(int party_id, int account_id) { dumb_ptr sd; sd = map_id2sd(account_id); -// if(battle_config.etc_log) -// PRINTF("intif: party add member %d %d\n",party_id,account_id); if (sd != NULL) { WFIFOW(char_fd, 0) = 0x3022; WFIFOL(char_fd, 2) = party_id; WFIFOL(char_fd, 6) = account_id; - memcpy(WFIFOP(char_fd, 10), sd->status.name, 24); - memcpy(WFIFOP(char_fd, 34), sd->bl_m->name, 16); + WFIFO_STRING(char_fd, 10, sd->status.name, 24); + WFIFO_STRING(char_fd, 34, sd->bl_m->name_, 16); WFIFOW(char_fd, 50) = sd->status.base_level; WFIFOSET(char_fd, 52); } - return 0; } // パーティ設定変更 -int intif_party_changeoption(int party_id, int account_id, int exp, int item) +void intif_party_changeoption(int party_id, int account_id, int exp, int item) { WFIFOW(char_fd, 0) = 0x3023; WFIFOL(char_fd, 2) = party_id; @@ -207,62 +187,52 @@ int intif_party_changeoption(int party_id, int account_id, int exp, int item) WFIFOW(char_fd, 10) = exp; WFIFOW(char_fd, 12) = item; WFIFOSET(char_fd, 14); - return 0; } // パーティ脱退要求 -int intif_party_leave(int party_id, int account_id) +void intif_party_leave(int party_id, int account_id) { -// if(battle_config.etc_log) -// PRINTF("intif: party leave %d %d\n",party_id,account_id); WFIFOW(char_fd, 0) = 0x3024; WFIFOL(char_fd, 2) = party_id; WFIFOL(char_fd, 6) = account_id; WFIFOSET(char_fd, 10); - return 0; } // パーティ移動要求 -int intif_party_changemap(dumb_ptr sd, int online) +void intif_party_changemap(dumb_ptr sd, int online) { if (sd != NULL) { WFIFOW(char_fd, 0) = 0x3025; WFIFOL(char_fd, 2) = sd->status.party_id; WFIFOL(char_fd, 6) = sd->status.account_id; - memcpy(WFIFOP(char_fd, 10), sd->bl_m->name, 16); + WFIFO_STRING(char_fd, 10, sd->bl_m->name_, 16); WFIFOB(char_fd, 26) = online; WFIFOW(char_fd, 27) = sd->status.base_level; WFIFOSET(char_fd, 29); } -// if(battle_config.etc_log) -// PRINTF("party: change map\n"); - return 0; } // パーティ会話送信 -int intif_party_message(int party_id, int account_id, const char *mes, int len) +void intif_party_message(int party_id, int account_id, const char *mes) { -// if(battle_config.etc_log) -// PRINTF("intif_party_message: %s\n",mes); + size_t len = strlen(mes) + 1; WFIFOW(char_fd, 0) = 0x3027; WFIFOW(char_fd, 2) = len + 12; WFIFOL(char_fd, 4) = party_id; WFIFOL(char_fd, 8) = account_id; - memcpy(WFIFOP(char_fd, 12), mes, len); + WFIFO_STRING(char_fd, 12, mes, len); WFIFOSET(char_fd, len + 12); - return 0; } // パーティ競合チェック要求 -int intif_party_checkconflict(int party_id, int account_id, const char *nick) +void intif_party_checkconflict(int party_id, int account_id, const char *nick) { WFIFOW(char_fd, 0) = 0x3028; WFIFOL(char_fd, 2) = party_id; WFIFOL(char_fd, 6) = account_id; - memcpy(WFIFOP(char_fd, 10), nick, 24); + WFIFO_STRING(char_fd, 10, nick, 24); WFIFOSET(char_fd, 34); - return 0; } //----------------------------------------------------------------- @@ -271,24 +241,36 @@ int intif_party_checkconflict(int party_id, int account_id, const char *nick) // Wisp/Page reception static int intif_parse_WisMessage(int fd) -{ // rewritten by [Yor] +{ + // rewritten by [Yor] dumb_ptr sd; + char from[24]; + RFIFO_STRING(fd, 8, from, 24); + char to[24]; + RFIFO_STRING(fd, 32, to, 24); + + size_t len = RFIFOW(fd, 2) - 56; + char buf[len]; + RFIFO_STRING(fd, 56, buf, len); + if (battle_config.etc_log) + { + const char *mes = buf; PRINTF("intif_parse_wismessage: id: %d, from: %s, to: %s, message: '%s'\n", RFIFOL(fd, 4), - static_cast(RFIFOP(fd, 8)), - static_cast(RFIFOP(fd, 32)), - static_cast(RFIFOP(fd, 56))); - sd = map_nick2sd(static_cast(RFIFOP(fd, 32))); // Searching destination player - if (sd != NULL && strcmp(sd->status.name, static_cast(RFIFOP(fd, 32))) == 0) + from, + to, + mes); + } + sd = map_nick2sd(to); // Searching destination player + if (sd != NULL && strcmp(sd->status.name, to) == 0) { // exactly same name (inter-server have checked the name before) { // if source player not found in ignore list { - clif_wis_message(sd->fd, static_cast(RFIFOP(fd, 8)), static_cast(RFIFOP(fd, 56)), - RFIFOW(fd, 2) - 56); + clif_wis_message(sd->fd, from, buf); intif_wis_replay(RFIFOL(fd, 4), 0); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target } } @@ -317,23 +299,21 @@ int intif_parse_WisEnd(int fd) // Received wisp message from map-server via char-server for ALL gm static -int mapif_parse_WisToGM(int fd) +void mapif_parse_WisToGM(int fd) { // 0x3003/0x3803 .w .24B .w .?B int min_gm_level, len; char Wisp_name[24]; if (RFIFOW(fd, 2) - 30 <= 0) - return 0; + return; len = RFIFOW(fd, 2) - 30; - char message[len + 1]; + char message[len]; min_gm_level = RFIFOW(fd, 28); - memcpy(Wisp_name, RFIFOP(fd, 4), 24); - Wisp_name[23] = '\0'; - memcpy(message, RFIFOP(fd, 30), len); - message[len] = '\0'; + RFIFO_STRING(fd, 4, Wisp_name, 24); + RFIFO_STRING(fd, 30, message, len); // information is sended to all online GM for (int i = 0; i < fd_max; i++) { @@ -342,11 +322,8 @@ int mapif_parse_WisToGM(int fd) dumb_ptr pl_sd = dumb_ptr(static_cast(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) if (pc_isGM(pl_sd) >= min_gm_level) - clif_wis_message(i, Wisp_name, message, - strlen(message) + 1); + clif_wis_message(i, Wisp_name, message); } - - return 0; } // アカウント変数通知 @@ -361,7 +338,7 @@ int intif_parse_AccountReg(int fd) for (p = 8, j = 0; p < RFIFOW(fd, 2) && j < ACCOUNT_REG_NUM; p += 36, j++) { - memcpy(sd->status.account_reg[j].str, RFIFOP(fd, p), 32); + RFIFO_STRING(fd, p, sd->status.account_reg[j].str, 32); sd->status.account_reg[j].value = RFIFOL(fd, p + 32); } sd->status.account_reg_num = j; @@ -410,7 +387,7 @@ int intif_parse_LoadStorage(int fd) } if (battle_config.save_log) PRINTF("intif_openstorage: %d\n", RFIFOL(fd, 4)); - memcpy(stor, RFIFOP(fd, 8), sizeof(struct storage)); + RFIFO_STRUCT(fd, 8, *stor); stor->dirty = 0; stor->storage_status = 1; sd->state.storage_open = 1; @@ -423,36 +400,34 @@ int intif_parse_LoadStorage(int fd) // 倉庫データ送信成功 static -int intif_parse_SaveStorage(int fd) +void intif_parse_SaveStorage(int fd) { if (battle_config.save_log) PRINTF("intif_savestorage: done %d %d\n", RFIFOL(fd, 2), RFIFOB(fd, 6)); storage_storage_saved(RFIFOL(fd, 2)); - return 0; } // パーティ作成可否 static -int intif_parse_PartyCreated(int fd) +void intif_parse_PartyCreated(int fd) { if (battle_config.etc_log) PRINTF("intif: party created\n"); party_created(RFIFOL(fd, 2), RFIFOB(fd, 6), RFIFOL(fd, 7), static_cast(RFIFOP(fd, 11))); - return 0; } // パーティ情報 static -int intif_parse_PartyInfo(int fd) +void intif_parse_PartyInfo(int fd) { if (RFIFOW(fd, 2) == 8) { if (battle_config.error_log) PRINTF("intif: party noinfo %d\n", RFIFOL(fd, 4)); party_recv_noinfo(RFIFOL(fd, 4)); - return 0; + return; } // PRINTF("intif: party info %d\n",RFIFOL(fd,4)); @@ -464,68 +439,63 @@ int intif_parse_PartyInfo(int fd) sizeof(struct party) + 4); } party_recv_info(static_cast(RFIFOP(fd, 4))); - return 0; } // パーティ追加通知 static -int intif_parse_PartyMemberAdded(int fd) +void intif_parse_PartyMemberAdded(int fd) { if (battle_config.etc_log) PRINTF("intif: party member added %d %d %d\n", RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10)); party_member_added(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOB(fd, 10)); - return 0; } // パーティ設定変更通知 static -int intif_parse_PartyOptionChanged(int fd) +void intif_parse_PartyOptionChanged(int fd) { party_optionchanged(RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOW(fd, 10), RFIFOW(fd, 12), RFIFOB(fd, 14)); - return 0; } // パーティ脱退通知 static -int intif_parse_PartyMemberLeaved(int fd) +void intif_parse_PartyMemberLeaved(int fd) { if (battle_config.etc_log) PRINTF("intif: party member leaved %d %d %s\n", RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast(RFIFOP(fd, 10))); party_member_leaved(RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast(RFIFOP(fd, 10))); - return 0; } // パーティ解散通知 static -int intif_parse_PartyBroken(int fd) +void intif_parse_PartyBroken(int fd) { party_broken(RFIFOL(fd, 2)); - return 0; } // パーティ移動通知 static -int intif_parse_PartyMove(int fd) +void intif_parse_PartyMove(int fd) { // if(battle_config.etc_log) // PRINTF("intif: party move %d %d %s %d %d\n",RFIFOL(fd,2),RFIFOL(fd,6),RFIFOP(fd,10),RFIFOB(fd,26),RFIFOW(fd,27)); party_recv_movemap(RFIFOL(fd, 2), RFIFOL(fd, 6), static_cast(RFIFOP(fd, 10)), RFIFOB(fd, 26), RFIFOW(fd, 27)); - return 0; } // パーティメッセージ static -int intif_parse_PartyMessage(int fd) +void intif_parse_PartyMessage(int fd) { // if(battle_config.etc_log) // PRINTF("intif_parse_PartyMessage: %s\n",RFIFOP(fd,12)); - party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), static_cast(RFIFOP(fd, 12)), - RFIFOW(fd, 2) - 12); - return 0; + size_t len = RFIFOW(fd, 2) - 12; + char buf[len]; + RFIFO_STRING(fd, 12, buf, len); + party_recv_message(RFIFOL(fd, 4), RFIFOL(fd, 8), buf); } //----------------------------------------------------------------- -- cgit v1.2.3-60-g2f50