Generate a public key only for ProtocolLib listener

This commit is contained in:
games647
2018-03-09 13:57:51 +01:00
parent f250f8071f
commit 3f9eba69ba
26 changed files with 112 additions and 149 deletions
+1 -1
View File
@@ -28,7 +28,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.7</version>
<version>2.7.8</version>
</dependency>
<!--Logging framework implements slf4j which is required by hikari-->
@@ -11,6 +11,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.Instant;
import java.util.Optional;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.ThreadFactory;
@@ -93,25 +94,15 @@ public class AuthStorage {
public PlayerProfile loadProfile(String name) {
try (Connection con = dataSource.getConnection();
PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_NAME)) {
PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_NAME)
) {
loadStmt.setString(1, name);
try (ResultSet resultSet = loadStmt.executeQuery()) {
if (resultSet.next()) {
long userId = resultSet.getInt(1);
UUID uuid = UUIDTypeAdapter.parseId(resultSet.getString(2));
boolean premium = resultSet.getBoolean(4);
String lastIp = resultSet.getString(5);
Instant lastLogin = resultSet.getTimestamp(6).toInstant();
return new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin);
} else {
return new PlayerProfile(null, name, false, "");
}
return parseResult(resultSet).orElseGet(() -> new PlayerProfile(null, name, false, ""));
}
} catch (SQLException sqlEx) {
core.getPlugin().getLog().error("Failed to query profile", sqlEx);
core.getPlugin().getLog().error("Failed to query profile: {}", name, sqlEx);
}
return null;
@@ -119,27 +110,36 @@ public class AuthStorage {
public PlayerProfile loadProfile(UUID uuid) {
try (Connection con = dataSource.getConnection();
PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_UUID)) {
PreparedStatement loadStmt = con.prepareStatement(LOAD_BY_UUID)
) {
loadStmt.setString(1, UUIDTypeAdapter.toMojangId(uuid));
try (ResultSet resultSet = loadStmt.executeQuery()) {
if (resultSet.next()) {
long userId = resultSet.getInt(1);
String name = resultSet.getString(3);
boolean premium = resultSet.getBoolean(4);
String lastIp = resultSet.getString(5);
Instant lastLogin = resultSet.getTimestamp(6).toInstant();
return new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin);
}
return parseResult(resultSet).orElse(null);
}
} catch (SQLException sqlEx) {
core.getPlugin().getLog().error("Failed to query profile", sqlEx);
core.getPlugin().getLog().error("Failed to query profile: {}", uuid, sqlEx);
}
return null;
}
private Optional<PlayerProfile> parseResult(ResultSet resultSet) throws SQLException {
if (resultSet.next()) {
long userId = resultSet.getInt(1);
UUID uuid = UUIDTypeAdapter.parseId(resultSet.getString(2));
String name = resultSet.getString(3);
boolean premium = resultSet.getBoolean(4);
String lastIp = resultSet.getString(5);
Instant lastLogin = resultSet.getTimestamp(6).toInstant();
return Optional.of(new PlayerProfile(userId, uuid, name, premium, lastIp, lastLogin));
}
return Optional.empty();
}
public void save(PlayerProfile playerProfile) {
try (Connection con = dataSource.getConnection()) {
String uuid = playerProfile.getId().map(UUIDTypeAdapter::toMojangId).orElse(null);
@@ -163,7 +163,6 @@ public class AuthStorage {
saveStmt.setString(4, playerProfile.getLastIp());
saveStmt.execute();
try (ResultSet generatedKeys = saveStmt.getGeneratedKeys()) {
if (generatedKeys != null && generatedKeys.next()) {
playerProfile.setRowId(generatedKeys.getInt(1));
@@ -171,11 +170,9 @@ public class AuthStorage {
}
}
}
} catch (SQLException ex) {
core.getPlugin().getLog().error("Failed to save playerProfile", ex);
core.getPlugin().getLog().error("Failed to save playerProfile {}", playerProfile, ex);
}
}
public void close() {
@@ -7,7 +7,6 @@ import java.util.UUID;
public class PlayerProfile {
private String playerName;
private long rowId;
private UUID uuid;
@@ -48,7 +47,6 @@ public class PlayerProfile {
this.rowId = generatedId;
}
//todo: this should be optional
public synchronized Optional<UUID> getId() {
return Optional.ofNullable(uuid);
}
@@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -62,13 +61,13 @@ public class MojangApiConnector {
protected final Gson gson = new GsonBuilder()
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
public MojangApiConnector(Logger logger, Collection<String> localAddresses, int rateLimit
public MojangApiConnector(Logger logger, Iterable<String> localAddresses, int rateLimit
, Iterable<HostAndPort> proxies) {
this.logger = logger;
this.rateLimit = Math.max(rateLimit, 600);
this.sslFactory = buildAddresses(logger, localAddresses);
List<Proxy> proxyBuilder = new ArrayList<>();
Collection<Proxy> proxyBuilder = new ArrayList<>();
for (HostAndPort proxy : proxies) {
proxyBuilder.add(new Proxy(Type.HTTP, new InetSocketAddress(proxy.getHostText(), proxy.getPort())));
}
@@ -14,7 +14,7 @@ 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) {
public static UUID parseId(CharSequence withoutDashes) {
return UUID.fromString(UUID_PATTERN.matcher(withoutDashes).replaceAll("$1-$2-$3-$4-$5"));
}
@@ -17,7 +17,6 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -42,7 +41,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
protected final Map<String, String> localeMessages = new ConcurrentHashMap<>();
private final ConcurrentMap<String, Object> pendingLogin = CommonUtil.buildCache(5, -1);
private final Set<UUID> pendingConfirms = new HashSet<>();
private final Collection<UUID> pendingConfirms = new HashSet<>();
private final T plugin;
private Configuration config;
@@ -64,7 +64,7 @@ public abstract class ForceLoginManagement<P extends C, C, L extends LoginSessio
storage.save(playerProfile);
}
} catch (Exception ex) {
core.getPlugin().getLog().warn("ERROR ON FORCE LOGIN", ex);
core.getPlugin().getLog().warn("ERROR ON FORCE LOGIN of {}", getName(player), ex);
}
}
@@ -62,7 +62,7 @@ public abstract class JoinManagement<P extends C, C, S extends LoginSource> {
}
}
} catch (Exception ex) {
core.getPlugin().getLog().error("Failed to check premium state", ex);
core.getPlugin().getLog().error("Failed to check premium state of {}", username, ex);
}
}
@@ -55,7 +55,7 @@ public abstract class LoginSession {
}
@Override
public String toString() {
public synchronized String toString() {
return this.getClass().getSimpleName() + '{' +
"username='" + username + '\'' +
", profile=" + profile +