diff options
author | archshift <admin@archshift.com> | 2014-04-25 02:24:39 +0200 |
---|---|---|
committer | archshift <admin@archshift.com> | 2014-04-25 03:03:49 +0200 |
commit | b008ba5d982542d8a2857544af1aa88a41cf7b13 (patch) | |
tree | 8b08264287ae5eb55f6a10b952126d399dc15b5d | |
parent | Fixed class capitalization for the cave spider. (diff) | |
download | cuberite-b008ba5d982542d8a2857544af1aa88a41cf7b13.tar cuberite-b008ba5d982542d8a2857544af1aa88a41cf7b13.tar.gz cuberite-b008ba5d982542d8a2857544af1aa88a41cf7b13.tar.bz2 cuberite-b008ba5d982542d8a2857544af1aa88a41cf7b13.tar.lz cuberite-b008ba5d982542d8a2857544af1aa88a41cf7b13.tar.xz cuberite-b008ba5d982542d8a2857544af1aa88a41cf7b13.tar.zst cuberite-b008ba5d982542d8a2857544af1aa88a41cf7b13.zip |
Diffstat (limited to '')
-rw-r--r-- | src/ClientHandle.cpp | 162 | ||||
-rw-r--r-- | src/ClientHandle.h | 3 |
2 files changed, 81 insertions, 84 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 0f26d41e7..6ff944c01 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -186,6 +186,82 @@ void cClientHandle::GenerateOfflineUUID(void) +AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString &a_AdditionalData) +{ + switch (a_ChatPrefix) + { + case mtCustom: return AString(); + case mtFailure: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Rose.c_str()); + } + case mtInformation: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Yellow.c_str()); + } + case mtSuccess: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Green.c_str()); + } + case mtWarning: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Rose.c_str()); + } + case mtFatal: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Red.c_str()); + } + case mtDeath: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Gray.c_str()); + } + case mtPrivateMessage: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); + else + return Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str()); + } + case mtJoin: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Yellow.c_str()); + } + case mtLeave: + { + if (ShouldAppendChatPrefixes) + return Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); + else + return Printf("%s", cChatColor::Yellow.c_str()); + } + } + ASSERT(!"Unhandled chat prefix type!"); +} + + + + + AString cClientHandle::GenerateOfflineUUID(const AString & a_Username) { // Proper format for a version 3 UUID is: @@ -1848,8 +1924,6 @@ void cClientHandle::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlock void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefix, const AString & a_AdditionalData) { - bool ShouldAppendChatPrefixes = true; - if (GetPlayer()->GetWorld() == NULL) { cWorld * World = cRoot::Get()->GetWorld(GetPlayer()->GetLoadedWorldName()); @@ -1868,89 +1942,9 @@ void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefi ShouldAppendChatPrefixes = false; } - AString Message; - - switch (a_ChatPrefix) - { - case mtCustom: break; - case mtFailure: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[INFO] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Rose.c_str()); - break; - } - case mtInformation: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[INFO] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Yellow.c_str()); - break; - } - case mtSuccess: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[INFO] %s", cChatColor::Green.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Green.c_str()); - break; - } - case mtWarning: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[WARN] %s", cChatColor::Rose.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Rose.c_str()); - break; - } - case mtFatal: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[FATAL] %s", cChatColor::Red.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Red.c_str()); - break; - } - case mtDeath: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[DEATH] %s", cChatColor::Gray.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Gray.c_str()); - break; - } - case mtPrivateMessage: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[MSG: %s] %s%s", cChatColor::LightBlue.c_str(), a_AdditionalData.c_str(), cChatColor::White.c_str(), cChatColor::Italic.c_str()); - else - Message = Printf("%s: %s", a_AdditionalData.c_str(), cChatColor::LightBlue.c_str()); - break; - } - case mtJoin: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[JOIN] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Yellow.c_str()); - break; - } - case mtLeave: - { - if (ShouldAppendChatPrefixes) - Message = Printf("%s[LEAVE] %s", cChatColor::Yellow.c_str(), cChatColor::White.c_str()); - else - Message = Printf("%s", cChatColor::Yellow.c_str()); - break; - } - default: ASSERT(!"Unhandled chat prefix type!"); return; - } - - Message.append(a_Message); + AString Message = FormatMessageType(ShouldAppendChatPrefixes, a_ChatPrefix, a_AdditionalData); - m_Protocol->SendChat(Message); + m_Protocol->SendChat(Message.append(a_Message)); } diff --git a/src/ClientHandle.h b/src/ClientHandle.h index 3d01d8034..e2b44ce8a 100644 --- a/src/ClientHandle.h +++ b/src/ClientHandle.h @@ -77,6 +77,9 @@ public: This is used for the offline (non-auth) mode, when there's no UUID source. Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. */ static AString GenerateOfflineUUID(const AString & a_Username); // tolua_export + + // Formats the type of message with the proper color and prefix for sending to the client. + AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData); void Kick(const AString & a_Reason); // tolua_export void Authenticate(const AString & a_Name, const AString & a_UUID); // Called by cAuthenticator when the user passes authentication |