2012-06-14 06:06:06 -07:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 15:09:57 -07:00
|
|
|
#include "GroupManager.h"
|
|
|
|
#include "Group.h"
|
2012-06-14 06:06:06 -07:00
|
|
|
#include "../iniFile/iniFile.h"
|
2012-09-23 15:09:57 -07:00
|
|
|
#include "ChatColor.h"
|
|
|
|
#include "Root.h"
|
2012-06-14 06:06:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-18 14:54:56 -07:00
|
|
|
typedef std::map< AString, cGroup* > GroupMap;
|
2013-01-11 20:46:01 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 06:06:06 -07:00
|
|
|
struct cGroupManager::sGroupManagerState
|
|
|
|
{
|
|
|
|
GroupMap Groups;
|
|
|
|
};
|
|
|
|
|
2013-01-11 20:46:01 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 06:06:06 -07: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 20:46:01 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 06:06:06 -07:00
|
|
|
cGroupManager::cGroupManager()
|
|
|
|
: m_pState( new sGroupManagerState )
|
|
|
|
{
|
|
|
|
LOG("-- Loading Groups --");
|
|
|
|
cIniFile IniFile("groups.ini");
|
2012-11-16 14:06:12 -08:00
|
|
|
if (!IniFile.ReadFile())
|
2012-06-14 06:06:06 -07:00
|
|
|
{
|
2013-08-05 06:24:23 -07:00
|
|
|
LOGWARNING("groups.ini inaccessible, no groups are defined");
|
|
|
|
return;
|
2012-11-16 14:06:12 -08:00
|
|
|
}
|
2012-06-14 06:06:06 -07:00
|
|
|
|
2012-11-16 14:06:12 -08: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 06:06:06 -07:00
|
|
|
|
2012-11-16 14:06:12 -08:00
|
|
|
LOG("Loading group: %s", KeyName.c_str() );
|
2012-06-14 06:06:06 -07:00
|
|
|
|
2012-11-16 14:06:12 -08: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 06:06:06 -07:00
|
|
|
{
|
2012-11-16 14:06:12 -08:00
|
|
|
Group->AddCommand( Split[i] );
|
|
|
|
//LOG("%s", Split[i].c_str() );
|
2012-06-14 06:06:06 -07:00
|
|
|
}
|
2012-11-16 14:06:12 -08:00
|
|
|
}
|
2012-06-14 06:06:06 -07:00
|
|
|
|
2012-11-16 14:06:12 -08: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 06:06:06 -07:00
|
|
|
{
|
2012-11-16 14:06:12 -08:00
|
|
|
Group->AddPermission( Split[i] );
|
2013-08-03 09:49:38 -07:00
|
|
|
//LOGINFO("Permission: %s", Split[i].c_str() );
|
2012-06-14 06:06:06 -07:00
|
|
|
}
|
2012-11-16 14:06:12 -08:00
|
|
|
}
|
2012-06-14 06:06:06 -07:00
|
|
|
|
2012-11-16 14:06:12 -08: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 06:06:06 -07:00
|
|
|
{
|
2012-11-16 14:06:12 -08:00
|
|
|
Group->InheritFrom( GetGroup( Split[i].c_str() ) );
|
2012-06-14 06:06:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-03 09:49:38 -07:00
|
|
|
LOG("-- Groups Successfully Loaded --");
|
2012-06-14 06:06:06 -07:00
|
|
|
}
|
|
|
|
|
2013-01-11 20:46:01 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-18 14:54:56 -07:00
|
|
|
cGroup* cGroupManager::GetGroup( const AString & a_Name )
|
2012-06-14 06:06:06 -07: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 20:46:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-14 06:06:06 -07:00
|
|
|
|