Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into command-perms-refactor

This commit is contained in:
ljacqu
2015-12-04 22:00:44 +01:00
10 changed files with 233 additions and 198 deletions
@@ -50,33 +50,16 @@ public class AsynchronousJoin {
}
public void process() {
if (AuthMePlayerListener.gameMode.containsKey(name))
AuthMePlayerListener.gameMode.remove(name);
AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode());
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
if (Utils.isUnrestricted(player)) {
return;
}
AuthMePlayerListener.gameMode.put(name, player.getGameMode());
if (plugin.ess != null && Settings.disableSocialSpy) {
plugin.ess.getUser(player).setSocialSpyEnabled(false);
}
if (!plugin.canConnect()) {
final GameMode gM = AuthMePlayerListener.gameMode.get(name);
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
player.setGameMode(gM);
player.kickPlayer("Server is loading, please wait before joining!");
}
});
return;
}
final String ip = plugin.getIP(player);
if (Settings.isAllowRestrictedIp && !Settings.getRestrictedIp(name, ip)) {
final GameMode gM = AuthMePlayerListener.gameMode.get(name);
@@ -5,16 +5,13 @@ 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.permission.PlayerPermission;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Player;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
/**
*/
public class AsyncRegister {
@@ -22,7 +19,8 @@ public class AsyncRegister {
protected final Player player;
protected final String name;
protected final String password;
protected String email = "";
private final String ip;
private String email = "";
private final AuthMe plugin;
private final DataSource database;
private final Messages m;
@@ -35,13 +33,10 @@ public class AsyncRegister {
this.email = email;
this.plugin = plugin;
this.database = data;
this.ip = plugin.getIP(player);
}
protected String getIp() {
return plugin.getIP(player);
}
protected boolean preRegisterCheck() throws Exception {
private boolean preRegisterCheck() throws Exception {
String passLow = password.toLowerCase();
if (PlayerCache.getInstance().isAuthenticated(name)) {
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
@@ -65,10 +60,10 @@ public class AsyncRegister {
m.send(player, MessageKey.NAME_ALREADY_REGISTERED);
return false;
} else if (Settings.getmaxRegPerIp > 0
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp
&& !getIp().equalsIgnoreCase("127.0.0.1")
&& !getIp().equalsIgnoreCase("localhost")) {
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& !ip.equalsIgnoreCase("127.0.0.1")
&& !ip.equalsIgnoreCase("localhost")
&& database.getAllAuthsByIp(ip).size() >= Settings.getmaxRegPerIp) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return false;
}
@@ -81,16 +76,10 @@ public class AsyncRegister {
return;
}
if (!email.isEmpty() && !email.equals("")) {
if (Settings.getmaxRegPerEmail > 0
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
emailRegister();
return;
} else {
passwordRegister();
}
passwordRegister();
} catch (Exception e) {
ConsoleLogger.showError(e.getMessage());
ConsoleLogger.writeStackTrace(e);
@@ -98,20 +87,32 @@ public class AsyncRegister {
}
}
protected void emailRegister() throws Exception {
private void emailRegister() throws Exception {
if (Settings.getmaxRegPerEmail > 0
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
PlayerAuth auth;
final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
auth = new PlayerAuth(name, hashNew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, player.getName());
if (PasswordSecurity.userSalt.containsKey(name)) {
auth.setSalt(PasswordSecurity.userSalt.get(name));
final String salt = PasswordSecurity.userSalt.get(name);
PlayerAuth auth = PlayerAuth.builder()
.name(name)
.realName(player.getName())
.hash(hashNew)
.ip(ip)
.locWorld(player.getLocation().getWorld().getName())
.locX(player.getLocation().getX())
.locY(player.getLocation().getY())
.locZ(player.getLocation().getZ())
.email(email)
.salt(salt != null ? salt : "")
.build();
if (!database.saveAuth(auth)) {
m.send(player, MessageKey.ERROR);
return;
}
database.saveAuth(auth);
database.updateEmail(auth);
database.updateSession(auth);
plugin.mail.main(auth, password);
@@ -120,21 +121,21 @@ public class AsyncRegister {
}
protected void passwordRegister() {
PlayerAuth auth;
String hash;
try {
hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
} catch (NoSuchAlgorithmException e) {
ConsoleLogger.showError(e.getMessage());
m.send(player, MessageKey.ERROR);
return;
}
if (Settings.getMySQLColumnSalt.isEmpty() && !PasswordSecurity.userSalt.containsKey(name)) {
auth = new PlayerAuth(name, hash, getIp(), new Date().getTime(), "your@email.com", player.getName());
} else {
auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), getIp(), new Date().getTime(), player.getName());
}
private void passwordRegister() throws Exception {
final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
final String salt = PasswordSecurity.userSalt.get(name);
PlayerAuth auth = PlayerAuth.builder()
.name(name)
.realName(player.getName())
.hash(hashNew)
.ip(ip)
.locWorld(player.getLocation().getWorld().getName())
.locX(player.getLocation().getX())
.locY(player.getLocation().getY())
.locZ(player.getLocation().getZ())
.salt(salt != null ? salt : "")
.build();
if (!database.saveAuth(auth)) {
m.send(player, MessageKey.ERROR);
return;
@@ -41,15 +41,13 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
this.plugin = plugin;
}
protected void forceCommands() {
private void forceCommands() {
for (String command : Settings.forceRegisterCommands) {
try {
player.performCommand(command.replace("%p", player.getName()));
} catch (Exception ignored) {
}
player.performCommand(command.replace("%p", player.getName()));
}
for (String command : Settings.forceRegisterCommandsAsConsole) {
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName()));
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
command.replace("%p", player.getName()));
}
}
@@ -58,20 +56,21 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
*
* @param player Player
*/
protected void forceLogin(Player player) {
private void forceLogin(Player player) {
Utils.teleportToSpawn(player);
if (LimboCache.getInstance().hasLimboPlayer(name))
LimboCache.getInstance().deleteLimboPlayer(name);
LimboCache.getInstance().addLimboPlayer(player);
LimboCache cache = LimboCache.getInstance();
cache.updateLimboPlayer(player);
int delay = Settings.getRegistrationTimeout * 20;
int interval = Settings.getWarnMessageInterval;
BukkitScheduler sched = plugin.getServer().getScheduler();
BukkitTask task;
if (delay != 0) {
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
task = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
cache.getLimboPlayer(name).setTimeoutTaskId(task);
}
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.retrieve(MessageKey.LOGIN_MESSAGE), interval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
task = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name,
m.retrieve(MessageKey.LOGIN_MESSAGE), interval));
cache.getLimboPlayer(name).setMessageTaskId(task);
if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject();
}
@@ -97,33 +96,39 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
}
}
limbo.getTimeoutTaskId().cancel();
limbo.getMessageTaskId().cancel();
LimboCache.getInstance().deleteLimboPlayer(name);
}
if (!Settings.getRegisteredGroup.isEmpty()) {
Utils.setGroup(player, Utils.GroupType.REGISTERED);
}
m.send(player, MessageKey.REGISTER_SUCCESS);
if (!Settings.getmailAccount.isEmpty())
if (!Settings.getmailAccount.isEmpty()) {
m.send(player, MessageKey.ADD_EMAIL_MESSAGE);
}
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(false);
player.setFlying(false);
}
if (Settings.applyBlindEffect)
if (Settings.applyBlindEffect) {
player.removePotionEffect(PotionEffectType.BLINDNESS);
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
player.setWalkSpeed(0.2f);
player.setFlySpeed(0.1f);
}
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
player.setWalkSpeed(0.0f);
player.setFlySpeed(0.0f);
}
// The LoginEvent now fires (as intended) after everything is processed
plugin.getServer().getPluginManager().callEvent(new LoginEvent(player, true));
player.saveData();
if (!Settings.noConsoleSpam)
if (!Settings.noConsoleSpam) {
ConsoleLogger.info(player.getName() + " registered " + plugin.getIP(player));
}
// Kick Player after Registration is enabled, kick the player
if (Settings.forceRegKick) {
@@ -138,7 +143,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
}
// Register is finish and player is logged, display welcome message
if (Settings.useWelcomeMessage)
if (Settings.useWelcomeMessage) {
if (Settings.broadcastWelcomeMessage) {
for (String s : Settings.welcomeMsg) {
plugin.getServer().broadcastMessage(plugin.replaceAllInfo(s, player));
@@ -148,6 +153,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
player.sendMessage(plugin.replaceAllInfo(s, player));
}
}
}
// Register is now finish , we can force all commands
forceCommands();