From d4f5b547d494e9a0f617804287ff6f6f0cb51f4d Mon Sep 17 00:00:00 2001 From: games647 Date: Thu, 5 May 2016 09:46:21 +0200 Subject: [PATCH] Listen to the success of the bukkit module --- .../fastlogin/bukkit/ForceLoginTask.java | 60 +++++++++++++------ .../bukkit/commands/PremiumCommand.java | 2 +- .../fastlogin/bungee/ForceLoginTask.java | 59 +++++++++--------- .../bungee/PlayerConnectionListener.java | 9 +++ 4 files changed, 80 insertions(+), 50 deletions(-) diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java index d663c98a..7e725a30 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java @@ -1,6 +1,8 @@ package com.github.games647.fastlogin.bukkit; import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; import java.util.logging.Level; @@ -33,36 +35,47 @@ public class ForceLoginTask implements Runnable { //check if it's the same player as we checked before final BukkitAuthPlugin authPlugin = plugin.getAuthPlugin(); - if (session == null || !player.getName().equals(session.getUsername()) || authPlugin == null) { - return; - } Storage storage = plugin.getStorage(); PlayerProfile playerProfile = null; if (storage != null) { - playerProfile = storage.getProfile(session.getUsername(), false); + playerProfile = storage.getProfile(player.getName(), false); } - if (session.isVerified()) { - boolean success = true; + if (session == null) { + //cracked player if (playerProfile != null) { - playerProfile.setUuid(session.getUuid()); - playerProfile.setPremium(true); + playerProfile.setUuid(null); + playerProfile.setPremium(false); + storage.save(playerProfile); } - - if (success) { - if (session.needsRegistration()) { - if (forceRegister(authPlugin, player)) { - storage.save(playerProfile); - } - } else { - if (forceLogin(authPlugin, player)) { - storage.save(playerProfile); + } else if (player.getName().equals(session.getUsername())) { + //premium player + if (authPlugin == null) { + //maybe only bungeecord plugin + sendSuccessNotification(); + } else { + boolean success = false; + if (session.isVerified()) { + if (session.needsRegistration()) { + success = forceRegister(authPlugin, player); + } else { + success = forceLogin(authPlugin, player); } } + + if (success) { + //update only on success to prevent corrupt data + if (playerProfile != null) { + playerProfile.setUuid(session.getUuid()); + //save cracked players too + playerProfile.setPremium(session.isVerified()); + storage.save(playerProfile); + } + + sendSuccessNotification(); + } } - } else if (playerProfile != null) { - storage.save(playerProfile); } } @@ -82,4 +95,13 @@ public class ForceLoginTask implements Runnable { player.sendMessage(ChatColor.DARK_GREEN + "Auto logged in"); return success; } + + private void sendSuccessNotification() { + if (plugin.isBungeeCord()) { + ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); + dataOutput.writeUTF("SUCCESS"); + + player.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray()); + } + } } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java index 2e504d96..45635811 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/commands/PremiumCommand.java @@ -54,7 +54,7 @@ public class PremiumCommand implements CommandExecutor { plugin.getStorage().save(profile); } }); - + sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players"); } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/ForceLoginTask.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/ForceLoginTask.java index e7fbde70..d31f5d02 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/ForceLoginTask.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/ForceLoginTask.java @@ -23,50 +23,49 @@ public class ForceLoginTask implements Runnable { public void run() { PlayerProfile playerProfile = plugin.getStorage().getProfile(player.getName(), false); - if (playerProfile.getUserId() == -1) { - playerProfile.setPremium(player.getPendingConnection().isOnlineMode()); - if (player.getPendingConnection().isOnlineMode()) { - playerProfile.setUuid(player.getUniqueId()); - } - } - //force login only on success if (player.getPendingConnection().isOnlineMode()) { - Server server = player.getServer(); - boolean autoRegister = plugin.getPendingAutoRegister().remove(player.getPendingConnection()) != null; - ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); - //subchannel name - if (autoRegister) { - dataOutput.writeUTF("AUTO_REGISTER"); - } else { - dataOutput.writeUTF("AUTO_LOGIN"); - } - - //Data is sent through a random player. We have to tell the Bukkit version of this plugin the target - dataOutput.writeUTF(player.getName()); - - //proxy identifier to check if it's a acceptable proxy - UUID proxyId = UUID.fromString(plugin.getProxy().getConfig().getUuid()); - dataOutput.writeLong(proxyId.getMostSignificantBits()); - dataOutput.writeLong(proxyId.getLeastSignificantBits()); - - server.sendData(plugin.getDescription().getName(), dataOutput.toByteArray()); - BungeeAuthPlugin authPlugin = plugin.getBungeeAuthPlugin(); - if (authPlugin != null) { + if (authPlugin == null) { + sendBukkitLoginNotification(autoRegister); + } else { if (autoRegister) { String password = plugin.generateStringPassword(); if (authPlugin.forceRegister(player, password)) { - plugin.getStorage().save(playerProfile); + sendBukkitLoginNotification(autoRegister); } } else if (authPlugin.forceLogin(player)) { - plugin.getStorage().save(playerProfile); + sendBukkitLoginNotification(autoRegister); } } } else { + //cracked player + //update only on success to prevent corrupt data + playerProfile.setPremium(false); plugin.getStorage().save(playerProfile); } } + + private void sendBukkitLoginNotification(boolean autoRegister) { + ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput(); + //subchannel name + if (autoRegister) { + dataOutput.writeUTF("AUTO_REGISTER"); + } else { + dataOutput.writeUTF("AUTO_LOGIN"); + } + + //Data is sent through a random player. We have to tell the Bukkit version of this plugin the target + dataOutput.writeUTF(player.getName()); + + //proxy identifier to check if it's a acceptable proxy + UUID proxyId = UUID.fromString(plugin.getProxy().getConfig().getUuid()); + dataOutput.writeLong(proxyId.getMostSignificantBits()); + dataOutput.writeLong(proxyId.getLeastSignificantBits()); + + Server server = player.getServer(); + server.sendData(plugin.getDescription().getName(), dataOutput.toByteArray()); + } } diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java index 17f204b0..bbee4ceb 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerConnectionListener.java @@ -139,6 +139,15 @@ public class PlayerConnectionListener implements Listener { plugin.getStorage().save(playerProfile); } }); + } else if ("SUCCESS".equals(subchannel)) { + if (forPlayer.getPendingConnection().isOnlineMode()) { + //bukkit module successfully received and force logged in the user + //update only on success to prevent corrupt data + PlayerProfile playerProfile = plugin.getStorage().getProfile(forPlayer.getName(), false); + playerProfile.setPremium(true); + playerProfile.setUuid(forPlayer.getUniqueId()); + plugin.getStorage().save(playerProfile); + } } } }