[DEV] [NEED TEST] BungeeCord

Add a way to send player login on other AuthMe instance through
BungeeCord plugin channel
This commit is contained in:
Xephi 2015-12-10 18:31:46 +01:00
parent 9c86fbd8bf
commit d01713a2f5
3 changed files with 69 additions and 1 deletions

View File

@ -3,6 +3,9 @@ package fr.xephi.authme.hooks;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
@ -43,6 +46,30 @@ public class BungeeCordMessage implements PluginMessageListener {
// Put the IP (only the ip not the port) in the hashMap
plugin.realIp.put(player.getName().toLowerCase(), ip);
}
if (subChannel.equals("Forward"))
{
String str = in.readUTF();
if (!str.startsWith("AuthMe"))
return;
String[] args = str.split(";");
try {
String name = args[2];
PlayerAuth auth = plugin.database.getAuth(name);
if (auth == null)
return;
if (args[1].equalsIgnoreCase("login"))
{
PlayerCache.getInstance().addPlayer(auth);
plugin.database.setLogged(name);
}
else if (args[1].equalsIgnoreCase("logout"))
{
PlayerCache.getInstance().removePlayer(name);
plugin.database.setUnlogged(name);
}
} catch (Exception e)
{}
}
}
}

View File

@ -14,6 +14,10 @@ import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -113,6 +117,21 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
}
}
protected void sendBungeeMessage() {
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try {
String str = "AuthMe;login;" + name;
out.writeUTF("Forward");
out.writeUTF("ALL");
out.writeUTF("AuthMe");
out.writeShort(str.length());
out.writeUTF(str);
player.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
} catch (Exception e)
{}
}
/**
* Method run.
*
@ -186,7 +205,8 @@ public class ProcessSyncronousPlayerLogin implements Runnable {
// The Login event now fires (as intended) after everything is processed
Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true));
player.saveData();
if (Settings.bungee)
sendBungeeMessage();
// Login is finish, display welcome message
if (Settings.useWelcomeMessage)
if (Settings.broadcastWelcomeMessage) {

View File

@ -9,6 +9,10 @@ import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
@ -38,6 +42,21 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
this.name = player.getName().toLowerCase();
}
protected void sendBungeeMessage() {
ByteArrayOutputStream b = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(b);
try {
String str = "AuthMe;login;" + name;
out.writeUTF("Forward");
out.writeUTF("ALL");
out.writeUTF("AuthMe");
out.writeShort(str.length());
out.writeUTF(str);
player.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
} catch (Exception e)
{}
}
/**
* Method run.
*
@ -76,6 +95,8 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
}
// Player is now logout... Time to fire event !
Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player));
if (Settings.bungee)
sendBungeeMessage();
m.send(player, MessageKey.LOGOUT_SUCCESS);
ConsoleLogger.info(player.getName() + " logged out");
}