Merge pull request #1456 from Howaner/Fixes
Fixed player custom names in 1.8 and added type checking to map loading
This commit is contained in:
commit
305778f22f
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,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);
|
||||
|
@ -130,14 +130,14 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT)
|
||||
}
|
||||
|
||||
int CurrLine = a_NBT.FindChildByName(Data, "scale");
|
||||
if (CurrLine >= 0)
|
||||
if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Byte))
|
||||
{
|
||||
unsigned int Scale = a_NBT.GetByte(CurrLine);
|
||||
unsigned int Scale = (unsigned int)a_NBT.GetByte(CurrLine);
|
||||
m_Map->SetScale(Scale);
|
||||
}
|
||||
|
||||
CurrLine = a_NBT.FindChildByName(Data, "dimension");
|
||||
if (CurrLine >= 0)
|
||||
if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Byte))
|
||||
{
|
||||
eDimension Dimension = (eDimension) a_NBT.GetByte(CurrLine);
|
||||
|
||||
@ -149,9 +149,9 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT)
|
||||
}
|
||||
|
||||
CurrLine = a_NBT.FindChildByName(Data, "width");
|
||||
if (CurrLine >= 0)
|
||||
if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Short))
|
||||
{
|
||||
unsigned int Width = a_NBT.GetShort(CurrLine);
|
||||
unsigned int Width = (unsigned int)a_NBT.GetShort(CurrLine);
|
||||
if (Width != 128)
|
||||
{
|
||||
return false;
|
||||
@ -160,9 +160,9 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT)
|
||||
}
|
||||
|
||||
CurrLine = a_NBT.FindChildByName(Data, "height");
|
||||
if (CurrLine >= 0)
|
||||
if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Short))
|
||||
{
|
||||
unsigned int Height = a_NBT.GetShort(CurrLine);
|
||||
unsigned int Height = (unsigned int)a_NBT.GetShort(CurrLine);
|
||||
if (Height >= 256)
|
||||
{
|
||||
return false;
|
||||
@ -171,14 +171,14 @@ bool cMapSerializer::LoadMapFromNBT(const cParsedNBT & a_NBT)
|
||||
}
|
||||
|
||||
CurrLine = a_NBT.FindChildByName(Data, "xCenter");
|
||||
if (CurrLine >= 0)
|
||||
if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Int))
|
||||
{
|
||||
int CenterX = a_NBT.GetInt(CurrLine);
|
||||
m_Map->m_CenterX = CenterX;
|
||||
}
|
||||
|
||||
CurrLine = a_NBT.FindChildByName(Data, "zCenter");
|
||||
if (CurrLine >= 0)
|
||||
if ((CurrLine >= 0) && (a_NBT.GetType(CurrLine) == TAG_Int))
|
||||
{
|
||||
int CenterZ = a_NBT.GetInt(CurrLine);
|
||||
m_Map->m_CenterZ = CenterZ;
|
||||
|
@ -28,10 +28,10 @@ public:
|
||||
|
||||
cMapSerializer(const AString& a_WorldName, cMap * a_Map);
|
||||
|
||||
/** Try to load the scoreboard */
|
||||
/** Try to load the map */
|
||||
bool Load(void);
|
||||
|
||||
/** Try to save the scoreboard */
|
||||
/** Try to save the map */
|
||||
bool Save(void);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user