Merge pull request #645 from mc-server/GroupsPermissions
Improvements to the GroupManager
This commit is contained in:
commit
694fa5d541
@ -3,19 +3,34 @@
|
|||||||
|
|
||||||
#include "Group.h"
|
#include "Group.h"
|
||||||
|
|
||||||
void cGroup::AddCommand( std::string a_Command )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cGroup::AddCommand( AString a_Command )
|
||||||
{
|
{
|
||||||
m_Commands[ a_Command ] = true;
|
m_Commands[ a_Command ] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGroup::AddPermission( std::string a_Permission )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cGroup::AddPermission( AString a_Permission )
|
||||||
{
|
{
|
||||||
m_Permissions[ a_Permission ] = true;
|
m_Permissions[ a_Permission ] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cGroup::HasCommand( std::string a_Command )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cGroup::HasCommand( AString a_Command )
|
||||||
{
|
{
|
||||||
if( m_Commands.find("*") != m_Commands.end() ) return true;
|
if( m_Commands.find("*") != m_Commands.end() )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
CommandMap::iterator itr = m_Commands.find( a_Command );
|
CommandMap::iterator itr = m_Commands.find( a_Command );
|
||||||
if( itr != m_Commands.end() )
|
if( itr != m_Commands.end() )
|
||||||
@ -35,3 +50,11 @@ void cGroup::InheritFrom( cGroup* a_Group )
|
|||||||
m_Inherits.remove( a_Group );
|
m_Inherits.remove( a_Group );
|
||||||
m_Inherits.push_back( a_Group );
|
m_Inherits.push_back( a_Group );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cGroup::ClearPermission()
|
||||||
|
{
|
||||||
|
m_Permissions.clear();
|
||||||
|
}
|
22
src/Group.h
22
src/Group.h
@ -11,19 +11,21 @@ public: // tolua_export
|
|||||||
cGroup() {}
|
cGroup() {}
|
||||||
~cGroup() {}
|
~cGroup() {}
|
||||||
|
|
||||||
void SetName( std::string a_Name ) { m_Name = a_Name; } // tolua_export
|
void SetName( AString a_Name ) { m_Name = a_Name; } // tolua_export
|
||||||
const std::string & GetName() const { return m_Name; } // tolua_export
|
const AString & GetName() const { return m_Name; } // tolua_export
|
||||||
void SetColor( std::string a_Color ) { m_Color = a_Color; } // tolua_export
|
void SetColor( AString a_Color ) { m_Color = a_Color; } // tolua_export
|
||||||
void AddCommand( std::string a_Command ); // tolua_export
|
void AddCommand( AString a_Command ); // tolua_export
|
||||||
void AddPermission( std::string a_Permission ); // tolua_export
|
void AddPermission( AString a_Permission ); // tolua_export
|
||||||
void InheritFrom( cGroup* a_Group ); // tolua_export
|
void InheritFrom( cGroup* a_Group ); // tolua_export
|
||||||
|
|
||||||
bool HasCommand( std::string a_Command ); // tolua_export
|
bool HasCommand( AString a_Command ); // tolua_export
|
||||||
|
|
||||||
typedef std::map< std::string, bool > PermissionMap;
|
typedef std::map< AString, bool > PermissionMap;
|
||||||
const PermissionMap & GetPermissions() const { return m_Permissions; }
|
const PermissionMap & GetPermissions() const { return m_Permissions; }
|
||||||
|
|
||||||
typedef std::map< std::string, bool > CommandMap;
|
void ClearPermission(void);
|
||||||
|
|
||||||
|
typedef std::map< AString, bool > CommandMap;
|
||||||
const CommandMap & GetCommands() const { return m_Commands; }
|
const CommandMap & GetCommands() const { return m_Commands; }
|
||||||
|
|
||||||
const AString & GetColor() const { return m_Color; } // tolua_export
|
const AString & GetColor() const { return m_Color; } // tolua_export
|
||||||
@ -31,8 +33,8 @@ public: // tolua_export
|
|||||||
typedef std::list< cGroup* > GroupList;
|
typedef std::list< cGroup* > GroupList;
|
||||||
const GroupList & GetInherits() const { return m_Inherits; }
|
const GroupList & GetInherits() const { return m_Inherits; }
|
||||||
private:
|
private:
|
||||||
std::string m_Name;
|
AString m_Name;
|
||||||
std::string m_Color;
|
AString m_Color;
|
||||||
|
|
||||||
PermissionMap m_Permissions;
|
PermissionMap m_Permissions;
|
||||||
CommandMap m_Commands;
|
CommandMap m_Commands;
|
||||||
|
@ -44,6 +44,18 @@ cGroupManager::cGroupManager()
|
|||||||
: m_pState( new sGroupManagerState )
|
: m_pState( new sGroupManagerState )
|
||||||
{
|
{
|
||||||
LOGD("-- Loading Groups --");
|
LOGD("-- Loading Groups --");
|
||||||
|
|
||||||
|
LoadGroups();
|
||||||
|
|
||||||
|
LOGD("-- Groups Successfully Loaded --");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cGroupManager::LoadGroups()
|
||||||
|
{
|
||||||
cIniFile IniFile;
|
cIniFile IniFile;
|
||||||
if (!IniFile.ReadFile("groups.ini"))
|
if (!IniFile.ReadFile("groups.ini"))
|
||||||
{
|
{
|
||||||
@ -71,9 +83,11 @@ cGroupManager::cGroupManager()
|
|||||||
unsigned int NumKeys = IniFile.GetNumKeys();
|
unsigned int NumKeys = IniFile.GetNumKeys();
|
||||||
for (size_t i = 0; i < NumKeys; i++)
|
for (size_t i = 0; i < NumKeys; i++)
|
||||||
{
|
{
|
||||||
std::string KeyName = IniFile.GetKeyName( i );
|
AString KeyName = IniFile.GetKeyName( i );
|
||||||
cGroup* Group = GetGroup( KeyName.c_str() );
|
cGroup* Group = GetGroup( KeyName.c_str() );
|
||||||
|
|
||||||
|
Group->ClearPermission(); // Needed in case the groups are reloaded.
|
||||||
|
|
||||||
LOGD("Loading group: %s", KeyName.c_str() );
|
LOGD("Loading group: %s", KeyName.c_str() );
|
||||||
|
|
||||||
Group->SetName(KeyName);
|
Group->SetName(KeyName);
|
||||||
@ -107,7 +121,7 @@ cGroupManager::cGroupManager()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Groups = IniFile.GetValue(KeyName, "Inherits", "");
|
AString Groups = IniFile.GetValue(KeyName, "Inherits", "");
|
||||||
if (!Groups.empty())
|
if (!Groups.empty())
|
||||||
{
|
{
|
||||||
AStringVector Split = StringSplitAndTrim(Groups, ",");
|
AStringVector Split = StringSplitAndTrim(Groups, ",");
|
||||||
@ -117,7 +131,6 @@ cGroupManager::cGroupManager()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGD("-- Groups Successfully Loaded --");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ class cGroupManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cGroup * GetGroup(const AString & a_Name);
|
cGroup * GetGroup(const AString & a_Name);
|
||||||
|
void LoadGroups(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class cRoot;
|
friend class cRoot;
|
||||||
|
@ -536,6 +536,15 @@ void cRoot::SaveAllChunks(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cRoot::ReloadGroups(void)
|
||||||
|
{
|
||||||
|
m_GroupManager->LoadGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cRoot::BroadcastChat(const AString & a_Message)
|
void cRoot::BroadcastChat(const AString & a_Message)
|
||||||
{
|
{
|
||||||
for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr)
|
for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr)
|
||||||
|
@ -98,6 +98,9 @@ public:
|
|||||||
/// Saves all chunks in all worlds
|
/// Saves all chunks in all worlds
|
||||||
void SaveAllChunks(void); // tolua_export
|
void SaveAllChunks(void); // tolua_export
|
||||||
|
|
||||||
|
/// Reloads all the groups
|
||||||
|
void ReloadGroups(void); // tolua_export
|
||||||
|
|
||||||
/// Sends a chat message to all connected clients (in all worlds)
|
/// Sends a chat message to all connected clients (in all worlds)
|
||||||
void BroadcastChat(const AString & a_Message); // tolua_export
|
void BroadcastChat(const AString & a_Message); // tolua_export
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user