From 2a197705ac8785e01a48fa1ac5893d3bb876fd0a Mon Sep 17 00:00:00 2001 From: faketruth Date: Thu, 18 Oct 2012 21:54:56 +0000 Subject: Converted some const char*s and std::strings to AStrings Added a cPlayer:RemoveFromGroup() so players can be removed from groups programmatically Added a cClientHandle:SetUsername to be used by Lua. I'm curious what ThuGie can do with his plugin. git-svn-id: http://mc-server.googlecode.com/svn/trunk@978 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Player.cpp | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'source/Player.cpp') diff --git a/source/Player.cpp b/source/Player.cpp index 4ac71b25a..c7784c1b0 100644 --- a/source/Player.cpp +++ b/source/Player.cpp @@ -578,11 +578,11 @@ void cPlayer::SetVisible(bool a_bVisible) -void cPlayer::AddToGroup( const char* a_GroupName ) +void cPlayer::AddToGroup( const AString & a_GroupName ) { cGroup* Group = cRoot::Get()->GetGroupManager()->GetGroup( a_GroupName ); m_Groups.push_back( Group ); - LOGD("Added %s to group %s", m_PlayerName.c_str(), a_GroupName ); + LOGD("Added %s to group %s", m_PlayerName.c_str(), a_GroupName.c_str() ); ResolveGroups(); ResolvePermissions(); } @@ -591,7 +591,36 @@ void cPlayer::AddToGroup( const char* a_GroupName ) -bool cPlayer::CanUseCommand( const char* a_Command ) +void cPlayer::RemoveFromGroup( const AString & a_GroupName ) +{ + bool bRemoved = false; + for( GroupList::iterator itr = m_Groups.begin(); itr != m_Groups.end(); ++itr ) + { + if( (*itr)->GetName().compare(a_GroupName ) == 0 ) + { + m_Groups.erase( itr ); + bRemoved = true; + break; + } + } + + if( bRemoved ) + { + LOGD("Removed %s from group %s", m_PlayerName.c_str(), a_GroupName.c_str() ); + ResolveGroups(); + ResolvePermissions(); + } + else + { + LOGWARN("Tried to remove %s from group %s but was not in that group", m_PlayerName.c_str(), a_GroupName.c_str() ); + } +} + + + + + +bool cPlayer::CanUseCommand( const AString & a_Command ) { for( GroupList::iterator itr = m_Groups.begin(); itr != m_Groups.end(); ++itr ) { @@ -604,7 +633,7 @@ bool cPlayer::CanUseCommand( const char* a_Command ) -bool cPlayer::HasPermission( const char* a_Permission ) +bool cPlayer::HasPermission( const AString & a_Permission ) { AStringVector Split = StringSplit( a_Permission, "." ); PermissionMap Possibilities = m_ResolvedPermissions; @@ -640,11 +669,11 @@ bool cPlayer::HasPermission( const char* a_Permission ) -bool cPlayer::IsInGroup( const char* a_Group ) +bool cPlayer::IsInGroup( const AString & a_Group ) { for( GroupList::iterator itr = m_ResolvedGroups.begin(); itr != m_ResolvedGroups.end(); ++itr ) { - if( strcmp( a_Group, (*itr)->GetName().c_str() ) == 0 ) + if( a_Group.compare( (*itr)->GetName().c_str() ) == 0 ) return true; } return false; -- cgit v1.2.3