mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 12:45:57 +01:00
Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded.git
This commit is contained in:
commit
21ea54d604
@ -1,5 +1,9 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import fr.xephi.authme.api.NewAPI;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
@ -8,39 +12,30 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
|
|
||||||
import fr.xephi.authme.api.NewAPI;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
|
||||||
|
|
||||||
public class ConsoleLogger {
|
public class ConsoleLogger {
|
||||||
|
|
||||||
private static final Logger log = AuthMe.getInstance().getLogger();
|
private static final Logger log = AuthMe.getInstance().getLogger();
|
||||||
private static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
private static final DateFormat df = new SimpleDateFormat("[MM-dd HH:mm:ss]");
|
||||||
|
|
||||||
public static void info(String message) {
|
public static void info(String message) {
|
||||||
if (AuthMe.getInstance().isEnabled()) {
|
log.info("[AuthMe] " + message);
|
||||||
log.info("[AuthMe] " + message);
|
if (Settings.useLogging) {
|
||||||
if (Settings.useLogging) {
|
String dateTime;
|
||||||
String dateTime;
|
synchronized (df) {
|
||||||
synchronized (df) {
|
dateTime = df.format(new Date());
|
||||||
dateTime = df.format(new Date());
|
|
||||||
}
|
|
||||||
writeLog(dateTime + " " + message);
|
|
||||||
}
|
}
|
||||||
|
writeLog(dateTime + " " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showError(String message) {
|
public static void showError(String message) {
|
||||||
if (AuthMe.getInstance().isEnabled()) {
|
log.warning("[AuthMe] " + message);
|
||||||
log.warning("[AuthMe] " + message);
|
if (Settings.useLogging) {
|
||||||
if (Settings.useLogging) {
|
String dateTime;
|
||||||
String dateTime;
|
synchronized (df) {
|
||||||
synchronized (df) {
|
dateTime = df.format(new Date());
|
||||||
dateTime = df.format(new Date());
|
|
||||||
}
|
|
||||||
writeLog(dateTime + " ERROR: " + message);
|
|
||||||
}
|
}
|
||||||
|
writeLog(dateTime + " ERROR: " + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,10 +49,12 @@ public class ConsoleLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void writeStackTrace(Exception ex) {
|
public static void writeStackTrace(Exception ex) {
|
||||||
String dateTime;
|
if (Settings.useLogging) {
|
||||||
synchronized (df) {
|
String dateTime;
|
||||||
dateTime = df.format(new Date());
|
synchronized (df) {
|
||||||
|
dateTime = df.format(new Date());
|
||||||
|
}
|
||||||
|
writeLog(dateTime + " " + Throwables.getStackTraceAsString(ex));
|
||||||
}
|
}
|
||||||
writeLog(dateTime + " " + Throwables.getStackTraceAsString(ex));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package fr.xephi.authme.command.executable.authme;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@ -79,11 +80,20 @@ public class AccountsCommand extends ExecutableCommand {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
List<String> accountList;
|
||||||
|
try {
|
||||||
|
accountList = plugin.database.getAllAuthsByIp(playerQueryFinal);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder message = new StringBuilder("[AuthMe] ");
|
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||||
List<String> accountList = plugin.database.getAllAuthsByIp(playerQueryFinal);
|
|
||||||
if (accountList == null || accountList.isEmpty()) {
|
if (accountList == null || accountList.isEmpty()) {
|
||||||
sender.sendMessage("[AuthMe] This IP does not exist in the database");
|
sender.sendMessage("[AuthMe] This IP does not exist in the database");
|
||||||
return;
|
return;
|
||||||
|
@ -1,25 +1,20 @@
|
|||||||
package fr.xephi.authme.command.executable.email;
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class AddEmailCommand extends ExecutableCommand {
|
public class AddEmailCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the command.
|
* Execute the command.
|
||||||
*
|
*
|
||||||
* @param sender The command sender.
|
* @param sender The command sender.
|
||||||
* @param commandReference The command reference.
|
* @param commandReference The command reference.
|
||||||
* @param commandArguments The command arguments.
|
* @param commandArguments The command arguments.
|
||||||
*
|
|
||||||
* @return True if the command was executed successfully, false otherwise.
|
* @return True if the command was executed successfully, false otherwise.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -35,57 +30,16 @@ public class AddEmailCommand extends ExecutableCommand {
|
|||||||
String playerMailVerify = commandArguments.get(1);
|
String playerMailVerify = commandArguments.get(1);
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the player instance and name
|
// Get the player instance and name
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
final String playerName = player.getName();
|
final String playerName = player.getName().toLowerCase();
|
||||||
|
|
||||||
// Command logic
|
// Command logic
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
plugin.management.performAddEmail(player, playerMail, playerMailVerify);
|
||||||
if (!plugin.authmePermissible(sender, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(playerMail).size() >= Settings.getmaxRegPerEmail) {
|
|
||||||
m.send(player, "max_reg");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (playerMail.equals(playerMailVerify) && PlayerCache.getInstance().isAuthenticated(playerName)) {
|
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
|
|
||||||
|
|
||||||
if (auth.getEmail() == null || (!auth.getEmail().equals("your@email.com") && !auth.getEmail().isEmpty())) {
|
|
||||||
m.send(player, "usage_email_change");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Settings.isEmailCorrect(playerMail)) {
|
|
||||||
m.send(player, "email_invalid");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
auth.setEmail(playerMail);
|
|
||||||
|
|
||||||
if (!plugin.database.updateEmail(auth)) {
|
|
||||||
m.send(player, "error");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
|
||||||
m.send(player, "email_added");
|
|
||||||
player.sendMessage(auth.getEmail());
|
|
||||||
|
|
||||||
} else if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
|
||||||
m.send(player, "email_confirm");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (!plugin.database.isAuthAvailable(playerName)) {
|
|
||||||
m.send(player, "login_msg");
|
|
||||||
} else {
|
|
||||||
m.send(player, "reg_email_msg");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,20 @@
|
|||||||
package fr.xephi.authme.command.executable.email;
|
package fr.xephi.authme.command.executable.email;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
|
||||||
import fr.xephi.authme.command.CommandParts;
|
import fr.xephi.authme.command.CommandParts;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class ChangeEmailCommand extends ExecutableCommand {
|
public class ChangeEmailCommand extends ExecutableCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the command.
|
* Execute the command.
|
||||||
*
|
*
|
||||||
* @param sender The command sender.
|
* @param sender The command sender.
|
||||||
* @param commandReference The command reference.
|
* @param commandReference The command reference.
|
||||||
* @param commandArguments The command arguments.
|
* @param commandArguments The command arguments.
|
||||||
*
|
|
||||||
* @return True if the command was executed successfully, false otherwise.
|
* @return True if the command was executed successfully, false otherwise.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -37,7 +30,7 @@ public class ChangeEmailCommand extends ExecutableCommand {
|
|||||||
String playerMailNew = commandArguments.get(1);
|
String playerMailNew = commandArguments.get(1);
|
||||||
|
|
||||||
// Make sure the current command executor is a player
|
// Make sure the current command executor is a player
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,44 +39,7 @@ public class ChangeEmailCommand extends ExecutableCommand {
|
|||||||
final String playerName = player.getName();
|
final String playerName = player.getName();
|
||||||
|
|
||||||
// Command logic
|
// Command logic
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
plugin.management.performChangeEmail(player, playerMailOld, playerMailNew);
|
||||||
if (!plugin.authmePermissible(sender, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(playerMailNew).size() >= Settings.getmaxRegPerEmail) {
|
|
||||||
m.send(player, "max_reg");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
|
|
||||||
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) {
|
|
||||||
m.send(player, "usage_email_add");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!playerMailOld.equals(auth.getEmail())) {
|
|
||||||
m.send(player, "old_email_invalid");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!Settings.isEmailCorrect(playerMailNew)) {
|
|
||||||
m.send(player, "new_email_invalid");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
auth.setEmail(playerMailNew);
|
|
||||||
if (!plugin.database.updateEmail(auth)) {
|
|
||||||
m.send(player, "error");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
|
||||||
m.send(player, "email_changed");
|
|
||||||
player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail());
|
|
||||||
} else if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
|
||||||
m.send(player, "email_confirm");
|
|
||||||
} else {
|
|
||||||
if (!plugin.database.isAuthAvailable(playerName)) {
|
|
||||||
m.send(player, "login_msg");
|
|
||||||
} else {
|
|
||||||
m.send(player, "reg_email_msg");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
final String[] arguments = args;
|
final String[] arguments = args;
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
StringBuilder message = new StringBuilder("[AuthMe] ");
|
StringBuilder message = new StringBuilder("[AuthMe] ");
|
||||||
@ -202,7 +202,15 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
sender.sendMessage("[AuthMe] Please put a valid IP");
|
sender.sendMessage("[AuthMe] Please put a valid IP");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> accountList = plugin.database.getAllAuthsByIp(arguments[1]);
|
List<String> accountList = null;
|
||||||
|
try {
|
||||||
|
accountList = plugin.database.getAllAuthsByIp(arguments[1]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (accountList == null || accountList.isEmpty()) {
|
if (accountList == null || accountList.isEmpty()) {
|
||||||
sender.sendMessage("[AuthMe] This IP does not exist in the database");
|
sender.sendMessage("[AuthMe] This IP does not exist in the database");
|
||||||
return;
|
return;
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
package fr.xephi.authme.commands;
|
package fr.xephi.authme.commands;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
@ -16,9 +8,14 @@ import fr.xephi.authme.security.PasswordSecurity;
|
|||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Xephi59
|
* @author Xephi59
|
||||||
*/
|
*/
|
||||||
public class EmailCommand implements CommandExecutor {
|
public class EmailCommand implements CommandExecutor {
|
||||||
@ -32,7 +29,7 @@ public class EmailCommand implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmnd, String label,
|
public boolean onCommand(CommandSender sender, Command cmnd, String label,
|
||||||
String[] args) {
|
String[] args) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -57,81 +54,13 @@ public class EmailCommand implements CommandExecutor {
|
|||||||
m.send(player, "usage_email_add");
|
m.send(player, "usage_email_add");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
plugin.management.performAddEmail(player, args[1], args[2]);
|
||||||
if (!plugin.authmePermissible(sender, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(args[1]).size() >= Settings.getmaxRegPerEmail) {
|
|
||||||
m.send(player, "max_reg");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (args[1].equals(args[2]) && PlayerCache.getInstance().isAuthenticated(name)) {
|
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
|
||||||
if (auth.getEmail() == null || (!auth.getEmail().equals("your@email.com") && !auth.getEmail().isEmpty())) {
|
|
||||||
m.send(player, "usage_email_change");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!Settings.isEmailCorrect(args[1])) {
|
|
||||||
m.send(player, "email_invalid");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
auth.setEmail(args[1]);
|
|
||||||
if (!plugin.database.updateEmail(auth)) {
|
|
||||||
m.send(player, "error");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
|
||||||
m.send(player, "email_added");
|
|
||||||
player.sendMessage(auth.getEmail());
|
|
||||||
} else if (PlayerCache.getInstance().isAuthenticated(name)) {
|
|
||||||
m.send(player, "email_confirm");
|
|
||||||
} else {
|
|
||||||
if (!plugin.database.isAuthAvailable(name)) {
|
|
||||||
m.send(player, "login_msg");
|
|
||||||
} else {
|
|
||||||
m.send(player, "reg_email_msg");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (args[0].equalsIgnoreCase("change")) {
|
} else if (args[0].equalsIgnoreCase("change")) {
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
m.send(player, "usage_email_change");
|
m.send(player, "usage_email_change");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
plugin.management.performChangeEmail(player, args[1], args[2]);
|
||||||
if (!plugin.authmePermissible(sender, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(args[2]).size() >= Settings.getmaxRegPerEmail) {
|
|
||||||
m.send(player, "max_reg");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
|
||||||
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) {
|
|
||||||
m.send(player, "usage_email_add");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!args[1].equals(auth.getEmail())) {
|
|
||||||
m.send(player, "old_email_invalid");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!Settings.isEmailCorrect(args[2])) {
|
|
||||||
m.send(player, "new_email_invalid");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
auth.setEmail(args[2]);
|
|
||||||
if (!plugin.database.updateEmail(auth)) {
|
|
||||||
m.send(player, "error");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
|
||||||
m.send(player, "email_changed");
|
|
||||||
player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail());
|
|
||||||
} else if (PlayerCache.getInstance().isAuthenticated(name)) {
|
|
||||||
m.send(player, "email_confirm");
|
|
||||||
} else {
|
|
||||||
if (!plugin.database.isAuthAvailable(name)) {
|
|
||||||
m.send(player, "login_msg");
|
|
||||||
} else {
|
|
||||||
m.send(player, "reg_email_msg");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("recovery")) {
|
if (args[0].equalsIgnoreCase("recovery")) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
@ -151,7 +80,7 @@ public class EmailCommand implements CommandExecutor {
|
|||||||
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
|
RandomString rand = new RandomString(Settings.getRecoveryPassLength);
|
||||||
String thePass = rand.nextString();
|
String thePass = rand.nextString();
|
||||||
String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name);
|
String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, thePass, name);
|
||||||
PlayerAuth auth = null;
|
PlayerAuth auth;
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
auth = PlayerCache.getInstance().getAuth(name);
|
auth = PlayerCache.getInstance().getAuth(name);
|
||||||
} else if (plugin.database.isAuthAvailable(name)) {
|
} else if (plugin.database.isAuthAvailable(name)) {
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
public class CacheDataSource implements DataSource {
|
public class CacheDataSource implements DataSource {
|
||||||
|
|
||||||
@ -229,23 +226,15 @@ public class CacheDataSource implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
public synchronized boolean updateEmail(final PlayerAuth auth) {
|
||||||
if (!cache.containsKey(auth.getNickname())) {
|
try {
|
||||||
|
return exec.submit(new Callable<Boolean>() {
|
||||||
|
public Boolean call() {
|
||||||
|
return source.updateEmail(auth);
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerAuth cachedAuth = cache.get(auth.getNickname());
|
|
||||||
final String oldEmail = cachedAuth.getEmail();
|
|
||||||
cachedAuth.setEmail(auth.getEmail());
|
|
||||||
exec.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!source.updateEmail(auth)) {
|
|
||||||
if (cache.containsKey(auth.getNickname())) {
|
|
||||||
cache.get(auth.getNickname()).setEmail(oldEmail);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -281,25 +270,21 @@ public class CacheDataSource implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<String> getAllAuthsByIp(String ip) {
|
public synchronized List<String> getAllAuthsByIp(final String ip) throws Exception {
|
||||||
List<String> result = new ArrayList<>();
|
return exec.submit(new Callable<List<String>>() {
|
||||||
for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
|
public List<String> call() throws Exception {
|
||||||
PlayerAuth p = stringPlayerAuthEntry.getValue();
|
return source.getAllAuthsByIp(ip);
|
||||||
if (p.getIp().equals(ip))
|
}
|
||||||
result.add(p.getNickname());
|
}).get();
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<String> getAllAuthsByEmail(String email) {
|
public synchronized List<String> getAllAuthsByEmail(final String email) throws Exception {
|
||||||
List<String> result = new ArrayList<>();
|
return exec.submit(new Callable<List<String>>() {
|
||||||
for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
|
public List<String> call() throws Exception {
|
||||||
PlayerAuth p = stringPlayerAuthEntry.getValue();
|
return source.getAllAuthsByEmail(email);
|
||||||
if (p.getEmail().equals(email))
|
}
|
||||||
result.add(p.getNickname());
|
}).get();
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package fr.xephi.authme.datasource;
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
@ -35,9 +36,9 @@ public interface DataSource {
|
|||||||
|
|
||||||
List<String> getAllAuthsByName(PlayerAuth auth);
|
List<String> getAllAuthsByName(PlayerAuth auth);
|
||||||
|
|
||||||
List<String> getAllAuthsByIp(String ip);
|
List<String> getAllAuthsByIp(String ip) throws Exception;
|
||||||
|
|
||||||
List<String> getAllAuthsByEmail(String email);
|
List<String> getAllAuthsByEmail(String email) throws Exception;
|
||||||
|
|
||||||
boolean updateEmail(PlayerAuth auth);
|
boolean updateEmail(PlayerAuth auth);
|
||||||
|
|
||||||
|
@ -686,6 +686,7 @@ public class MySQL implements DataSource {
|
|||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(ex);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -745,6 +746,7 @@ public class MySQL implements DataSource {
|
|||||||
o.close();
|
o.close();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -802,14 +804,13 @@ public class MySQL implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<String> getAllAuthsByEmail(String email) {
|
public synchronized List<String> getAllAuthsByEmail(String email) throws SQLException {
|
||||||
Connection con = null;
|
final Connection con = getConnection();
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> countEmail = new ArrayList<>();
|
List<String> countEmail = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ((con = getConnection()) == null)
|
|
||||||
return countEmail;
|
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
||||||
pst.setString(1, email);
|
pst.setString(1, email);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -817,9 +818,6 @@ public class MySQL implements DataSource {
|
|||||||
countEmail.add(rs.getString(columnName));
|
countEmail.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countEmail;
|
return countEmail;
|
||||||
} catch (Exception ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return new ArrayList<>();
|
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(pst);
|
close(pst);
|
||||||
|
@ -472,13 +472,12 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByIp(String ip) {
|
public List<String> getAllAuthsByIp(String ip) throws SQLException {
|
||||||
Connection con = null;
|
final Connection con = getConnection();
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> countIp = new ArrayList<>();
|
List<String> countIp = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
pst.setString(1, ip);
|
pst.setString(1, ip);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -486,11 +485,6 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
countIp.add(rs.getString(columnName));
|
countIp.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countIp;
|
return countIp;
|
||||||
} catch (SQLException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return new ArrayList<>();
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -499,13 +493,12 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getAllAuthsByEmail(String email) {
|
public List<String> getAllAuthsByEmail(String email) throws SQLException {
|
||||||
Connection con = null;
|
final Connection con = getConnection();
|
||||||
PreparedStatement pst = null;
|
PreparedStatement pst = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
List<String> countEmail = new ArrayList<>();
|
List<String> countEmail = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
con = getConnection();
|
|
||||||
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
||||||
pst.setString(1, email);
|
pst.setString(1, email);
|
||||||
rs = pst.executeQuery();
|
rs = pst.executeQuery();
|
||||||
@ -513,11 +506,6 @@ public class SQLite_HIKARI implements DataSource {
|
|||||||
countEmail.add(rs.getString(columnName));
|
countEmail.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countEmail;
|
return countEmail;
|
||||||
} catch (SQLException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
return new ArrayList<>();
|
|
||||||
} catch (NullPointerException npe) {
|
|
||||||
return new ArrayList<>();
|
|
||||||
} finally {
|
} finally {
|
||||||
close(rs);
|
close(rs);
|
||||||
close(pst);
|
close(pst);
|
||||||
|
@ -1,38 +1,35 @@
|
|||||||
package fr.xephi.authme.process;
|
package fr.xephi.authme.process;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
||||||
import fr.xephi.authme.process.join.AsyncronousJoin;
|
import fr.xephi.authme.process.join.AsyncronousJoin;
|
||||||
import fr.xephi.authme.process.login.AsyncronousLogin;
|
import fr.xephi.authme.process.login.AsyncronousLogin;
|
||||||
import fr.xephi.authme.process.logout.AsyncronousLogout;
|
import fr.xephi.authme.process.logout.AsyncronousLogout;
|
||||||
import fr.xephi.authme.process.quit.AsyncronousQuit;
|
import fr.xephi.authme.process.quit.AsyncronousQuit;
|
||||||
import fr.xephi.authme.process.register.AsyncronousRegister;
|
import fr.xephi.authme.process.register.AsyncRegister;
|
||||||
import fr.xephi.authme.process.unregister.AsyncronousUnregister;
|
import fr.xephi.authme.process.unregister.AsyncronousUnregister;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @authors Xephi59,
|
* @authors Xephi59,
|
||||||
* <a href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
* <a href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Management {
|
public class Management {
|
||||||
|
|
||||||
public AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
|
private final BukkitScheduler sched;
|
||||||
public static RandomString rdm = new RandomString(Settings.captchaLength);
|
public static RandomString rdm = new RandomString(Settings.captchaLength);
|
||||||
public PluginManager pm;
|
|
||||||
|
|
||||||
public Management(AuthMe plugin) {
|
public Management(AuthMe plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.pm = plugin.getServer().getPluginManager();
|
this.sched = this.plugin.getServer().getScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
public void performLogin(final Player player, final String password, final boolean forceLogin) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -41,18 +38,8 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performRegister(final Player player, final String password, final String email) {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
new AsyncronousRegister(player, password, email, plugin, plugin.database).process();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void performLogout(final Player player) {
|
public void performLogout(final Player player) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -61,19 +48,28 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performQuit(final Player player, final boolean isKick) {
|
public void performRegister(final Player player, final String password, final String email) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsyncronousQuit(player, plugin, plugin.database, isKick).process();
|
new AsyncRegister(player, password, email, plugin, plugin.database).process();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void performUnregister(final Player player, final String password, final boolean force) {
|
||||||
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new AsyncronousUnregister(player, password, force, plugin).process();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performJoin(final Player player) {
|
public void performJoin(final Player player) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -83,13 +79,32 @@ public class Management {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performUnregister(final Player player, final String password, final boolean force) {
|
public void performQuit(final Player player, final boolean isKick) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new AsyncronousUnregister(player, password, force, plugin).process();
|
new AsyncronousQuit(player, plugin, plugin.database, isKick).process();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void performAddEmail(final Player player, final String newEmail, final String newEmailVerify) {
|
||||||
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new AsyncChangeEmail(player, plugin, null, newEmail, newEmailVerify).process();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void performChangeEmail(final Player player, final String oldEmail, final String newEmail) {
|
||||||
|
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new AsyncChangeEmail(player, plugin, oldEmail, newEmail).process();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
package fr.xephi.authme.process.email;
|
||||||
|
|
||||||
|
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.settings.Messages;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class AsyncChangeEmail {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private final AuthMe plugin;
|
||||||
|
private final String oldEmail;
|
||||||
|
private final String newEmail;
|
||||||
|
private final String newEmailVerify;
|
||||||
|
private final Messages m;
|
||||||
|
|
||||||
|
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail, String newEmailVerify) {
|
||||||
|
this.player = player;
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.oldEmail = oldEmail;
|
||||||
|
this.newEmail = newEmail;
|
||||||
|
this.newEmailVerify = newEmailVerify;
|
||||||
|
this.m = Messages.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail) {
|
||||||
|
this(player, plugin, oldEmail, newEmail, newEmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process() {
|
||||||
|
try {
|
||||||
|
String playerName = player.getName().toLowerCase();
|
||||||
|
|
||||||
|
if (Settings.getmaxRegPerEmail > 0) {
|
||||||
|
if (!plugin.authmePermissible(player, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
|
||||||
|
m.send(player, "max_reg");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
|
||||||
|
if (!newEmail.equals(newEmailVerify)) {
|
||||||
|
m.send(player, "email_confirm");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
|
||||||
|
if (oldEmail != null) {
|
||||||
|
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) {
|
||||||
|
m.send(player, "usage_email_add");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!oldEmail.equals(auth.getEmail())) {
|
||||||
|
m.send(player, "old_email_invalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Settings.isEmailCorrect(newEmail)) {
|
||||||
|
m.send(player, "new_email_invalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String old = auth.getEmail();
|
||||||
|
auth.setEmail(newEmail);
|
||||||
|
if (!plugin.database.updateEmail(auth)) {
|
||||||
|
m.send(player, "error");
|
||||||
|
auth.setEmail(old);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlayerCache.getInstance().updatePlayer(auth);
|
||||||
|
if (oldEmail == null) {
|
||||||
|
m.send(player, "email_added");
|
||||||
|
player.sendMessage(auth.getEmail());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m.send(player, "email_changed");
|
||||||
|
player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail());
|
||||||
|
} else {
|
||||||
|
if (plugin.database.isAuthAvailable(playerName)) {
|
||||||
|
m.send(player, "login_msg");
|
||||||
|
} else {
|
||||||
|
if (Settings.emailRegistration)
|
||||||
|
m.send(player, "reg_email_msg");
|
||||||
|
else
|
||||||
|
m.send(player, "reg_msg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
|
m.send(player, "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -70,6 +70,7 @@ public class AsyncronousJoin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String ip = plugin.getIP(player);
|
final String ip = plugin.getIP(player);
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
package fr.xephi.authme.process.register;
|
package fr.xephi.authme.process.register;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
@ -13,95 +8,90 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.settings.Messages;
|
import fr.xephi.authme.settings.Messages;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class AsyncronousRegister {
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class AsyncRegister {
|
||||||
|
|
||||||
protected Player player;
|
protected Player player;
|
||||||
protected String name;
|
protected String name;
|
||||||
protected String password;
|
protected String password;
|
||||||
protected String email = "";
|
protected String email = "";
|
||||||
protected boolean allowRegister;
|
|
||||||
private AuthMe plugin;
|
private AuthMe plugin;
|
||||||
private DataSource database;
|
private DataSource database;
|
||||||
private Messages m = Messages.getInstance();
|
private Messages m = Messages.getInstance();
|
||||||
|
|
||||||
public AsyncronousRegister(Player player, String password, String email,
|
public AsyncRegister(Player player, String password, String email,
|
||||||
AuthMe plugin, DataSource data) {
|
AuthMe plugin, DataSource data) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
name = player.getName().toLowerCase();
|
name = player.getName().toLowerCase();
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = data;
|
this.database = data;
|
||||||
this.allowRegister = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getIp() {
|
protected String getIp() {
|
||||||
return plugin.getIP(player);
|
return plugin.getIP(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void preRegister() {
|
protected boolean preRegisterCheck() throws Exception {
|
||||||
String lowpass = password.toLowerCase();
|
String lowpass = password.toLowerCase();
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
m.send(player, "logged_in");
|
m.send(player, "logged_in");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (!Settings.isRegistrationEnabled) {
|
||||||
|
|
||||||
else if (!Settings.isRegistrationEnabled) {
|
|
||||||
m.send(player, "reg_disabled");
|
m.send(player, "reg_disabled");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (lowpass.contains("delete") || lowpass.contains("where") || lowpass.contains("insert") || lowpass.contains("modify") || lowpass.contains("from") || lowpass.contains("select") || lowpass.contains(";") || lowpass.contains("null") || !lowpass.matches(Settings.getPassRegex)) {
|
||||||
|
|
||||||
else if (lowpass.contains("delete") || lowpass.contains("where") || lowpass.contains("insert") || lowpass.contains("modify") || lowpass.contains("from") || lowpass.contains("select") || lowpass.contains(";") || lowpass.contains("null") || !lowpass.matches(Settings.getPassRegex)) {
|
|
||||||
m.send(player, "password_error");
|
m.send(player, "password_error");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (lowpass.equalsIgnoreCase(player.getName())) {
|
||||||
|
|
||||||
else if (lowpass.equalsIgnoreCase(player.getName())) {
|
|
||||||
m.send(player, "password_error_nick");
|
m.send(player, "password_error_nick");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (password.length() < Settings.getPasswordMinLen || password.length() > Settings.passwordMaxLength) {
|
||||||
|
|
||||||
else if (password.length() < Settings.getPasswordMinLen || password.length() > Settings.passwordMaxLength) {
|
|
||||||
m.send(player, "pass_len");
|
m.send(player, "pass_len");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(password.toLowerCase())) {
|
||||||
|
|
||||||
else if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(password.toLowerCase())) {
|
|
||||||
m.send(player, "password_error_unsafe");
|
m.send(player, "password_error_unsafe");
|
||||||
allowRegister = false;
|
return false;
|
||||||
} else if (database.isAuthAvailable(name)) {
|
} else if (database.isAuthAvailable(name)) {
|
||||||
m.send(player, "user_regged");
|
m.send(player, "user_regged");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
} else if (Settings.getmaxRegPerIp > 0) {
|
||||||
|
|
||||||
else if (Settings.getmaxRegPerIp > 0) {
|
|
||||||
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp && !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("localhost")) {
|
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp && !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("localhost")) {
|
||||||
m.send(player, "max_reg");
|
m.send(player, "max_reg");
|
||||||
allowRegister = false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
preRegister();
|
try {
|
||||||
if (!allowRegister)
|
if (!preRegisterCheck())
|
||||||
return;
|
return;
|
||||||
if (!email.isEmpty() && !email.equals("")) {
|
if (!email.isEmpty() && !email.equals("")) {
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
if (Settings.getmaxRegPerEmail > 0) {
|
||||||
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
||||||
m.send(player, "max_reg");
|
m.send(player, "max_reg");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
emailRegister();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
emailRegister();
|
passwordRegister();
|
||||||
return;
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
ConsoleLogger.writeStackTrace(e);
|
||||||
|
m.send(player, "error");
|
||||||
}
|
}
|
||||||
passwordRegister();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void emailRegister() {
|
protected void emailRegister() throws Exception {
|
||||||
if (Settings.getmaxRegPerEmail > 0) {
|
if (Settings.getmaxRegPerEmail > 0) {
|
||||||
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
if (!plugin.authmePermissible(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
||||||
m.send(player, "max_reg");
|
m.send(player, "max_reg");
|
||||||
@ -109,14 +99,8 @@ public class AsyncronousRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerAuth auth;
|
PlayerAuth auth;
|
||||||
try {
|
final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||||
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());
|
||||||
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());
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
ConsoleLogger.showError(e.getMessage());
|
|
||||||
m.send(player, "error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (PasswordSecurity.userSalt.containsKey(name)) {
|
if (PasswordSecurity.userSalt.containsKey(name)) {
|
||||||
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
||||||
}
|
}
|
||||||
@ -124,8 +108,9 @@ public class AsyncronousRegister {
|
|||||||
database.updateEmail(auth);
|
database.updateEmail(auth);
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
plugin.mail.main(auth, password);
|
plugin.mail.main(auth, password);
|
||||||
ProcessSyncronousEmailRegister syncronous = new ProcessSyncronousEmailRegister(player, plugin);
|
ProcessSyncEmailRegister syncronous = new ProcessSyncEmailRegister(player, plugin);
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void passwordRegister() {
|
protected void passwordRegister() {
|
@ -14,14 +14,14 @@ import fr.xephi.authme.task.MessageTask;
|
|||||||
import fr.xephi.authme.task.TimeoutTask;
|
import fr.xephi.authme.task.TimeoutTask;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
|
||||||
public class ProcessSyncronousEmailRegister implements Runnable {
|
public class ProcessSyncEmailRegister implements Runnable {
|
||||||
|
|
||||||
protected Player player;
|
protected Player player;
|
||||||
protected String name;
|
protected String name;
|
||||||
private AuthMe plugin;
|
private AuthMe plugin;
|
||||||
private Messages m = Messages.getInstance();
|
private Messages m = Messages.getInstance();
|
||||||
|
|
||||||
public ProcessSyncronousEmailRegister(Player player, AuthMe plugin) {
|
public ProcessSyncEmailRegister(Player player, AuthMe plugin) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.name = player.getName().toLowerCase();
|
this.name = player.getName().toLowerCase();
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
Loading…
Reference in New Issue
Block a user