1
0

Add 'Group not found', when the Server load the users.ini and add auto generate from users.ini

This commit is contained in:
Howaner 2014-02-21 14:53:46 +01:00
parent 337c4e5cd4
commit 21febaf4b3
5 changed files with 61 additions and 2 deletions

View File

@ -1529,7 +1529,11 @@ void cPlayer::LoadPermissionsFromDisk()
AStringVector Split = StringSplit( Groups, "," );
for( unsigned int i = 0; i < Split.size(); i++ )
{
AddToGroup( Split[i].c_str() );
if (!cRoot::Get()->GetGroupManager()->ExistsGroup(Split[i]))
{
LOGWARNING("The group %s for player %s was not found!", Split[i].c_str(), m_PlayerName.c_str());
}
AddToGroup(Split[i].c_str());
}
}
else

View File

@ -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 );

View File

@ -14,8 +14,10 @@ class cGroup;
class cGroupManager
{
public:
bool ExistsGroup(const AString & a_Name);
cGroup * GetGroup(const AString & a_Name);
void LoadGroups(void);
void CheckUsers(void);
private:
friend class cRoot;

View File

@ -194,7 +194,7 @@ void cRoot::Start(void)
#if !defined(ANDROID_NDK)
LOGD("Starting InputThread...");
m_InputThread = new cThread( InputThread, this, "cRoot::InputThread" );
m_InputThread->Start( false ); // We should NOT wait? Otherwise we can´t stop the server from other threads than the input thread
m_InputThread->Start( false ); // We should NOT wait? Otherwise we can<EFBFBD>t stop the server from other threads than the input thread
#endif
long long finishmseconds = Time.GetNowTime();
@ -536,7 +536,9 @@ void cRoot::SaveAllChunks(void)
void cRoot::ReloadGroups(void)
{
LOG("Reload groups ...");
m_GroupManager->LoadGroups();
m_GroupManager->CheckUsers();
}

View File

@ -460,16 +460,20 @@ void cServer::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallbac
{
cPluginManager::Get()->ReloadPlugins();
cRoot::Get()->ReloadGroups();
a_Output.Finished();
return;
}
if (split[0] == "reloadplugins")
{
cPluginManager::Get()->ReloadPlugins();
a_Output.Finished();
return;
}
if (split[0] == "reloadgroups")
{
cRoot::Get()->ReloadGroups();
a_Output.Out("Groups reloaded!");
a_Output.Finished();
return;
}