Search in sources :

Example 91 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsynchronousUnregister method unregister.

/**
     * Processes a player's request to unregister himself. Unregisters the player after
     * successful password check.
     *
     * @param player the player
     * @param password the input password to check before unregister
     */
public void unregister(Player player, String password) {
    final String name = player.getName();
    final PlayerAuth cachedAuth = playerCache.getAuth(name);
    if (passwordSecurity.comparePassword(password, cachedAuth.getPassword(), name)) {
        if (dataSource.removeAuth(name)) {
            performUnregister(name, player);
            ConsoleLogger.info(name + " unregistered himself");
            bukkitService.createAndCallEvent(isAsync -> new UnregisterByPlayerEvent(player, isAsync));
        } else {
            service.send(player, MessageKey.ERROR);
        }
    } else {
        service.send(player, MessageKey.WRONG_PASSWORD);
    }
}
Also used : UnregisterByPlayerEvent(fr.xephi.authme.events.UnregisterByPlayerEvent) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 92 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AbstractDataSourceConverter method execute.

// Implementation note: Because of ForceFlatToSqlite it is possible that the CommandSender is null,
// which is never the case when a converter is launched from the /authme converter command.
@Override
public void execute(CommandSender sender) {
    if (destinationType != destination.getType()) {
        if (sender != null) {
            sender.sendMessage("Please configure your connection to " + destinationType + " and re-run this command");
        }
        return;
    }
    S source;
    try {
        source = getSource();
    } catch (Exception e) {
        logAndSendMessage(sender, "The data source to convert from could not be initialized");
        ConsoleLogger.logException("Could not initialize source:", e);
        return;
    }
    List<String> skippedPlayers = new ArrayList<>();
    for (PlayerAuth auth : source.getAllAuths()) {
        if (destination.isAuthAvailable(auth.getNickname())) {
            skippedPlayers.add(auth.getNickname());
        } else {
            adaptPlayerAuth(auth);
            destination.saveAuth(auth);
            destination.updateQuitLoc(auth);
        }
    }
    if (!skippedPlayers.isEmpty()) {
        logAndSendMessage(sender, "Skipped conversion for players which were already in " + destinationType + ": " + String.join(", ", skippedPlayers));
    }
    logAndSendMessage(sender, "Database successfully converted from " + source.getType() + " to " + destinationType);
}
Also used : ArrayList(java.util.ArrayList) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 93 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class LoginSecurityConverter method migrateData.

/**
     * Migrates the accounts.
     *
     * @param sender the command sender
     * @param resultSet result set with the account data to migrate
     */
private void migrateData(CommandSender sender, ResultSet resultSet) throws SQLException {
    List<String> skippedPlayers = new ArrayList<>();
    long successfulSaves = 0;
    while (resultSet.next()) {
        String name = resultSet.getString("last_name");
        if (dataSource.isAuthAvailable(name)) {
            skippedPlayers.add(name);
        } else {
            PlayerAuth auth = buildAuthFromLoginSecurity(name, resultSet);
            dataSource.saveAuth(auth);
            ++successfulSaves;
        }
    }
    logAndSendMessage(sender, "Migrated " + successfulSaves + " accounts successfully from LoginSecurity");
    if (!skippedPlayers.isEmpty()) {
        logAndSendMessage(sender, "Skipped conversion for players which were already in AuthMe: " + String.join(", ", skippedPlayers));
    }
}
Also used : ArrayList(java.util.ArrayList) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 94 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class PlayerListener method onPlayerRespawn.

// TODO: check this, why do we need to update the quit loc? -sgdc3
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
    if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
        return;
    }
    if (!listenerService.shouldCancelEvent(event)) {
        return;
    }
    Player player = event.getPlayer();
    String name = player.getName().toLowerCase();
    Location spawn = spawnLoader.getSpawnLocation(player);
    if (settings.getProperty(RestrictionSettings.SAVE_QUIT_LOCATION) && dataSource.isAuthAvailable(name)) {
        PlayerAuth auth = PlayerAuth.builder().name(name).realName(player.getName()).location(spawn).build();
        dataSource.updateQuitLoc(auth);
    }
    if (spawn != null && spawn.getWorld() != null) {
        event.setRespawnLocation(spawn);
    }
}
Also used : Player(org.bukkit.entity.Player) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 95 with PlayerAuth

use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.

the class AsynchronousUnregisterTest method shouldHandleDatabaseError.

@Test
public void shouldHandleDatabaseError() {
    // given
    Player player = mock(Player.class);
    String name = "Frank21";
    given(player.getName()).willReturn(name);
    PlayerAuth auth = mock(PlayerAuth.class);
    given(playerCache.getAuth(name)).willReturn(auth);
    HashedPassword password = new HashedPassword("password", "in_auth_obj");
    given(auth.getPassword()).willReturn(password);
    String userPassword = "pass";
    given(passwordSecurity.comparePassword(userPassword, password, name)).willReturn(true);
    given(dataSource.removeAuth(name)).willReturn(false);
    // when
    asynchronousUnregister.unregister(player, userPassword);
    // then
    verify(passwordSecurity).comparePassword(userPassword, password, name);
    verify(dataSource).removeAuth(name);
    verify(service).send(player, MessageKey.ERROR);
    verifyZeroInteractions(teleportationService, bukkitService);
}
Also used : Player(org.bukkit.entity.Player) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Test(org.junit.Test)

Aggregations

PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)102 Test (org.junit.Test)65 Player (org.bukkit.entity.Player)33 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)21 CommandSender (org.bukkit.command.CommandSender)16 Location (org.bukkit.Location)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)9 IOException (java.io.IOException)7 World (org.bukkit.World)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 ArrayList (java.util.ArrayList)5 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)4 Connection (java.sql.Connection)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 AuthMeMatchers.hasAuthLocation (fr.xephi.authme.AuthMeMatchers.hasAuthLocation)3 File (java.io.File)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3