Removes the need to use a bukkit auth plugin if you have a bungee one

(Fixes #4)
This commit is contained in:
games647
2016-03-22 21:25:58 +01:00
parent 0967f31b9a
commit f3e675e547
4 changed files with 18 additions and 6 deletions

View File

@ -153,7 +153,8 @@ public class FastLoginBukkit extends JavaPlugin {
}
/**
* Gets the auth plugin hook in order to interact with the plugins
* Gets the auth plugin hook in order to interact with the plugins.
* This can be null if no supporting auth plugin was found
*
* @return interface to any supported auth plugin
*/

View File

@ -4,6 +4,7 @@ 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.BukkitAuthPlugin;
import java.util.logging.Level;
@ -56,20 +57,23 @@ public class BukkitJoinListener implements Listener {
//blacklist this target player for BungeeCord Id brute force attacks
player.setMetadata(plugin.getName(), new FixedMetadataValue(plugin, true));
//check if it's the same player as we checked before
if (session != null && player.getName().equals(session.getUsername()) && session.isVerified()) {
BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
if (session != null && player.getName().equals(session.getUsername()) && session.isVerified()
&& authPlugin != null) {
if (session.needsRegistration()) {
plugin.getLogger().log(Level.FINE, "Register player {0}", player.getName());
plugin.getEnabledPremium().add(session.getUsername());
String generatedPassword = plugin.generateStringPassword();
plugin.getAuthPlugin().forceRegister(player, generatedPassword);
authPlugin.forceRegister(player, generatedPassword);
player.sendMessage(ChatColor.DARK_GREEN + "Auto registered with password: "
+ generatedPassword);
player.sendMessage(ChatColor.DARK_GREEN + "You may want change it?");
} else {
plugin.getLogger().log(Level.FINE, "Logging player {0} in", player.getName());
plugin.getAuthPlugin().forceLogin(player);
authPlugin.forceLogin(player);
player.sendMessage(ChatColor.DARK_GREEN + "Auto logged in");
}
}

View File

@ -2,6 +2,7 @@ package com.github.games647.fastlogin.bukkit.listener;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.PlayerSession;
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
import java.net.InetSocketAddress;
@ -29,10 +30,13 @@ public class ProtcolSupportListener implements Listener {
//remove old data every time on a new login in order to keep the session only for one person
plugin.getSessions().remove(playerName);
BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
if (plugin.getEnabledPremium().contains(playerName)) {
//the player have to be registered in order to invoke the command
startPremiumSession(playerName, loginStartEvent, true);
} else if (plugin.getConfig().getBoolean("autoRegister") && !plugin.getAuthPlugin().isRegistered(playerName)) {
} else if (plugin.getConfig().getBoolean("autoRegister")
&& authPlugin != null && !plugin.getAuthPlugin().isRegistered(playerName)) {
startPremiumSession(playerName, loginStartEvent, false);
plugin.getEnabledPremium().add(playerName);
}

View File

@ -7,6 +7,7 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.PlayerSession;
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
import java.lang.reflect.InvocationTargetException;
import java.security.PublicKey;
@ -72,9 +73,11 @@ public class StartPacketListener extends PacketAdapter {
plugin.getLogger().log(Level.FINER, "Player {0} with {1} connecting to the server"
, new Object[]{sessionKey, username});
if (!plugin.getBungeeCordUsers().containsKey(player)) {
BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
if (plugin.getEnabledPremium().contains(username)) {
enablePremiumLogin(username, sessionKey, player, packetEvent, true);
} else if (plugin.getConfig().getBoolean("autologin") && !plugin.getAuthPlugin().isRegistered(username)) {
} else if (plugin.getConfig().getBoolean("autologin")
&& authPlugin != null && !plugin.getAuthPlugin().isRegistered(username)) {
enablePremiumLogin(username, sessionKey, player, packetEvent, false);
plugin.getEnabledPremium().add(username);
}