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"
|
2013-11-26 12:14:46 -05: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 )
|
|
|
|
{
|
2013-09-28 15:36:01 -04:00
|
|
|
LOGD("-- Loading Groups --");
|
2013-10-25 05:15:44 -04:00
|
|
|
cIniFile IniFile;
|
|
|
|
if (!IniFile.ReadFile("groups.ini"))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-12-13 21:02:26 -05:00
|
|
|
LOGWARNING("Regenerating groups.ini, all groups will be reset");
|
|
|
|
IniFile.AddHeaderComment(" This is the MCServer permissions manager groups file");
|
|
|
|
IniFile.AddHeaderComment(" It stores all defined groups such as Administrators, Players, or Moderators");
|
|
|
|
|
|
|
|
IniFile.SetValue("Owner", "Permissions", "*", true);
|
|
|
|
IniFile.SetValue("Owner", "Color", "2", true);
|
|
|
|
|
|
|
|
IniFile.SetValue("Moderator", "Permissions", "core.time,core.item,core.teleport,core.ban,core.unban,core.save-all,core.toggledownfall");
|
|
|
|
IniFile.SetValue("Moderator", "Color", "2", true);
|
|
|
|
IniFile.SetValue("Moderator", "Inherits", "Player", true);
|
|
|
|
|
|
|
|
IniFile.SetValue("Player", "Permissions", "core.build", 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", "Color", "f", true);
|
|
|
|
|
|
|
|
IniFile.WriteFile("groups.ini");
|
2012-11-16 17:06:12 -05:00
|
|
|
}
|
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
|
|
|
|
2013-09-28 15:36:01 -04:00
|
|
|
LOGD("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 );
|
2013-12-24 05:36:06 -05:00
|
|
|
char Color = IniFile.GetValue( KeyName, "Color", "-" )[0];
|
2012-11-16 17:06:12 -05:00
|
|
|
if( Color != '-' )
|
2013-12-24 05:29:18 -05:00
|
|
|
Group->SetColor( cChatColor::Color + Color );
|
2012-11-16 17:06:12 -05:00
|
|
|
else
|
|
|
|
Group->SetColor( cChatColor::White );
|
|
|
|
|
2013-12-24 05:29:18 -05:00
|
|
|
AString Commands = IniFile.GetValue( KeyName, "Commands", "" );
|
2012-11-16 17:06:12 -05:00
|
|
|
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] );
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2012-11-16 17:06:12 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-12-24 05:29:18 -05:00
|
|
|
AString Permissions = IniFile.GetValue( KeyName, "Permissions", "" );
|
2012-11-16 17:06:12 -05:00
|
|
|
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] );
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-28 15:36:01 -04:00
|
|
|
LOGD("-- Groups Successfully Loaded --");
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|