2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#define LUA_USE_POSIX
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Plugin_NewLua.h"
|
2013-06-29 11:30:05 -04:00
|
|
|
#include "CommandOutput.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#include "lualib.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "tolua++.h"
|
|
|
|
#include "Bindings.h"
|
|
|
|
#include "ManualBindings.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-04-07 15:28:32 -04:00
|
|
|
// fwd: SQLite/lsqlite3.c
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
LUALIB_API int luaopen_lsqlite3(lua_State * L);
|
|
|
|
}
|
|
|
|
|
2013-04-09 09:43:24 -04:00
|
|
|
// fwd: LuaExpat/lxplib.c:
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
int luaopen_lxp(lua_State * L);
|
|
|
|
}
|
|
|
|
|
2013-04-07 15:28:32 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-01 14:55:42 -05:00
|
|
|
bool report_errors(lua_State * lua, int status)
|
|
|
|
{
|
|
|
|
if (status == 0)
|
|
|
|
{
|
|
|
|
// No error to report
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGERROR("LUA: %s", lua_tostring(lua, -1));
|
|
|
|
lua_pop(lua, 1);
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-28 11:54:11 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// cPlugin_NewLua:
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-28 11:54:11 -05:00
|
|
|
cPlugin_NewLua::cPlugin_NewLua(const AString & a_PluginDirectory)
|
2012-06-14 09:06:06 -04:00
|
|
|
: m_LuaState( 0 )
|
2012-08-22 10:22:21 -04:00
|
|
|
, cWebPlugin()
|
2013-01-28 11:54:11 -05:00
|
|
|
, cPlugin(a_PluginDirectory)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cPlugin_NewLua::~cPlugin_NewLua()
|
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
if( m_LuaState )
|
|
|
|
{
|
|
|
|
lua_close( m_LuaState );
|
|
|
|
m_LuaState = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-01 14:55:42 -05:00
|
|
|
bool cPlugin_NewLua::Initialize(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-02-01 14:55:42 -05:00
|
|
|
if (m_LuaState == NULL)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
m_LuaState = lua_open();
|
2013-02-01 14:55:42 -05:00
|
|
|
luaL_openlibs(m_LuaState);
|
2012-06-14 09:06:06 -04:00
|
|
|
tolua_AllToLua_open(m_LuaState);
|
2013-02-01 14:55:42 -05:00
|
|
|
ManualBindings::Bind(m_LuaState);
|
2013-04-07 15:28:32 -04:00
|
|
|
luaopen_lsqlite3(m_LuaState);
|
2013-04-09 09:43:24 -04:00
|
|
|
luaopen_lxp(m_LuaState);
|
2013-02-01 14:55:42 -05:00
|
|
|
|
|
|
|
// Inject the identification global variables into the state:
|
|
|
|
lua_pushlightuserdata(m_LuaState, this);
|
|
|
|
lua_setglobal(m_LuaState, LUA_PLUGIN_INSTANCE_VAR_NAME);
|
|
|
|
lua_pushstring(m_LuaState, GetName().c_str());
|
|
|
|
lua_setglobal(m_LuaState, LUA_PLUGIN_NAME_VAR_NAME);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2012-09-08 16:51:47 -04:00
|
|
|
std::string PluginPath = FILE_IO_PREFIX + GetLocalDirectory() + "/";
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// Load all files for this plugin, and execute them
|
|
|
|
AStringList Files = GetDirectoryContents(PluginPath.c_str());
|
|
|
|
for (AStringList::const_iterator itr = Files.begin(); itr != Files.end(); ++itr)
|
|
|
|
{
|
|
|
|
if (itr->rfind(".lua") == AString::npos)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
AString Path = PluginPath + *itr;
|
|
|
|
int s = luaL_loadfile(m_LuaState, Path.c_str() );
|
|
|
|
if( report_errors( m_LuaState, s ) )
|
|
|
|
{
|
2012-10-13 19:34:47 -04:00
|
|
|
LOGERROR("Can't load plugin %s because of an error in file %s", GetLocalDirectory().c_str(), Path.c_str() );
|
2012-06-14 09:06:06 -04:00
|
|
|
lua_close( m_LuaState );
|
|
|
|
m_LuaState = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = lua_pcall(m_LuaState, 0, LUA_MULTRET, 0);
|
|
|
|
if( report_errors( m_LuaState, s ) )
|
|
|
|
{
|
2012-10-13 19:34:47 -04:00
|
|
|
LOGERROR("Error in plugin %s in file %s", GetLocalDirectory().c_str(), Path.c_str() );
|
2012-06-14 09:06:06 -04:00
|
|
|
lua_close( m_LuaState );
|
|
|
|
m_LuaState = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} // for itr - Files[]
|
|
|
|
|
|
|
|
// Call intialize function
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!PushFunction("Initialize"))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
lua_close( m_LuaState );
|
|
|
|
m_LuaState = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, this, "cPlugin_NewLua");
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(1, 1, "Initialize"))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
lua_close( m_LuaState );
|
|
|
|
m_LuaState = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !lua_isboolean( m_LuaState, -1 ) )
|
|
|
|
{
|
2012-10-13 19:34:47 -04:00
|
|
|
LOGWARN("Error in plugin %s Initialize() must return a boolean value!", GetLocalDirectory().c_str() );
|
2012-06-14 09:06:06 -04:00
|
|
|
lua_close( m_LuaState );
|
|
|
|
m_LuaState = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bSuccess = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-06-14 09:06:06 -04:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPlugin_NewLua::OnDisable()
|
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
if (!PushFunction("OnDisable", false)) // false = don't log error if not found
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
CallFunction(0, 0, "OnDisable");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPlugin_NewLua::Tick(float a_Dt)
|
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_TICK);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
tolua_pushnumber( m_LuaState, a_Dt );
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
CallFunction(1, 0, FnName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-26 21:00:33 -05:00
|
|
|
bool cPlugin_NewLua::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_BLOCK_TO_PICKUPS);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_World, "cWorld");
|
|
|
|
tolua_pushusertype(m_LuaState, a_Digger, "cEntity");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockType);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockMeta);
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Pickups, "cItems");
|
|
|
|
|
|
|
|
if (!CallFunction(8, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-22 15:08:34 -04:00
|
|
|
bool cPlugin_NewLua::OnChat(cPlayer * a_Player, AString & a_Message)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHAT);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
|
|
|
|
tolua_pushstring (m_LuaState, a_Message.c_str());
|
|
|
|
|
2013-06-22 15:08:34 -04:00
|
|
|
if (!CallFunction(2, 2, FnName))
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-22 15:08:34 -04:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -2, 0) > 0);
|
|
|
|
if (lua_isstring(m_LuaState, -1))
|
|
|
|
{
|
|
|
|
a_Message = tolua_tostring(m_LuaState, -1, "");
|
|
|
|
}
|
|
|
|
lua_pop(m_LuaState, 2);
|
2013-01-11 23:46:01 -05:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-05 14:57:22 -05:00
|
|
|
bool cPlugin_NewLua::OnChunkAvailable(cWorld * a_World, int a_ChunkX, int a_ChunkZ)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-02-05 14:57:22 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_AVAILABLE);
|
2013-01-11 23:46:01 -05:00
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_World, "cWorld");
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkZ);
|
|
|
|
|
|
|
|
if (!CallFunction(3, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-05 14:57:22 -05:00
|
|
|
bool cPlugin_NewLua::OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_GENERATED);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_World, "cWorld");
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkZ);
|
|
|
|
tolua_pushusertype(m_LuaState, a_ChunkDesc, "cChunkDesc");
|
|
|
|
|
|
|
|
if (!CallFunction(4, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-25 05:12:29 -05:00
|
|
|
bool cPlugin_NewLua::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_pLuaChunk)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_GENERATING);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_World, "cWorld");
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkZ);
|
2013-01-25 05:12:29 -05:00
|
|
|
tolua_pushusertype(m_LuaState, a_pLuaChunk, "cChunkDesc");
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
if (!CallFunction(4, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-05 14:57:22 -05:00
|
|
|
bool cPlugin_NewLua::OnChunkUnloaded(cWorld * a_World, int a_ChunkX, int a_ChunkZ)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_UNLOADED);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_World, "cWorld");
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkZ);
|
|
|
|
|
|
|
|
if (!CallFunction(3, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cPlugin_NewLua::OnChunkUnloading(cWorld * a_World, int a_ChunkX, int a_ChunkZ)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_UNLOADING);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_World, "cWorld");
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_ChunkZ);
|
|
|
|
|
|
|
|
if (!CallFunction(3, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-28 11:17:26 -05:00
|
|
|
bool cPlugin_NewLua::OnCollectingPickup(cPlayer * a_Player, cPickup * a_Pickup)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-24 05:49:00 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-28 11:17:26 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_COLLECTING_PICKUP);
|
2013-01-11 23:46:01 -05:00
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-08-24 05:49:00 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-24 05:49:00 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
|
2012-08-24 05:49:00 -04:00
|
|
|
tolua_pushusertype(m_LuaState, a_Pickup, "cPickup");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(2, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cPlugin_NewLua::OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_CRAFTING_NO_RECIPE);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Grid, "cCraftingGrid");
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Recipe, "cCraftingRecipe");
|
|
|
|
|
|
|
|
if (!CallFunction(3, 1, FnName))
|
2012-08-24 05:49:00 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-24 05:49:00 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 15:42:32 -04:00
|
|
|
bool cPlugin_NewLua::OnDisconnect(cPlayer * a_Player, const AString & a_Reason)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-19 15:42:32 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_DISCONNECT);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
|
2012-08-19 15:42:32 -04:00
|
|
|
tolua_pushstring (m_LuaState, a_Reason.c_str());
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(2, 1, FnName))
|
2012-08-19 15:42:32 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-19 15:42:32 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-21 08:47:01 -05:00
|
|
|
bool cPlugin_NewLua::OnExecuteCommand(cPlayer * a_Player, const AStringVector & a_Split)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_EXECUTE_COMMAND);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
|
|
|
|
|
|
|
|
// Push the split:
|
|
|
|
lua_createtable(m_LuaState, a_Split.size(), 0);
|
|
|
|
int newTable = lua_gettop(m_LuaState);
|
|
|
|
int index = 1;
|
|
|
|
std::vector<std::string>::const_iterator iter = a_Split.begin(), end = a_Split.end();
|
|
|
|
while(iter != end)
|
|
|
|
{
|
|
|
|
tolua_pushstring(m_LuaState, (*iter).c_str());
|
|
|
|
lua_rawseti(m_LuaState, newTable, index);
|
|
|
|
++iter;
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CallFunction(2, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Username)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 05:56:28 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_HANDSHAKE);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-08-18 05:56:28 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-18 05:56:28 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, a_Client, "cClientHandle");
|
|
|
|
tolua_pushstring (m_LuaState, a_Username.c_str());
|
|
|
|
|
|
|
|
if (!CallFunction(2, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-01 06:39:56 -04:00
|
|
|
bool cPlugin_NewLua::OnKilling(cEntity & a_Victim, cEntity * a_Killer)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-28 11:54:11 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_KILLING);
|
2013-01-11 23:46:01 -05:00
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-01 06:39:56 -04:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Victim, "cEntity");
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, a_Killer, "cEntity");
|
|
|
|
|
|
|
|
if (!CallFunction(2, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cPlugin_NewLua::OnLogin(cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_LOGIN);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype (m_LuaState, a_Client, "cClientHandle");
|
|
|
|
tolua_pushnumber (m_LuaState, a_ProtocolVersion);
|
|
|
|
tolua_pushcppstring(m_LuaState, a_Username);
|
|
|
|
|
|
|
|
if (!CallFunction(3, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cPlugin_NewLua::OnPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_BREAKING_BLOCK);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
2012-08-18 05:56:28 -04:00
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushnumber (m_LuaState, a_BlockType);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockMeta);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(7, 1, FnName))
|
2012-08-18 05:56:28 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-18 05:56:28 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 05:56:28 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_BROKEN_BLOCK);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-08-18 05:56:28 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-18 05:56:28 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
2012-08-18 05:56:28 -04:00
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushnumber (m_LuaState, a_BlockType);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockMeta);
|
2012-08-18 05:56:28 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(7, 1, FnName))
|
2012-08-18 05:56:28 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-18 05:56:28 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerEating(cPlayer & a_Player)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 06:38:15 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_EATING);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-08-18 06:38:15 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-18 06:38:15 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(1, 1, FnName))
|
2012-08-18 06:38:15 -04:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2012-08-18 06:38:15 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerJoined(cPlayer & a_Player)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_JOINED);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(1, 1, FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 09:06:06 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_LEFT_CLICK);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
|
|
|
tolua_pushnumber (m_LuaState, a_Status);
|
|
|
|
|
|
|
|
if (!CallFunction(6, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerMoved(cPlayer & a_Player)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-26 02:50:06 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_MOVING);
|
2013-01-11 23:46:01 -05:00
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(1, 1, FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 09:06:06 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerPlacedBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_PLACED_BLOCK);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockType);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockMeta);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(10, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerPlacingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-21 06:04:08 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_PLACING_BLOCK);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-12-21 06:04:08 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockType);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockMeta);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(10, 1, FnName))
|
2012-12-21 06:04:08 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-12-21 06:04:08 -05:00
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerRightClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-18 13:28:27 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_RIGHT_CLICK);
|
2013-01-11 23:46:01 -05:00
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorZ);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(8, 1, FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 09:06:06 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-02 02:44:06 -04:00
|
|
|
bool cPlugin_NewLua::OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Entity, "cEntity");
|
|
|
|
|
|
|
|
if (!CallFunction(2, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerShooting(cPlayer & a_Player)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_SHOOTING);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
|
|
|
|
if (!CallFunction(1, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cPlugin_NewLua::OnPlayerSpawned(cPlayer & a_Player)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_SPAWNED);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
|
|
|
|
if (!CallFunction(1, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerTossingItem(cPlayer & a_Player)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_TOSSING_ITEM);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(1, 1, FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 09:06:06 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerUsedBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_USED_BLOCK);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockType);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockMeta);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(10, 1, FnName))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 09:06:06 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPlayerUsedItem(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_USED_ITEM);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorZ);
|
|
|
|
|
|
|
|
if (!CallFunction(8, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cPlugin_NewLua::OnPlayerUsingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_USING_BLOCK);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockType);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockMeta);
|
|
|
|
|
2013-05-25 08:03:20 -04:00
|
|
|
if (!CallFunction(10, 1, FnName))
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cPlugin_NewLua::OnPlayerUsingItem(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_USING_ITEM);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockFace);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_CursorZ);
|
|
|
|
|
|
|
|
if (!CallFunction(8, 1, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cPlugin_NewLua::OnPostCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_POST_CRAFTING);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Grid, "cCraftingGrid");
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Recipe, "cCraftingRecipe");
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(3, 1, FnName))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 09:06:06 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_PRE_CRAFTING);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Grid, "cCraftingGrid");
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Recipe, "cCraftingRecipe");
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(3, 1, FnName))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 09:06:06 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-01 06:39:56 -04:00
|
|
|
bool cPlugin_NewLua::OnTakeDamage(cEntity & a_Receiver, TakeDamageInfo & a_TDI)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_TAKE_DAMAGE);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-07-01 06:39:56 -04:00
|
|
|
tolua_pushusertype(m_LuaState, &a_Receiver, "cEntity");
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_TDI, "TakeDamageInfo");
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(2, 1, FnName))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) != 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 09:06:06 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::OnUpdatedSign(
|
|
|
|
cWorld * a_World,
|
|
|
|
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
|
|
|
|
)
|
2012-06-14 15:20:31 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_UPDATED_SIGN);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-06-14 15:20:31 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_World, "cWorld");
|
2013-01-11 23:46:01 -05:00
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushstring (m_LuaState, a_Line1.c_str());
|
|
|
|
tolua_pushstring (m_LuaState, a_Line2.c_str());
|
|
|
|
tolua_pushstring (m_LuaState, a_Line3.c_str());
|
|
|
|
tolua_pushstring (m_LuaState, a_Line4.c_str());
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
|
2012-06-14 15:20:31 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(9, 1, FnName))
|
2012-06-14 15:20:31 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 15:20:31 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-16 11:06:14 -04:00
|
|
|
bool cPlugin_NewLua::OnUpdatingSign(
|
|
|
|
cWorld * a_World,
|
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ,
|
2012-09-01 17:31:20 -04:00
|
|
|
AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4,
|
|
|
|
cPlayer * a_Player
|
2012-06-16 11:06:14 -04:00
|
|
|
)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_UPDATING_SIGN);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-06-16 11:06:14 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_World, "cWorld");
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockX);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockY);
|
|
|
|
tolua_pushnumber (m_LuaState, a_BlockZ);
|
|
|
|
tolua_pushstring (m_LuaState, a_Line1.c_str());
|
|
|
|
tolua_pushstring (m_LuaState, a_Line2.c_str());
|
|
|
|
tolua_pushstring (m_LuaState, a_Line3.c_str());
|
|
|
|
tolua_pushstring (m_LuaState, a_Line4.c_str());
|
2012-09-01 17:31:20 -04:00
|
|
|
tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
|
2012-06-16 11:06:14 -04:00
|
|
|
|
2012-09-01 17:31:20 -04:00
|
|
|
if (!CallFunction(9, 5, "OnUpdatingSign"))
|
2012-06-16 11:06:14 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-11 16:49:18 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -5, 0) > 0);
|
2012-06-16 11:06:14 -04:00
|
|
|
if (lua_isstring(m_LuaState, -4))
|
|
|
|
{
|
|
|
|
a_Line1 = tolua_tostring(m_LuaState, -4, "");
|
|
|
|
}
|
|
|
|
if (lua_isstring(m_LuaState, -3))
|
|
|
|
{
|
|
|
|
a_Line2 = tolua_tostring(m_LuaState, -3, "");
|
|
|
|
}
|
|
|
|
if (lua_isstring(m_LuaState, -2))
|
|
|
|
{
|
|
|
|
a_Line3 = tolua_tostring(m_LuaState, -2, "");
|
|
|
|
}
|
|
|
|
if (lua_isstring(m_LuaState, -1))
|
|
|
|
{
|
|
|
|
a_Line4 = tolua_tostring(m_LuaState, -1, "");
|
|
|
|
}
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-13 14:22:08 -05:00
|
|
|
bool cPlugin_NewLua::OnWeatherChanged(cWorld & a_World)
|
2012-06-16 11:06:14 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_WEATHER_CHANGED);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
2012-06-16 11:06:14 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-13 14:22:08 -05:00
|
|
|
tolua_pushusertype(m_LuaState, &a_World, "cWorld");
|
2012-06-16 11:06:14 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!CallFunction(1, 1, FnName))
|
2012-06-16 11:06:14 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
2012-10-11 16:49:18 -04:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-16 11:06:14 -04:00
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-13 14:22:08 -05:00
|
|
|
bool cPlugin_NewLua::OnWeatherChanging(cWorld & a_World, eWeather & a_NewWeather)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_WEATHER_CHANGED);
|
|
|
|
ASSERT(FnName != NULL);
|
|
|
|
if (!PushFunction(FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
tolua_pushusertype(m_LuaState, &a_World, "cWorld");
|
|
|
|
tolua_pushnumber (m_LuaState, a_NewWeather);
|
|
|
|
|
|
|
|
if (!CallFunction(2, 2, FnName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
if (lua_isnumber(m_LuaState, -2))
|
|
|
|
{
|
|
|
|
a_NewWeather = (eWeather)lua_tointeger(m_LuaState, -2);
|
|
|
|
}
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-01 14:55:42 -05:00
|
|
|
bool cPlugin_NewLua::HandleCommand(const AStringVector & a_Split, cPlayer * a_Player)
|
|
|
|
{
|
|
|
|
ASSERT(!a_Split.empty());
|
|
|
|
CommandMap::iterator cmd = m_Commands.find(a_Split[0]);
|
|
|
|
if (cmd == m_Commands.end())
|
|
|
|
{
|
2013-02-15 08:00:59 -05:00
|
|
|
LOGWARNING("Command handler is registered in cPluginManager but not in cPlugin, wtf? Command \"%s\".", a_Split[0].c_str());
|
2013-02-01 14:55:42 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
|
|
|
|
// Push the function to be called:
|
|
|
|
lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, cmd->second); // same as lua_getref()
|
|
|
|
|
|
|
|
// Push the split:
|
|
|
|
lua_createtable(m_LuaState, a_Split.size(), 0);
|
|
|
|
int newTable = lua_gettop(m_LuaState);
|
|
|
|
int index = 1;
|
|
|
|
std::vector<std::string>::const_iterator iter = a_Split.begin(), end = a_Split.end();
|
|
|
|
while(iter != end)
|
|
|
|
{
|
|
|
|
tolua_pushstring(m_LuaState, (*iter).c_str());
|
|
|
|
lua_rawseti(m_LuaState, newTable, index);
|
|
|
|
++iter;
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push player:
|
|
|
|
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
|
|
|
|
|
|
|
|
// Call function:
|
|
|
|
int s = lua_pcall(m_LuaState, 2, 1, 0);
|
|
|
|
if (report_errors(m_LuaState, s))
|
|
|
|
{
|
2013-02-21 08:47:01 -05:00
|
|
|
LOGERROR("LUA error in %s. Stack size: %i", __FUNCTION__, lua_gettop(m_LuaState));
|
2013-02-01 14:55:42 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle return value:
|
|
|
|
bool RetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 1); // Pop return value
|
|
|
|
|
|
|
|
return RetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
bool cPlugin_NewLua::HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output)
|
2013-02-15 08:00:59 -05:00
|
|
|
{
|
|
|
|
ASSERT(!a_Split.empty());
|
|
|
|
CommandMap::iterator cmd = m_ConsoleCommands.find(a_Split[0]);
|
|
|
|
if (cmd == m_ConsoleCommands.end())
|
|
|
|
{
|
2013-06-29 11:30:05 -04:00
|
|
|
LOGWARNING("Console command handler is registered in cPluginManager but not in cPlugin, wtf? Console command \"%s\", plugin \"%s\".",
|
|
|
|
a_Split[0].c_str(), GetName().c_str()
|
|
|
|
);
|
2013-02-15 08:00:59 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
|
|
|
|
// Push the function to be called:
|
|
|
|
lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, cmd->second); // same as lua_getref()
|
|
|
|
|
|
|
|
// Push the split:
|
|
|
|
lua_createtable(m_LuaState, a_Split.size(), 0);
|
|
|
|
int newTable = lua_gettop(m_LuaState);
|
|
|
|
int index = 1;
|
|
|
|
std::vector<std::string>::const_iterator iter = a_Split.begin(), end = a_Split.end();
|
|
|
|
while(iter != end)
|
|
|
|
{
|
|
|
|
tolua_pushstring(m_LuaState, (*iter).c_str());
|
|
|
|
lua_rawseti(m_LuaState, newTable, index);
|
|
|
|
++iter;
|
|
|
|
++index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call function:
|
2013-06-29 11:30:05 -04:00
|
|
|
int s = lua_pcall(m_LuaState, 1, 2, 0);
|
2013-02-15 08:00:59 -05:00
|
|
|
if (report_errors(m_LuaState, s))
|
|
|
|
{
|
|
|
|
LOGERROR("Lua error. Stack size: %i", lua_gettop(m_LuaState));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-29 11:30:05 -04:00
|
|
|
// Handle return values:
|
|
|
|
if (lua_isstring(m_LuaState, -1))
|
|
|
|
{
|
|
|
|
AString str = tolua_tocppstring(m_LuaState, -1, "");
|
|
|
|
a_Output.Out(str);
|
|
|
|
}
|
|
|
|
bool RetVal = (tolua_toboolean(m_LuaState, -2, 0) > 0);
|
|
|
|
lua_pop(m_LuaState, 2); // Pop return values
|
2013-02-15 08:00:59 -05:00
|
|
|
|
|
|
|
return RetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-01 14:55:42 -05:00
|
|
|
void cPlugin_NewLua::ClearCommands(void)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
|
|
|
|
// Unreference the bound functions so that Lua can GC them
|
|
|
|
if (m_LuaState != NULL)
|
|
|
|
{
|
|
|
|
for (CommandMap::iterator itr = m_Commands.begin(), end = m_Commands.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
luaL_unref(m_LuaState, LUA_REGISTRYINDEX, itr->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_Commands.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-15 08:00:59 -05:00
|
|
|
void cPlugin_NewLua::ClearConsoleCommands(void)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
|
|
|
|
// Unreference the bound functions so that Lua can GC them
|
|
|
|
if (m_LuaState != NULL)
|
|
|
|
{
|
|
|
|
for (CommandMap::iterator itr = m_ConsoleCommands.begin(), end = m_ConsoleCommands.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
luaL_unref(m_LuaState, LUA_REGISTRYINDEX, itr->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_ConsoleCommands.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::CanAddHook(cPluginManager::PluginHook a_Hook)
|
2012-09-05 16:30:27 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
const char * FnName = GetHookFnName(a_Hook);
|
|
|
|
if (FnName == NULL)
|
2012-09-05 16:30:27 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
// Unknown hook ID
|
|
|
|
LOGWARNING("Plugin %s wants to add an unknown hook ID (%d). The plugin need not work properly.", GetName().c_str(), a_Hook);
|
2012-09-05 16:30:27 -04:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
// Check if the function is available
|
|
|
|
lua_getglobal(m_LuaState, FnName);
|
|
|
|
bool res = lua_isfunction(m_LuaState, -1);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
|
|
|
|
if (res)
|
2012-09-05 16:30:27 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
return true;
|
2012-09-05 16:30:27 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
LOGWARNING("Plugin %s wants to add a hook (%d), but it doesn't provide the callback function \"%s\" for it. The plugin need not work properly.",
|
|
|
|
GetName().c_str(), a_Hook, FnName
|
|
|
|
);
|
|
|
|
|
|
|
|
// Lua stacktrace:
|
|
|
|
LOGWARNING("Stack trace:");
|
|
|
|
lua_Debug entry;
|
|
|
|
int depth = 0;
|
|
|
|
while (lua_getstack(m_LuaState, depth, &entry))
|
|
|
|
{
|
|
|
|
int status = lua_getinfo(m_LuaState, "Sln", &entry);
|
|
|
|
assert(status);
|
2012-09-05 16:30:27 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
LOGWARNING(" %s(%d): %s", entry.short_src, entry.currentline, entry.name ? entry.name : "?");
|
|
|
|
depth++;
|
|
|
|
}
|
|
|
|
LOGWARNING("Stack trace end");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char * cPlugin_NewLua::GetHookFnName(cPluginManager::PluginHook a_Hook)
|
|
|
|
{
|
|
|
|
switch (a_Hook)
|
|
|
|
{
|
2013-08-02 02:44:06 -04:00
|
|
|
case cPluginManager::HOOK_BLOCK_TO_PICKUPS: return "OnBlockToPickups";
|
|
|
|
case cPluginManager::HOOK_CHAT: return "OnChat";
|
|
|
|
case cPluginManager::HOOK_CHUNK_AVAILABLE: return "OnChunkAvailable";
|
|
|
|
case cPluginManager::HOOK_CHUNK_GENERATED: return "OnChunkGenerated";
|
|
|
|
case cPluginManager::HOOK_CHUNK_GENERATING: return "OnChunkGenerating";
|
|
|
|
case cPluginManager::HOOK_CHUNK_UNLOADED: return "OnChunkUnloaded";
|
|
|
|
case cPluginManager::HOOK_CHUNK_UNLOADING: return "OnChunkUnloading";
|
|
|
|
case cPluginManager::HOOK_COLLECTING_PICKUP: return "OnCollectingPickup";
|
|
|
|
case cPluginManager::HOOK_CRAFTING_NO_RECIPE: return "OnCraftingNoRecipe";
|
|
|
|
case cPluginManager::HOOK_DISCONNECT: return "OnDisconnect";
|
|
|
|
case cPluginManager::HOOK_EXECUTE_COMMAND: return "OnExecuteCommand";
|
|
|
|
case cPluginManager::HOOK_HANDSHAKE: return "OnHandshake";
|
|
|
|
case cPluginManager::HOOK_KILLING: return "OnKilling";
|
|
|
|
case cPluginManager::HOOK_LOGIN: return "OnLogin";
|
|
|
|
case cPluginManager::HOOK_PLAYER_BREAKING_BLOCK: return "OnPlayerBreakingBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_BROKEN_BLOCK: return "OnPlayerBrokenBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_EATING: return "OnPlayerEating";
|
|
|
|
case cPluginManager::HOOK_PLAYER_JOINED: return "OnPlayerJoined";
|
|
|
|
case cPluginManager::HOOK_PLAYER_LEFT_CLICK: return "OnPlayerLeftClick";
|
|
|
|
case cPluginManager::HOOK_PLAYER_MOVING: return "OnPlayerMoving";
|
|
|
|
case cPluginManager::HOOK_PLAYER_PLACED_BLOCK: return "OnPlayerPlacedBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_PLACING_BLOCK: return "OnPlayerPlacingBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_RIGHT_CLICK: return "OnPlayerRightClick";
|
|
|
|
case cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY: return "OnPlayerRightClickingEntity";
|
|
|
|
case cPluginManager::HOOK_PLAYER_SHOOTING: return "OnPlayerShooting";
|
|
|
|
case cPluginManager::HOOK_PLAYER_SPAWNED: return "OnPlayerSpawned";
|
|
|
|
case cPluginManager::HOOK_PLAYER_TOSSING_ITEM: return "OnPlayerTossingItem";
|
|
|
|
case cPluginManager::HOOK_PLAYER_USED_BLOCK: return "OnPlayerUsedBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_USED_ITEM: return "OnPlayerUsedItem";
|
|
|
|
case cPluginManager::HOOK_PLAYER_USING_BLOCK: return "OnPlayerUsingBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_USING_ITEM: return "OnPlayerUsingItem";
|
|
|
|
case cPluginManager::HOOK_POST_CRAFTING: return "OnPostCrafting";
|
|
|
|
case cPluginManager::HOOK_PRE_CRAFTING: return "OnPreCrafting";
|
|
|
|
case cPluginManager::HOOK_TAKE_DAMAGE: return "OnTakeDamage";
|
|
|
|
case cPluginManager::HOOK_TICK: return "OnTick";
|
|
|
|
case cPluginManager::HOOK_UPDATED_SIGN: return "OnUpdatedSign";
|
|
|
|
case cPluginManager::HOOK_UPDATING_SIGN: return "OnUpdatingSign";
|
|
|
|
case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged";
|
|
|
|
case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging";
|
2013-01-11 23:46:01 -05:00
|
|
|
default: return NULL;
|
|
|
|
} // switch (a_Hook)
|
2012-09-05 16:30:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
AString cPlugin_NewLua::HandleWebRequest(const HTTPRequest * a_Request )
|
2012-08-22 10:22:21 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2012-08-22 10:22:21 -04:00
|
|
|
std::string RetVal = "";
|
|
|
|
|
|
|
|
std::pair< std::string, std::string > TabName = GetTabNameForRequest(a_Request);
|
|
|
|
std::string SafeTabName = TabName.second;
|
|
|
|
if( SafeTabName.empty() )
|
|
|
|
return "";
|
|
|
|
|
|
|
|
sWebPluginTab* Tab = 0;
|
|
|
|
for( TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr )
|
|
|
|
{
|
|
|
|
if( (*itr)->SafeTitle.compare( SafeTabName ) == 0 ) // This is the one! Rawr
|
|
|
|
{
|
|
|
|
Tab = *itr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Tab )
|
|
|
|
{
|
|
|
|
//LOGINFO("1. Stack size: %i", lua_gettop(m_LuaState) );
|
|
|
|
lua_rawgeti( m_LuaState, LUA_REGISTRYINDEX, Tab->UserData); // same as lua_getref()
|
|
|
|
|
|
|
|
//LOGINFO("2. Stack size: %i", lua_gettop(m_LuaState) );
|
|
|
|
// Push HTTPRequest
|
2013-07-28 20:37:59 -04:00
|
|
|
tolua_pushusertype( m_LuaState, (void*)a_Request, "const HTTPRequest" );
|
2012-08-22 10:22:21 -04:00
|
|
|
//LOGINFO("Calling bound function! :D");
|
|
|
|
int s = lua_pcall( m_LuaState, 1, 1, 0);
|
|
|
|
|
|
|
|
if ( s != 0 )
|
|
|
|
{
|
|
|
|
std::string err = lua_tostring(m_LuaState, -1);
|
|
|
|
LOGERROR("-- %s", err.c_str() );
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
LOGINFO("error. Stack size: %i", lua_gettop(m_LuaState) );
|
|
|
|
return err; // Show the error message in the web page, looks cool
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !lua_isstring( m_LuaState, -1 ) )
|
|
|
|
{
|
|
|
|
LOGWARN("WARNING: WebPlugin tab '%s' did not return a string!", Tab->Title.c_str() );
|
|
|
|
lua_pop(m_LuaState, 1); // Pop return value
|
|
|
|
return std::string("WARNING: WebPlugin tab '") + Tab->Title + std::string("' did not return a string!");
|
|
|
|
}
|
|
|
|
|
|
|
|
RetVal += tolua_tostring(m_LuaState, -1, 0);
|
|
|
|
lua_pop(m_LuaState, 1); // Pop return value
|
|
|
|
//LOGINFO("ok. Stack size: %i", lua_gettop(m_LuaState) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return RetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cPlugin_NewLua::AddWebTab( const AString & a_Title, lua_State * a_LuaState, int a_FunctionReference )
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
if (a_LuaState != m_LuaState)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-22 10:22:21 -04:00
|
|
|
LOGERROR("Only allowed to add a tab to a WebPlugin of your own Plugin!");
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
sWebPluginTab * Tab = new sWebPluginTab();
|
2012-08-22 10:22:21 -04:00
|
|
|
Tab->Title = a_Title;
|
2013-01-11 23:46:01 -05:00
|
|
|
Tab->SafeTitle = SafeString(a_Title);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-22 10:22:21 -04:00
|
|
|
Tab->UserData = a_FunctionReference;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-22 10:22:21 -04:00
|
|
|
GetTabs().push_back( Tab );
|
|
|
|
return true;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 10:22:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-01 14:55:42 -05:00
|
|
|
void cPlugin_NewLua::BindCommand(const AString & a_Command, int a_FnRef)
|
|
|
|
{
|
|
|
|
ASSERT(m_Commands.find(a_Command) == m_Commands.end());
|
|
|
|
m_Commands[a_Command] = a_FnRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-15 08:00:59 -05:00
|
|
|
void cPlugin_NewLua::BindConsoleCommand(const AString & a_Command, int a_FnRef)
|
|
|
|
{
|
|
|
|
ASSERT(m_ConsoleCommands.find(a_Command) == m_ConsoleCommands.end());
|
|
|
|
m_ConsoleCommands[a_Command] = a_FnRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-30 15:34:09 -04:00
|
|
|
void cPlugin_NewLua::Unreference(int a_LuaRef)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
luaL_unref(m_LuaState, LUA_REGISTRYINDEX, a_LuaRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-02 17:59:25 -04:00
|
|
|
bool cPlugin_NewLua::CallbackWindowClosing(int a_FnRef, cWindow & a_Window, cPlayer & a_Player, bool a_CanRefuse)
|
2013-05-30 16:40:43 -04:00
|
|
|
{
|
2013-05-31 03:16:14 -04:00
|
|
|
ASSERT(a_FnRef != LUA_REFNIL);
|
|
|
|
|
2013-05-30 16:40:43 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_FnRef); // Push the function to be called
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Window, "cWindow");
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Player, "cPlayer");
|
2013-06-02 17:59:25 -04:00
|
|
|
tolua_pushboolean (m_LuaState, a_CanRefuse ? 1 : 0);
|
2013-05-30 16:40:43 -04:00
|
|
|
|
|
|
|
// Call function:
|
2013-06-02 17:59:25 -04:00
|
|
|
int s = lua_pcall(m_LuaState, 3, 1, 0);
|
2013-05-30 16:40:43 -04:00
|
|
|
if (report_errors(m_LuaState, s))
|
|
|
|
{
|
|
|
|
LOGERROR("LUA error in %s. Stack size: %i", __FUNCTION__, lua_gettop(m_LuaState));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bRetVal = (tolua_toboolean(m_LuaState, -1, false) > 0);
|
|
|
|
lua_pop(m_LuaState, 1);
|
|
|
|
return bRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-31 03:16:14 -04:00
|
|
|
void cPlugin_NewLua::CallbackWindowSlotChanged(int a_FnRef, cWindow & a_Window, int a_SlotNum)
|
|
|
|
{
|
|
|
|
ASSERT(a_FnRef != LUA_REFNIL);
|
|
|
|
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
lua_rawgeti(m_LuaState, LUA_REGISTRYINDEX, a_FnRef); // Push the function to be called
|
|
|
|
tolua_pushusertype(m_LuaState, &a_Window, "cWindow");
|
|
|
|
tolua_pushnumber (m_LuaState, a_SlotNum);
|
|
|
|
|
|
|
|
// Call function:
|
|
|
|
int s = lua_pcall(m_LuaState, 2, 0, 0);
|
|
|
|
if (report_errors(m_LuaState, s))
|
|
|
|
{
|
|
|
|
LOGERROR("LUA error in %s. Stack size: %i", __FUNCTION__, lua_gettop(m_LuaState));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
// Helper functions
|
2013-01-11 23:46:01 -05:00
|
|
|
bool cPlugin_NewLua::PushFunction(const char * a_FunctionName, bool a_bLogError /* = true */)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-02-01 14:55:42 -05:00
|
|
|
if (m_LuaState == NULL)
|
|
|
|
{
|
|
|
|
// This happens if Initialize() fails with an error
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
lua_getglobal(m_LuaState, a_FunctionName);
|
2013-01-11 23:46:01 -05:00
|
|
|
if (!lua_isfunction(m_LuaState, -1))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
if (a_bLogError)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
LOGWARN("Error in plugin %s: Could not find function %s()", GetName().c_str(), a_FunctionName);
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
lua_pop(m_LuaState, 1);
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-21 08:47:01 -05:00
|
|
|
bool cPlugin_NewLua::CallFunction( int a_NumArgs, int a_NumResults, const char * a_FunctionName)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-02-21 08:47:01 -05:00
|
|
|
ASSERT(lua_isfunction(m_LuaState, -a_NumArgs - 1));
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
int s = lua_pcall(m_LuaState, a_NumArgs, a_NumResults, 0);
|
2013-01-11 23:46:01 -05:00
|
|
|
if (report_errors(m_LuaState, s))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
LOGWARN("Error in plugin %s calling function %s()", GetName().c_str(), a_FunctionName);
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|