Added BungeeCord support

This commit is contained in:
games647
2015-11-13 22:46:38 +01:00
parent 834818bb7a
commit c3f8e59a9a
16 changed files with 527 additions and 78 deletions

View File

@@ -1,13 +1,16 @@
package com.github.games647.fastlogin;
import com.github.games647.fastlogin.listener.PlayerListener;
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.google.common.cache.CacheLoader;
import com.google.common.collect.MapMaker;
import com.google.common.collect.Sets;
import com.google.common.reflect.ClassPath;
@@ -20,16 +23,16 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import org.bukkit.entity.Player;
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.
* This plugin checks if a player has a paid account and if so tries to skip offline mode authentication.
*/
public class FastLogin extends JavaPlugin {
//http connection, read timeout and user agent for a connection to mojang api servers
private static final int TIMEOUT = 10 * 1000;
private static final int TIMEOUT = 1 * 1000;
private static final String USER_AGENT = "Premium-Checker";
//provide a immutable key pair to be thread safe | used for encrypting and decrypting traffic
@@ -38,11 +41,14 @@ public class FastLogin extends JavaPlugin {
//we need a thread-safe set because we access it async in the packet listener
private final Set<String> enabledPremium = Sets.newConcurrentHashSet();
//player=fake player created by Protocollib | this mapmaker creates a concurrent map with weak keys
private final ConcurrentMap<Player, Object> bungeeCordUsers = new MapMaker().weakKeys().makeMap();
//this map is thread-safe for async access (Packet Listener)
//SafeCacheBuilder is used in order to be version independent
private final ConcurrentMap<String, PlayerSession> session = SafeCacheBuilder.<String, PlayerSession>newBuilder()
//2 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang)
.expireAfterWrite(2, TimeUnit.MINUTES)
.expireAfterWrite(1, TimeUnit.MINUTES)
//mapped by ip:port -> PlayerSession
.build(new CacheLoader<String, PlayerSession>() {
@@ -72,11 +78,15 @@ public class FastLogin extends JavaPlugin {
//register packet listeners on success
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
protocolManager.addPacketListener(new EncryptionPacketListener(this, protocolManager));
protocolManager.addPacketListener(new HandshakePacketListener(this));
protocolManager.addPacketListener(new StartPacketListener(this, protocolManager));
protocolManager.addPacketListener(new EncryptionPacketListener(this, protocolManager));
//register commands using a unique name
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));
}
@Override
@@ -84,11 +94,12 @@ public class FastLogin extends JavaPlugin {
//clean up
session.clear();
enabledPremium.clear();
bungeeCordUsers.clear();
}
/**
* 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
*/
@@ -97,8 +108,20 @@ public class FastLogin extends JavaPlugin {
}
/**
* Gets the server KeyPair. This is used to encrypt or decrypt traffic between
* the client and server
* 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
*
* @return
*/
public ConcurrentMap<Player, Object> getBungeeCordUsers() {
return bungeeCordUsers;
}
/**
* Gets the server KeyPair. This is used to encrypt or decrypt traffic between the client and server
*
* @return the server KeyPair
*/
@@ -166,7 +189,7 @@ public class FastLogin extends JavaPlugin {
}
//We found a supporting plugin - we can now register a forwarding listener to skip authentication from them
getServer().getPluginManager().registerEvents(new PlayerListener(this, authPluginHook), this);
getServer().getPluginManager().registerEvents(new BukkitJoinListener(this, authPluginHook), this);
return true;
}
}