From 0ca24c219b8a5a7cd4beb15d8384380f7e6fa9b5 Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 25 Aug 2019 17:44:10 +0200 Subject: Remove round-trip to the inter-server for the whisper-to-gm messages Signed-off-by: Haru --- src/char/inter.c | 3 +-- src/char/mapif.c | 13 ---------- src/char/mapif.h | 1 - src/map/atcommand.c | 2 +- src/map/clif.c | 4 +-- src/map/intif.c | 71 +---------------------------------------------------- src/map/intif.h | 3 --- src/map/pc.c | 50 +++++++++++++++++++++++++++++++++++++ src/map/pc.h | 2 ++ src/map/trade.c | 6 ++--- 10 files changed, 60 insertions(+), 95 deletions(-) diff --git a/src/char/inter.c b/src/char/inter.c index 53bcd6de1..4f49dab7d 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -67,7 +67,7 @@ int party_share_level = 10; // recv. packet list static int inter_recv_packet_length[] = { - -1, 0, 0,-1, -1,13,36, (2 + 4 + 4 + 4 + NAME_LENGTH), 0, 0, 0, 0, 0, 0, 0, 0, // 3000- + -1, 0, 0, 0, -1,13,36, (2 + 4 + 4 + 4 + NAME_LENGTH), 0, 0, 0, 0, 0, 0, 0, 0, // 3000- 6,-1, 6,-1, 0, 0, 0, 0, 10,-1, 0, 0, 0, 0, 0, 0, // 3010- Account Storage, Achievements [Smokexyz] -1,10,-1,14, 14,19, 6,-1, 14,14, 0, 0, 0, 0, 0, 0, // 3020- Party -1, 6,-1,-1, 55,23, 6,-1, 14,-1,-1,-1, 18,19,186,-1, // 3030- @@ -1036,7 +1036,6 @@ static int inter_parse_frommap(int fd) switch(cmd) { case 0x3000: mapif->parse_broadcast(fd); break; - case 0x3003: mapif->parse_WisToGM(fd); break; case 0x3004: mapif->parse_Registry(fd); break; case 0x3005: mapif->parse_RegistryRequest(fd); break; case 0x3006: mapif->parse_NameChangeRequest(fd); break; diff --git a/src/char/mapif.c b/src/char/mapif.c index 89cd358ec..7e29727c7 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -2093,18 +2093,6 @@ static int mapif_parse_broadcast(int fd) return 0; } -// Received wisp message from map-server for ALL gm (just copy the message and resends it to ALL map-servers) -static int mapif_parse_WisToGM(int fd) -{ - unsigned char buf[2048]; // 0x3003/0x3803 .w .24B .w .?B - - memcpy(WBUFP(buf,0), RFIFOP(fd,0), RFIFOW(fd,2)); // Message contains the NUL terminator (see intif_wis_message_to_gm()) - WBUFW(buf, 0) = 0x3803; - mapif->sendall(buf, RFIFOW(fd,2)); - - return 0; -} - // Save account_reg into sql (type=2) static int mapif_parse_Registry(int fd) { @@ -2544,7 +2532,6 @@ void mapif_defaults(void) mapif->account_reg_reply = mapif_account_reg_reply; mapif->disconnectplayer = mapif_disconnectplayer; mapif->parse_broadcast = mapif_parse_broadcast; - mapif->parse_WisToGM = mapif_parse_WisToGM; mapif->parse_Registry = mapif_parse_Registry; mapif->parse_RegistryRequest = mapif_parse_RegistryRequest; mapif->namechange_ack = mapif_namechange_ack; diff --git a/src/char/mapif.h b/src/char/mapif.h index 7cb7e4f3f..1b83243eb 100644 --- a/src/char/mapif.h +++ b/src/char/mapif.h @@ -185,7 +185,6 @@ struct mapif_interface { int (*account_reg_reply) (int fd,int account_id,int char_id, int type); int (*disconnectplayer) (int fd, int account_id, int char_id, int reason); int (*parse_broadcast) (int fd); - int (*parse_WisToGM) (int fd); int (*parse_Registry) (int fd); int (*parse_RegistryRequest) (int fd); void (*namechange_ack) (int fd, int account_id, int char_id, int type, int flag, const char *name); diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 2fac5b4a4..3bdc43875 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -8263,7 +8263,7 @@ ACMD(request) } safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,278), message); // (@request): %s - intif->wis_message_to_gm(sd->status.name, PC_PERM_RECEIVE_REQUESTS, atcmd_output); + pc->wis_message_to_gm(sd->status.name, PC_PERM_RECEIVE_REQUESTS, atcmd_output); clif_disp_onlyself(sd, atcmd_output); clif->message(sd->fd,msg_fd(fd,279)); // @request sent. return true; diff --git a/src/map/clif.c b/src/map/clif.c index 62c621324..976ba6530 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -11087,13 +11087,13 @@ static void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) sc = status->get_sc(bl); if (sc && sc->option&OPTION_INVISIBLE && !clif->isdisguised(bl) && bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple - pc_get_group_level(sd) < battle_config.hack_info_GM_level + !pc_has_permission(sd, PC_PERM_RECEIVE_HACK_INFO) ) { char gm_msg[256]; sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target (id: %d).\n", sd->status.name, sd->status.account_id, id); ShowWarning(gm_msg); // information is sent to all online GMs - intif->wis_message_to_gm(map->wisp_server_name, battle_config.hack_info_GM_level, gm_msg); + pc->wis_message_to_gm(map->wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, gm_msg); return; } #endif // 0 diff --git a/src/map/intif.c b/src/map/intif.c index a250b22a9..cb9dd465f 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -234,31 +234,6 @@ static int intif_main_message(struct map_session_data *sd, const char *message) return 0; } -// The transmission of GM only Wisp/Page from server to inter-server -static int intif_wis_message_to_gm(char *wisp_name, int permission, char *mes) -{ - int mes_len; - if (intif->CheckForCharServer()) - return 0; - nullpo_ret(wisp_name); - nullpo_ret(mes); - mes_len = (int)strlen(mes) + 1; // + null - Assert_ret(mes_len > 0 && mes_len <= INT16_MAX - 32); - - 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. static int intif_saveregistry(struct map_session_data *sd) { @@ -1120,46 +1095,6 @@ static int intif_homunculus_requestdelete(int homun_id) //----------------------------------------------------------------- // Packets receive from inter server -static int intif_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 .w .24B .l .?B -static void intif_parse_WisToGM(int fd) -{ - int permission, mes_len; - char Wisp_name[NAME_LENGTH]; - char mbuf[255] = { 0 }; - char *message; - - mes_len = RFIFOW(fd,2) - 33; // Length not including the NUL terminator - Assert_retv(mes_len > 0 && mes_len < 32000); - message = (mes_len >= 255 ? aMalloc(mes_len + 1) : mbuf); - - permission = RFIFOL(fd,28); - safestrncpy(Wisp_name, RFIFOP(fd,4), NAME_LENGTH); - safestrncpy(message, RFIFOP(fd,32), mes_len + 1); - // information is sent to all online GM - map->foreachpc(intif->pWisToGM_sub, permission, Wisp_name, message, mes_len); - - if (message != mbuf) - aFree(message); -} - // Request player registre static void intif_parse_Registers(int fd) { @@ -2823,7 +2758,6 @@ static int intif_parse(int fd) else //Color announce. clif->broadcast2(NULL, RFIFOP(fd,16), packet_len-16, RFIFOL(fd,4), RFIFOW(fd,8), RFIFOW(fd,10), RFIFOW(fd,12), RFIFOW(fd,14), ALL_CLIENT); 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; @@ -2928,7 +2862,7 @@ static int intif_parse(int fd) void intif_defaults(void) { const int packet_len_table [INTIF_PACKET_LEN_TABLE_SIZE] = { - -1, 0, 0,-1, -1,-1,37,-1, 7, 0, 0, 0, 0, 0, 0, 0, //0x3800-0x380f + -1, 0, 0, 0, -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,25, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830 @@ -2951,7 +2885,6 @@ void intif_defaults(void) intif->broadcast = intif_broadcast; intif->broadcast2 = intif_broadcast2; intif->main_message = intif_main_message; - 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; @@ -3037,8 +2970,6 @@ void intif_defaults(void) intif->achievements_request = intif_achievements_request; intif->achievements_save = intif_achievements_save; /* parse functions */ - intif->pWisToGM_sub = intif_parse_WisToGM_sub; - intif->pWisToGM = intif_parse_WisToGM; intif->pRegisters = intif_parse_Registers; intif->pChangeNameOk = intif_parse_ChangeNameOk; intif->pMessageToFD = intif_parse_MessageToFD; diff --git a/src/map/intif.h b/src/map/intif.h index 8aab653c2..043facb53 100644 --- a/src/map/intif.h +++ b/src/map/intif.h @@ -63,7 +63,6 @@ struct intif_interface { int (*broadcast) (const char *mes, int len, int type); int (*broadcast2) (const char *mes, int len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY); int (*main_message) (struct map_session_data* sd, const char* message); - int (*wis_message_to_gm) (char *Wisp_name, int permission, char *mes); int (*saveregistry) (struct map_session_data *sd); int (*request_registry) (struct map_session_data *sd, int flag); void (*request_account_storage) (const struct map_session_data *sd); @@ -150,8 +149,6 @@ struct intif_interface { void(*achievements_request) (struct map_session_data *sd); void(*achievements_save) (struct map_session_data *sd); /* */ - int (*pWisToGM_sub) (struct map_session_data* sd,va_list va); - void (*pWisToGM) (int fd); void (*pRegisters) (int fd); void (*pAccountStorage) (int fd); void (*pChangeNameOk) (int fd); diff --git a/src/map/pc.c b/src/map/pc.c index 84d49e1db..827619be8 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -12311,6 +12311,54 @@ static void pc_check_supernovice_call(struct map_session_data *sd, const char *m } } +/** + * Sends a message t all online GMs having the specified permission. + * + * @param sender_name Sender character name. + * @param permission The required permission to receive this message. + * @param message The message body. + * + * @return The amount of characters the message was delivered to. + */ +// The transmission of GM only Wisp/Page from server to inter-server +static int pc_wis_message_to_gm(const char *sender_name, int permission, const char *message) +{ + nullpo_ret(sender_name); + nullpo_ret(message); + int mes_len = (int)strlen(message) + 1; // + null + int count = 0; + + // information is sent to all online GM + map->foreachpc(pc->wis_message_to_gm_sub, permission, sender_name, message, mes_len, &count); + + return count; +} + +/** + * Helper function for pc_wis_message_to_gm(). + */ +static int pc_wis_message_to_gm_sub(struct map_session_data *sd, va_list va) +{ + nullpo_ret(sd); + + int permission = va_arg(va, int); + if (!pc_has_permission(sd, permission)) + return 0; + + const char *sender_name = va_arg(va, const char *); + const char *message = va_arg(va, const char *); + int len = va_arg(va, int); + int *count = va_arg(va, int *); + + nullpo_ret(sender_name); + nullpo_ret(message); + nullpo_ret(count); + + clif->wis_message(sd->fd, sender_name, message, len); + ++*count; + return 1; +} + static void pc_update_job_and_level(struct map_session_data *sd) { nullpo_retv(sd); @@ -12758,6 +12806,8 @@ void pc_defaults(void) pc->check_supernovice_call = pc_check_supernovice_call; pc->process_chat_message = pc_process_chat_message; + pc->wis_message_to_gm = pc_wis_message_to_gm; + pc->wis_message_to_gm_sub = pc_wis_message_to_gm_sub; /** * Autotrade persistency [Ind/Hercules <3] diff --git a/src/map/pc.h b/src/map/pc.h index 7c89f7f32..3a95981a6 100644 --- a/src/map/pc.h +++ b/src/map/pc.h @@ -1185,6 +1185,8 @@ END_ZEROED_BLOCK; /* End */ int (*have_magnifier) (struct map_session_data *sd); bool (*process_chat_message) (struct map_session_data *sd, const char *message); + int (*wis_message_to_gm) (const char *sender_name, int permission, const char *message); + int (*wis_message_to_gm_sub) (struct map_session_data *sd, va_list va); void (*check_supernovice_call) (struct map_session_data *sd, const char *message); bool (*check_basicskill) (struct map_session_data *sd, int level); bool (*isDeathPenaltyJob) (uint16 job); diff --git a/src/map/trade.c b/src/map/trade.c index cef14ffe6..b71c3ecc8 100644 --- a/src/map/trade.c +++ b/src/map/trade.c @@ -223,9 +223,9 @@ static int impossible_trade_check(struct map_session_data *sd) if (inventory[index].amount < sd->deal.item[i].amount) { // if more than the player have -> hack snprintf(message_to_gm, sizeof(message_to_gm), msg_txt(538), sd->status.name, sd->status.account_id); // Hack on trade: character '%s' (account: %d) try to trade more items that he has. - intif->wis_message_to_gm(map->wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm); + pc->wis_message_to_gm(map->wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm); snprintf(message_to_gm, sizeof(message_to_gm), msg_txt(539), inventory[index].amount, inventory[index].nameid, sd->deal.item[i].amount); // This player has %d of a kind of item (id: %d), and try to trade %d of them. - intif->wis_message_to_gm(map->wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm); + pc->wis_message_to_gm(map->wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm); // if we block people if (battle_config.ban_hack_trade < 0) { chrif->char_ask_name(-1, sd->status.name, CHAR_ASK_NAME_BLOCK, 0, 0, 0, 0, 0, 0); @@ -242,7 +242,7 @@ static int impossible_trade_check(struct map_session_data *sd) // message about the ban safestrncpy(message_to_gm, msg_txt(508), sizeof(message_to_gm)); // This player hasn't been banned (Ban option is disabled). - intif->wis_message_to_gm(map->wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm); + pc->wis_message_to_gm(map->wisp_server_name, PC_PERM_RECEIVE_HACK_INFO, message_to_gm); return 1; } inventory[index].amount -= sd->deal.item[i].amount; // remove item from inventory -- cgit v1.2.3-70-g09d2