mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-04 09:40:05 +01:00
Merge branch 'Xephi-master'
This commit is contained in:
commit
04d222126f
@ -50,8 +50,8 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmnd, String label,
|
public boolean onCommand(final CommandSender sender, Command cmnd,
|
||||||
String[] args) {
|
String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage("Usage:");
|
sender.sendMessage("Usage:");
|
||||||
sender.sendMessage("/authme reload - Reload the config");
|
sender.sendMessage("/authme reload - Reload the config");
|
||||||
@ -468,9 +468,19 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
final String name = args[1].toLowerCase();
|
||||||
|
final String raw = args[2];
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String hash;
|
||||||
try {
|
try {
|
||||||
String name = args[1].toLowerCase();
|
hash = PasswordSecurity.getHash(Settings.getPasswordHash, raw, name);
|
||||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[2], name);
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
PlayerAuth auth = null;
|
PlayerAuth auth = null;
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
auth = PlayerCache.getInstance().getAuth(name);
|
auth = PlayerCache.getInstance().getAuth(name);
|
||||||
@ -479,7 +489,7 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
m.send(sender, "unknown_user");
|
m.send(sender, "unknown_user");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
auth.setHash(hash);
|
auth.setHash(hash);
|
||||||
if (PasswordSecurity.userSalt.containsKey(name)) {
|
if (PasswordSecurity.userSalt.containsKey(name)) {
|
||||||
@ -488,14 +498,13 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
if (!plugin.database.updatePassword(auth)) {
|
if (!plugin.database.updatePassword(auth)) {
|
||||||
m.send(sender, "error");
|
m.send(sender, "error");
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
sender.sendMessage("pwd_changed");
|
sender.sendMessage("pwd_changed");
|
||||||
ConsoleLogger.info(args[1] + "'s password changed");
|
ConsoleLogger.info(name + "'s password changed");
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
m.send(sender, "error");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("unregister") || args[0].equalsIgnoreCase("unreg") || args[0].equalsIgnoreCase("del")) {
|
} else if (args[0].equalsIgnoreCase("unregister") || args[0].equalsIgnoreCase("unreg") || args[0].equalsIgnoreCase("del")) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
|
@ -13,6 +13,14 @@ public class CustomEvent extends Event implements Cancellable {
|
|||||||
private boolean isCancelled;
|
private boolean isCancelled;
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public CustomEvent() {
|
||||||
|
super(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomEvent(boolean b) {
|
||||||
|
super(b);
|
||||||
|
}
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ public class FirstSpawnTeleportEvent extends CustomEvent {
|
|||||||
private Location from;
|
private Location from;
|
||||||
|
|
||||||
public FirstSpawnTeleportEvent(Player player, Location from, Location to) {
|
public FirstSpawnTeleportEvent(Player player, Location from, Location to) {
|
||||||
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.from = from;
|
this.from = from;
|
||||||
this.to = to;
|
this.to = to;
|
||||||
|
@ -22,6 +22,7 @@ public class PasswordEncryptionEvent extends Event {
|
|||||||
private String playerName = "";
|
private String playerName = "";
|
||||||
|
|
||||||
public PasswordEncryptionEvent(EncryptionMethod method, String playerName) {
|
public PasswordEncryptionEvent(EncryptionMethod method, String playerName) {
|
||||||
|
super(true);
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ public class ProtectInventoryEvent extends CustomEvent {
|
|||||||
|
|
||||||
public ProtectInventoryEvent(Player player, ItemStack[] storedinventory,
|
public ProtectInventoryEvent(Player player, ItemStack[] storedinventory,
|
||||||
ItemStack[] storedarmor) {
|
ItemStack[] storedarmor) {
|
||||||
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.storedinventory = storedinventory;
|
this.storedinventory = storedinventory;
|
||||||
this.storedarmor = storedarmor;
|
this.storedarmor = storedarmor;
|
||||||
|
@ -13,6 +13,7 @@ public class ResetInventoryEvent extends CustomEvent {
|
|||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
public ResetInventoryEvent(Player player) {
|
public ResetInventoryEvent(Player player) {
|
||||||
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,14 @@ public class RestoreInventoryEvent extends CustomEvent {
|
|||||||
this.armor = armor;
|
this.armor = armor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RestoreInventoryEvent(Player player, ItemStack[] inventory,
|
||||||
|
ItemStack[] armor, boolean b) {
|
||||||
|
super(b);
|
||||||
|
this.player = player;
|
||||||
|
this.inventory = inventory;
|
||||||
|
this.armor = armor;
|
||||||
|
}
|
||||||
|
|
||||||
public ItemStack[] getInventory() {
|
public ItemStack[] getInventory() {
|
||||||
return this.inventory;
|
return this.inventory;
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,7 @@ public class StoreInventoryEvent extends CustomEvent {
|
|||||||
try {
|
try {
|
||||||
this.inventory = fileCache.readCache(player).getInventory();
|
this.inventory = fileCache.readCache(player).getInventory();
|
||||||
this.armor = fileCache.readCache(player).getArmour();
|
this.armor = fileCache.readCache(player).getArmour();
|
||||||
} catch (Exception e)
|
} catch (Exception e) {
|
||||||
{
|
|
||||||
this.inventory = player.getInventory().getContents();
|
this.inventory = player.getInventory().getContents();
|
||||||
this.armor = player.getInventory().getArmorContents();
|
this.armor = player.getInventory().getArmorContents();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
@ -176,10 +177,6 @@ public class AsyncronousJoin {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
||||||
ProtectInventoryEvent ev = new ProtectInventoryEvent(player, limbo.getInventory(), limbo.getArmour());
|
ProtectInventoryEvent ev = new ProtectInventoryEvent(player, limbo.getInventory(), limbo.getArmour());
|
||||||
@ -188,14 +185,20 @@ public class AsyncronousJoin {
|
|||||||
if (!Settings.noConsoleSpam)
|
if (!Settings.noConsoleSpam)
|
||||||
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
|
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
|
||||||
} else {
|
} else {
|
||||||
plugin.api.setPlayerInventory(player, ev.getEmptyInventory(), ev.getEmptyArmor());
|
final ItemStack[] inv = ev.getEmptyArmor();
|
||||||
}
|
final ItemStack[] armor = ev.getEmptyArmor();
|
||||||
} catch (NullPointerException ex) {
|
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
plugin.api.setPlayerInventory(player, inv, armor);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
String[] msg;
|
String[] msg;
|
||||||
if (Settings.emailRegistration) {
|
if (Settings.emailRegistration) {
|
||||||
msg = database.isAuthAvailable(name) ? m.send("login_msg") : m.send("reg_email_msg");
|
msg = database.isAuthAvailable(name) ? m.send("login_msg") : m.send("reg_email_msg");
|
||||||
@ -262,21 +265,21 @@ public class AsyncronousJoin {
|
|||||||
else {
|
else {
|
||||||
if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null)
|
if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null)
|
||||||
return false;
|
return false;
|
||||||
final Location loc = Spawn.getInstance().getFirstSpawn();
|
FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), Spawn.getInstance().getFirstSpawn());
|
||||||
|
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||||
|
if (!tpEvent.isCancelled()) {
|
||||||
|
if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
|
||||||
|
final Location fLoc = tpEvent.getTo();
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), loc);
|
player.teleport(fLoc);
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
|
||||||
if (!tpEvent.isCancelled()) {
|
|
||||||
if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
|
|
||||||
player.teleport(tpEvent.getTo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,13 +56,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
|||||||
player.setFlying(true);
|
player.setFlying(true);
|
||||||
}
|
}
|
||||||
// Player is now logout... Time to fire event !
|
// Player is now logout... Time to fire event !
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player));
|
Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player));
|
||||||
}
|
|
||||||
});
|
|
||||||
m.send(player, "logout");
|
m.send(player, "logout");
|
||||||
ConsoleLogger.info(player.getDisplayName() + " logged out");
|
ConsoleLogger.info(player.getDisplayName() + " logged out");
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||||
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
|
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
@ -97,6 +98,15 @@ public class AsyncronousQuit {
|
|||||||
}
|
}
|
||||||
AuthMePlayerListener.gameMode.remove(name);
|
AuthMePlayerListener.gameMode.remove(name);
|
||||||
final Player p = player;
|
final Player p = player;
|
||||||
|
RestoreInventoryEvent ev = new RestoreInventoryEvent(player, inv, armor, true);
|
||||||
|
Bukkit.getPluginManager().callEvent(ev);
|
||||||
|
if (ev.isCancelled()) {
|
||||||
|
inv = null;
|
||||||
|
armor = null;
|
||||||
|
} else {
|
||||||
|
inv = ev.getInventory();
|
||||||
|
armor = ev.getArmor();
|
||||||
|
}
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, p, inv, armor, isOp, isFlying, needToChange));
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, p, inv, armor, isOp, isFlying, needToChange));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
public class ProcessSyncronousPlayerQuit implements Runnable {
|
public class ProcessSyncronousPlayerQuit implements Runnable {
|
||||||
@ -32,13 +31,8 @@ public class ProcessSyncronousPlayerQuit implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (inv != null && armor != null) {
|
if (inv != null && armor != null)
|
||||||
RestoreInventoryEvent ev = new RestoreInventoryEvent(player, inv, armor);
|
plugin.api.setPlayerInventory(player, inv, armor);
|
||||||
player.getServer().getPluginManager().callEvent(ev);
|
|
||||||
if (!ev.isCancelled()) {
|
|
||||||
plugin.api.setPlayerInventory(player, ev.getInventory(), ev.getArmor());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (needToChange) {
|
if (needToChange) {
|
||||||
player.setOp(isOp);
|
player.setOp(isOp);
|
||||||
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
|
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
|
||||||
|
@ -29,6 +29,7 @@ public enum HashAlgorithm {
|
|||||||
ROYALAUTH(fr.xephi.authme.security.crypts.ROYALAUTH.class),
|
ROYALAUTH(fr.xephi.authme.security.crypts.ROYALAUTH.class),
|
||||||
CRAZYCRYPT1(fr.xephi.authme.security.crypts.CRAZYCRYPT1.class),
|
CRAZYCRYPT1(fr.xephi.authme.security.crypts.CRAZYCRYPT1.class),
|
||||||
BCRYPT2Y(fr.xephi.authme.security.crypts.BCRYPT2Y.class),
|
BCRYPT2Y(fr.xephi.authme.security.crypts.BCRYPT2Y.class),
|
||||||
|
SALTEDSHA512(fr.xephi.authme.security.crypts.SALTEDSHA512.class),
|
||||||
CUSTOM(Null.class);
|
CUSTOM(Null.class);
|
||||||
|
|
||||||
Class<?> classe;
|
Class<?> classe;
|
||||||
|
@ -96,7 +96,12 @@ public class PasswordSecurity {
|
|||||||
userSalt.put(playerName, salt);
|
userSalt.put(playerName, salt);
|
||||||
break;
|
break;
|
||||||
case BCRYPT2Y:
|
case BCRYPT2Y:
|
||||||
salt = createSalt(22);
|
salt = createSalt(16);
|
||||||
|
userSalt.put(playerName, salt);
|
||||||
|
break;
|
||||||
|
case SALTEDSHA512:
|
||||||
|
salt = createSalt(32);
|
||||||
|
userSalt.put(playerName, salt);
|
||||||
break;
|
break;
|
||||||
case MD5:
|
case MD5:
|
||||||
case SHA1:
|
case SHA1:
|
||||||
@ -165,7 +170,7 @@ public class PasswordSecurity {
|
|||||||
PlayerAuth nAuth = AuthMe.getInstance().database.getAuth(playerName);
|
PlayerAuth nAuth = AuthMe.getInstance().database.getAuth(playerName);
|
||||||
if (nAuth != null) {
|
if (nAuth != null) {
|
||||||
nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName));
|
nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName));
|
||||||
nAuth.setSalt(userSalt.get(playerName));
|
nAuth.setSalt(userSalt.containsKey(playerName) ? userSalt.get(playerName) : "");
|
||||||
AuthMe.getInstance().database.updatePassword(nAuth);
|
AuthMe.getInstance().database.updatePassword(nAuth);
|
||||||
AuthMe.getInstance().database.updateSalt(nAuth);
|
AuthMe.getInstance().database.updateSalt(nAuth);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package fr.xephi.authme.security.crypts;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
|
||||||
|
public class SALTEDSHA512 implements EncryptionMethod {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHash(String password, String salt, String name)
|
||||||
|
throws NoSuchAlgorithmException {
|
||||||
|
return getSHA512(password + salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean comparePassword(String hash, String password,
|
||||||
|
String playerName) throws NoSuchAlgorithmException {
|
||||||
|
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
|
||||||
|
return hash.equals(getHash(password, salt, ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSHA512(String message)
|
||||||
|
throws NoSuchAlgorithmException {
|
||||||
|
MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
|
||||||
|
sha512.reset();
|
||||||
|
sha512.update(message.getBytes());
|
||||||
|
byte[] digest = sha512.digest();
|
||||||
|
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user