Merge pull request #1290 from mc-server/Ranks
Rewriting permission system to use UUIDs and Ranks
This commit is contained in:
commit
be32c0527c
@ -942,24 +942,6 @@ cFile:Delete("/usr/bin/virus.exe");
|
||||
Inherits = "cEntity",
|
||||
},
|
||||
|
||||
cGroup =
|
||||
{
|
||||
Desc = [[
|
||||
This class represents a group {{cPlayer|players}} can be in. Groups define the permissions players
|
||||
have, and optionally the color of their name in the chat.
|
||||
]],
|
||||
Functions =
|
||||
{
|
||||
SetName = { Return = "" },
|
||||
GetName = { Return = "string" },
|
||||
SetColor = { Return = "" },
|
||||
GetColor = { Return = "string" },
|
||||
AddCommand = { Return = "" },
|
||||
AddPermission = { Return = "" },
|
||||
InheritFrom = { Return = "" },
|
||||
},
|
||||
}, -- cGroup
|
||||
|
||||
cIniFile =
|
||||
{
|
||||
Desc = [[
|
||||
@ -1760,7 +1742,6 @@ a_Player:OpenWindow(Window);
|
||||
Functions =
|
||||
{
|
||||
AddFoodExhaustion = { Params = "Exhaustion", Return = "", Notes = "Adds the specified number to the food exhaustion. Only positive numbers expected." },
|
||||
AddToGroup = { Params = "GroupName", Return = "", Notes = "Temporarily adds the player to the specified group. The assignment is lost when the player disconnects." },
|
||||
CalcLevelFromXp = { Params = "XPAmount", Return = "number", Notes = "(STATIC) Returns the level which is reached with the specified amount of XP. Inverse of XpForLevel()." },
|
||||
CanFly = { Return = "bool", Notes = "Returns if the player is able to fly." },
|
||||
CloseWindow = { Params = "[CanRefuse]", Return = "", Notes = "Closes the currently open UI window. If CanRefuse is true (default), the window may refuse the closing." },
|
||||
@ -1770,7 +1751,7 @@ a_Player:OpenWindow(Window);
|
||||
FoodPoison = { Params = "NumTicks", Return = "", Notes = "Starts the food poisoning for the specified amount of ticks; if already foodpoisoned, sets FoodPoisonedTicksRemaining to the larger of the two" },
|
||||
ForceSetSpeed = { Params = "{{Vector3d|Direction}}", Notes = "Forces the player to move to the given direction." },
|
||||
GetClientHandle = { Params = "", Return = "{{cClientHandle}}", Notes = "Returns the client handle representing the player's connection. May be nil (AI players)." },
|
||||
GetColor = { Return = "string", Notes = "Returns the full color code to be used for this player (based on the first group). Prefix player messages with this code." },
|
||||
GetColor = { Return = "string", Notes = "Returns the full color code to be used for this player's messages (based on their rank). Prefix player messages with this code." },
|
||||
GetCurrentXp = { Params = "", Return = "number", Notes = "Returns the current amount of XP" },
|
||||
GetEffectiveGameMode = { Params = "", Return = "{{Globals#GameMode|GameMode}}", Notes = "(OBSOLETE) Returns the current resolved game mode of the player. If the player is set to inherit the world's gamemode, returns that instead. See also GetGameMode() and IsGameModeXXX() functions. Note that this function is the same as GetGameMode(), use that function instead." },
|
||||
GetEquippedItem = { Params = "", Return = "{{cItem}}", Notes = "Returns the item that the player is currently holding; empty item if holding nothing." },
|
||||
@ -1784,7 +1765,6 @@ a_Player:OpenWindow(Window);
|
||||
GetFoodSaturationLevel = { Params = "", Return = "number", Notes = "Returns the food saturation (overcharge of the food level, is depleted before food level)" },
|
||||
GetFoodTickTimer = { Params = "", Return = "", Notes = "Returns the number of ticks past the last food-based heal or damage action; when this timer reaches 80, a new heal / damage is applied." },
|
||||
GetGameMode = { Return = "{{Globals#GameMode|GameMode}}", Notes = "Returns the player's gamemode. The player may have their gamemode unassigned, in which case they inherit the gamemode from the current {{cWorld|world}}.<br /> <b>NOTE:</b> Instead of comparing the value returned by this function to the gmXXX constants, use the IsGameModeXXX() functions. These functions handle the gamemode inheritance automatically."},
|
||||
GetGroups = { Return = "array-table of {{cGroup}}", Notes = "Returns all the groups that this player is member of, as a table. The groups are stored in the array part of the table, beginning with index 1."},
|
||||
GetIP = { Return = "string", Notes = "Returns the IP address of the player, if available. Returns an empty string if there's no IP to report."},
|
||||
GetInventory = { Return = "{{cInventory|Inventory}}", Notes = "Returns the player's inventory"},
|
||||
GetMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's current maximum speed, relative to the game default speed. Takes into account the sprinting / flying status." },
|
||||
@ -1807,15 +1787,13 @@ a_Player:OpenWindow(Window);
|
||||
IsGameModeAdventure = { Params = "", Return = "bool", Notes = "Returns true if the player is in the gmAdventure gamemode, or has their gamemode unset and the world is a gmAdventure world." },
|
||||
IsGameModeCreative = { Params = "", Return = "bool", Notes = "Returns true if the player is in the gmCreative gamemode, or has their gamemode unset and the world is a gmCreative world." },
|
||||
IsGameModeSurvival = { Params = "", Return = "bool", Notes = "Returns true if the player is in the gmSurvival gamemode, or has their gamemode unset and the world is a gmSurvival world." },
|
||||
IsInGroup = { Params = "GroupNameString", Return = "bool", Notes = "Returns true if the player is a member of the specified group." },
|
||||
IsOnGround = { Params = "", Return = "bool", Notes = "Returns true if the player is on ground (not falling, not jumping, not flying)" },
|
||||
IsSatiated = { Params = "", Return = "bool", Notes = "Returns true if the player is satiated (cannot eat)." },
|
||||
IsVisible = { Params = "", Return = "bool", Notes = "Returns true if the player is visible to other players" },
|
||||
LoadPermissionsFromDisk = { Params = "", Return = "", Notes = "Reloads the player's permissions from the disk. This loses any temporary changes made to the player's groups." },
|
||||
LoadRank = { Params = "", Return = "", Notes = "Reloads the player's rank, message visuals and permissions from the {{cRankManager}}, based on the player's current rank." },
|
||||
MoveTo = { Params = "{{Vector3d|NewPosition}}", Return = "Tries to move the player into the specified position." },
|
||||
MoveToWorld = { Params = "WorldName", Return = "bool", Return = "Moves the player to the specified world. Returns true if successful." },
|
||||
OpenWindow = { Params = "{{cWindow|Window}}", Return = "", Notes = "Opens the specified UI window for the player." },
|
||||
RemoveFromGroup = { Params = "GroupName", Return = "", Notes = "Temporarily removes the player from the specified group. This change is lost when the player disconnects." },
|
||||
Respawn = { Params = "", Return = "", Notes = "Restores the health, extinguishes fire, makes visible and sends the Respawn packet." },
|
||||
SendMessage = { Params = "Message", Return = "", Notes = "Sends the specified message to the player." },
|
||||
SendMessageFailure = { Params = "Message", Return = "", Notes = "Prepends Rose [INFO] / colours entire text (depending on ShouldUseChatPrefixes()) and sends message to player. For a command that failed to run because of insufficient permissions, etc." },
|
||||
@ -2004,6 +1982,71 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
|
||||
},
|
||||
}, -- cPluginManager
|
||||
|
||||
cRankManager =
|
||||
{
|
||||
Desc = [[
|
||||
Manages the players' permissions. The players are assigned a single rank, which contains groups of
|
||||
permissions. The functions in this class query or modify these.</p>
|
||||
<p>
|
||||
All the functions are static, call them using the <code>cRankManager:Function()</code> convention.</p>
|
||||
<p>
|
||||
The players are identified by their UUID, to support player renaming.</p>
|
||||
<p>
|
||||
The rank also contains specific "mesage visuals" - bits that are used for formatting messages from the
|
||||
players. There's a message prefix, which is put in front of every message the player sends, and the
|
||||
message suffix that is appended to each message. There's also a PlayerNameColorCode, which holds the
|
||||
color that is used for the player's name in the messages.</p>
|
||||
<p>
|
||||
Each rank can contain any number of permission groups. These groups allow for an easier setup of the
|
||||
permissions - you can share groups among ranks, so the usual approach is to group similar permissions
|
||||
together and add that group to any rank that should use those permissions.</p>
|
||||
<p>
|
||||
Permissions are added to individual groups. Each group can support unlimited permissions. Note that
|
||||
adding a permission to a group will make the permission available to all the ranks that contain that
|
||||
permission group.</p>
|
||||
<p>
|
||||
One rank is reserved as the Default rank. All players that don't have an explicit rank assigned to them
|
||||
will behave as if assigned to this rank. The default rank can be changed to any other rank at any time.
|
||||
Note that the default rank cannot be removed from the RankManager - RemoveRank() will change the default
|
||||
rank to the replacement rank, if specified, and fail if no replacement rank is specified. Renaming the
|
||||
default rank using RenameRank() will change the default rank to the new name.
|
||||
]],
|
||||
Functions =
|
||||
{
|
||||
AddGroup = { Params = "GroupName", Return = "", Notes = "Adds the group of the specified name. Logs a warning and does nothing if the group already exists." },
|
||||
AddGroupToRank = { Params = "GroupName, RankName", Return = "bool", Notes = "Adds the specified group to the specified rank. Returns true on success, false on failure - if the group name or the rank name is not found." },
|
||||
AddPermissionToGroup = { Params = "Permission, GroupName", Return = "bool", Notes = "Adds the specified permission to the specified group. Returns true on success, false on failure - if the group name is not found." },
|
||||
AddRank = { Params = "RankName, MsgPrefix, MsgSuffix, MsgNameColorCode", Return = "", Notes = "Adds a new rank of the specified name and with the specified message visuals. Logs an info message and does nothing if the rank already exists." },
|
||||
GetAllGroups = { Params = "", Return = "array-table of groups' names", Notes = "Returns an array-table containing the names of all the groups that are known to the manager." },
|
||||
GetAllPermissions = { Params = "", Return = "array-table of permissions", Notes = "Returns an array-table containing all the permissions that are known to the manager." },
|
||||
GetAllRanks = { Params = "", Return = "array-table of ranks' names", Notes = "Returns an array-table containing the names of all the ranks that are known to the manager." },
|
||||
GetDefaultRank = { Params = "", Return = "string", Notes = "Returns the name of the default rank. " },
|
||||
GetGroupPermissions = { Params = "GroupName", Return = "array-table of permissions", Notes = "Returns an array-table containing the permissions that the specified group contains." },
|
||||
GetPlayerGroups = { Params = "PlayerUUID", Return = "array-table of groups' names", Notes = "Returns an array-table of the names of the groups that are assigned to the specified player through their rank. Returns an empty table if the player is not known or has no rank or groups assigned to them." },
|
||||
GetPlayerMsgVisuals = { Params = "PlayerUUID", Return = "MsgPrefix, MsgSuffix, MsgNameColorCode", Notes = "Returns the message visuals assigned to the player. If the player is not explicitly assigned a rank, the default rank's visuals are returned. If there is an error, no value is returned at all." },
|
||||
GetPlayerPermissions = { Params = "PlayerUUID", Return = "array-table of permissions", Notes = "Returns the permissions that the specified player is assigned through their rank. Returns the default rank's permissions if the player has no explicit rank assigned to them. Returns an empty array on error." },
|
||||
GetPlayerRankName = { Params = "PlayerUUID", Return = "RankName", Notes = "Returns the name of the rank that is assigned to the specified player. An empty string (NOT the default rank) is returned if the player has no rank assigned to them." },
|
||||
GetRankGroups = { Params = "RankName", Return = "array-table of groups' names", Notes = "Returns an array-table of the names of all the groups that are assigned to the specified rank. Returns an empty table if there is no such rank." },
|
||||
GetRankPermissions = { Params = "RankName", Return = "array-table of permissions", Notes = "Returns an array-table of all the permissions that are assigned to the specified rank through its groups. Returns an empty table if there is no such rank." },
|
||||
GetRankVisuals = { Params = "RankName", Return = "MsgPrefix, MsgSuffix, MsgNameColorCode", Notes = "Returns the message visuals for the specified rank. Returns no value if the specified rank does not exist." },
|
||||
GroupExists = { Params = "GroupName", Return = "bool", Notes = "Returns true iff the specified group exists." },
|
||||
IsGroupInRank = { Params = "GroupName, RankName", Return = "bool", Notes = "Returns true iff the specified group is assigned to the specified rank." },
|
||||
IsPermissionInGroup = { Params = "Permission, GroupName", Return = "bool", Notes = "Returns true iff the specified permission is assigned to the specified group." },
|
||||
IsPlayerRankSet = { Params = "PlayerUUID", Return = "bool", Notes = "Returns true iff the specified player has a rank assigned to them." },
|
||||
RankExists = { Params = "RankName", Return = "bool", Notes = "Returns true iff the specified rank exists." },
|
||||
RemoveGroup = { Params = "GroupName", Return = "", Notes = "Removes the specified group completely. The group will be removed from all the ranks using it and then erased from the manager. Logs an info message and does nothing if the group doesn't exist." },
|
||||
RemoveGroupFromRank = { Params = "GroupName, RankName", Return = "", Notes = "Removes the specified group from the specified rank. The group will still exist, even if it isn't assigned to any rank. Logs an info message and does nothing if the group or rank doesn't exist." },
|
||||
RemovePermissionFromGroup = { Params = "Permission, GroupName", Return = "", Notes = "Removes the specified permission from the specified group. Logs an info message and does nothing if the group doesn't exist." },
|
||||
RemovePlayerRank = { Params = "PlayerUUID", Return = "", Notes = "Removes the player's rank; the player's left without a rank. Note that this doesn't change the {{cPlayer}} instances for the already connected players, you need to update all the instances manually. No action if the player has no rank assigned to them already." },
|
||||
RemoveRank = { Params = "RankName, [ReplacementRankName]", Return = "", Notes = "Removes the specified rank. If ReplacementRankName is given, the players that have RankName will get their rank set to ReplacementRankName. If it isn't given, or is an invalid rank, the players will be removed from the manager, their ranks will be unset completely. Logs an info message and does nothing if the rank is not found." },
|
||||
RenameGroup = { Params = "OldName, NewName", Return = "", Notes = "Renames the specified group. Logs an info message and does nothing if the group is not found or the new name is already used." },
|
||||
RenameRank = { Params = "OldName, NewName", Return = "", Notes = "Renames the specified rank. Logs an info message and does nothing if the rank is not found or the new name is already used." },
|
||||
SetDefaultRank = { Params = "RankName", Return = "bool", Notes = "Sets the specified rank as the default rank. Returns true on success, false on failure (rank doesn't exist)." },
|
||||
SetPlayerRank = { Params = "PlayerUUID, PlayerName, RankName", Return = "", Notes = "Updates the rank for the specified player. The player name is provided for reference, the UUID is used for identification. Logs a warning and does nothing if the rank is not found." },
|
||||
SetRankVisuals = { Params = "RankName, MsgPrefix, MsgSuffix, MsgNameColorCode", Return = "", Notes = "Updates the rank's message visuals. Logs an info message and does nothing if rank not found." },
|
||||
},
|
||||
}, -- cRankManager
|
||||
|
||||
cRoot =
|
||||
{
|
||||
Desc = [[
|
||||
@ -2032,7 +2075,6 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
|
||||
GetDefaultWorld = { Params = "", Return = "{{cWorld|cWorld}}", Notes = "Returns the world object from the default world." },
|
||||
GetFurnaceFuelBurnTime = { Params = "{{cItem|Fuel}}", Return = "number", Notes = "(STATIC) Returns the number of ticks for how long the item would fuel a furnace. Returns zero if not a fuel." },
|
||||
GetFurnaceRecipe = { Params = "{{cItem|InItem}}", Return = "{{cItem|OutItem}}, NumTicks, {{cItem|InItem}}", Notes = "(STATIC) Returns the furnace recipe for smelting the specified input. If a recipe is found, returns the smelted result, the number of ticks required for the smelting operation, and the input consumed (note that MCServer supports smelting M items into N items and different smelting rates). If no recipe is found, returns no value." },
|
||||
GetGroupManager = { Params = "", Return = "{{cGroupManager|cGroupManager}}", Notes = "Returns the cGroupManager object." },
|
||||
GetPhysicalRAMUsage = { Params = "", Return = "number", Notes = "Returns the amount of physical RAM that the entire MCServer process is using, in KiB. Negative if the OS doesn't support this query." },
|
||||
GetPluginManager = { Params = "", Return = "{{cPluginManager|cPluginManager}}", Notes = "Returns the cPluginManager object." },
|
||||
GetPrimaryServerVersion = { Params = "", Return = "number", Notes = "Returns the servers primary server version." },
|
||||
@ -2116,10 +2158,11 @@ end
|
||||
{
|
||||
GetDescription = { Return = "string", Notes = "Returns the server description set in the settings.ini." },
|
||||
GetMaxPlayers = { Return = "number", Notes = "Returns the max amount of players who can join the server." },
|
||||
SetMaxPlayers = { Params = "number", Notes = "Sets the max amount of players who can join." },
|
||||
GetNumPlayers = { Return = "number", Notes = "Returns the amount of players online." },
|
||||
GetServerID = { Return = "string", Notes = "Returns the ID of the server?" },
|
||||
IsHardcore = { Params = "", Return = "bool", Notes = "Returns true if the server is hardcore (players get banned on death)." },
|
||||
SetMaxPlayers = { Params = "number", Notes = "Sets the max amount of players who can join." },
|
||||
ShouldAuthenticate = { Params = "", Return = "bool", Notes = "Returns true iff the server is set to authenticate players (\"online mode\")." },
|
||||
},
|
||||
}, -- cServer
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 1b16c23c216d359e9fe0334c63deeecc347e69bd
|
||||
Subproject commit 7cc99285ae5117418f657c3b295ca71f2b75b4f4
|
@ -80,7 +80,8 @@ function Initialize(Plugin)
|
||||
|
||||
TestBlockAreasString()
|
||||
TestStringBase64()
|
||||
TestUUIDFromName()
|
||||
-- TestUUIDFromName()
|
||||
-- TestRankMgr()
|
||||
|
||||
--[[
|
||||
-- Test cCompositeChat usage in console-logging:
|
||||
@ -352,6 +353,18 @@ end
|
||||
|
||||
|
||||
|
||||
function TestRankMgr()
|
||||
LOG("Testing the rank manager")
|
||||
cRankManager:AddRank("LuaRank")
|
||||
cRankManager:AddGroup("LuaTestGroup")
|
||||
cRankManager:AddGroupToRank("LuaTestGroup", "LuaRank")
|
||||
cRankManager:AddPermissionToGroup("luaperm", "LuaTestGroup")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function TestSQLiteBindings()
|
||||
LOG("Testing SQLite bindings...");
|
||||
|
||||
|
@ -67,7 +67,6 @@ $cfile "../Root.h"
|
||||
$cfile "../Cuboid.h"
|
||||
$cfile "../BoundingBox.h"
|
||||
$cfile "../Tracer.h"
|
||||
$cfile "../Group.h"
|
||||
$cfile "../BlockArea.h"
|
||||
$cfile "../Generating/ChunkDesc.h"
|
||||
$cfile "../CraftingRecipes.h"
|
||||
|
@ -11,6 +11,7 @@ SET (SRCS
|
||||
LuaState.cpp
|
||||
LuaWindow.cpp
|
||||
ManualBindings.cpp
|
||||
ManualBindings_RankManager.cpp
|
||||
Plugin.cpp
|
||||
PluginLua.cpp
|
||||
PluginManager.cpp
|
||||
@ -96,7 +97,6 @@ set(BINDING_DEPENDENCIES
|
||||
../Entities/HangingEntity.h
|
||||
../Entities/ItemFrame.h
|
||||
../Generating/ChunkDesc.h
|
||||
../Group.h
|
||||
../Inventory.h
|
||||
../Item.h
|
||||
../ItemGrid.h
|
||||
|
@ -1803,49 +1803,30 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
|
||||
|
||||
|
||||
|
||||
static int tolua_cPlayer_GetGroups(lua_State * tolua_S)
|
||||
static int tolua_cPlayer_GetPermissions(lua_State * tolua_S)
|
||||
{
|
||||
// Function signature: cPlayer:GetPermissions() -> {permissions-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, NULL);
|
||||
|
||||
const cPlayer::GroupList & AllGroups = self->GetGroups();
|
||||
|
||||
lua_createtable(tolua_S, (int)AllGroups.size(), 0);
|
||||
int newTable = lua_gettop(tolua_S);
|
||||
int index = 1;
|
||||
cPlayer::GroupList::const_iterator iter = AllGroups.begin();
|
||||
while (iter != AllGroups.end())
|
||||
if (self == NULL)
|
||||
{
|
||||
const cGroup * Group = *iter;
|
||||
tolua_pushusertype(tolua_S, (void *)Group, "const cGroup");
|
||||
lua_rawseti(tolua_S, newTable, index);
|
||||
++iter;
|
||||
++index;
|
||||
LOGWARNING("%s: invalid self (%p)", __FUNCTION__, self);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_cPlayer_GetResolvedPermissions(lua_State * tolua_S)
|
||||
{
|
||||
cPlayer * self = (cPlayer*) tolua_tousertype(tolua_S, 1, NULL);
|
||||
|
||||
cPlayer::StringList AllPermissions = self->GetResolvedPermissions();
|
||||
|
||||
lua_createtable(tolua_S, (int)AllPermissions.size(), 0);
|
||||
int newTable = lua_gettop(tolua_S);
|
||||
int index = 1;
|
||||
cPlayer::StringList::iterator iter = AllPermissions.begin();
|
||||
while (iter != AllPermissions.end())
|
||||
{
|
||||
std::string & Permission = *iter;
|
||||
lua_pushlstring(tolua_S, Permission.c_str(), Permission.length());
|
||||
lua_rawseti(tolua_S, newTable, index);
|
||||
++iter;
|
||||
++index;
|
||||
}
|
||||
// Push the permissions:
|
||||
L.Push(self->GetPermissions());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1902,6 +1883,40 @@ static int tolua_cPlayer_OpenWindow(lua_State * tolua_S)
|
||||
|
||||
|
||||
|
||||
static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S)
|
||||
{
|
||||
// Function signature: cPlayer:PermissionMatches(PermissionStr, TemplateStr) -> bool
|
||||
|
||||
// Check the params:
|
||||
cLuaState L(tolua_S);
|
||||
if (
|
||||
!L.CheckParamUserType(1, "cPlayer") ||
|
||||
!L.CheckParamString (2, 3) ||
|
||||
!L.CheckParamEnd (4)
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the params:
|
||||
cPlayer * self = (cPlayer *)tolua_tousertype(tolua_S, 1, NULL);
|
||||
if (self == NULL)
|
||||
{
|
||||
LOGWARNING("%s: invalid self (%p)", __FUNCTION__, self);
|
||||
return 0;
|
||||
}
|
||||
AString Permission, Template;
|
||||
L.GetStackValues(2, Permission, Template);
|
||||
|
||||
// Push the result of the match:
|
||||
L.Push(self->PermissionMatches(StringSplit(Permission, "."), StringSplit(Template, ".")));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <
|
||||
class OBJTYPE,
|
||||
void (OBJTYPE::*SetCallback)(cPluginLua * a_Plugin, int a_FnRef)
|
||||
@ -2399,6 +2414,62 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L)
|
||||
|
||||
|
||||
|
||||
static int tolua_cMojangAPI_MakeUUIDDashed(lua_State * L)
|
||||
{
|
||||
// Function signature: cMojangAPI:MakeUUIDDashed(UUID) -> string
|
||||
|
||||
// Check params:
|
||||
cLuaState S(L);
|
||||
if (
|
||||
!S.CheckParamUserTable(1, "cMojangAPI") ||
|
||||
!S.CheckParamString(2) ||
|
||||
!S.CheckParamEnd(3)
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the params:
|
||||
AString UUID;
|
||||
S.GetStackValue(2, UUID);
|
||||
|
||||
// Push the result:
|
||||
S.Push(cRoot::Get()->GetMojangAPI().MakeUUIDDashed(UUID));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_cMojangAPI_MakeUUIDShort(lua_State * L)
|
||||
{
|
||||
// Function signature: cMojangAPI:MakeUUIDShort(UUID) -> string
|
||||
|
||||
// Check params:
|
||||
cLuaState S(L);
|
||||
if (
|
||||
!S.CheckParamUserTable(1, "cMojangAPI") ||
|
||||
!S.CheckParamString(2) ||
|
||||
!S.CheckParamEnd(3)
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the params:
|
||||
AString UUID;
|
||||
S.GetStackValue(2, UUID);
|
||||
|
||||
// Push the result:
|
||||
S.Push(cRoot::Get()->GetMojangAPI().MakeUUIDShort(UUID));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int Lua_ItemGrid_GetSlotCoords(lua_State * L)
|
||||
{
|
||||
tolua_Error tolua_err;
|
||||
@ -3295,9 +3366,9 @@ void ManualBindings::Bind(lua_State * tolua_S)
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_beginmodule(tolua_S, "cPlayer");
|
||||
tolua_function(tolua_S, "GetGroups", tolua_cPlayer_GetGroups);
|
||||
tolua_function(tolua_S, "GetResolvedPermissions", tolua_cPlayer_GetResolvedPermissions);
|
||||
tolua_function(tolua_S, "GetPermissions", tolua_cPlayer_GetPermissions);
|
||||
tolua_function(tolua_S, "OpenWindow", tolua_cPlayer_OpenWindow);
|
||||
tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_beginmodule(tolua_S, "cLuaWindow");
|
||||
@ -3340,6 +3411,8 @@ void ManualBindings::Bind(lua_State * tolua_S)
|
||||
tolua_function(tolua_S, "GetPlayerNameFromUUID", tolua_cMojangAPI_GetPlayerNameFromUUID);
|
||||
tolua_function(tolua_S, "GetUUIDFromPlayerName", tolua_cMojangAPI_GetUUIDFromPlayerName);
|
||||
tolua_function(tolua_S, "GetUUIDsFromPlayerNames", tolua_cMojangAPI_GetUUIDsFromPlayerNames);
|
||||
tolua_function(tolua_S, "MakeUUIDDashed", tolua_cMojangAPI_MakeUUIDDashed);
|
||||
tolua_function(tolua_S, "MakeUUIDShort", tolua_cMojangAPI_MakeUUIDShort);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_beginmodule(tolua_S, "cItemGrid");
|
||||
@ -3348,6 +3421,8 @@ void ManualBindings::Bind(lua_State * tolua_S)
|
||||
|
||||
tolua_function(tolua_S, "md5", tolua_md5);
|
||||
|
||||
BindRankManager(tolua_S);
|
||||
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
struct lua_State;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** Provides namespace for the bindings. */
|
||||
class ManualBindings
|
||||
{
|
||||
public:
|
||||
static void Bind( lua_State* tolua_S);
|
||||
/** Binds all the manually implemented functions to tolua_S. */
|
||||
static void Bind(lua_State * tolua_S);
|
||||
|
||||
protected:
|
||||
/** Binds the manually implemented cRankManager glue code to tolua_S.
|
||||
Implemented in ManualBindings_RankManager.cpp. */
|
||||
static void BindRankManager(lua_State * tolua_S);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
1007
src/Bindings/ManualBindings_RankManager.cpp
Normal file
1007
src/Bindings/ManualBindings_RankManager.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -183,6 +183,33 @@ for _, combination in ipairs(Combinations) do
|
||||
WriteOverload(f, combination[1], combination[2])
|
||||
end
|
||||
|
||||
-- Generate the cLuaState::GetStackValues() multi-param templates:
|
||||
for i = 2, 6 do
|
||||
f:write("/** Reads ", i, " consecutive values off the stack */\ntemplate <\n")
|
||||
|
||||
-- Write the template function header:
|
||||
local txt = {}
|
||||
for idx = 1, i do
|
||||
table.insert(txt, "\ttypename ArgT" .. idx)
|
||||
end
|
||||
f:write(table.concat(txt, ",\n"))
|
||||
|
||||
-- Write the argument declarations:
|
||||
txt = {}
|
||||
f:write("\n>\nvoid GetStackValues(\n\tint a_BeginPos,\n")
|
||||
for idx = 1, i do
|
||||
table.insert(txt, "\tArgT" .. idx .. " & Arg" .. idx)
|
||||
end
|
||||
f:write(table.concat(txt, ",\n"))
|
||||
|
||||
-- Write the function body:
|
||||
f:write("\n)\n{\n")
|
||||
for idx = 1, i do
|
||||
f:write("\tGetStackValue(a_BeginPos + ", idx - 1, ", Arg", idx, ");\n")
|
||||
end
|
||||
f:write("}\n\n\n\n\n\n")
|
||||
end
|
||||
|
||||
-- Close the generated file
|
||||
f:close()
|
||||
|
||||
|
@ -34,8 +34,6 @@ SET (SRCS
|
||||
FastRandom.cpp
|
||||
FurnaceRecipe.cpp
|
||||
Globals.cpp
|
||||
Group.cpp
|
||||
GroupManager.cpp
|
||||
Inventory.cpp
|
||||
Item.cpp
|
||||
ItemGrid.cpp
|
||||
@ -53,6 +51,7 @@ SET (SRCS
|
||||
MonsterConfig.cpp
|
||||
Noise.cpp
|
||||
ProbabDistrib.cpp
|
||||
RankManager.cpp
|
||||
RCONServer.cpp
|
||||
Root.cpp
|
||||
Scoreboard.cpp
|
||||
@ -98,8 +97,6 @@ SET (HDRS
|
||||
ForEachChunkProvider.h
|
||||
FurnaceRecipe.h
|
||||
Globals.h
|
||||
Group.h
|
||||
GroupManager.h
|
||||
Inventory.h
|
||||
Item.h
|
||||
ItemGrid.h
|
||||
@ -122,6 +119,7 @@ SET (HDRS
|
||||
MonsterConfig.h
|
||||
Noise.h
|
||||
ProbabDistrib.h
|
||||
RankManager.h
|
||||
RCONServer.h
|
||||
Root.h
|
||||
Scoreboard.h
|
||||
|
@ -10,8 +10,6 @@
|
||||
#include "../Bindings/PluginManager.h"
|
||||
#include "../BlockEntities/BlockEntity.h"
|
||||
#include "../BlockEntities/EnderChestEntity.h"
|
||||
#include "../GroupManager.h"
|
||||
#include "../Group.h"
|
||||
#include "../Root.h"
|
||||
#include "../OSSupport/Timer.h"
|
||||
#include "../Chunk.h"
|
||||
@ -59,7 +57,6 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) :
|
||||
m_EnderChestContents(9, 3),
|
||||
m_CurrentWindow(NULL),
|
||||
m_InventoryWindow(NULL),
|
||||
m_Color('-'),
|
||||
m_GameMode(eGameMode_NotSet),
|
||||
m_IP(""),
|
||||
m_ClientHandle(a_Client),
|
||||
@ -1367,48 +1364,6 @@ void cPlayer::SetVisible(bool a_bVisible)
|
||||
|
||||
|
||||
|
||||
void cPlayer::AddToGroup( const AString & a_GroupName)
|
||||
{
|
||||
cGroup* Group = cRoot::Get()->GetGroupManager()->GetGroup( a_GroupName);
|
||||
m_Groups.push_back( Group);
|
||||
LOGD("Added %s to group %s", GetName().c_str(), a_GroupName.c_str());
|
||||
ResolveGroups();
|
||||
ResolvePermissions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlayer::RemoveFromGroup( const AString & a_GroupName)
|
||||
{
|
||||
bool bRemoved = false;
|
||||
for (GroupList::iterator itr = m_Groups.begin(); itr != m_Groups.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->GetName().compare(a_GroupName) == 0)
|
||||
{
|
||||
m_Groups.erase( itr);
|
||||
bRemoved = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bRemoved)
|
||||
{
|
||||
LOGD("Removed %s from group %s", GetName().c_str(), a_GroupName.c_str());
|
||||
ResolveGroups();
|
||||
ResolvePermissions();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGWARN("Tried to remove %s from group %s but was not in that group", GetName().c_str(), a_GroupName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlayer::HasPermission(const AString & a_Permission)
|
||||
{
|
||||
if (a_Permission.empty())
|
||||
@ -1417,47 +1372,18 @@ bool cPlayer::HasPermission(const AString & a_Permission)
|
||||
return true;
|
||||
}
|
||||
|
||||
AStringVector Split = StringSplit( a_Permission, ".");
|
||||
PermissionMap Possibilities = m_ResolvedPermissions;
|
||||
// Now search the namespaces
|
||||
while (Possibilities.begin() != Possibilities.end())
|
||||
{
|
||||
PermissionMap::iterator itr = Possibilities.begin();
|
||||
if (itr->second)
|
||||
{
|
||||
AStringVector OtherSplit = StringSplit( itr->first, ".");
|
||||
if (OtherSplit.size() <= Split.size())
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < OtherSplit.size(); ++i)
|
||||
{
|
||||
if (OtherSplit[i].compare( Split[i]) != 0)
|
||||
{
|
||||
if (OtherSplit[i].compare("*") == 0) return true; // WildCard man!! WildCard!
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == Split.size()) return true;
|
||||
}
|
||||
}
|
||||
Possibilities.erase( itr);
|
||||
}
|
||||
AStringVector Split = StringSplit(a_Permission, ".");
|
||||
|
||||
// Nothing that matched :(
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlayer::IsInGroup( const AString & a_Group)
|
||||
{
|
||||
for (GroupList::iterator itr = m_ResolvedGroups.begin(); itr != m_ResolvedGroups.end(); ++itr)
|
||||
// Iterate over all granted permissions; if any matches, then return success:
|
||||
for (AStringVectorVector::const_iterator itr = m_SplitPermissions.begin(), end = m_SplitPermissions.end(); itr != end; ++itr)
|
||||
{
|
||||
if (PermissionMatches(Split, *itr))
|
||||
{
|
||||
if (a_Group.compare( (*itr)->GetName().c_str()) == 0)
|
||||
return true;
|
||||
}
|
||||
} // for itr - m_SplitPermissions[]
|
||||
|
||||
// No granted permission matches
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1465,68 +1391,35 @@ bool cPlayer::IsInGroup( const AString & a_Group)
|
||||
|
||||
|
||||
|
||||
void cPlayer::ResolvePermissions()
|
||||
bool cPlayer::PermissionMatches(const AStringVector & a_Permission, const AStringVector & a_Template)
|
||||
{
|
||||
m_ResolvedPermissions.clear(); // Start with an empty map
|
||||
|
||||
// Copy all player specific permissions into the resolved permissions map
|
||||
for (PermissionMap::iterator itr = m_Permissions.begin(); itr != m_Permissions.end(); ++itr)
|
||||
// Check the sub-items if they are the same or there's a wildcard:
|
||||
size_t lenP = a_Permission.size();
|
||||
size_t lenT = a_Template.size();
|
||||
size_t minLen = std::min(lenP, lenT);
|
||||
for (size_t i = 0; i < minLen; i++)
|
||||
{
|
||||
m_ResolvedPermissions[ itr->first ] = itr->second;
|
||||
if (a_Template[i] == "*")
|
||||
{
|
||||
// Has matched so far and now there's a wildcard in the template, so the permission matches:
|
||||
return true;
|
||||
}
|
||||
if (a_Permission[i] != a_Template[i])
|
||||
{
|
||||
// Found a mismatch
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (GroupList::iterator GroupItr = m_ResolvedGroups.begin(); GroupItr != m_ResolvedGroups.end(); ++GroupItr)
|
||||
// So far all the sub-items have matched
|
||||
// If the sub-item count is the same, then the permission matches:
|
||||
if (lenP == lenT)
|
||||
{
|
||||
const cGroup::PermissionMap & Permissions = (*GroupItr)->GetPermissions();
|
||||
for (cGroup::PermissionMap::const_iterator itr = Permissions.begin(); itr != Permissions.end(); ++itr)
|
||||
{
|
||||
m_ResolvedPermissions[ itr->first ] = itr->second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlayer::ResolveGroups()
|
||||
{
|
||||
// Clear resolved groups first
|
||||
m_ResolvedGroups.clear();
|
||||
|
||||
// Get a complete resolved list of all groups the player is in
|
||||
std::map< cGroup*, bool > AllGroups; // Use a map, because it's faster than iterating through a list to find duplicates
|
||||
GroupList ToIterate;
|
||||
for (GroupList::iterator GroupItr = m_Groups.begin(); GroupItr != m_Groups.end(); ++GroupItr)
|
||||
{
|
||||
ToIterate.push_back( *GroupItr);
|
||||
}
|
||||
while (ToIterate.begin() != ToIterate.end())
|
||||
{
|
||||
cGroup* CurrentGroup = *ToIterate.begin();
|
||||
if (AllGroups.find( CurrentGroup) != AllGroups.end())
|
||||
{
|
||||
LOGWARNING("ERROR: Player \"%s\" is in the group multiple times (\"%s\"). Please fix your settings in users.ini!",
|
||||
GetName().c_str(), CurrentGroup->GetName().c_str()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
AllGroups[ CurrentGroup ] = true;
|
||||
m_ResolvedGroups.push_back( CurrentGroup); // Add group to resolved list
|
||||
const cGroup::GroupList & Inherits = CurrentGroup->GetInherits();
|
||||
for (cGroup::GroupList::const_iterator itr = Inherits.begin(); itr != Inherits.end(); ++itr)
|
||||
{
|
||||
if (AllGroups.find( *itr) != AllGroups.end())
|
||||
{
|
||||
LOGERROR("ERROR: Player %s is in the same group multiple times due to inheritance (%s). FIX IT!", GetName().c_str(), (*itr)->GetName().c_str());
|
||||
continue;
|
||||
}
|
||||
ToIterate.push_back( *itr);
|
||||
}
|
||||
}
|
||||
ToIterate.erase( ToIterate.begin());
|
||||
}
|
||||
// There are more sub-items in either the permission or the template, not a match:
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -1535,17 +1428,14 @@ void cPlayer::ResolveGroups()
|
||||
|
||||
AString cPlayer::GetColor(void) const
|
||||
{
|
||||
if (m_Color != '-')
|
||||
if (m_MsgNameColorCode.empty() || (m_MsgNameColorCode == "-"))
|
||||
{
|
||||
return cChatColor::Delimiter + m_Color;
|
||||
// Color has not been assigned, return an empty string:
|
||||
return AString();
|
||||
}
|
||||
|
||||
if (m_Groups.size() < 1)
|
||||
{
|
||||
return cChatColor::White;
|
||||
}
|
||||
|
||||
return (*m_Groups.begin())->GetColor();
|
||||
// Return the color, including the delimiter:
|
||||
return cChatColor::Delimiter + m_MsgNameColorCode;
|
||||
}
|
||||
|
||||
|
||||
@ -1661,48 +1551,9 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
|
||||
|
||||
|
||||
|
||||
void cPlayer::LoadPermissionsFromDisk()
|
||||
{
|
||||
m_Groups.clear();
|
||||
m_Permissions.clear();
|
||||
|
||||
cIniFile IniFile;
|
||||
if (IniFile.ReadFile("users.ini"))
|
||||
{
|
||||
AString Groups = IniFile.GetValueSet(GetName(), "Groups", "Default");
|
||||
AStringVector Split = StringSplitAndTrim(Groups, ",");
|
||||
|
||||
for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr)
|
||||
{
|
||||
if (!cRoot::Get()->GetGroupManager()->ExistsGroup(*itr))
|
||||
{
|
||||
LOGWARNING("The group %s for player %s was not found!", itr->c_str(), GetName().c_str());
|
||||
}
|
||||
AddToGroup(*itr);
|
||||
}
|
||||
|
||||
AString Color = IniFile.GetValue(GetName(), "Color", "-");
|
||||
if (!Color.empty())
|
||||
{
|
||||
m_Color = Color[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cGroupManager::GenerateDefaultUsersIni(IniFile);
|
||||
IniFile.AddValue("Groups", GetName(), "Default");
|
||||
AddToGroup("Default");
|
||||
}
|
||||
IniFile.WriteFile("users.ini");
|
||||
ResolvePermissions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlayer::LoadFromDisk(cWorldPtr & a_World)
|
||||
{
|
||||
LoadPermissionsFromDisk();
|
||||
LoadRank();
|
||||
|
||||
// Load from the UUID file:
|
||||
if (LoadFromFile(GetUUIDFileName(m_UUID), a_World))
|
||||
@ -1937,26 +1788,6 @@ bool cPlayer::SaveToDisk()
|
||||
|
||||
|
||||
|
||||
cPlayer::StringList cPlayer::GetResolvedPermissions()
|
||||
{
|
||||
StringList Permissions;
|
||||
|
||||
const PermissionMap& ResolvedPermissions = m_ResolvedPermissions;
|
||||
for (PermissionMap::const_iterator itr = ResolvedPermissions.begin(); itr != ResolvedPermissions.end(); ++itr)
|
||||
{
|
||||
if (itr->second)
|
||||
{
|
||||
Permissions.push_back( itr->first);
|
||||
}
|
||||
}
|
||||
|
||||
return Permissions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlayer::UseEquippedItem(int a_Amount)
|
||||
{
|
||||
if (IsGameModeCreative()) // No damage in creative
|
||||
@ -2215,6 +2046,31 @@ void cPlayer::ApplyFoodExhaustionFromMovement()
|
||||
|
||||
|
||||
|
||||
void cPlayer::LoadRank(void)
|
||||
{
|
||||
// Load the values from cRankManager:
|
||||
cRankManager & RankMgr = cRoot::Get()->GetRankManager();
|
||||
m_Rank = RankMgr.GetPlayerRankName(m_UUID);
|
||||
if (m_Rank.empty())
|
||||
{
|
||||
m_Rank = RankMgr.GetDefaultRank();
|
||||
}
|
||||
m_Permissions = RankMgr.GetPlayerPermissions(m_UUID);
|
||||
RankMgr.GetRankVisuals(m_Rank, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);
|
||||
|
||||
// Break up the individual permissions on each dot, into m_SplitPermissions:
|
||||
m_SplitPermissions.clear();
|
||||
m_SplitPermissions.reserve(m_Permissions.size());
|
||||
for (AStringVector::const_iterator itr = m_Permissions.begin(), end = m_Permissions.end(); itr != end; ++itr)
|
||||
{
|
||||
m_SplitPermissions.push_back(StringSplit(*itr, "."));
|
||||
} // for itr - m_Permissions[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlayer::Detach()
|
||||
{
|
||||
super::Detach();
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
|
||||
|
||||
class cGroup;
|
||||
class cWindow;
|
||||
class cClientHandle;
|
||||
class cTeam;
|
||||
@ -236,24 +235,20 @@ public:
|
||||
|
||||
// tolua_end
|
||||
|
||||
typedef std::list< cGroup* > GroupList;
|
||||
typedef std::list< std::string > StringList;
|
||||
bool HasPermission(const AString & a_Permission); // tolua_export
|
||||
|
||||
/** Adds a player to existing group or creates a new group when it doesn't exist */
|
||||
void AddToGroup( const AString & a_GroupName); // tolua_export
|
||||
/** Returns true iff a_Permission matches the a_Template.
|
||||
A match is defined by either being exactly the same, or each sub-item matches until there's a wildcard in a_Template.
|
||||
Ie. {"a", "b", "c"} matches {"a", "b", "*"} but doesn't match {"a", "b"} */
|
||||
static bool PermissionMatches(const AStringVector & a_Permission, const AStringVector & a_Template); // Exported in ManualBindings with AString params
|
||||
|
||||
/** Removes a player from the group, resolves permissions and group inheritance (case sensitive) */
|
||||
void RemoveFromGroup( const AString & a_GroupName); // tolua_export
|
||||
|
||||
bool HasPermission( const AString & a_Permission); // tolua_export
|
||||
const GroupList & GetGroups() { return m_Groups; } // >> EXPORTED IN MANUALBINDINGS <<
|
||||
StringList GetResolvedPermissions(); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
bool IsInGroup( const AString & a_Group); // tolua_export
|
||||
/** Returns all the permissions that the player has assigned to them. */
|
||||
const AStringVector & GetPermissions(void) { return m_Permissions; } // Exported in ManualBindings.cpp
|
||||
|
||||
// tolua_begin
|
||||
|
||||
/** Returns the full color code to use for this player, based on their primary group or set in m_Color.
|
||||
The returned value includes the cChatColor::Delimiter. */
|
||||
/** Returns the full color code to use for this player, based on their rank.
|
||||
The returned value either is empty, or includes the cChatColor::Delimiter. */
|
||||
AString GetColor(void) const;
|
||||
|
||||
/** tosses the item in the selected hotbar slot */
|
||||
@ -347,8 +342,6 @@ public:
|
||||
*/
|
||||
bool LoadFromFile(const AString & a_FileName, cWorldPtr & a_World);
|
||||
|
||||
void LoadPermissionsFromDisk(void); // tolua_export
|
||||
|
||||
const AString & GetLoadedWorldName() { return m_LoadedWorldName; }
|
||||
|
||||
void UseEquippedItem(int a_Amount = 1);
|
||||
@ -422,6 +415,11 @@ public:
|
||||
/** Returns the UUID (short format) that has been read from the client, or empty string if not available. */
|
||||
const AString & GetUUID(void) const { return m_UUID; }
|
||||
|
||||
/** (Re)loads the rank and permissions from the cRankManager.
|
||||
Expects the m_UUID member to be valid.
|
||||
Loads the m_Rank, m_Permissions, m_MsgPrefix, m_MsgSuffix and m_MsgNameColorCode members. */
|
||||
void LoadRank(void);
|
||||
|
||||
// tolua_end
|
||||
|
||||
// cEntity overrides:
|
||||
@ -432,12 +430,22 @@ public:
|
||||
virtual void Detach(void);
|
||||
|
||||
protected:
|
||||
typedef std::map< std::string, bool > PermissionMap;
|
||||
PermissionMap m_ResolvedPermissions;
|
||||
PermissionMap m_Permissions;
|
||||
|
||||
GroupList m_ResolvedGroups;
|
||||
GroupList m_Groups;
|
||||
typedef std::vector<std::vector<AString> > AStringVectorVector;
|
||||
|
||||
/** The name of the rank assigned to this player. */
|
||||
AString m_Rank;
|
||||
|
||||
/** All the permissions that this player has, based on their rank. */
|
||||
AStringVector m_Permissions;
|
||||
|
||||
/** All the permissions that this player has, based on their rank, split into individual dot-delimited parts.
|
||||
This is used mainly by the HasPermission() function to optimize the lookup. */
|
||||
AStringVectorVector m_SplitPermissions;
|
||||
|
||||
// Message visuals:
|
||||
AString m_MsgPrefix, m_MsgSuffix;
|
||||
AString m_MsgNameColorCode;
|
||||
|
||||
AString m_PlayerName;
|
||||
AString m_LoadedWorldName;
|
||||
@ -482,8 +490,6 @@ protected:
|
||||
/** The player's last saved bed position */
|
||||
Vector3i m_LastBedPos;
|
||||
|
||||
char m_Color;
|
||||
|
||||
eGameMode m_GameMode;
|
||||
AString m_IP;
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#include "Group.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cGroup::AddCommand( const AString & a_Command)
|
||||
{
|
||||
m_Commands[ a_Command ] = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cGroup::AddPermission( const AString & a_Permission)
|
||||
{
|
||||
m_Permissions[ a_Permission ] = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cGroup::InheritFrom( cGroup* a_Group)
|
||||
{
|
||||
m_Inherits.remove( a_Group);
|
||||
m_Inherits.push_back( a_Group);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cGroup::ClearPermission()
|
||||
{
|
||||
m_Permissions.clear();
|
||||
}
|
44
src/Group.h
44
src/Group.h
@ -1,44 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
class cGroup
|
||||
{
|
||||
public:
|
||||
// tolua_end
|
||||
cGroup() {}
|
||||
~cGroup() {}
|
||||
|
||||
// tolua_begin
|
||||
void SetName( const AString & a_Name) { m_Name = a_Name; }
|
||||
const AString & GetName() const { return m_Name; }
|
||||
void SetColor( const AString & a_Color) { m_Color = a_Color; }
|
||||
void AddCommand( const AString & a_Command);
|
||||
void AddPermission( const AString & a_Permission);
|
||||
void InheritFrom( cGroup* a_Group);
|
||||
// tolua_end
|
||||
|
||||
typedef std::map< AString, bool > PermissionMap;
|
||||
const PermissionMap & GetPermissions() const { return m_Permissions; }
|
||||
|
||||
void ClearPermission(void);
|
||||
|
||||
typedef std::map< AString, bool > CommandMap;
|
||||
const CommandMap & GetCommands() const { return m_Commands; }
|
||||
|
||||
const AString & GetColor() const { return m_Color; } // tolua_export
|
||||
|
||||
typedef std::list< cGroup* > GroupList;
|
||||
const GroupList & GetInherits() const { return m_Inherits; }
|
||||
private:
|
||||
AString m_Name;
|
||||
AString m_Color;
|
||||
|
||||
PermissionMap m_Permissions;
|
||||
CommandMap m_Commands;
|
||||
GroupList m_Inherits;
|
||||
}; // tolua_export
|
@ -1,227 +0,0 @@
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#include "GroupManager.h"
|
||||
#include "Group.h"
|
||||
#include "inifile/iniFile.h"
|
||||
#include "ChatColor.h"
|
||||
#include "Root.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef std::map< AString, cGroup* > GroupMap;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct cGroupManager::sGroupManagerState
|
||||
{
|
||||
GroupMap Groups;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cGroupManager::~cGroupManager()
|
||||
{
|
||||
for (GroupMap::iterator itr = m_pState->Groups.begin(); itr != m_pState->Groups.end(); ++itr)
|
||||
{
|
||||
delete itr->second;
|
||||
itr->second = NULL;
|
||||
}
|
||||
m_pState->Groups.clear();
|
||||
|
||||
delete m_pState;
|
||||
m_pState = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cGroupManager::cGroupManager()
|
||||
: m_pState( new sGroupManagerState)
|
||||
{
|
||||
LOGD("-- Loading Groups --");
|
||||
|
||||
if (!LoadGroups())
|
||||
{
|
||||
LOGWARNING("ERROR: Groups could not load!");
|
||||
}
|
||||
if (!CheckUsers())
|
||||
{
|
||||
LOGWARNING("ERROR: User file could not be found!");
|
||||
}
|
||||
|
||||
LOGD("-- Groups Successfully Loaded --");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cGroupManager::GenerateDefaultUsersIni(cIniFile & a_IniFile)
|
||||
{
|
||||
LOGWARN("Regenerating users.ini, all users will be reset");
|
||||
a_IniFile.AddHeaderComment(" This file stores the players' groups.");
|
||||
a_IniFile.AddHeaderComment(" The format is:");
|
||||
a_IniFile.AddHeaderComment(" [PlayerName]");
|
||||
a_IniFile.AddHeaderComment(" Groups = GroupName1, GroupName2, ...");
|
||||
|
||||
a_IniFile.WriteFile("users.ini");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cGroupManager::CheckUsers()
|
||||
{
|
||||
cIniFile IniFile;
|
||||
if (!IniFile.ReadFile("users.ini"))
|
||||
{
|
||||
GenerateDefaultUsersIni(IniFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
int NumKeys = IniFile.GetNumKeys();
|
||||
for (int i = 0; i < NumKeys; i++)
|
||||
{
|
||||
AString Player = IniFile.GetKeyName(i);
|
||||
AString Groups = IniFile.GetValue(Player, "Groups", "");
|
||||
if (Groups.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
AStringVector Split = StringSplitAndTrim(Groups, ",");
|
||||
for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr)
|
||||
{
|
||||
if (!ExistsGroup(*itr))
|
||||
{
|
||||
LOGWARNING("The group %s for player %s was not found!", Split[i].c_str(), Player.c_str());
|
||||
}
|
||||
} // for itr - Split[]
|
||||
} // for i - ini file keys
|
||||
// Always return true for now, just but we can handle writefile fails later.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cGroupManager::LoadGroups()
|
||||
{
|
||||
cIniFile IniFile;
|
||||
if (!IniFile.ReadFile("groups.ini"))
|
||||
{
|
||||
LOGWARNING("Regenerating groups.ini, all groups will be reset");
|
||||
IniFile.AddHeaderComment(" This is the MCServer permissions manager groups file");
|
||||
IniFile.AddHeaderComment(" It stores all defined groups such as Administrators, Players, or Moderators");
|
||||
|
||||
IniFile.SetValue("Owner", "Permissions", "*", true);
|
||||
IniFile.SetValue("Owner", "Color", "2", true);
|
||||
|
||||
IniFile.SetValue("Moderator", "Permissions", "core.time, core.item, core.tpa, core.tpaccept, core.ban, core.unban, core.save-all, core.toggledownfall");
|
||||
IniFile.SetValue("Moderator", "Color", "2", true);
|
||||
IniFile.SetValue("Moderator", "Inherits", "Player", true);
|
||||
|
||||
IniFile.SetValue("Player", "Permissions", "core.portal", true);
|
||||
IniFile.SetValue("Player", "Color", "f", true);
|
||||
IniFile.SetValue("Player", "Inherits", "Default", true);
|
||||
|
||||
IniFile.SetValue("Default", "Permissions", "core.help, core.plugins, core.spawn, core.worlds, core.back, core.motd, core.build, core.locate, core.viewdistance", true);
|
||||
IniFile.SetValue("Default", "Color", "f", true);
|
||||
|
||||
IniFile.WriteFile("groups.ini");
|
||||
}
|
||||
|
||||
int NumKeys = IniFile.GetNumKeys();
|
||||
for (int i = 0; i < NumKeys; i++)
|
||||
{
|
||||
AString KeyName = IniFile.GetKeyName(i);
|
||||
cGroup * Group = GetGroup(KeyName.c_str());
|
||||
|
||||
Group->ClearPermission(); // Needed in case the groups are reloaded.
|
||||
|
||||
LOGD("Loading group %s", KeyName.c_str());
|
||||
|
||||
Group->SetName(KeyName);
|
||||
AString Color = IniFile.GetValue(KeyName, "Color", "-");
|
||||
if ((Color != "-") && (Color.length() >= 1))
|
||||
{
|
||||
Group->SetColor(AString(cChatColor::Delimiter) + Color[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Group->SetColor(cChatColor::White);
|
||||
}
|
||||
|
||||
AString Commands = IniFile.GetValue(KeyName, "Commands", "");
|
||||
if (!Commands.empty())
|
||||
{
|
||||
AStringVector Split = StringSplitAndTrim(Commands, ",");
|
||||
for (size_t i = 0; i < Split.size(); i++)
|
||||
{
|
||||
Group->AddCommand(Split[i]);
|
||||
}
|
||||
}
|
||||
|
||||
AString Permissions = IniFile.GetValue(KeyName, "Permissions", "");
|
||||
if (!Permissions.empty())
|
||||
{
|
||||
AStringVector Split = StringSplitAndTrim(Permissions, ",");
|
||||
for (size_t i = 0; i < Split.size(); i++)
|
||||
{
|
||||
Group->AddPermission(Split[i]);
|
||||
}
|
||||
}
|
||||
|
||||
AString Groups = IniFile.GetValue(KeyName, "Inherits", "");
|
||||
if (!Groups.empty())
|
||||
{
|
||||
AStringVector Split = StringSplitAndTrim(Groups, ",");
|
||||
for (size_t i = 0; i < Split.size(); i++)
|
||||
{
|
||||
Group->InheritFrom(GetGroup(Split[i].c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Always return true, we can handle writefile fails later.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cGroupManager::ExistsGroup( const AString & a_Name)
|
||||
{
|
||||
GroupMap::iterator itr = m_pState->Groups.find( a_Name);
|
||||
return ( itr != m_pState->Groups.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cGroup* cGroupManager::GetGroup( const AString & a_Name)
|
||||
{
|
||||
GroupMap::iterator itr = m_pState->Groups.find( a_Name);
|
||||
if (itr != m_pState->Groups.end())
|
||||
{
|
||||
return itr->second;
|
||||
}
|
||||
|
||||
cGroup* Group = new cGroup();
|
||||
m_pState->Groups[a_Name] = Group;
|
||||
|
||||
return Group;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,36 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cGroup;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cGroupManager
|
||||
{
|
||||
public:
|
||||
bool ExistsGroup(const AString & a_Name);
|
||||
cGroup * GetGroup(const AString & a_Name);
|
||||
bool LoadGroups();
|
||||
bool CheckUsers();
|
||||
|
||||
/** Writes the default header to the specified ini file, and saves it as "users.ini". */
|
||||
static void GenerateDefaultUsersIni(cIniFile & a_IniFile);
|
||||
|
||||
private:
|
||||
friend class cRoot;
|
||||
cGroupManager();
|
||||
~cGroupManager();
|
||||
|
||||
struct sGroupManagerState;
|
||||
sGroupManagerState * m_pState;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "inifile/iniFile.h"
|
||||
#include "json/json.h"
|
||||
#include "PolarSSL++/BlockingSslClientSocket.h"
|
||||
#include "../RankManager.h"
|
||||
|
||||
|
||||
|
||||
@ -300,6 +301,7 @@ void cMojangAPI::AddPlayerNameToUUIDMapping(const AString & a_PlayerName, const
|
||||
cCSLock Lock(m_CSUUIDToName);
|
||||
m_UUIDToName[UUID] = sProfile(a_PlayerName, UUID, "", "", Now);
|
||||
}
|
||||
NotifyNameUUID(a_PlayerName, a_UUID);
|
||||
}
|
||||
|
||||
|
||||
@ -322,6 +324,7 @@ void cMojangAPI::AddPlayerProfile(const AString & a_PlayerName, const AString &
|
||||
cCSLock Lock(m_CSUUIDToProfile);
|
||||
m_UUIDToProfile[UUID] = sProfile(a_PlayerName, UUID, a_Properties, Now);
|
||||
}
|
||||
NotifyNameUUID(a_PlayerName, a_UUID);
|
||||
}
|
||||
|
||||
|
||||
@ -669,6 +672,7 @@ void cMojangAPI::CacheNamesToUUIDs(const AStringVector & a_PlayerNames)
|
||||
continue;
|
||||
}
|
||||
m_NameToUUID[StrToLower(JsonName)] = sProfile(JsonName, JsonUUID, "", "", Now);
|
||||
NotifyNameUUID(JsonName, JsonUUID);
|
||||
} // for idx - root[]
|
||||
} // cCSLock (m_CSNameToUUID)
|
||||
|
||||
@ -792,6 +796,21 @@ void cMojangAPI::CacheUUIDToProfile(const AString & a_UUID)
|
||||
cCSLock Lock(m_CSNameToUUID);
|
||||
m_NameToUUID[StrToLower(PlayerName)] = sProfile(PlayerName, a_UUID, Properties, Now);
|
||||
}
|
||||
NotifyNameUUID(PlayerName, a_UUID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cMojangAPI::NotifyNameUUID(const AString & a_PlayerName, const AString & a_UUID)
|
||||
{
|
||||
// Notify the rank manager:
|
||||
cCSLock Lock(m_CSRankMgr);
|
||||
if (m_RankMgr != NULL)
|
||||
{
|
||||
m_RankMgr->NotifyNameUUID(a_PlayerName, a_UUID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,6 +11,13 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// fwd: ../RankManager.h"
|
||||
class cRankManager;
|
||||
|
||||
namespace Json
|
||||
{
|
||||
class Value;
|
||||
@ -38,8 +45,6 @@ public:
|
||||
Returns true if all was successful, false on failure. */
|
||||
static bool SecureRequest(const AString & a_ServerName, const AString & a_Request, AString & a_Response);
|
||||
|
||||
// tolua_begin
|
||||
|
||||
/** Normalizes the given UUID to its short form (32 bytes, no dashes, lowercase).
|
||||
Logs a warning and returns empty string if not a UUID.
|
||||
Note: only checks the string's length, not the actual content. */
|
||||
@ -50,8 +55,6 @@ public:
|
||||
Note: only checks the string's length, not the actual content. */
|
||||
static AString MakeUUIDDashed(const AString & a_UUID);
|
||||
|
||||
// tolua_end
|
||||
|
||||
/** Converts a player name into a UUID.
|
||||
The UUID will be empty on error.
|
||||
If a_UseOnlyCached is true, the function only consults the cached values.
|
||||
@ -86,6 +89,9 @@ public:
|
||||
the profile to the respective mapping caches and updtes their datetime stamp to now. */
|
||||
void AddPlayerProfile(const AString & a_PlayerName, const AString & a_UUID, const Json::Value & a_Properties);
|
||||
|
||||
/** Sets the m_RankMgr that is used for name-uuid notifications. Accepts NULL to remove the binding. */
|
||||
void SetRankManager(cRankManager * a_RankManager) { m_RankMgr = a_RankManager; }
|
||||
|
||||
protected:
|
||||
/** Holds data for a single player profile. */
|
||||
struct sProfile
|
||||
@ -166,6 +172,12 @@ protected:
|
||||
/** Protects m_UUIDToProfile against simultaneous multi-threaded access. */
|
||||
cCriticalSection m_CSUUIDToProfile;
|
||||
|
||||
/** The rank manager that is notified of the name-uuid pairings. May be NULL. Protected by m_CSRankMgr. */
|
||||
cRankManager * m_RankMgr;
|
||||
|
||||
/** Protects m_RankMgr agains simultaneous multi-threaded access. */
|
||||
cCriticalSection m_CSRankMgr;
|
||||
|
||||
|
||||
/** Loads the caches from a disk storage. */
|
||||
void LoadCachesFromDisk(void);
|
||||
@ -182,6 +194,10 @@ protected:
|
||||
UUIDs that are not valid will not be added into the cache.
|
||||
ASSUMEs that a_UUID is a lowercased short UUID. */
|
||||
void CacheUUIDToProfile(const AString & a_UUID);
|
||||
|
||||
/** Called for each name-uuid pairing that is discovered.
|
||||
If assigned, notifies the m_RankManager of the event. */
|
||||
void NotifyNameUUID(const AString & a_PlayerName, const AString & a_PlayerUUID);
|
||||
} ; // tolua_export
|
||||
|
||||
|
||||
|
1839
src/RankManager.cpp
Normal file
1839
src/RankManager.cpp
Normal file
File diff suppressed because it is too large
Load Diff
246
src/RankManager.h
Normal file
246
src/RankManager.h
Normal file
@ -0,0 +1,246 @@
|
||||
|
||||
// RankManager.h
|
||||
|
||||
// Declares the cRankManager class that represents the rank manager responsible for assigning permissions and message visuals to players
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SQLiteCpp/Database.h"
|
||||
#include "SQLiteCpp/Transaction.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cMojangAPI;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cRankManager
|
||||
{
|
||||
public:
|
||||
/** Acquire this lock to perform mass changes.
|
||||
Improves performance by wrapping everything into a transaction.
|
||||
Makes sure that no other thread is accessing the DB. */
|
||||
class cMassChangeLock
|
||||
{
|
||||
public:
|
||||
cMassChangeLock(cRankManager & a_RankManager) :
|
||||
m_Lock(a_RankManager.m_CS),
|
||||
m_Transaction(a_RankManager.m_DB)
|
||||
{
|
||||
}
|
||||
|
||||
~cMassChangeLock()
|
||||
{
|
||||
m_Transaction.commit();
|
||||
}
|
||||
|
||||
protected:
|
||||
cCSLock m_Lock;
|
||||
SQLite::Transaction m_Transaction;
|
||||
};
|
||||
|
||||
|
||||
/** Creates the rank manager. Needs to be initialized before other use. */
|
||||
cRankManager(void);
|
||||
|
||||
~cRankManager();
|
||||
|
||||
/** Initializes the rank manager. Performs migration and default-setting if no data is found in the DB.
|
||||
The a_MojangAPI param is used when migrating from old ini files, to look up player UUIDs. */
|
||||
void Initialize(cMojangAPI & a_MojangAPI);
|
||||
|
||||
/** Returns the name of the rank that the specified player has assigned to them.
|
||||
If the player has no rank assigned, returns an empty string (NOT the default rank). */
|
||||
AString GetPlayerRankName(const AString & a_PlayerUUID);
|
||||
|
||||
/** Returns the names of Groups that the specified player has assigned to them. */
|
||||
AStringVector GetPlayerGroups(const AString & a_PlayerUUID);
|
||||
|
||||
/** Returns the permissions that the specified player has assigned to them.
|
||||
If the player has no rank assigned to them, returns the default rank's permissions. */
|
||||
AStringVector GetPlayerPermissions(const AString & a_PlayerUUID);
|
||||
|
||||
/** Returns the names of groups that the specified rank has assigned to it.
|
||||
Returns an empty vector if the rank doesn't exist. */
|
||||
AStringVector GetRankGroups(const AString & a_RankName);
|
||||
|
||||
/** Returns the permissions that the specified group has assigned to it.
|
||||
Returns an empty vector if the group doesn't exist. */
|
||||
AStringVector GetGroupPermissions(const AString & a_GroupName);
|
||||
|
||||
/** Returns all permissions that the specified rank has assigned to it, through all its groups.
|
||||
Returns an empty vector if the rank doesn't exist. Any non-existent groups are ignored. */
|
||||
AStringVector GetRankPermissions(const AString & a_RankName);
|
||||
|
||||
/** Returns the names of all defined ranks. */
|
||||
AStringVector GetAllRanks(void);
|
||||
|
||||
/** Returns the names of all permission groups. */
|
||||
AStringVector GetAllGroups(void);
|
||||
|
||||
/** Returns all the distinct permissions that are stored in the DB. */
|
||||
AStringVector GetAllPermissions(void);
|
||||
|
||||
/** Returns the message visuals (prefix, postfix, color) for the specified player.
|
||||
Returns true if the visuals were read from the DB, false if not (player not found etc). */
|
||||
bool GetPlayerMsgVisuals(
|
||||
const AString & a_PlayerUUID,
|
||||
AString & a_MsgPrefix,
|
||||
AString & a_MsgSuffix,
|
||||
AString & a_MsgNameColorCode
|
||||
);
|
||||
|
||||
/** Adds a new rank. No action if the rank already exists. */
|
||||
void AddRank(
|
||||
const AString & a_RankName,
|
||||
const AString & a_MsgPrefix,
|
||||
const AString & a_MsgSuffix,
|
||||
const AString & a_MsgNameColorCode
|
||||
);
|
||||
|
||||
/** Adds a new permission group. No action if such a group already exists. */
|
||||
void AddGroup(const AString & a_GroupName);
|
||||
|
||||
/** Bulk-adds groups. Group names that already exist are silently skipped. */
|
||||
void AddGroups(const AStringVector & a_GroupNames);
|
||||
|
||||
/** Adds the specified permission group to the specified rank.
|
||||
Fails if the rank or group names are not found.
|
||||
Returns true if successful, false on error. */
|
||||
bool AddGroupToRank(const AString & a_GroupName, const AString & a_RankName);
|
||||
|
||||
/** Adds the specified permission to the specified permission group.
|
||||
Fails if the permission group name is not found.
|
||||
Returns true if successful, false on error. */
|
||||
bool AddPermissionToGroup(const AString & a_Permission, const AString & a_GroupName);
|
||||
|
||||
/** Adds the specified permissions to the specified permission group.
|
||||
Fails if the permission group name is not found.
|
||||
Returns true if successful, false on error. */
|
||||
bool AddPermissionsToGroup(const AStringVector & a_Permissions, const AString & a_GroupName);
|
||||
|
||||
/** Removes the specified rank.
|
||||
All players assigned to that rank will be re-assigned to a_ReplacementRankName.
|
||||
If a_ReplacementRankName is empty or not a valid rank, the player will be removed from the DB,
|
||||
which means they will receive the default rank the next time they are queried.
|
||||
If the rank being removed is the default rank, the default will be changed to the replacement
|
||||
rank; the operation fails if there's no replacement. */
|
||||
void RemoveRank(const AString & a_RankName, const AString & a_ReplacementRankName);
|
||||
|
||||
/** Removes the specified group completely.
|
||||
The group will first be removed from all ranks using it, and then removed itself. */
|
||||
void RemoveGroup(const AString & a_GroupName);
|
||||
|
||||
/** Removes the specified group from the specified rank.
|
||||
The group will stay defined, even if no rank is using it. */
|
||||
void RemoveGroupFromRank(const AString & a_GroupName, const AString & a_RankName);
|
||||
|
||||
/** Removes the specified permission from the specified group. */
|
||||
void RemovePermissionFromGroup(const AString & a_Permission, const AString & a_GroupName);
|
||||
|
||||
/** Renames the specified rank. No action if the rank name is not found.
|
||||
Fails if the new name is already used.
|
||||
Updates the cached m_DefaultRank if the default rank is being renamed.
|
||||
Returns true on success, false on failure. */
|
||||
bool RenameRank(const AString & a_OldName, const AString & a_NewName);
|
||||
|
||||
/** Renames the specified group. No action if the rank name is not found.
|
||||
Fails if the new name is already used.
|
||||
Returns true on success, false on failure. */
|
||||
bool RenameGroup(const AString & a_OldName, const AString & a_NewName);
|
||||
|
||||
/** Sets the specified player's rank.
|
||||
If the player already had rank assigned to them, it is overwritten with the new rank and name.
|
||||
Note that this doesn't change the cPlayer if the player is already connected, you need to update all the
|
||||
cPlayer instances manually.
|
||||
The PlayerName is provided for reference, so that GetRankPlayerNames() can work. */
|
||||
void SetPlayerRank(const AString & a_PlayerUUID, const AString & a_PlayerName, const AString & a_RankName);
|
||||
|
||||
/** Removes the player's rank assignment. The player is left without a rank.
|
||||
Note that this doesn't change the cPlayer instances for the already connected players, you need to update
|
||||
all the instances manually.
|
||||
No action if the player has no rank assigned to them already. */
|
||||
void RemovePlayerRank(const AString & a_PlayerUUID);
|
||||
|
||||
/** Sets the message visuals of an existing rank. No action if the rank name is not found. */
|
||||
void SetRankVisuals(
|
||||
const AString & a_RankName,
|
||||
const AString & a_MsgPrefix,
|
||||
const AString & a_MsgSuffix,
|
||||
const AString & a_MsgNameColorCode
|
||||
);
|
||||
|
||||
/** Returns the message visuals of an existing rank.
|
||||
Returns true if successful, false on error (rank doesn't exist). */
|
||||
bool GetRankVisuals(
|
||||
const AString & a_RankName,
|
||||
AString & a_MsgPrefix,
|
||||
AString & a_MsgSuffix,
|
||||
AString & a_MsgNameColorCode
|
||||
);
|
||||
|
||||
/** Returns true iff the specified rank exists in the DB. */
|
||||
bool RankExists(const AString & a_RankName);
|
||||
|
||||
/** Returns true iff the specified group exists in the DB. */
|
||||
bool GroupExists(const AString & a_GroupName);
|
||||
|
||||
/** Returns true iff the specified player has a rank assigned to them in the DB. */
|
||||
bool IsPlayerRankSet(const AString & a_PlayerUUID);
|
||||
|
||||
/** Returns true iff the specified rank contains the specified group. */
|
||||
bool IsGroupInRank(const AString & a_GroupName, const AString & a_RankName);
|
||||
|
||||
/** Returns true iff the specified group contains the specified permission. */
|
||||
bool IsPermissionInGroup(const AString & a_Permission, const AString & a_GroupName);
|
||||
|
||||
/** Called by cMojangAPI whenever the playername-uuid pairing is discovered. Updates the DB. */
|
||||
void NotifyNameUUID(const AString & a_PlayerName, const AString & a_UUID);
|
||||
|
||||
/** Sets the specified rank as the default rank.
|
||||
Returns true on success, false on failure (rank not found). */
|
||||
bool SetDefaultRank(const AString & a_RankName);
|
||||
|
||||
/** Returns the name of the default rank. */
|
||||
const AString & GetDefaultRank(void) const { return m_DefaultRank; }
|
||||
|
||||
protected:
|
||||
|
||||
/** The database storage for all the data. Protected by m_CS. */
|
||||
SQLite::Database m_DB;
|
||||
|
||||
/** The name of the default rank. Kept as a cache so that queries for it don't need to go through the DB. */
|
||||
AString m_DefaultRank;
|
||||
|
||||
/** The mutex protecting m_DB and m_DefaultRank against multi-threaded access. */
|
||||
cCriticalSection m_CS;
|
||||
|
||||
/** Set to true once the manager is initialized. */
|
||||
bool m_IsInitialized;
|
||||
|
||||
/** The MojangAPI instance that is used for translating playernames to UUIDs.
|
||||
Set in Initialize(), may be NULL. */
|
||||
cMojangAPI * m_MojangAPI;
|
||||
|
||||
|
||||
/** Returns true if all the DB tables are empty, indicating a fresh new install. */
|
||||
bool AreDBTablesEmpty(void);
|
||||
|
||||
/** Returns true iff the specified DB table is empty.
|
||||
If there's an error while querying, returns false. */
|
||||
bool IsDBTableEmpty(const AString & a_TableName);
|
||||
|
||||
/** Creates a default set of ranks / groups / permissions. */
|
||||
void CreateDefaults(void);
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
17
src/Root.cpp
17
src/Root.cpp
@ -6,7 +6,6 @@
|
||||
#include "World.h"
|
||||
#include "WebAdmin.h"
|
||||
#include "FurnaceRecipe.h"
|
||||
#include "GroupManager.h"
|
||||
#include "CraftingRecipes.h"
|
||||
#include "Bindings/PluginManager.h"
|
||||
#include "MonsterConfig.h"
|
||||
@ -47,7 +46,6 @@ cRoot::cRoot(void) :
|
||||
m_InputThread(NULL),
|
||||
m_Server(NULL),
|
||||
m_MonsterConfig(NULL),
|
||||
m_GroupManager(NULL),
|
||||
m_CraftingRecipes(NULL),
|
||||
m_FurnaceRecipe(NULL),
|
||||
m_WebAdmin(NULL),
|
||||
@ -161,7 +159,7 @@ void cRoot::Start(void)
|
||||
m_WebAdmin->Init();
|
||||
|
||||
LOGD("Loading settings...");
|
||||
m_GroupManager = new cGroupManager();
|
||||
m_RankManager.Initialize(m_MojangAPI);
|
||||
m_CraftingRecipes = new cCraftingRecipes;
|
||||
m_FurnaceRecipe = new cFurnaceRecipe();
|
||||
|
||||
@ -240,8 +238,6 @@ void cRoot::Start(void)
|
||||
LOGD("Unloading recipes...");
|
||||
delete m_FurnaceRecipe; m_FurnaceRecipe = NULL;
|
||||
delete m_CraftingRecipes; m_CraftingRecipes = NULL;
|
||||
LOGD("Forgetting groups...");
|
||||
delete m_GroupManager; m_GroupManager = NULL;
|
||||
LOGD("Unloading worlds...");
|
||||
UnloadWorlds();
|
||||
|
||||
@ -555,17 +551,6 @@ void cRoot::SaveAllChunks(void)
|
||||
|
||||
|
||||
|
||||
void cRoot::ReloadGroups(void)
|
||||
{
|
||||
LOG("Reload groups ...");
|
||||
m_GroupManager->LoadGroups();
|
||||
m_GroupManager->CheckUsers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cRoot::BroadcastChat(const AString & a_Message, eMessageType a_ChatPrefix)
|
||||
{
|
||||
for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr)
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "Protocol/MojangAPI.h"
|
||||
#include "HTTPServer/HTTPServer.h"
|
||||
#include "Defines.h"
|
||||
#include "RankManager.h"
|
||||
|
||||
|
||||
|
||||
@ -13,7 +14,6 @@
|
||||
// fwd:
|
||||
class cThread;
|
||||
class cMonsterConfig;
|
||||
class cGroupManager;
|
||||
class cCraftingRecipes;
|
||||
class cFurnaceRecipe;
|
||||
class cWebAdmin;
|
||||
@ -78,7 +78,6 @@ public:
|
||||
|
||||
cMonsterConfig * GetMonsterConfig(void) { return m_MonsterConfig; }
|
||||
|
||||
cGroupManager * GetGroupManager (void) { return m_GroupManager; } // tolua_export
|
||||
cCraftingRecipes * GetCraftingRecipes(void) { return m_CraftingRecipes; } // tolua_export
|
||||
cFurnaceRecipe * GetFurnaceRecipe (void) { return m_FurnaceRecipe; } // Exported in ManualBindings.cpp with quite a different signature
|
||||
|
||||
@ -89,6 +88,7 @@ public:
|
||||
cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export
|
||||
cAuthenticator & GetAuthenticator (void) { return m_Authenticator; }
|
||||
cMojangAPI & GetMojangAPI (void) { return m_MojangAPI; }
|
||||
cRankManager & GetRankManager (void) { return m_RankManager; }
|
||||
|
||||
/** Queues a console command for execution through the cServer class.
|
||||
The command will be executed in the tick thread
|
||||
@ -122,9 +122,6 @@ public:
|
||||
/// Saves all chunks in all worlds
|
||||
void SaveAllChunks(void); // tolua_export
|
||||
|
||||
/// Reloads all the groups
|
||||
void ReloadGroups(void); // tolua_export
|
||||
|
||||
/// Calls the callback for each player in all worlds
|
||||
bool ForEachPlayer(cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
|
||||
|
||||
@ -187,13 +184,13 @@ private:
|
||||
cServer * m_Server;
|
||||
cMonsterConfig * m_MonsterConfig;
|
||||
|
||||
cGroupManager * m_GroupManager;
|
||||
cCraftingRecipes * m_CraftingRecipes;
|
||||
cFurnaceRecipe * m_FurnaceRecipe;
|
||||
cWebAdmin * m_WebAdmin;
|
||||
cPluginManager * m_PluginManager;
|
||||
cAuthenticator m_Authenticator;
|
||||
cMojangAPI m_MojangAPI;
|
||||
cRankManager m_RankManager;
|
||||
cHTTPServer m_HTTPServer;
|
||||
|
||||
bool m_bStop;
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "World.h"
|
||||
#include "ChunkDef.h"
|
||||
#include "Bindings/PluginManager.h"
|
||||
#include "GroupManager.h"
|
||||
#include "ChatColor.h"
|
||||
#include "Entities/Player.h"
|
||||
#include "Inventory.h"
|
||||
@ -471,25 +470,17 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
|
||||
PrintHelp(split, a_Output);
|
||||
return;
|
||||
}
|
||||
if (split[0] == "reload")
|
||||
{
|
||||
cPluginManager::Get()->ReloadPlugins();
|
||||
cRoot::Get()->ReloadGroups();
|
||||
return;
|
||||
}
|
||||
if (split[0] == "reloadplugins")
|
||||
else if (split[0] == "reload")
|
||||
{
|
||||
cPluginManager::Get()->ReloadPlugins();
|
||||
return;
|
||||
}
|
||||
if (split[0] == "reloadgroups")
|
||||
else if (split[0] == "reloadplugins")
|
||||
{
|
||||
cRoot::Get()->ReloadGroups();
|
||||
a_Output.Out("Groups reloaded!");
|
||||
a_Output.Finished();
|
||||
cPluginManager::Get()->ReloadPlugins();
|
||||
return;
|
||||
}
|
||||
if (split[0] == "load")
|
||||
else if (split[0] == "load")
|
||||
{
|
||||
if (split.size() > 1)
|
||||
{
|
||||
@ -504,8 +495,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (split[0] == "unload")
|
||||
else if (split[0] == "unload")
|
||||
{
|
||||
if (split.size() > 1)
|
||||
{
|
||||
@ -521,21 +511,21 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
|
||||
}
|
||||
|
||||
// There is currently no way a plugin can do these (and probably won't ever be):
|
||||
if (split[0].compare("chunkstats") == 0)
|
||||
else if (split[0].compare("chunkstats") == 0)
|
||||
{
|
||||
cRoot::Get()->LogChunkStats(a_Output);
|
||||
a_Output.Finished();
|
||||
return;
|
||||
}
|
||||
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
|
||||
if (split[0].compare("dumpmem") == 0)
|
||||
else if (split[0].compare("dumpmem") == 0)
|
||||
{
|
||||
LeakFinderXmlOutput Output("memdump.xml");
|
||||
DumpUsedMemory(&Output);
|
||||
return;
|
||||
}
|
||||
|
||||
if (split[0].compare("killmem") == 0)
|
||||
else if (split[0].compare("killmem") == 0)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
@ -544,7 +534,7 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cPluginManager::Get()->ExecuteConsoleCommand(split, a_Output))
|
||||
else if (cPluginManager::Get()->ExecuteConsoleCommand(split, a_Output))
|
||||
{
|
||||
a_Output.Finished();
|
||||
return;
|
||||
|
@ -120,7 +120,7 @@ public: // tolua_export
|
||||
const AString & GetPublicKeyDER(void) const { return m_PublicKeyDER; }
|
||||
|
||||
/** Returns true if authentication has been turned on in server settings. */
|
||||
bool ShouldAuthenticate(void) const { return m_ShouldAuthenticate; }
|
||||
bool ShouldAuthenticate(void) const { return m_ShouldAuthenticate; } // tolua_export
|
||||
|
||||
/** Returns true if offline UUIDs should be used to load data for players whose normal UUIDs cannot be found.
|
||||
Loaded from the settings.ini [PlayerData].LoadOfflinePlayerData setting. */
|
||||
|
Loading…
Reference in New Issue
Block a user