Перевод конфигов на Json часть 8

Порция фиксов
Комплируется, пока не работает
This commit is contained in:
Gravit 2018-12-24 12:51:47 +07:00
parent 28cb9b0f23
commit 08d7f61a19
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
16 changed files with 67 additions and 20 deletions

View file

@ -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"))) {

View file

@ -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<UUID, Entry> entryCache = new HashMap<>(1024);
@Expose(serialize = false, deserialize = false)
private final Map<String, UUID> usernamesCache = new HashMap<>(1024);
private transient final Map<UUID, Entry> entryCache = new HashMap<>(1024);
private transient final Map<String, UUID> usernamesCache = new HashMap<>(1024);
protected void addEntry(Entry entry) {

View file

@ -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<String, Class> 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;
}

View file

@ -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

View file

@ -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);

View file

@ -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));

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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 {

View file

@ -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);

View file

@ -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<Path> 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;