1
0

Fixed players custom name in 1.8

This commit is contained in:
Howaner 2014-09-26 17:37:19 +02:00
parent 749c6092d3
commit d83d6456e8
14 changed files with 30 additions and 66 deletions

View File

@ -2453,9 +2453,9 @@ void cClientHandle::SendPlayerListUpdatePing(const cPlayer & a_Player)
void cClientHandle::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
void cClientHandle::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName)
{
m_Protocol->SendPlayerListUpdateDisplayName(a_Player, a_OldListName);
m_Protocol->SendPlayerListUpdateDisplayName(a_Player, a_CustomName);
}

View File

@ -172,7 +172,7 @@ public:
void SendPlayerListRemovePlayer (const cPlayer & a_Player);
void SendPlayerListUpdateGameMode (const cPlayer & a_Player);
void SendPlayerListUpdatePing (const cPlayer & a_Player);
void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName);
void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName);
void SendPlayerMaxSpeed (void); ///< Informs the client of the maximum player speed (1.6.1+)
void SendPlayerMoveLook (void);
void SendPlayerPosition (void);

View File

@ -816,7 +816,8 @@ void cPlayer::SetCustomName(const AString & a_CustomName)
{
return;
}
AString OldCustomName = m_CustomName;
m_World->BroadcastPlayerListRemovePlayer(*this);
m_CustomName = a_CustomName;
if (m_CustomName.length() > 16)
@ -824,8 +825,8 @@ void cPlayer::SetCustomName(const AString & a_CustomName)
m_CustomName = m_CustomName.substr(0, 16);
}
m_World->BroadcastPlayerListUpdateDisplayName(*this, m_CustomName);
m_World->BroadcastSpawnEntity(*this, m_ClientHandle);
m_World->BroadcastPlayerListAddPlayer(*this);
m_World->BroadcastSpawnEntity(*this, GetClientHandle());
}

View File

@ -98,7 +98,7 @@ public:
virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) = 0;
virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) = 0;
virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) = 0;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) = 0;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) = 0;
virtual void SendPlayerMaxSpeed (void) = 0; ///< Informs the client of the maximum player speed (1.6.1+)
virtual void SendPlayerMoveLook (void) = 0;
virtual void SendPlayerPosition (void) = 0;

View File

@ -767,25 +767,11 @@ void cProtocol125::SendPlayerListUpdatePing(const cPlayer & a_Player)
void cProtocol125::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
void cProtocol125::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName)
{
if (a_OldListName == a_Player.GetPlayerListName())
{
return;
}
cCSLock Lock(m_CSPacket);
// Remove the old name from the tablist:
{
WriteByte (PACKET_PLAYER_LIST_ITEM);
WriteString(a_OldListName);
WriteBool (false);
WriteShort (0);
Flush();
}
SendPlayerListAddPlayer(a_Player);
// Not implemented in this protocol version
UNUSED(a_Player);
UNUSED(a_CustomName);
}

View File

@ -69,7 +69,7 @@ public:
virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) override;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) override;
virtual void SendPlayerMaxSpeed (void) override;
virtual void SendPlayerMoveLook (void) override;
virtual void SendPlayerPosition (void) override;

View File

@ -838,23 +838,11 @@ void cProtocol172::SendPlayerListUpdatePing(const cPlayer & a_Player)
void cProtocol172::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
void cProtocol172::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName)
{
ASSERT(m_State == 3); // In game mode?
if (a_OldListName == a_Player.GetPlayerListName())
{
return;
}
// Remove the old name from the tablist:
{
cPacketizer Pkt(*this, 0x38);
Pkt.WriteString(a_OldListName);
Pkt.WriteBool(false);
Pkt.WriteShort(0);
}
SendPlayerListAddPlayer(a_Player);
// Not implemented in this protocol version
UNUSED(a_Player);
UNUSED(a_CustomName);
}

View File

@ -105,7 +105,7 @@ public:
virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) override;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) override;
virtual void SendPlayerMaxSpeed (void) override;
virtual void SendPlayerMoveLook (void) override;
virtual void SendPlayerPosition (void) override;

View File

