Search in sources :

Example 1 with PlayerAuth

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

the class AsynchronousLogin method getPlayerAuth.

/**
     * Checks the precondition for authentication (like user known) and returns
     * the player's {@link PlayerAuth} object.
     *
     * @param player the player to check
     * @return the PlayerAuth object, or {@code null} if the player doesn't exist or may not log in
     *         (e.g. because he is already logged in)
     */
private PlayerAuth getPlayerAuth(Player player) {
    final String name = player.getName().toLowerCase();
    if (playerCache.isAuthenticated(name)) {
        service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
        return null;
    }
    PlayerAuth auth = dataSource.getAuth(name);
    if (auth == null) {
        service.send(player, MessageKey.UNKNOWN_USER);
        // Recreate the message task to immediately send the message again as response
        limboService.resetMessageTask(player, false);
        return null;
    }
    if (!service.getProperty(DatabaseSettings.MYSQL_COL_GROUP).isEmpty() && auth.getGroupId() == service.getProperty(HooksSettings.NON_ACTIVATED_USERS_GROUP)) {
        service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
        return null;
    }
    final String ip = PlayerUtils.getPlayerIp(player);
    if (hasReachedMaxLoggedInPlayersForIp(player, ip)) {
        service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
        return null;
    }
    boolean isAsync = service.getProperty(PluginSettings.USE_ASYNC_TASKS);
    AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player, isAsync);
    bukkitService.callEvent(event);
    if (!event.canLogin()) {
        return null;
    }
    return auth;
}
Also used : AuthMeAsyncPreLoginEvent(fr.xephi.authme.events.AuthMeAsyncPreLoginEvent) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 2 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)

Example 3 with PlayerAuth

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

the class CountryLookup method outputInfoForPlayer.

private void outputInfoForPlayer(CommandSender sender, String name) {
    PlayerAuth auth = dataSource.getAuth(name);
    if (auth == null) {
        sender.sendMessage("No player with name '" + name + "'");
    } else {
        sender.sendMessage("Player '" + name + "' has IP address " + auth.getIp());
        outputInfoForIpAddr(sender, auth.getIp());
    }
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 4 with PlayerAuth

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

the class EmailRegisterExecutorProviderTest method shouldCreatePlayerAuth.

@Test
public void shouldCreatePlayerAuth() {
    // given
    given(commonService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(12);
    given(passwordSecurity.computeHash(anyString(), anyString())).willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
    Player player = mock(Player.class);
    TestHelper.mockPlayerIp(player, "123.45.67.89");
    given(player.getName()).willReturn("Veronica");
    World world = mock(World.class);
    given(world.getName()).willReturn("someWorld");
    given(player.getLocation()).willReturn(new Location(world, 48, 96, 144));
    EmailRegisterParams params = EmailRegisterParams.of(player, "test@example.com");
    // when
    PlayerAuth auth = executor.buildPlayerAuth(params);
    // then
    assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "123.45.67.89"));
    assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 0, 0));
    assertThat(auth.getPassword().getHash(), stringWithLength(12));
}
Also used : Player(org.bukkit.entity.Player) World(org.bukkit.World) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) AuthMeMatchers.hasAuthLocation(fr.xephi.authme.AuthMeMatchers.hasAuthLocation) Location(org.bukkit.Location) Test(org.junit.Test)

Example 5 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)

Aggregations

PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)165 Test (org.junit.Test)112 Player (org.bukkit.entity.Player)46 CommandSender (org.bukkit.command.CommandSender)28 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)22 Location (org.bukkit.Location)12 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 Matchers.containsString (org.hamcrest.Matchers.containsString)10 Connection (java.sql.Connection)9 ArrayList (java.util.ArrayList)9 EmailChangedEvent (fr.xephi.authme.events.EmailChangedEvent)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 SQLException (java.sql.SQLException)8 Function (java.util.function.Function)8 IOException (java.io.IOException)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 Statement (java.sql.Statement)5