mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
Перевод конфигов на Json часть 8
Порция фиксов Комплируется, пока не работает
This commit is contained in:
parent
28cb9b0f23
commit
08d7f61a19
16 changed files with 67 additions and 20 deletions
|
@ -32,6 +32,7 @@
|
||||||
import ru.gravit.launchserver.manangers.SessionManager;
|
import ru.gravit.launchserver.manangers.SessionManager;
|
||||||
import ru.gravit.launchserver.response.Response;
|
import ru.gravit.launchserver.response.Response;
|
||||||
import ru.gravit.launchserver.socket.ServerSocketHandler;
|
import ru.gravit.launchserver.socket.ServerSocketHandler;
|
||||||
|
import ru.gravit.launchserver.texture.RequestTextureProvider;
|
||||||
import ru.gravit.launchserver.texture.TextureProvider;
|
import ru.gravit.launchserver.texture.TextureProvider;
|
||||||
import ru.gravit.utils.helper.*;
|
import ru.gravit.utils.helper.*;
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ public static final class Config {
|
||||||
|
|
||||||
// Handlers & Providers
|
// Handlers & Providers
|
||||||
|
|
||||||
public AuthHandler[] authHandler;
|
public AuthHandler authHandler;
|
||||||
|
|
||||||
public AuthProvider[] authProvider;
|
public AuthProvider[] authProvider;
|
||||||
|
|
||||||
|
@ -127,6 +128,18 @@ public void setAddress(String address) {
|
||||||
|
|
||||||
public void verify() {
|
public void verify() {
|
||||||
VerifyHelper.verify(getAddress(), VerifyHelper.NOT_EMPTY, "LaunchServer address can't be empty");
|
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
|
// Close handlers & providers
|
||||||
try {
|
try {
|
||||||
for (AuthHandler h : config.authHandler) h.close();
|
config.authHandler.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
|
@ -423,9 +436,11 @@ private void generateConfigIfNotExists() throws IOException {
|
||||||
newConfig.launch4j = new ExeConf();
|
newConfig.launch4j = new ExeConf();
|
||||||
newConfig.buildPostTransform = new PostBuildTransformConf();
|
newConfig.buildPostTransform = new PostBuildTransformConf();
|
||||||
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
||||||
newConfig.authHandler = new AuthHandler[]{new MemoryAuthHandler()};
|
newConfig.authHandler = new MemoryAuthHandler();
|
||||||
newConfig.hwidHandler = new AcceptHWIDHandler();
|
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.port = 7420;
|
||||||
newConfig.bindAddress = "0.0.0.0";
|
newConfig.bindAddress = "0.0.0.0";
|
||||||
//try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launchserver/defaults/config.cfg"))) {
|
//try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launchserver/defaults/config.cfg"))) {
|
||||||
|
|
|
@ -29,10 +29,8 @@ public Entry(UUID uuid, String username, String accessToken, String serverID) {
|
||||||
this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID);
|
this.serverID = serverID == null ? null : VerifyHelper.verifyServerID(serverID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Expose(serialize = false, deserialize = false)
|
private transient final Map<UUID, Entry> entryCache = new HashMap<>(1024);
|
||||||
private final Map<UUID, Entry> entryCache = new HashMap<>(1024);
|
private transient final Map<String, UUID> usernamesCache = new HashMap<>(1024);
|
||||||
@Expose(serialize = false, deserialize = false)
|
|
||||||
private final Map<String, UUID> usernamesCache = new HashMap<>(1024);
|
|
||||||
|
|
||||||
|
|
||||||
protected void addEntry(Entry entry) {
|
protected void addEntry(Entry entry) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ru.gravit.launchserver.auth.provider;
|
package ru.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
public abstract class AuthProvider implements AutoCloseable {
|
public abstract class AuthProvider implements AutoCloseable {
|
||||||
private static final Map<String, Class> AUTH_PROVIDERS = new ConcurrentHashMap<>(8);
|
private static final Map<String, Class> AUTH_PROVIDERS = new ConcurrentHashMap<>(8);
|
||||||
private static boolean registredProv = false;
|
private static boolean registredProv = false;
|
||||||
private LaunchServer server;
|
private transient LaunchServer server = LaunchServer.server;
|
||||||
|
|
||||||
|
|
||||||
public static AuthProviderResult authError(String message) throws AuthException {
|
public static AuthProviderResult authError(String message) throws AuthException {
|
||||||
|
@ -33,7 +34,7 @@ public static void registerProviders() {
|
||||||
registerProvider("reject", RejectAuthProvider.class);
|
registerProvider("reject", RejectAuthProvider.class);
|
||||||
|
|
||||||
// Auth providers that doesn't do nothing :D
|
// Auth providers that doesn't do nothing :D
|
||||||
registerProvider("com.mojang", MojangAuthProvider.class);
|
registerProvider("mojang", MojangAuthProvider.class);
|
||||||
registerProvider("mysql", MySQLAuthProvider.class);
|
registerProvider("mysql", MySQLAuthProvider.class);
|
||||||
registerProvider("request", RequestAuthProvider.class);
|
registerProvider("request", RequestAuthProvider.class);
|
||||||
registerProvider("json", JsonAuthProvider.class);
|
registerProvider("json", JsonAuthProvider.class);
|
||||||
|
@ -42,7 +43,7 @@ public static void registerProviders() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthHandler getAccociateHandler(int this_position) {
|
public AuthHandler getAccociateHandler(int this_position) {
|
||||||
return server.config.authHandler[0];
|
return server.config.authHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
|
|
||||||
import ru.gravit.launchserver.auth.AuthException;
|
import ru.gravit.launchserver.auth.AuthException;
|
||||||
public final class RejectAuthProvider extends AuthProvider {
|
public final class RejectAuthProvider extends AuthProvider {
|
||||||
|
public RejectAuthProvider() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RejectAuthProvider(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,7 +29,7 @@ public void invoke(String... args) throws CommandException, IOException {
|
||||||
UUID uuid = parseUUID(args[0]);
|
UUID uuid = parseUUID(args[0]);
|
||||||
|
|
||||||
// Get UUID by username
|
// Get UUID by username
|
||||||
String username = server.config.authHandler[0].uuidToUsername(uuid);
|
String username = server.config.authHandler.uuidToUsername(uuid);
|
||||||
if (username == null)
|
if (username == null)
|
||||||
throw new CommandException("Unknown UUID: " + uuid);
|
throw new CommandException("Unknown UUID: " + uuid);
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public void invoke(String... args) throws CommandException, IOException {
|
||||||
String username = parseUsername(args[0]);
|
String username = parseUsername(args[0]);
|
||||||
|
|
||||||
// Get UUID by username
|
// Get UUID by username
|
||||||
UUID uuid = server.config.authHandler[0].usernameToUUID(username);
|
UUID uuid = server.config.authHandler.usernameToUUID(username);
|
||||||
if (uuid == null)
|
if (uuid == null)
|
||||||
throw new CommandException(String.format("Unknown username: '%s'", username));
|
throw new CommandException(String.format("Unknown username: '%s'", username));
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ public void reply() throws Exception {
|
||||||
// Authenticate on server (and get UUID)
|
// Authenticate on server (and get UUID)
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
try {
|
try {
|
||||||
uuid = provider.getAccociateHandler(auth_id).auth(result);
|
uuid = server.config.authHandler.auth(result);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
requestError(e.getMessage());
|
requestError(e.getMessage());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -31,7 +31,7 @@ public void reply() throws IOException {
|
||||||
// Try check server with auth handler
|
// Try check server with auth handler
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
try {
|
try {
|
||||||
uuid = server.config.authHandler[0].checkServer(username, serverID);
|
uuid = server.config.authHandler.checkServer(username, serverID);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
requestError(e.getMessage());
|
requestError(e.getMessage());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -28,7 +28,7 @@ public void reply() throws IOException {
|
||||||
debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
|
debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
|
||||||
boolean success;
|
boolean success;
|
||||||
try {
|
try {
|
||||||
success = server.config.authHandler[0].joinServer(username, accessToken, serverID);
|
success = server.config.authHandler.joinServer(username, accessToken, serverID);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
requestError(e.getMessage());
|
requestError(e.getMessage());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -47,7 +47,7 @@ public void reply() throws IOException {
|
||||||
debug("UUID: " + uuid);
|
debug("UUID: " + uuid);
|
||||||
String client = input.readString(SerializeLimits.MAX_CLIENT);
|
String client = input.readString(SerializeLimits.MAX_CLIENT);
|
||||||
// Verify has such profile
|
// Verify has such profile
|
||||||
String username = server.config.authHandler[0].uuidToUsername(uuid);
|
String username = server.config.authHandler.uuidToUsername(uuid);
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
output.writeBoolean(false);
|
output.writeBoolean(false);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
public final class ProfileByUsernameResponse extends Response {
|
public final class ProfileByUsernameResponse extends Response {
|
||||||
|
|
||||||
public static void writeProfile(LaunchServer server, HOutput output, String username, String client) throws IOException {
|
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) {
|
if (uuid == null) {
|
||||||
output.writeBoolean(false);
|
output.writeBoolean(false);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -20,7 +20,7 @@ public String getType() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||||
try {
|
try {
|
||||||
LaunchServer.server.config.authHandler[0].checkServer(username, serverID);
|
LaunchServer.server.config.authHandler.checkServer(username, serverID);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -22,7 +22,7 @@ public String getType() {
|
||||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception {
|
||||||
boolean success;
|
boolean success;
|
||||||
try {
|
try {
|
||||||
success = LaunchServer.server.config.authHandler[0].joinServer(username, accessToken, serverID);
|
success = LaunchServer.server.config.authHandler.joinServer(username, accessToken, serverID);
|
||||||
} catch (AuthException e) {
|
} catch (AuthException e) {
|
||||||
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage()));
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -11,8 +11,16 @@
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class RequestTextureProvider extends TextureProvider {
|
public final class RequestTextureProvider extends TextureProvider {
|
||||||
|
public RequestTextureProvider() {
|
||||||
|
}
|
||||||
|
|
||||||
private static final UUID ZERO_UUID = new UUID(0, 0);
|
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 {
|
private static Texture getTexture(String url, boolean cloak) throws IOException {
|
||||||
LogHelper.debug("Getting texture: '%s'", url);
|
LogHelper.debug("Getting texture: '%s'", url);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ru.gravit.launcher;
|
package ru.gravit.launcher;
|
||||||
|
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import ru.gravit.launcher.client.*;
|
import ru.gravit.launcher.client.*;
|
||||||
import ru.gravit.launcher.gui.choosebox.CheckComboBox;
|
import ru.gravit.launcher.gui.choosebox.CheckComboBox;
|
||||||
import ru.gravit.launcher.gui.choosebox.CheckComboBoxSkin;
|
import ru.gravit.launcher.gui.choosebox.CheckComboBoxSkin;
|
||||||
|
@ -130,6 +131,7 @@ public static void main(String... args) throws Throwable {
|
||||||
LogHelper.printVersion("Launcher");
|
LogHelper.printVersion("Launcher");
|
||||||
LogHelper.printLicense("Launcher");
|
LogHelper.printLicense("Launcher");
|
||||||
// Start Launcher
|
// Start Launcher
|
||||||
|
initGson();
|
||||||
Instant start = Instant.now();
|
Instant start = Instant.now();
|
||||||
try {
|
try {
|
||||||
new LauncherEngine().start(args);
|
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());
|
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
|
// Instance
|
||||||
private final AtomicBoolean started = new AtomicBoolean(false);
|
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.gravit.launcher.client;
|
package ru.gravit.launcher.client;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import ru.gravit.launcher.*;
|
import ru.gravit.launcher.*;
|
||||||
import ru.gravit.launcher.hasher.DirWatcher;
|
import ru.gravit.launcher.hasher.DirWatcher;
|
||||||
|
@ -400,6 +401,7 @@ public static Process launch(
|
||||||
public static void main(String... args) throws Throwable {
|
public static void main(String... args) throws Throwable {
|
||||||
Launcher.modulesManager = new ClientModuleManager(null);
|
Launcher.modulesManager = new ClientModuleManager(null);
|
||||||
LauncherConfig.getAutogenConfig().initModules(); //INIT
|
LauncherConfig.getAutogenConfig().initModules(); //INIT
|
||||||
|
initGson();
|
||||||
LauncherEngine engine = LauncherEngine.clientInstance();
|
LauncherEngine engine = LauncherEngine.clientInstance();
|
||||||
engine.loadScript(Launcher.API_SCRIPT_FILE);
|
engine.loadScript(Launcher.API_SCRIPT_FILE);
|
||||||
engine.loadScript(Launcher.CONFIG_SCRIPT_FILE);
|
engine.loadScript(Launcher.CONFIG_SCRIPT_FILE);
|
||||||
|
@ -536,6 +538,13 @@ private static LinkedList<Path> resolveClassPathList(Path clientDir, String... c
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void initGson()
|
||||||
|
{
|
||||||
|
if(Launcher.gson != null) return;
|
||||||
|
Launcher.gsonBuilder = new GsonBuilder();
|
||||||
|
Launcher.gson = Launcher.gsonBuilder.create();
|
||||||
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void setProfile(ClientProfile profile) {
|
public static void setProfile(ClientProfile profile) {
|
||||||
Launcher.profile = profile;
|
Launcher.profile = profile;
|
||||||
|
|
Loading…
Reference in a new issue