Always forward premium status to spigot

This commit is contained in:
games647
2018-03-16 15:14:35 +01:00
parent 5bcfdfeb32
commit b534765ff8
12 changed files with 78 additions and 47 deletions

39
.gitignore vendored
View File

@@ -7,31 +7,15 @@
nbproject/ nbproject/
nb-configuration.xml nb-configuration.xml
# Maven
target/
# Vim
.*.sw[a-p]
# virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# various other potential build files
build/
bin/
dist/
manifest.mf
*.log
# Mac filesystem dust
.DS_Store
# IntelliJ # IntelliJ
*.iml *.iml
*.ipr *.ipr
*.iws *.iws
.idea/ .idea/
# Maven
target/
# Gradle # Gradle
.gradle .gradle
@@ -40,3 +24,20 @@ gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar !gradle-wrapper.jar
# various other potential build files
build/
bin/
dist/
manifest.mf
*.log
# Vim
.*.sw[a-p]
# virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Mac filesystem dust
.DS_Store

View File

@@ -3,12 +3,13 @@ package com.github.games647.fastlogin.bukkit;
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;
import com.github.games647.fastlogin.bukkit.listener.BungeeListener; import com.github.games647.fastlogin.bukkit.listener.BungeeListener;
import com.github.games647.fastlogin.bukkit.listener.JoinListener; import com.github.games647.fastlogin.bukkit.listener.ConnectionListener;
import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener; import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener;
import com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener; import com.github.games647.fastlogin.bukkit.listener.protocollib.SkinApplyListener;
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener; import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook; import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook;
import com.github.games647.fastlogin.core.CommonUtil; import com.github.games647.fastlogin.core.CommonUtil;
import com.github.games647.fastlogin.core.PremiumStatus;
import com.github.games647.fastlogin.core.messages.ChannelMessage; import com.github.games647.fastlogin.core.messages.ChannelMessage;
import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin; import com.github.games647.fastlogin.core.shared.PlatformPlugin;
@@ -16,6 +17,9 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@@ -30,14 +34,14 @@ import org.slf4j.Logger;
*/ */
public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<CommandSender> { public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<CommandSender> {
private final Logger logger = CommonUtil.createLoggerFromJDK(getLogger());
private boolean bungeeCord;
private FastLoginCore<Player, CommandSender, FastLoginBukkit> core;
private boolean serverStarted;
//1 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang) //1 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang)
private final ConcurrentMap<String, BukkitLoginSession> loginSession = CommonUtil.buildCache(1, -1); private final ConcurrentMap<String, BukkitLoginSession> loginSession = CommonUtil.buildCache(1, -1);
private final Logger logger = CommonUtil.createLoggerFromJDK(getLogger());
private final Map<UUID, PremiumStatus> premiumPlayers = new ConcurrentHashMap<>();
private boolean serverStarted;
private boolean bungeeCord;
private FastLoginCore<Player, CommandSender, FastLoginBukkit> core;
@Override @Override
public void onEnable() { public void onEnable() {
@@ -84,7 +88,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
//delay dependency setup because we load the plugin very early where plugins are initialized yet //delay dependency setup because we load the plugin very early where plugins are initialized yet
getServer().getScheduler().runTaskLater(this, new DelayedAuthHook(this), 5L); getServer().getScheduler().runTaskLater(this, new DelayedAuthHook(this), 5L);
pluginManager.registerEvents(new JoinListener(this), this); pluginManager.registerEvents(new ConnectionListener(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));
@@ -99,6 +103,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
@Override @Override
public void onDisable() { public void onDisable() {
loginSession.clear(); loginSession.clear();
premiumPlayers.clear();
if (core != null) { if (core != null) {
core.close(); core.close();
@@ -122,6 +127,10 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
return loginSession; return loginSession;
} }
public Map<UUID, PremiumStatus> getPremiumPlayers() {
return premiumPlayers;
}
public boolean isBungeeEnabled() { public boolean isBungeeEnabled() {
return bungeeCord; return bungeeCord;
} }

View File

@@ -3,9 +3,10 @@ package com.github.games647.fastlogin.bukkit.listener;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession; import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit; import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.bukkit.tasks.ForceLoginTask; import com.github.games647.fastlogin.bukkit.tasks.ForceLoginTask;
import com.github.games647.fastlogin.core.PremiumStatus;
import com.github.games647.fastlogin.core.hooks.AuthPlugin; import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.github.games647.fastlogin.core.messages.ForceActionMessage; import com.github.games647.fastlogin.core.messages.LoginActionMessage;
import com.github.games647.fastlogin.core.messages.ForceActionMessage.Type; import com.github.games647.fastlogin.core.messages.LoginActionMessage.Type;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
@@ -51,12 +52,12 @@ public class BungeeListener implements PluginMessageListener {
ByteArrayDataInput dataInput = ByteStreams.newDataInput(message); ByteArrayDataInput dataInput = ByteStreams.newDataInput(message);
String subChannel = dataInput.readUTF(); String subChannel = dataInput.readUTF();
if (!"FORCE_ACTION".equals(subChannel)) { if (!"LoginAction".equals(subChannel)) {
plugin.getLog().info("Unknown sub channel {}", subChannel); plugin.getLog().info("Unknown sub channel {}", subChannel);
return; return;
} }
ForceActionMessage loginMessage = new ForceActionMessage(); LoginActionMessage loginMessage = new LoginActionMessage();
loginMessage.readFrom(dataInput); loginMessage.readFrom(dataInput);
plugin.getLog().debug("Received plugin message {}", loginMessage); plugin.getLog().debug("Received plugin message {}", loginMessage);
@@ -81,18 +82,23 @@ public class BungeeListener implements PluginMessageListener {
} }
} }
private void readMessage(Player player, ForceActionMessage message) { private void readMessage(Player player, LoginActionMessage message) {
String playerName = message.getPlayerName(); String playerName = message.getPlayerName();
Type type = message.getType(); Type type = message.getType();
InetSocketAddress address = player.getAddress(); InetSocketAddress address = player.getAddress();
String id = '/' + address.getAddress().getHostAddress() + ':' + address.getPort(); String id = '/' + address.getAddress().getHostAddress() + ':' + address.getPort();
if (type == Type.LOGIN) { if (type == Type.LOGIN) {
plugin.getPremiumPlayers().put(player.getUniqueId(), PremiumStatus.PREMIUM);
BukkitLoginSession playerSession = new BukkitLoginSession(playerName, true); BukkitLoginSession playerSession = new BukkitLoginSession(playerName, true);
playerSession.setVerified(true); playerSession.setVerified(true);
plugin.getLoginSessions().put(id, playerSession); plugin.getLoginSessions().put(id, playerSession);
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new ForceLoginTask(plugin.getCore(), player), 20L); Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new ForceLoginTask(plugin.getCore(), player), 20L);
} else if (type == Type.REGISTER) { } else if (type == Type.REGISTER) {
plugin.getPremiumPlayers().put(player.getUniqueId(), PremiumStatus.PREMIUM);
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> { Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook(); AuthPlugin<Player> authPlugin = plugin.getCore().getAuthPluginHook();
try { try {
@@ -107,6 +113,8 @@ public class BungeeListener implements PluginMessageListener {
plugin.getLog().error("Failed to query isRegistered for player: {}", player, ex); plugin.getLog().error("Failed to query isRegistered for player: {}", player, ex);
} }
}, 20L); }, 20L);
} else if (type == Type.CRACKED) {
plugin.getPremiumPlayers().put(player.getUniqueId(), PremiumStatus.CRACKED);
} }
} }

