diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index bf2d8e88..1a460e15 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -32,6 +32,7 @@ import ru.gravit.launchserver.manangers.SessionManager; import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.ServerSocketHandler; +import ru.gravit.launchserver.texture.RequestTextureProvider; import ru.gravit.launchserver.texture.TextureProvider; import ru.gravit.utils.helper.*; @@ -60,7 +61,7 @@ public static final class Config { // Handlers & Providers - public AuthHandler[] authHandler; + public AuthHandler authHandler; public AuthProvider[] authProvider; @@ -127,6 +128,18 @@ public void setAddress(String address) { public void verify() { VerifyHelper.verify(getAddress(), VerifyHelper.NOT_EMPTY, "LaunchServer address can't be empty"); + if(authHandler == null) + { + throw new NullPointerException("AuthHandler must not be null"); + } + if(authProvider == null || authProvider[0] == null) + { + throw new NullPointerException("AuthProvider must not be null"); + } + if(textureProvider == null) + { + throw new NullPointerException("TextureProvider must not be null"); + } } } @@ -392,7 +405,7 @@ public void close() { // Close handlers & providers try { - for (AuthHandler h : config.authHandler) h.close(); + config.authHandler.close(); } catch (IOException e) { LogHelper.error(e); } @@ -423,9 +436,11 @@ private void generateConfigIfNotExists() throws IOException { newConfig.launch4j = new ExeConf(); newConfig.buildPostTransform = new PostBuildTransformConf(); newConfig.env = LauncherConfig.LauncherEnvironment.STD; - newConfig.authHandler = new AuthHandler[]{new MemoryAuthHandler()}; + newConfig.authHandler = new MemoryAuthHandler(); newConfig.hwidHandler = new AcceptHWIDHandler(); - newConfig.authProvider = new AuthProvider[]{new RejectAuthProvider()}; + + newConfig.authProvider = new AuthProvider[]{new RejectAuthProvider("Технические работы")}; + newConfig.textureProvider = new RequestTextureProvider("http://example.com/skins/%username%.png","http://example.com/cloaks/%username%.png"); newConfig.port = 7420; newConfig.bindAddress = "0.0.0.0"; //try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launchserver/defaults/config.cfg"))) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java index 5e91d3b4..fa7c4805 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java @@ -29,10 +29,8 @@ public Entry(UUID uuid, String username, String accessToken, String serverID) { this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID); } } - @Expose(serialize = false, deserialize = false) - private final Map entryCache = new HashMap<>(1024); - @Expose(serialize = false, deserialize = false) - private final Map usernamesCache = new HashMap<>(1024); + private transient final Map entryCache = new HashMap<>(1024); + private transient final Map usernamesCache = new HashMap<>(1024); protected void addEntry(Entry entry) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java index 9ab4a4ce..6580cd74 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AuthProvider.java @@ -1,5 +1,6 @@ package ru.gravit.launchserver.auth.provider; +import com.google.gson.annotations.Expose; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.handler.AuthHandler; @@ -13,7 +14,7 @@ public abstract class AuthProvider implements AutoCloseable { private static final Map AUTH_PROVIDERS = new ConcurrentHashMap<>(8); private static boolean registredProv = false; - private LaunchServer server; + private transient LaunchServer server = LaunchServer.server; public static AuthProviderResult authError(String message) throws AuthException { @@ -33,7 +34,7 @@ public static void registerProviders() { registerProvider("reject", RejectAuthProvider.class); // Auth providers that doesn't do nothing :D - registerProvider("com.mojang", MojangAuthProvider.class); + registerProvider("mojang", MojangAuthProvider.class); registerProvider("mysql", MySQLAuthProvider.class); registerProvider("request", RequestAuthProvider.class); registerProvider("json", JsonAuthProvider.class); @@ -42,7 +43,7 @@ public static void registerProviders() { } public AuthHandler getAccociateHandler(int this_position) { - return server.config.authHandler[0]; + return server.config.authHandler; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java index 836d5e79..7d63c51a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/RejectAuthProvider.java @@ -2,6 +2,13 @@ import ru.gravit.launchserver.auth.AuthException; public final class RejectAuthProvider extends AuthProvider { + public RejectAuthProvider() { + } + + public RejectAuthProvider(String message) { + this.message = message; + } + private String message; @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java index 49dc4d47..918a5e7f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UUIDToUsernameCommand.java @@ -29,7 +29,7 @@ public void invoke(String... args) throws CommandException, IOException { UUID uuid = parseUUID(args[0]); // Get UUID by username - String username = server.config.authHandler[0].uuidToUsername(uuid); + String username = server.config.authHandler.uuidToUsername(uuid); if (username == null) throw new CommandException("Unknown UUID: " + uuid); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java index eca96027..24d226ac 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UsernameToUUIDCommand.java @@ -29,7 +29,7 @@ public void invoke(String... args) throws CommandException, IOException { String username = parseUsername(args[0]); // Get UUID by username - UUID uuid = server.config.authHandler[0].usernameToUUID(username); + UUID uuid = server.config.authHandler.usernameToUUID(username); if (uuid == null) throw new CommandException(String.format("Unknown username: '%s'", username)); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java index ec2e3e3b..9987d5a2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java @@ -107,7 +107,7 @@ public void reply() throws Exception { // Authenticate on server (and get UUID) UUID uuid; try { - uuid = provider.getAccociateHandler(auth_id).auth(result); + uuid = server.config.authHandler.auth(result); } catch (AuthException e) { requestError(e.getMessage()); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java index c2ceec31..3ad7d1cf 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/CheckServerResponse.java @@ -31,7 +31,7 @@ public void reply() throws IOException { // Try check server with auth handler UUID uuid; try { - uuid = server.config.authHandler[0].checkServer(username, serverID); + uuid = server.config.authHandler.checkServer(username, serverID); } catch (AuthException e) { requestError(e.getMessage()); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java index a6f0b426..8ae04ec4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/JoinServerResponse.java @@ -28,7 +28,7 @@ public void reply() throws IOException { debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID); boolean success; try { - success = server.config.authHandler[0].joinServer(username, accessToken, serverID); + success = server.config.authHandler.joinServer(username, accessToken, serverID); } catch (AuthException e) { requestError(e.getMessage()); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java index 9147c4c0..0aeeca44 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUUIDResponse.java @@ -47,7 +47,7 @@ public void reply() throws IOException { debug("UUID: " + uuid); String client = input.readString(SerializeLimits.MAX_CLIENT); // Verify has such profile - String username = server.config.authHandler[0].uuidToUsername(uuid); + String username = server.config.authHandler.uuidToUsername(uuid); if (username == null) { output.writeBoolean(false); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java index eae95e7c..859ada26 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/ProfileByUsernameResponse.java @@ -13,7 +13,7 @@ public final class ProfileByUsernameResponse extends Response { public static void writeProfile(LaunchServer server, HOutput output, String username, String client) throws IOException { - UUID uuid = server.config.authHandler[0].usernameToUUID(username); + UUID uuid = server.config.authHandler.usernameToUUID(username); if (uuid == null) { output.writeBoolean(false); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java index 1e740a7e..c88c8486 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java @@ -20,7 +20,7 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { try { - LaunchServer.server.config.authHandler[0].checkServer(username, serverID); + LaunchServer.server.config.authHandler.checkServer(username, serverID); } catch (AuthException e) { service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage())); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java index b9a5b502..0ece3b78 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java @@ -22,7 +22,7 @@ public String getType() { public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { boolean success; try { - success = LaunchServer.server.config.authHandler[0].joinServer(username, accessToken, serverID); + success = LaunchServer.server.config.authHandler.joinServer(username, accessToken, serverID); } catch (AuthException e) { service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage())); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java index 39cb3dd0..55859b52 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/texture/RequestTextureProvider.java @@ -11,8 +11,16 @@ import java.util.UUID; public final class RequestTextureProvider extends TextureProvider { + public RequestTextureProvider() { + } + private static final UUID ZERO_UUID = new UUID(0, 0); + public RequestTextureProvider(String skinURL, String cloakURL) { + this.skinURL = skinURL; + this.cloakURL = cloakURL; + } + private static Texture getTexture(String url, boolean cloak) throws IOException { LogHelper.debug("Getting texture: '%s'", url); try { diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 3d96d21b..6f30ed9c 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -1,5 +1,6 @@ package ru.gravit.launcher; +import com.google.gson.GsonBuilder; import ru.gravit.launcher.client.*; import ru.gravit.launcher.gui.choosebox.CheckComboBox; import ru.gravit.launcher.gui.choosebox.CheckComboBoxSkin; @@ -130,6 +131,7 @@ public static void main(String... args) throws Throwable { LogHelper.printVersion("Launcher"); LogHelper.printLicense("Launcher"); // Start Launcher + initGson(); Instant start = Instant.now(); try { new LauncherEngine().start(args); @@ -141,6 +143,13 @@ public static void main(String... args) throws Throwable { LogHelper.debug("Launcher started in %dms", Duration.between(start, end).toMillis()); } + public static void initGson() + { + if(Launcher.gson != null) return; + Launcher.gsonBuilder = new GsonBuilder(); + Launcher.gson = Launcher.gsonBuilder.create(); + } + // Instance private final AtomicBoolean started = new AtomicBoolean(false); diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index 51ab3e29..1994075d 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -1,6 +1,7 @@ package ru.gravit.launcher.client; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import ru.gravit.launcher.*; import ru.gravit.launcher.hasher.DirWatcher; @@ -400,6 +401,7 @@ public static Process launch( public static void main(String... args) throws Throwable { Launcher.modulesManager = new ClientModuleManager(null); LauncherConfig.getAutogenConfig().initModules(); //INIT + initGson(); LauncherEngine engine = LauncherEngine.clientInstance(); engine.loadScript(Launcher.API_SCRIPT_FILE); engine.loadScript(Launcher.CONFIG_SCRIPT_FILE); @@ -536,6 +538,13 @@ private static LinkedList resolveClassPathList(Path clientDir, String... c return result; } + public static void initGson() + { + if(Launcher.gson != null) return; + Launcher.gsonBuilder = new GsonBuilder(); + Launcher.gson = Launcher.gsonBuilder.create(); + } + @LauncherAPI public static void setProfile(ClientProfile profile) { Launcher.profile = profile;