Shade the Bungee-Config implementation because it's platform independent

This commit is contained in:
games647
2017-09-22 19:47:10 +02:00
parent bb80521ab6
commit 2f0eb81735
21 changed files with 92 additions and 143 deletions

View File

@ -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)
### 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)

View File

@ -1,6 +1,7 @@
package com.github.games647.fastlogin.bukkit;
import com.github.games647.fastlogin.core.PlayerProfile;
import com.github.games647.fastlogin.core.mojang.SkinProperties;
import com.github.games647.fastlogin.core.shared.LoginSession;
import org.apache.commons.lang.ArrayUtils;
@ -17,8 +18,7 @@ public class BukkitLoginSession extends LoginSession {
private boolean verified;
private String encodedSkinData;
private String skinSignature;
private SkinProperties skinProperty;
public BukkitLoginSession(String username, String serverId, byte[] verifyToken, boolean registered
, PlayerProfile profile) {
@ -62,23 +62,15 @@ public class BukkitLoginSession extends LoginSession {
return ArrayUtils.clone(verifyToken);
}
public synchronized String getEncodedSkinData() {
return encodedSkinData;
}
public synchronized String getSkinSignature() {
return skinSignature;
public synchronized SkinProperties getSkinProperty() {
return skinProperty;
}
/**
* Sets the premium skin property which was retrieved by the session server
*
* @param encodedData
* @param skinSignature
*/
public synchronized void setSkin(String encodedData, String skinSignature) {
this.encodedSkinData = encodedData;
this.skinSignature = skinSignature;
public synchronized void setSkinProperty(SkinProperties skinProperty) {
this.skinProperty = skinProperty;
}
/**

View File

@ -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.protocolsupport.ProtocolSupportListener;
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.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
import com.google.common.collect.Iterables;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import java.io.Reader;
import java.security.KeyPair;
import java.util.List;
import java.util.Map;
@ -26,7 +25,6 @@ import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageRecipient;
@ -190,12 +188,6 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
sender.sendPluginMessage(this, getName(), dataOutput.toByteArray());
}
@Override
public Map<String, Object> loadYamlFile(Reader reader) {
YamlConfiguration config = YamlConfiguration.loadConfiguration(reader);
return config.getValues(true);
}
@Override
public void sendMessage(CommandSender receiver, String message) {
receiver.sendMessage(message);

View File

@ -50,10 +50,7 @@ public class MojangApiBukkit extends MojangApiConnector {
SkinProperties[] properties = verification.getProperties();
if (properties != null && properties.length > 0) {
SkinProperties skinProperty = properties[0];
String skinValue = skinProperty.getValue();
String signature = skinProperty.getSignature();
playerSession.setSkin(skinValue, signature);
playerSession.setSkinProperty(skinProperty);
}
return true;

View File

@ -30,7 +30,7 @@ public class AuthMeHook implements AuthPlugin<Player> {
}
@Override
public boolean isRegistered(String playerName) throws Exception {
public boolean isRegistered(String playerName) {
return AuthMeApi.getInstance().isRegistered(playerName);
}

View File

@ -78,7 +78,7 @@ public class CrazyLoginHook implements AuthPlugin<Player> {
}
@Override
public boolean isRegistered(String playerName) throws Exception {
public boolean isRegistered(String playerName) {
return crazyLoginPlugin.getPlayerData(playerName) != null;
}

View File

@ -26,7 +26,7 @@ public class LogItHook implements AuthPlugin<Player> {
}
@Override
public boolean isRegistered(String playerName) throws Exception {
public boolean isRegistered(String playerName) {
return LogItCore.getInstance().getAccountManager().isRegistered(playerName);
}

View File

@ -29,7 +29,7 @@ public class LoginSecurityHook implements AuthPlugin<Player> {
}
@Override
public boolean isRegistered(String playerName) throws Exception {
public boolean isRegistered(String playerName) {
PlayerSession session = LoginSecurity.getSessionManager().getOfflineSession(playerName);
return session.isRegistered();
}

View File

@ -45,7 +45,7 @@ public class UltraAuthHook implements AuthPlugin<Player> {
}
@Override
public boolean isRegistered(String playerName) throws Exception {
public boolean isRegistered(String playerName) {
return UltraAuthAPI.isRegisterd(playerName);
}

View File

@ -52,7 +52,7 @@ public class xAuthHook implements AuthPlugin<Player> {
}
@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
xAuthPlayer xAuthPlayer = xAuthPlugin.getPlayerManager().getPlayer(playerName);
return xAuthPlayer != null && xAuthPlayer.isRegistered();

View File

@ -8,6 +8,7 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
import com.github.games647.fastlogin.bukkit.BukkitLoginSession;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.mojang.SkinProperties;
import java.lang.reflect.InvocationTargetException;
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
for (BukkitLoginSession session : plugin.getLoginSessions().values()) {
if (session.getUsername().equals(player.getName())) {
String signature = session.getSkinSignature();
String skinData = session.getEncodedSkinData();
applySkin(player, skinData, signature);
SkinProperties skinProperty = session.getSkinProperty();
applySkin(player, skinProperty.getValue(), skinProperty.getSignature());
break;
}
}

View File

@ -49,7 +49,7 @@ public class ProtocolLibLoginSource implements LoginSource {
}
@Override
public void kick(String message) throws Exception {
public void kick(String message) throws InvocationTargetException {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
PacketContainer kickPacket = protocolManager.createPacket(DISCONNECT);

View File

@ -17,12 +17,6 @@
<name>FastLoginBungee</name>
<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>
<id>vik1395-repo</id>
<url>https://vik1395.github.io/repo.vik1395.me/repositories</url>
@ -37,6 +31,7 @@
<scope>provided</scope>
</dependency>
<!--BungeeCord with also the part outside the API-->
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-proxy</artifactId>

View File

@ -3,19 +3,16 @@ package com.github.games647.fastlogin.bungee;
import com.github.games647.fastlogin.bungee.hooks.BungeeAuthHook;
import com.github.games647.fastlogin.bungee.listener.ConnectionListener;
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.shared.FastLoginCore;
import com.github.games647.fastlogin.core.shared.PlatformPlugin;
import com.google.common.collect.Maps;
import java.io.Reader;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ThreadFactory;
import java.util.function.Function;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import net.md_5.bungee.api.ChatColor;
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.plugin.Plugin;
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.
@ -83,15 +77,6 @@ public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSen
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
public void sendMessage(CommandSender receiver, String message) {
receiver.sendMessage(TextComponent.fromLegacyText(message));

View File

@ -26,7 +26,7 @@ public class BungeeAuthHook implements AuthPlugin<ProxiedPlayer> {
}
@Override
public boolean isRegistered(String playerName) throws Exception {
public boolean isRegistered(String playerName) {
return requestHandler.isRegistered(playerName);
}

View File

@ -14,7 +14,16 @@
<name>FastLoginCore</name>
<repositories>
<repository>
<id>luck-repo</id>
<url>https://ci.lucko.me/plugin/repository/everything</url>
</repository>
</repositories>
<dependencies>
<!-- Libraries that we shade into the project -->
<!--Database pooling-->
<dependency>
<groupId>com.zaxxer</groupId>
@ -29,9 +38,20 @@
<version>1.7.25</version>
</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>
<groupId>com.google.guava</groupId>
<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>
<scope>provided</scope>
</dependency>

View File

@ -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;
}
}

View File

@ -2,7 +2,6 @@ package com.github.games647.fastlogin.core.shared;
import com.github.games647.fastlogin.core.AuthStorage;
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.DefaultPasswordGenerator;
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.Sets;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.logging.Level;
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 <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 T plugin;
private SharedConfig sharedConfig;
private Configuration config;
private MojangApiConnector apiConnector;
private AuthStorage storage;
private PasswordGenerator<P> passwordGenerator = new DefaultPasswordGenerator<>();
@ -85,22 +87,26 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
saveDefaultFile("config.yml");
try {
sharedConfig = new SharedConfig(loadFile("config.yml"));
Map<String, Object> messages = loadFile("messages.yml");
config = loadFile("config.yml");
Configuration messages = loadFile("messages.yml");
for (Entry<String, Object> entry : messages.entrySet()) {
String message = plugin.translateColorCodes('&', (String) entry.getValue());
if (!message.isEmpty()) {
localeMessages.put(entry.getKey(), message);
}
}
messages.getKeys()
.stream()
.filter(key -> config.get(key) != null)
.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) {
plugin.getLogger().log(Level.INFO, "Failed to load yaml files", ioEx);
}
List<String> ipAddresses = sharedConfig.get("ip-addresses");
int requestLimit = sharedConfig.get("mojang-request-limit");
List<String> proxyList = sharedConfig.get("proxies", Lists.newArrayList());
List<String> ipAddresses = config.getStringList("ip-addresses");
int requestLimit = config.getInt("mojang-request-limit");
List<String> proxyList = config.get("proxies", Lists.newArrayList());
Map<String, Integer> proxies = proxyList.stream()
.collect(Collectors
.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);
}
private Map<String, Object> loadFile(String fileName) throws IOException {
Map<String, Object> values;
private Configuration loadFile(String fileName) throws IOException {
Configuration defaults;
try (InputStream defaultStream = getClass().getClassLoader().getResourceAsStream(fileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(defaultStream))) {
values = plugin.loadYamlFile(reader);
ConfigurationProvider configProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
try (InputStream defaultStream = getClass().getClassLoader().getResourceAsStream(fileName)) {
defaults = configProvider.load(defaultStream);
}
Path file = plugin.getDataFolder().toPath().resolve(fileName);
try (BufferedReader reader = Files.newBufferedReader(file)) {
values.putAll(plugin.loadYamlFile(reader));
}
return values;
File file = new File(plugin.getDataFolder(), fileName);
return configProvider.load(file, defaults);
}
public MojangApiConnector getApiConnector() {
@ -148,15 +150,15 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
}
public boolean setupDatabase() {
String driver = sharedConfig.get("driver");
String host = sharedConfig.get("host", "");
int port = sharedConfig.get("port", 3306);
String database = sharedConfig.get("database");
String driver = config.getString("driver");
String host = config.get("host", "");
int port = config.get("port", 3306);
String database = config.getString("database");
String user = sharedConfig.get("username", "");
String password = sharedConfig.get("password", "");
String user = config.get("username", "");
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);
try {
@ -168,8 +170,8 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
}
}
public SharedConfig getConfig() {
return sharedConfig;
public Configuration getConfig() {
return config;
}
public PasswordGenerator<P> getPasswordGenerator() {
@ -201,18 +203,16 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
try {
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) {
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() {

View File

@ -1,12 +1,13 @@
package com.github.games647.fastlogin.core.shared;
import com.github.games647.fastlogin.core.PlayerProfile;
import com.github.games647.fastlogin.core.SharedConfig;
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import java.util.UUID;
import java.util.logging.Level;
import net.md_5.bungee.config.Configuration;
public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
protected final FastLoginCore<P, C, ?> core;
@ -23,7 +24,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
return;
}
SharedConfig config = core.getConfig();
Configuration config = core.getConfig();
String ip = source.getAddress().getAddress().getHostAddress();
profile.setLastIp(ip);

View File

@ -3,7 +3,6 @@ package com.github.games647.fastlogin.core.shared;
import com.github.games647.fastlogin.core.mojang.MojangApiConnector;
import java.io.File;
import java.io.Reader;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadFactory;
@ -17,8 +16,6 @@ public interface PlatformPlugin<C> {
Logger getLogger();
Map<String, Object> loadYamlFile(Reader reader);
void sendMessage(C receiver, String message);
ThreadFactory getThreadFactory();

View File

@ -31,6 +31,7 @@
<include>${project.groupId}:*</include>
<include>com.zaxxer:HikariCP</include>
<include>org.slf4j:*</include>
<include>net.md-5:bungeecord-config</include>
</includes>
</artifactSet>
</configuration>