forked from TuxCoding/FastLogin
Migrate SLF4J logging (Fixes #177)
This commit is contained in:
@@ -13,7 +13,6 @@ import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class AuthStorage {
|
||||
|
||||
@@ -104,7 +103,7 @@ public class AuthStorage {
|
||||
}
|
||||
}
|
||||
} catch (SQLException sqlEx) {
|
||||
core.getPlugin().getLogger().log(Level.SEVERE, "Failed to query profile", sqlEx);
|
||||
core.getPlugin().getLog().error("Failed to query profile", sqlEx);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -128,7 +127,7 @@ public class AuthStorage {
|
||||
}
|
||||
}
|
||||
} catch (SQLException sqlEx) {
|
||||
core.getPlugin().getLogger().log(Level.SEVERE, "Failed to query profile", sqlEx);
|
||||
core.getPlugin().getLog().error("Failed to query profile", sqlEx);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -179,7 +178,7 @@ public class AuthStorage {
|
||||
|
||||
return true;
|
||||
} catch (SQLException ex) {
|
||||
core.getPlugin().getLogger().log(Level.SEVERE, "Failed to save playerProfile", ex);
|
||||
core.getPlugin().getLog().error("Failed to save playerProfile", ex);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -2,9 +2,15 @@ package com.github.games647.fastlogin.core;
|
||||
|
||||
import com.google.common.cache.CacheLoader;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.impl.JDK14LoggerAdapter;
|
||||
|
||||
public class CommonUtil {
|
||||
|
||||
@@ -47,6 +53,19 @@ public class CommonUtil {
|
||||
return new String(chars);
|
||||
}
|
||||
|
||||
public static Logger createLoggerFromJDK(java.util.logging.Logger parent) {
|
||||
try {
|
||||
Class<JDK14LoggerAdapter> adapterClass = JDK14LoggerAdapter.class;
|
||||
Constructor<JDK14LoggerAdapter> cons = adapterClass.getDeclaredConstructor(java.util.logging.Logger.class);
|
||||
cons.setAccessible(true);
|
||||
return cons.newInstance(parent);
|
||||
} catch (ReflectiveOperationException reflectEx) {
|
||||
parent.log(Level.WARNING, "Cannot create slf4j logging adapter", reflectEx);
|
||||
parent.log(Level.WARNING, "Creating logger instance manually...");
|
||||
return LoggerFactory.getLogger(parent.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private CommonUtil() {
|
||||
//Utility class
|
||||
}
|
||||
|
||||
+7
-7
@@ -27,24 +27,23 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class MojangApiConnector {
|
||||
|
||||
//http connection, read timeout and user agent for a connection to mojang api servers
|
||||
private static final int TIMEOUT = 3 * 1_000;
|
||||
private static final String USER_AGENT = "Premium-Checker";
|
||||
private static final int RATE_LIMIT_CODE = 429;
|
||||
|
||||
//only premium (paid account) users have a uuid from here
|
||||
private static final String UUID_LINK = "https://api.mojang.com/users/profiles/minecraft/";
|
||||
|
||||
private static final int RATE_LIMIT_CODE = 429;
|
||||
|
||||
//this includes a-zA-Z1-9_
|
||||
//compile the pattern only on plugin enable -> and this have to be thread-safe
|
||||
private final Pattern validNameMatcher = Pattern.compile("^\\w{2,16}$");
|
||||
@@ -53,6 +52,7 @@ public class MojangApiConnector {
|
||||
private final Map<Object, Object> requests = CommonUtil.buildCache(10, -1);
|
||||
private final SSLSocketFactory sslFactory;
|
||||
private final int rateLimit;
|
||||
|
||||
private long lastRateLimit;
|
||||
|
||||
protected final Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
|
||||
@@ -110,7 +110,7 @@ public class MojangApiConnector {
|
||||
}
|
||||
//204 - no content for not found
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, "Failed to check if player has a paid account", ex);
|
||||
logger.error("Failed to check if player has a paid account", ex);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
@@ -161,13 +161,13 @@ public class MojangApiConnector {
|
||||
try {
|
||||
InetAddress address = InetAddress.getByName(localAddress);
|
||||
if (!address.isAnyLocalAddress()) {
|
||||
logger.log(Level.WARNING, "Submitted IP-Address is not local {0}", address);
|
||||
logger.warn("Submitted IP-Address is not local {0}", address);
|
||||
continue;
|
||||
}
|
||||
|
||||
addresses.add(address);
|
||||
} catch (UnknownHostException ex) {
|
||||
logger.log(Level.SEVERE, "IP-Address is unknown to us", ex);
|
||||
logger.error("IP-Address is unknown to us", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
@@ -72,7 +71,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
||||
}
|
||||
});
|
||||
} catch (IOException ioEx) {
|
||||
plugin.getLogger().log(Level.INFO, "Failed to load yaml files", ioEx);
|
||||
plugin.getLog().error("Failed to load yaml files", ioEx);
|
||||
}
|
||||
|
||||
List<String> ipAddresses = config.getStringList("ip-addresses");
|
||||
@@ -134,7 +133,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
||||
storage.createTables();
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to setup database. Disabling plugin...", ex);
|
||||
plugin.getLog().warn("Failed to setup database. Disabling plugin...", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -180,7 +179,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
||||
}
|
||||
}
|
||||
} catch (IOException ioExc) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Cannot create plugin folder " + dataFolder, ioExc);
|
||||
plugin.getLog().error("Cannot create plugin folder {}", dataFolder, ioExc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -4,8 +4,6 @@ import com.github.games647.fastlogin.core.AuthStorage;
|
||||
import com.github.games647.fastlogin.core.PlayerProfile;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class ForceLoginManagement<P extends C, C, L extends LoginSession, T extends PlatformPlugin<C>>
|
||||
implements Runnable {
|
||||
|
||||
@@ -66,12 +64,12 @@ public abstract class ForceLoginManagement<P extends C, C, L extends LoginSessio
|
||||
storage.save(playerProfile);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
core.getPlugin().getLogger().log(Level.WARNING, "ERROR ON FORCE LOGIN", ex);
|
||||
core.getPlugin().getLog().warn("ERROR ON FORCE LOGIN", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean forceRegister(P player) {
|
||||
core.getPlugin().getLogger().log(Level.INFO, "Register player {0}", getName(player));
|
||||
core.getPlugin().getLog().info("Register player {}", getName(player));
|
||||
|
||||
String generatedPassword = core.getPasswordGenerator().getRandomPassword(player);
|
||||
boolean success = core.getAuthPluginHook().forceRegister(player, generatedPassword);
|
||||
@@ -86,7 +84,7 @@ public abstract class ForceLoginManagement<P extends C, C, L extends LoginSessio
|
||||
}
|
||||
|
||||
public boolean forceLogin(P player) {
|
||||
core.getPlugin().getLogger().log(Level.INFO, "Logging player {0} in", getName(player));
|
||||
core.getPlugin().getLog().info("Logging player {} in", getName(player));
|
||||
boolean success = core.getAuthPluginHook().forceLogin(player);
|
||||
|
||||
if (success) {
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
@@ -32,7 +31,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||
try {
|
||||
if (profile.getUserId() == -1) {
|
||||
if (core.getPendingLogin().remove(ip + username) != null && config.get("secondAttemptCracked", false)) {
|
||||
core.getPlugin().getLogger().log(Level.INFO, "Second attempt login -> cracked {0}", username);
|
||||
core.getPlugin().getLog().info("Second attempt login -> cracked {}", username);
|
||||
|
||||
//first login request failed so make a cracked session
|
||||
startCrackedSession(source, profile, username);
|
||||
@@ -61,12 +60,12 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||
startCrackedSession(source, profile, username);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
core.getPlugin().getLogger().log(Level.SEVERE, "Failed to check premium state", ex);
|
||||
core.getPlugin().getLog().error("Failed to check premium state", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkPremiumName(S source, String username, PlayerProfile profile) throws Exception {
|
||||
core.getPlugin().getLogger().log(Level.FINER, "GameProfile {0} uses a premium username", username);
|
||||
core.getPlugin().getLog().debug("GameProfile {} uses a premium username", username);
|
||||
if (core.getConfig().get("autoRegister", false) && (authHook == null || !authHook.isRegistered(username))) {
|
||||
requestPremiumLogin(source, profile, username, false);
|
||||
return true;
|
||||
@@ -81,7 +80,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||
PlayerProfile profile = core.getStorage().loadProfile(premiumUUID);
|
||||
if (profile != null) {
|
||||
//uuid exists in the database
|
||||
core.getPlugin().getLogger().log(Level.FINER, "GameProfile {0} changed it's username", premiumUUID);
|
||||
core.getPlugin().getLog().info("GameProfile {} changed it's username", premiumUUID);
|
||||
|
||||
//update the username to the new one in the database
|
||||
profile.setPlayerName(username);
|
||||
|
||||
@@ -6,7 +6,8 @@ import com.google.common.net.HostAndPort;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public interface PlatformPlugin<C> {
|
||||
|
||||
@@ -14,7 +15,7 @@ public interface PlatformPlugin<C> {
|
||||
|
||||
File getDataFolder();
|
||||
|
||||
Logger getLogger();
|
||||
Logger getLog();
|
||||
|
||||
void sendMessage(C receiver, String message);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user