From ae685e906893da69a28dbc363716da55de359221 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Tue, 3 Nov 2020 19:43:25 +0100 Subject: [PATCH 1/2] Move ConfigurationPaths into type based paths, add some custom exceptions, ... --- .../java/de/bixilon/minosoft/Minosoft.java | 21 +++++------ .../config/ConfigMigrationException.java | 35 +++++++++++++++++++ .../minosoft/config/Configuration.java | 32 +++++++---------- .../minosoft/config/ConfigurationPaths.java | 27 ++++++++------ .../minosoft/data/assets/AssetsManager.java | 2 +- .../data/mappings/versions/Versions.java | 2 +- .../minosoft/gui/main/ServerListCell.java | 1 - .../minosoft/gui/main/SettingsWindow.java | 2 +- .../java/de/bixilon/minosoft/logging/Log.java | 6 ++-- .../protocol/protocol/PacketHandler.java | 2 +- .../util/mojang/api/MojangAuthentication.java | 4 +-- 11 files changed, 83 insertions(+), 51 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/config/ConfigMigrationException.java diff --git a/src/main/java/de/bixilon/minosoft/Minosoft.java b/src/main/java/de/bixilon/minosoft/Minosoft.java index 2981386b5..48f72e968 100644 --- a/src/main/java/de/bixilon/minosoft/Minosoft.java +++ b/src/main/java/de/bixilon/minosoft/Minosoft.java @@ -51,9 +51,6 @@ public final class Minosoft { public static Configuration config; public static void main(String[] args) { - // init log thread - Log.initThread(); - Log.info("Starting..."); AsyncTaskWorker taskWorker = new AsyncTaskWorker("StartUp"); @@ -108,9 +105,9 @@ public final class Minosoft { e.printStackTrace(); return; } - Log.info(String.format("Loaded config file (version=%s)", config.getInt(ConfigurationPaths.CONFIG_VERSION))); + Log.info(String.format("Loaded config file (version=%s)", config.getInt(ConfigurationPaths.IntegerPaths.GENERAL_CONFIG_VERSION))); // set log level from config - Log.setLevel(LogLevels.valueOf(config.getString(ConfigurationPaths.GENERAL_LOG_LEVEL))); + Log.setLevel(LogLevels.valueOf(config.getString(ConfigurationPaths.StringPaths.GENERAL_LOG_LEVEL))); Log.info(String.format("Logging info with level: %s", Log.getLevel())); serverList = config.getServers(); @@ -123,7 +120,7 @@ public final class Minosoft { taskWorker.addTask(new Task(progress -> { progress.countUp(); - LocaleManager.load(config.getString(ConfigurationPaths.GENERAL_LANGUAGE)); + LocaleManager.load(config.getString(ConfigurationPaths.StringPaths.GENERAL_LANGUAGE)); progress.countDown(); }, "Minosoft Language", "Load minosoft language files", Priorities.HIGH, TaskImportance.REQUIRED, "Configuration")); @@ -140,7 +137,7 @@ public final class Minosoft { Log.debug("Refreshing account token..."); checkClientToken(); accountList = config.getMojangAccounts(); - selectAccount(accountList.get(config.getString(ConfigurationPaths.ACCOUNT_SELECTED))); + selectAccount(accountList.get(config.getString(ConfigurationPaths.StringPaths.ACCOUNT_SELECTED))); }, "Token refresh", "Refresh selected account token", Priorities.LOW, TaskImportance.OPTIONAL, "Configuration")); taskWorker.addTask(new Task(progress -> { @@ -157,7 +154,7 @@ public final class Minosoft { taskWorker.addTask(new Task(progress -> { progress.countUp(); - MinecraftLocaleManager.load(config.getString(ConfigurationPaths.GENERAL_LANGUAGE)); + MinecraftLocaleManager.load(config.getString(ConfigurationPaths.StringPaths.GENERAL_LANGUAGE)); progress.countDown(); }, "Mojang language", "Load minecraft language files", Priorities.HIGH, TaskImportance.REQUIRED, "Assets")); @@ -171,8 +168,8 @@ public final class Minosoft { } public static void checkClientToken() { - if (config.getString(ConfigurationPaths.CLIENT_TOKEN).isBlank()) { - config.putString(ConfigurationPaths.CLIENT_TOKEN, UUID.randomUUID().toString()); + if (config.getString(ConfigurationPaths.StringPaths.CLIENT_TOKEN).isBlank()) { + config.putString(ConfigurationPaths.StringPaths.CLIENT_TOKEN, UUID.randomUUID().toString()); config.saveToFile(); } } @@ -180,7 +177,7 @@ public final class Minosoft { public static void selectAccount(MojangAccount account) { if (account == null) { selectedAccount = null; - config.putString(ConfigurationPaths.ACCOUNT_SELECTED, ""); + config.putString(ConfigurationPaths.StringPaths.ACCOUNT_SELECTED, ""); config.saveToFile(); return; } @@ -192,7 +189,7 @@ public final class Minosoft { selectedAccount = null; return; } - config.putString(ConfigurationPaths.ACCOUNT_SELECTED, account.getUserId()); + config.putString(ConfigurationPaths.StringPaths.ACCOUNT_SELECTED, account.getUserId()); selectedAccount = account; MainWindow.selectAccount(); account.saveToConfig(); diff --git a/src/main/java/de/bixilon/minosoft/config/ConfigMigrationException.java b/src/main/java/de/bixilon/minosoft/config/ConfigMigrationException.java new file mode 100644 index 000000000..ac99e0bee --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/ConfigMigrationException.java @@ -0,0 +1,35 @@ +/* + * Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.config; + +public class ConfigMigrationException extends Exception { + public ConfigMigrationException() { + } + + public ConfigMigrationException(String message) { + super(message); + } + + public ConfigMigrationException(String message, Throwable cause) { + super(message, cause); + } + + public ConfigMigrationException(Throwable cause) { + super(cause); + } + + public ConfigMigrationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/de/bixilon/minosoft/config/Configuration.java b/src/main/java/de/bixilon/minosoft/config/Configuration.java index 8a42d054e..7c3f6e119 100644 --- a/src/main/java/de/bixilon/minosoft/config/Configuration.java +++ b/src/main/java/de/bixilon/minosoft/config/Configuration.java @@ -32,7 +32,7 @@ public class Configuration { final JsonObject config; private final Object lock = new Object(); - public Configuration() throws IOException { + public Configuration() throws IOException, ConfigMigrationException { File file = new File(StaticConfiguration.HOME_DIR + "config/" + StaticConfiguration.CONFIG_FILENAME); if (!file.exists()) { // no configuration file @@ -48,9 +48,9 @@ public class Configuration { file = new File(StaticConfiguration.HOME_DIR + "config/" + StaticConfiguration.CONFIG_FILENAME); } config = Util.readJsonFromFile(file.getAbsolutePath()); - int configVersion = getInt(ConfigurationPaths.CONFIG_VERSION); + int configVersion = getInt(ConfigurationPaths.IntegerPaths.GENERAL_CONFIG_VERSION); if (configVersion > LATEST_CONFIG_VERSION) { - throw new RuntimeException(String.format("Configuration was migrated to newer config format (version=%d, expected=%d). Downgrading the config file is unsupported!", configVersion, LATEST_CONFIG_VERSION)); + throw new ConfigMigrationException(String.format("Configuration was migrated to newer config format (version=%d, expected=%d). Downgrading the config file is unsupported!", configVersion, LATEST_CONFIG_VERSION)); } if (configVersion < LATEST_CONFIG_VERSION) { migrateConfiguration(); @@ -96,57 +96,51 @@ public class Configuration { }, "IO").start(); } - public boolean getBoolean(ConfigurationPaths path) { + public boolean getBoolean(ConfigurationPaths.BooleanPaths path) { return switch (path) { case NETWORK_FAKE_CLIENT_BRAND -> config.getAsJsonObject("network").get("fake-network-brand").getAsBoolean(); case DEBUG_VERIFY_ASSETS -> config.getAsJsonObject("debug").get("verify-assets").getAsBoolean(); - default -> throw new RuntimeException(String.format("Illegal boolean value: %s", path)); }; } - public void putBoolean(ConfigurationPaths path, boolean value) { + public void putBoolean(ConfigurationPaths.BooleanPaths path, boolean value) { switch (path) { case NETWORK_FAKE_CLIENT_BRAND -> config.getAsJsonObject("network").addProperty("fake-network-brand", value); case DEBUG_VERIFY_ASSETS -> config.getAsJsonObject("debug").addProperty("verify-assets", value); - default -> throw new RuntimeException(String.format("Illegal boolean value: %s", path)); } } - public int getInt(ConfigurationPaths path) { + public int getInt(ConfigurationPaths.IntegerPaths path) { return switch (path) { - case CONFIG_VERSION -> config.getAsJsonObject("general").get("version").getAsInt(); + case GENERAL_CONFIG_VERSION -> config.getAsJsonObject("general").get("version").getAsInt(); case GAME_RENDER_DISTANCE -> config.getAsJsonObject("game").get("render-distance").getAsInt(); - default -> throw new RuntimeException(String.format("Illegal int value: %s", path)); }; } - public void putInt(ConfigurationPaths path, int value) { + public void putInt(ConfigurationPaths.IntegerPaths path, int value) { switch (path) { - case CONFIG_VERSION -> config.getAsJsonObject("general").addProperty("version", value); + case GENERAL_CONFIG_VERSION -> config.getAsJsonObject("general").addProperty("version", value); case GAME_RENDER_DISTANCE -> config.getAsJsonObject("game").addProperty("render-distance", value); - default -> throw new RuntimeException(String.format("Illegal int value: %s", path)); } } - public String getString(ConfigurationPaths path) { + public String getString(ConfigurationPaths.StringPaths path) { return switch (path) { case ACCOUNT_SELECTED -> config.getAsJsonObject("accounts").get("selected").getAsString(); case GENERAL_LOG_LEVEL -> config.getAsJsonObject("general").get("log-level").getAsString(); case GENERAL_LANGUAGE -> config.getAsJsonObject("general").get("language").getAsString(); case MAPPINGS_URL -> config.getAsJsonObject("download").getAsJsonObject("urls").get("mappings").getAsString(); case CLIENT_TOKEN -> config.getAsJsonObject("accounts").get("client-token").getAsString(); - default -> throw new RuntimeException(String.format("Illegal String value: %s", path)); }; } - public void putString(ConfigurationPaths path, String value) { + public void putString(ConfigurationPaths.StringPaths path, String value) { switch (path) { case ACCOUNT_SELECTED -> config.getAsJsonObject("accounts").addProperty("selected", value); case GENERAL_LOG_LEVEL -> config.getAsJsonObject("general").addProperty("log-level", value); case GENERAL_LANGUAGE -> config.getAsJsonObject("general").addProperty("language", value); case MAPPINGS_URL -> config.getAsJsonObject("download").getAsJsonObject("urls").addProperty("mappings", value); case CLIENT_TOKEN -> config.getAsJsonObject("accounts").addProperty("client-token", value); - default -> throw new RuntimeException(String.format("Illegal String value: %s", path)); } } @@ -194,12 +188,12 @@ public class Configuration { } private void migrateConfiguration() { - int configVersion = getInt(ConfigurationPaths.CONFIG_VERSION); + int configVersion = getInt(ConfigurationPaths.IntegerPaths.GENERAL_CONFIG_VERSION); Log.info(String.format("Migrating config from version %d to %d", configVersion, LATEST_CONFIG_VERSION)); for (int nextVersion = configVersion + 1; nextVersion <= LATEST_CONFIG_VERSION; nextVersion++) { migrateConfiguration(nextVersion); } - putInt(ConfigurationPaths.CONFIG_VERSION, LATEST_CONFIG_VERSION); + putInt(ConfigurationPaths.IntegerPaths.GENERAL_CONFIG_VERSION, LATEST_CONFIG_VERSION); saveToFile(); Log.info("Finished migrating config!"); diff --git a/src/main/java/de/bixilon/minosoft/config/ConfigurationPaths.java b/src/main/java/de/bixilon/minosoft/config/ConfigurationPaths.java index 01b0b49a3..5f7c68ac7 100644 --- a/src/main/java/de/bixilon/minosoft/config/ConfigurationPaths.java +++ b/src/main/java/de/bixilon/minosoft/config/ConfigurationPaths.java @@ -13,14 +13,21 @@ package de.bixilon.minosoft.config; -public enum ConfigurationPaths { - CONFIG_VERSION, - GAME_RENDER_DISTANCE, - NETWORK_FAKE_CLIENT_BRAND, - GENERAL_LOG_LEVEL, - CLIENT_TOKEN, - MAPPINGS_URL, - ACCOUNT_SELECTED, - GENERAL_LANGUAGE, - DEBUG_VERIFY_ASSETS, +public abstract class ConfigurationPaths { + public enum StringPaths { + GENERAL_LOG_LEVEL, + CLIENT_TOKEN, + MAPPINGS_URL, + ACCOUNT_SELECTED, + GENERAL_LANGUAGE, + } + + public enum BooleanPaths { + NETWORK_FAKE_CLIENT_BRAND, DEBUG_VERIFY_ASSETS + } + + public enum IntegerPaths { + GENERAL_CONFIG_VERSION, + GAME_RENDER_DISTANCE + } } diff --git a/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java b/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java index efdd220ef..72be9b975 100644 --- a/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java +++ b/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java @@ -152,7 +152,7 @@ public class AssetsManager { if (getAssetSize(hash) == -1) { return false; } - if (!Minosoft.config.getBoolean(ConfigurationPaths.DEBUG_VERIFY_ASSETS)) { + if (!Minosoft.config.getBoolean(ConfigurationPaths.BooleanPaths.DEBUG_VERIFY_ASSETS)) { return true; } try { diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/versions/Versions.java b/src/main/java/de/bixilon/minosoft/data/mappings/versions/Versions.java index 9fd2f28fb..4c8cfb2e3 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/versions/Versions.java +++ b/src/main/java/de/bixilon/minosoft/data/mappings/versions/Versions.java @@ -145,7 +145,7 @@ public class Versions { } catch (FileNotFoundException e) { long downloadStartTime = System.currentTimeMillis(); Log.info(String.format("Mappings for %s are not available on disk. Downloading them...", version.getVersionName())); - Util.downloadFile(String.format(Minosoft.getConfig().getString(ConfigurationPaths.MAPPINGS_URL), version.getVersionName()), fileName); + Util.downloadFile(String.format(Minosoft.getConfig().getString(ConfigurationPaths.StringPaths.MAPPINGS_URL), version.getVersionName()), fileName); try { files = Util.readJsonTarGzFile(fileName); } catch (ZipException e2) { diff --git a/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java b/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java index 2237a5579..d26780091 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java @@ -190,7 +190,6 @@ public class ServerListCell extends ListCell implements Initializable { setErrorMotd(String.format("%s", server.getLastPing().getLastConnectionException().getLocalizedMessage())); } })); - } @Override diff --git a/src/main/java/de/bixilon/minosoft/gui/main/SettingsWindow.java b/src/main/java/de/bixilon/minosoft/gui/main/SettingsWindow.java index 3340f2f3f..22840e2c1 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/SettingsWindow.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/SettingsWindow.java @@ -45,7 +45,7 @@ public class SettingsWindow implements Initializable { return; } Log.setLevel(newLevel); - Minosoft.getConfig().putString(ConfigurationPaths.GENERAL_LOG_LEVEL, newLevel.name()); + Minosoft.getConfig().putString(ConfigurationPaths.StringPaths.GENERAL_LOG_LEVEL, newLevel.name()); Minosoft.getConfig().saveToFile(); })); diff --git a/src/main/java/de/bixilon/minosoft/logging/Log.java b/src/main/java/de/bixilon/minosoft/logging/Log.java index 5d2126772..ce4d97bd3 100644 --- a/src/main/java/de/bixilon/minosoft/logging/Log.java +++ b/src/main/java/de/bixilon/minosoft/logging/Log.java @@ -24,10 +24,10 @@ import java.util.concurrent.LinkedBlockingQueue; public class Log { final static SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); final static LinkedBlockingQueue queue = new LinkedBlockingQueue<>(); - final static long startTime = System.currentTimeMillis(); + public final static long MINOSOFT_START_TIME = System.currentTimeMillis(); static LogLevels level = LogLevels.PROTOCOL; - public static void initThread() { + static { new Thread(() -> { while (true) { // something to print @@ -69,7 +69,7 @@ public class Log { StringBuilder builder = new StringBuilder(); builder.append("["); if (StaticConfiguration.LOG_RELATIVE_TIME) { - builder.append(System.currentTimeMillis() - startTime); + builder.append(System.currentTimeMillis() - MINOSOFT_START_TIME); } else { builder.append(timeFormat.format(System.currentTimeMillis())); } diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java index 086f680eb..e46ad6bbc 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java @@ -199,7 +199,7 @@ public class PacketHandler { if (pkg.getChannel().equals(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(connection.getVersion().getVersionId()))) { InByteBuffer data = pkg.getDataAsBuffer(); String serverVersion; - String clientVersion = (Minosoft.getConfig().getBoolean(ConfigurationPaths.NETWORK_FAKE_CLIENT_BRAND) ? "vanilla" : "Minosoft"); + String clientVersion = (Minosoft.getConfig().getBoolean(ConfigurationPaths.BooleanPaths.NETWORK_FAKE_CLIENT_BRAND) ? "vanilla" : "Minosoft"); OutByteBuffer toSend = new OutByteBuffer(connection); if (connection.getVersion().getVersionId() < 29) { // no length prefix diff --git a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAuthentication.java b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAuthentication.java index e739436ca..ea24e439e 100644 --- a/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAuthentication.java +++ b/src/main/java/de/bixilon/minosoft/util/mojang/api/MojangAuthentication.java @@ -26,7 +26,7 @@ import java.net.http.HttpResponse; public final class MojangAuthentication { public static MojangAccountAuthenticationAttempt login(String username, String password) { - return login(Minosoft.getConfig().getString(ConfigurationPaths.CLIENT_TOKEN), username, password); + return login(Minosoft.getConfig().getString(ConfigurationPaths.StringPaths.CLIENT_TOKEN), username, password); } public static MojangAccountAuthenticationAttempt login(String clientToken, String username, String password) { @@ -81,7 +81,7 @@ public final class MojangAuthentication { } public static String refresh(String accessToken) { - return refresh(Minosoft.getConfig().getString(ConfigurationPaths.CLIENT_TOKEN), accessToken); + return refresh(Minosoft.getConfig().getString(ConfigurationPaths.StringPaths.CLIENT_TOKEN), accessToken); } public static String refresh(String clientToken, String accessToken) { From e24b657c3f12adc009ae08bb36e0bce4c52d4b8e Mon Sep 17 00:00:00 2001 From: Bixilon Date: Tue, 3 Nov 2020 20:07:19 +0100 Subject: [PATCH 2/2] More custom exceptions --- ReadMe.md | 4 +-- .../mappings/MappingsLoadingException.java | 35 +++++++++++++++++++ .../minosoft/gui/main/ServerListCell.java | 2 +- .../minosoft/protocol/network/Connection.java | 3 +- .../network/socket/SocketNetwork.java | 10 ++---- .../protocol/PacketParseException.java | 35 +++++++++++++++++++ .../protocol/UnknownPacketException.java | 35 +++++++++++++++++++ 7 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/data/mappings/MappingsLoadingException.java create mode 100644 src/main/java/de/bixilon/minosoft/protocol/protocol/PacketParseException.java create mode 100644 src/main/java/de/bixilon/minosoft/protocol/protocol/UnknownPacketException.java diff --git a/ReadMe.md b/ReadMe.md index 3201942b6..6f6420012 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -31,10 +31,10 @@ Minosoft is an open source minecraft client, written from scratch in java. It ai ## Rendering Rendering is developed and maintained by Lukas Eisenhauer. It is very WIP, but it works. See !8 for more details. -![Rendering](doc/img/rendering.png) +![Rendering](doc/img/rendering.png) The current result of rendering (taken in 739f861bf62341698abcd58386c353a4831f4818). -![Rendering](doc/img/rendering_hypixel.png) +![Rendering](doc/img/rendering_hypixel.png) The Hypixel prototype lobby (taken in 91ab431004fa1ae132a1eb1115550f84c27f48f8). ## Launcher diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/MappingsLoadingException.java b/src/main/java/de/bixilon/minosoft/data/mappings/MappingsLoadingException.java new file mode 100644 index 000000000..77fc02e74 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/mappings/MappingsLoadingException.java @@ -0,0 +1,35 @@ +/* + * Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.data.mappings; + +public class MappingsLoadingException extends Exception { + public MappingsLoadingException() { + } + + public MappingsLoadingException(String message) { + super(message); + } + + public MappingsLoadingException(String message, Throwable cause) { + super(message, cause); + } + + public MappingsLoadingException(Throwable cause) { + super(cause); + } + + public MappingsLoadingException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java b/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java index d26780091..4da172cb5 100644 --- a/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java +++ b/src/main/java/de/bixilon/minosoft/gui/main/ServerListCell.java @@ -187,7 +187,7 @@ public class ServerListCell extends ListCell implements Initializable { version.setStyle("-fx-text-fill: red;"); optionsConnect.setDisable(true); canConnect = false; - setErrorMotd(String.format("%s", server.getLastPing().getLastConnectionException().getLocalizedMessage())); + setErrorMotd(String.format("%s: %s", server.getLastPing().getLastConnectionException().getClass().getCanonicalName(), server.getLastPing().getLastConnectionException().getLocalizedMessage())); } })); } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java b/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java index 7cf5a3573..5de6560f3 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java +++ b/src/main/java/de/bixilon/minosoft/protocol/network/Connection.java @@ -17,6 +17,7 @@ import de.bixilon.minosoft.Minosoft; import de.bixilon.minosoft.data.Player; import de.bixilon.minosoft.data.VelocityHandler; import de.bixilon.minosoft.data.mappings.CustomMapping; +import de.bixilon.minosoft.data.mappings.MappingsLoadingException; import de.bixilon.minosoft.data.mappings.recipes.Recipes; import de.bixilon.minosoft.data.mappings.versions.Version; import de.bixilon.minosoft.data.mappings.versions.Versions; @@ -160,7 +161,7 @@ public class Connection { } catch (IOException e) { Log.printException(e, LogLevels.DEBUG); Log.fatal(String.format("Could not load mapping for %s. This version seems to be unsupported!", version)); - lastException = new RuntimeException(String.format("Mappings could not be loaded: %s", e.getLocalizedMessage())); + lastException = new MappingsLoadingException("Mappings could not be loaded", e); setConnectionState(ConnectionStates.FAILED_NO_RETRY); } } diff --git a/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java b/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java index 61ce17ae4..63f7e1a1e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java +++ b/src/main/java/de/bixilon/minosoft/protocol/network/socket/SocketNetwork.java @@ -192,24 +192,20 @@ public class SocketNetwork implements Network { try { packet = connection.getPacketByCommand(connection.getConnectionState(), inPacketBuffer.getCommand()); if (packet == null) { - Log.fatal(String.format("Packet mapping does not contain a packet with id 0x%x. The server sends bullshit or your versions.json broken!", inPacketBuffer.getCommand())); disconnect(); - lastException = new RuntimeException(String.format("Invalid packet 0x%x", inPacketBuffer.getCommand())); + lastException = new UnknownPacketException(String.format("Invalid packet 0x%x", inPacketBuffer.getCommand())); throw lastException; } Class clazz = packet.getClazz(); if (clazz == null) { - Log.warn(String.format("[IN] Received unknown packet (id=0x%x, name=%s, length=%d, dataLength=%d, version=%s, state=%s)", inPacketBuffer.getCommand(), packet, inPacketBuffer.getLength(), inPacketBuffer.getBytesLeft(), connection.getVersion(), connection.getConnectionState())); - continue; + throw new UnknownPacketException(String.format("Unknown packet (id=0x%x, name=%s, length=%d, dataLength=%d, version=%s, state=%s)", inPacketBuffer.getCommand(), packet, inPacketBuffer.getLength(), inPacketBuffer.getBytesLeft(), connection.getVersion(), connection.getConnectionState())); } try { ClientboundPacket packetInstance = clazz.getConstructor().newInstance(); boolean success = packetInstance.read(inPacketBuffer); if (inPacketBuffer.getBytesLeft() > 0 || !success) { - // warn not all data used - Log.warn(String.format("[IN] Could not parse packet %s (used=%d, available=%d, total=%d, success=%s)", packet, inPacketBuffer.getPosition(), inPacketBuffer.getBytesLeft(), inPacketBuffer.getLength(), success)); - continue; + throw new PacketParseException(String.format("Could not parse packet %s (used=%d, available=%d, total=%d, success=%s)", packet, inPacketBuffer.getPosition(), inPacketBuffer.getBytesLeft(), inPacketBuffer.getLength(), success)); } //set special settings to avoid miss timing issues diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketParseException.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketParseException.java new file mode 100644 index 000000000..0f5d39e2b --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketParseException.java @@ -0,0 +1,35 @@ +/* + * Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.protocol; + +public class PacketParseException extends Exception { + public PacketParseException() { + } + + public PacketParseException(String message) { + super(message); + } + + public PacketParseException(String message, Throwable cause) { + super(message, cause); + } + + public PacketParseException(Throwable cause) { + super(cause); + } + + public PacketParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/UnknownPacketException.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/UnknownPacketException.java new file mode 100644 index 000000000..55ca2d637 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/UnknownPacketException.java @@ -0,0 +1,35 @@ +/* + * Minosoft + * Copyright (C) 2020 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.protocol; + +public class UnknownPacketException extends Exception { + public UnknownPacketException() { + } + + public UnknownPacketException(String message) { + super(message); + } + + public UnknownPacketException(String message, Throwable cause) { + super(message, cause); + } + + public UnknownPacketException(Throwable cause) { + super(cause); + } + + public UnknownPacketException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +}