コード例 #1
0
ファイル: CAuthModule.cpp プロジェクト: Gilgalal/divercities
	void CAuthModule::Handle_User_Update_Packet( CUserUpdatePacket* pPacket, CConnection* pConnection ) {
		
		// Get user object
		CUser* pUser = Get_User_By_Name( pPacket->m_Username );
		
		if( !pUser ) {
			pUser = Create_New_User( pPacket->m_UserType );
				
			return;
		}
		
		pUser->Serialize_From(*pPacket->Get_ByteStream() );
		
		DLog(LOG_AUTH, "Updated User object for: %s\n", pUser->Get_Name().c_str());
		
	}
コード例 #2
0
ファイル: CAuthModule.cpp プロジェクト: Gilgalal/divercities
	void CAuthModule::Handle_User_Update_Request_Packet( CUserUpdateRequestPacket* pPacket, CConnection* pConnection ) {
		// Get the user object
		CUser* pUser = Get_User_By_Name( pPacket->m_Username );
		if( !pUser ) {
			// We don't have this user's info
			// TODO pass request upstream
			return;
		}

		// Create packet
		CUserUpdatePacket* pUpdatePacket = (CUserUpdatePacket*)m_pNetworkModule->Create_Packet( PACKET_USERUPDATE );
		if( !pUpdatePacket ) {
			Log(LOG_AUTH, "Could not create CUserUpdatePacket to service CUserUpdateRequestPacket\n");
			return;
		}
		
		pUpdatePacket->m_pUser = pUser;
		pUpdatePacket->m_Username = pUser->Get_Name();
		
		pConnection->Send_Packet( pUpdatePacket );
		
		m_pNetworkModule->Destroy_Packet( pUpdatePacket );
		
	}
コード例 #3
0
ファイル: CAuthModule.cpp プロジェクト: Gilgalal/divercities
	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;
	}