diff options
Diffstat (limited to 'source/GroupManager.cpp')
-rw-r--r-- | source/GroupManager.cpp | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/source/GroupManager.cpp b/source/GroupManager.cpp index 98357ffa9..912f1196c 100644 --- a/source/GroupManager.cpp +++ b/source/GroupManager.cpp @@ -39,53 +39,59 @@ cGroupManager::cGroupManager() { LOG("-- Loading Groups --"); cIniFile IniFile("groups.ini"); - if( IniFile.ReadFile() ) + if (!IniFile.ReadFile()) { - 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() ); + LOGINFO("groups.ini inaccessible, using groups.example.ini for defaults!"); + IniFile.Path("groups.example.ini"); + IniFile.ReadFile(); + IniFile.Path("groups.ini"); + IniFile.WriteFile(); + } - LOG("Loading group: %s", KeyName.c_str() ); + 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() ); - Group->SetName( KeyName ); - char Color = IniFile.GetValue( KeyName, "Color", "-" )[0]; - if( Color != '-' ) - Group->SetColor( cChatColor::MakeColor(Color) ); - else - Group->SetColor( cChatColor::White ); + LOG("Loading group: %s", KeyName.c_str() ); - std::string Commands = IniFile.GetValue( KeyName, "Commands", "" ); - if( Commands.size() > 0 ) + 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++) { - AStringVector Split = StringSplit( Commands, "," ); - for( unsigned int i = 0; i < Split.size(); i++) - { - Group->AddCommand( Split[i] ); - //LOG("%s", Split[i].c_str() ); - } + Group->AddCommand( Split[i] ); + //LOG("%s", Split[i].c_str() ); } + } - std::string Permissions = IniFile.GetValue( KeyName, "Permissions", "" ); - if( Permissions.size() > 0 ) + std::string Permissions = IniFile.GetValue( KeyName, "Permissions", "" ); + if( Permissions.size() > 0 ) + { + AStringVector Split = StringSplit( Permissions, "," ); + for( unsigned int i = 0; i < Split.size(); i++) { - AStringVector Split = StringSplit( Permissions, "," ); - for( unsigned int i = 0; i < Split.size(); i++) - { - Group->AddPermission( Split[i] ); - LOGINFO("Permission: %s", Split[i].c_str() ); - } + Group->AddPermission( Split[i] ); + LOGINFO("Permission: %s", Split[i].c_str() ); } + } - std::string Groups = IniFile.GetValue( KeyName, "Inherits", "" ); - if( Groups.size() > 0 ) + std::string Groups = IniFile.GetValue( KeyName, "Inherits", "" ); + if( Groups.size() > 0 ) + { + AStringVector Split = StringSplit( Groups, "," ); + for( unsigned int i = 0; i < Split.size(); i++) { - AStringVector Split = StringSplit( Groups, "," ); - for( unsigned int i = 0; i < Split.size(); i++) - { - Group->InheritFrom( GetGroup( Split[i].c_str() ) ); - } + Group->InheritFrom( GetGroup( Split[i].c_str() ) ); } } } |