Fixed bungeecord detection for older Spigot builds

This commit is contained in:
games647
2016-05-12 20:11:56 +02:00
parent 9e06fd7735
commit bfaf390463
7 changed files with 28 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
######1.1 ######1.1
* Make the configuration options also work under BungeeCord (premiumUUID, forwardSkin) * Make the configuration options also work under BungeeCord (premiumUUID, forwardSkin)
* Catch configuration loading exception if it's not spigot build
* Fix config loading for older PaperSpigot builds
######1.0 ######1.0

View File

@@ -3,6 +3,7 @@ package com.github.games647.fastlogin.bukkit;
import com.comphenix.protocol.AsynchronousManager; import com.comphenix.protocol.AsynchronousManager;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.utility.SafeCacheBuilder; import com.comphenix.protocol.utility.SafeCacheBuilder;
import com.github.games647.fastlogin.bukkit.commands.CrackedCommand; import com.github.games647.fastlogin.bukkit.commands.CrackedCommand;
import com.github.games647.fastlogin.bukkit.commands.PremiumCommand; import com.github.games647.fastlogin.bukkit.commands.PremiumCommand;
@@ -16,6 +17,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.reflect.ClassPath; import com.google.common.reflect.ClassPath;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method;
import java.security.KeyPair; import java.security.KeyPair;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
@@ -25,6 +27,7 @@ import java.util.logging.Level;
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@@ -32,7 +35,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. * This plugin checks if a player has a paid account and if so tries to skip offline mode authentication.
*/ */
public class FastLoginBukkit extends JavaPlugin { public class FastLoginBukkit extends JavaPlugin {
private static final int WORKER_THREADS = 5; private static final int WORKER_THREADS = 5;
public static UUID parseId(String withoutDashes) { public static UUID parseId(String withoutDashes) {
@@ -46,7 +49,6 @@ public class FastLoginBukkit extends JavaPlugin {
//provide a immutable key pair to be thread safe | used for encrypting and decrypting traffic //provide a immutable key pair to be thread safe | used for encrypting and decrypting traffic
private final KeyPair keyPair = EncryptionUtil.generateKeyPair(); private final KeyPair keyPair = EncryptionUtil.generateKeyPair();
private boolean bungeeCord; private boolean bungeeCord;
private Storage storage; private Storage storage;
@@ -79,7 +81,20 @@ public class FastLoginBukkit extends JavaPlugin {
return; return;
} }
bungeeCord = Bukkit.spigot().getConfig().getBoolean("settings.bungeecord"); try {
if (Bukkit.spigot().getConfig().isBoolean("settings.bungeecord")) {
bungeeCord = Bukkit.spigot().getConfig().getBoolean("settings.bungeecord");
} else {
Method getConfigMethod = FuzzyReflection.fromObject(getServer().spigot(), true)
.getMethodByName("getSpigotConfig");
getConfigMethod.setAccessible(true);
YamlConfiguration spigotConfig = (YamlConfiguration) getConfigMethod.invoke(getServer().spigot());
bungeeCord = spigotConfig.getBoolean("settings.bungeecord");
}
} catch (Exception | NoSuchMethodError ex) {
getLogger().warning("Cannot check bungeecord support. You use a non-spigot build");
}
boolean hookFound = registerHooks(); boolean hookFound = registerHooks();
if (bungeeCord) { if (bungeeCord) {
getLogger().info("BungeeCord setting detected. No auth plugin is required"); getLogger().info("BungeeCord setting detected. No auth plugin is required");

View File

@@ -30,15 +30,14 @@ public class ForceLoginTask implements Runnable {
return; return;
} }
//remove the bungeecord identifier //remove the bungeecord identifier if there is ones
String id = '/' + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort(); String id = '/' + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort();
PlayerSession session = plugin.getSessions().get(id); PlayerSession session = plugin.getSessions().get(id);
//blacklist this target player for BungeeCord Id brute force attacks //blacklist this target player for BungeeCord Id brute force attacks
player.setMetadata(plugin.getName(), new FixedMetadataValue(plugin, true)); player.setMetadata(plugin.getName(), new FixedMetadataValue(plugin, true));
//check if it's the same player as we checked before
final BukkitAuthPlugin authPlugin = plugin.getAuthPlugin(); BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
Storage storage = plugin.getStorage(); Storage storage = plugin.getStorage();
PlayerProfile playerProfile = null; PlayerProfile playerProfile = null;
@@ -53,6 +52,7 @@ public class ForceLoginTask implements Runnable {
playerProfile.setPremium(false); playerProfile.setPremium(false);
storage.save(playerProfile); storage.save(playerProfile);
} }
//check if it's the same player as we checked before
} else if (player.getName().equals(session.getUsername())) { } else if (player.getName().equals(session.getUsername())) {
//premium player //premium player
if (authPlugin == null) { if (authPlugin == null) {

View File

@@ -68,7 +68,7 @@ public class PlayerProfile {
this.lastIp = lastIp; this.lastIp = lastIp;
} }
public long getLastLogin() { public synchronized long getLastLogin() {
return lastLogin; return lastLogin;
} }

View File

@@ -19,7 +19,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
*/ */
public class BukkitJoinListener implements Listener { public class BukkitJoinListener implements Listener {
private static final long DELAY_LOGIN = 1 * 20L / 2; private static final long DELAY_LOGIN = 20L / 2;
protected final FastLoginBukkit plugin; protected final FastLoginBukkit plugin;

View File

@@ -1,6 +1,7 @@
package com.github.games647.fastlogin.bungee; package com.github.games647.fastlogin.bungee;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@@ -9,6 +10,7 @@ import java.net.URL;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
public class MojangApiConnector { public class MojangApiConnector {

View File

@@ -68,7 +68,7 @@ public class PlayerProfile {
this.lastIp = lastIp; this.lastIp = lastIp;
} }
public long getLastLogin() { public synchronized long getLastLogin() {
return lastLogin; return lastLogin;
} }