From 2ba1812b8315b5df8291f68144b0c380a6cd749d Mon Sep 17 00:00:00 2001 From: wushin Date: Fri, 4 Mar 2016 15:15:23 -0600 Subject: add player nicks back to messages closes #194 --- src/map/battle.cpp | 21 +++++++++++++++++++++ src/map/battle.hpp | 1 + src/map/clif.cpp | 34 +++++++++++++++++----------------- 3 files changed, 39 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 589568b..991a489 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -182,6 +182,27 @@ int battle_get_max_hp(dumb_ptr bl) } } +VString<23> battle_get_name(dumb_ptr bl) +{ + VString<23> name; + nullpo_retr(name, bl); + + switch (bl->bl_type) + { + case BL::PC: + name = bl->is_player()->status_key.name.to__actual(); + break; + case BL::NPC: + name = bl->is_npc()->name; + break; + case BL::MOB: + name = bl->is_mob()->name; + break; + } + + return name; +} + /*========================================== * 対象のStrを返す(汎用) * 戻りは整数で0以上 diff --git a/src/map/battle.hpp b/src/map/battle.hpp index 1a13420..8f31fe0 100644 --- a/src/map/battle.hpp +++ b/src/map/battle.hpp @@ -67,6 +67,7 @@ ATK battle_weapon_attack(dumb_ptr bl, dumb_ptr target, int battle_is_unarmed(dumb_ptr bl); Species battle_get_class(dumb_ptr bl); +VString<23> battle_get_name(dumb_ptr bl); DIR battle_get_dir(dumb_ptr bl); int battle_get_lv(dumb_ptr bl); int battle_get_range(dumb_ptr bl); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 9743e49..349d2e9 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -3790,6 +3790,20 @@ RecvResult clif_parse_GetCharNameRequest(Session *s, dumb_ptr return rv; } +static +void clif_message_sub(Buffer& buf, dumb_ptr bl, AString msg) +{ + VString<23> name = battle_get_name(bl); + msg = STRPRINTF("%s : %s"_fmt, name, msg); + size_t msg_len = msg.size() + 1; + if (msg_len + 16 > 512) + return; + + Packet_Head<0x008d> head_8d; + head_8d.block_id = bl->bl_id; + buf = create_vpacket<0x008d, 8, 1>(head_8d, msg); +} + /*========================================== * Validate and process transmission of a * global/public message. @@ -3825,10 +3839,8 @@ RecvResult clif_parse_GlobalMessage(Session *s, dumb_ptr sd) } /* It's not a spell/magic message, so send the message to others. */ - Packet_Head<0x008d> head_8d; - head_8d.block_id = sd->bl_id; - XString repeat_8d = mbuf; - Buffer sendbuf = create_vpacket<0x008d, 8, 1>(head_8d, repeat_8d); + Buffer sendbuf; + clif_message_sub(sendbuf, sd, mbuf); clif_send(sendbuf, sd, SendWho::AREA_CHAT_WOC, MIN_CLIENT_VERSION); } @@ -3839,18 +3851,6 @@ RecvResult clif_parse_GlobalMessage(Session *s, dumb_ptr sd) return rv; } -static -void clif_message_sub(Buffer& buf, dumb_ptr bl, XString msg) -{ - size_t msg_len = msg.size() + 1; - if (msg_len + 16 > 512) - return; - - Packet_Head<0x008d> head_8d; - head_8d.block_id = bl->bl_id; - buf = create_vpacket<0x008d, 8, 1>(head_8d, msg); -} - void clif_npc_send_title(Session *s, BlockId npcid, XString msg) { size_t msg_len = msg.size() + 1; @@ -5688,7 +5688,7 @@ AString clif_validate_chat(dumb_ptr sd, ChatType type, XString return AString(); } - if (type == ChatType::Global) + if (type == ChatType::Global && sd->client_version < 6) { XString p = pbuf; if (!(p.startswith(sd->status_key.name.to__actual()) && p.xslice_t(name_len).startswith(" : "_s))) -- cgit v1.2.3-60-g2f50