Exemplo n.º 1
0
// Return the name of an account which already exists, and is using the same name with one or more letters in a different case
SString CAccountManager::GetActiveCaseVariation ( const SString& strName )
{
    // Check for exact match already existing
    if ( Get( strName ) )
        return "";

    std::vector < CAccount* > results;
    // Case insensitive search to find all variations
    m_List.FindAccountMatches ( &results, strName, false );
    for ( uint i = 0 ; i < results.size () ; i++ )
    {
        CAccount* pAccount = results[i];
        if ( pAccount->IsRegistered () && pAccount->GetName () != strName )
        {
            return pAccount->GetName ();
        }
    }
    return "";
}
Exemplo n.º 2
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;
}
int CLuaFunctionDefs::GetAccountName ( lua_State* luaVM )
{
    //  string getAccountName ( account theAccount )
    CAccount* pAccount;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pAccount );

    if ( !argStream.HasErrors () )
    {
        std::string strName = pAccount->GetName ();
        if ( !strName.empty () )
        {
            lua_pushstring ( luaVM, strName.c_str () );
            return 1;
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    lua_pushboolean ( luaVM, false );
    return 1;
}
Exemplo n.º 4
0
bool CChar::Player_OnVerb( CScript &s, CTextConsole * pSrc ) // Execute command from script
{
	ADDTOCALLSTACK("CChar::Player_OnVerb");
	if ( !m_pPlayer )
		return false;

	LPCTSTR pszKey = s.GetKey();
	int cpVerb = FindTableSorted( pszKey, CCharPlayer::sm_szVerbKeys, COUNTOF(CCharPlayer::sm_szVerbKeys)-1 );

	if ( cpVerb <= -1 )
	{
		if ( ( !strnicmp(pszKey, "GUILD", 5) ) || ( !strnicmp(pszKey, "TOWN", 4) ) )
		{
			bool bIsGuild = !strnicmp(pszKey, "GUILD", 5);
			pszKey += bIsGuild ? 5 : 4;
			if ( *pszKey == '.' )
			{
				pszKey += 1;
				CItemStone *pMyGuild = Guild_Find(bIsGuild ? MEMORY_GUILD : MEMORY_TOWN);
                if ( pMyGuild )
                {
                        CScript sToParse(pszKey, s.GetArgRaw());
                        return pMyGuild->r_Verb(sToParse, pSrc);
                }
			}
			return false;
		}
	}

	switch ( cpVerb )
	{
		case CPV_KICK: // "KICK" = kick and block the account
			return (IsClient() && GetClient()->addKick(pSrc));

		case CPV_PASSWORD:	// "PASSWORD"
		{
			// Set/Clear the password
			if ( pSrc != this )
			{
				if ( pSrc->GetPrivLevel() <= GetPrivLevel() || pSrc->GetPrivLevel() < PLEVEL_Admin )
				{
					pSrc->SysMessage(g_Cfg.GetDefaultMsg(DEFMSG_MSG_ACC_PRIV));
					return false;
				}
			}

			CAccount * pAccount = m_pPlayer->GetAccount();
			ASSERT(pAccount != NULL);

			if ( !s.HasArgs() )
			{
				pAccount->ClearPassword();
				SysMessage(g_Cfg.GetDefaultMsg(DEFMSG_MSG_ACC_PASSCLEAR));
				SysMessage(g_Cfg.GetDefaultMsg(DEFMSG_MSG_ACC_PASSCLEAR_RELOG));
				g_Log.Event(LOGM_ACCOUNTS|LOGL_EVENT, "Account '%s', password cleared\n", pAccount->GetName());
			}
			else
			{
				if ( pAccount->SetPassword(s.GetArgStr()) )
				{
					SysMessage(g_Cfg.GetDefaultMsg(DEFMSG_MSG_ACC_ACCEPTPASS));
					g_Log.Event(LOGM_ACCOUNTS|LOGL_EVENT, "Account '%s', password set to '%s'\n", pAccount->GetName(), s.GetArgStr());
					return true;
				}

				SysMessage(g_Cfg.GetDefaultMsg(DEFMSG_MSG_ACC_INVALIDPASS));
			}
			break;
		}

		default:
			return false;
	}

	return true;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
int CLuaACLDefs::hasObjectPermissionTo ( lua_State* luaVM )
{
//  bool hasObjectPermissionTo ( string / element theObject, string theAction [, bool defaultPermission = true ] )
    CResource* pResource = NULL; CElement* pElement = NULL; SString strObject; SString strRightName; bool bDefault; CAccessControlListGroupObject::EObjectType eObjectType;

    CScriptArgReader argStream ( luaVM );
    if ( argStream.NextIsUserDataOfType < CResource > () )
        argStream.ReadUserData ( pResource );
    else
    if ( argStream.NextIsUserDataOfType < CElement > () )
        argStream.ReadUserData ( pElement );
    else
        argStream.ReadString ( strObject );

    argStream.ReadString ( strRightName );
    argStream.ReadBool ( bDefault, true );

    if ( !argStream.HasErrors () )
    {
        if ( pResource )
        {
            // Grab the resource's name
            strObject = pResource->GetName ();
            eObjectType = CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE;
        }
        else if ( pElement )
        {
            // Grab the client this player/console/whatever is
            CClient* pClient = pElement->GetClient ();
            if ( pClient )
            {
                // Get his account
                CAccount* pAccount = pClient->GetAccount ();
                if ( pAccount )
                {
                    // Grab the username
                    strObject = pAccount->GetName ();
                    eObjectType = CAccessControlListGroupObject::OBJECT_TYPE_USER;
                }
            }
        }
        else
        {
            // Extract the object name itself including the type
            const char * szName = CAccessControlListManager::ExtractObjectName ( strObject.c_str (), eObjectType );
            strObject = szName ? szName : "";
        }

        // Got a string?
        if ( !strObject.empty () )
        {
            // Extract the right name itself including the type
            CAccessControlListRight::ERightType eRightType;
            strRightName = CAccessControlListManager::ExtractRightName ( strRightName, eRightType );

            // Did we get a right name without the prefix?
            if ( strRightName )
            {
                bool bHasPermission = m_pACLManager->CanObjectUseRight ( strObject, eObjectType, strRightName, eRightType, bDefault );

                // Return whether we had access or not
                lua_pushboolean ( luaVM, bHasPermission );
                return 1;
            }
        }
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Failed
    lua_pushnil ( luaVM );
    return 1;
}
Exemplo n.º 7
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_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;
}
Exemplo n.º 8
0
int CLuaACLDefs::hasObjectPermissionTo ( lua_State* luaVM )
{
    // What object name we're going to check
    CAccessControlListGroupObject::EObjectType eObjectType;
    std::string strObject;

    // Got a pointer argument?
    if ( lua_type ( luaVM, 1 ) == LUA_TLIGHTUSERDATA )
    {
        // Grab it
        CResource* pResource = lua_toresource ( luaVM, 1 );
        CElement* pElement = lua_toelement ( luaVM, 1 );

        // Is it a valid resource?
        if ( pResource )
        {
            // Grab the resource's name
            strObject = pResource->GetName ();
            eObjectType = CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE;
        }

        // Is this a valid element?
        else if ( pElement )
        {
            // Grab the client this player/console/whatever is
            CClient* pClient = pElement->GetClient ();
            if ( pClient )
            {
                // Get his account
                CAccount* pAccount = pClient->GetAccount ();
                if ( pAccount )
                {
                    // Grab the username
                    strObject = pAccount->GetName ();
                    eObjectType = CAccessControlListGroupObject::OBJECT_TYPE_USER;
                }
            }
        }
    }

    // Got a string argument?
    else if ( lua_type ( luaVM, 1 ) == LUA_TSTRING )
    {
        // Change the pointer to point to our argument
        strObject = lua_tostring ( luaVM, 1 );

        // Extract the object name itself including the type
        const char * szName = CAccessControlListManager::ExtractObjectName ( strObject.c_str (), eObjectType );
        strObject = szName ? szName : "";
    }

    // Got a string?
    if ( !strObject.empty () )
    {
        // Got a string with the action to check for permission?
        if ( lua_type ( luaVM, 2 ) == LUA_TSTRING )
        {
            // Grab the right name we should've gotten passed
            const char* szRightName = lua_tostring ( luaVM, 2 );

            // Extract the right name itself including the type
            CAccessControlListRight::ERightType eRightType;
            szRightName = CAccessControlListManager::ExtractRightName ( szRightName, eRightType );

            // Did we get a right name without the prefix?
            if ( szRightName )
            {
                // Third argument to specify what the return defaults to.
                // This is if no ACL could be found.
                bool bDefault = true;
                if ( lua_type ( luaVM, 3 ) == LUA_TBOOLEAN )
                {
                    bDefault = lua_toboolean ( luaVM, 3 ) ? true:false;
                }

                // Check whether he has permissions to do that
                bool bHasPermission = m_pACLManager->CanObjectUseRight ( strObject.c_str (),
                                                                         eObjectType,
                                                                         szRightName,
                                                                         eRightType,
                                                                         bDefault );

                // Return whether we had access or not
                lua_pushboolean ( luaVM, bHasPermission );
                return 1;
            }
            else
                m_pScriptDebugging->LogBadType ( luaVM, "hasObjectPermissionTo" );
        }
        else
            m_pScriptDebugging->LogBadType ( luaVM, "hasObjectPermissionTo" );
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "hasObjectPermissionTo" );

    // Failed
    lua_pushnil ( luaVM );
    return 1;
}