forked from TuxCoding/FastLogin
Listen to the success of the bukkit module
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package com.github.games647.fastlogin.bukkit;
|
package com.github.games647.fastlogin.bukkit;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
|
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;
|
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
|
//check if it's the same player as we checked before
|
||||||
|
|
||||||
final BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
|
final BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
|
||||||
if (session == null || !player.getName().equals(session.getUsername()) || authPlugin == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Storage storage = plugin.getStorage();
|
Storage storage = plugin.getStorage();
|
||||||
PlayerProfile playerProfile = null;
|
PlayerProfile playerProfile = null;
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
playerProfile = storage.getProfile(session.getUsername(), false);
|
playerProfile = storage.getProfile(player.getName(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.isVerified()) {
|
if (session == null) {
|
||||||
boolean success = true;
|
//cracked player
|
||||||
if (playerProfile != null) {
|
if (playerProfile != null) {
|
||||||
playerProfile.setUuid(session.getUuid());
|
playerProfile.setUuid(null);
|
||||||
playerProfile.setPremium(true);
|
playerProfile.setPremium(false);
|
||||||
|
storage.save(playerProfile);
|
||||||
}
|
}
|
||||||
|
} else if (player.getName().equals(session.getUsername())) {
|
||||||
if (success) {
|
//premium player
|
||||||
if (session.needsRegistration()) {
|
if (authPlugin == null) {
|
||||||
if (forceRegister(authPlugin, player)) {
|
//maybe only bungeecord plugin
|
||||||
storage.save(playerProfile);
|
sendSuccessNotification();
|
||||||
}
|
} else {
|
||||||
} else {
|
boolean success = false;
|
||||||
if (forceLogin(authPlugin, player)) {
|
if (session.isVerified()) {
|
||||||
storage.save(playerProfile);
|
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");
|
player.sendMessage(ChatColor.DARK_GREEN + "Auto logged in");
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendSuccessNotification() {
|
||||||
|
if (plugin.isBungeeCord()) {
|
||||||
|
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||||
|
dataOutput.writeUTF("SUCCESS");
|
||||||
|
|
||||||
|
player.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ public class PremiumCommand implements CommandExecutor {
|
|||||||
plugin.getStorage().save(profile);
|
plugin.getStorage().save(profile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players");
|
sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,50 +23,49 @@ public class ForceLoginTask implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
PlayerProfile playerProfile = plugin.getStorage().getProfile(player.getName(), false);
|
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
|
//force login only on success
|
||||||
if (player.getPendingConnection().isOnlineMode()) {
|
if (player.getPendingConnection().isOnlineMode()) {
|
||||||
Server server = player.getServer();
|
|
||||||
|
|
||||||
boolean autoRegister = plugin.getPendingAutoRegister().remove(player.getPendingConnection()) != null;
|
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();
|
BungeeAuthPlugin authPlugin = plugin.getBungeeAuthPlugin();
|
||||||
if (authPlugin != null) {
|
if (authPlugin == null) {
|
||||||
|
sendBukkitLoginNotification(autoRegister);
|
||||||
|
} else {
|
||||||
if (autoRegister) {
|
if (autoRegister) {
|
||||||
String password = plugin.generateStringPassword();
|
String password = plugin.generateStringPassword();
|
||||||
if (authPlugin.forceRegister(player, password)) {
|
if (authPlugin.forceRegister(player, password)) {
|
||||||
plugin.getStorage().save(playerProfile);
|
sendBukkitLoginNotification(autoRegister);
|
||||||
}
|
}
|
||||||
} else if (authPlugin.forceLogin(player)) {
|
} else if (authPlugin.forceLogin(player)) {
|
||||||
plugin.getStorage().save(playerProfile);
|
sendBukkitLoginNotification(autoRegister);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//cracked player
|
||||||
|
//update only on success to prevent corrupt data
|
||||||
|
playerProfile.setPremium(false);
|
||||||
plugin.getStorage().save(playerProfile);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -139,6 +139,15 @@ public class PlayerConnectionListener implements Listener {
|
|||||||
plugin.getStorage().save(playerProfile);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user