forked from TuxCoding/FastLogin
A few code styling things
This commit is contained in:
@ -65,11 +65,6 @@ public class BukkitCore extends FastLoginCore<Player> {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig() {
|
||||
plugin.saveDefaultConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MojangApiConnector makeApiConnector(Logger logger, List<String> addresses, int requests) {
|
||||
return new MojangApiBukkit(logger, addresses, requests);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.games647.fastlogin.bukkit;
|
||||
|
||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||
import com.github.games647.fastlogin.core.shared.LoginSession;
|
||||
import com.github.games647.fastlogin.core.shared.MojangApiConnector;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -24,11 +25,7 @@ public class MojangApiBukkit extends MojangApiConnector {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasJoinedServer(Object session, String serverId) {
|
||||
if (!(session instanceof BukkitLoginSession)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasJoinedServer(LoginSession session, String serverId) {
|
||||
BukkitLoginSession playerSession = (BukkitLoginSession) session;
|
||||
try {
|
||||
String url = HAS_JOINED_URL + "username=" + playerSession.getUsername() + "&serverId=" + serverId;
|
||||
|
@ -24,6 +24,7 @@ public class AuthMeHook implements AuthPlugin<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean forceLogin(Player player) {
|
||||
//skips registration and login
|
||||
if (isNewAPIAvailable) {
|
||||
@ -36,6 +37,7 @@ public class AuthMeHook implements AuthPlugin<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isRegistered(String playerName) throws Exception {
|
||||
if (isNewAPIAvailable) {
|
||||
return NewAPI.getInstance().isRegistered(playerName);
|
||||
@ -45,6 +47,7 @@ public class AuthMeHook implements AuthPlugin<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean forceRegister(Player player, String password) {
|
||||
if (isNewAPIAvailable) {
|
||||
NewAPI.getInstance().forceRegister(player, password);
|
||||
|
@ -102,8 +102,6 @@ public class BungeeCordListener implements PluginMessageListener {
|
||||
|
||||
public Set<UUID> loadBungeeCordIds() {
|
||||
File whitelistFile = new File(plugin.getDataFolder(), FILE_NAME);
|
||||
//create a new folder if it doesn't exist. Fail silently otherwise
|
||||
whitelistFile.getParentFile().mkdir();
|
||||
try {
|
||||
if (!whitelistFile.exists()) {
|
||||
whitelistFile.createNewFile();
|
||||
|
@ -23,7 +23,8 @@ import net.md_5.bungee.config.YamlConfiguration;
|
||||
public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
|
||||
|
||||
private static Map<String, Object> generateConfigMap(Configuration config) {
|
||||
return config.getKeys().stream().filter(key -> config.get(key) != null)
|
||||
return config.getKeys().stream()
|
||||
.filter(key -> config.get(key) != null)
|
||||
.collect(Collectors.toMap(key -> key, config::get));
|
||||
}
|
||||
|
||||
@ -46,13 +47,15 @@ public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public ThreadFactory getThreadFactory() {
|
||||
String pluginName = plugin.getDescription().getName();
|
||||
return new ThreadFactoryBuilder()
|
||||
.setNameFormat(pluginName + " Database Pool Thread #%1$d")
|
||||
//Hikari create daemons by default
|
||||
.setDaemon(true)
|
||||
.setThreadFactory(new GroupedThreadFactory(plugin, pluginName)).build();
|
||||
.setThreadFactory(new GroupedThreadFactory(plugin, pluginName))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -77,15 +80,6 @@ public class BungeeCore extends FastLoginCore<ProxiedPlayer> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadConfig() {
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
plugin.saveDefaultFile("config.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public MojangApiConnector makeApiConnector(Logger logger, List<String> addresses, int requests) {
|
||||
return new MojangApiBungee(logger, addresses, requests);
|
||||
|
@ -48,7 +48,6 @@ public class FastLoginBungee extends Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
core.loadConfig();
|
||||
core.setApiConnector();
|
||||
core.loadMessages();
|
||||
|
||||
@ -73,6 +72,10 @@ public class FastLoginBungee extends Plugin {
|
||||
}
|
||||
|
||||
public void saveDefaultFile(String fileName) {
|
||||
if (!getDataFolder().exists()) {
|
||||
getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
File configFile = new File(getDataFolder(), fileName);
|
||||
if (!configFile.exists()) {
|
||||
InputStream in = getResourceAsStream(fileName);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.games647.fastlogin.bungee;
|
||||
|
||||
import com.github.games647.fastlogin.core.shared.LoginSession;
|
||||
import com.github.games647.fastlogin.core.shared.MojangApiConnector;
|
||||
|
||||
import java.util.List;
|
||||
@ -33,7 +34,7 @@ public class MojangApiBungee extends MojangApiConnector {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasJoinedServer(Object session, String serverId) {
|
||||
public boolean hasJoinedServer(LoginSession session, String serverId) {
|
||||
//this is not needed in Bungee
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class ForceLoginTask implements Runnable {
|
||||
BungeeLoginSession session = plugin.getSession().get(pendingConnection);
|
||||
|
||||
if (session == null || !player.isConnected()) {
|
||||
plugin.getLogger().log(Level.FINE, "Invalid session player {0} proparly left the server", player);
|
||||
plugin.getLogger().log(Level.FINE, "Invalid session player {0} propaly left the server", player);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -23,12 +23,7 @@ public class PlayerProfile {
|
||||
}
|
||||
|
||||
public PlayerProfile(UUID uuid, String playerName, boolean premium, String lastIp) {
|
||||
this.userId = -1;
|
||||
|
||||
this.uuid = uuid;
|
||||
this.playerName = playerName;
|
||||
this.premium = premium;
|
||||
this.lastIp = lastIp;
|
||||
this(-1, uuid, playerName, premium, lastIp, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public synchronized String getPlayerName() {
|
||||
|
@ -19,4 +19,8 @@ public class SharedConfig {
|
||||
public <T> T get(String path) {
|
||||
return get(path, null);
|
||||
}
|
||||
|
||||
public Map<String, Object> getConfigValues() {
|
||||
return configValues;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package com.github.games647.fastlogin.core.hooks;
|
||||
/**
|
||||
* Represents a supporting authentication plugin in BungeeCord and Bukkit/Spigot/... servers
|
||||
*
|
||||
* @param <T> either org.bukkit.entity.Player for Bukkit or net.md_5.bungee.api.connection.ProxiedPlayer for BungeeCord
|
||||
* @param <P> either org.bukkit.entity.Player for Bukkit or net.md_5.bungee.api.connection.ProxiedPlayer for BungeeCord
|
||||
*/
|
||||
public interface AuthPlugin<T> {
|
||||
public interface AuthPlugin<P> {
|
||||
|
||||
/**
|
||||
* Login the premium (paid account) player after the player joined successfully the server.
|
||||
@ -16,7 +16,7 @@ public interface AuthPlugin<T> {
|
||||
* @param player the player that needs to be logged in
|
||||
* @return if the operation was successful
|
||||
*/
|
||||
boolean forceLogin(T player);
|
||||
boolean forceLogin(P player);
|
||||
|
||||
/**
|
||||
* Forces a register in order to protect the paid account.
|
||||
@ -39,7 +39,7 @@ public interface AuthPlugin<T> {
|
||||
* @param password a strong random generated password
|
||||
* @return if the operation was successful
|
||||
*/
|
||||
boolean forceRegister(T player, String password);
|
||||
boolean forceRegister(P player, String password);
|
||||
|
||||
/**
|
||||
* Checks whether an account exists for this player name.
|
||||
|
@ -2,14 +2,14 @@ package com.github.games647.fastlogin.core.hooks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class DefaultPasswordGenerator<T> implements PasswordGenerator<T> {
|
||||
public class DefaultPasswordGenerator<P> implements PasswordGenerator<P> {
|
||||
|
||||
private static final char[] PASSWORD_CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
.toCharArray();
|
||||
private final Random random = new Random();
|
||||
|
||||
@Override
|
||||
public String getRandomPassword(T player) {
|
||||
public String getRandomPassword(P player) {
|
||||
StringBuilder generatedPassword = new StringBuilder(8);
|
||||
for (int i = 1; i <= 8; i++) {
|
||||
generatedPassword.append(PASSWORD_CHARACTERS[random.nextInt(PASSWORD_CHARACTERS.length - 1)]);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.github.games647.fastlogin.core.hooks;
|
||||
|
||||
public interface PasswordGenerator<T> {
|
||||
public interface PasswordGenerator<P> {
|
||||
|
||||
String getRandomPassword(T player);
|
||||
String getRandomPassword(P player);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public abstract class FastLoginCore<P> {
|
||||
|
||||
protected final Map<String, String> localeMessages = new ConcurrentHashMap<>();
|
||||
|
||||
private final ConcurrentMap<String, Object> pendingLogins;
|
||||
private final ConcurrentMap<String, Object> pendingLogins = FastLoginCore.buildCache(5, 0);
|
||||
private final Set<UUID> pendingConfirms = Sets.newHashSet();
|
||||
private final SharedConfig sharedConfig;
|
||||
|
||||
@ -72,7 +72,6 @@ public abstract class FastLoginCore<P> {
|
||||
private AuthPlugin<P> authPlugin;
|
||||
|
||||
public FastLoginCore(Map<String, Object> config) {
|
||||
this.pendingLogins = FastLoginCore.buildCache(5, 0);
|
||||
this.sharedConfig = new SharedConfig(config);
|
||||
}
|
||||
|
||||
@ -102,8 +101,6 @@ public abstract class FastLoginCore<P> {
|
||||
|
||||
public abstract void loadMessages();
|
||||
|
||||
public abstract void loadConfig();
|
||||
|
||||
public abstract MojangApiConnector makeApiConnector(Logger logger, List<String> addresses, int requests);
|
||||
|
||||
public boolean setupDatabase() {
|
||||
@ -165,7 +162,7 @@ public abstract class FastLoginCore<P> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public SharedConfig getSharedConfig() {
|
||||
public SharedConfig getConfig() {
|
||||
return sharedConfig;
|
||||
}
|
||||
|
||||
|
@ -23,13 +23,12 @@ public abstract class JoinManagement<T, S extends LoginSource> {
|
||||
return;
|
||||
}
|
||||
|
||||
SharedConfig sharedConfig = core.getSharedConfig();
|
||||
SharedConfig config = core.getConfig();
|
||||
|
||||
String ip = source.getAddress().getAddress().getHostAddress();
|
||||
try {
|
||||
if (profile.getUserId() == -1) {
|
||||
if (core.getPendingLogins().containsKey(ip + username)
|
||||
&& sharedConfig.get("secondAttemptCracked", false)) {
|
||||
if (core.getPendingLogins().containsKey(ip + username) && config.get("secondAttemptCracked", false)) {
|
||||
core.getLogger().log(Level.INFO, "Second attempt login -> cracked {0}", username);
|
||||
|
||||
//first login request failed so make a cracked session
|
||||
@ -38,20 +37,21 @@ public abstract class JoinManagement<T, S extends LoginSource> {
|
||||
}
|
||||
|
||||
UUID premiumUUID = null;
|
||||
if (sharedConfig.get("nameChangeCheck", false) || sharedConfig.get("autoRegister", false)) {
|
||||
if (config.get("nameChangeCheck", false) || config.get("autoRegister", false)) {
|
||||
core.getLogger().log(Level.FINER, "Player {0} uses a premium username", username);
|
||||
premiumUUID = core.getApiConnector().getPremiumUUID(username);
|
||||
}
|
||||
|
||||
if (premiumUUID == null
|
||||
|| (!checkNameChange(premiumUUID, source, username)
|
||||
&& !checkPremiumName(username, source, profile))) {
|
||||
|| (!checkNameChange(source, username, premiumUUID)
|
||||
&& !checkPremiumName(source, username, profile))) {
|
||||
//nothing detected the player as premium -> start a cracked session
|
||||
startCrackedSession(source, profile, username);
|
||||
}
|
||||
} else if (profile.isPremium()) {
|
||||
requestPremiumLogin(source, profile, username, true);
|
||||
} else {
|
||||
if (core.getSharedConfig().get("switchMode", false)) {
|
||||
if (core.getConfig().get("switchMode", false)) {
|
||||
source.kick(core.getMessage("switch-kick-message"));
|
||||
return;
|
||||
}
|
||||
@ -63,10 +63,8 @@ public abstract class JoinManagement<T, S extends LoginSource> {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkPremiumName(String username, S source, PlayerProfile profile) throws Exception {
|
||||
if (core.getSharedConfig().get("autoRegister", false)
|
||||
&& (authHook == null || !authHook.isRegistered(username))) {
|
||||
core.getLogger().log(Level.FINER, "Player {0} uses a premium username", username);
|
||||
private boolean checkPremiumName(S source, String username, PlayerProfile profile) throws Exception {
|
||||
if (core.getConfig().get("autoRegister", false) && (authHook == null || !authHook.isRegistered(username))) {
|
||||
requestPremiumLogin(source, profile, username, false);
|
||||
return true;
|
||||
}
|
||||
@ -74,9 +72,9 @@ public abstract class JoinManagement<T, S extends LoginSource> {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkNameChange(UUID premiumUUID, S source, String username) {
|
||||
private boolean checkNameChange(S source, String username, UUID premiumUUID) {
|
||||
//user not exists in the db
|
||||
if (core.getSharedConfig().get("nameChangeCheck", false)) {
|
||||
if (core.getConfig().get("nameChangeCheck", false)) {
|
||||
PlayerProfile profile = core.getStorage().loadProfile(premiumUUID);
|
||||
if (profile != null) {
|
||||
//uuid exists in the database
|
||||
|
@ -137,7 +137,7 @@ public abstract class MojangApiConnector {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean hasJoinedServer(Object session, String serverId);
|
||||
public abstract boolean hasJoinedServer(LoginSession session, String serverId);
|
||||
|
||||
protected abstract String getUUIDFromJson(String json);
|
||||
|
||||
|
Reference in New Issue
Block a user