diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-15 17:29:20 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-15 17:29:20 +0200 |
commit | a67760f7c98a9e57a61ee9c61a2175a33ebcb91b (patch) | |
tree | e4079bd37abb06465a5bce59d3af397ec2be2b2a | |
parent | Fixed The MagicCarpet plugin (diff) | |
download | cuberite-a67760f7c98a9e57a61ee9c61a2175a33ebcb91b.tar cuberite-a67760f7c98a9e57a61ee9c61a2175a33ebcb91b.tar.gz cuberite-a67760f7c98a9e57a61ee9c61a2175a33ebcb91b.tar.bz2 cuberite-a67760f7c98a9e57a61ee9c61a2175a33ebcb91b.tar.lz cuberite-a67760f7c98a9e57a61ee9c61a2175a33ebcb91b.tar.xz cuberite-a67760f7c98a9e57a61ee9c61a2175a33ebcb91b.tar.zst cuberite-a67760f7c98a9e57a61ee9c61a2175a33ebcb91b.zip |
Diffstat (limited to '')
-rw-r--r-- | source/ChunkMap.h | 3 | ||||
-rw-r--r-- | source/ClientHandle.cpp | 12 | ||||
-rw-r--r-- | source/World.cpp | 12 | ||||
-rw-r--r-- | source/World.h | 13 |
4 files changed, 39 insertions, 1 deletions
diff --git a/source/ChunkMap.h b/source/ChunkMap.h index 1af26c39a..f8f03e063 100644 --- a/source/ChunkMap.h +++ b/source/ChunkMap.h @@ -298,6 +298,9 @@ public: /// Queues the specified block for ticking (block update) void QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ); + + /// Returns the CS for locking the chunkmap; only cWorld::cLock may use this function! + cCriticalSection & GetCS(void) { return m_CSLayers; } private: diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index d0904bfb0..9d5bbaeaf 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -1957,7 +1957,17 @@ void cClientHandle::PacketError(unsigned char a_PacketType) void cClientHandle::DataReceived(const char * a_Data, int a_Size) { // Data is received from the client, hand it off to the protocol: - m_Protocol->DataReceived(a_Data, a_Size); + if ((m_Player != NULL) && (m_Player->GetWorld() != NULL)) + { + // Lock the world, so that plugins reacting to protocol events have already the chunkmap locked + cWorld::cLock(*m_Player->GetWorld()); + + m_Protocol->DataReceived(a_Data, a_Size); + } + else + { + m_Protocol->DataReceived(a_Data, a_Size); + } m_TimeSinceLastPacket = 0; } diff --git a/source/World.cpp b/source/World.cpp index 36fb08702..f9da43ed2 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -173,6 +173,18 @@ protected: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cWorld::cLock: + +cWorld::cLock::cLock(cWorld & a_World) : + super(&(a_World.m_ChunkMap->GetCS())) +{ +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cWorld: cWorld::cWorld(const AString & a_WorldName) : diff --git a/source/World.h b/source/World.h index 21869bd41..fe339ea61 100644 --- a/source/World.h +++ b/source/World.h @@ -66,6 +66,19 @@ public: dimEnd = 1, } ; + // tolua_end + + /// A simple RAII locker for the chunkmap - locks the chunkmap in its constructor, unlocks it in the destructor + class cLock : + public cCSLock + { + typedef cCSLock super; + public: + cLock(cWorld & a_World); + } ; + + // tolua_begin + static const char * GetClassStatic(void) { return "cWorld"; |