From c1c7936c6874adcba45d6e31eeafba9a92aaaedd Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 2 Feb 2014 22:55:41 +0000 Subject: Fixed multiple invalid permission nodes New players can build as default now --- src/GroupManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/GroupManager.cpp') diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 792acc2c3..497f98c93 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -58,11 +58,11 @@ cGroupManager::cGroupManager() IniFile.SetValue("Moderator", "Color", "2", true); IniFile.SetValue("Moderator", "Inherits", "Player", true); - IniFile.SetValue("Player", "Permissions", "core.build", true); + IniFile.SetValue("Player", "Permissions", "core.portal", true); IniFile.SetValue("Player", "Color", "f", true); IniFile.SetValue("Player", "Inherits", "Default", true); - IniFile.SetValue("Default", "Permissions", "core.help,core.playerlist,core.pluginlist,core.spawn,core.listworlds,core.back,core.motd,core.gotoworld,core.coords,core.viewdistance", true); + IniFile.SetValue("Default", "Permissions", "core.help,core.plugins,core.spawn,core.worlds,core.back,core.motd,core.build,core.locate,core.viewdistance", true); IniFile.SetValue("Default", "Color", "f", true); IniFile.WriteFile("groups.ini"); -- cgit v1.2.3 From c2c1639af8f9db9bdd0f720c0e748c98d2835b5c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 2 Feb 2014 22:43:39 +0100 Subject: Groups.ini can contain spaces around commas in values. This includes Permissions, Inherits and Commands. Also fixed an unlikely but possible crash with group colors. --- src/GroupManager.cpp | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'src/GroupManager.cpp') diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 497f98c93..d5567d91e 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -69,47 +69,51 @@ cGroupManager::cGroupManager() } unsigned int NumKeys = IniFile.GetNumKeys(); - for( unsigned int i = 0; i < NumKeys; i++ ) + for (size_t i = 0; i < NumKeys; i++) { std::string KeyName = IniFile.GetKeyName( i ); cGroup* Group = GetGroup( KeyName.c_str() ); LOGD("Loading group: %s", KeyName.c_str() ); - Group->SetName( KeyName ); - char Color = IniFile.GetValue( KeyName, "Color", "-" )[0]; - if( Color != '-' ) - Group->SetColor( cChatColor::Color + Color ); + Group->SetName(KeyName); + AString Color = IniFile.GetValue(KeyName, "Color", "-"); + if ((Color != "-") && (Color.length() >= 1)) + { + Group->SetColor(cChatColor::Color + Color[0]); + } else - Group->SetColor( cChatColor::White ); + { + Group->SetColor(cChatColor::White); + } - AString Commands = IniFile.GetValue( KeyName, "Commands", "" ); - if( Commands.size() > 0 ) + AString Commands = IniFile.GetValue(KeyName, "Commands", ""); + if (!Commands.empty()) { - AStringVector Split = StringSplit( Commands, "," ); - for( unsigned int i = 0; i < Split.size(); i++) + AStringVector Split = StringSplitAndTrim(Commands, ","); + for (size_t i = 0; i < Split.size(); i++) { - Group->AddCommand( Split[i] ); + Group->AddCommand(Split[i]); } } - AString Permissions = IniFile.GetValue( KeyName, "Permissions", "" ); - if( Permissions.size() > 0 ) + AString Permissions = IniFile.GetValue(KeyName, "Permissions", ""); + if (!Permissions.empty()) { - AStringVector Split = StringSplit( Permissions, "," ); - for( unsigned int i = 0; i < Split.size(); i++) + AStringVector Split = StringSplitAndTrim(Permissions, ","); + for (size_t i = 0; i < Split.size(); i++) { - Group->AddPermission( Split[i] ); + Group->AddPermission(Split[i]); } } - std::string Groups = IniFile.GetValue( KeyName, "Inherits", "" ); - if( Groups.size() > 0 ) + std::string Groups = IniFile.GetValue(KeyName, "Inherits", ""); + if (!Groups.empty()) { - AStringVector Split = StringSplit( Groups, "," ); - for( unsigned int i = 0; i < Split.size(); i++) + AStringVector Split = StringSplitAndTrim(Groups, ","); + for (size_t i = 0; i < Split.size(); i++) { - Group->InheritFrom( GetGroup( Split[i].c_str() ) ); + Group->InheritFrom(GetGroup(Split[i].c_str())); } } } -- cgit v1.2.3 From 7c750914f0ddd0fec414e8690b10145ed61e7fa9 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 5 Feb 2014 18:10:08 +0100 Subject: Improvements: Adds a function in cRoot that allows you to reload all the groups permissions. Note: Players don't automatically load their new permissions. You can use cPlayer::LoadPermissionsFromDisk for that. --- src/GroupManager.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/GroupManager.cpp') diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index d5567d91e..99befa0ff 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -44,6 +44,18 @@ cGroupManager::cGroupManager() : m_pState( new sGroupManagerState ) { LOGD("-- Loading Groups --"); + + LoadGroups(); + + LOGD("-- Groups Successfully Loaded --"); +} + + + + + +void cGroupManager::LoadGroups() +{ cIniFile IniFile; if (!IniFile.ReadFile("groups.ini")) { @@ -71,8 +83,10 @@ cGroupManager::cGroupManager() unsigned int NumKeys = IniFile.GetNumKeys(); for (size_t i = 0; i < NumKeys; i++) { - std::string KeyName = IniFile.GetKeyName( i ); + AString KeyName = IniFile.GetKeyName( i ); cGroup* Group = GetGroup( KeyName.c_str() ); + + Group->ClearPermission(); // Needed in case the groups are reloaded. LOGD("Loading group: %s", KeyName.c_str() ); @@ -107,7 +121,7 @@ cGroupManager::cGroupManager() } } - std::string Groups = IniFile.GetValue(KeyName, "Inherits", ""); + AString Groups = IniFile.GetValue(KeyName, "Inherits", ""); if (!Groups.empty()) { AStringVector Split = StringSplitAndTrim(Groups, ","); @@ -117,13 +131,8 @@ cGroupManager::cGroupManager() } } } - LOGD("-- Groups Successfully Loaded --"); } - - - - cGroup* cGroupManager::GetGroup( const AString & a_Name ) { GroupMap::iterator itr = m_pState->Groups.find( a_Name ); -- cgit v1.2.3 From d6142b53f30dd212bea8f7daef3915e189791df5 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Wed, 5 Feb 2014 18:14:51 +0100 Subject: Forgot extra lines. --- src/GroupManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/GroupManager.cpp') diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 99befa0ff..723b86f94 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -133,6 +133,10 @@ void cGroupManager::LoadGroups() } } + + + + cGroup* cGroupManager::GetGroup( const AString & a_Name ) { GroupMap::iterator itr = m_pState->Groups.find( a_Name ); -- cgit v1.2.3 From 21febaf4b342aecd5d797b1e2017591fde208388 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 21 Feb 2014 14:53:46 +0100 Subject: Add 'Group not found', when the Server load the users.ini and add auto generate from users.ini --- src/GroupManager.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/GroupManager.cpp') diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 723b86f94..5125e7586 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -46,6 +46,7 @@ cGroupManager::cGroupManager() LOGD("-- Loading Groups --"); LoadGroups(); + CheckUsers(); LOGD("-- Groups Successfully Loaded --"); } @@ -54,6 +55,42 @@ cGroupManager::cGroupManager() +void cGroupManager::CheckUsers(void) +{ + cIniFile IniFile; + if (!IniFile.ReadFile("users.ini")) + { + LOGWARN("Regenerating users.ini, all users will be reset"); + IniFile.AddHeaderComment(" This is the file in which the group the player belongs to is stored"); + IniFile.AddHeaderComment(" The format is: [PlayerName] | Groups=GroupName"); + + IniFile.WriteFile("users.ini"); + return; + } + + unsigned int NumKeys = IniFile.GetNumKeys(); + for (size_t i = 0; i < NumKeys; i++) + { + AString Player = IniFile.GetKeyName( i ); + AString Groups = IniFile.GetValue(Player, "Groups", ""); + if (!Groups.empty()) + { + AStringVector Split = StringSplit( Groups, "," ); + for( unsigned int i = 0; i < Split.size(); i++ ) + { + if (!ExistsGroup(Split[i])) + { + LOGWARNING("The group %s for player %s was not found!", Split[i].c_str(), Player.c_str()); + } + } + } + } +} + + + + + void cGroupManager::LoadGroups() { cIniFile IniFile; @@ -137,6 +174,16 @@ void cGroupManager::LoadGroups() +bool cGroupManager::ExistsGroup( const AString & a_Name ) +{ + GroupMap::iterator itr = m_pState->Groups.find( a_Name ); + return ( itr != m_pState->Groups.end() ); +} + + + + + cGroup* cGroupManager::GetGroup( const AString & a_Name ) { GroupMap::iterator itr = m_pState->Groups.find( a_Name ); -- cgit v1.2.3 From 35def963f06dd46823300aebf09af0009189328b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 28 Feb 2014 15:31:20 +0100 Subject: Moved common cGroupManager code to a separate function. This fixes my concerns in PR #709. --- src/GroupManager.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/GroupManager.cpp') diff --git a/src/GroupManager.cpp b/src/GroupManager.cpp index 5125e7586..33b601e82 100644 --- a/src/GroupManager.cpp +++ b/src/GroupManager.cpp @@ -55,16 +55,27 @@ cGroupManager::cGroupManager() +void cGroupManager::GenerateDefaultUsersIni(cIniFile & a_IniFile) +{ + LOGWARN("Regenerating users.ini, all users will be reset"); + a_IniFile.AddHeaderComment(" This file stores the players' groups."); + a_IniFile.AddHeaderComment(" The format is:"); + a_IniFile.AddHeaderComment(" [PlayerName]"); + a_IniFile.AddHeaderComment(" Groups = GroupName1, GroupName2, ..."); + + a_IniFile.WriteFile("users.ini"); +} + + + + + void cGroupManager::CheckUsers(void) { cIniFile IniFile; if (!IniFile.ReadFile("users.ini")) { - LOGWARN("Regenerating users.ini, all users will be reset"); - IniFile.AddHeaderComment(" This is the file in which the group the player belongs to is stored"); - IniFile.AddHeaderComment(" The format is: [PlayerName] | Groups=GroupName"); - - IniFile.WriteFile("users.ini"); + GenerateDefaultUsersIni(IniFile); return; } -- cgit v1.2.3