View File

@@ -17,13 +17,13 @@ import org.bukkit.event.player.PlayerQuitEvent;
* This listener tells authentication plugins if the player has a premium account and we checked it successfully. So the * This listener tells authentication plugins if the player has a premium account and we checked it successfully. So the
* plugin can skip authentication. * plugin can skip authentication.
*/ */
public class JoinListener implements Listener { public class ConnectionListener implements Listener {
private static final long DELAY_LOGIN = 20L / 2; private static final long DELAY_LOGIN = 20L / 2;
private final FastLoginBukkit plugin; private final FastLoginBukkit plugin;
public JoinListener(FastLoginBukkit plugin) { public ConnectionListener(FastLoginBukkit plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
@@ -51,5 +51,6 @@ public class JoinListener implements Listener {
player.removeMetadata(plugin.getName(), plugin); player.removeMetadata(plugin.getName(), plugin);
plugin.getCore().getPendingConfirms().remove(player.getUniqueId()); plugin.getCore().getPendingConfirms().remove(player.getUniqueId());
plugin.getPremiumPlayers().remove(player.getUniqueId());
} }
} }

View File

@@ -22,7 +22,6 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
public boolean forceLogin(ProxiedPlayer player) { public boolean forceLogin(ProxiedPlayer player) {
String playerName = player.getName(); String playerName = player.getName();
return Main.plonline.contains(playerName) || requestHandler.forceLogin(playerName); return Main.plonline.contains(playerName) || requestHandler.forceLogin(playerName);
} }
@Override @Override

View File

@@ -1,5 +1,6 @@
package com.github.games647.fastlogin.bungee.listener; package com.github.games647.fastlogin.bungee.listener;
import com.github.games647.craftapi.UUIDAdapter;
import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.bungee.tasks.AsyncPremiumCheck; import com.github.games647.fastlogin.bungee.tasks.AsyncPremiumCheck;
import com.github.games647.fastlogin.bungee.tasks.ForceLoginTask; import com.github.games647.fastlogin.bungee.tasks.ForceLoginTask;

View File

@@ -56,9 +56,9 @@ public class MessageListener implements Listener {
ByteArrayDataInput dataInput = ByteStreams.newDataInput(data); ByteArrayDataInput dataInput = ByteStreams.newDataInput(data);
String subChannel = dataInput.readUTF(); String subChannel = dataInput.readUTF();
if ("SUCCESS".equals(subChannel)) { if ("Success".equals(subChannel)) {
onSuccessMessage(forPlayer); onSuccessMessage(forPlayer);
} else if ("CHANGE".equals(subChannel)) { } else if ("ChangeStatus".equals(subChannel)) {
ChangePremiumMessage changeMessage = new ChangePremiumMessage(); ChangePremiumMessage changeMessage = new ChangePremiumMessage();
changeMessage.readFrom(dataInput); changeMessage.readFrom(dataInput);

View File

@@ -3,8 +3,8 @@ package com.github.games647.fastlogin.bungee.tasks;
import com.github.games647.fastlogin.bungee.BungeeLoginSession; import com.github.games647.fastlogin.bungee.BungeeLoginSession;
import com.github.games647.fastlogin.bungee.FastLoginBungee; import com.github.games647.fastlogin.bungee.FastLoginBungee;
import com.github.games647.fastlogin.core.messages.ChannelMessage; import com.github.games647.fastlogin.core.messages.ChannelMessage;
import com.github.games647.fastlogin.core.messages.ForceActionMessage; import com.github.games647.fastlogin.core.messages.LoginActionMessage;
import com.github.games647.fastlogin.core.messages.ForceActionMessage.Type; import com.github.games647.fastlogin.core.messages.LoginActionMessage.Type;
import com.github.games647.fastlogin.core.shared.FastLoginCore; import com.github.games647.fastlogin.core.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.ForceLoginManagement; import com.github.games647.fastlogin.core.shared.ForceLoginManagement;
import com.github.games647.fastlogin.core.shared.LoginSession; import com.github.games647.fastlogin.core.shared.LoginSession;
@@ -66,7 +66,7 @@ public class ForceLoginTask
} }
UUID proxyId = UUID.fromString(ProxyServer.getInstance().getConfig().getUuid()); UUID proxyId = UUID.fromString(ProxyServer.getInstance().getConfig().getUuid());
ChannelMessage loginMessage = new ForceActionMessage(type, player.getName(), proxyId); ChannelMessage loginMessage = new LoginActionMessage(type, player.getName(), proxyId);
core.getPlugin().sendPluginMessage(server, loginMessage); core.getPlugin().sendPluginMessage(server, loginMessage);
} }

