1
0

Fixed a security problem with signs.

This commit is contained in:
Howaner 2014-11-15 15:16:52 +01:00
parent 7120b1a769
commit 78fb789631
5 changed files with 18 additions and 16 deletions

View File

@ -1038,7 +1038,7 @@ static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
} }
#endif #endif
{ {
bool res = self->UpdateSign(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4, Player); bool res = self->SetSignLines(BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4, Player);
tolua_pushboolean(tolua_S, res ? 1 : 0); tolua_pushboolean(tolua_S, res ? 1 : 0);
} }
} }

View File

@ -93,6 +93,7 @@ cClientHandle::cClientHandle(const cSocket * a_Socket, int a_ViewDistance) :
m_UniqueID(0), m_UniqueID(0),
m_HasSentPlayerChunk(false), m_HasSentPlayerChunk(false),
m_Locale("en_GB"), m_Locale("en_GB"),
m_LastPlacedBlock(0, -1, 0),
m_ProtocolVersion(0) m_ProtocolVersion(0)
{ {
m_Protocol = new cProtocolRecognizer(this); m_Protocol = new cProtocolRecognizer(this);
@ -1500,6 +1501,8 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, e
{ {
m_Player->GetInventory().RemoveOneEquippedItem(); m_Player->GetInventory().RemoveOneEquippedItem();
} }
m_LastPlacedBlock.Set(a_BlockX, a_BlockY, a_BlockZ);
cChunkInterface ChunkInterface(World->GetChunkMap()); cChunkInterface ChunkInterface(World->GetChunkMap());
NewBlock->OnPlacedByPlayer(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta); NewBlock->OnPlacedByPlayer(ChunkInterface, *World, m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, BlockType, BlockMeta);
@ -1677,8 +1680,10 @@ void cClientHandle::HandleUpdateSign(
const AString & a_Line3, const AString & a_Line4 const AString & a_Line3, const AString & a_Line4
) )
{ {
cWorld * World = m_Player->GetWorld(); if (m_LastPlacedBlock.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ)))
World->UpdateSign(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, m_Player); {
m_Player->GetWorld()->SetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, m_Player);
}
} }

View File

@ -125,6 +125,9 @@ public:
inline bool IsLoggedIn(void) const { return (m_State >= csAuthenticating); } inline bool IsLoggedIn(void) const { return (m_State >= csAuthenticating); }
/** Returns the positions from the last block that the player placed. */
const Vector3i & GetLastPlacedBlock(void) const { return m_LastPlacedBlock; } // tolua_export
/** Called while the client is being ticked from the world via its cPlayer object */ /** Called while the client is being ticked from the world via its cPlayer object */
void Tick(float a_Dt); void Tick(float a_Dt);
@ -432,6 +435,9 @@ private:
/** Client Settings */ /** Client Settings */
AString m_Locale; AString m_Locale;
/** The positions from the last block that the player placed. It's needed to verify the sign text change. */
Vector3i m_LastPlacedBlock;
/** The plugin channels that the client has registered. */ /** The plugin channels that the client has registered. */
cChannels m_PluginChannels; cChannels m_PluginChannels;

View File

@ -2926,15 +2926,18 @@ bool cWorld::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AStrin
AString Line2(a_Line2); AString Line2(a_Line2);
AString Line3(a_Line3); AString Line3(a_Line3);
AString Line4(a_Line4); AString Line4(a_Line4);
if (cRoot::Get()->GetPluginManager()->CallHookUpdatingSign(*this, a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4, a_Player)) if (cRoot::Get()->GetPluginManager()->CallHookUpdatingSign(*this, a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4, a_Player))
{ {
return false; return false;
} }
if (m_ChunkMap->SetSignLines(a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4)) if (m_ChunkMap->SetSignLines(a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4))
{ {
cRoot::Get()->GetPluginManager()->CallHookUpdatedSign(*this, a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4, a_Player); cRoot::Get()->GetPluginManager()->CallHookUpdatedSign(*this, a_BlockX, a_BlockY, a_BlockZ, Line1, Line2, Line3, Line4, a_Player);
return true; return true;
} }
return false; return false;
} }
@ -2942,15 +2945,6 @@ bool cWorld::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AStrin
bool cWorld::UpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player)
{
return SetSignLines(a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player);
}
bool cWorld::SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command) bool cWorld::SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command)
{ {
class cUpdateCommandBlock : public cCommandBlockCallback class cUpdateCommandBlock : public cCommandBlockCallback

View File

@ -377,11 +377,8 @@ public:
/** Marks the chunk as failed-to-load: */ /** Marks the chunk as failed-to-load: */
void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ); void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ);
/** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be nullptr. Returns true if sign text changed. Same as UpdateSign() */ /** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be nullptr. Returns true if sign text changed. */
bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = nullptr); // Exported in ManualBindings.cpp bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = nullptr); // Exported in ManualBindings.cpp
/** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be nullptr. Returns true if sign text changed. Same as SetSignLines() */
bool UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = nullptr); // Exported in ManualBindings.cpp
/** Sets the command block command. Returns true if command changed. */ /** Sets the command block command. Returns true if command changed. */
bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command); // tolua_export bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command); // tolua_export