Added protocol support

This commit is contained in:
games647
2016-01-24 11:50:49 +01:00
parent 3b4c4a1c79
commit d1b2fe8865
9 changed files with 136 additions and 36 deletions

View File

@ -1,6 +1,7 @@
######0.4 ######0.4
* Added forward premium skin * Added forward premium skin
* Added plugin support for protocolsupport
######0.3.2 ######0.3.2

Binary file not shown.

View File

@ -58,6 +58,14 @@
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>protcolsupport</groupId>
<artifactId>ProtocolSupport</artifactId>
<version>Build-337</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ProtocolSupport b337.jar</systemPath>
</dependency>
<!--Login Plugins--> <!--Login Plugins-->
<dependency> <dependency>
<groupId>fr.xephi</groupId> <groupId>fr.xephi</groupId>

View File

@ -1,15 +1,16 @@
package com.github.games647.fastlogin.bukkit; package com.github.games647.fastlogin.bukkit;
import com.comphenix.protocol.AsynchronousManager; 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.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.utility.SafeCacheBuilder; import com.comphenix.protocol.utility.SafeCacheBuilder;
import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin; 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.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.cache.CacheLoader;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -60,6 +61,8 @@ public class FastLoginBukkit extends JavaPlugin {
} }
}); });
private AuthPlugin authPlugin;
@Override @Override
public void onEnable() { public void onEnable() {
if (getServer().getOnlineMode() || !registerHooks()) { if (getServer().getOnlineMode() || !registerHooks()) {
@ -69,14 +72,20 @@ public class FastLoginBukkit extends JavaPlugin {
return; return;
} }
//register packet listeners on success //register listeners on success
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); if (getServer().getPluginManager().isPluginEnabled("ProtocolSupport")) {
protocolManager.addPacketListener(new HandshakePacketListener(this)); 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) //we are performing HTTP request on these so run it async (seperate from the Netty IO threads)
AsynchronousManager asynchronousManager = protocolManager.getAsynchronousManager(); AsynchronousManager asynchronousManager = protocolManager.getAsynchronousManager();
asynchronousManager.registerAsyncHandler(new StartPacketListener(this, protocolManager)).start(); asynchronousManager.registerAsyncHandler(new StartPacketListener(this, protocolManager)).start();
asynchronousManager.registerAsyncHandler(new EncryptionPacketListener(this, protocolManager)).start(); asynchronousManager.registerAsyncHandler(new EncryptionPacketListener(this, protocolManager)).start();
getServer().getPluginManager().registerEvents(new BukkitJoinListener(this), this);
}
//register commands using a unique name //register commands using a unique name
getCommand("premium").setExecutor(new PremiumCommand(this)); 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 * Gets a thread-safe map about players which are connecting to the server are being checked to be premium (paid
* are being checked to be premium (paid account) * account)
* *
* @return a thread-safe session map * @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 * Gets a concurrent map with weak keys for all bungeecord users which could be detected. It's mapped by a fake
* which could be detected. It's mapped by a fake instance of player * instance of player created by Protocollib and a non-null raw object.
* created by Protocollib and a non-null raw object.
* *
* Represents a similar set collection * Represents a similar set collection
* *
@ -140,6 +148,15 @@ public class FastLoginBukkit extends JavaPlugin {
return enabledPremium; 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 * Prepares a Mojang API connection. The connection is not started in this method
* *
@ -190,8 +207,7 @@ public class FastLoginBukkit extends JavaPlugin {
return false; return false;
} }
//We found a supporting plugin - we can now register a forwarding listener to skip authentication from them authPlugin = authPluginHook;
getServer().getPluginManager().registerEvents(new BukkitJoinListener(this, authPluginHook), this);
return true; return true;
} }
} }

View File

@ -1,6 +1,7 @@
package com.github.games647.fastlogin.bukkit; package com.github.games647.fastlogin.bukkit;
import com.comphenix.protocol.wrappers.WrappedSignedProperty; import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
/** /**

View File

@ -2,9 +2,6 @@ package com.github.games647.fastlogin.bukkit.hooks;
import de.luricos.bukkit.xAuth.xAuth; import de.luricos.bukkit.xAuth.xAuth;
import de.luricos.bukkit.xAuth.xAuthPlayer; import de.luricos.bukkit.xAuth.xAuthPlayer;
import de.luricos.bukkit.xAuth.xAuthPlayer.Status;
import java.sql.Timestamp;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -20,19 +17,12 @@ public class xAuthHook implements AuthPlugin {
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player); xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(player);
if (xAuthPlayer != null) { if (xAuthPlayer != null) {
xAuthPlugin.getPlayerManager().doLogin(xAuthPlayer);
//we checked that the player is premium (paid account) //we checked that the player is premium (paid account)
xAuthPlayer.setPremium(true); xAuthPlayer.setPremium(true);
//mark the player online //mark the player online
xAuthPlugin.getAuthClass(xAuthPlayer).online(xAuthPlayer.getName()); 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);
} }
} }
} }

View File

@ -4,7 +4,6 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty; import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.PlayerSession; import com.github.games647.fastlogin.bukkit.PlayerSession;
import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin;
import java.util.logging.Level; import java.util.logging.Level;
@ -25,11 +24,9 @@ public class BukkitJoinListener implements Listener {
private static final long DELAY_LOGIN = 1 * 20L / 2; private static final long DELAY_LOGIN = 1 * 20L / 2;
protected final FastLoginBukkit plugin; protected final FastLoginBukkit plugin;
protected final AuthPlugin authPlugin;
public BukkitJoinListener(FastLoginBukkit plugin, AuthPlugin authPlugin) { public BukkitJoinListener(FastLoginBukkit plugin) {
this.plugin = plugin; this.plugin = plugin;
this.authPlugin = authPlugin;
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@ -59,7 +56,7 @@ public class BukkitJoinListener implements Listener {
//check if it's the same player as we checked before //check if it's the same player as we checked before
if (session != null && player.getName().equals(session.getUsername()) && session.isVerified()) { if (session != null && player.getName().equals(session.getUsername()) && session.isVerified()) {
plugin.getLogger().log(Level.FINE, "Logging player {0} in", player.getName()); plugin.getLogger().log(Level.FINE, "Logging player {0} in", player.getName());
authPlugin.forceLogin(player); plugin.getAuthPlugin().forceLogin(player);
} }
} }
} }

View File

@ -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);
}
}

View File

@ -13,8 +13,10 @@ dev-url: ${project.url}
# Without Protocollib the plugin does not work at all # Without Protocollib the plugin does not work at all
depend: [ProtocolLib] depend: [ProtocolLib]
# Auth plugins
softdepend: softdepend:
- ProtocolSupport
# Auth plugins
- xAuth - xAuth
- AuthMe - AuthMe
- CrazyLogin - CrazyLogin