diff --git a/CHANGELOG.md b/CHANGELOG.md index f5f98bce..31ee75cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ######0.4 * Added forward premium skin +* Added plugin support for protocolsupport ######0.3.2 diff --git a/bukkit/lib/ProtocolSupport b337.jar b/bukkit/lib/ProtocolSupport b337.jar new file mode 100644 index 00000000..052c1e15 Binary files /dev/null and b/bukkit/lib/ProtocolSupport b337.jar differ diff --git a/bukkit/pom.xml b/bukkit/pom.xml index d0e1f35c..71656153 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -58,6 +58,14 @@ true + + protcolsupport + ProtocolSupport + Build-337 + system + ${project.basedir}/lib/ProtocolSupport b337.jar + + fr.xephi diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index 51f4dce5..51305c1b 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -1,15 +1,16 @@ package com.github.games647.fastlogin.bukkit; import com.comphenix.protocol.AsynchronousManager; -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.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.utility.SafeCacheBuilder; import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin; +import com.github.games647.fastlogin.bukkit.listener.BukkitJoinListener; +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.github.games647.fastlogin.bukkit.listener.ProtcolSupportListener; +import com.github.games647.fastlogin.bukkit.listener.StartPacketListener; import com.google.common.cache.CacheLoader; import com.google.common.collect.MapMaker; import com.google.common.collect.Sets; @@ -60,6 +61,8 @@ public class FastLoginBukkit extends JavaPlugin { } }); + private AuthPlugin authPlugin; + @Override public void onEnable() { if (getServer().getOnlineMode() || !registerHooks()) { @@ -69,14 +72,20 @@ public class FastLoginBukkit extends JavaPlugin { return; } - //register packet listeners on success - ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); - protocolManager.addPacketListener(new HandshakePacketListener(this)); + //register listeners on success + if (getServer().getPluginManager().isPluginEnabled("ProtocolSupport")) { + getServer().getPluginManager().registerEvents(new ProtcolSupportListener(this), this); + } else { + ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); + protocolManager.addPacketListener(new HandshakePacketListener(this)); - //we are performing HTTP request on these so run it async (seperate from the Netty IO threads) - AsynchronousManager asynchronousManager = protocolManager.getAsynchronousManager(); - asynchronousManager.registerAsyncHandler(new StartPacketListener(this, protocolManager)).start(); - asynchronousManager.registerAsyncHandler(new EncryptionPacketListener(this, protocolManager)).start(); + //we are performing HTTP request on these so run it async (seperate from the Netty IO threads) + AsynchronousManager asynchronousManager = protocolManager.getAsynchronousManager(); + asynchronousManager.registerAsyncHandler(new StartPacketListener(this, protocolManager)).start(); + asynchronousManager.registerAsyncHandler(new EncryptionPacketListener(this, protocolManager)).start(); + + getServer().getPluginManager().registerEvents(new BukkitJoinListener(this), this); + } //register commands using a unique name getCommand("premium").setExecutor(new PremiumCommand(this)); @@ -100,8 +109,8 @@ public class FastLoginBukkit extends JavaPlugin { } /** - * Gets a thread-safe map about players which are connecting to the server - * are being checked to be premium (paid account) + * Gets a thread-safe map about players which are connecting to the server are being checked to be premium (paid + * account) * * @return a thread-safe session map */ @@ -110,9 +119,8 @@ public class FastLoginBukkit extends JavaPlugin { } /** - * Gets a concurrent map with weak keys for all bungeecord users - * which could be detected. It's mapped by a fake instance of player - * created by Protocollib and a non-null raw object. + * Gets a concurrent map with weak keys for all bungeecord users which could be detected. It's mapped by a fake + * instance of player created by Protocollib and a non-null raw object. * * Represents a similar set collection * @@ -140,6 +148,15 @@ public class FastLoginBukkit extends JavaPlugin { return enabledPremium; } + /** + * Gets the auth plugin hook in order to interact with the plugins + * + * @return interface to any supported auth plugin + */ + public AuthPlugin getAuthPlugin() { + return authPlugin; + } + /** * Prepares a Mojang API connection. The connection is not started in this method * @@ -190,8 +207,7 @@ public class FastLoginBukkit extends JavaPlugin { return false; } - //We found a supporting plugin - we can now register a forwarding listener to skip authentication from them - getServer().getPluginManager().registerEvents(new BukkitJoinListener(this, authPluginHook), this); + authPlugin = authPluginHook; return true; } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java index d1abc6f0..34838467 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerSession.java @@ -1,6 +1,7 @@ package com.github.games647.fastlogin.bukkit; import com.comphenix.protocol.wrappers.WrappedSignedProperty; + import org.apache.commons.lang.ArrayUtils; /** diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java index 186b9296..36ab0dc2 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/hooks/xAuthHook.java @@ -2,9 +2,6 @@ package com.github.games647.fastlogin.bukkit.hooks; import de.luricos.bukkit.xAuth.xAuth; import de.luricos.bukkit.xAuth.xAuthPlayer; -import de.luricos.bukkit.xAuth.xAuthPlayer.Status; - -import java.sql.Timestamp; import org.bukkit.entity.Player; @@ -20,19 +17,12 @@ public class xAuthHook implements AuthPlugin { xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player); if (xAuthPlayer != null) { + xAuthPlugin.getPlayerManager().doLogin(xAuthPlayer); //we checked that the player is premium (paid account) xAuthPlayer.setPremium(true); + //mark the player online xAuthPlugin.getAuthClass(xAuthPlayer).online(xAuthPlayer.getName()); - - //update last login time - xAuthPlayer.setLoginTime(new Timestamp(System.currentTimeMillis())); - - //mark the player as logged in - xAuthPlayer.setStatus(Status.AUTHENTICATED); - - //restore inventory - xAuthPlugin.getPlayerManager().unprotect(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 index faf02881..2073bd75 100644 --- 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 @@ -4,7 +4,6 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedSignedProperty; 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; @@ -25,11 +24,9 @@ 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) { + public BukkitJoinListener(FastLoginBukkit plugin) { this.plugin = plugin; - this.authPlugin = authPlugin; } @EventHandler(ignoreCancelled = true) @@ -59,7 +56,7 @@ public class BukkitJoinListener implements Listener { //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); + plugin.getAuthPlugin().forceLogin(player); } } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtcolSupportListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtcolSupportListener.java new file mode 100644 index 00000000..8af2a1c9 --- /dev/null +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/ProtcolSupportListener.java @@ -0,0 +1,85 @@ +package com.github.games647.fastlogin.bukkit.listener; + +import com.comphenix.protocol.wrappers.WrappedSignedProperty; +import com.github.games647.fastlogin.bukkit.FastLoginBukkit; +import com.github.games647.fastlogin.bukkit.PlayerSession; + +import java.net.InetSocketAddress; +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 protocolsupport.api.events.PlayerLoginStartEvent; +import protocolsupport.api.events.PlayerPropertiesResolveEvent; + +public class ProtcolSupportListener implements Listener { + + private static final long DELAY_LOGIN = 1 * 20L / 2; + + protected final FastLoginBukkit plugin; + + public ProtcolSupportListener(FastLoginBukkit plugin) { + this.plugin = plugin; + } + + @EventHandler(ignoreCancelled = true) + public void onLoginStart(PlayerLoginStartEvent loginStartEvent) { + if (loginStartEvent.isLoginDenied()) { + return; + } + + String playerName = loginStartEvent.getName(); + if (plugin.getEnabledPremium().contains(playerName)) { + loginStartEvent.setOnlineMode(true); + InetSocketAddress address = loginStartEvent.getAddress(); + + PlayerSession playerSession = new PlayerSession(playerName, null, null); + plugin.getSessions().put(address.toString(), playerSession); +// loginStartEvent.setUseOnlineModeUUID(true); + } + } + + @EventHandler(ignoreCancelled = true) + public void onPropertiesResolve(PlayerPropertiesResolveEvent propertiesResolveEvent) { + InetSocketAddress address = propertiesResolveEvent.getAddress(); + PlayerSession session = plugin.getSessions().get(address.toString()); + if (session != null) { + session.setVerified(true); + + PlayerPropertiesResolveEvent.ProfileProperty skinProperty = propertiesResolveEvent.getProperties() + .get("textures"); + if (skinProperty != null) { + WrappedSignedProperty signedProperty = WrappedSignedProperty + .fromValues(skinProperty.getName(), skinProperty.getValue(), skinProperty.getSignature()); + session.setSkin(signedProperty); + } + } + } + + @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().getAddress().toString(); + //removing the session because we now use it + PlayerSession session = plugin.getSessions().remove(address); + + if (player.isOnline()) { + //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()); + plugin.getAuthPlugin().forceLogin(player); + } + } + } + //Wait before auth plugin and we received a message from BungeeCord initializes the player + }, DELAY_LOGIN); + } +} diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index 7abd1edf..8b8b736e 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -13,8 +13,10 @@ dev-url: ${project.url} # Without Protocollib the plugin does not work at all depend: [ProtocolLib] -# Auth plugins + softdepend: + - ProtocolSupport + # Auth plugins - xAuth - AuthMe - CrazyLogin