1
0

Merge pull request #2488 from cuberite/ChatFlag

Refactored cProtocol Chat handling
This commit is contained in:
worktycho 2015-09-21 13:30:17 +01:00
commit 87489dc308
8 changed files with 32 additions and 227 deletions

View File

@ -2086,8 +2086,9 @@ void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefi
}
}
AString Message = FormatMessageType(World->ShouldUseChatPrefixes(), a_ChatPrefix, a_AdditionalData);
m_Protocol->SendChat(Message.append(a_Message));
bool ShouldUsePrefixes = World->ShouldUseChatPrefixes();
AString Message = FormatMessageType(ShouldUsePrefixes, a_ChatPrefix, a_AdditionalData);
m_Protocol->SendChat(Message.append(a_Message), ctChatBox, ShouldUsePrefixes);
}
@ -2096,7 +2097,7 @@ void cClientHandle::SendChat(const AString & a_Message, eMessageType a_ChatPrefi
void cClientHandle::SendChat(const cCompositeChat & a_Message)
{
m_Protocol->SendChat(a_Message);
m_Protocol->SendChat(a_Message, ctChatBox, GetPlayer()->GetWorld()->ShouldUseChatPrefixes());
}
@ -2116,7 +2117,7 @@ void cClientHandle::SendChatAboveActionBar(const AString & a_Message, eMessageTy
}
AString Message = FormatMessageType(World->ShouldUseChatPrefixes(), a_ChatPrefix, a_AdditionalData);
m_Protocol->SendChatAboveActionBar(Message.append(a_Message));
m_Protocol->SendChat(Message.append(a_Message), ctAboveActionBar);
}
@ -2125,7 +2126,7 @@ void cClientHandle::SendChatAboveActionBar(const AString & a_Message, eMessageTy
void cClientHandle::SendChatAboveActionBar(const cCompositeChat & a_Message)
{
m_Protocol->SendChatAboveActionBar(a_Message);
m_Protocol->SendChat(a_Message, ctAboveActionBar, GetPlayer()->GetWorld()->ShouldUseChatPrefixes());
}
@ -2144,8 +2145,9 @@ void cClientHandle::SendChatSystem(const AString & a_Message, eMessageType a_Cha
}
}
AString Message = FormatMessageType(World->ShouldUseChatPrefixes(), a_ChatPrefix, a_AdditionalData);
m_Protocol->SendChatSystem(Message.append(a_Message));
auto ShouldUsePrefixes = World->ShouldUseChatPrefixes();
AString Message = FormatMessageType(ShouldUsePrefixes, a_ChatPrefix, a_AdditionalData);
m_Protocol->SendChat(Message.append(a_Message), ctSystem, ShouldUsePrefixes);
}
@ -2154,7 +2156,7 @@ void cClientHandle::SendChatSystem(const AString & a_Message, eMessageType a_Cha
void cClientHandle::SendChatSystem(const cCompositeChat & a_Message)
{
m_Protocol->SendChatSystem(a_Message);
m_Protocol->SendChat(a_Message, ctSystem, GetPlayer()->GetWorld()->ShouldUseChatPrefixes());
}

View File

@ -68,14 +68,8 @@ public:
virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) = 0;
virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) = 0;
virtual void SendChat (const AString & a_Message) = 0;
virtual void SendChat (const cCompositeChat & a_Message) = 0;
virtual void SendChatAboveActionBar (const AString & a_Message) = 0;
virtual void SendChatAboveActionBar (const cCompositeChat & a_Message) = 0;
virtual void SendChatSystem (const AString & a_Message) = 0;
virtual void SendChatSystem (const cCompositeChat & a_Message) = 0;
virtual void SendChatType (const AString & a_Message, eChatType type) = 0;
virtual void SendChatType (const cCompositeChat & a_Message, eChatType type) = 0;
virtual void SendChat (const AString & a_Message, eChatType a_Type) = 0;
virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) = 0;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) = 0;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) = 0;
virtual void SendDestroyEntity (const cEntity & a_Entity) = 0;

View File

