Merge branch 'master' into 674-purge-process-refactor

This commit is contained in:
Gnat008
2016-06-16 12:36:31 -04:00
22 changed files with 158 additions and 121 deletions
@@ -723,15 +723,6 @@ public class AuthMe extends JavaPlugin {
// Service getters (deprecated)
// Use @Inject fields instead
// -------------
/**
* @return Plugin's messages.
* @deprecated should be used in API classes only (temporarily)
*/
@Deprecated
public Messages getMessages() {
return messages;
}
/**
* @return NewSetting
* @deprecated should be used in API classes only (temporarily)
@@ -93,13 +93,12 @@ public class UnregisterAdminCommand implements ExecutableCommand {
* @param target the player that was unregistered
*/
private void applyUnregisteredEffectsAndTasks(Player target) {
// TODO ljacqu 20160612: Remove use of Utils method and behave according to settings
// TODO #765: Remove use of Utils method and behave according to settings
Utils.teleportToSpawn(target);
limboCache.addLimboPlayer(target);
limboPlayerTaskManager.registerTimeoutTask(target);
limboPlayerTaskManager.registerMessageTask(target.getName(),
MessageKey.REGISTER_MESSAGE);
limboPlayerTaskManager.registerMessageTask(target.getName(), false);
final int timeout = commandService.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (commandService.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
@@ -1,13 +1,10 @@
package fr.xephi.authme.command.executable.changepassword;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.task.ChangePasswordTask;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.util.ValidationService;
import fr.xephi.authme.util.ValidationService.ValidationResult;
import org.bukkit.entity.Player;
@@ -26,15 +23,11 @@ public class ChangePasswordCommand extends PlayerCommand {
@Inject
private PlayerCache playerCache;
@Inject
private BukkitService bukkitService;
@Inject
private ValidationService validationService;
@Inject
// TODO ljacqu 20160531: Remove this once change password task runs as a process (via Management)
private PasswordSecurity passwordSecurity;
private Management management;
@Override
public void runCommand(Player player, List<String> arguments) {
@@ -54,9 +47,6 @@ public class ChangePasswordCommand extends PlayerCommand {
return;
}
AuthMe plugin = AuthMe.getInstance();
// TODO ljacqu 20160117: Call async task via Management
bukkitService.runTaskAsynchronously(
new ChangePasswordTask(plugin, player, oldPassword, newPassword, passwordSecurity));
management.performPasswordChange(player, oldPassword, newPassword);
}
}
@@ -1,5 +1,6 @@
package fr.xephi.authme.process;
import fr.xephi.authme.process.changepassword.AsyncChangePassword;
import fr.xephi.authme.process.email.AsyncAddEmail;
import fr.xephi.authme.process.email.AsyncChangeEmail;
import fr.xephi.authme.process.join.AsynchronousJoin;
@@ -36,9 +37,12 @@ public class Management {
private AsynchronousLogin asynchronousLogin;
@Inject
private AsynchronousUnregister asynchronousUnregister;
@Inject
private AsyncChangePassword asyncChangePassword;
Management() { }
public void performLogin(final Player player, final String password, final boolean forceLogin) {
runTask(new Runnable() {
@Override
@@ -111,6 +115,15 @@ public class Management {
});
}
public void performPasswordChange(final Player player, final String oldPassword, final String newPassword) {
runTask(new Runnable() {
@Override
public void run() {
asyncChangePassword.changePassword(player, oldPassword, newPassword);
}
});
}
private void runTask(Runnable runnable) {
bukkitService.runTaskAsynchronously(runnable);
}
@@ -1,4 +1,4 @@
package fr.xephi.authme.task;
package fr.xephi.authme.process.changepassword;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
@@ -6,52 +6,60 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.util.BukkitService;
import org.bukkit.entity.Player;
public class ChangePasswordTask implements Runnable {
import javax.inject.Inject;
private final AuthMe plugin;
private final Player player;
private final String oldPassword;
private final String newPassword;
private final PasswordSecurity passwordSecurity;
public class AsyncChangePassword implements AsynchronousProcess {
public ChangePasswordTask(AuthMe plugin, Player player, String oldPassword, String newPassword,
PasswordSecurity passwordSecurity) {
this.plugin = plugin;
this.player = player;
this.oldPassword = oldPassword;
this.newPassword = newPassword;
this.passwordSecurity = passwordSecurity;
}
@Inject
private AuthMe plugin;
@Override
public void run() {
Messages m = plugin.getMessages();
@Inject
private DataSource dataSource;
@Inject
private ProcessService processService;
@Inject
private PasswordSecurity passwordSecurity;
@Inject
private PlayerCache playerCache;
@Inject
private BukkitService bukkitService;
AsyncChangePassword() { }
public void changePassword(final Player player, String oldPassword, String newPassword) {
final String name = player.getName().toLowerCase();
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
PlayerAuth auth = playerCache.getAuth(name);
if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, name);
auth.setPassword(hashedPassword);
if (!plugin.getDataSource().updatePassword(auth)) {
m.send(player, MessageKey.ERROR);
if (!dataSource.updatePassword(auth)) {
processService.send(player, MessageKey.ERROR);
return;
}
PlayerCache.getInstance().updatePlayer(auth);
m.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
playerCache.updatePlayer(auth);
processService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
ConsoleLogger.info(player.getName() + " changed his password");
if (Settings.bungee) {
if (processService.getProperty(HooksSettings.BUNGEECORD)) {
final String hash = hashedPassword.getHash();
final String salt = hashedPassword.getSalt();
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
bukkitService.scheduleSyncDelayedTask(new Runnable() {
@Override
public void run() {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
@@ -64,7 +72,7 @@ public class ChangePasswordTask implements Runnable {
});
}
} else {
m.send(player, MessageKey.WRONG_PASSWORD);
processService.send(player, MessageKey.WRONG_PASSWORD);
}
}
}
@@ -195,16 +195,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
// Timeout and message task
limboPlayerTaskManager.registerTimeoutTask(player);
MessageKey msg;
if (isAuthAvailable) {
msg = MessageKey.LOGIN_MESSAGE;
} else {
msg = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
? MessageKey.REGISTER_EMAIL_MESSAGE
: MessageKey.REGISTER_MESSAGE;
}
limboPlayerTaskManager.registerMessageTask(name, msg);
limboPlayerTaskManager.registerMessageTask(name, isAuthAvailable);
}
private boolean isPlayerUnrestricted(String name) {
@@ -21,7 +21,6 @@ import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.LimboPlayerTaskManager;
@@ -33,7 +32,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@@ -108,10 +106,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
service.send(player, MessageKey.USER_NOT_REGISTERED);
// TODO ljacqu 20160612: Why is the message task being canceled and added again here?
MessageKey key = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
? MessageKey.REGISTER_EMAIL_MESSAGE
: MessageKey.REGISTER_MESSAGE;
limboPlayerTaskManager.registerMessageTask(name, key);
limboPlayerTaskManager.registerMessageTask(name, false);
return null;
}
@@ -66,7 +66,7 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
}
limboPlayerTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, MessageKey.LOGIN_MESSAGE);
limboPlayerTaskManager.registerMessageTask(name, true);
if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject();
@@ -33,7 +33,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
limboPlayerTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, MessageKey.LOGIN_MESSAGE);
limboPlayerTaskManager.registerMessageTask(name, true);
player.saveData();
if (!service.getProperty(SecuritySettings.REMOVE_SPAM_FROM_CONSOLE)) {
@@ -81,7 +81,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
limboCache.updateLimboPlayer(player);
limboPlayerTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, MessageKey.LOGIN_MESSAGE);
limboPlayerTaskManager.registerMessageTask(name, true);
if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject();
@@ -64,7 +64,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
}
limboCache.addLimboPlayer(player);
limboPlayerTaskManager.registerTimeoutTask(player);
limboPlayerTaskManager.registerMessageTask(name, MessageKey.REGISTER_MESSAGE);
limboPlayerTaskManager.registerMessageTask(name, false);
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
ConsoleLogger.info(player.getDisplayName() + " unregistered himself");
@@ -2,7 +2,6 @@ package fr.xephi.authme.settings;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
@@ -26,7 +25,6 @@ public final class Settings {
public static boolean protectInventoryBeforeLogInEnabled;
public static boolean isStopEnabled;
public static boolean reloadSupport;
public static boolean bungee;
public static boolean forceRegLogin;
public static boolean noTeleport;
public static boolean isRemoveSpeedEnabled;
@@ -65,7 +63,6 @@ public final class Settings {
protectInventoryBeforeLogInEnabled = load(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN);
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
bungee = load(HooksSettings.BUNGEECORD);
defaultWorld = configFile.getString("Purge.defaultWorld", "world");
forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER);
noTeleport = load(RestrictionSettings.NO_TELEPORT);
@@ -44,10 +44,12 @@ public class LimboPlayerTaskManager {
* Registers a {@link MessageTask} for the given player name.
*
* @param name the name of the player to schedule a repeating message task for
* @param key the key of the message to display
* @param isRegistered whether the name is registered or not
* (false shows "please register", true shows "please log in")
*/
public void registerMessageTask(String name, MessageKey key) {
public void registerMessageTask(String name, boolean isRegistered) {
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
final MessageKey key = getMessageKey(isRegistered);
if (interval > 0) {
final LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
if (limboPlayer == null) {
@@ -81,6 +83,22 @@ public class LimboPlayerTaskManager {
}
}
/**
* Returns the appropriate message key according to the registration status and settings.
*
* @param isRegistered whether or not the username is registered
* @return the message key to display to the user
*/
private MessageKey getMessageKey(boolean isRegistered) {
if (isRegistered) {
return MessageKey.LOGIN_MESSAGE;
} else {
return settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
? MessageKey.REGISTER_EMAIL_MESSAGE
: MessageKey.REGISTER_MESSAGE;
}
}
/**
* Null-safe method to cancel a potentially existing task.
*
+7 -4
View File
@@ -1,4 +1,7 @@
# Lingua Italiana creata da Maxetto e sgdc3.
denied_command: '&cPer poter usare questo comando devi essere autenticato!'
same_ip_online: 'Un giocatore con il tuo stesso IP è già connesso sul server!'
denied_chat: '&cPer poter scrivere messaggi in chat devi essere autenticato!'
kick_antibot: 'Il servizio di AntiBot è attualmente attivo! Devi aspettare qualche minuto prima di poter entrare nel server.'
unknown_user: '&cL''utente non è presente nel database.'
unsafe_spawn: '&cIl tuo punto di disconnessione risulta ostruito o insicuro, sei stato teletrasportato al punto di rigenerazione!'
@@ -30,7 +33,7 @@ invalid_session: '&cIl tuo indirizzo IP è cambiato e la tua sessione è stata t
reg_only: '&4Puoi giocare in questo server solo dopo aver effettuato la registrazione attraverso il sito web! Per favore, vai su http://esempio.it per procedere!'
logged_in: '&cHai già eseguito l''autenticazione, non è necessario eseguirla nuovamente!'
logout: '&2Disconnessione avvenuta correttamente!'
same_nick: '&4Questo stesso nome utente è già online sul server!'
same_nick: '&4Un giocatore con il tuo stesso nome utente è già connesso sul server!'
registered: '&2Registrato correttamente!'
pass_len: '&cLa password che hai inserito è troppo corta o troppo lunga, per favore scegline un''altra...'
reload: '&2La configurazione e il database sono stati ricaricati correttamente!'
@@ -63,6 +66,6 @@ email_already_used: '&4L''indirizzo email inserito è già in uso'
two_factor_create: '&2Il tuo codice segreto è: &f%code&n&2Puoi anche scannerizzare il codice QR da qui: &f%url'
not_owner_error: 'Non sei il proprietario di questo account. Per favore scegli un altro nome!'
invalid_name_case: 'Dovresti entrare con questo nome utente: "%valid", al posto di: "%invalid".'
# TODO denied_command: '&cIn order to use this command you must be authenticated!'
# TODO same_ip_online: 'A player with the same IP is already in game!'
# TODO denied_chat: '&cIn order to chat you must be authenticated!'
tempban_max_logins: '&cSei stato temporaneamente bandito per aver fallito l''autenticazione troppe volte.'
accounts_owned_self: 'Possiedi %count account:'
accounts_owned_other: 'Il giocatore %name possiede %count account:'