Search in sources :

Example 11 with PlayerAuth

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

the class AuthMeApi 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 12 with PlayerAuth

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

the class LastLoginCommand method executeCommand.

@Override
public void executeCommand(CommandSender sender, List<String> arguments) {
    // Get the player
    String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
    PlayerAuth auth = dataSource.getAuth(playerName);
    if (auth == null) {
        commonService.send(sender, MessageKey.UNKNOWN_USER);
        return;
    }
    // Get the last login date
    final long lastLogin = auth.getLastLogin();
    final long diff = System.currentTimeMillis() - lastLogin;
    final String lastLoginMessage = (int) (diff / 86400000) + " days " + (int) (diff / 3600000 % 24) + " hours " + (int) (diff / 60000 % 60) + " mins " + (int) (diff / 1000 % 60) + " secs";
    Date date = new Date(lastLogin);
    // Show the player status
    sender.sendMessage("[AuthMe] " + playerName + " last login: " + date.toString());
    sender.sendMessage("[AuthMe] The player " + playerName + " last logged in " + lastLoginMessage + " ago.");
    sender.sendMessage("[AuthMe] Last Player's IP: " + auth.getIp());
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Date(java.util.Date)

Example 13 with PlayerAuth

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

the class PurgeLastPositionCommand method executeCommand.

@Override
public void executeCommand(final CommandSender sender, List<String> arguments) {
    String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
    if ("*".equals(playerName)) {
        for (PlayerAuth auth : dataSource.getAllAuths()) {
            resetLastPosition(auth);
            dataSource.updateQuitLoc(auth);
        }
        sender.sendMessage("All players last position locations are now reset");
    } else {
        // Get the user auth and make sure the user exists
        PlayerAuth auth = dataSource.getAuth(playerName);
        if (auth == null) {
            commonService.send(sender, MessageKey.UNKNOWN_USER);
            return;
        }
        resetLastPosition(auth);
        dataSource.updateQuitLoc(auth);
        sender.sendMessage(playerName + "'s last position location is now reset");
    }
}
Also used : PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth)

Example 14 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 15 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)

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