@ -245,65 +245,11 @@ void cProtocol172::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV
void cProtocol172::SendChat(const AString & a_Message)
{
this->SendChatType(a_Message, ctChatBox);
}
void cProtocol172::SendChat(const cCompositeChat & a_Message)
{
this->SendChatType(a_Message, ctChatBox);
}
void cProtocol172::SendChatSystem(const AString & a_Message)
{
this->SendChatType(a_Message, ctSystem);
}
void cProtocol172::SendChatSystem(const cCompositeChat & a_Message)
{
this->SendChatType(a_Message, ctSystem);
}
void cProtocol172::SendChatAboveActionBar(const AString & a_Message)
{
this->SendChatType(a_Message, ctAboveActionBar);
}
void cProtocol172::SendChatAboveActionBar(const cCompositeChat & a_Message)
{
this->SendChatType(a_Message, ctAboveActionBar);
}
void cProtocol172::SendChatType(const AString & a_Message, eChatType type)
void cProtocol172::SendChat(const AString & a_Message, eChatType a_Type)
{
ASSERT(m_State == 3); // In game mode?
if (type != ctChatBox) // 1.7.2 doesn't support anything else
if (a_Type != ctChatBox) // 1.7.2 doesn't support anything else
{
return;
}
@ -316,21 +262,18 @@ void cProtocol172::SendChatType(const AString & a_Message, eChatType type)
void cProtocol172::SendChatType(const cCompositeChat & a_Message, eChatType type)
void cProtocol172::SendChat(const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes)
{
ASSERT(m_State == 3); // In game mode?
if (type != ctChatBox) // 1.7.2 doesn't support anything else
if (a_Type != ctChatBox) // 1.7.2 doesn't support anything else
{
return;
}
cWorld * World = m_Client->GetPlayer()->GetWorld();
bool ShouldUseChatPrefixes = (World == nullptr) ? false : World->ShouldUseChatPrefixes();
// Send the message to the client:
cPacketizer Pkt(*this, 0x02);
Pkt.WriteString(a_Message.CreateJsonString(ShouldUseChatPrefixes));
Pkt.WriteString(a_Message.CreateJsonString(a_ShouldUseChatPrefixes));
}

View File

@ -66,14 +66,8 @@ public:
virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
virtual void SendChat (const AString & a_Message) override;
virtual void SendChat (const cCompositeChat & a_Message) override;
virtual void SendChatAboveActionBar (const AString & a_Message) override;
virtual void SendChatAboveActionBar (const cCompositeChat & a_Message) override;
virtual void SendChatSystem (const AString & a_Message) override;
virtual void SendChatSystem (const cCompositeChat & a_Message) override;
virtual void SendChatType (const AString & a_Message, eChatType type) override;
virtual void SendChatType (const cCompositeChat & a_Message, eChatType type) override;
virtual void SendChat (const AString & a_Message, eChatType a_Type) override;
virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
virtual void SendDestroyEntity (const cEntity & a_Entity) override;

View File

@ -232,84 +232,28 @@ void cProtocol180::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV
void cProtocol180::SendChat(const AString & a_Message)
{
this->SendChatType(a_Message, ctChatBox);
}
void cProtocol180::SendChat(const cCompositeChat & a_Message)
{
this->SendChatType(a_Message, ctChatBox);
}
void cProtocol180::SendChatSystem(const AString & a_Message)
{
this->SendChatType(a_Message, ctSystem);
}
void cProtocol180::SendChatSystem(const cCompositeChat & a_Message)
{
this->SendChatType(a_Message, ctSystem);
}
void cProtocol180::SendChatAboveActionBar(const AString & a_Message)
{
this->SendChatType(a_Message, ctAboveActionBar);
}
void cProtocol180::SendChatAboveActionBar(const cCompositeChat & a_Message)
{
this->SendChatType(a_Message, ctAboveActionBar);
}
void cProtocol180::SendChatType(const AString & a_Message, eChatType type)
void cProtocol180::SendChat(const AString & a_Message, eChatType a_Type)
{
ASSERT(m_State == 3); // In game mode?
cPacketizer Pkt(*this, 0x02); // Chat Message packet
Pkt.WriteString(Printf("{\"text\":\"%s\"}", EscapeString(a_Message).c_str()));
Pkt.WriteBEInt8(type);
Pkt.WriteBEInt8(a_Type);
}
void cProtocol180::SendChatType(const cCompositeChat & a_Message, eChatType type)
void cProtocol180::SendChat(const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes)
{
ASSERT(m_State == 3); // In game mode?
cWorld * World = m_Client->GetPlayer()->GetWorld();
bool ShouldUseChatPrefixes = (World == nullptr) ? false : World->ShouldUseChatPrefixes();
// Send the message to the client:
cPacketizer Pkt(*this, 0x02);
Pkt.WriteString(a_Message.CreateJsonString(ShouldUseChatPrefixes));
Pkt.WriteBEInt8(type);
Pkt.WriteString(a_Message.CreateJsonString(a_ShouldUseChatPrefixes));
Pkt.WriteBEInt8(a_Type);
}

View File

@ -65,14 +65,8 @@ public:
virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
virtual void SendChat (const AString & a_Message) override;
virtual void SendChat (const cCompositeChat & a_Message) override;
virtual void SendChatAboveActionBar (const AString & a_Message) override;
virtual void SendChatAboveActionBar (const cCompositeChat & a_Message) override;
virtual void SendChatSystem (const AString & a_Message) override;
virtual void SendChatSystem (const cCompositeChat & a_Message) override;
virtual void SendChatType (const AString & a_Message, eChatType type) override;
virtual void SendChatType (const cCompositeChat & a_Message, eChatType type) override;
virtual void SendChat (const AString & a_Message, eChatType a_Type) override;
virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
virtual void SendDestroyEntity (const cEntity & a_Entity) override;

View File

@ -138,80 +138,20 @@ void cProtocolRecognizer::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSe
void cProtocolRecognizer::SendChat(const AString & a_Message)
void cProtocolRecognizer::SendChat(const AString & a_Message, eChatType a_Type)
{
ASSERT(m_Protocol != nullptr);
m_Protocol->SendChat(a_Message);
m_Protocol->SendChat(a_Message, a_Type);
}
void cProtocolRecognizer::SendChat(const cCompositeChat & a_Message)
void cProtocolRecognizer::SendChat(const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes)
{
ASSERT(m_Protocol != nullptr);
m_Protocol->SendChat(a_Message);
}
void cProtocolRecognizer::SendChatAboveActionBar(const AString & a_Message)
{
ASSERT(m_Protocol != nullptr);
m_Protocol->SendChatAboveActionBar(a_Message);
}
void cProtocolRecognizer::SendChatAboveActionBar(const cCompositeChat & a_Message)
{
ASSERT(m_Protocol != nullptr);
m_Protocol->SendChatAboveActionBar(a_Message);
}
void cProtocolRecognizer::SendChatSystem(const AString & a_Message)
{
ASSERT(m_Protocol != nullptr);
m_Protocol->SendChatSystem(a_Message);
}
void cProtocolRecognizer::SendChatSystem(const cCompositeChat & a_Message)
{
ASSERT(m_Protocol != nullptr);
m_Protocol->SendChatSystem(a_Message);
}
void cProtocolRecognizer::SendChatType(const AString & a_Message, eChatType type)
{
ASSERT(m_Protocol != nullptr);
m_Protocol->SendChatType(a_Message, type);
}
void cProtocolRecognizer::SendChatType(const cCompositeChat & a_Message, eChatType type)
{
ASSERT(m_Protocol != nullptr);
m_Protocol->SendChatType(a_Message, type);
m_Protocol->SendChat(a_Message, a_Type, a_ShouldUseChatPrefixes);
}

View File

@ -53,14 +53,8 @@ public:
virtual void SendBlockBreakAnim (UInt32 a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage) override;
virtual void SendBlockChange (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual void SendBlockChanges (int a_ChunkX, int a_ChunkZ, const sSetBlockVector & a_Changes) override;
virtual void SendChat (const AString & a_Message) override;
virtual void SendChat (const cCompositeChat & a_Message) override;
virtual void SendChatAboveActionBar (const AString & a_Message) override;
virtual void SendChatAboveActionBar (const cCompositeChat & a_Message) override;
virtual void SendChatSystem (const AString & a_Message) override;
virtual void SendChatSystem (const cCompositeChat & a_Message) override;
virtual void SendChatType (const AString & a_Message, eChatType type) override;
virtual void SendChatType (const cCompositeChat & a_Message, eChatType type) override;
virtual void SendChat (const AString & a_Message, eChatType a_Type) override;
virtual void SendChat (const cCompositeChat & a_Message, eChatType a_Type, bool a_ShouldUseChatPrefixes) override;
virtual void SendChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer) override;
virtual void SendCollectEntity (const cEntity & a_Entity, const cPlayer & a_Player) override;
virtual void SendDestroyEntity (const cEntity & a_Entity) override;