void CAuthModule::Handle_Login_Packet( CLoginPacket* pPacket, CConnection* pConnection ) { // Make sure username is in all lowercase std::string Name = pPacket->Get_Username(); std::transform(Name.begin(), Name.end(), Name.begin(), ::tolower); // This will try loading from disk if it isn't already in mem CUser* pUser = Get_User_By_Name( Name ); if( !pUser ) { // Not loaded in mem, can't loaded from disk // Check if we are allowing new users CStateModule* pStateModule = (CStateModule*)GETMODULE(MODULE_STATE); CState* pState = pStateModule->Get_Current_State(); // Only Master server can create new users if( (CDCEngine::GetInstance()->Get_Driver_Mode() == MODE_MASTER) && (pState->Allow_New_User()) ) { DLog(LOG_AUTH, "Creating new user: %s\n", Name.c_str()); CPlayer* pPlayer = NULL; // Create the new User obj pPlayer = (CPlayer*)Create_New_User( pPacket->Get_UserType() ); pPlayer->m_Name = Name; pPlayer->m_Password = pPacket->Get_Password(); // Establish link between connection and user pPlayer->m_pConnection = pConnection; pConnection->m_pUser = pPlayer; // Add to loaded users map m_UsersByName.insert( USER_MAP_NAME_PAIR(pPlayer->Get_Name(),pPlayer) ); m_UsersByID.insert( USER_MAP_ID_PAIR(pPlayer->Get_UserID(), pPlayer) ); // Send Ident Send_Ident( pConnection ); // Notify engine of new login CDCEngine::GetInstance()->On_New_Login( pPlayer ); return; } // Disconnect this connection Log(LOG_DRIVER, "Not allowing new users, disconnecting: %s:%d\n", pConnection->Get_Address().c_str(), pConnection->Get_Port()); m_pNetworkModule->Disconnect_Connection( pConnection->Get_ID(), DR_NO_NEW_USERS ); return; } // User is loaded DLog(LOG_AUTH, "User logged in new: %s\n", pUser->Get_Name().c_str()); // Link connection and user pUser->m_pConnection = pConnection; pConnection->m_pUser = pUser; // Send Ident Send_Ident( pConnection ); // Notify Engine CDCEngine::GetInstance()->On_New_Login( pUser ); return; }