mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
Added protocol support
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
######0.4
|
||||
|
||||
* Added forward premium skin
|
||||
* Added plugin support for protocolsupport
|
||||
|
||||
######0.3.2
|
||||
|
||||
|
BIN
bukkit/lib/ProtocolSupport b337.jar
Normal file
BIN
bukkit/lib/ProtocolSupport b337.jar
Normal file
Binary file not shown.
@ -58,6 +58,14 @@
|
||||
<optional>true</optional>
|
||||
</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-->
|
||||
<dependency>
|
||||
<groupId>fr.xephi</groupId>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.games647.fastlogin.bukkit;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Reference in New Issue
Block a user