summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings')
-rw-r--r--src/Bindings/CMakeLists.txt2
-rw-r--r--src/Bindings/LuaState.cpp86
-rw-r--r--src/Bindings/LuaState.h10
-rw-r--r--src/Bindings/ManualBindings.cpp179
-rw-r--r--src/Bindings/ManualBindings_RankManager.cpp318
-rw-r--r--src/Bindings/PluginLua.cpp5
6 files changed, 546 insertions, 54 deletions
diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt
index 4cc73b350..366284fcb 100644
--- a/src/Bindings/CMakeLists.txt
+++ b/src/Bindings/CMakeLists.txt
@@ -142,5 +142,5 @@ set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPER
if(NOT MSVC)
add_library(Bindings ${SRCS} ${HDRS})
- target_link_libraries(Bindings lua sqlite tolualib polarssl)
+ target_link_libraries(Bindings lua sqlite tolualib mbedtls)
endif()
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 38e008b2a..9c1e2865c 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -937,6 +937,18 @@ void cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
+void cLuaState::GetStackValue(int a_StackPos, BLOCKTYPE & a_ReturnedVal)
+{
+ if (lua_isnumber(m_LuaState, a_StackPos))
+ {
+ a_ReturnedVal = static_cast<BLOCKTYPE>(tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal));
+ }
+}
+
+
+
+
+
void cLuaState::GetStackValue(int a_StackPos, bool & a_ReturnedVal)
{
a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);
@@ -995,6 +1007,24 @@ void cLuaState::GetStackValue(int a_StackPos, int & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, pBlockArea & a_ReturnedVal)
+{
+ if (lua_isnil(m_LuaState, a_StackPos))
+ {
+ a_ReturnedVal = nullptr;
+ return;
+ }
+ tolua_Error err;
+ if (tolua_isusertype(m_LuaState, a_StackPos, "cBlockArea", false, &err))
+ {
+ a_ReturnedVal = *(reinterpret_cast<cBlockArea **>(lua_touserdata(m_LuaState, a_StackPos)));
+ }
+}
+
+
+
+
+
void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal)
{
if (lua_isnil(m_LuaState, a_StackPos))
@@ -1005,7 +1035,7 @@ void cLuaState::GetStackValue(int a_StackPos, pBoundingBox & a_ReturnedVal)
tolua_Error err;
if (tolua_isusertype(m_LuaState, a_StackPos, "cBoundingBox", false, &err))
{
- a_ReturnedVal = *((cBoundingBox **)lua_touserdata(m_LuaState, a_StackPos));
+ a_ReturnedVal = *(reinterpret_cast<cBoundingBox **>(lua_touserdata(m_LuaState, a_StackPos)));
}
}
@@ -1103,6 +1133,23 @@ void cLuaState::GetStackValue(int a_StackPos, pWorld & a_ReturnedVal)
+void cLuaState::GetStackValue(int a_StackPos, pClientHandle & a_ReturnedVal)
+{
+ if (lua_isnil(m_LuaState, a_StackPos))
+ {
+ a_ReturnedVal = nullptr;
+ return;
+ }
+ tolua_Error err;
+ if (tolua_isusertype(m_LuaState, a_StackPos, "cClientHandle", false, &err))
+ {
+ a_ReturnedVal = *(reinterpret_cast<cClientHandle **>(lua_touserdata(m_LuaState, a_StackPos)));
+ }
+}
+
+
+
+
bool cLuaState::CallFunction(int a_NumResults)
{
ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -1385,6 +1432,30 @@ bool cLuaState::CheckParamEnd(int a_Param)
+bool cLuaState::IsParamUserType(int a_Param, AString a_UserType)
+{
+ ASSERT(IsValid());
+
+ tolua_Error tolua_err;
+ return tolua_isusertype(m_LuaState, a_Param, a_UserType.c_str(), 0, &tolua_err);
+}
+
+
+
+
+
+bool cLuaState::IsParamNumber(int a_Param)
+{
+ ASSERT(IsValid());
+
+ tolua_Error tolua_err;
+ return tolua_isnumber(m_LuaState, a_Param, 0, &tolua_err);
+}
+
+
+
+
+
bool cLuaState::ReportErrors(int a_Status)
{
return ReportErrors(m_LuaState, a_Status);
@@ -1464,7 +1535,7 @@ int cLuaState::CallFunctionWithForeignParams(
if (!PushFunction(a_FunctionName.c_str()))
{
LOGWARNING("Function '%s' not found", a_FunctionName.c_str());
- lua_pop(m_LuaState, 2);
+ lua_settop(m_LuaState, OldTop);
return -1;
}
@@ -1472,7 +1543,7 @@ int cLuaState::CallFunctionWithForeignParams(
if (CopyStackFrom(a_SrcLuaState, a_SrcParamStart, a_SrcParamEnd) < 0)
{
// Something went wrong, fix the stack and exit
- lua_pop(m_LuaState, 2);
+ lua_settop(m_LuaState, OldTop);
m_NumCurrentFunctionArgs = -1;
m_CurrentFunctionName.clear();
return -1;
@@ -1483,13 +1554,8 @@ int cLuaState::CallFunctionWithForeignParams(
if (ReportErrors(s))
{
LOGWARN("Error while calling function '%s' in '%s'", a_FunctionName.c_str(), m_SubsystemName.c_str());
- // Fix the stack.
- // We don't know how many values have been pushed, so just get rid of any that weren't there initially
- int CurTop = lua_gettop(m_LuaState);
- if (CurTop > OldTop)
- {
- lua_pop(m_LuaState, CurTop - OldTop);
- }
+ // Reset the stack:
+ lua_settop(m_LuaState, OldTop);
// Reset the internal checking mechanisms:
m_NumCurrentFunctionArgs = -1;
diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h
index a6e121eb7..3f2e828f3 100644
--- a/src/Bindings/LuaState.h
+++ b/src/Bindings/LuaState.h
@@ -37,6 +37,7 @@ extern "C"
+class cBlockArea;
class cBlockEntity;
class cBoundingBox;
class cChunkDesc;
@@ -68,12 +69,14 @@ struct HTTPRequest;
struct HTTPTemplateRequest;
struct TakeDamageInfo;
+typedef cBlockArea * pBlockArea;
typedef cBoundingBox * pBoundingBox;
typedef cMapManager * pMapManager;
typedef cPluginManager * pPluginManager;
typedef cRoot * pRoot;
typedef cScoreboard * pScoreboard;
typedef cWorld * pWorld;
+typedef cClientHandle * pClientHandle;
@@ -244,12 +247,15 @@ public:
// GetStackValue() retrieves the value at a_StackPos, if it is a valid type. If not, a_Value is unchanged.
// Enum values are clamped to their allowed range.
void GetStackValue(int a_StackPos, AString & a_Value);
+ void GetStackValue(int a_StackPos, BLOCKTYPE & a_Value);
void GetStackValue(int a_StackPos, bool & a_Value);
void GetStackValue(int a_StackPos, cRef & a_Ref);
void GetStackValue(int a_StackPos, double & a_Value);
void GetStackValue(int a_StackPos, eWeather & a_Value);
void GetStackValue(int a_StackPos, int & a_Value);
+ void GetStackValue(int a_StackPos, pBlockArea & a_Value);
void GetStackValue(int a_StackPos, pBoundingBox & a_Value);
+ void GetStackValue(int a_StackPos, pClientHandle & a_Value);
void GetStackValue(int a_StackPos, pMapManager & a_Value);
void GetStackValue(int a_StackPos, pPluginManager & a_Value);
void GetStackValue(int a_StackPos, pRoot & a_Value);
@@ -303,6 +309,10 @@ public:
/** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */
bool CheckParamEnd(int a_Param);
+ bool IsParamUserType(int a_Param, AString a_UserType);
+
+ bool IsParamNumber(int a_Param);
+
/** If the status is nonzero, prints the text on the top of Lua stack and returns true */
bool ReportErrors(int status);
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 253d57297..20042a780 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -32,9 +32,10 @@
#include "../WorldStorage/SchematicFileSerializer.h"
#include "../CompositeChat.h"
#include "../StringCompression.h"
+#include "../Broadcaster.h"
-
+#include <array>
// Better error reporting for Lua
@@ -253,12 +254,13 @@ static int tolua_InflateString(lua_State * tolua_S)
static int tolua_StringSplit(lua_State * tolua_S)
{
+ // Get the params:
cLuaState LuaState(tolua_S);
- std::string str = (std::string)tolua_tocppstring(LuaState, 1, 0);
- std::string delim = (std::string)tolua_tocppstring(LuaState, 2, 0);
+ AString str, delim;
+ LuaState.GetStackValues(1, str, delim);
- AStringVector Split = StringSplit(str, delim);
- LuaState.Push(Split);
+ // Execute and push the result:
+ LuaState.Push(StringSplit(str, delim));
return 1;
}
@@ -472,6 +474,33 @@ cPluginLua * GetLuaPlugin(lua_State * L)
static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
{
+ // Check params:
+ cLuaState LuaState(tolua_S);
+ if (
+ !LuaState.CheckParamUserTable(1, "cFile") ||
+ !LuaState.CheckParamString (2) ||
+ !LuaState.CheckParamEnd (3)
+ )
+ {
+ return 0;
+ }
+
+ // Get params:
+ AString Folder;
+ LuaState.GetStackValues(2, Folder);
+
+ // Execute and push result:
+ LuaState.Push(cFile::GetFolderContents(Folder));
+ return 1;
+}
+
+
+
+
+
+static int tolua_cFile_ReadWholeFile(lua_State * tolua_S)
+{
+ // Check params:
cLuaState LuaState(tolua_S);
if (
!LuaState.CheckParamUserTable(1, "cFile") ||
@@ -482,10 +511,12 @@ static int tolua_cFile_GetFolderContents(lua_State * tolua_S)
return 0;
}
- AString Folder = (AString)tolua_tocppstring(LuaState, 2, 0);
+ // Get params:
+ AString FileName;
+ LuaState.GetStackValues(2, FileName);
- AStringVector Contents = cFile::GetFolderContents(Folder);
- LuaState.Push(Contents);
+ // Execute and push result:
+ LuaState.Push(cFile::ReadWholeFile(FileName));
return 1;
}
@@ -1957,6 +1988,11 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
{
return 0;
}
+ if (Callback.m_NumReturns < 0)
+ {
+ // The call has failed, there are zero return values. Do NOT return negative number (Lua considers that a "yield")
+ return 0;
+ }
return Callback.m_NumReturns;
}
@@ -1979,6 +2015,60 @@ static int tolua_cPluginManager_FindPlugins(lua_State * tolua_S)
+static int tolua_cWorld_BroadcastParticleEffect(lua_State * tolua_S)
+{
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cWorld") ||
+ !L.CheckParamString (2) ||
+ !L.CheckParamNumber (3, 10)
+ )
+ {
+ return 0;
+ }
+
+ cPluginLua * Plugin = GetLuaPlugin(tolua_S);
+ if (Plugin == nullptr)
+ {
+ return 0;
+ }
+
+ // Read the params:
+ cWorld * World = nullptr;
+ AString Name;
+ double PosX, PosY, PosZ, OffX, OffY, OffZ;
+ double ParticleData;
+ int ParticleAmmount;
+ L.GetStackValues(1, World, Name, PosX, PosY, PosZ, OffX, OffY, OffZ, ParticleData, ParticleAmmount);
+ if (World == nullptr)
+ {
+ LOGWARNING("World:BroadcastParticleEffect(): invalid world parameter");
+ L.LogStackTrace();
+ return 0;
+ }
+
+ std::array<int, 2> data;
+
+ for (int i = 0; (i < 2) && L.IsParamNumber(11 + i); i++)
+ {
+ L.GetStackValue(11 + i, data[i]);
+ }
+
+ cClientHandle * Exclude = nullptr;
+
+ if (L.IsParamUserType(11, "cClientHandle"))
+ {
+ L.GetStackValue(11, Exclude);
+ }
+ World->GetBroadcaster().BroadcastParticleEffect(Name, Vector3f(PosX, PosY, PosZ), Vector3f(OffX, OffY, OffZ), ParticleData, ParticleAmmount, Exclude);
+
+ return 0;
+}
+
+
+
+
+
static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
{
/* Function signature:
@@ -2125,6 +2215,37 @@ static int tolua_cPlayer_GetPermissions(lua_State * tolua_S)
+static int tolua_cPlayer_GetRestrictions(lua_State * tolua_S)
+{
+ // Function signature: cPlayer:GetRestrictions() -> {restrictions-array}
+
+ // Check the params:
+ cLuaState L(tolua_S);
+ if (
+ !L.CheckParamUserType(1, "cPlayer") ||
+ !L.CheckParamEnd (2)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ cPlayer * self = (cPlayer *)tolua_tousertype(tolua_S, 1, nullptr);
+ if (self == nullptr)
+ {
+ LOGWARNING("%s: invalid self (%p)", __FUNCTION__, self);
+ return 0;
+ }
+
+ // Push the permissions:
+ L.Push(self->GetRestrictions());
+ return 1;
+}
+
+
+
+
+
static int tolua_cPlayer_OpenWindow(lua_State * tolua_S)
{
// Function signature: cPlayer:OpenWindow(Window)
@@ -3156,6 +3277,44 @@ static int tolua_cBlockArea_GetOrigin(lua_State * tolua_S)
+static int tolua_cBlockArea_GetNonAirCropRelCoords(lua_State * tolua_S)
+{
+ // function cBlockArea::GetNonAirCropRelCoords()
+ // Exported manually because tolua would generate extra input params for the outputs
+
+ cLuaState L(tolua_S);
+ if (!L.CheckParamUserType(1, "cBlockArea"))
+ {
+ return 0;
+ }
+
+ cBlockArea * self = nullptr;
+ BLOCKTYPE IgnoreBlockType = E_BLOCK_AIR;
+ L.GetStackValues(1, self, IgnoreBlockType);
+ if (self == nullptr)
+ {
+ tolua_error(tolua_S, "invalid 'self' in function 'cBlockArea:GetNonAirCropRelCoords'", nullptr);
+ return 0;
+ }
+
+ // Calculate the crop coords:
+ int MinRelX, MinRelY, MinRelZ, MaxRelX, MaxRelY, MaxRelZ;
+ self->GetNonAirCropRelCoords(MinRelX, MinRelY, MinRelZ, MaxRelX, MaxRelY, MaxRelZ, IgnoreBlockType);
+
+ // Push the six crop coords:
+ L.Push(MinRelX);
+ L.Push(MinRelY);
+ L.Push(MinRelZ);
+ L.Push(MaxRelX);
+ L.Push(MaxRelY);
+ L.Push(MaxRelZ);
+ return 6;
+}
+
+
+
+
+
static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * tolua_S)
{
// function cBlockArea::GetRelBlockTypeMeta()
@@ -3650,12 +3809,14 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cFile");
tolua_function(tolua_S, "GetFolderContents", tolua_cFile_GetFolderContents);
+ tolua_function(tolua_S, "ReadWholeFile", tolua_cFile_ReadWholeFile);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cBlockArea");
tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cBlockArea_GetBlockTypeMeta);
tolua_function(tolua_S, "GetCoordRange", tolua_cBlockArea_GetCoordRange);
tolua_function(tolua_S, "GetOrigin", tolua_cBlockArea_GetOrigin);
+ tolua_function(tolua_S, "GetNonAirCropRelCoords", tolua_cBlockArea_GetNonAirCropRelCoords);
tolua_function(tolua_S, "GetRelBlockTypeMeta", tolua_cBlockArea_GetRelBlockTypeMeta);
tolua_function(tolua_S, "GetSize", tolua_cBlockArea_GetSize);
tolua_function(tolua_S, "LoadFromSchematicFile", tolua_cBlockArea_LoadFromSchematicFile);
@@ -3691,6 +3852,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cWorld");
+ tolua_function(tolua_S, "BroadcastParticleEffect", tolua_cWorld_BroadcastParticleEffect);
tolua_function(tolua_S, "ChunkStay", tolua_cWorld_ChunkStay);
tolua_function(tolua_S, "DoWithBlockEntityAt", tolua_DoWithXYZ<cWorld, cBlockEntity, &cWorld::DoWithBlockEntityAt>);
tolua_function(tolua_S, "DoWithBeaconAt", tolua_DoWithXYZ<cWorld, cBeaconEntity, &cWorld::DoWithBeaconAt>);
@@ -3756,6 +3918,7 @@ void ManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cPlayer");
tolua_function(tolua_S, "GetPermissions", tolua_cPlayer_GetPermissions);
+ tolua_function(tolua_S, "GetRestrictions", tolua_cPlayer_GetRestrictions);
tolua_function(tolua_S, "OpenWindow", tolua_cPlayer_OpenWindow);
tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches);
tolua_endmodule(tolua_S);
diff --git a/src/Bindings/ManualBindings_RankManager.cpp b/src/Bindings/ManualBindings_RankManager.cpp
index fa1b88b6a..c9f187fc6 100644
--- a/src/Bindings/ManualBindings_RankManager.cpp
+++ b/src/Bindings/ManualBindings_RankManager.cpp
@@ -100,6 +100,35 @@ static int tolua_cRankManager_AddPermissionToGroup(lua_State * L)
+/** Binds cRankManager::AddRestrictionToGroup */
+static int tolua_cRankManager_AddRestrictionToGroup(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:AddRestrictionToGroup(Permission, GroupName) -> bool
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Read the params:
+ AString GroupName, Permission;
+ S.GetStackValues(2, Permission, GroupName);
+
+ // Add the group to the rank:
+ S.Push(cRoot::Get()->GetRankManager()->AddRestrictionToGroup(Permission, GroupName));
+ return 1;
+}
+
+
+
+
+
/** Binds cRankManager::AddRank */
static int tolua_cRankManager_AddRank(lua_State * L)
{
@@ -204,6 +233,60 @@ static int tolua_cRankManager_GetAllPermissions(lua_State * L)
+/** Binds cRankManager::GetAllPermissions */
+static int tolua_cRankManager_GetAllRestrictions(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:GetAllRestrictions() -> arraytable of Permissions
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamEnd(2)
+ )
+ {
+ return 0;
+ }
+
+ // Get the permissions:
+ AStringVector Permissions = cRoot::Get()->GetRankManager()->GetAllRestrictions();
+
+ // Push the results:
+ S.Push(Permissions);
+ return 1;
+}
+
+
+
+
+
+/** Binds cRankManager::GetAllPermissionsRestrictions */
+static int tolua_cRankManager_GetAllPermissionsRestrictions(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:GetAllPermissionsRestrictions() -> arraytable of Permissions and Restrictions
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamEnd(2)
+ )
+ {
+ return 0;
+ }
+
+ // Get the permissions:
+ AStringVector Permissions = cRoot::Get()->GetRankManager()->GetAllPermissionsRestrictions();
+
+ // Push the results:
+ S.Push(Permissions);
+ return 1;
+}
+
+
+
+
+
/** Binds cRankManager::GetAllPlayerUUIDs */
static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State * L)
{
@@ -314,6 +397,38 @@ static int tolua_cRankManager_GetGroupPermissions(lua_State * L)
+/** Binds cRankManager::GetGroupRestrictions */
+static int tolua_cRankManager_GetGroupRestrictions(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:GetGroupRestrictions(GroupName) -> arraytable of restrictions
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName;
+ S.GetStackValue(2, GroupName);
+
+ // Get the restrictions:
+ AStringVector Restrictions = cRoot::Get()->GetRankManager()->GetGroupRestrictions(GroupName);
+
+ // Push the results:
+ S.Push(Restrictions);
+ return 1;
+}
+
+
+
+
+
/** Binds cRankManager::GetPlayerGroups */
static int tolua_cRankManager_GetPlayerGroups(lua_State * L)
{
@@ -416,6 +531,38 @@ static int tolua_cRankManager_GetPlayerPermissions(lua_State * L)
+/** Binds cRankManager::GetPlayerRestrictions */
+static int tolua_cRankManager_GetPlayerRestrictions(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:GetPlayerRestrictions(PlayerUUID) -> arraytable of restrictions
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString PlayerUUID;
+ S.GetStackValue(2, PlayerUUID);
+
+ // Get the permissions:
+ AStringVector Restrictions = cRoot::Get()->GetRankManager()->GetPlayerRestrictions(PlayerUUID);
+
+ // Push the results:
+ S.Push(Restrictions);
+ return 1;
+}
+
+
+
+
+
/** Binds cRankManager::GetPlayerRankName */
static int tolua_cRankManager_GetPlayerRankName(lua_State * L)
{
@@ -544,6 +691,38 @@ static int tolua_cRankManager_GetRankPermissions(lua_State * L)
+/** Binds cRankManager::GetRankRestrictions */
+static int tolua_cRankManager_GetRankRestrictions(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:GetRankRestrictions(RankName) -> arraytable of restrictions
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2) ||
+ !S.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString RankName;
+ S.GetStackValue(2, RankName);
+
+ // Get the permissions:
+ AStringVector Restrictions = cRoot::Get()->GetRankManager()->GetRankRestrictions(RankName);
+
+ // Push the results:
+ S.Push(Restrictions);
+ return 1;
+}
+
+
+
+
+
/** Binds cRankManager::GetRankVisuals */
static int tolua_cRankManager_GetRankVisuals(lua_State * L)
{
@@ -679,6 +858,38 @@ static int tolua_cRankManager_IsPermissionInGroup(lua_State * L)
+/** Binds cRankManager::IsRestrictionInGroup */
+static int tolua_cRankManager_IsRestrictionInGroup(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:IsRestrictionInGroup(Restriction, GroupName) -> bool
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName, Restriction;
+ S.GetStackValues(2, Restriction, GroupName);
+
+ // Get the response:
+ bool res = cRoot::Get()->GetRankManager()->IsRestrictionInGroup(Restriction, GroupName);
+
+ // Push the result:
+ S.Push(res);
+ return 1;
+}
+
+
+
+
+
/** Binds cRankManager::IsPlayerRankSet */
static int tolua_cRankManager_IsPlayerRankSet(lua_State * L)
{
@@ -821,7 +1032,7 @@ static int tolua_cRankManager_RemovePermissionFromGroup(lua_State * L)
AString GroupName, Permission;
S.GetStackValues(2, Permission, GroupName);
- // Remove the group:
+ // Remove the permission:
cRoot::Get()->GetRankManager()->RemovePermissionFromGroup(Permission, GroupName);
return 0;
}
@@ -830,6 +1041,35 @@ static int tolua_cRankManager_RemovePermissionFromGroup(lua_State * L)
+/** Binds cRankManager::RemoveRestrictionFromGroup */
+static int tolua_cRankManager_RemoveRestrictionFromGroup(lua_State * L)
+{
+ // Function signature:
+ // cRankManager:RemoveRestrictionFromGroup(Restriction, GroupName)
+
+ cLuaState S(L);
+ if (
+ !S.CheckParamUserTable(1, "cRankManager") ||
+ !S.CheckParamString(2, 3) ||
+ !S.CheckParamEnd(4)
+ )
+ {
+ return 0;
+ }
+
+ // Get the params:
+ AString GroupName, Restriction;
+ S.GetStackValues(2, Restriction, GroupName);
+
+ // Remove the restriction:
+ cRoot::Get()->GetRankManager()->RemoveRestrictionFromGroup(Restriction, GroupName);
+ return 0;
+}
+
+
+
+
+
/** Binds cRankManager::RemovePlayerRank */
static int tolua_cRankManager_RemovePlayerRank(lua_State * L)
{
@@ -1048,40 +1288,48 @@ void ManualBindings::BindRankManager(lua_State * tolua_S)
// Fill in the functions (alpha-sorted):
tolua_beginmodule(tolua_S, "cRankManager");
- tolua_function(tolua_S, "AddGroup", tolua_cRankManager_AddGroup);
- tolua_function(tolua_S, "AddGroupToRank", tolua_cRankManager_AddGroupToRank);
- tolua_function(tolua_S, "AddPermissionToGroup", tolua_cRankManager_AddPermissionToGroup);
- tolua_function(tolua_S, "AddRank", tolua_cRankManager_AddRank);
- tolua_function(tolua_S, "ClearPlayerRanks", tolua_cRankManager_ClearPlayerRanks);
- tolua_function(tolua_S, "GetAllGroups", tolua_cRankManager_GetAllGroups);
- tolua_function(tolua_S, "GetAllPermissions", tolua_cRankManager_GetAllPermissions);
- tolua_function(tolua_S, "GetAllPlayerUUIDs", tolua_cRankManager_GetAllPlayerUUIDs);
- tolua_function(tolua_S, "GetAllRanks", tolua_cRankManager_GetAllRanks);
- tolua_function(tolua_S, "GetDefaultRank", tolua_cRankManager_GetDefaultRank);
- tolua_function(tolua_S, "GetGroupPermissions", tolua_cRankManager_GetGroupPermissions);
- tolua_function(tolua_S, "GetPlayerGroups", tolua_cRankManager_GetPlayerGroups);
- tolua_function(tolua_S, "GetPlayerMsgVisuals", tolua_cRankManager_GetPlayerMsgVisuals);
- tolua_function(tolua_S, "GetPlayerPermissions", tolua_cRankManager_GetPlayerPermissions);
- tolua_function(tolua_S, "GetPlayerRankName", tolua_cRankManager_GetPlayerRankName);
- tolua_function(tolua_S, "GetPlayerName", tolua_cRankManager_GetPlayerName);
- tolua_function(tolua_S, "GetRankGroups", tolua_cRankManager_GetRankGroups);
- tolua_function(tolua_S, "GetRankPermissions", tolua_cRankManager_GetRankPermissions);
- tolua_function(tolua_S, "GetRankVisuals", tolua_cRankManager_GetRankVisuals);
- tolua_function(tolua_S, "GroupExists", tolua_cRankManager_GroupExists);
- tolua_function(tolua_S, "IsGroupInRank", tolua_cRankManager_IsGroupInRank);
- tolua_function(tolua_S, "IsPermissionInGroup", tolua_cRankManager_IsPermissionInGroup);
- tolua_function(tolua_S, "IsPlayerRankSet", tolua_cRankManager_IsPlayerRankSet);
- tolua_function(tolua_S, "RankExists", tolua_cRankManager_RankExists);
- tolua_function(tolua_S, "RemoveGroup", tolua_cRankManager_RemoveGroup);
- tolua_function(tolua_S, "RemoveGroupFromRank", tolua_cRankManager_RemoveGroupFromRank);
- tolua_function(tolua_S, "RemovePermissionFromGroup", tolua_cRankManager_RemovePermissionFromGroup);
- tolua_function(tolua_S, "RemovePlayerRank", tolua_cRankManager_RemovePlayerRank);
- tolua_function(tolua_S, "RemoveRank", tolua_cRankManager_RemoveRank);
- tolua_function(tolua_S, "RenameGroup", tolua_cRankManager_RenameGroup);
- tolua_function(tolua_S, "RenameRank", tolua_cRankManager_RenameRank);
- tolua_function(tolua_S, "SetDefaultRank", tolua_cRankManager_SetDefaultRank);
- tolua_function(tolua_S, "SetPlayerRank", tolua_cRankManager_SetPlayerRank);
- tolua_function(tolua_S, "SetRankVisuals", tolua_cRankManager_SetRankVisuals);
+ tolua_function(tolua_S, "AddGroup", tolua_cRankManager_AddGroup);
+ tolua_function(tolua_S, "AddGroupToRank", tolua_cRankManager_AddGroupToRank);
+ tolua_function(tolua_S, "AddPermissionToGroup", tolua_cRankManager_AddPermissionToGroup);
+ tolua_function(tolua_S, "AddRestrictionToGroup", tolua_cRankManager_AddRestrictionToGroup);
+ tolua_function(tolua_S, "AddRank", tolua_cRankManager_AddRank);
+ tolua_function(tolua_S, "ClearPlayerRanks", tolua_cRankManager_ClearPlayerRanks);
+ tolua_function(tolua_S, "GetAllGroups", tolua_cRankManager_GetAllGroups);
+ tolua_function(tolua_S, "GetAllPermissions", tolua_cRankManager_GetAllPermissions);
+ tolua_function(tolua_S, "GetAllRestrictions", tolua_cRankManager_GetAllRestrictions);
+ tolua_function(tolua_S, "GetAllPermissionsRestrictions", tolua_cRankManager_GetAllPermissionsRestrictions);
+ tolua_function(tolua_S, "GetAllPlayerUUIDs", tolua_cRankManager_GetAllPlayerUUIDs);
+ tolua_function(tolua_S, "GetAllRanks", tolua_cRankManager_GetAllRanks);
+ tolua_function(tolua_S, "GetDefaultRank", tolua_cRankManager_GetDefaultRank);
+ tolua_function(tolua_S, "GetGroupPermissions", tolua_cRankManager_GetGroupPermissions);
+ tolua_function(tolua_S, "GetGroupRestrictions", tolua_cRankManager_GetGroupRestrictions);
+ tolua_function(tolua_S, "GetPlayerGroups", tolua_cRankManager_GetPlayerGroups);
+ tolua_function(tolua_S, "GetPlayerMsgVisuals", tolua_cRankManager_GetPlayerMsgVisuals);
+ tolua_function(tolua_S, "GetPlayerPermissions", tolua_cRankManager_GetPlayerPermissions);
+ tolua_function(tolua_S, "GetPlayerPermissions", tolua_cRankManager_GetPlayerRestrictions);
+ tolua_function(tolua_S, "GetPlayerRankName", tolua_cRankManager_GetPlayerRankName);
+ tolua_function(tolua_S, "GetPlayerName", tolua_cRankManager_GetPlayerName);
+ tolua_function(tolua_S, "GetRankGroups", tolua_cRankManager_GetRankGroups);
+ tolua_function(tolua_S, "GetRankPermissions", tolua_cRankManager_GetRankPermissions);
+ tolua_function(tolua_S, "GetRankRestrictions", tolua_cRankManager_GetRankRestrictions);
+ tolua_function(tolua_S, "GetRankVisuals", tolua_cRankManager_GetRankVisuals);
+ tolua_function(tolua_S, "GroupExists", tolua_cRankManager_GroupExists);
+ tolua_function(tolua_S, "IsGroupInRank", tolua_cRankManager_IsGroupInRank);
+ tolua_function(tolua_S, "IsPermissionInGroup", tolua_cRankManager_IsPermissionInGroup);
+ tolua_function(tolua_S, "IsRestrictionInGroup", tolua_cRankManager_IsRestrictionInGroup);
+ tolua_function(tolua_S, "IsPlayerRankSet", tolua_cRankManager_IsPlayerRankSet);
+ tolua_function(tolua_S, "RankExists", tolua_cRankManager_RankExists);
+ tolua_function(tolua_S, "RemoveGroup", tolua_cRankManager_RemoveGroup);
+ tolua_function(tolua_S, "RemoveGroupFromRank", tolua_cRankManager_RemoveGroupFromRank);
+ tolua_function(tolua_S, "RemovePermissionFromGroup", tolua_cRankManager_RemovePermissionFromGroup);
+ tolua_function(tolua_S, "RemoveRestrictionFromGroup", tolua_cRankManager_RemoveRestrictionFromGroup);
+ tolua_function(tolua_S, "RemovePlayerRank", tolua_cRankManager_RemovePlayerRank);
+ tolua_function(tolua_S, "RemoveRank", tolua_cRankManager_RemoveRank);
+ tolua_function(tolua_S, "RenameGroup", tolua_cRankManager_RenameGroup);
+ tolua_function(tolua_S, "RenameRank", tolua_cRankManager_RenameRank);
+ tolua_function(tolua_S, "SetDefaultRank", tolua_cRankManager_SetDefaultRank);
+ tolua_function(tolua_S, "SetPlayerRank", tolua_cRankManager_SetPlayerRank);
+ tolua_function(tolua_S, "SetRankVisuals", tolua_cRankManager_SetRankVisuals);
tolua_endmodule(tolua_S);
}
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index ddd3398a5..4c98b8d26 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -63,6 +63,11 @@ void cPluginLua::Close(void)
return;
}
+ // Remove the command bindings and web tabs:
+ ClearCommands();
+ ClearConsoleCommands();
+ ClearTabs();
+
// Notify and remove all m_Resettables (unlock the m_CriticalSection while resetting them):
cResettablePtrs resettables;
std::swap(m_Resettables, resettables);