View File

@@ -0,0 +1,10 @@
package com.github.games647.fastlogin.core;
public enum PremiumStatus {
PREMIUM,
CRACKED,
UNKNOWN
}

View File

@@ -33,7 +33,7 @@ public class ChangePremiumMessage implements ChannelMessage {
@Override @Override
public String getChannelName() { public String getChannelName() {
return "CHANGE"; return "ChangeStatus";
} }
@Override @Override

View File

@@ -5,20 +5,20 @@ import com.google.common.io.ByteArrayDataOutput;
import java.util.UUID; import java.util.UUID;
public class ForceActionMessage implements ChannelMessage { public class LoginActionMessage implements ChannelMessage {
private Type type; private Type type;
private String playerName; private String playerName;
private UUID proxyId; private UUID proxyId;
public ForceActionMessage(Type type, String playerName, UUID proxyId) { public LoginActionMessage(Type type, String playerName, UUID proxyId) {
this.type = type; this.type = type;
this.playerName = playerName; this.playerName = playerName;
this.proxyId = proxyId; this.proxyId = proxyId;
} }
public ForceActionMessage() { public LoginActionMessage() {
//reading mode //reading mode
} }
@@ -60,7 +60,7 @@ public class ForceActionMessage implements ChannelMessage {
@Override @Override
public String getChannelName() { public String getChannelName() {
return "FORCE_ACTION"; return "LoginAction";
} }
@Override @Override
@@ -76,6 +76,8 @@ public class ForceActionMessage implements ChannelMessage {
LOGIN, LOGIN,
REGISTER REGISTER,
CRACKED
} }
} }

View File

@@ -7,7 +7,7 @@ public class SuccessMessage implements ChannelMessage {
@Override @Override
public String getChannelName() { public String getChannelName() {
return "SUCCESS"; return "Success";
} }
@Override @Override