mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
Fixes storage bugs
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
######0.8
|
||||
|
||||
* Fixed BungeeCord support for the Bukkit module
|
||||
* Added database storage to save the premium state
|
||||
* Fix logical error on /premium (Thanks to @NorbiPeti)
|
||||
* Fixed issues with host lookup from hosts file (Thanks to @NorbiPeti)
|
||||
* Remove handshake listener because it creates errors on some systems
|
||||
|
@ -227,4 +227,8 @@ public class FastLoginBukkit extends JavaPlugin {
|
||||
authPlugin = authPluginHook;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isBungeeCord() {
|
||||
return bungeeCord;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -99,7 +98,15 @@ public class Storage {
|
||||
ResultSet resultSet = loadStatement.executeQuery();
|
||||
if (resultSet.next()) {
|
||||
long userId = resultSet.getInt(1);
|
||||
UUID uuid = FastLoginBukkit.parseId(resultSet.getString(2));
|
||||
|
||||
String unparsedUUID = resultSet.getString(2);
|
||||
UUID uuid;
|
||||
if (unparsedUUID == null) {
|
||||
uuid = null;
|
||||
} else {
|
||||
uuid = FastLoginBukkit.parseId(unparsedUUID);
|
||||
}
|
||||
|
||||
// String name = resultSet.getString(3);
|
||||
boolean premium = resultSet.getBoolean(4);
|
||||
String lastIp = resultSet.getString(5);
|
||||
@ -122,38 +129,7 @@ public class Storage {
|
||||
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;
|
||||
//todo
|
||||
// }
|
||||
|
||||
public boolean save(PlayerProfile playerProfile) {
|
||||
@ -161,11 +137,18 @@ public class Storage {
|
||||
try {
|
||||
con = dataSource.getConnection();
|
||||
|
||||
UUID uuid = playerProfile.getUuid();
|
||||
|
||||
if (playerProfile.getUserId() == -1) {
|
||||
PreparedStatement saveStatement = con.prepareStatement("INSERT INTO " + PREMIUM_TABLE
|
||||
+ " (UUID, Name, Premium, LastIp) VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
saveStatement.setString(1, playerProfile.getUuid().toString().replace("-", ""));
|
||||
if (uuid == null) {
|
||||
saveStatement.setString(1, null);
|
||||
} else {
|
||||
saveStatement.setString(1, uuid.toString().replace("-", ""));
|
||||
}
|
||||
|
||||
saveStatement.setString(2, playerProfile.getPlayerName());
|
||||
saveStatement.setBoolean(3, playerProfile.isPremium());
|
||||
saveStatement.setString(4, playerProfile.getLastIp());
|
||||
@ -177,15 +160,20 @@ public class Storage {
|
||||
}
|
||||
} else {
|
||||
PreparedStatement saveStatement = con.prepareStatement("UPDATE " + PREMIUM_TABLE
|
||||
+ " SET UUID=?, Name=?, Premium=?, LastIp=?, LastLogin=? WHERE UserID=?");
|
||||
+ " SET UUID=?, Name=?, Premium=?, LastIp=?, LastLogin=CURRENT_TIMESTAMP WHERE UserID=?");
|
||||
|
||||
if (uuid == null) {
|
||||
saveStatement.setString(1, null);
|
||||
} else {
|
||||
saveStatement.setString(1, uuid.toString().replace("-", ""));
|
||||
}
|
||||
|
||||
saveStatement.setString(1, playerProfile.getUuid().toString().replace("-", ""));
|
||||
saveStatement.setString(2, playerProfile.getPlayerName());
|
||||
saveStatement.setBoolean(3, playerProfile.isPremium());
|
||||
saveStatement.setString(4, playerProfile.getLastIp());
|
||||
saveStatement.setTimestamp(5, new Timestamp(playerProfile.getLastLogin()));
|
||||
// saveStatement.setTimestamp(5, new Timestamp(playerProfile.getLastLogin()));
|
||||
|
||||
saveStatement.setLong(6, playerProfile.getUserId());
|
||||
saveStatement.setLong(5, playerProfile.getUserId());
|
||||
saveStatement.execute();
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,8 @@ 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.ByteStreams;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class CrackedCommand implements CommandExecutor {
|
||||
|
||||
private final FastLoginBukkit plugin;
|
||||
protected final FastLoginBukkit plugin;
|
||||
|
||||
public CrackedCommand(FastLoginBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -34,11 +34,11 @@ public class CrackedCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
final Player player = (Player) sender;
|
||||
// UUID uuid = player.getUniqueId();
|
||||
|
||||
//todo: load async if it's not in the cache anymore
|
||||
final PlayerProfile profile = plugin.getStorage().getProfile(player.getName(), false);
|
||||
final PlayerProfile profile = plugin.getStorage().getProfile(player.getName(), true);
|
||||
if (profile.isPremium()) {
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Removed from the list of premium players");
|
||||
profile.setPremium(false);
|
||||
@ -73,9 +73,11 @@ public class CrackedCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void notifiyBungeeCord(Player target) {
|
||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||
dataOutput.writeUTF("OFF");
|
||||
if (plugin.isBungeeCord()) {
|
||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||
dataOutput.writeUTF("OFF");
|
||||
|
||||
target.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray());
|
||||
target.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.github.games647.fastlogin.bukkit.PlayerProfile;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -18,7 +19,7 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
public class PremiumCommand implements CommandExecutor {
|
||||
|
||||
private final FastLoginBukkit plugin;
|
||||
protected final FastLoginBukkit plugin;
|
||||
|
||||
public PremiumCommand(FastLoginBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -41,13 +42,19 @@ public class PremiumCommand implements CommandExecutor {
|
||||
Player player = (Player) sender;
|
||||
// UUID uuid = player.getUniqueId();
|
||||
|
||||
//todo: load async if it's not in the cache anymore
|
||||
PlayerProfile profile = plugin.getStorage().getProfile(player.getName(), false);
|
||||
// //todo: load async if it's not in the cache anymore
|
||||
final PlayerProfile profile = plugin.getStorage().getProfile(player.getName(), true);
|
||||
if (profile.isPremium()) {
|
||||
sender.sendMessage(ChatColor.DARK_RED + "You are already on the premium list");
|
||||
} else {
|
||||
//todo: resolve uuid
|
||||
profile.setPremium(true);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.getStorage().save(profile);
|
||||
}
|
||||
});
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Added to the list of premium players");
|
||||
}
|
||||
|
||||
@ -70,9 +77,11 @@ public class PremiumCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void notifiyBungeeCord(Player target) {
|
||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||
dataOutput.writeUTF("ON");
|
||||
if (plugin.isBungeeCord()) {
|
||||
ByteArrayDataOutput dataOutput = ByteStreams.newDataOutput();
|
||||
dataOutput.writeUTF("ON");
|
||||
|
||||
target.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray());
|
||||
target.sendPluginMessage(plugin, plugin.getName(), dataOutput.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,7 @@ public class BukkitJoinListener implements Listener {
|
||||
final Storage storage = plugin.getStorage();
|
||||
if (storage != null) {
|
||||
final PlayerProfile playerProfile = storage.getProfile(session.getUsername(), false);
|
||||
playerProfile.setUuid(session.getUuid());
|
||||
playerProfile.setPremium(true);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
@ -88,6 +89,18 @@ public class BukkitJoinListener implements Listener {
|
||||
plugin.getLogger().log(Level.FINE, "Logging player {0} in", player.getName());
|
||||
authPlugin.forceLogin(player);
|
||||
player.sendMessage(ChatColor.DARK_GREEN + "Auto logged in");
|
||||
|
||||
final Storage storage = plugin.getStorage();
|
||||
if (storage != null) {
|
||||
final PlayerProfile playerProfile = storage.getProfile(session.getUsername(), false);
|
||||
playerProfile.setUuid(session.getUuid());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
storage.save(playerProfile);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ autoRegister: false
|
||||
# Moreover you may want to convert the offline UUID to a premium UUID. This will ensure that the player
|
||||
# will have the same inventory, permissions, ... if they switched to premium authentification from offline/cracked
|
||||
# authentification.
|
||||
#
|
||||
# This feature requires Cauldron, Spigot or a fork of Spigot (PaperSpigot, TacoSpigot)
|
||||
premiumUuid: false
|
||||
|
||||
# If your players have a premium account and a skin associated to their account, this plugin
|
||||
@ -49,6 +51,9 @@ premiumUuid: false
|
||||
# This means this plugin doesn't need to create a new connection to the Mojang servers, because
|
||||
# the skin data is included in the Auth-Verification-Response sent by Mojang. If you want to use for other
|
||||
# players like cracked player, you have to use other plugins.
|
||||
#
|
||||
# If you want to use skins for your cracked player, you need an additional plugin like
|
||||
# ChangeSkin, SKinRestoer, ...
|
||||
forwardSkin: true
|
||||
|
||||
# Database configuration
|
||||
@ -63,6 +68,6 @@ database: '{pluginDir}/FastLogin.db'
|
||||
#driver: com.mysql.jdbc.Driver
|
||||
#host: localhost
|
||||
#port: 3306
|
||||
#database: FastLogin
|
||||
#database: fastlogin
|
||||
#username: myUser
|
||||
#password: myPassword
|
Reference in New Issue
Block a user