From 57a22c101bda7d58c8b1d6a4f28f5b4d3e3f8883 Mon Sep 17 00:00:00 2001 From: Xephi Date: Wed, 23 Dec 2015 12:48:00 +0100 Subject: [PATCH] Add changepassword to Bungee Hook --- .../xephi/authme/hooks/BungeeCordMessage.java | 10 ++++++++- .../xephi/authme/task/ChangePasswordTask.java | 22 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/hooks/BungeeCordMessage.java b/src/main/java/fr/xephi/authme/hooks/BungeeCordMessage.java index 5b19348b8..11240003d 100644 --- a/src/main/java/fr/xephi/authme/hooks/BungeeCordMessage.java +++ b/src/main/java/fr/xephi/authme/hooks/BungeeCordMessage.java @@ -47,7 +47,7 @@ public class BungeeCordMessage implements PluginMessageListener { } if (subChannel.equalsIgnoreCase("AuthMe")) { String str = in.readUTF(); - String[] args = str.split(";"); + final String[] args = str.split(";"); final String act = args[0]; final String name = args[1]; plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { @@ -71,6 +71,14 @@ public class BungeeCordMessage implements PluginMessageListener { ConsoleLogger.info("Player " + auth.getNickname() + " has registered out from one of your server!"); } + else if ("changepassword".equals(act)) { + final String password = args[2]; + auth.setHash(password); + if (args.length == 4) + auth.setSalt(args[3]); + PlayerCache.getInstance().updatePlayer(auth); + plugin.database.updatePassword(auth); + } } }); diff --git a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java index 9b4dfac51..e5b54b8da 100644 --- a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java +++ b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java @@ -10,6 +10,9 @@ import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.entity.Player; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; + import java.security.NoSuchAlgorithmException; /** @@ -40,7 +43,7 @@ public class ChangePasswordTask implements Runnable { public void run() { Messages m = plugin.getMessages(); try { - String name = player.getName().toLowerCase(); + final String name = player.getName().toLowerCase(); String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, newPassword, name); PlayerAuth auth = PlayerCache.getInstance().getAuth(name); if (PasswordSecurity.comparePasswordWithHash(oldPassword, auth.getHash(), player.getName())) { @@ -58,6 +61,23 @@ public class ChangePasswordTask implements Runnable { PlayerCache.getInstance().updatePlayer(auth); m.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS); ConsoleLogger.info(player.getName() + " changed his password"); + if (Settings.bungee) + { + final String hash = auth.getHash(); + final String salt = auth.getSalt(); + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ + + @Override + public void run() { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Forward"); + out.writeUTF("ALL"); + out.writeUTF("AuthMe"); + out.writeUTF("changepassword;" + name + ";" + hash + ";" + salt); + player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); + } + }); + } } else { m.send(player, MessageKey.WRONG_PASSWORD); }