mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-31 11:17:33 +02:00
Shade the Bungee-Config implementation because it's platform independent
This commit is contained in:
3
.github/ISSUE_TEMPLATE.md
vendored
3
.github/ISSUE_TEMPLATE.md
vendored
@ -22,4 +22,5 @@ This can be found by running `/version plugin-name`
|
|||||||
[Hastebin](https://hastebin.com/) / [Gist](https://gist.github.com/) link of the error or stacktrace (if any)
|
[Hastebin](https://hastebin.com/) / [Gist](https://gist.github.com/) link of the error or stacktrace (if any)
|
||||||
|
|
||||||
### Configuration:
|
### Configuration:
|
||||||
[Hastebin](https://hastebin.com/) / [Gist](https://gist.github.com/) link of your config.yml file (remember to delete any sensitive data)
|
[Hastebin](https://hastebin.com/) / [Gist](https://gist.github.com/) link of your config.yml file
|
||||||
|
(remember to delete any sensitive data)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.games647.fastlogin.bukkit;
|
package com.github.games647.fastlogin.bukkit;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.core.PlayerProfile;
|
import com.github.games647.fastlogin.core.PlayerProfile;
|
||||||
|
import com.github.games647.fastlogin.core.mojang.SkinProperties;
|
||||||
import com.github.games647.fastlogin.core.shared.LoginSession;
|
import com.github.games647.fastlogin.core.shared.LoginSession;
|
||||||
|
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
import org.apache.commons.lang.ArrayUtils;
|
||||||
@ -17,8 +18,7 @@ public class BukkitLoginSession extends LoginSession {
|
|||||||
|
|
||||||
private boolean verified;
|
private boolean verified;
|
||||||
|
|
||||||
private String encodedSkinData;
|
private SkinProperties skinProperty;
|
||||||
private String skinSignature;
|
|
||||||
|
|
||||||
public BukkitLoginSession(String username, String serverId, byte[] verifyToken, boolean registered
|
public BukkitLoginSession(String username, String serverId, byte[] verifyToken, boolean registered
|
||||||
, PlayerProfile profile) {
|
, PlayerProfile profile) {
|
||||||
@ -62,23 +62,15 @@ public class BukkitLoginSession extends LoginSession {
|
|||||||
return ArrayUtils.clone(verifyToken);
|
return ArrayUtils.clone(verifyToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String getEncodedSkinData() {
|
public synchronized SkinProperties getSkinProperty() {
|
||||||
return encodedSkinData;
|
return skinProperty;
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized String getSkinSignature() {
|
|
||||||
return skinSignature;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the premium skin property which was retrieved by the session server
|
* Sets the premium skin property which was retrieved by the session server
|
||||||
*
|
|
||||||
* @param encodedData
|
|
||||||
* @param skinSignature
|
|
||||||
*/
|
*/
|
||||||
public synchronized void setSkin(String encodedData, String skinSignature) {
|
public synchronized void setSkinProperty(SkinProperties skinProperty) {
|
||||||
this.encodedSkinData = encodedData;
|
this.skinProperty = skinProperty;
|
||||||
this.skinSignature = skinSignature;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,14 +8,13 @@ import com.github.games647.fastlogin.bukkit.listener.protocollib.LoginSkinApplyL
|
|||||||
import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener;
|
import com.github.games647.fastlogin.bukkit.listener.protocollib.ProtocolLibListener;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
|
import com.github.games647.fastlogin.bukkit.listener.protocolsupport.ProtocolSupportListener;
|
||||||
import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook;
|
import com.github.games647.fastlogin.bukkit.tasks.DelayedAuthHook;
|
||||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
|
||||||
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
||||||
|
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||||
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
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 java.io.Reader;
|
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -26,7 +25,6 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageRecipient;
|
import org.bukkit.plugin.messaging.PluginMessageRecipient;
|
||||||
@ -190,12 +188,6 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
|
|||||||
sender.sendPluginMessage(this, getName(), dataOutput.toByteArray());
|
sender.sendPluginMessage(this, getName(), dataOutput.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> loadYamlFile(Reader reader) {
|
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(reader);
|
|
||||||
return config.getValues(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(CommandSender receiver, String message) {
|
public void sendMessage(CommandSender receiver, String message) {
|
||||||
receiver.sendMessage(message);
|
receiver.sendMessage(message);
|
||||||
|
@ -50,10 +50,7 @@ public class MojangApiBukkit extends MojangApiConnector {
|
|||||||
SkinProperties[] properties = verification.getProperties();
|
SkinProperties[] properties = verification.getProperties();
|
||||||
if (properties != null && properties.length > 0) {
|
if (properties != null && properties.length > 0) {
|
||||||
SkinProperties skinProperty = properties[0];
|
SkinProperties skinProperty = properties[0];
|
||||||
|
playerSession.setSkinProperty(skinProperty);
|
||||||
String skinValue = skinProperty.getValue();
|
|
||||||
String signature = skinProperty.getSignature();
|
|
||||||
playerSession.setSkin(skinValue, signature);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -30,7 +30,7 @@ public class AuthMeHook implements AuthPlugin<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRegistered(String playerName) throws Exception {
|
public boolean isRegistered(String playerName) {
|
||||||
return AuthMeApi.getInstance().isRegistered(playerName);
|
return AuthMeApi.getInstance().isRegistered(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRegistered(String playerName) throws Exception {
|
public boolean isRegistered(String playerName) {
|
||||||
return crazyLoginPlugin.getPlayerData(playerName) != null;
|
return crazyLoginPlugin.getPlayerData(playerName) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public class LogItHook implements AuthPlugin<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRegistered(String playerName) throws Exception {
|
public boolean isRegistered(String playerName) {
|
||||||
return LogItCore.getInstance().getAccountManager().isRegistered(playerName);
|
return LogItCore.getInstance().getAccountManager().isRegistered(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class LoginSecurityHook implements AuthPlugin<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRegistered(String playerName) throws Exception {
|
public boolean isRegistered(String playerName) {
|
||||||
PlayerSession session = LoginSecurity.getSessionManager().getOfflineSession(playerName);
|
PlayerSession session = LoginSecurity.getSessionManager().getOfflineSession(playerName);
|
||||||
return session.isRegistered();
|
return session.isRegistered();
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class UltraAuthHook implements AuthPlugin<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRegistered(String playerName) throws Exception {
|
public boolean isRegistered(String playerName) {
|
||||||
return UltraAuthAPI.isRegisterd(playerName);
|
return UltraAuthAPI.isRegisterd(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public class xAuthHook implements AuthPlugin<Player> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRegistered(String playerName) throws Exception {
|
public boolean isRegistered(String playerName) {
|
||||||
//this will load the player if it's not in the cache
|
//this will load the player if it's not in the cache
|
||||||
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(playerName);
|
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(playerName);
|
||||||
return xAuthPlayer != null && xAuthPlayer.isRegistered();
|
return xAuthPlayer != null && xAuthPlayer.isRegistered();
|
||||||
|
@ -8,6 +8,7 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
|||||||
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
||||||
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
|
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
|
||||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||||
|
import com.github.games647.fastlogin.core.mojang.SkinProperties;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -45,10 +46,8 @@ public class LoginSkinApplyListener implements Listener {
|
|||||||
//loginEvent.getAddress is just a InetAddress not InetSocketAddress, so not unique enough
|
//loginEvent.getAddress is just a InetAddress not InetSocketAddress, so not unique enough
|
||||||
for (BukkitLoginSession session : plugin.getLoginSessions().values()) {
|
for (BukkitLoginSession session : plugin.getLoginSessions().values()) {
|
||||||
if (session.getUsername().equals(player.getName())) {
|
if (session.getUsername().equals(player.getName())) {
|
||||||
String signature = session.getSkinSignature();
|
SkinProperties skinProperty = session.getSkinProperty();
|
||||||
String skinData = session.getEncodedSkinData();
|
applySkin(player, skinProperty.getValue(), skinProperty.getSignature());
|
||||||
|
|
||||||
applySkin(player, skinData, signature);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class ProtocolLibLoginSource implements LoginSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kick(String message) throws Exception {
|
public void kick(String message) throws InvocationTargetException {
|
||||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
|
|
||||||
PacketContainer kickPacket = protocolManager.createPacket(DISCONNECT);
|
PacketContainer kickPacket = protocolManager.createPacket(DISCONNECT);
|
||||||
|
@ -17,12 +17,6 @@
|
|||||||
<name>FastLoginBungee</name>
|
<name>FastLoginBungee</name>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<!--BungeeCord with also the part outside the API-->
|
|
||||||
<repository>
|
|
||||||
<id>luck-repo</id>
|
|
||||||
<url>https://ci.lucko.me/plugin/repository/everything</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>vik1395-repo</id>
|
<id>vik1395-repo</id>
|
||||||
<url>https://vik1395.github.io/repo.vik1395.me/repositories</url>
|
<url>https://vik1395.github.io/repo.vik1395.me/repositories</url>
|
||||||
@ -37,6 +31,7 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--BungeeCord with also the part outside the API-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-proxy</artifactId>
|
<artifactId>bungeecord-proxy</artifactId>
|
||||||
|
@ -3,19 +3,16 @@ package com.github.games647.fastlogin.bungee;
|
|||||||
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthHook;
|
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthHook;
|
||||||
import com.github.games647.fastlogin.bungee.listener.ConnectionListener;
|
import com.github.games647.fastlogin.bungee.listener.ConnectionListener;
|
||||||
import com.github.games647.fastlogin.bungee.listener.PluginMessageListener;
|
import com.github.games647.fastlogin.bungee.listener.PluginMessageListener;
|
||||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
|
||||||
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
||||||
|
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||||
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
@ -24,9 +21,6 @@ import net.md_5.bungee.api.connection.PendingConnection;
|
|||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
|
import net.md_5.bungee.api.scheduler.GroupedThreadFactory;
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BungeeCord version of FastLogin. This plugin keeps track on online mode connections.
|
* BungeeCord version of FastLogin. This plugin keeps track on online mode connections.
|
||||||
@ -83,15 +77,6 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
|
|||||||
return getDescription().getName();
|
return getDescription().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> loadYamlFile(Reader reader) {
|
|
||||||
ConfigurationProvider configProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
|
||||||
Configuration config = configProvider.load(reader);
|
|
||||||
return config.getKeys().stream()
|
|
||||||
.filter(key -> config.get(key) != null)
|
|
||||||
.collect(Collectors.toMap(Function.identity(), config::get));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(CommandSender receiver, String message) {
|
public void sendMessage(CommandSender receiver, String message) {
|
||||||
receiver.sendMessage(TextComponent.fromLegacyText(message));
|
receiver.sendMessage(TextComponent.fromLegacyText(message));
|
||||||
|
@ -26,7 +26,7 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isRegistered(String playerName) throws Exception {
|
public boolean isRegistered(String playerName) {
|
||||||
return requestHandler.isRegistered(playerName);
|
return requestHandler.isRegistered(playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
core/pom.xml
20
core/pom.xml
@ -14,7 +14,16 @@
|
|||||||
|
|
||||||
<name>FastLoginCore</name>
|
<name>FastLoginCore</name>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>luck-repo</id>
|
||||||
|
<url>https://ci.lucko.me/plugin/repository/everything</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- Libraries that we shade into the project -->
|
||||||
|
|
||||||
<!--Database pooling-->
|
<!--Database pooling-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zaxxer</groupId>
|
<groupId>com.zaxxer</groupId>
|
||||||
@ -29,9 +38,20 @@
|
|||||||
<version>1.7.25</version>
|
<version>1.7.25</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- snakeyaml is present in Bungee, Spigot, Cauldron and so we could use this independent implementation -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-config</artifactId>
|
||||||
|
<version>1.12-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- APIs we can use because they are available in all platforms (Spigot, Bungee, Cauldron) -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
|
<!-- The Uranium project (fork of Cauldron) uses 17.0 like Spigot 1.8 as experimental feature -->
|
||||||
|
<!-- Project url: https://github.com/UraniumMC/Uranium -->
|
||||||
<version>10.0.1</version>
|
<version>10.0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
package com.github.games647.fastlogin.core;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class SharedConfig {
|
|
||||||
|
|
||||||
private final Map<String, Object> configValues;
|
|
||||||
|
|
||||||
public SharedConfig(Map<String, Object> configValues) {
|
|
||||||
this.configValues = configValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> T get(String path, T def) {
|
|
||||||
Object val = configValues.get(path);
|
|
||||||
|
|
||||||
if (def instanceof String) {
|
|
||||||
return (T) String.valueOf(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( val != null ) ? (T) val : def;
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T get(String path) {
|
|
||||||
return get(path, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Object> getConfigValues() {
|
|
||||||
return configValues;
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,6 @@ package com.github.games647.fastlogin.core.shared;
|
|||||||
|
|
||||||
import com.github.games647.fastlogin.core.AuthStorage;
|
import com.github.games647.fastlogin.core.AuthStorage;
|
||||||
import com.github.games647.fastlogin.core.CompatibleCacheBuilder;
|
import com.github.games647.fastlogin.core.CompatibleCacheBuilder;
|
||||||
import com.github.games647.fastlogin.core.SharedConfig;
|
|
||||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||||
import com.github.games647.fastlogin.core.hooks.DefaultPasswordGenerator;
|
import com.github.games647.fastlogin.core.hooks.DefaultPasswordGenerator;
|
||||||
import com.github.games647.fastlogin.core.hooks.PasswordGenerator;
|
import com.github.games647.fastlogin.core.hooks.PasswordGenerator;
|
||||||
@ -11,24 +10,27 @@ import com.google.common.cache.CacheLoader;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param <P> Player class
|
* @param <P> Player class
|
||||||
* @param <C> CommandSender
|
* @param <C> CommandSender
|
||||||
@ -70,7 +72,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
private final Set<UUID> pendingConfirms = Sets.newHashSet();
|
private final Set<UUID> pendingConfirms = Sets.newHashSet();
|
||||||
private final T plugin;
|
private final T plugin;
|
||||||
|
|
||||||
private SharedConfig sharedConfig;
|
private Configuration config;
|
||||||
private MojangApiConnector apiConnector;
|
private MojangApiConnector apiConnector;
|
||||||
private AuthStorage storage;
|
private AuthStorage storage;
|
||||||
private PasswordGenerator<P> passwordGenerator = new DefaultPasswordGenerator<>();
|
private PasswordGenerator<P> passwordGenerator = new DefaultPasswordGenerator<>();
|
||||||
@ -85,22 +87,26 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
saveDefaultFile("config.yml");
|
saveDefaultFile("config.yml");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sharedConfig = new SharedConfig(loadFile("config.yml"));
|
config = loadFile("config.yml");
|
||||||
Map<String, Object> messages = loadFile("messages.yml");
|
Configuration messages = loadFile("messages.yml");
|
||||||
|
|
||||||
for (Entry<String, Object> entry : messages.entrySet()) {
|
messages.getKeys()
|
||||||
String message = plugin.translateColorCodes('&', (String) entry.getValue());
|
.stream()
|
||||||
if (!message.isEmpty()) {
|
.filter(key -> config.get(key) != null)
|
||||||
localeMessages.put(entry.getKey(), message);
|
.collect(Collectors.toMap(Function.identity(), config::get))
|
||||||
}
|
.forEach((key, message) -> {
|
||||||
}
|
String colored = plugin.translateColorCodes('&', (String) message);
|
||||||
|
if (!colored.isEmpty()) {
|
||||||
|
localeMessages.put(key, colored);
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (IOException ioEx) {
|
} catch (IOException ioEx) {
|
||||||
plugin.getLogger().log(Level.INFO, "Failed to load yaml files", ioEx);
|
plugin.getLogger().log(Level.INFO, "Failed to load yaml files", ioEx);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> ipAddresses = sharedConfig.get("ip-addresses");
|
List<String> ipAddresses = config.getStringList("ip-addresses");
|
||||||
int requestLimit = sharedConfig.get("mojang-request-limit");
|
int requestLimit = config.getInt("mojang-request-limit");
|
||||||
List<String> proxyList = sharedConfig.get("proxies", Lists.newArrayList());
|
List<String> proxyList = config.get("proxies", Lists.newArrayList());
|
||||||
Map<String, Integer> proxies = proxyList.stream()
|
Map<String, Integer> proxies = proxyList.stream()
|
||||||
.collect(Collectors
|
.collect(Collectors
|
||||||
.toMap(line -> line.split(":")[0], line -> Integer.parseInt(line.split(":")[1])));
|
.toMap(line -> line.split(":")[0], line -> Integer.parseInt(line.split(":")[1])));
|
||||||
@ -108,20 +114,16 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
this.apiConnector = plugin.makeApiConnector(plugin.getLogger(), ipAddresses, requestLimit, proxies);
|
this.apiConnector = plugin.makeApiConnector(plugin.getLogger(), ipAddresses, requestLimit, proxies);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> loadFile(String fileName) throws IOException {
|
private Configuration loadFile(String fileName) throws IOException {
|
||||||
Map<String, Object> values;
|
Configuration defaults;
|
||||||
|
|
||||||
try (InputStream defaultStream = getClass().getClassLoader().getResourceAsStream(fileName);
|
ConfigurationProvider configProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(defaultStream))) {
|
try (InputStream defaultStream = getClass().getClassLoader().getResourceAsStream(fileName)) {
|
||||||
values = plugin.loadYamlFile(reader);
|
defaults = configProvider.load(defaultStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
Path file = plugin.getDataFolder().toPath().resolve(fileName);
|
File file = new File(plugin.getDataFolder(), fileName);
|
||||||
try (BufferedReader reader = Files.newBufferedReader(file)) {
|
return configProvider.load(file, defaults);
|
||||||
values.putAll(plugin.loadYamlFile(reader));
|
|
||||||
}
|
|
||||||
|
|
||||||
return values;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MojangApiConnector getApiConnector() {
|
public MojangApiConnector getApiConnector() {
|
||||||
@ -148,15 +150,15 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean setupDatabase() {
|
public boolean setupDatabase() {
|
||||||
String driver = sharedConfig.get("driver");
|
String driver = config.getString("driver");
|
||||||
String host = sharedConfig.get("host", "");
|
String host = config.get("host", "");
|
||||||
int port = sharedConfig.get("port", 3306);
|
int port = config.get("port", 3306);
|
||||||
String database = sharedConfig.get("database");
|
String database = config.getString("database");
|
||||||
|
|
||||||
String user = sharedConfig.get("username", "");
|
String user = config.get("username", "");
|
||||||
String password = sharedConfig.get("password", "");
|
String password = config.get("password", "");
|
||||||
|
|
||||||
boolean useSSL = sharedConfig.get("useSSL", false);
|
boolean useSSL = config.get("useSSL", false);
|
||||||
|
|
||||||
storage = new AuthStorage(this, driver, host, port, database, user, password, useSSL);
|
storage = new AuthStorage(this, driver, host, port, database, user, password, useSSL);
|
||||||
try {
|
try {
|
||||||
@ -168,8 +170,8 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SharedConfig getConfig() {
|
public Configuration getConfig() {
|
||||||
return sharedConfig;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PasswordGenerator<P> getPasswordGenerator() {
|
public PasswordGenerator<P> getPasswordGenerator() {
|
||||||
@ -201,18 +203,16 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(dataFolder);
|
Files.createDirectories(dataFolder);
|
||||||
|
|
||||||
|
Path configFile = dataFolder.resolve(fileName);
|
||||||
|
if (Files.notExists(configFile)) {
|
||||||
|
try (InputStream defaultStream = getClass().getClassLoader().getResourceAsStream(fileName)) {
|
||||||
|
Files.copy(defaultStream, configFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (IOException ioExc) {
|
} catch (IOException ioExc) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "Cannot create plugin folder " + dataFolder, ioExc);
|
plugin.getLogger().log(Level.SEVERE, "Cannot create plugin folder " + dataFolder, ioExc);
|
||||||
}
|
}
|
||||||
|
|
||||||
Path configFile = dataFolder.resolve(fileName);
|
|
||||||
if (Files.notExists(configFile)) {
|
|
||||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream(fileName)) {
|
|
||||||
Files.copy(in, configFile);
|
|
||||||
} catch (IOException ioExc) {
|
|
||||||
plugin.getLogger().log(Level.SEVERE, "Error saving default " + fileName, ioExc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package com.github.games647.fastlogin.core.shared;
|
package com.github.games647.fastlogin.core.shared;
|
||||||
|
|
||||||
import com.github.games647.fastlogin.core.PlayerProfile;
|
import com.github.games647.fastlogin.core.PlayerProfile;
|
||||||
import com.github.games647.fastlogin.core.SharedConfig;
|
|
||||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
|
||||||
public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
||||||
|
|
||||||
protected final FastLoginCore<P, C, ?> core;
|
protected final FastLoginCore<P, C, ?> core;
|
||||||
@ -23,7 +24,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedConfig config = core.getConfig();
|
Configuration config = core.getConfig();
|
||||||
|
|
||||||
String ip = source.getAddress().getAddress().getHostAddress();
|
String ip = source.getAddress().getAddress().getHostAddress();
|
||||||
profile.setLastIp(ip);
|
profile.setLastIp(ip);
|
||||||
|
@ -3,7 +3,6 @@ package com.github.games647.fastlogin.core.shared;
|
|||||||
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.Reader;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
@ -17,8 +16,6 @@ public interface PlatformPlugin<C> {
|
|||||||
|
|
||||||
Logger getLogger();
|
Logger getLogger();
|
||||||
|
|
||||||
Map<String, Object> loadYamlFile(Reader reader);
|
|
||||||
|
|
||||||
void sendMessage(C receiver, String message);
|
void sendMessage(C receiver, String message);
|
||||||
|
|
||||||
ThreadFactory getThreadFactory();
|
ThreadFactory getThreadFactory();
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
<include>${project.groupId}:*</include>
|
<include>${project.groupId}:*</include>
|
||||||
<include>com.zaxxer:HikariCP</include>
|
<include>com.zaxxer:HikariCP</include>
|
||||||
<include>org.slf4j:*</include>
|
<include>org.slf4j:*</include>
|
||||||
|
<include>net.md-5:bungeecord-config</include>
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
Reference in New Issue
Block a user