diff --git a/LaunchServer/source/auth/handler/BinaryFileAuthHandler.java b/LaunchServer/source/auth/handler/BinaryFileAuthHandler.java index 51259e5..2ce9c3b 100644 --- a/LaunchServer/source/auth/handler/BinaryFileAuthHandler.java +++ b/LaunchServer/source/auth/handler/BinaryFileAuthHandler.java @@ -28,9 +28,9 @@ } @Override - protected void writeAuthFile() throws IOException { + protected void writeAuthFileTmp() throws IOException { Set> entrySet = entrySet(); - try (HOutput output = new HOutput(IOHelper.newOutput(file))) { + try (HOutput output = new HOutput(IOHelper.newOutput(fileTmp))) { output.writeLength(entrySet.size(), 0); for (Map.Entry entry : entrySet) { output.writeUUID(entry.getKey()); diff --git a/LaunchServer/source/auth/handler/FileAuthHandler.java b/LaunchServer/source/auth/handler/FileAuthHandler.java index 0e0b46c..da3dc25 100644 --- a/LaunchServer/source/auth/handler/FileAuthHandler.java +++ b/LaunchServer/source/auth/handler/FileAuthHandler.java @@ -27,6 +27,7 @@ public abstract class FileAuthHandler extends AuthHandler { @LauncherAPI public final Path file; + @LauncherAPI public final Path fileTmp; @LauncherAPI public final boolean offlineUUIDs; // Instance @@ -34,13 +35,14 @@ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); // Storage - private final Map entryMap = new HashMap<>(); - private final Map usernamesMap = new HashMap<>(); + private final Map entryMap = new HashMap<>(256); + private final Map usernamesMap = new HashMap<>(256); @LauncherAPI protected FileAuthHandler(BlockConfigEntry block) { super(block); file = IOHelper.toPath(block.getEntryValue("file", StringConfigEntry.class)); + fileTmp = IOHelper.toPath(block.getEntryValue("file", StringConfigEntry.class) + ".tmp"); offlineUUIDs = block.getEntryValue("offlineUUIDs", BooleanConfigEntry.class); // Read auth handler file @@ -98,7 +100,8 @@ lock.readLock().lock(); try { LogHelper.info("Writing auth handler file (%d entries)", entryMap.size()); - writeAuthFile(); + writeAuthFileTmp(); + IOHelper.move(fileTmp, file); } finally { lock.readLock().unlock(); } @@ -140,7 +143,7 @@ protected abstract void readAuthFile() throws IOException; @LauncherAPI - protected abstract void writeAuthFile() throws IOException; + protected abstract void writeAuthFileTmp() throws IOException; @LauncherAPI protected final void addAuth(UUID uuid, Entry entry) { diff --git a/LaunchServer/source/auth/handler/MemoryAuthHandler.java b/LaunchServer/source/auth/handler/MemoryAuthHandler.java index 9ccadde..782d84e 100644 --- a/LaunchServer/source/auth/handler/MemoryAuthHandler.java +++ b/LaunchServer/source/auth/handler/MemoryAuthHandler.java @@ -1,6 +1,5 @@ package launchserver.auth.handler; -import java.io.IOException; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.UUID; diff --git a/LaunchServer/source/auth/handler/MySQLAuthHandler.java b/LaunchServer/source/auth/handler/MySQLAuthHandler.java index 6a29d75..2dc518a 100644 --- a/LaunchServer/source/auth/handler/MySQLAuthHandler.java +++ b/LaunchServer/source/auth/handler/MySQLAuthHandler.java @@ -17,7 +17,6 @@ public final class MySQLAuthHandler extends CachedAuthHandler { private final MySQLSourceConfig mySQLHolder; - private final String table; private final String uuidColumn; private final String usernameColumn; private final String accessTokenColumn; @@ -34,7 +33,7 @@ mySQLHolder = new MySQLSourceConfig("authHandlerPool", block); // Read query params - table = VerifyHelper.verifyIDName( + String table = VerifyHelper.verifyIDName( block.getEntryValue("table", StringConfigEntry.class)); uuidColumn = VerifyHelper.verifyIDName( block.getEntryValue("uuidColumn", StringConfigEntry.class)); diff --git a/LaunchServer/source/auth/handler/NullAuthHandler.java b/LaunchServer/source/auth/handler/NullAuthHandler.java index 95fc6e7..facb569 100644 --- a/LaunchServer/source/auth/handler/NullAuthHandler.java +++ b/LaunchServer/source/auth/handler/NullAuthHandler.java @@ -1,6 +1,7 @@ package launchserver.auth.handler; import java.io.IOException; +import java.util.Objects; import java.util.UUID; import launcher.LauncherAPI; @@ -53,6 +54,6 @@ } private AuthHandler getHandler() { - return VerifyHelper.verify(handler, a -> a != null, "Backend auth handler wasn't set"); + return VerifyHelper.verify(handler, Objects::nonNull, "Backend auth handler wasn't set"); } } diff --git a/LaunchServer/source/auth/handler/TextFileAuthHandler.java b/LaunchServer/source/auth/handler/TextFileAuthHandler.java index d5ee7f3..d4163e6 100644 --- a/LaunchServer/source/auth/handler/TextFileAuthHandler.java +++ b/LaunchServer/source/auth/handler/TextFileAuthHandler.java @@ -50,7 +50,7 @@ } @Override - protected void writeAuthFile() throws IOException { + protected void writeAuthFileTmp() throws IOException { boolean next = false; // Write auth blocks to map @@ -85,7 +85,7 @@ } // Write auth handler file - try (BufferedWriter writer = IOHelper.newWriter(file)) { + try (BufferedWriter writer = IOHelper.newWriter(fileTmp)) { BlockConfigEntry authFile = new BlockConfigEntry(map, true, 1); authFile.setComment(0, "\n"); TextConfigWriter.write(authFile, writer, true); diff --git a/LaunchServer/source/response/Response.java b/LaunchServer/source/response/Response.java index b058823..8be6b89 100644 --- a/LaunchServer/source/response/Response.java +++ b/LaunchServer/source/response/Response.java @@ -37,6 +37,7 @@ } @LauncherAPI + @SuppressWarnings("MethodMayBeStatic") // Intentionally not static protected final void writeNoError(HOutput output) throws IOException { output.writeString("", 0); } diff --git a/LaunchServer/source/response/ServerSocketHandler.java b/LaunchServer/source/response/ServerSocketHandler.java index 9a67c68..a1516aa 100644 --- a/LaunchServer/source/response/ServerSocketHandler.java +++ b/LaunchServer/source/response/ServerSocketHandler.java @@ -17,7 +17,6 @@ import launcher.helper.CommonHelper; import launcher.helper.LogHelper; import launcher.helper.VerifyHelper; -import launcher.request.Request; import launcher.request.Request.Type; import launcher.serialize.HInput; import launcher.serialize.HOutput; @@ -27,10 +26,12 @@ public final class ServerSocketHandler implements Runnable, AutoCloseable { private static final ThreadFactory THREAD_FACTORY = r -> CommonHelper.newThread("Network Thread", true, r); @LauncherAPI public volatile boolean logConnections = Boolean.getBoolean("launcher.logConnections"); + // Instance private final LaunchServer server; private final AtomicReference serverSocket = new AtomicReference<>(); private final ExecutorService threadPool = Executors.newCachedThreadPool(THREAD_FACTORY); + // API private final Map customResponses = new ConcurrentHashMap<>(2); private final AtomicLong idCounter = new AtomicLong(0L); diff --git a/LaunchServer/source/texture/NullTextureProvider.java b/LaunchServer/source/texture/NullTextureProvider.java index 4f762de..8ed2c58 100644 --- a/LaunchServer/source/texture/NullTextureProvider.java +++ b/LaunchServer/source/texture/NullTextureProvider.java @@ -1,10 +1,10 @@ package launchserver.texture; import java.io.IOException; +import java.util.Objects; import java.util.UUID; import launcher.LauncherAPI; -import launcher.client.PlayerProfile; import launcher.client.PlayerProfile.Texture; import launcher.helper.VerifyHelper; import launcher.serialize.config.entry.BlockConfigEntry; @@ -40,6 +40,6 @@ } private TextureProvider getProvider() { - return VerifyHelper.verify(provider, a -> a != null, "Backend texture provider wasn't set"); + return VerifyHelper.verify(provider, Objects::nonNull, "Backend texture provider wasn't set"); } } diff --git a/LaunchServer/source/texture/TextureProvider.java b/LaunchServer/source/texture/TextureProvider.java index c64cf2c..d4d5f4c 100644 --- a/LaunchServer/source/texture/TextureProvider.java +++ b/LaunchServer/source/texture/TextureProvider.java @@ -7,7 +7,6 @@ import java.util.concurrent.ConcurrentHashMap; import launcher.LauncherAPI; -import launcher.client.PlayerProfile; import launcher.client.PlayerProfile.Texture; import launcher.helper.VerifyHelper; import launcher.serialize.config.ConfigObject;