From f8c10d6890121abe4b982b5a6f95a149d0dc3e13 Mon Sep 17 00:00:00 2001 From: games647 Date: Sat, 14 Nov 2015 20:03:24 +0100 Subject: [PATCH] Merge the Bukkit and BungeeCord version together to a universal plugin --- .gitignore | 2 +- CHANGELOG.md | 4 + README.md | 11 +- {lib => bukkit/lib}/CrazyCore v10.7.7.jar | Bin {lib => bukkit/lib}/CrazyLogin v7.23.2.jar | Bin {lib => bukkit/lib}/LoginSecurity v2.0.10.jar | Bin bukkit/pom.xml | 116 ++++++++++++++++ .../fastlogin/bukkit}/EncryptionUtil.java | 2 +- .../fastlogin/bukkit/FastLoginBukkit.java | 24 ++-- .../fastlogin/bukkit}/PlayerSession.java | 2 +- .../fastlogin/bukkit}/PremiumCommand.java | 16 ++- .../fastlogin/bukkit}/hooks/AuthMeHook.java | 2 +- .../fastlogin/bukkit}/hooks/AuthPlugin.java | 2 +- .../bukkit}/hooks/CrazyLoginHook.java | 2 +- .../bukkit}/hooks/LoginSecurityHook.java | 2 +- .../fastlogin/bukkit}/hooks/xAuthHook.java | 2 +- .../bukkit/listener/BukkitJoinListener.java | 66 +++++++++ .../bukkit}/listener/BungeeCordListener.java | 46 ++++--- .../listener/EncryptionPacketListener.java | 12 +- .../listener/HandshakePacketListener.java | 8 +- .../bukkit}/listener/StartPacketListener.java | 10 +- {src => bukkit/src}/main/resources/plugin.yml | 8 +- bungee/pom.xml | 83 ++---------- .../bungee/FastLoginBungee.java} | 8 +- .../bungee}/PlayerConnectionListener.java | 26 +++- .../fastloginbungee/PremiumCommand.java | 38 ------ bungee/src/main/resources/bungee.yml | 4 +- pom.xml | 127 ++---------------- .../listener/BukkitJoinListener.java | 53 -------- universal/pom.xml | 55 ++++++++ 30 files changed, 377 insertions(+), 354 deletions(-) rename {lib => bukkit/lib}/CrazyCore v10.7.7.jar (100%) rename {lib => bukkit/lib}/CrazyLogin v7.23.2.jar (100%) rename {lib => bukkit/lib}/LoginSecurity v2.0.10.jar (100%) create mode 100644 bukkit/pom.xml rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/EncryptionUtil.java (99%) rename src/main/java/com/github/games647/fastlogin/FastLogin.java => bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java (90%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/PlayerSession.java (97%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/PremiumCommand.java (68%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/hooks/AuthMeHook.java (88%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/hooks/AuthPlugin.java (84%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/hooks/CrazyLoginHook.java (95%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/hooks/LoginSecurityHook.java (95%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/hooks/xAuthHook.java (95%) create mode 100644 bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/listener/BungeeCordListener.java (63%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/listener/EncryptionPacketListener.java (96%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/listener/HandshakePacketListener.java (90%) rename {src/main/java/com/github/games647/fastlogin => bukkit/src/main/java/com/github/games647/fastlogin/bukkit}/listener/StartPacketListener.java (95%) rename {src => bukkit/src}/main/resources/plugin.yml (82%) rename bungee/src/main/java/com/github/games647/{fastloginbungee/FastLogin.java => fastlogin/bungee/FastLoginBungee.java} (75%) rename bungee/src/main/java/com/github/games647/{fastloginbungee => fastlogin/bungee}/PlayerConnectionListener.java (77%) delete mode 100644 bungee/src/main/java/com/github/games647/fastloginbungee/PremiumCommand.java delete mode 100644 src/main/java/com/github/games647/fastlogin/listener/BukkitJoinListener.java create mode 100644 universal/pom.xml diff --git a/.gitignore b/.gitignore index 38cd6398..48d89aac 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,4 @@ hs_err_pid* gradle-app.setting # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar +!gradle-wrapper.jar \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 93f1d1f5..cbbb83cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +######0.3.1 + +* Improved BungeeCord security + #####0.3 * Added BungeeCord support diff --git a/README.md b/README.md index 04fe9e5f..a8cf6d58 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Build Status](https://travis-ci.org/games647/FastLogin.svg?branch=master)](https://travis-ci.org/games647/FastLogin) Checks if a minecraft player has a paid account (premium). If so, they can skip offline authentication (auth plugins). -So they don't need to enter passwords. This is also called auto login. +So they don't need to enter passwords. This is also called auto login (auto-login). ###Features: * Detect paid accounts from others @@ -12,8 +12,9 @@ So they don't need to enter passwords. This is also called auto login. * Experimental Cauldron support * BungeeCord support * No client modifications needed -* Good performance by async non blocking operations +* Good performance by using async non blocking operations * Free +* Open source *** @@ -118,8 +119,10 @@ by buying the username. ####Does the plugin have BungeeCord support? Yes it has. Just activate ipForward in your BungeeCord config and place the plugin in the plugins folder of -Bukkit/Spigot and BungeeCord. This plugin will automatically detect if BungeeCord is running and so handle checks -there. +Bukkit/Spigot and BungeeCord. Then you have fill your BungeeCord Id (from the Stats-Option in the BungeeCord config) +into the whitelist file of your Bukkit/Spigot server. For security reasons, don't post this Id on Forums. + +This plugin will automatically detect if BungeeCord is running and handle premium checks on BungeeCord. ####Could premium players have a premium UUID and Skin? Something like that is possible, but is not yet implemented. diff --git a/lib/CrazyCore v10.7.7.jar b/bukkit/lib/CrazyCore v10.7.7.jar similarity index 100% rename from lib/CrazyCore v10.7.7.jar rename to bukkit/lib/CrazyCore v10.7.7.jar diff --git a/lib/CrazyLogin v7.23.2.jar b/bukkit/lib/CrazyLogin v7.23.2.jar similarity index 100% rename from lib/CrazyLogin v7.23.2.jar rename to bukkit/lib/CrazyLogin v7.23.2.jar diff --git a/lib/LoginSecurity v2.0.10.jar b/bukkit/lib/LoginSecurity v2.0.10.jar similarity index 100% rename from lib/LoginSecurity v2.0.10.jar rename to bukkit/lib/LoginSecurity v2.0.10.jar diff --git a/bukkit/pom.xml b/bukkit/pom.xml new file mode 100644 index 00000000..f58ebcfc --- /dev/null +++ b/bukkit/pom.xml @@ -0,0 +1,116 @@ + + 4.0.0 + + + com.github.games647 + fastlogin-parent + 0.3 + ../pom.xml + + + + fastlogin.bukkit + jar + + FastLoginBukkit + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + dmulloy2-repo + http://repo.dmulloy2.net/content/groups/public/ + + + + + xephi-repo + http://ci.xephi.fr/plugin/repository/everything/ + + + + + luricos.de-repo + http://repo.luricos.de/bukkit-plugins/ + + + + + + + org.spigotmc + spigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + + + + com.comphenix.protocol + ProtocolLib + 3.6.5-SNAPSHOT + true + + + + + fr.xephi + authme + 5.1-SNAPSHOT + true + + + + de.luricos.bukkit + xAuth + 2.6 + true + + + + net.gravitydevelopment.updater + updater + + + net.ess3 + EssentialsGroupManager + + + + + + + de.st_ddt.crazy + CrazyCore + 10.7.7 + true + system + ${project.basedir}/lib/CrazyCore v10.7.7.jar + + + + de.st_ddt.crazy + CrazyLogin + 7.23 + true + system + ${project.basedir}/lib/CrazyLogin v7.23.2.jar + + + + + me.lenis0012.ls + LoginSecurity + 2.0.10 + true + system + ${project.basedir}/lib/LoginSecurity v2.0.10.jar + + + diff --git a/src/main/java/com/github/games647/fastlogin/EncryptionUtil.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/EncryptionUtil.java similarity index 99% rename from src/main/java/com/github/games647/fastlogin/EncryptionUtil.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/EncryptionUtil.java index 8c1d7093..9df73752 100644 --- a/src/main/java/com/github/games647/fastlogin/EncryptionUtil.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/EncryptionUtil.java @@ -1,4 +1,4 @@ -package com.github.games647.fastlogin; +package com.github.games647.fastlogin.bukkit; import com.google.common.base.Charsets; diff --git a/src/main/java/com/github/games647/fastlogin/FastLogin.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java similarity index 90% rename from src/main/java/com/github/games647/fastlogin/FastLogin.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index e304a924..3e87d9b8 100644 --- a/src/main/java/com/github/games647/fastlogin/FastLogin.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -1,14 +1,14 @@ -package com.github.games647.fastlogin; +package com.github.games647.fastlogin.bukkit; +import com.github.games647.fastlogin.bukkit.listener.BukkitJoinListener; +import com.github.games647.fastlogin.bukkit.listener.StartPacketListener; +import com.github.games647.fastlogin.bukkit.listener.BungeeCordListener; +import com.github.games647.fastlogin.bukkit.listener.EncryptionPacketListener; +import com.github.games647.fastlogin.bukkit.listener.HandshakePacketListener; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.utility.SafeCacheBuilder; -import com.github.games647.fastlogin.hooks.AuthPlugin; -import com.github.games647.fastlogin.listener.BukkitJoinListener; -import com.github.games647.fastlogin.listener.BungeeCordListener; -import com.github.games647.fastlogin.listener.EncryptionPacketListener; -import com.github.games647.fastlogin.listener.HandshakePacketListener; -import com.github.games647.fastlogin.listener.StartPacketListener; +import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin; import com.google.common.cache.CacheLoader; import com.google.common.collect.MapMaker; import com.google.common.collect.Sets; @@ -29,7 +29,7 @@ import org.bukkit.plugin.java.JavaPlugin; /** * This plugin checks if a player has a paid account and if so tries to skip offline mode authentication. */ -public class FastLogin extends JavaPlugin { +public class FastLoginBukkit extends JavaPlugin { //http connection, read timeout and user agent for a connection to mojang api servers private static final int TIMEOUT = 1 * 1000; @@ -86,7 +86,8 @@ public class FastLogin extends JavaPlugin { getCommand("premium").setExecutor(new PremiumCommand(this)); //check for incoming messages from the bungeecord version of this plugin - getServer().getMessenger().registerIncomingPluginChannel(this, this.getName(), new BungeeCordListener(this)); + getServer().getMessenger().registerIncomingPluginChannel(this, getName(), new BungeeCordListener(this)); + getServer().getMessenger().registerOutgoingPluginChannel(this, getName()); } @Override @@ -95,6 +96,11 @@ public class FastLogin extends JavaPlugin { session.clear(); enabledPremium.clear(); bungeeCordUsers.clear(); + + //remove old blacklists + for (Player player : getServer().getOnlinePlayers()) { + player.removeMetadata(getName(), this); + } } /** diff --git a/src/main/java/com/github/games647/fastlogin/PlayerSession.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java similarity index 97% rename from src/main/java/com/github/games647/fastlogin/PlayerSession.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java index f76750f4..57fe00c7 100644 --- a/src/main/java/com/github/games647/fastlogin/PlayerSession.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java @@ -1,4 +1,4 @@ -package com.github.games647.fastlogin; +package com.github.games647.fastlogin.bukkit; import org.apache.commons.lang.ArrayUtils; diff --git a/src/main/java/com/github/games647/fastlogin/PremiumCommand.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PremiumCommand.java similarity index 68% rename from src/main/java/com/github/games647/fastlogin/PremiumCommand.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PremiumCommand.java index 02f91802..36459cd1 100644 --- a/src/main/java/com/github/games647/fastlogin/PremiumCommand.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PremiumCommand.java @@ -1,5 +1,7 @@ -package com.github.games647.fastlogin; +package com.github.games647.fastlogin.bukkit; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -13,9 +15,9 @@ import org.bukkit.entity.Player; */ public class PremiumCommand implements CommandExecutor { - private final FastLogin plugin; + private final FastLoginBukkit plugin; - public PremiumCommand(FastLogin plugin) { + public PremiumCommand(FastLoginBukkit plugin) { this.plugin = plugin; } @@ -31,9 +33,17 @@ public class PremiumCommand implements CommandExecutor { String playerName = sender.getName(); plugin.getEnabledPremium().add(playerName); sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players"); + notifiyBungeeCord((Player) sender); return true; } return true; } + + private void notifiyBungeeCord(Player target) { + ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); + dataOutput.writeUTF("ACTIVE"); + + target.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray()); + } } diff --git a/src/main/java/com/github/games647/fastlogin/hooks/AuthMeHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthMeHook.java similarity index 88% rename from src/main/java/com/github/games647/fastlogin/hooks/AuthMeHook.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthMeHook.java index f4949c70..96c86a55 100644 --- a/src/main/java/com/github/games647/fastlogin/hooks/AuthMeHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthMeHook.java @@ -1,4 +1,4 @@ -package com.github.games647.fastlogin.hooks; +package com.github.games647.fastlogin.bukkit.hooks; import fr.xephi.authme.api.NewAPI; diff --git a/src/main/java/com/github/games647/fastlogin/hooks/AuthPlugin.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthPlugin.java similarity index 84% rename from src/main/java/com/github/games647/fastlogin/hooks/AuthPlugin.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthPlugin.java index 73cf66d8..3398d530 100644 --- a/src/main/java/com/github/games647/fastlogin/hooks/AuthPlugin.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/AuthPlugin.java @@ -1,4 +1,4 @@ -package com.github.games647.fastlogin.hooks; +package com.github.games647.fastlogin.bukkit.hooks; import org.bukkit.entity.Player; diff --git a/src/main/java/com/github/games647/fastlogin/hooks/CrazyLoginHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java similarity index 95% rename from src/main/java/com/github/games647/fastlogin/hooks/CrazyLoginHook.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java index e8a26b62..c5c2b1f9 100644 --- a/src/main/java/com/github/games647/fastlogin/hooks/CrazyLoginHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/CrazyLoginHook.java @@ -1,4 +1,4 @@ -package com.github.games647.fastlogin.hooks; +package com.github.games647.fastlogin.bukkit.hooks; import de.st_ddt.crazylogin.CrazyLogin; import de.st_ddt.crazylogin.data.LoginPlayerData; diff --git a/src/main/java/com/github/games647/fastlogin/hooks/LoginSecurityHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/LoginSecurityHook.java similarity index 95% rename from src/main/java/com/github/games647/fastlogin/hooks/LoginSecurityHook.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/LoginSecurityHook.java index 93ef26ed..a0fbfd2d 100644 --- a/src/main/java/com/github/games647/fastlogin/hooks/LoginSecurityHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/LoginSecurityHook.java @@ -1,4 +1,4 @@ -package com.github.games647.fastlogin.hooks; +package com.github.games647.fastlogin.bukkit.hooks; import com.lenis0012.bukkit.ls.LoginSecurity; diff --git a/src/main/java/com/github/games647/fastlogin/hooks/xAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java similarity index 95% rename from src/main/java/com/github/games647/fastlogin/hooks/xAuthHook.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java index d884baf3..186b9296 100644 --- a/src/main/java/com/github/games647/fastlogin/hooks/xAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java @@ -1,4 +1,4 @@ -package com.github.games647.fastlogin.hooks; +package com.github.games647.fastlogin.bukkit.hooks; import de.luricos.bukkit.xAuth.xAuth; import de.luricos.bukkit.xAuth.xAuthPlayer; diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java new file mode 100644 index 00000000..6ceb07a4 --- /dev/null +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java @@ -0,0 +1,66 @@ +package com.github.games647.fastlogin.bukkit.listener; + +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; +import com.github.games647.fastlogin.bukkit.PlayerSession; +import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin; + +import java.util.logging.Level; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.metadata.FixedMetadataValue; + +/** + * This listener tells authentication plugins if the player has a premium account and we checked it successfully. + * So the plugin can skip authentication. + */ +public class BukkitJoinListener implements Listener { + + private static final long DELAY_LOGIN = 1 * 20L / 2; + + protected final FastLoginBukkit plugin; + protected final AuthPlugin authPlugin; + + public BukkitJoinListener(FastLoginBukkit plugin, AuthPlugin authPlugin) { + this.plugin = plugin; + this.authPlugin = authPlugin; + } + + @EventHandler(ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent joinEvent) { + final Player player = joinEvent.getPlayer(); + + Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { + + @Override + public void run() { + String address = player.getAddress().toString(); + //removing the session because we now use it + PlayerSession session = plugin.getSessions().remove(address); + + if (player.isOnline()) { + //blacklist this target player for BungeeCord Id brute force attacks + player.setMetadata(plugin.getName(), new FixedMetadataValue(plugin, true)); + //check if it's the same player as we checked before + if (session != null && player.getName().equals(session.getUsername()) && session.isVerified()) { + plugin.getLogger().log(Level.FINE, "Logging player {0} in", player.getName()); + authPlugin.forceLogin(player); + } + } + } + //Wait before auth plugin and we received a message from BungeeCord initializes the player + }, DELAY_LOGIN); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent quitEvent) { + final Player player = quitEvent.getPlayer(); + + //prevent memory leaks + player.removeMetadata(plugin.getName(), plugin); + } +} diff --git a/src/main/java/com/github/games647/fastlogin/listener/BungeeCordListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java similarity index 63% rename from src/main/java/com/github/games647/fastlogin/listener/BungeeCordListener.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java index d738a2d0..241d3089 100644 --- a/src/main/java/com/github/games647/fastlogin/listener/BungeeCordListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BungeeCordListener.java @@ -1,7 +1,7 @@ -package com.github.games647.fastlogin.listener; +package com.github.games647.fastlogin.bukkit.listener; -import com.github.games647.fastlogin.FastLogin; -import com.github.games647.fastlogin.PlayerSession; +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; +import com.github.games647.fastlogin.bukkit.PlayerSession; import com.google.common.base.Charsets; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; @@ -13,23 +13,24 @@ import java.util.UUID; import java.util.logging.Level; import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.messaging.PluginMessageListener; /** * Responsible for receiving messages from a BungeeCord instance. * - * This class also receives the plugin message from the bungeecord version of this plugin in order to - * get notified if the connection is in online mode. + * This class also receives the plugin message from the bungeecord version of this plugin in order to get notified if + * the connection is in online mode. */ public class BungeeCordListener implements PluginMessageListener { private static final String FILE_NAME = "proxy-whitelist.txt"; - private final FastLogin plugin; + private final FastLoginBukkit plugin; //null if whitelist is empty so bungeecord support is disabled private final UUID proxyId; - public BungeeCordListener(FastLogin plugin) { + public BungeeCordListener(FastLoginBukkit plugin) { this.plugin = plugin; this.proxyId = loadBungeeCordId(); } @@ -44,23 +45,30 @@ public class BungeeCordListener implements PluginMessageListener { String subchannel = dataInput.readUTF(); plugin.getLogger().log(Level.FINEST, "Received plugin message for subchannel {0} from {1}" , new Object[]{subchannel, player}); - if ("Checked".equalsIgnoreCase(subchannel)) { - //bungeecord UUID - long mostSignificantBits = dataInput.readLong(); - long leastSignificantBits = dataInput.readLong(); - UUID sourceId = new UUID(mostSignificantBits, leastSignificantBits); - //fails too if no proxy id is specified in the whitelist file - if (sourceId.equals(proxyId)) { - //make sure the proxy is allowed to transfer data to us - String playerName = dataInput.readUTF(); - //check if the player is still online or disconnected - Player checkedPlayer = plugin.getServer().getPlayerExact(playerName); - if (checkedPlayer != null && checkedPlayer.isOnline()) { + if ("CHECKED".equalsIgnoreCase(subchannel)) { + //make sure the proxy is allowed to transfer data to us + String playerName = dataInput.readUTF(); + + //check if the player is still online or disconnected + Player checkedPlayer = plugin.getServer().getPlayerExact(playerName); + if (checkedPlayer != null && checkedPlayer.isOnline() + //fail if target player is blacklisted because already authed or wrong bungeecord id + && !checkedPlayer.hasMetadata(plugin.getName())) { + //bungeecord UUID + long mostSignificantBits = dataInput.readLong(); + long leastSignificantBits = dataInput.readLong(); + UUID sourceId = new UUID(mostSignificantBits, leastSignificantBits); + + //fail if BungeeCord support is disabled (id = null) + if (sourceId.equals(proxyId)) { PlayerSession playerSession = new PlayerSession(playerName, null, null); playerSession.setVerified(true); //put it only if the user doesn't has a session open //so that the player have to send the bungeecord packet and cannot skip the verification then plugin.getSessions().putIfAbsent(checkedPlayer.getAddress().toString(), playerSession); + } else { + //blacklist target for the current login + checkedPlayer.setMetadata(plugin.getName(), new FixedMetadataValue(plugin, true)); } } } diff --git a/src/main/java/com/github/games647/fastlogin/listener/EncryptionPacketListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/EncryptionPacketListener.java similarity index 96% rename from src/main/java/com/github/games647/fastlogin/listener/EncryptionPacketListener.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/EncryptionPacketListener.java index bbd95d0d..4348b04a 100644 --- a/src/main/java/com/github/games647/fastlogin/listener/EncryptionPacketListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/EncryptionPacketListener.java @@ -1,4 +1,4 @@ -package com.github.games647.fastlogin.listener; +package com.github.games647.fastlogin.bukkit.listener; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolManager; @@ -9,9 +9,9 @@ import com.comphenix.protocol.injector.server.TemporaryPlayerFactory; import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; -import com.github.games647.fastlogin.EncryptionUtil; -import com.github.games647.fastlogin.FastLogin; -import com.github.games647.fastlogin.PlayerSession; +import com.github.games647.fastlogin.bukkit.EncryptionUtil; +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; +import com.github.games647.fastlogin.bukkit.PlayerSession; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -54,9 +54,9 @@ public class EncryptionPacketListener extends PacketAdapter { private final ProtocolManager protocolManager; //hides the inherit Plugin plugin field, but we need this type - private final FastLogin plugin; + private final FastLoginBukkit plugin; - public EncryptionPacketListener(FastLogin plugin, ProtocolManager protocolManger) { + public EncryptionPacketListener(FastLoginBukkit plugin, ProtocolManager protocolManger) { //run async in order to not block the server, because we make api calls to Mojang super(params(plugin, PacketType.Login.Client.ENCRYPTION_BEGIN).optionAsync()); diff --git a/src/main/java/com/github/games647/fastlogin/listener/HandshakePacketListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/HandshakePacketListener.java similarity index 90% rename from src/main/java/com/github/games647/fastlogin/listener/HandshakePacketListener.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/HandshakePacketListener.java index e143f129..e873b24d 100644 --- a/src/main/java/com/github/games647/fastlogin/listener/HandshakePacketListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/HandshakePacketListener.java @@ -1,10 +1,10 @@ -package com.github.games647.fastlogin.listener; +package com.github.games647.fastlogin.bukkit.listener; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; -import com.github.games647.fastlogin.FastLogin; +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import java.util.logging.Level; @@ -27,9 +27,9 @@ import java.util.logging.Level; public class HandshakePacketListener extends PacketAdapter { //hides the inherit Plugin plugin field, but we need a more detailed type than just Plugin - private final FastLogin plugin; + private final FastLoginBukkit plugin; - public HandshakePacketListener(FastLogin plugin) { + public HandshakePacketListener(FastLoginBukkit plugin) { //run async in order to not block the server, because we are making api calls to Mojang super(params(plugin, PacketType.Handshake.Client.SET_PROTOCOL).optionAsync()); diff --git a/src/main/java/com/github/games647/fastlogin/listener/StartPacketListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/StartPacketListener.java similarity index 95% rename from src/main/java/com/github/games647/fastlogin/listener/StartPacketListener.java rename to bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/StartPacketListener.java index 65171744..737fad06 100644 --- a/src/main/java/com/github/games647/fastlogin/listener/StartPacketListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/StartPacketListener.java @@ -1,12 +1,12 @@ -package com.github.games647.fastlogin.listener; +package com.github.games647.fastlogin.bukkit.listener; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; -import com.github.games647.fastlogin.FastLogin; -import com.github.games647.fastlogin.PlayerSession; +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; +import com.github.games647.fastlogin.bukkit.PlayerSession; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -40,14 +40,14 @@ public class StartPacketListener extends PacketAdapter { private final ProtocolManager protocolManager; //hides the inherit Plugin plugin field, but we need a more detailed type than just Plugin - private final FastLogin plugin; + private final FastLoginBukkit plugin; //just create a new once on plugin enable. This used for verify token generation private final Random random = new Random(); //compile the pattern on plugin enable private final Pattern playernameMatcher = Pattern.compile(VALID_PLAYERNAME); - public StartPacketListener(FastLogin plugin, ProtocolManager protocolManger) { + public StartPacketListener(FastLoginBukkit plugin, ProtocolManager protocolManger) { //run async in order to not block the server, because we are making api calls to Mojang super(params(plugin, PacketType.Login.Client.START).optionAsync()); diff --git a/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml similarity index 82% rename from src/main/resources/plugin.yml rename to bukkit/src/main/resources/plugin.yml index 623757d5..7abd1edf 100644 --- a/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ # project informations for Bukkit in order to register our plugin with all it components -# ${project.name} are variables from Maven (pom.xml) which will be replaced after the build -name: ${project.name} +# ${-} are variables from Maven (pom.xml) which will be replaced after the build +name: ${project.parent.name} version: ${project.version} main: ${project.groupId}.${project.artifactId}.${project.name} @@ -21,13 +21,13 @@ softdepend: - LoginSecurity commands: - ${project.artifactId}.: + ${project.parent.name}: description: 'Label the invoker or the player specified as premium' aliases: [prem, premium, loginfast] usage: / [player] permission: ${project.artifactId}.command.premium permissions: - ${project.artifactId}.command.premium: + ${project.parent.name}.command.premium: description: 'Label themselves as premium using a command' default: true \ No newline at end of file diff --git a/bungee/pom.xml b/bungee/pom.xml index c067e4e0..c3ef0f67 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -2,82 +2,19 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.games647 + + com.github.games647 + fastlogin-parent + 0.3 + ../pom.xml + + - fastloginbungee + fastlogin.bungee jar - FastLogin - 0.1 - 2015 - https://github.com/games647/FastLogin - - Automatically logins premium (paid accounts) player on a offline mode server - - - - UTF-8 - - ${basedir}/target - - - - GitHub - https://github.com/games647/FastLogin/issues - - - - https://github.com/games647/FastLogin - scm:git:git://github.com/games647/FastLogin.git - scm:git:ssh://git@github.com:games647/FastLogin.git - - - - install - - ${project.name} - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.2 - - 1.7 - 1.7 - true - true - - false - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - ${outputDir} - - - - - - - src/main/resources - - true - - - - - ${basedir} - - LICENSE - - - - + + FastLoginBungee diff --git a/bungee/src/main/java/com/github/games647/fastloginbungee/FastLogin.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java similarity index 75% rename from bungee/src/main/java/com/github/games647/fastloginbungee/FastLogin.java rename to bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java index 5384dd8b..36113575 100644 --- a/bungee/src/main/java/com/github/games647/fastloginbungee/FastLogin.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/FastLoginBungee.java @@ -1,4 +1,4 @@ -package com.github.games647.fastloginbungee; +package com.github.games647.fastlogin.bungee; import com.google.common.collect.Sets; @@ -10,7 +10,7 @@ import net.md_5.bungee.api.plugin.Plugin; * BungeeCord version of FastLogin. This plugin keeps track * on online mode connections. */ -public class FastLogin extends Plugin { +public class FastLoginBungee extends Plugin { private final Set enabledPremium = Sets.newConcurrentHashSet(); @@ -19,8 +19,8 @@ public class FastLogin extends Plugin { //events getProxy().getPluginManager().registerListener(this, new PlayerConnectionListener(this)); - //commands - getProxy().getPluginManager().registerCommand(this, new PremiumCommand(this)); + //this is required to listen to messages from the server + getProxy().registerChannel(getDescription().getName()); } /** diff --git a/bungee/src/main/java/com/github/games647/fastloginbungee/PlayerConnectionListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java similarity index 77% rename from bungee/src/main/java/com/github/games647/fastloginbungee/PlayerConnectionListener.java rename to bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java index ca77e532..e681e80c 100644 --- a/bungee/src/main/java/com/github/games647/fastloginbungee/PlayerConnectionListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java @@ -1,5 +1,6 @@ -package com.github.games647.fastloginbungee; +package com.github.games647.fastlogin.bungee; +import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; @@ -21,9 +22,9 @@ import net.md_5.bungee.event.EventHandler; */ public class PlayerConnectionListener implements Listener { - private final FastLogin plugin; + private final FastLoginBungee plugin; - public PlayerConnectionListener(FastLogin plugin) { + public PlayerConnectionListener(FastLoginBungee plugin) { this.plugin = plugin; } @@ -50,16 +51,16 @@ public class PlayerConnectionListener implements Listener { ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); //subchannel name - dataOutput.writeUTF("Checked"); + dataOutput.writeUTF("CHECKED"); + + //Data is sent through a random player. We have to tell the Bukkit version of this plugin the target + dataOutput.writeUTF(player.getName()); //proxy identifier to check if it's a acceptable proxy UUID proxyId = UUID.fromString(plugin.getProxy().getConfig().getUuid()); dataOutput.writeLong(proxyId.getMostSignificantBits()); dataOutput.writeLong(proxyId.getLeastSignificantBits()); - //Data is sent through a random player. We have to tell the Bukkit version of this plugin the target - dataOutput.writeUTF(player.getName()); - server.sendData(plugin.getDescription().getName(), dataOutput.toByteArray()); } } @@ -74,5 +75,16 @@ public class PlayerConnectionListener implements Listener { //the client shouldn't be able to read the messages in order to know something about server internal states //moreover the client shouldn't be able fake a running premium check by sending the result message pluginMessageEvent.setCancelled(true); + + //check if the message is sent from the server + if (Server.class.isAssignableFrom(pluginMessageEvent.getSender().getClass())) { + byte[] data = pluginMessageEvent.getData(); + ByteArrayDataInput dataInput = ByteStreams.newDataInput(data); + String subchannel = dataInput.readUTF(); + if ("ACTIVE".equals(subchannel)) { + ProxiedPlayer forPlayer = (ProxiedPlayer) pluginMessageEvent.getReceiver(); + plugin.getEnabledPremium().add(forPlayer.getName()); + } + } } } diff --git a/bungee/src/main/java/com/github/games647/fastloginbungee/PremiumCommand.java b/bungee/src/main/java/com/github/games647/fastloginbungee/PremiumCommand.java deleted file mode 100644 index 3497a09c..00000000 --- a/bungee/src/main/java/com/github/games647/fastloginbungee/PremiumCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.games647.fastloginbungee; - -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.plugin.Command; - -/** - * Let players activate the fastlogin method on a BungeeCord instance. - */ -public class PremiumCommand extends Command { - - private final FastLogin plugin; - - public PremiumCommand(FastLogin plugin) { - super(plugin.getDescription().getName() - , plugin.getDescription().getName() + ".command." + "premium" - , "prem" , "premium", "loginfast"); - - this.plugin = plugin; - } - - @Override - public void execute(CommandSender sender, String[] args) { - if (!(sender instanceof ProxiedPlayer)) { - sender.sendMessage(new ComponentBuilder("Only player can invoke this command") - .color(ChatColor.DARK_RED) - .create()); - return; - } - - plugin.getEnabledPremium().add(sender.getName()); - sender.sendMessage(new ComponentBuilder("Added to the list of premium players") - .color(ChatColor.DARK_GREEN) - .create()); - } -} diff --git a/bungee/src/main/resources/bungee.yml b/bungee/src/main/resources/bungee.yml index de451534..2d441d11 100644 --- a/bungee/src/main/resources/bungee.yml +++ b/bungee/src/main/resources/bungee.yml @@ -1,8 +1,8 @@ # project informations for BungeeCord # This file will be prioritised over plugin.yml which can be also used for Bungee # This make it easy to combine BungeeCord and Bukkit support in one plugin -name: ${project.name} -# ${...} will be automatically replaced by Maven +name: ${project.parent.name} +# ${-} will be automatically replaced by Maven main: ${project.groupId}.${project.artifactId}.${project.name} version: ${project.version} diff --git a/pom.xml b/pom.xml index a8f2c59e..f8960d3d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,23 +4,27 @@ com.github.games647 - fastlogin - jar + fastlogin-parent + pom FastLogin 0.3 2015 - https://github.com/games647/FastLogin + https://www.spigotmc.org/resources/fastlogin.14153/ Automatically logins premium (paid accounts) player on a offline mode server UTF-8 - - ${basedir}/target + + bukkit + bungee + universal + + GitHub https://github.com/games647/FastLogin/issues @@ -41,7 +45,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.2 + 3.3 1.7 1.7 @@ -51,15 +55,6 @@ false - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - ${outputDir} - - @@ -71,110 +66,12 @@ - ${basedir} + + ${basedir}/.. LICENSE - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - - - dmulloy2-repo - http://repo.dmulloy2.net/content/groups/public/ - - - - - xephi-repo - http://ci.xephi.fr/plugin/repository/everything/ - - - - - luricos.de-repo - http://repo.luricos.de/bukkit-plugins/ - - - - - - - org.spigotmc - spigot-api - 1.8.8-R0.1-SNAPSHOT - provided - - - - - com.comphenix.protocol - ProtocolLib - 3.6.5-SNAPSHOT - true - - - - - fr.xephi - authme - 5.1-SNAPSHOT - true - - - - de.luricos.bukkit - xAuth - 2.6 - true - - - - net.gravitydevelopment.updater - updater - - - net.ess3 - EssentialsGroupManager - - - - - - - de.st_ddt.crazy - CrazyCore - 10.7.7 - true - system - ${project.basedir}/lib/CrazyCore v10.7.7.jar - - - - de.st_ddt.crazy - CrazyLogin - 7.23 - true - system - ${project.basedir}/lib/CrazyLogin v7.23.2.jar - - - - - me.lenis0012.ls - LoginSecurity - 2.0.10 - true - system - ${project.basedir}/lib/LoginSecurity v2.0.10.jar - - diff --git a/src/main/java/com/github/games647/fastlogin/listener/BukkitJoinListener.java b/src/main/java/com/github/games647/fastlogin/listener/BukkitJoinListener.java deleted file mode 100644 index 51956633..00000000 --- a/src/main/java/com/github/games647/fastlogin/listener/BukkitJoinListener.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.github.games647.fastlogin.listener; - -import com.github.games647.fastlogin.FastLogin; -import com.github.games647.fastlogin.PlayerSession; -import com.github.games647.fastlogin.hooks.AuthPlugin; - -import java.util.logging.Level; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -/** - * This listener tells authentication plugins if the player has a premium account and we checked it successfully. So the - * plugin can skip authentication. - */ -public class BukkitJoinListener implements Listener { - - private static final long DELAY_LOGIN = 2 * 20L; - - protected final FastLogin plugin; - protected final AuthPlugin authPlugin; - - public BukkitJoinListener(FastLogin plugin, AuthPlugin authPlugin) { - this.plugin = plugin; - this.authPlugin = authPlugin; - } - - @EventHandler(ignoreCancelled = true) - public void onJoin(PlayerJoinEvent joinEvent) { - final Player player = joinEvent.getPlayer(); - - Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { - - @Override - public void run() { - String address = player.getAddress().toString(); - //removing the session because we now use it - PlayerSession session = plugin.getSessions().remove(address); - - //check if it's the same player as we checked before - if (player.isOnline() && session != null - && player.getName().equals(session.getUsername()) && session.isVerified()) { - plugin.getLogger().log(Level.FINE, "Logging player {0} in", player.getName()); - authPlugin.forceLogin(player); - } - } - //Wait before auth plugin and we received a message from BungeeCord initializes the player - }, DELAY_LOGIN); - } -} diff --git a/universal/pom.xml b/universal/pom.xml new file mode 100644 index 00000000..18747aaa --- /dev/null +++ b/universal/pom.xml @@ -0,0 +1,55 @@ + + 4.0.0 + + + com.github.games647 + fastlogin-parent + 0.3 + ../pom.xml + + + fastlogin-universal + jar + + FastLoginUniversal + + + package + ${project.parent.name} + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.2 + + false + false + + + + package + + shade + + + + + + + + + + ${project.groupId} + fastlogin.bukkit + ${project.version} + + + + ${project.groupId} + fastlogin.bungee + ${project.version} + + +