@ -802,7 +802,7 @@ void cProtocol180::SendPlayerListAddPlayer(const cPlayer & a_Player)
Pkt.WriteVarInt(0);
Pkt.WriteVarInt(1);
Pkt.WriteUUID(a_Player.GetUUID());
Pkt.WriteString(a_Player.GetName());
Pkt.WriteString(a_Player.GetPlayerListName());
const Json::Value & Properties = a_Player.GetClientHandle()->GetProperties();
Pkt.WriteVarInt(Properties.size());
@ -824,17 +824,7 @@ void cProtocol180::SendPlayerListAddPlayer(const cPlayer & a_Player)
Pkt.WriteVarInt((UInt32)a_Player.GetGameMode());
Pkt.WriteVarInt((UInt32)a_Player.GetClientHandle()->GetPing());
AString CustomName = a_Player.GetPlayerListName();
if (CustomName != a_Player.GetName())
{
Pkt.WriteBool(true);
Pkt.WriteString(Printf("{\"text\":\"%s\"}", CustomName.c_str()));
}
else
{
Pkt.WriteBool(false);
}
Pkt.WriteBool(false);
}
@ -885,7 +875,7 @@ void cProtocol180::SendPlayerListUpdatePing(const cPlayer & a_Player)
void cProtocol180::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
void cProtocol180::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName)
{
ASSERT(m_State == 3); // In game mode?
@ -894,15 +884,14 @@ void cProtocol180::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, con
Pkt.WriteVarInt(1);
Pkt.WriteUUID(a_Player.GetUUID());
AString CustomName = a_Player.GetPlayerListName();
if (CustomName == a_Player.GetName())
if (a_CustomName.empty())
{
Pkt.WriteBool(false);
}
else
{
Pkt.WriteBool(true);
Pkt.WriteString(Printf("{\"text\":\"%s\"}", CustomName.c_str()));
Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_CustomName.c_str()));
}
}

View File

@ -101,7 +101,7 @@ public:
virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) override;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) override;
virtual void SendPlayerMaxSpeed (void) override;
virtual void SendPlayerMoveLook (void) override;
virtual void SendPlayerPosition (void) override;

View File

@ -529,10 +529,10 @@ void cProtocolRecognizer::SendPlayerListUpdatePing(const cPlayer & a_Player)
void cProtocolRecognizer::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName)
void cProtocolRecognizer::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName)
{
ASSERT(m_Protocol != NULL);
m_Protocol->SendPlayerListUpdateDisplayName(a_Player, a_OldListName);
m_Protocol->SendPlayerListUpdateDisplayName(a_Player, a_CustomName);
}

View File

@ -105,7 +105,7 @@ public:
virtual void SendPlayerListRemovePlayer (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdatePing (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName) override;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) override;
virtual void SendPlayerMaxSpeed (void) override;
virtual void SendPlayerMoveLook (void) override;
virtual void SendPlayerPosition (void) override;

View File

@ -2236,7 +2236,7 @@ void cWorld::BroadcastPlayerListUpdatePing(const cPlayer & a_Player, const cClie
void cWorld::BroadcastPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName, const cClientHandle * a_Exclude)
void cWorld::BroadcastPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSPlayers);
for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
@ -2246,7 +2246,7 @@ void cWorld::BroadcastPlayerListUpdateDisplayName(const cPlayer & a_Player, cons
{
continue;
}
ch->SendPlayerListUpdateDisplayName(a_Player, a_OldListName);
ch->SendPlayerListUpdateDisplayName(a_Player, a_CustomName);
}
}

View File

@ -244,7 +244,7 @@ public:
void BroadcastPlayerListRemovePlayer (const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
void BroadcastPlayerListUpdateGameMode (const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
void BroadcastPlayerListUpdatePing (const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
void BroadcastPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_OldListName, const cClientHandle * a_Exclude = NULL);
void BroadcastPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName, const cClientHandle * a_Exclude = NULL);
void BroadcastRemoveEntityEffect (const cEntity & a_Entity, int a_EffectID, const cClientHandle * a_Exclude = NULL);
void BroadcastScoreboardObjective (const AString & a_Name, const AString & a_DisplayName, Byte a_Mode);
void BroadcastScoreUpdate (const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode);