2012-06-14 09:06:06 -04:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "GroupManager.h"
|
|
|
|
#include "Group.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
#include "../iniFile/iniFile.h"
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "ChatColor.h"
|
|
|
|
#include "Root.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-18 17:54:56 -04:00
|
|
|
typedef std::map< AString, cGroup* > GroupMap;
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
struct cGroupManager::sGroupManagerState
|
|
|
|
{
|
|
|
|
GroupMap Groups;
|
|
|
|
};
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cGroupManager::~cGroupManager()
|
|
|
|
{
|
|
|
|
for( GroupMap::iterator itr = m_pState->Groups.begin(); itr != m_pState->Groups.end(); ++itr )
|
|
|
|
{
|
|
|
|
delete itr->second;
|
|
|
|
}
|
|
|
|
m_pState->Groups.clear();
|
|
|
|
|
|
|
|
delete m_pState;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cGroupManager::cGroupManager()
|
|
|
|
: m_pState( new sGroupManagerState )
|
|
|
|
{
|
2013-09-28 15:36:01 -04:00
|
|
|
LOGD("-- Loading Groups --");
|
2012-06-14 09:06:06 -04:00
|
|
|
cIniFile IniFile("groups.ini");
|
2012-11-16 17:06:12 -05:00
|
|
|
if (!IniFile.ReadFile())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-08-05 09:24:23 -04:00
|
|
|
LOGWARNING("groups.ini inaccessible, no groups are defined");
|
|
|
|
return;
|
2012-11-16 17:06:12 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-11-16 17:06:12 -05:00
|
|
|
unsigned int NumKeys = IniFile.GetNumKeys();
|
|
|
|
for( unsigned int i = 0; i < NumKeys; i++ )
|
|
|
|
{
|
|
|
|
std::string KeyName = IniFile.GetKeyName( i );
|
|
|
|
cGroup* Group = GetGroup( KeyName.c_str() );
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
LOGD("Loading group: %s", KeyName.c_str() );
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-11-16 17:06:12 -05:00
|
|
|
Group->SetName( KeyName );
|
|
|
|
char Color = IniFile.GetValue( KeyName, "Color", "-" )[0];
|
|
|
|
if( Color != '-' )
|
|
|
|
Group->SetColor( cChatColor::MakeColor(Color) );
|
|
|
|
else
|
|
|
|
Group->SetColor( cChatColor::White );
|
|
|
|
|
|
|
|
std::string Commands = IniFile.GetValue( KeyName, "Commands", "" );
|
|
|
|
if( Commands.size() > 0 )
|
|
|
|
{
|
|
|
|
AStringVector Split = StringSplit( Commands, "," );
|
|
|
|
for( unsigned int i = 0; i < Split.size(); i++)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-11-16 17:06:12 -05:00
|
|
|
Group->AddCommand( Split[i] );
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-11-16 17:06:12 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-11-16 17:06:12 -05:00
|
|
|
std::string Permissions = IniFile.GetValue( KeyName, "Permissions", "" );
|
|
|
|
if( Permissions.size() > 0 )
|
|
|
|
{
|
|
|
|
AStringVector Split = StringSplit( Permissions, "," );
|
|
|
|
for( unsigned int i = 0; i < Split.size(); i++)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-11-16 17:06:12 -05:00
|
|
|
Group->AddPermission( Split[i] );
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-11-16 17:06:12 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-11-16 17:06:12 -05:00
|
|
|
std::string Groups = IniFile.GetValue( KeyName, "Inherits", "" );
|
|
|
|
if( Groups.size() > 0 )
|
|
|
|
{
|
|
|
|
AStringVector Split = StringSplit( Groups, "," );
|
|
|
|
for( unsigned int i = 0; i < Split.size(); i++)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-11-16 17:06:12 -05:00
|
|
|
Group->InheritFrom( GetGroup( Split[i].c_str() ) );
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-28 15:36:01 -04:00
|
|
|
LOGD("-- Groups Successfully Loaded --");
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-18 17:54:56 -04:00
|
|
|
cGroup* cGroupManager::GetGroup( const AString & a_Name )
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
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;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|