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 )
|
|
|
|
{
|
|
|
|
LOG("-- Loading Groups --");
|
|
|
|
cIniFile IniFile("groups.ini");
|
2012-11-16 17:06:12 -05:00
|
|
|
if (!IniFile.ReadFile())
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-11-16 17:06:12 -05:00
|
|
|
LOGINFO("groups.ini inaccessible, using groups.example.ini for defaults!");
|
|
|
|
IniFile.Path("groups.example.ini");
|
|
|
|
IniFile.ReadFile();
|
|
|
|
IniFile.Path("groups.ini");
|
|
|
|
IniFile.WriteFile();
|
|
|
|
}
|
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
|
|
|
|
2012-11-16 17:06:12 -05:00
|
|
|
LOG("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] );
|
|
|
|
//LOG("%s", Split[i].c_str() );
|
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] );
|
|
|
|
LOGINFO("Permission: %s", Split[i].c_str() );
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LOG("-- Done Loading Groups --");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|