Listen to the success of the bukkit module

This commit is contained in:
games647
2016-05-05 09:46:21 +02:00
parent 67a4f41056
commit d4f5b547d4
4 changed files with 80 additions and 50 deletions

View File

@ -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());
}
}
}

View File

@ -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");
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}
}
}