diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 6a353e9a..da369875 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -113,8 +113,6 @@ public AuthProviderPair getAuthProviderPair() public PermissionsHandler permissionsHandler; - public TextureProvider textureProvider; - public HWIDHandler hwidHandler; // Misc options @@ -202,9 +200,6 @@ public void verify() { { throw new IllegalStateException("No auth pairs declared by default."); } - if (textureProvider == null) { - throw new NullPointerException("TextureProvider must not be null"); - } if (permissionsHandler == null) { throw new NullPointerException("PermissionsHandler must not be null"); } @@ -223,11 +218,6 @@ public void close() } catch (IOException e) { LogHelper.error(e); } - try { - textureProvider.close(); - } catch (IOException e) { - LogHelper.error(e); - } try { hwidHandler.close(); } catch (Exception e) { @@ -494,9 +484,9 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE reloadManager.registerReloadable("auth.".concat(pair.name).concat(".provider"), (Reloadable) pair.provider); if (pair.handler instanceof Reloadable) reloadManager.registerReloadable("auth.".concat(pair.name).concat(".handler"), (Reloadable) pair.handler); + if (pair.textureProvider instanceof Reloadable) + reloadManager.registerReloadable("auth.".concat(pair.name).concat(".texture"), (Reloadable) pair.textureProvider); } - if (config.textureProvider instanceof Reloadable) - reloadManager.registerReloadable("textureProvider", (Reloadable) config.textureProvider); Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror); @@ -508,9 +498,9 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE reconfigurableManager.registerReconfigurable("auth.".concat(pair.name).concat(".provider"), (Reconfigurable) pair.provider); if (pair.handler instanceof Reconfigurable) reconfigurableManager.registerReconfigurable("auth.".concat(pair.name).concat(".handler"), (Reconfigurable) pair.handler); + if (pair.textureProvider instanceof Reconfigurable) + reconfigurableManager.registerReconfigurable("auth.".concat(pair.name).concat(".texture"), (Reconfigurable) pair.textureProvider); } - if (config.textureProvider instanceof Reconfigurable) - reconfigurableManager.registerReconfigurable("textureProvider", (Reconfigurable) config.textureProvider); Arrays.stream(config.mirrors).forEach(mirrorManager::addMirror); @@ -617,8 +607,10 @@ private void generateConfigIfNotExists() throws IOException { newConfig.env = LauncherConfig.LauncherEnvironment.STD; newConfig.startScript = JVMHelper.OS_TYPE.equals(JVMHelper.OS.MUSTDIE) ? "." + File.separator + "start.bat" : "." + File.separator + "start.sh"; newConfig.hwidHandler = new AcceptHWIDHandler(); - newConfig.auth = new AuthProviderPair[]{ new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), new MemoryAuthHandler(), "std") }; - newConfig.textureProvider = new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png"); + newConfig.auth = new AuthProviderPair[]{ new AuthProviderPair(new RejectAuthProvider("Настройте authProvider"), + new MemoryAuthHandler(), + new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png") + , "std") }; newConfig.permissionsHandler = new JsonFilePermissionsHandler(); newConfig.port = 7240; newConfig.bindAddress = "0.0.0.0"; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java index 38e45f4e..b617f9e5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthProviderPair.java @@ -2,18 +2,21 @@ import ru.gravit.launchserver.auth.handler.AuthHandler; import ru.gravit.launchserver.auth.provider.AuthProvider; +import ru.gravit.launchserver.texture.TextureProvider; import java.io.IOException; public class AuthProviderPair { public AuthProvider provider; public AuthHandler handler; + public TextureProvider textureProvider; public String name; public boolean isDefault = true; - public AuthProviderPair(AuthProvider provider, AuthHandler handler, String name) { + public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvider textureProvider, String name) { this.provider = provider; this.handler = handler; + this.textureProvider = textureProvider; this.name = name; } @@ -26,5 +29,6 @@ public void init() public void close() throws IOException { provider.close(); handler.close(); + textureProvider.close(); } } 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 3eeb5ae6..f115ee28 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 @@ -147,7 +147,7 @@ public void reply() throws Exception { } writeNoError(output); // Write profile and UUID - ProfileByUUIDResponse.getProfile(server, uuid, result.username, client).write(output); + ProfileByUUIDResponse.getProfile(server, uuid, result.username, client, clientData.auth.textureProvider).write(output); output.writeASCII(result.accessToken, -SecurityHelper.TOKEN_STRING_LENGTH); clientData.permissions.write(output); } 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 7638242d..51b10fd5 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 @@ -48,6 +48,6 @@ public void reply() throws IOException { // Write profile and UUID output.writeBoolean(uuid != null); if (uuid != null) - ProfileByUUIDResponse.getProfile(server, uuid, username, client).write(output); + ProfileByUUIDResponse.getProfile(server, uuid, username, client, clientData.auth.textureProvider).write(output); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java index ef0a45f0..9981a8bf 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/profile/BatchProfileByUsernameResponse.java @@ -30,6 +30,6 @@ public void reply() throws IOException { // Respond with profiles array for (int i = 0; i < usernames.length; i++) - ProfileByUsernameResponse.writeProfile(server, output, usernames[i], clients[i], clientData.auth.handler); + ProfileByUsernameResponse.writeProfile(server, output, usernames[i], clients[i], clientData.auth); } } 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 b683fa51..3227efe4 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 @@ -8,6 +8,7 @@ import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.texture.TextureProvider; import ru.gravit.utils.helper.LogHelper; import java.io.IOException; @@ -15,11 +16,11 @@ public final class ProfileByUUIDResponse extends Response { - public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client) { + public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String username, String client, TextureProvider textureProvider) { // Get skin texture Texture skin; try { - skin = server.config.textureProvider.getSkinTexture(uuid, username, client); + skin = textureProvider.getSkinTexture(uuid, username, client); } catch (IOException e) { LogHelper.error(new IOException(String.format("Can't get skin texture: '%s'", username), e)); skin = null; @@ -28,7 +29,7 @@ public static PlayerProfile getProfile(LaunchServer server, UUID uuid, String us // Get cloak texture Texture cloak; try { - cloak = server.config.textureProvider.getCloakTexture(uuid, username, client); + cloak = textureProvider.getCloakTexture(uuid, username, client); } catch (IOException e) { LogHelper.error(new IOException(String.format("Can't get cloak texture: '%s'", username), e)); cloak = null; @@ -56,6 +57,6 @@ public void reply() throws IOException { // Write profile output.writeBoolean(true); - getProfile(server, uuid, username, client).write(output); + getProfile(server, uuid, username, client, clientData.auth.textureProvider).write(output); } } 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 2d63fd68..d09468b2 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 @@ -4,6 +4,7 @@ import ru.gravit.launcher.serialize.HOutput; import ru.gravit.launcher.serialize.SerializeLimits; import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.auth.AuthProviderPair; import ru.gravit.launchserver.auth.handler.AuthHandler; import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.socket.Client; @@ -14,8 +15,8 @@ public final class ProfileByUsernameResponse extends Response { - public static void writeProfile(LaunchServer server, HOutput output, String username, String client, AuthHandler handler) throws IOException { - UUID uuid = handler.usernameToUUID(username); + public static void writeProfile(LaunchServer server, HOutput output, String username, String client, AuthProviderPair pair) throws IOException { + UUID uuid = pair.handler.usernameToUUID(username); if (uuid == null) { output.writeBoolean(false); return; @@ -23,7 +24,7 @@ public static void writeProfile(LaunchServer server, HOutput output, String user // Write profile output.writeBoolean(true); - ProfileByUUIDResponse.getProfile(server, uuid, username, client).write(output); + ProfileByUUIDResponse.getProfile(server, uuid, username, client, pair.textureProvider).write(output); } public ProfileByUsernameResponse(LaunchServer server, long session, HInput input, HOutput output, String ip, Client clientData) { @@ -36,6 +37,6 @@ public void reply() throws IOException { debug("Username: " + username); String client = input.readString(SerializeLimits.MAX_CLIENT); // Write response - writeProfile(server, output, username, client, clientData.auth.handler); + writeProfile(server, output, username, client, clientData.auth); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index 88371df9..01ed5b1c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -117,7 +117,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData.updateAuth(); result.accessToken = aresult.accessToken; result.permissions = clientData.permissions; - result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,aresult.username,client); + result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,aresult.username,client, clientData.auth.textureProvider); service.sendObject(ctx, result); } catch (AuthException | HWIDException e) { service.sendObject(ctx, new ErrorRequestEvent(e.getMessage())); 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 2e07a30c..46c1bdfc 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 @@ -27,7 +27,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client try { result.uuid = pClient.auth.handler.checkServer(username, serverID); if(result.uuid != null) - result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,result.uuid,username,client); + result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,result.uuid,username,client, pClient.auth.textureProvider); } catch (AuthException e) { service.sendObject(ctx, new ErrorRequestEvent(e.getMessage())); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java index 477e8e95..c3945080 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java @@ -29,7 +29,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client for(int i=0;i