mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-26 00:31:50 +01:00
run admin register task async.
This commit is contained in:
parent
e11a1e9b09
commit
f60604c86c
@ -1,30 +1,6 @@
|
|||||||
package fr.xephi.authme.commands;
|
package fr.xephi.authme.commands;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
import org.bukkit.potion.PotionEffectType;
|
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import com.zaxxer.hikari.pool.PoolInitializationException;
|
import com.zaxxer.hikari.pool.PoolInitializationException;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.Utils;
|
import fr.xephi.authme.Utils;
|
||||||
@ -39,6 +15,28 @@ import fr.xephi.authme.settings.Settings;
|
|||||||
import fr.xephi.authme.settings.Spawn;
|
import fr.xephi.authme.settings.Spawn;
|
||||||
import fr.xephi.authme.task.MessageTask;
|
import fr.xephi.authme.task.MessageTask;
|
||||||
import fr.xephi.authme.task.TimeoutTask;
|
import fr.xephi.authme.task.TimeoutTask;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class AdminCommand implements CommandExecutor {
|
public class AdminCommand implements CommandExecutor {
|
||||||
|
|
||||||
@ -289,13 +287,13 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else
|
} else if (args[0].equalsIgnoreCase("register") || args[0].equalsIgnoreCase("reg")) {
|
||||||
if (args[0].equalsIgnoreCase("register") || args[0].equalsIgnoreCase("reg")) {
|
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
sender.sendMessage("Usage: /authme register <playername> <password>");
|
sender.sendMessage("Usage: /authme register <playername> <password>");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String lowpass = args[2].toLowerCase();
|
final String name = args[1].toLowerCase();
|
||||||
|
final String lowpass = args[2].toLowerCase();
|
||||||
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)) {
|
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(sender, "password_error");
|
m.send(sender, "password_error");
|
||||||
return true;
|
return true;
|
||||||
@ -314,27 +312,32 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String name = args[1].toLowerCase();
|
|
||||||
if (plugin.database.isAuthAvailable(name)) {
|
if (plugin.database.isAuthAvailable(name)) {
|
||||||
m.send(sender, "user_regged");
|
m.send(sender, "user_regged");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[2], name);
|
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, lowpass, name);
|
||||||
PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0L, "your@email.com");
|
PlayerAuth auth = new PlayerAuth(name, hash, "192.168.0.1", 0L, "your@email.com");
|
||||||
if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null)
|
if (PasswordSecurity.userSalt.containsKey(name) && PasswordSecurity.userSalt.get(name) != null)
|
||||||
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
||||||
else auth.setSalt("");
|
else auth.setSalt("");
|
||||||
if (!plugin.database.saveAuth(auth)) {
|
if (!plugin.database.saveAuth(auth)) {
|
||||||
m.send(sender, "error");
|
m.send(sender, "error");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
m.send(sender, "registered");
|
m.send(sender, "registered");
|
||||||
ConsoleLogger.info(args[1] + " registered");
|
ConsoleLogger.info(name + " registered");
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
m.send(sender, "error");
|
m.send(sender, "error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("getemail")) {
|
} else if (args[0].equalsIgnoreCase("getemail")) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
@ -443,8 +446,7 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else if (args[0].equalsIgnoreCase("changepassword") || args[0].equalsIgnoreCase("cp")) {
|
||||||
if (args[0].equalsIgnoreCase("changepassword") || args[0].equalsIgnoreCase("cp")) {
|
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
sender.sendMessage("Usage: /authme changepassword <playername> <newpassword>");
|
sender.sendMessage("Usage: /authme changepassword <playername> <newpassword>");
|
||||||
return true;
|
return true;
|
||||||
@ -555,8 +557,7 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
m.send(sender, "unregistered");
|
m.send(sender, "unregistered");
|
||||||
ConsoleLogger.info(args[1] + " unregistered");
|
ConsoleLogger.info(args[1] + " unregistered");
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else if (args[0].equalsIgnoreCase("purgelastpos") || args[0].equalsIgnoreCase("resetposition")) {
|
||||||
if (args[0].equalsIgnoreCase("purgelastpos") || args[0].equalsIgnoreCase("resetposition")) {
|
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
sender.sendMessage("Usage: /authme purgelastpos <playername>");
|
sender.sendMessage("Usage: /authme purgelastpos <playername>");
|
||||||
return true;
|
return true;
|
||||||
|
@ -112,7 +112,7 @@ public class AsyncronousRegister {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerAuth auth = null;
|
PlayerAuth auth;
|
||||||
try {
|
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());
|
||||||
@ -130,12 +130,11 @@ public class AsyncronousRegister {
|
|||||||
plugin.mail.main(auth, password);
|
plugin.mail.main(auth, password);
|
||||||
ProcessSyncronousEmailRegister syncronous = new ProcessSyncronousEmailRegister(player, plugin);
|
ProcessSyncronousEmailRegister syncronous = new ProcessSyncronousEmailRegister(player, plugin);
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void passwordRegister() {
|
protected void passwordRegister() {
|
||||||
PlayerAuth auth = null;
|
PlayerAuth auth;
|
||||||
String hash = "";
|
String hash;
|
||||||
try {
|
try {
|
||||||
hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
@ -159,6 +158,5 @@ public class AsyncronousRegister {
|
|||||||
plugin.otherAccounts.addPlayer(player.getUniqueId());
|
plugin.otherAccounts.addPlayer(player.getUniqueId());
|
||||||
ProcessSyncronousPasswordRegister syncronous = new ProcessSyncronousPasswordRegister(player, plugin);
|
ProcessSyncronousPasswordRegister syncronous = new ProcessSyncronousPasswordRegister(player, plugin);
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, syncronous);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import fr.xephi.authme.settings.Settings;
|
|||||||
public class PasswordSecurity {
|
public class PasswordSecurity {
|
||||||
|
|
||||||
private static SecureRandom rnd = new SecureRandom();
|
private static SecureRandom rnd = new SecureRandom();
|
||||||
public static HashMap<String, String> userSalt = new HashMap<String, String>();
|
public static HashMap<String, String> userSalt = new HashMap<>();
|
||||||
|
|
||||||
public static String createSalt(int length)
|
public static String createSalt(int length)
|
||||||
throws NoSuchAlgorithmException {
|
throws NoSuchAlgorithmException {
|
||||||
@ -37,9 +37,7 @@ public class PasswordSecurity {
|
|||||||
if (alg != HashAlgorithm.CUSTOM)
|
if (alg != HashAlgorithm.CUSTOM)
|
||||||
method = (EncryptionMethod) alg.getclasse().newInstance();
|
method = (EncryptionMethod) alg.getclasse().newInstance();
|
||||||
else method = null;
|
else method = null;
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
|
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
|
||||||
}
|
}
|
||||||
String salt = "";
|
String salt = "";
|
||||||
@ -135,9 +133,7 @@ public class PasswordSecurity {
|
|||||||
if (algo != HashAlgorithm.CUSTOM)
|
if (algo != HashAlgorithm.CUSTOM)
|
||||||
method = (EncryptionMethod) algo.getclasse().newInstance();
|
method = (EncryptionMethod) algo.getclasse().newInstance();
|
||||||
else method = null;
|
else method = null;
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
|
throw new NoSuchAlgorithmException("Problem with this hash algorithm");
|
||||||
}
|
}
|
||||||
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
|
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
|
||||||
|
@ -23,14 +23,13 @@ public class Messages extends CustomConfiguration {
|
|||||||
/**
|
/**
|
||||||
* Loads a file from the plugin jar and sets as default
|
* Loads a file from the plugin jar and sets as default
|
||||||
*
|
*
|
||||||
* @param filename
|
* @param file
|
||||||
* The filename to open
|
* The filename to open
|
||||||
*/
|
*/
|
||||||
public final void loadDefaults(File file) {
|
public final void loadDefaults(File file) {
|
||||||
if(file.isFile()){
|
if(file.isFile()){
|
||||||
setDefaults(YamlConfiguration.loadConfiguration(file));
|
setDefaults(YamlConfiguration.loadConfiguration(file));
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,7 +100,7 @@ public class Messages extends CustomConfiguration {
|
|||||||
for (a = 0; a < i; a++) {
|
for (a = 0; a < i; a++) {
|
||||||
loc[a] = ((String) this.get(msg)).split("&n")[a].replace("&", "\u00a7");
|
loc[a] = ((String) this.get(msg)).split("&n")[a].replace("&", "\u00a7");
|
||||||
}
|
}
|
||||||
if (loc == null || loc.length == 0) {
|
if (loc.length == 0) {
|
||||||
loc[0] = "Error with " + msg + " translation; Please contact the admin for verify or update translation files";
|
loc[0] = "Error with " + msg + " translation; Please contact the admin for verify or update translation files";
|
||||||
}
|
}
|
||||||
return loc;
|
return loc;
|
||||||
|
Loading…
Reference in New Issue
Block a user