Search in sources :

Example 6 with PlayerAuth

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

the class FlatFile method updateQuitLoc.

@Override
public boolean updateQuitLoc(PlayerAuth auth) {
    if (!isAuthAvailable(auth.getNickname())) {
        return false;
    }
    PlayerAuth newAuth = null;
    try (BufferedReader br = new BufferedReader(new FileReader(source))) {
        String line;
        while ((line = br.readLine()) != null) {
            String[] args = line.split(":");
            if (args[0].equalsIgnoreCase(auth.getNickname())) {
                newAuth = buildAuthFromArray(args);
                if (newAuth != null) {
                    newAuth.setQuitLocX(auth.getQuitLocX());
                    newAuth.setQuitLocY(auth.getQuitLocY());
                    newAuth.setQuitLocZ(auth.getQuitLocZ());
                    newAuth.setWorld(auth.getWorld());
                    newAuth.setEmail(auth.getEmail());
                }
                break;
            }
        }
    } catch (IOException ex) {
        ConsoleLogger.warning(ex.getMessage());
        return false;
    }
    if (newAuth != null) {
        removeAuth(auth.getNickname());
        saveAuth(newAuth);
    }
    return true;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 7 with PlayerAuth

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

the class FlatFile method updateSession.

@Override
public boolean updateSession(PlayerAuth auth) {
    if (!isAuthAvailable(auth.getNickname())) {
        return false;
    }
    PlayerAuth newAuth = null;
    try (BufferedReader br = new BufferedReader(new FileReader(source))) {
        String line;
        while ((line = br.readLine()) != null) {
            String[] args = line.split(":");
            if (args[0].equalsIgnoreCase(auth.getNickname())) {
                newAuth = buildAuthFromArray(args);
                if (newAuth != null) {
                    newAuth.setLastLogin(auth.getLastLogin());
                    newAuth.setIp(auth.getIp());
                }
                break;
            }
        }
    } catch (IOException ex) {
        ConsoleLogger.warning(ex.getMessage());
        return false;
    }
    if (newAuth != null) {
        removeAuth(auth.getNickname());
        saveAuth(newAuth);
    }
    return true;
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 8 with PlayerAuth

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

the class SQLite method getAllAuths.

@Override
public List<PlayerAuth> getAllAuths() {
    List<PlayerAuth> auths = new ArrayList<>();
    String sql = "SELECT * FROM " + tableName + ";";
    try (PreparedStatement pst = con.prepareStatement(sql);
        ResultSet rs = pst.executeQuery()) {
        while (rs.next()) {
            PlayerAuth auth = buildAuthFromResultSet(rs);
            auths.add(auth);
        }
    } catch (SQLException ex) {
        logSqlException(ex);
    }
    return auths;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 9 with PlayerAuth

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

the class CrazyLoginConverter method migrateAccount.

/**
     * Moves an account from CrazyLogin to the AuthMe database.
     *
     * @param line line read from the CrazyLogin file (one account)
     */
private void migrateAccount(String line) {
    String[] args = line.split("\\|");
    if (args.length < 2 || "name".equalsIgnoreCase(args[0])) {
        return;
    }
    String playerName = args[0];
    String password = args[1];
    if (password != null) {
        PlayerAuth auth = PlayerAuth.builder().name(playerName.toLowerCase()).realName(playerName).password(password, null).build();
        database.saveAuth(auth);
    }
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 10 with PlayerAuth

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

the class NewAPI method registerPlayer.

/**
     * Register an OFFLINE/ONLINE player with the given password.
     *
     * @param playerName The player to register
     * @param password   The password to register the player with
     * 
     * @return true if the player was registered successfully
     */
public boolean registerPlayer(String playerName, String password) {
    String name = playerName.toLowerCase();
    HashedPassword result = passwordSecurity.computeHash(password, name);
    if (isRegistered(name)) {
        return false;
    }
    PlayerAuth auth = PlayerAuth.builder().name(name).password(result).realName(playerName).build();
    return dataSource.saveAuth(auth);
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword)

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