104 lines
2.0 KiB
C++
104 lines
2.0 KiB
C++
#include "StdAfx.h"
|
|
#include ".\UserInfoManager.h"
|
|
#include <PublicDefine.h>
|
|
#include "UserInfoParser.h"
|
|
|
|
UserInfoManager::UserInfoManager(void)
|
|
{
|
|
m_KeyGenerator.Init();
|
|
}
|
|
|
|
UserInfoManager::~UserInfoManager(void)
|
|
{
|
|
Release();
|
|
}
|
|
|
|
VOID UserInfoManager::Release()
|
|
{
|
|
USER_ITER iter;
|
|
|
|
for( iter = m_mapUser.begin(); iter != m_mapUser.end(); ++iter )
|
|
{
|
|
UserInfo* pUser = (*iter).second;
|
|
if( pUser )
|
|
delete pUser;
|
|
}
|
|
|
|
m_mapUser.clear();
|
|
}
|
|
|
|
|
|
BOOL UserInfoManager::AddUser( UserInfo* pUser )
|
|
{
|
|
if( !pUser )
|
|
return FALSE;
|
|
|
|
m_mapUser.insert( std::make_pair(pUser->GetUserGUID(), pUser) );
|
|
|
|
//Used Key Alloc
|
|
if( !m_KeyGenerator.RestoreKey( pUser->GetUserGUID() ) )
|
|
{
|
|
DISPMSG( "Used Key Fail = %d\n", pUser->GetUserGUID() );
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
UserInfo* UserInfoManager::FindUser( DWORD dwUserGUID )
|
|
{
|
|
USER_ITER iter;
|
|
iter = m_mapUser.find( dwUserGUID );
|
|
if( iter != m_mapUser.end() )
|
|
return (*iter).second;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
UserInfo* UserInfoManager::FindUser( const char* pszID, const char* pszPass )
|
|
{
|
|
USER_ITER iter;
|
|
|
|
for( iter = m_mapUser.begin(); iter != m_mapUser.end(); ++iter )
|
|
{
|
|
UserInfo* pUser = (*iter).second;
|
|
if( pUser )
|
|
{
|
|
if( strcmp( pUser->GetUserID(), pszID ) != 0 )
|
|
continue;
|
|
|
|
if( strcmp( pUser->GetUserPassWord(), pszPass ) != 0 )
|
|
continue;
|
|
|
|
return pUser;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
//신규유저 추가
|
|
BOOL UserInfoManager::NewUser( const char* pszID, const char* pszPass, BYTE byRight )
|
|
{
|
|
if( !pszID || !pszPass || byRight < USER_RIGHT_NORMAL || byRight > USER_RIGHT_MANAGER )
|
|
return FALSE;
|
|
|
|
//새로운 유저 생성
|
|
UserInfo* pNewUser = new UserInfo;
|
|
pNewUser->SetUserID( pszID );
|
|
pNewUser->SetUserPassWord( pszPass );
|
|
pNewUser->SetUserRight( byRight );
|
|
|
|
// New Key Alloc
|
|
|
|
DWORD dwUserKey = 0;
|
|
if( !m_KeyGenerator.AllocKey( dwUserKey ) )
|
|
return FALSE;
|
|
|
|
pNewUser->SetUserGUID( dwUserKey );
|
|
m_mapUser.insert( std::make_pair( dwUserKey, pNewUser ) );
|
|
|
|
//XML DB에 유저 추가.
|
|
UserInfoParser::Instance()->InsertUser( pNewUser );
|
|
|
|
return TRUE;
|
|
} |