forked from TuxCoding/FastLogin
Minor refactoring
This commit is contained in:
@ -76,8 +76,8 @@
|
||||
|
||||
<!--AuthMe Reloaded and xAuth -->
|
||||
<repository>
|
||||
<id>xephi-repo</id>
|
||||
<url>https://ci.codemc.org/plugin/repository/everything/</url>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
<!--GitHub automatic maven builds-->
|
||||
|
@ -23,7 +23,6 @@ import java.security.KeyPair;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -127,7 +126,6 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
|
||||
ChannelMessage message = new ChangePremiumMessage(target, activate, true);
|
||||
sendPluginMessage((PluginMessageRecipient) invoker, message);
|
||||
} else {
|
||||
|
||||
Optional<? extends Player> optPlayer = getServer().getOnlinePlayers().stream().findFirst();
|
||||
if (!optPlayer.isPresent()) {
|
||||
logger.info("No player online to send a plugin message to the proxy");
|
||||
@ -204,12 +202,6 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
|
||||
receiver.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThreadFactory getThreadFactory() {
|
||||
//not required here to make a custom thread factory
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MojangApiConnector makeApiConnector(List<String> addresses, int requests, List<HostAndPort> proxies) {
|
||||
return new MojangApiBukkit(logger, addresses, requests, proxies);
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.github.games647.fastlogin.bukkit.hooks;
|
||||
|
||||
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
|
||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
/**
|
||||
* GitHub: https://github.com/Xephi/AuthMeReloaded/
|
||||
@ -17,23 +15,16 @@ import org.bukkit.event.Listener;
|
||||
* <p>
|
||||
* Spigot: https://www.spigotmc.org/resources/authme-reloaded.6269/
|
||||
*/
|
||||
public class AuthMeHook implements AuthPlugin<Player>, Listener {
|
||||
|
||||
private final FastLoginBukkit plugin;
|
||||
|
||||
public AuthMeHook(FastLoginBukkit plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public class AuthMeHook implements AuthPlugin<Player> {
|
||||
|
||||
@Override
|
||||
public boolean forceLogin(Player player) {
|
||||
//skips registration and login
|
||||
if (AuthMeApi.getInstance().isAuthenticated(player)) {
|
||||
return false;
|
||||
} else {
|
||||
AuthMeApi.getInstance().forceLogin(player);
|
||||
}
|
||||
|
||||
AuthMeApi.getInstance().forceLogin(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.github.games647.fastlogin.core.messages.ChannelMessage;
|
||||
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.MapMaker;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.net.HostAndPort;
|
||||
@ -15,7 +16,6 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
@ -34,7 +34,7 @@ import org.slf4j.Logger;
|
||||
*/
|
||||
public class FastLoginBungee extends Plugin implements PlatformPlugin<CommandSender> {
|
||||
|
||||
private final ConcurrentMap<PendingConnection, BungeeLoginSession> session = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<PendingConnection, BungeeLoginSession> session = new MapMaker().weakKeys().makeMap();
|
||||
|
||||
private FastLoginCore<ProxiedPlayer, CommandSender, FastLoginBungee> core;
|
||||
private Logger logger;
|
||||
|
@ -3,8 +3,8 @@ package com.github.games647.fastlogin.bungee.listener;
|
||||
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
||||
import com.github.games647.fastlogin.bungee.tasks.AsyncPremiumCheck;
|
||||
import com.github.games647.fastlogin.bungee.tasks.ForceLoginTask;
|
||||
import com.github.games647.fastlogin.core.CommonUtil;
|
||||
import com.github.games647.fastlogin.core.PlayerProfile;
|
||||
import com.github.games647.fastlogin.core.mojang.UUIDTypeAdapter;
|
||||
import com.github.games647.fastlogin.core.shared.LoginSession;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -73,7 +73,7 @@ public class ConnectListener implements Listener {
|
||||
//bungeecord will do this automatically so override it on disabled option
|
||||
if (!plugin.getCore().getConfig().get("premiumUuid", true)) {
|
||||
try {
|
||||
UUID offlineUUID = CommonUtil.getOfflineUUID(username);
|
||||
UUID offlineUUID = UUIDTypeAdapter.getOfflineUUID(username);
|
||||
|
||||
//bungeecord doesn't support overriding the premium uuid
|
||||
//so we have to do it with reflection
|
||||
|
@ -4,6 +4,7 @@ import com.github.games647.fastlogin.bungee.BungeeLoginSession;
|
||||
import com.github.games647.fastlogin.bungee.FastLoginBungee;
|
||||
import com.github.games647.fastlogin.core.messages.ChannelMessage;
|
||||
import com.github.games647.fastlogin.core.messages.ForceActionMessage;
|
||||
import com.github.games647.fastlogin.core.messages.ForceActionMessage.Type;
|
||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||
import com.github.games647.fastlogin.core.shared.ForceLoginManagement;
|
||||
import com.github.games647.fastlogin.core.shared.LoginSession;
|
||||
@ -59,9 +60,9 @@ public class ForceLoginTask
|
||||
@Override
|
||||
public void onForceActionSuccess(LoginSession session) {
|
||||
//sub channel name
|
||||
String type = "AUTO_LOGIN";
|
||||
Type type = Type.LOGIN;
|
||||
if (session.needsRegistration()) {
|
||||
type = "AUTO_REGISTER";
|
||||
type = Type.LOGIN;
|
||||
}
|
||||
|
||||
UUID proxyId = UUID.fromString(ProxyServer.getInstance().getConfig().getUuid());
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.games647.fastlogin.core;
|
||||
|
||||
import com.github.games647.fastlogin.core.mojang.UUIDTypeAdapter;
|
||||
import com.github.games647.fastlogin.core.shared.FastLoginCore;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
@ -35,6 +36,8 @@ public class AuthStorage {
|
||||
this.core = core;
|
||||
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setPoolName(core.getPlugin().getName());
|
||||
|
||||
config.setUsername(user);
|
||||
config.setPassword(pass);
|
||||
config.setDriverClassName(driver);
|
||||
@ -97,7 +100,7 @@ public class AuthStorage {
|
||||
if (resultSet.next()) {
|
||||
long userId = resultSet.getInt(1);
|
||||
|
||||
UUID uuid = CommonUtil.parseId(resultSet.getString(2));
|
||||
UUID uuid = UUIDTypeAdapter.parseId(resultSet.getString(2));
|
||||
|
||||
boolean premium = resultSet.getBoolean(4);
|
||||
String lastIp = resultSet.getString(5);
|
||||
@ -117,7 +120,7 @@ public class AuthStorage {
|
||||
public PlayerProfile loadProfile(UUID uuid) {
|
||||
try (Connection con = dataSource.getConnection();
|
||||
PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_UUID)) {
|
||||
loadStmt.setString(1, CommonUtil.toMojangId(uuid));
|
||||
loadStmt.setString(1, UUIDTypeAdapter.toMojangId(uuid));
|
||||
|
||||
try (ResultSet resultSet = loadStmt.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
@ -146,7 +149,7 @@ public class AuthStorage {
|
||||
if (uuid == null) {
|
||||
saveStmt.setString(1, null);
|
||||
} else {
|
||||
saveStmt.setString(1, CommonUtil.toMojangId(uuid));
|
||||
saveStmt.setString(1, UUIDTypeAdapter.toMojangId(uuid));
|
||||
}
|
||||
|
||||
saveStmt.setString(2, playerProfile.getPlayerName());
|
||||
@ -166,7 +169,7 @@ public class AuthStorage {
|
||||
if (uuid == null) {
|
||||
saveStmt.setString(1, null);
|
||||
} else {
|
||||
saveStmt.setString(1, CommonUtil.toMojangId(uuid));
|
||||
saveStmt.setString(1, UUIDTypeAdapter.toMojangId(uuid));
|
||||
}
|
||||
|
||||
saveStmt.setString(2, playerProfile.getPlayerName());
|
||||
|
@ -3,12 +3,9 @@ package com.github.games647.fastlogin.core;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -16,8 +13,6 @@ import org.slf4j.impl.JDK14LoggerAdapter;
|
||||
|
||||
public class CommonUtil {
|
||||
|
||||
private static final Pattern UUID_PATTERN = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})");
|
||||
|
||||
private static final char COLOR_CHAR = '&';
|
||||
private static final char TRANSLATED_CHAR = '§';
|
||||
|
||||
@ -37,18 +32,6 @@ public class CommonUtil {
|
||||
}));
|
||||
}
|
||||
|
||||
public static UUID parseId(String withoutDashes) {
|
||||
return UUID.fromString(UUID_PATTERN.matcher(withoutDashes).replaceAll("$1-$2-$3-$4-$5"));
|
||||
}
|
||||
|
||||
public static String toMojangId(UUID uuid) {
|
||||
return uuid.toString().replace("-", "");
|
||||
}
|
||||
|
||||
public static UUID getOfflineUUID(String playerName) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static String translateColorCodes(String rawMessage) {
|
||||
char[] chars = rawMessage.toCharArray();
|
||||
for (int i = 0; i < chars.length - 1; i++) {
|
||||
|
@ -3,7 +3,7 @@ package com.github.games647.fastlogin.core.hooks;
|
||||
/**
|
||||
* Represents a supporting authentication plugin in BungeeCord and Bukkit/Spigot/... servers
|
||||
*
|
||||
* @param <P> either org.bukkit.entity.GameProfile for Bukkit or net.md_5.bungee.api.connection.ProxiedPlayer
|
||||
* @param <P> either {@link org.bukkit.entity.Player} for Bukkit or {@link net.md_5.bungee.api.connection.ProxiedPlayer}
|
||||
* for BungeeCord
|
||||
*/
|
||||
public interface AuthPlugin<P> {
|
||||
|
@ -7,6 +7,15 @@ public class GameProfile {
|
||||
private UUID id;
|
||||
private String name;
|
||||
|
||||
public GameProfile(UUID id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public GameProfile() {
|
||||
//gson
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
@ -98,8 +99,8 @@ public class MojangApiConnector {
|
||||
|
||||
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line = reader.readLine();
|
||||
return Optional.of(getUUIDFromJson(line));
|
||||
String content = reader.lines().collect(Collectors.joining());
|
||||
return Optional.of(getUUIDFromJson(content));
|
||||
}
|
||||
} else if (connection.getResponseCode() == RATE_LIMIT_CODE) {
|
||||
logger.info("Mojang's rate-limit reached. The public IPv4 address of this server issued more than 600" +
|
||||
|
@ -1,21 +1,36 @@
|
||||
package com.github.games647.fastlogin.core.mojang;
|
||||
|
||||
import com.github.games647.fastlogin.core.CommonUtil;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.internal.bind.TypeAdapters;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class UUIDTypeAdapter extends TypeAdapter<UUID> {
|
||||
|
||||
private static final Pattern UUID_PATTERN = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})");
|
||||
|
||||
public static UUID parseId(String withoutDashes) {
|
||||
return UUID.fromString(UUID_PATTERN.matcher(withoutDashes).replaceAll("$1-$2-$3-$4-$5"));
|
||||
}
|
||||
|
||||
public static String toMojangId(UUID uuid) {
|
||||
return uuid.toString().replace("-", "");
|
||||
}
|
||||
|
||||
public static UUID getOfflineUUID(String playerName) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public void write(JsonWriter out, UUID value) throws IOException {
|
||||
TypeAdapters.STRING.write(out, CommonUtil.toMojangId(value));
|
||||
TypeAdapters.STRING.write(out, toMojangId(value));
|
||||
}
|
||||
|
||||
public UUID read(JsonReader in) throws IOException {
|
||||
return CommonUtil.parseId(TypeAdapters.STRING.read(in));
|
||||
return parseId(TypeAdapters.STRING.read(in));
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,9 @@ public interface PlatformPlugin<C> {
|
||||
|
||||
void sendMessage(C receiver, String message);
|
||||
|
||||
ThreadFactory getThreadFactory();
|
||||
default ThreadFactory getThreadFactory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
MojangApiConnector makeApiConnector(List<String> addresses, int requests, List<HostAndPort> proxies);
|
||||
}
|
||||
|
Reference in New Issue
Block a user