mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 18:57:31 +02:00
Finish basic bukkit support
This commit is contained in:
@ -13,13 +13,11 @@ import com.github.games647.fastlogin.bukkit.listener.EncryptionPacketListener;
|
|||||||
import com.github.games647.fastlogin.bukkit.listener.ProtocolSupportListener;
|
import com.github.games647.fastlogin.bukkit.listener.ProtocolSupportListener;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.StartPacketListener;
|
import com.github.games647.fastlogin.bukkit.listener.StartPacketListener;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import com.google.common.reflect.ClassPath;
|
import com.google.common.reflect.ClassPath;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -46,8 +44,7 @@ public class FastLoginBukkit extends JavaPlugin {
|
|||||||
//provide a immutable key pair to be thread safe | used for encrypting and decrypting traffic
|
//provide a immutable key pair to be thread safe | used for encrypting and decrypting traffic
|
||||||
private final KeyPair keyPair = EncryptionUtil.generateKeyPair();
|
private final KeyPair keyPair = EncryptionUtil.generateKeyPair();
|
||||||
|
|
||||||
//we need a thread-safe set because we access it async in the packet listener
|
private static final int WORKER_THREADS = 5;
|
||||||
private final Set<String> enabledPremium = Sets.newConcurrentHashSet();
|
|
||||||
|
|
||||||
private boolean bungeeCord;
|
private boolean bungeeCord;
|
||||||
private Storage storage;
|
private Storage storage;
|
||||||
@ -122,8 +119,12 @@ public class FastLoginBukkit extends JavaPlugin {
|
|||||||
|
|
||||||
//we are performing HTTP request on these so run it async (seperate from the Netty IO threads)
|
//we are performing HTTP request on these so run it async (seperate from the Netty IO threads)
|
||||||
AsynchronousManager asynchronousManager = protocolManager.getAsynchronousManager();
|
AsynchronousManager asynchronousManager = protocolManager.getAsynchronousManager();
|
||||||
asynchronousManager.registerAsyncHandler(new StartPacketListener(this, protocolManager)).start();
|
|
||||||
asynchronousManager.registerAsyncHandler(new EncryptionPacketListener(this, protocolManager)).start();
|
StartPacketListener startPacketListener = new StartPacketListener(this, protocolManager);
|
||||||
|
EncryptionPacketListener encryptionPacketListener = new EncryptionPacketListener(this, protocolManager);
|
||||||
|
|
||||||
|
asynchronousManager.registerAsyncHandler(startPacketListener).start(WORKER_THREADS);
|
||||||
|
asynchronousManager.registerAsyncHandler(encryptionPacketListener).start(WORKER_THREADS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,13 +173,8 @@ public class FastLoginBukkit extends JavaPlugin {
|
|||||||
return keyPair;
|
return keyPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Storage getStorage() {
|
||||||
* Gets a set of user who activated premium logins
|
return storage;
|
||||||
*
|
|
||||||
* @return user who activated premium logins
|
|
||||||
*/
|
|
||||||
public Set<String> getEnabledPremium() {
|
|
||||||
return enabledPremium;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,8 +227,4 @@ public class FastLoginBukkit extends JavaPlugin {
|
|||||||
authPlugin = authPluginHook;
|
authPlugin = authPluginHook;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBungee() {
|
|
||||||
return bungeeCord;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -38,23 +38,34 @@ public class MojangApiConnector {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPremiumName(String playerName) {
|
/**
|
||||||
|
*
|
||||||
|
* @param playerName
|
||||||
|
* @return null on non-premium
|
||||||
|
*/
|
||||||
|
public UUID getPremiumUUID(String playerName) {
|
||||||
//check if it's a valid playername
|
//check if it's a valid playername
|
||||||
if (playernameMatcher.matcher(playerName).matches()) {
|
if (playernameMatcher.matcher(playerName).matches()) {
|
||||||
//only make a API call if the name is valid existing mojang account
|
//only make a API call if the name is valid existing mojang account
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = getConnection(UUID_LINK + playerName);
|
HttpURLConnection connection = getConnection(UUID_LINK + playerName);
|
||||||
int responseCode = connection.getResponseCode();
|
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
return responseCode == HttpURLConnection.HTTP_OK;
|
String line = reader.readLine();
|
||||||
|
if (line != null && !line.equals("null")) {
|
||||||
|
JSONObject userData = (JSONObject) JSONValue.parseWithException(line);
|
||||||
|
String uuid = (String) userData.get("id");
|
||||||
|
return parseId(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
//204 - no content for not found
|
//204 - no content for not found
|
||||||
} catch (IOException ex) {
|
} catch (Exception ex) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "Failed to check if player has a paid account", ex);
|
plugin.getLogger().log(Level.SEVERE, "Failed to check if player has a paid account", ex);
|
||||||
}
|
}
|
||||||
//this connection doesn't need to be closed. So can make use of keep alive in java
|
//this connection doesn't need to be closed. So can make use of keep alive in java
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasJoinedServer(PlayerSession session, String serverId) {
|
public boolean hasJoinedServer(PlayerSession session, String serverId) {
|
||||||
|
@ -4,11 +4,11 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class PlayerProfile {
|
public class PlayerProfile {
|
||||||
|
|
||||||
private final UUID uuid;
|
|
||||||
private final String playerName;
|
private final String playerName;
|
||||||
|
|
||||||
private long userId;
|
private long userId;
|
||||||
|
|
||||||
|
private UUID uuid;
|
||||||
private boolean premium;
|
private boolean premium;
|
||||||
private String lastIp;
|
private String lastIp;
|
||||||
private long lastLogin;
|
private long lastLogin;
|
||||||
@ -32,6 +32,10 @@ public class PlayerProfile {
|
|||||||
this.lastIp = lastIp;
|
this.lastIp = lastIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPlayerName() {
|
||||||
|
return playerName;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized long getUserId() {
|
public synchronized long getUserId() {
|
||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
@ -40,27 +44,27 @@ public class PlayerProfile {
|
|||||||
this.userId = generatedId;
|
this.userId = generatedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUuid() {
|
public synchronized UUID getUuid() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlayerName() {
|
public synchronized void setUuid(UUID uuid) {
|
||||||
return playerName;
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPremium() {
|
public synchronized boolean isPremium() {
|
||||||
return premium;
|
return premium;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPremium(boolean premium) {
|
public synchronized void setPremium(boolean premium) {
|
||||||
this.premium = premium;
|
this.premium = premium;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastIp() {
|
public synchronized String getLastIp() {
|
||||||
return lastIp;
|
return lastIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastIp(String lastIp) {
|
public synchronized void setLastIp(String lastIp) {
|
||||||
this.lastIp = lastIp;
|
this.lastIp = lastIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +72,7 @@ public class PlayerProfile {
|
|||||||
return lastLogin;
|
return lastLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastLogin(long lastLogin) {
|
public synchronized void setLastLogin(long lastLogin) {
|
||||||
this.lastLogin = lastLogin;
|
this.lastLogin = lastLogin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class Storage {
|
|||||||
Statement statement = con.createStatement();
|
Statement statement = con.createStatement();
|
||||||
String createDataStmt = "CREATE TABLE IF NOT EXISTS " + PREMIUM_TABLE + " ("
|
String createDataStmt = "CREATE TABLE IF NOT EXISTS " + PREMIUM_TABLE + " ("
|
||||||
+ "`UserID` INTEGER PRIMARY KEY AUTO_INCREMENT, "
|
+ "`UserID` INTEGER PRIMARY KEY AUTO_INCREMENT, "
|
||||||
+ "`UUID` CHAR(36) NOT NULL, "
|
+ "`UUID` CHAR(36), "
|
||||||
+ "`Name` VARCHAR(16) NOT NULL, "
|
+ "`Name` VARCHAR(16) NOT NULL, "
|
||||||
+ "`Premium` BOOLEAN NOT NULL, "
|
+ "`Premium` BOOLEAN NOT NULL, "
|
||||||
+ "`LastIp` VARCHAR(255) NOT NULL, "
|
+ "`LastIp` VARCHAR(255) NOT NULL, "
|
||||||
@ -107,6 +107,10 @@ public class Storage {
|
|||||||
PlayerProfile playerProfile = new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin);
|
PlayerProfile playerProfile = new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin);
|
||||||
profileCache.put(name, playerProfile);
|
profileCache.put(name, playerProfile);
|
||||||
return playerProfile;
|
return playerProfile;
|
||||||
|
} else {
|
||||||
|
PlayerProfile crackedProfile = new PlayerProfile(null, name, false, "");
|
||||||
|
profileCache.put(name, crackedProfile);
|
||||||
|
return crackedProfile;
|
||||||
}
|
}
|
||||||
} catch (SQLException sqlEx) {
|
} catch (SQLException sqlEx) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "Failed to query profile", sqlEx);
|
plugin.getLogger().log(Level.SEVERE, "Failed to query profile", sqlEx);
|
||||||
@ -117,6 +121,40 @@ public class Storage {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// public PlayerProfile getProfile(UUID uuid, boolean fetch) {
|
||||||
|
// if (profileCache.containsKey(name)) {
|
||||||
|
// return profileCache.get(name);
|
||||||
|
// } else if (fetch) {
|
||||||
|
// Connection con = null;
|
||||||
|
// try {
|
||||||
|
// con = dataSource.getConnection();
|
||||||
|
// PreparedStatement loadStatement = con.prepareStatement("SELECT * FROM " + PREMIUM_TABLE
|
||||||
|
// + " WHERE `Name`=? LIMIT 1");
|
||||||
|
// loadStatement.setString(1, name);
|
||||||
|
//
|
||||||
|
// ResultSet resultSet = loadStatement.executeQuery();
|
||||||
|
// if (resultSet.next()) {
|
||||||
|
// long userId = resultSet.getInt(1);
|
||||||
|
// UUID uuid = FastLoginBukkit.parseId(resultSet.getString(2));
|
||||||
|
//// String name = resultSet.getString(3);
|
||||||
|
// boolean premium = resultSet.getBoolean(4);
|
||||||
|
// String lastIp = resultSet.getString(5);
|
||||||
|
// long lastLogin = resultSet.getTimestamp(6).getTime();
|
||||||
|
// PlayerProfile playerProfile = new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin);
|
||||||
|
// profileCache.put(name, playerProfile);
|
||||||
|
// return playerProfile;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //todo: result on failure
|
||||||
|
// } catch (SQLException sqlEx) {
|
||||||
|
// plugin.getLogger().log(Level.SEVERE, "Failed to query profile", sqlEx);
|
||||||
|
// } finally {
|
||||||
|
// closeQuietly(con);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
public boolean save(PlayerProfile playerProfile) {
|
public boolean save(PlayerProfile playerProfile) {
|
||||||
Connection con = null;
|
Connection con = null;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package com.github.games647.fastlogin.bukkit.commands;
|
package com.github.games647.fastlogin.bukkit.commands;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
|
import com.github.games647.fastlogin.bukkit.PlayerProfile;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -20,6 +22,11 @@ public class CrackedCommand implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (plugin.getStorage() == null) {
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "This command is disabled on the backend server");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
//console or command block
|
//console or command block
|
||||||
@ -27,10 +34,22 @@ public class CrackedCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String playerName = sender.getName();
|
Player player = (Player) sender;
|
||||||
boolean existed = plugin.getEnabledPremium().remove(playerName);
|
// UUID uuid = player.getUniqueId();
|
||||||
if (existed) {
|
|
||||||
|
//todo: load async if it's not in the cache anymore
|
||||||
|
final PlayerProfile profile = plugin.getStorage().getProfile(player.getName(), false);
|
||||||
|
if (profile.isPremium()) {
|
||||||
sender.sendMessage(ChatColor.DARK_GREEN + "Removed from the list of premium players");
|
sender.sendMessage(ChatColor.DARK_GREEN + "Removed from the list of premium players");
|
||||||
|
profile.setPremium(false);
|
||||||
|
profile.setUuid(null);
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
plugin.getStorage().save(profile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
notifiyBungeeCord((Player) sender);
|
notifiyBungeeCord((Player) sender);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "You are not in the premium list");
|
sender.sendMessage(ChatColor.DARK_RED + "You are not in the premium list");
|
||||||
@ -38,14 +57,16 @@ public class CrackedCommand implements CommandExecutor {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
String playerName = args[0];
|
sender.sendMessage(ChatColor.DARK_RED + "NOT IMPLEMENTED YET");
|
||||||
boolean existed = plugin.getEnabledPremium().remove(playerName);
|
//todo:
|
||||||
if (existed) {
|
// String playerName = args[0];
|
||||||
sender.sendMessage(ChatColor.DARK_GREEN + "Removed from the list of premium players");
|
// boolean existed = plugin.getEnabledPremium().remove(playerName);
|
||||||
|
// if (existed) {
|
||||||
|
// sender.sendMessage(ChatColor.DARK_GREEN + "Removed from the list of premium players");
|
||||||
// notifiyBungeeCord((Player) sender);
|
// notifiyBungeeCord((Player) sender);
|
||||||
} else {
|
// } else {
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "User is not in the premium list");
|
// sender.sendMessage(ChatColor.DARK_RED + "User is not in the premium list");
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.games647.fastlogin.bukkit.commands;
|
package com.github.games647.fastlogin.bukkit.commands;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
|
import com.github.games647.fastlogin.bukkit.PlayerProfile;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
@ -25,6 +26,11 @@ public class PremiumCommand implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (plugin.getStorage() == null) {
|
||||||
|
sender.sendMessage(ChatColor.DARK_RED + "This command is disabled on the backend server");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
//console or command block
|
//console or command block
|
||||||
@ -32,24 +38,31 @@ public class PremiumCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String playerName = sender.getName();
|
Player player = (Player) sender;
|
||||||
boolean didntexist = plugin.getEnabledPremium().add(playerName);
|
// UUID uuid = player.getUniqueId();
|
||||||
if (!didntexist) {
|
|
||||||
|
//todo: load async if it's not in the cache anymore
|
||||||
|
PlayerProfile profile = plugin.getStorage().getProfile(player.getName(), false);
|
||||||
|
if (profile.isPremium()) {
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "You are already on the premium list");
|
sender.sendMessage(ChatColor.DARK_RED + "You are already on the premium list");
|
||||||
} else {
|
} else {
|
||||||
|
//todo: resolve uuid
|
||||||
|
profile.setPremium(true);
|
||||||
sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players");
|
sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players");
|
||||||
}
|
}
|
||||||
|
|
||||||
notifiyBungeeCord((Player) sender);
|
notifiyBungeeCord((Player) sender);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
String playerName = args[0];
|
sender.sendMessage(ChatColor.DARK_RED + "NOT IMPLEMENTED YET");
|
||||||
boolean didntexist = plugin.getEnabledPremium().add(playerName);
|
//todo: async load
|
||||||
if (!didntexist) {
|
// String playerName = args[0];
|
||||||
sender.sendMessage(ChatColor.DARK_RED + "You are already on the premium list");
|
// boolean didntexist = plugin.getEnabledPremium().add(playerName);
|
||||||
} else {
|
// if (!didntexist) {
|
||||||
sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players");
|
// sender.sendMessage(ChatColor.DARK_RED + "You are already on the premium list");
|
||||||
}
|
// } else {
|
||||||
|
// sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players");
|
||||||
|
// }
|
||||||
// notifiyBungeeCord();
|
// notifiyBungeeCord();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,9 @@ package com.github.games647.fastlogin.bukkit.listener;
|
|||||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||||
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
|
import com.github.games647.fastlogin.bukkit.PlayerProfile;
|
||||||
import com.github.games647.fastlogin.bukkit.PlayerSession;
|
import com.github.games647.fastlogin.bukkit.PlayerSession;
|
||||||
|
import com.github.games647.fastlogin.bukkit.Storage;
|
||||||
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
|
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -65,7 +67,17 @@ public class BukkitJoinListener implements Listener {
|
|||||||
if (session.needsRegistration()) {
|
if (session.needsRegistration()) {
|
||||||
plugin.getLogger().log(Level.FINE, "Register player {0}", player.getName());
|
plugin.getLogger().log(Level.FINE, "Register player {0}", player.getName());
|
||||||
|
|
||||||
plugin.getEnabledPremium().add(session.getUsername());
|
final Storage storage = plugin.getStorage();
|
||||||
|
if (storage != null) {
|
||||||
|
final PlayerProfile playerProfile = storage.getProfile(session.getUsername(), false);
|
||||||
|
playerProfile.setPremium(true);
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
storage.save(playerProfile);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
String generatedPassword = plugin.generateStringPassword();
|
String generatedPassword = plugin.generateStringPassword();
|
||||||
authPlugin.forceRegister(player, generatedPassword);
|
authPlugin.forceRegister(player, generatedPassword);
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package com.github.games647.fastlogin.bukkit.listener;
|
package com.github.games647.fastlogin.bukkit.listener;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
|
import com.github.games647.fastlogin.bukkit.PlayerProfile;
|
||||||
import com.github.games647.fastlogin.bukkit.PlayerSession;
|
import com.github.games647.fastlogin.bukkit.PlayerSession;
|
||||||
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
|
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -26,19 +29,26 @@ public class ProtocolSupportListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String playerName = loginStartEvent.getName();
|
String username = loginStartEvent.getName();
|
||||||
|
|
||||||
//remove old data every time on a new login in order to keep the session only for one person
|
//remove old data every time on a new login in order to keep the session only for one person
|
||||||
plugin.getSessions().remove(playerName);
|
plugin.getSessions().remove(username);
|
||||||
|
|
||||||
|
PlayerProfile playerProfile = plugin.getStorage().getProfile(username, true);
|
||||||
|
if (playerProfile != null) {
|
||||||
|
//user not exists in the db
|
||||||
|
if (playerProfile.getUserId() == -1) {
|
||||||
BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
|
BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
|
||||||
if (plugin.getEnabledPremium().contains(playerName)) {
|
if (plugin.getConfig().getBoolean("autoRegister") && !authPlugin.isRegistered(username)) {
|
||||||
//the player have to be registered in order to invoke the command
|
UUID premiumUUID = plugin.getApiConnector().getPremiumUUID(username);
|
||||||
startPremiumSession(playerName, loginStartEvent, true);
|
if (premiumUUID != null) {
|
||||||
} else if (plugin.getConfig().getBoolean("autoRegister")
|
plugin.getLogger().log(Level.FINER, "Player {0} uses a premium username", username);
|
||||||
&& authPlugin != null && !plugin.getAuthPlugin().isRegistered(playerName)) {
|
startPremiumSession(username, loginStartEvent, false);
|
||||||
startPremiumSession(playerName, loginStartEvent, false);
|
}
|
||||||
plugin.getEnabledPremium().add(playerName);
|
}
|
||||||
|
} else if (playerProfile.isPremium()) {
|
||||||
|
startPremiumSession(username, loginStartEvent, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +65,6 @@ public class ProtocolSupportListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startPremiumSession(String playerName, PlayerLoginStartEvent loginStartEvent, boolean registered) {
|
private void startPremiumSession(String playerName, PlayerLoginStartEvent loginStartEvent, boolean registered) {
|
||||||
if (plugin.getApiConnector().isPremiumName(playerName)) {
|
|
||||||
loginStartEvent.setOnlineMode(true);
|
loginStartEvent.setOnlineMode(true);
|
||||||
InetSocketAddress address = loginStartEvent.getAddress();
|
InetSocketAddress address = loginStartEvent.getAddress();
|
||||||
|
|
||||||
@ -66,5 +75,4 @@ public class ProtocolSupportListener implements Listener {
|
|||||||
loginStartEvent.setUseOnlineModeUUID(true);
|
loginStartEvent.setUseOnlineModeUUID(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,14 @@ import com.comphenix.protocol.events.PacketAdapter;
|
|||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
|
import com.github.games647.fastlogin.bukkit.PlayerProfile;
|
||||||
import com.github.games647.fastlogin.bukkit.PlayerSession;
|
import com.github.games647.fastlogin.bukkit.PlayerSession;
|
||||||
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
|
import com.github.games647.fastlogin.bukkit.hooks.BukkitAuthPlugin;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -72,25 +74,29 @@ public class StartPacketListener extends PacketAdapter {
|
|||||||
String username = packet.getGameProfiles().read(0).getName();
|
String username = packet.getGameProfiles().read(0).getName();
|
||||||
plugin.getLogger().log(Level.FINER, "Player {0} with {1} connecting to the server"
|
plugin.getLogger().log(Level.FINER, "Player {0} with {1} connecting to the server"
|
||||||
, new Object[]{sessionKey, username});
|
, new Object[]{sessionKey, username});
|
||||||
if (!plugin.isBungee()) {
|
|
||||||
|
PlayerProfile playerProfile = plugin.getStorage().getProfile(username, true);
|
||||||
|
if (playerProfile != null) {
|
||||||
|
//user not exists in the db
|
||||||
|
if (playerProfile.getUserId() == -1) {
|
||||||
BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
|
BukkitAuthPlugin authPlugin = plugin.getAuthPlugin();
|
||||||
if (plugin.getEnabledPremium().contains(username)) {
|
if (plugin.getConfig().getBoolean("autoRegister") && !authPlugin.isRegistered(username)) {
|
||||||
enablePremiumLogin(username, sessionKey, player, packetEvent, true);
|
UUID premiumUUID = plugin.getApiConnector().getPremiumUUID(username);
|
||||||
} else if (plugin.getConfig().getBoolean("autoRegister")
|
if (premiumUUID != null) {
|
||||||
&& authPlugin != null && !plugin.getAuthPlugin().isRegistered(username)) {
|
plugin.getLogger().log(Level.FINER, "Player {0} uses a premium username", username);
|
||||||
enablePremiumLogin(username, sessionKey, player, packetEvent, false);
|
enablePremiumLogin(username, sessionKey, player, packetEvent, false);
|
||||||
plugin.getEnabledPremium().add(username);
|
}
|
||||||
|
}
|
||||||
|
} else if (playerProfile.isPremium()) {
|
||||||
|
enablePremiumLogin(username, sessionKey, player, packetEvent, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enablePremiumLogin(String username, String sessionKey, Player player, PacketEvent packetEvent
|
|
||||||
, boolean registered) {
|
|
||||||
if (plugin.getApiConnector().isPremiumName(username)) {
|
|
||||||
plugin.getLogger().log(Level.FINER, "Player {0} uses a premium username", username);
|
|
||||||
//minecraft server implementation
|
//minecraft server implementation
|
||||||
//https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/LoginListener.java#L161
|
//https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/LoginListener.java#L161
|
||||||
|
private void enablePremiumLogin(String username, String sessionKey, Player player, PacketEvent packetEvent
|
||||||
|
, boolean registered) {
|
||||||
//randomized server id to make sure the request is for our server
|
//randomized server id to make sure the request is for our server
|
||||||
//this could be relevant http://www.sk89q.com/2011/09/minecraft-name-spoofing-exploit/
|
//this could be relevant http://www.sk89q.com/2011/09/minecraft-name-spoofing-exploit/
|
||||||
String serverId = Long.toString(random.nextLong(), 16);
|
String serverId = Long.toString(random.nextLong(), 16);
|
||||||
@ -108,7 +114,6 @@ public class StartPacketListener extends PacketAdapter {
|
|||||||
packetEvent.setCancelled(true);
|
packetEvent.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private boolean sentEncryptionRequest(Player player, String serverId, byte[] verifyToken) {
|
private boolean sentEncryptionRequest(Player player, String serverId, byte[] verifyToken) {
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user