From a0341d561a177bcd1ed45229129065556c261049 Mon Sep 17 00:00:00 2001 From: Heiko Hund Date: Sat, 27 May 2017 03:15:56 +0200 Subject: Add rank prefix and suffix to player name in chat (#3730) Fixes issue #1721 --- Server/Plugins/APIDump/APIDesc.lua | 20 ++++++++++++++++++++ src/ClientHandle.cpp | 6 +++++- src/Entities/Player.cpp | 18 ++++++++++++++++++ src/Entities/Player.h | 6 ++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index e0d5cbd71..724f52398 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -11433,6 +11433,26 @@ a_Player:OpenWindow(Window); }, Notes = "Returns the full color code to be used for this player's messages (based on their rank). Prefix player messages with this code.", }, + GetPrefix = + { + Returns = + { + { + Type = "string", + }, + }, + Notes = "Returns the prefix to player names for messages (based on their rank), may contain @ format codes.", + }, + GetSuffix = + { + Returns = + { + { + Type = "string", + }, + }, + Notes = "Returns the suffix to player names for messages (based on their rank), may contain @ format codes.", + }, GetCurrentXp = { Returns = diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 17b93a62c..efd592405 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1562,7 +1562,11 @@ void cClientHandle::HandleChat(const AString & a_Message) { Color.clear(); } - Msg.AddTextPart(AString("<") + m_Player->GetName() + "> ", Color); + Msg.AddTextPart("<"); + Msg.ParseText(m_Player->GetPrefix()); + Msg.AddTextPart(m_Player->GetName(), Color); + Msg.ParseText(m_Player->GetSuffix()); + Msg.AddTextPart("> "); Msg.ParseText(Message); Msg.UnderlineUrls(); cRoot::Get()->BroadcastChat(Msg); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 94398c258..c0a078bcb 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1828,6 +1828,24 @@ AString cPlayer::GetColor(void) const +AString cPlayer::GetPrefix(void) const +{ + return m_MsgPrefix; +} + + + + + +AString cPlayer::GetSuffix(void) const +{ + return m_MsgSuffix; +} + + + + + AString cPlayer::GetPlayerListName(void) const { const AString & Color = GetColor(); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 02f187e31..d25432e9f 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -285,6 +285,12 @@ public: The returned value either is empty, or includes the cChatColor::Delimiter. */ AString GetColor(void) const; + /** Returns the player name prefix, may contain @ format directives */ + AString GetPrefix(void) const; + + /** Returns the player name suffix, may contain @ format directives */ + AString GetSuffix(void) const; + /** Returns the name that is used in the playerlist. */ AString GetPlayerListName(void) const; -- cgit v1.2.3