Added a CriticalSection to cPlugin_NewLua. Lua plugins are not threadsafe but they ARE accessed by multiple threads, this can create some hard to find errors, but I fixed it now :P
git-svn-id: http://mc-server.googlecode.com/svn/trunk@311 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
37415b4297
commit
42a3cd60d4
@ -31,6 +31,7 @@ cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName )
|
||||
|
||||
cPlugin_NewLua::~cPlugin_NewLua()
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
for( WebPluginList::iterator itr = m_WebPlugins.begin(); itr != m_WebPlugins.end(); ++itr )
|
||||
{
|
||||
delete *itr;
|
||||
@ -46,6 +47,7 @@ cPlugin_NewLua::~cPlugin_NewLua()
|
||||
|
||||
bool cPlugin_NewLua::Initialize()
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !m_LuaState )
|
||||
{
|
||||
m_LuaState = lua_open();
|
||||
@ -122,6 +124,7 @@ bool cPlugin_NewLua::Initialize()
|
||||
|
||||
void cPlugin_NewLua::OnDisable()
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnDisable", false) ) // false = don't log error if not found
|
||||
return;
|
||||
|
||||
@ -130,6 +133,7 @@ void cPlugin_NewLua::OnDisable()
|
||||
|
||||
void cPlugin_NewLua::Tick(float a_Dt)
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("Tick") )
|
||||
return;
|
||||
|
||||
@ -140,6 +144,7 @@ void cPlugin_NewLua::Tick(float a_Dt)
|
||||
|
||||
bool cPlugin_NewLua::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnCollectItem") )
|
||||
return false;
|
||||
|
||||
@ -155,6 +160,7 @@ bool cPlugin_NewLua::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player )
|
||||
|
||||
bool cPlugin_NewLua::OnDisconnect( std::string a_Reason, cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnDisconnect") )
|
||||
return false;
|
||||
|
||||
@ -170,6 +176,7 @@ bool cPlugin_NewLua::OnDisconnect( std::string a_Reason, cPlayer* a_Player )
|
||||
|
||||
bool cPlugin_NewLua::OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnBlockPlace") )
|
||||
return false;
|
||||
|
||||
@ -185,6 +192,7 @@ bool cPlugin_NewLua::OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_
|
||||
|
||||
bool cPlugin_NewLua::OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnBlockDig") )
|
||||
return false;
|
||||
|
||||
@ -201,6 +209,7 @@ bool cPlugin_NewLua::OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Play
|
||||
|
||||
bool cPlugin_NewLua::OnChat( const char* a_Chat, cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnChat") )
|
||||
return false;
|
||||
|
||||
@ -216,6 +225,7 @@ bool cPlugin_NewLua::OnChat( const char* a_Chat, cPlayer* a_Player )
|
||||
|
||||
bool cPlugin_NewLua::OnLogin( cPacket_Login* a_PacketData )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnLogin") )
|
||||
return false;
|
||||
|
||||
@ -230,6 +240,7 @@ bool cPlugin_NewLua::OnLogin( cPacket_Login* a_PacketData )
|
||||
|
||||
void cPlugin_NewLua::OnPlayerSpawn( cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnPlayerSpawn") )
|
||||
return;
|
||||
|
||||
@ -240,6 +251,7 @@ void cPlugin_NewLua::OnPlayerSpawn( cPlayer* a_Player )
|
||||
|
||||
bool cPlugin_NewLua::OnPlayerJoin( cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnPlayerJoin") )
|
||||
return false;
|
||||
|
||||
@ -254,6 +266,7 @@ bool cPlugin_NewLua::OnPlayerJoin( cPlayer* a_Player )
|
||||
|
||||
void cPlugin_NewLua::OnPlayerMove( cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnPlayerMove") )
|
||||
return;
|
||||
|
||||
@ -264,6 +277,7 @@ void cPlugin_NewLua::OnPlayerMove( cPlayer* a_Player )
|
||||
|
||||
void cPlugin_NewLua::OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnTakeDamage") )
|
||||
return;
|
||||
|
||||
@ -275,6 +289,7 @@ void cPlugin_NewLua::OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageIn
|
||||
|
||||
bool cPlugin_NewLua::OnKilled( cPawn* a_Killed, cEntity* a_Killer )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( !PushFunction("OnKilled") )
|
||||
return false;
|
||||
|
||||
@ -291,6 +306,7 @@ bool cPlugin_NewLua::OnKilled( cPawn* a_Killed, cEntity* a_Killer )
|
||||
|
||||
cWebPlugin_Lua* cPlugin_NewLua::CreateWebPlugin(lua_State* a_LuaState)
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
if( a_LuaState != m_LuaState )
|
||||
{
|
||||
LOGERROR("Not allowed to create a WebPlugin from another plugin but your own!");
|
||||
|
@ -42,6 +42,8 @@ private:
|
||||
typedef std::list< cWebPlugin_Lua* > WebPluginList;
|
||||
WebPluginList m_WebPlugins;
|
||||
|
||||
cCriticalSection m_CriticalSection;
|
||||
|
||||
std::string m_Directory;
|
||||
lua_State* m_LuaState;
|
||||
};//tolua_export
|
Loading…
Reference in New Issue
Block a user