From 92c59963f82f81aa3202657e7fdbb2592924ede3 Mon Sep 17 00:00:00 2001 From: "cedeel@gmail.com" Date: Thu, 14 Jun 2012 13:06:06 +0000 Subject: Attempt to bring sanity to newlines across systems. git-svn-id: http://mc-server.googlecode.com/svn/trunk@606 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cGroupManager.cpp | 214 +++++++++++++++++++++++------------------------ 1 file changed, 107 insertions(+), 107 deletions(-) (limited to 'source/cGroupManager.cpp') diff --git a/source/cGroupManager.cpp b/source/cGroupManager.cpp index 30d70171c..2458308c9 100644 --- a/source/cGroupManager.cpp +++ b/source/cGroupManager.cpp @@ -1,108 +1,108 @@ - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "cGroupManager.h" -#include "cGroup.h" -#include "../iniFile/iniFile.h" -#include "cChatColor.h" -#include "cRoot.h" - - - - - -typedef std::map< std::string, cGroup* > GroupMap; -struct cGroupManager::sGroupManagerState -{ - GroupMap Groups; -}; - -cGroupManager* cGroupManager::GetGroupManager() -{ - LOGWARN("WARNING: Using deprecated function cGroupManager::GetGroupManager() use cRoot::Get()->GetGroupManager() instead!"); - return cRoot::Get()->GetGroupManager(); -} - -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; -} - -cGroupManager::cGroupManager() - : m_pState( new sGroupManagerState ) -{ - LOG("-- Loading Groups --"); - cIniFile IniFile("groups.ini"); - 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() ); - - LOG("Loading group: %s", 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 ); - - std::string Commands = IniFile.GetValue( KeyName, "Commands", "" ); - if( Commands.size() > 0 ) - { - AStringVector Split = StringSplit( Commands, "," ); - for( unsigned int i = 0; i < Split.size(); i++) - { - Group->AddCommand( Split[i] ); - //LOG("%s", Split[i].c_str() ); - } - } - - std::string Permissions = IniFile.GetValue( KeyName, "Permissions", "" ); - if( Permissions.size() > 0 ) - { - AStringVector Split = StringSplit( Permissions, "," ); - for( unsigned int i = 0; i < Split.size(); i++) - { - Group->AddPermission( Split[i] ); - LOGINFO("Permission: %s", Split[i].c_str() ); - } - } - - std::string Groups = IniFile.GetValue( KeyName, "Inherits", "" ); - if( Groups.size() > 0 ) - { - AStringVector Split = StringSplit( Groups, "," ); - for( unsigned int i = 0; i < Split.size(); i++) - { - Group->InheritFrom( GetGroup( Split[i].c_str() ) ); - } - } - } - } - LOG("-- Done Loading Groups --"); -} - -cGroup* cGroupManager::GetGroup( const char* a_Name ) -{ - 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; - + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "cGroupManager.h" +#include "cGroup.h" +#include "../iniFile/iniFile.h" +#include "cChatColor.h" +#include "cRoot.h" + + + + + +typedef std::map< std::string, cGroup* > GroupMap; +struct cGroupManager::sGroupManagerState +{ + GroupMap Groups; +}; + +cGroupManager* cGroupManager::GetGroupManager() +{ + LOGWARN("WARNING: Using deprecated function cGroupManager::GetGroupManager() use cRoot::Get()->GetGroupManager() instead!"); + return cRoot::Get()->GetGroupManager(); +} + +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; +} + +cGroupManager::cGroupManager() + : m_pState( new sGroupManagerState ) +{ + LOG("-- Loading Groups --"); + cIniFile IniFile("groups.ini"); + 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() ); + + LOG("Loading group: %s", 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 ); + + std::string Commands = IniFile.GetValue( KeyName, "Commands", "" ); + if( Commands.size() > 0 ) + { + AStringVector Split = StringSplit( Commands, "," ); + for( unsigned int i = 0; i < Split.size(); i++) + { + Group->AddCommand( Split[i] ); + //LOG("%s", Split[i].c_str() ); + } + } + + std::string Permissions = IniFile.GetValue( KeyName, "Permissions", "" ); + if( Permissions.size() > 0 ) + { + AStringVector Split = StringSplit( Permissions, "," ); + for( unsigned int i = 0; i < Split.size(); i++) + { + Group->AddPermission( Split[i] ); + LOGINFO("Permission: %s", Split[i].c_str() ); + } + } + + std::string Groups = IniFile.GetValue( KeyName, "Inherits", "" ); + if( Groups.size() > 0 ) + { + AStringVector Split = StringSplit( Groups, "," ); + for( unsigned int i = 0; i < Split.size(); i++) + { + Group->InheritFrom( GetGroup( Split[i].c_str() ) ); + } + } + } + } + LOG("-- Done Loading Groups --"); +} + +cGroup* cGroupManager::GetGroup( const char* a_Name ) +{ + 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; + } \ No newline at end of file -- cgit v1.2.3