Example #1
0
bool CAccountManager::LogOut ( CClient* pClient, CClient* pEchoClient )
{
    // Is he logged in?
    if ( !pClient->IsRegistered () )
    {
        if ( pEchoClient )
            pEchoClient->SendEcho ( "logout: You were not logged in" );
        return false;
    }

    if ( pClient->GetClientType () != CClient::CLIENT_PLAYER )
    {
        if ( pEchoClient )
            pEchoClient->SendEcho ( "logout: Only players can log out" );
        return false;
    }
    CPlayer* pPlayer = static_cast < CPlayer* > ( pClient );

    CAccount* pCurrentAccount = pClient->GetAccount ();
    pCurrentAccount->SetClient ( NULL );

    CAccount* pAccount = g_pGame->GetAccountManager ()->AddGuestAccount( GUEST_ACCOUNT_NAME );
    pClient->SetAccount ( pAccount );

    // Call our script event
    CLuaArguments Arguments;
    Arguments.PushAccount ( pCurrentAccount );
    Arguments.PushAccount ( pAccount );
    if ( !pPlayer->CallEvent ( "onPlayerLogout", Arguments ) )
    {
        // DENIED!
        pClient->SetAccount ( pCurrentAccount );
        pCurrentAccount->SetClient ( pClient );
        delete pAccount;
        return false;
    }

    // Tell the console
    CLogger::AuthPrintf ( "LOGOUT: %s logged out as '%s'\n", pClient->GetNick (), pCurrentAccount->GetName ().c_str () );

    // Tell the player
    if ( pEchoClient )
        pEchoClient->SendEcho ( "logout: You logged out" );

    return true;
}
Example #2
0
bool CAccountManager::LogIn ( CClient* pClient, CClient* pEchoClient, const char* szAccountName, const char* szPassword )
{
    // Is he already logged in?
    if ( pClient->IsRegistered () )
    {
        if ( pEchoClient ) pEchoClient->SendEcho ( "login: You are already logged in" );
        return false;
    }

    if ( pClient->GetClientType () != CClient::CLIENT_PLAYER )
    {
        if ( pEchoClient ) pEchoClient->SendEcho ( "login: Only players can log in" );
        return false;
    }

    // Get the players details
    CPlayer* pPlayer = static_cast < CPlayer* > ( pClient );
    SString strPlayerName = pPlayer->GetNick ();
    SString strPlayerIP = pPlayer->GetSourceIP ();
    SString strPlayerSerial = pPlayer->GetSerial ();

    if ( m_AccountProtect.IsFlooding ( strPlayerIP.c_str () ) )
    {
        if ( pEchoClient ) pEchoClient->SendEcho ( SString( "login: Account locked", szAccountName ).c_str() );
        CLogger::AuthPrintf ( "LOGIN: Ignoring %s trying to log in as '%s' (IP: %s  Serial: %s)\n", strPlayerName.c_str (), szAccountName, strPlayerIP.c_str (), strPlayerSerial.c_str () );
        return false;
    }

    // Grab the account on his nick if any
    CAccount* pAccount = g_pGame->GetAccountManager ()->Get ( szAccountName );
    if ( !pAccount )
    {
        if ( pEchoClient ) pEchoClient->SendEcho( SString( "login: No known account for '%s'", szAccountName ).c_str() );
        CLogger::AuthPrintf ( "LOGIN: %s tried to log in as '%s' (Unknown account) (IP: %s  Serial: %s)\n", strPlayerName.c_str (), szAccountName, strPlayerIP.c_str (), strPlayerSerial.c_str () );
        return false;
    }

    if ( pAccount->GetClient () )
    {
        if ( pEchoClient ) pEchoClient->SendEcho ( SString( "login: Account for '%s' is already in use", szAccountName ).c_str() );
        return false;
    }
    if ( !IsValidPassword( szPassword ) || !pAccount->IsPassword ( szPassword ) )
    {
        if ( pEchoClient ) pEchoClient->SendEcho ( SString( "login: Invalid password for account '%s'", szAccountName ).c_str() );
        CLogger::AuthPrintf ( "LOGIN: %s tried to log in as '%s' with an invalid password (IP: %s  Serial: %s)\n", strPlayerName.c_str (), szAccountName, strPlayerIP.c_str (), strPlayerSerial.c_str () );
        m_AccountProtect.AddConnect ( strPlayerIP.c_str () );
        return false;
    }

    // Check serial authorization
    if ( IsAuthorizedSerialRequired( pAccount ) )
    {
        pAccount->AddSerialForAuthorization( strPlayerSerial, strPlayerIP );
        if ( !pAccount->IsSerialAuthorized( strPlayerSerial ) )
        {
            if ( pEchoClient )
                pEchoClient->SendEcho( SString( "login: Serial pending authorization for account '%s' - See https:""//mtasa.com/authserial", szAccountName ) );
            CLogger::AuthPrintf( "LOGIN: %s tried to log in as '%s' with an unauthorized serial (IP: %s  Serial: %s)\n", *strPlayerName, szAccountName, *strPlayerIP, *strPlayerSerial );
            CLogger::AuthPrintf( "LOGIN: See https:""//mtasa.com/authserial\n" );
            return false;
        }
    }

    // Log him in
    CAccount* pCurrentAccount = pClient->GetAccount ();
    pClient->SetAccount ( pAccount );
    pAccount->SetClient ( pClient );

    // Call the onPlayerLogin script event
    CLuaArguments Arguments;
    Arguments.PushAccount ( pCurrentAccount );
    Arguments.PushAccount ( pAccount );
    Arguments.PushBoolean ( false );    // was bAutoLogin
    if ( !pPlayer->CallEvent ( "onPlayerLogin", Arguments ) )
    {
        // DENIED!
        pClient->SetAccount ( pCurrentAccount );
        pAccount->SetClient ( NULL );
        return false;
    }

    // Success is here
    pAccount->OnLoginSuccess ( strPlayerSerial, strPlayerIP );

    SString strGroupList = SString::Join ( ", ", g_pGame->GetACLManager ()->GetObjectGroupNames ( pAccount->GetName (), CAccessControlListGroupObject::OBJECT_TYPE_USER ) );
    CLogger::AuthPrintf ( "LOGIN: (%s) %s successfully logged in as '%s' (IP: %s  Serial: %s)\n", strGroupList.c_str (), pClient->GetNick (), pAccount->GetName ().c_str (), strPlayerIP.c_str (), strPlayerSerial.c_str () );

    // Tell the player
    if ( pEchoClient )
    {
        pEchoClient->SendEcho ( "login: You successfully logged in" );
    }

    // Update who was info
    if ( pClient->GetClientType () == CClient::CLIENT_PLAYER )
        g_pGame->GetConsole ()->GetWhoWas ()->OnPlayerLogin ( static_cast < CPlayer* > ( pClient ) );

    // Delete the old account if it was a guest account
    if ( !pCurrentAccount->IsRegistered () )
        delete pCurrentAccount;

    return true;
}
bool CAccountManager::LogOut ( CClient* pClient, CClient* pEchoClient )
{
    // Is he logged in?
    if ( !pClient->IsRegistered () )
    {
        if ( pEchoClient )
            pEchoClient->SendEcho ( "logout: You were not logged in" );
        return false;
    }

    if ( pClient->GetClientType () == CClient::CLIENT_CONSOLE )
    {
        if ( pEchoClient )
            pEchoClient->SendEcho ( "logout: Console may not log out" );
        return false;
    }

    CAccount* pCurrentAccount = pClient->GetAccount ();
    pCurrentAccount->SetClient ( NULL );

    CAccount* pAccount = new CAccount ( g_pGame->GetAccountManager (), false, GUEST_ACCOUNT_NAME );
    pClient->SetAccount ( pAccount );

    // Call the onClientLogout event
    CElement* pClientElement = NULL;
    switch ( pClient->GetClientType () )
    {
    case CClient::CLIENT_PLAYER:
    {
        CPlayer* pPlayer = static_cast < CPlayer* > ( pClient );
        pClientElement = static_cast < CElement* > ( pPlayer );
        break;
    }
    case CClient::CLIENT_CONSOLE:
    {
        CConsoleClient* pConsoleClient = static_cast < CConsoleClient* > ( pClient );
        pClientElement = static_cast < CElement* > ( pConsoleClient );
        break;
    }
    }
    if ( pClientElement )
    {
        // Call our script event
        CLuaArguments Arguments;
        Arguments.PushAccount ( pCurrentAccount );
        Arguments.PushAccount ( pAccount );
        if ( !pClientElement->CallEvent ( "onPlayerLogout", Arguments ) )
        {
            // DENIED!
            pClient->SetAccount ( pCurrentAccount );
            pCurrentAccount->SetClient ( pClient );
            delete pAccount;
            return false;
        }
    }

    // Tell the console
    CLogger::AuthPrintf ( "LOGOUT: %s logged out as '%s'\n", pClient->GetNick (), pCurrentAccount->GetName ().c_str () );

    // Tell the player
    if ( pEchoClient )
        pEchoClient->SendEcho ( "logout: You logged out" );

    return true;
}