1
0

Improvements:

Adds a function in cRoot that allows you to reload all the groups permissions.
Note: Players don't automatically load their new permissions.
You can use cPlayer::LoadPermissionsFromDisk for that.
This commit is contained in:
STRWarrior 2014-02-05 18:10:08 +01:00
parent 70e48960ac
commit 7c750914f0
6 changed files with 69 additions and 22 deletions

View File

@ -3,19 +3,34 @@
#include "Group.h"
void cGroup::AddCommand( std::string a_Command )
void cGroup::AddCommand( AString a_Command )
{
m_Commands[ a_Command ] = true;
}
void cGroup::AddPermission( std::string a_Permission )
void cGroup::AddPermission( AString a_Permission )
{
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 );
if( itr != m_Commands.end() )
@ -35,3 +50,11 @@ void cGroup::InheritFrom( cGroup* a_Group )
m_Inherits.remove( a_Group );
m_Inherits.push_back( a_Group );
}
void cGroup::ClearPermission()
{
m_Permissions.clear();
}

View File

@ -11,19 +11,21 @@ public: // tolua_export
cGroup() {}
~cGroup() {}
void SetName( std::string a_Name ) { m_Name = a_Name; } // tolua_export
const std::string & GetName() const { return m_Name; } // tolua_export
void SetColor( std::string a_Color ) { m_Color = a_Color; } // tolua_export
void AddCommand( std::string a_Command ); // tolua_export
void AddPermission( std::string a_Permission ); // tolua_export
void InheritFrom( cGroup* a_Group ); // tolua_export
void SetName( AString a_Name ) { m_Name = a_Name; } // tolua_export
const AString & GetName() const { return m_Name; } // tolua_export
void SetColor( AString a_Color ) { m_Color = a_Color; } // tolua_export
void AddCommand( AString a_Command ); // tolua_export
void AddPermission( AString a_Permission ); // 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; }
typedef std::map< std::string, bool > CommandMap;
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
@ -31,8 +33,8 @@ public: // tolua_export
typedef std::list< cGroup* > GroupList;
const GroupList & GetInherits() const { return m_Inherits; }
private:
std::string m_Name;
std::string m_Color;
AString m_Name;
AString m_Color;
PermissionMap m_Permissions;
CommandMap m_Commands;

View File

@ -44,6 +44,18 @@ cGroupManager::cGroupManager()
: m_pState( new sGroupManagerState )
{
LOGD("-- Loading Groups --");
LoadGroups();
LOGD("-- Groups Successfully Loaded --");
}
void cGroupManager::LoadGroups()
{
cIniFile IniFile;
if (!IniFile.ReadFile("groups.ini"))
{
@ -71,9 +83,11 @@ cGroupManager::cGroupManager()
unsigned int NumKeys = IniFile.GetNumKeys();
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() );
Group->ClearPermission(); // Needed in case the groups are reloaded.
LOGD("Loading group: %s", KeyName.c_str() );
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())
{
AStringVector Split = StringSplitAndTrim(Groups, ",");
@ -117,13 +131,8 @@ cGroupManager::cGroupManager()
}
}
}
LOGD("-- Groups Successfully Loaded --");
}
cGroup* cGroupManager::GetGroup( const AString & a_Name )
{
GroupMap::iterator itr = m_pState->Groups.find( a_Name );

View File

@ -15,6 +15,7 @@ class cGroupManager
{
public:
cGroup * GetGroup(const AString & a_Name);
void LoadGroups(void);
private:
friend class cRoot;

View File

@ -536,6 +536,15 @@ void cRoot::SaveAllChunks(void)
void cRoot::ReloadGroups(void)
{
m_GroupManager->LoadGroups();
}
void cRoot::BroadcastChat(const AString & a_Message)
{
for (WorldMap::iterator itr = m_WorldsByName.begin(), end = m_WorldsByName.end(); itr != end; ++itr)

View File

@ -98,6 +98,9 @@ public:
/// Saves all chunks in all worlds
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)
void BroadcastChat(const AString & a_Message); // tolua_export