Merge branch 'development' into render

This commit is contained in:
Bixilon 2020-11-03 20:08:30 +01:00
commit 687410bc31
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
17 changed files with 196 additions and 62 deletions

View File

@ -31,10 +31,10 @@ Minosoft is an open source minecraft client, written from scratch in java. It ai
## Rendering ## Rendering
Rendering is developed and maintained by Lukas Eisenhauer. It is very WIP, but it works. See !8 for more details. 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). 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). The Hypixel prototype lobby (taken in 91ab431004fa1ae132a1eb1115550f84c27f48f8).
## Launcher ## Launcher

View File

@ -52,9 +52,6 @@ public final class Minosoft {
public static Configuration config; public static Configuration config;
public static void main(String[] args) { public static void main(String[] args) {
// init log thread
Log.initThread();
Log.info("Starting..."); Log.info("Starting...");
AsyncTaskWorker taskWorker = new AsyncTaskWorker("StartUp"); AsyncTaskWorker taskWorker = new AsyncTaskWorker("StartUp");
@ -109,9 +106,9 @@ public final class Minosoft {
e.printStackTrace(); e.printStackTrace();
return; 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 // 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())); Log.info(String.format("Logging info with level: %s", Log.getLevel()));
serverList = config.getServers(); serverList = config.getServers();
@ -124,7 +121,7 @@ public final class Minosoft {
taskWorker.addTask(new Task(progress -> { taskWorker.addTask(new Task(progress -> {
progress.countUp(); progress.countUp();
LocaleManager.load(config.getString(ConfigurationPaths.GENERAL_LANGUAGE)); LocaleManager.load(config.getString(ConfigurationPaths.StringPaths.GENERAL_LANGUAGE));
progress.countDown(); progress.countDown();
}, "Minosoft Language", "Load minosoft language files", Priorities.HIGH, TaskImportance.REQUIRED, "Configuration")); }, "Minosoft Language", "Load minosoft language files", Priorities.HIGH, TaskImportance.REQUIRED, "Configuration"));
@ -141,7 +138,7 @@ public final class Minosoft {
Log.debug("Refreshing account token..."); Log.debug("Refreshing account token...");
checkClientToken(); checkClientToken();
accountList = config.getMojangAccounts(); 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")); }, "Token refresh", "Refresh selected account token", Priorities.LOW, TaskImportance.OPTIONAL, "Configuration"));
taskWorker.addTask(new Task(progress -> { taskWorker.addTask(new Task(progress -> {
@ -158,7 +155,7 @@ public final class Minosoft {
taskWorker.addTask(new Task(progress -> { taskWorker.addTask(new Task(progress -> {
progress.countUp(); progress.countUp();
MinecraftLocaleManager.load(config.getString(ConfigurationPaths.GENERAL_LANGUAGE)); MinecraftLocaleManager.load(config.getString(ConfigurationPaths.StringPaths.GENERAL_LANGUAGE));
progress.countDown(); progress.countDown();
}, "Mojang language", "Load minecraft language files", Priorities.HIGH, TaskImportance.REQUIRED, "Assets")); }, "Mojang language", "Load minecraft language files", Priorities.HIGH, TaskImportance.REQUIRED, "Assets"));
@ -179,8 +176,8 @@ public final class Minosoft {
} }
public static void checkClientToken() { public static void checkClientToken() {
if (config.getString(ConfigurationPaths.CLIENT_TOKEN).isBlank()) { if (config.getString(ConfigurationPaths.StringPaths.CLIENT_TOKEN).isBlank()) {
config.putString(ConfigurationPaths.CLIENT_TOKEN, UUID.randomUUID().toString()); config.putString(ConfigurationPaths.StringPaths.CLIENT_TOKEN, UUID.randomUUID().toString());
config.saveToFile(); config.saveToFile();
} }
} }
@ -188,7 +185,7 @@ public final class Minosoft {
public static void selectAccount(MojangAccount account) { public static void selectAccount(MojangAccount account) {
if (account == null) { if (account == null) {
selectedAccount = null; selectedAccount = null;
config.putString(ConfigurationPaths.ACCOUNT_SELECTED, ""); config.putString(ConfigurationPaths.StringPaths.ACCOUNT_SELECTED, "");
config.saveToFile(); config.saveToFile();
return; return;
} }
@ -200,7 +197,7 @@ public final class Minosoft {
selectedAccount = null; selectedAccount = null;
return; return;
} }
config.putString(ConfigurationPaths.ACCOUNT_SELECTED, account.getUserId()); config.putString(ConfigurationPaths.StringPaths.ACCOUNT_SELECTED, account.getUserId());
selectedAccount = account; selectedAccount = account;
MainWindow.selectAccount(); MainWindow.selectAccount();
account.saveToConfig(); account.saveToConfig();

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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);
}
}

View File

@ -32,7 +32,7 @@ public class Configuration {
final JsonObject config; final JsonObject config;
private final Object lock = new Object(); 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); File file = new File(StaticConfiguration.HOME_DIR + "config/" + StaticConfiguration.CONFIG_FILENAME);
if (!file.exists()) { if (!file.exists()) {
// no configuration file // no configuration file
@ -48,9 +48,9 @@ public class Configuration {
file = new File(StaticConfiguration.HOME_DIR + "config/" + StaticConfiguration.CONFIG_FILENAME); file = new File(StaticConfiguration.HOME_DIR + "config/" + StaticConfiguration.CONFIG_FILENAME);
} }
config = Util.readJsonFromFile(file.getAbsolutePath()); config = Util.readJsonFromFile(file.getAbsolutePath());
int configVersion = getInt(ConfigurationPaths.CONFIG_VERSION); int configVersion = getInt(ConfigurationPaths.IntegerPaths.GENERAL_CONFIG_VERSION);
if (configVersion > LATEST_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) { if (configVersion < LATEST_CONFIG_VERSION) {
migrateConfiguration(); migrateConfiguration();
@ -96,57 +96,51 @@ public class Configuration {
}, "IO").start(); }, "IO").start();
} }
public boolean getBoolean(ConfigurationPaths path) { public boolean getBoolean(ConfigurationPaths.BooleanPaths path) {
return switch (path) { return switch (path) {
case NETWORK_FAKE_CLIENT_BRAND -> config.getAsJsonObject("network").get("fake-network-brand").getAsBoolean(); case NETWORK_FAKE_CLIENT_BRAND -> config.getAsJsonObject("network").get("fake-network-brand").getAsBoolean();
case DEBUG_VERIFY_ASSETS -> config.getAsJsonObject("debug").get("verify-assets").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) { switch (path) {
case NETWORK_FAKE_CLIENT_BRAND -> config.getAsJsonObject("network").addProperty("fake-network-brand", value); case NETWORK_FAKE_CLIENT_BRAND -> config.getAsJsonObject("network").addProperty("fake-network-brand", value);
case DEBUG_VERIFY_ASSETS -> config.getAsJsonObject("debug").addProperty("verify-assets", 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) { 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(); 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) { 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); 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) { return switch (path) {
case ACCOUNT_SELECTED -> config.getAsJsonObject("accounts").get("selected").getAsString(); case ACCOUNT_SELECTED -> config.getAsJsonObject("accounts").get("selected").getAsString();
case GENERAL_LOG_LEVEL -> config.getAsJsonObject("general").get("log-level").getAsString(); case GENERAL_LOG_LEVEL -> config.getAsJsonObject("general").get("log-level").getAsString();
case GENERAL_LANGUAGE -> config.getAsJsonObject("general").get("language").getAsString(); case GENERAL_LANGUAGE -> config.getAsJsonObject("general").get("language").getAsString();
case MAPPINGS_URL -> config.getAsJsonObject("download").getAsJsonObject("urls").get("mappings").getAsString(); case MAPPINGS_URL -> config.getAsJsonObject("download").getAsJsonObject("urls").get("mappings").getAsString();
case CLIENT_TOKEN -> config.getAsJsonObject("accounts").get("client-token").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) { switch (path) {
case ACCOUNT_SELECTED -> config.getAsJsonObject("accounts").addProperty("selected", value); case ACCOUNT_SELECTED -> config.getAsJsonObject("accounts").addProperty("selected", value);
case GENERAL_LOG_LEVEL -> config.getAsJsonObject("general").addProperty("log-level", value); case GENERAL_LOG_LEVEL -> config.getAsJsonObject("general").addProperty("log-level", value);
case GENERAL_LANGUAGE -> config.getAsJsonObject("general").addProperty("language", value); case GENERAL_LANGUAGE -> config.getAsJsonObject("general").addProperty("language", value);
case MAPPINGS_URL -> config.getAsJsonObject("download").getAsJsonObject("urls").addProperty("mappings", value); case MAPPINGS_URL -> config.getAsJsonObject("download").getAsJsonObject("urls").addProperty("mappings", value);
case CLIENT_TOKEN -> config.getAsJsonObject("accounts").addProperty("client-token", 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() { 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)); 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++) { for (int nextVersion = configVersion + 1; nextVersion <= LATEST_CONFIG_VERSION; nextVersion++) {
migrateConfiguration(nextVersion); migrateConfiguration(nextVersion);
} }
putInt(ConfigurationPaths.CONFIG_VERSION, LATEST_CONFIG_VERSION); putInt(ConfigurationPaths.IntegerPaths.GENERAL_CONFIG_VERSION, LATEST_CONFIG_VERSION);
saveToFile(); saveToFile();
Log.info("Finished migrating config!"); Log.info("Finished migrating config!");

View File

@ -13,14 +13,21 @@
package de.bixilon.minosoft.config; package de.bixilon.minosoft.config;
public enum ConfigurationPaths { public abstract class ConfigurationPaths {
CONFIG_VERSION, public enum StringPaths {
GAME_RENDER_DISTANCE, GENERAL_LOG_LEVEL,
NETWORK_FAKE_CLIENT_BRAND, CLIENT_TOKEN,
GENERAL_LOG_LEVEL, MAPPINGS_URL,
CLIENT_TOKEN, ACCOUNT_SELECTED,
MAPPINGS_URL, GENERAL_LANGUAGE,
ACCOUNT_SELECTED, }
GENERAL_LANGUAGE,
DEBUG_VERIFY_ASSETS, public enum BooleanPaths {
NETWORK_FAKE_CLIENT_BRAND, DEBUG_VERIFY_ASSETS
}
public enum IntegerPaths {
GENERAL_CONFIG_VERSION,
GAME_RENDER_DISTANCE
}
} }

View File

@ -160,7 +160,7 @@ public class AssetsManager {
if (getAssetSize(hash) == -1) { if (getAssetSize(hash) == -1) {
return false; return false;
} }
if (!Minosoft.config.getBoolean(ConfigurationPaths.DEBUG_VERIFY_ASSETS)) { if (!Minosoft.config.getBoolean(ConfigurationPaths.BooleanPaths.DEBUG_VERIFY_ASSETS)) {
return true; return true;
} }
try { try {

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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);
}
}

View File

@ -145,7 +145,7 @@ public class Versions {
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
long downloadStartTime = System.currentTimeMillis(); long downloadStartTime = System.currentTimeMillis();
Log.info(String.format("Mappings for %s are not available on disk. Downloading them...", version.getVersionName())); 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 { try {
files = Util.readJsonTarGzFile(fileName); files = Util.readJsonTarGzFile(fileName);
} catch (ZipException e2) { } catch (ZipException e2) {

View File

@ -187,10 +187,9 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
version.setStyle("-fx-text-fill: red;"); version.setStyle("-fx-text-fill: red;");
optionsConnect.setDisable(true); optionsConnect.setDisable(true);
canConnect = false; canConnect = false;
setErrorMotd(String.format("%s", server.getLastPing().getLastConnectionException().getLocalizedMessage())); setErrorMotd(String.format("%s: %s", server.getLastPing().getLastConnectionException().getClass().getCanonicalName(), server.getLastPing().getLastConnectionException().getLocalizedMessage()));
} }
})); }));
} }
@Override @Override

View File

@ -45,7 +45,7 @@ public class SettingsWindow implements Initializable {
return; return;
} }
Log.setLevel(newLevel); 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(); Minosoft.getConfig().saveToFile();
})); }));

View File

@ -24,10 +24,10 @@ import java.util.concurrent.LinkedBlockingQueue;
public class Log { public class Log {
final static SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); final static SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
final static LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>(); final static LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>();
final static long startTime = System.currentTimeMillis(); public final static long MINOSOFT_START_TIME = System.currentTimeMillis();
static LogLevels level = LogLevels.PROTOCOL; static LogLevels level = LogLevels.PROTOCOL;
public static void initThread() { static {
new Thread(() -> { new Thread(() -> {
while (true) { while (true) {
// something to print // something to print
@ -69,7 +69,7 @@ public class Log {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("["); builder.append("[");
if (StaticConfiguration.LOG_RELATIVE_TIME) { if (StaticConfiguration.LOG_RELATIVE_TIME) {
builder.append(System.currentTimeMillis() - startTime); builder.append(System.currentTimeMillis() - MINOSOFT_START_TIME);
} else { } else {
builder.append(timeFormat.format(System.currentTimeMillis())); builder.append(timeFormat.format(System.currentTimeMillis()));
} }

View File

@ -17,6 +17,7 @@ import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.data.Player; import de.bixilon.minosoft.data.Player;
import de.bixilon.minosoft.data.VelocityHandler; import de.bixilon.minosoft.data.VelocityHandler;
import de.bixilon.minosoft.data.mappings.CustomMapping; 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.recipes.Recipes;
import de.bixilon.minosoft.data.mappings.versions.Version; import de.bixilon.minosoft.data.mappings.versions.Version;
import de.bixilon.minosoft.data.mappings.versions.Versions; import de.bixilon.minosoft.data.mappings.versions.Versions;
@ -163,7 +164,7 @@ public class Connection {
} catch (IOException e) { } catch (IOException e) {
Log.printException(e, LogLevels.DEBUG); Log.printException(e, LogLevels.DEBUG);
Log.fatal(String.format("Could not load mapping for %s. This version seems to be unsupported!", version)); 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); setConnectionState(ConnectionStates.FAILED_NO_RETRY);
} }
} }

View File

@ -192,24 +192,20 @@ public class SocketNetwork implements Network {
try { try {
packet = connection.getPacketByCommand(connection.getConnectionState(), inPacketBuffer.getCommand()); packet = connection.getPacketByCommand(connection.getConnectionState(), inPacketBuffer.getCommand());
if (packet == null) { 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(); 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; throw lastException;
} }
Class<? extends ClientboundPacket> clazz = packet.getClazz(); Class<? extends ClientboundPacket> clazz = packet.getClazz();
if (clazz == null) { 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())); 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()));
continue;
} }
try { try {
ClientboundPacket packetInstance = clazz.getConstructor().newInstance(); ClientboundPacket packetInstance = clazz.getConstructor().newInstance();
boolean success = packetInstance.read(inPacketBuffer); boolean success = packetInstance.read(inPacketBuffer);
if (inPacketBuffer.getBytesLeft() > 0 || !success) { if (inPacketBuffer.getBytesLeft() > 0 || !success) {
// warn not all data used 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));
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;
} }
//set special settings to avoid miss timing issues //set special settings to avoid miss timing issues

View File

@ -201,7 +201,7 @@ public class PacketHandler {
if (pkg.getChannel().equals(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(connection.getVersion().getVersionId()))) { if (pkg.getChannel().equals(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(connection.getVersion().getVersionId()))) {
InByteBuffer data = pkg.getDataAsBuffer(); InByteBuffer data = pkg.getDataAsBuffer();
String serverVersion; 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); OutByteBuffer toSend = new OutByteBuffer(connection);
if (connection.getVersion().getVersionId() < 29) { if (connection.getVersion().getVersionId() < 29) {
// no length prefix // no length prefix

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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);
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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);
}
}

View File

@ -26,7 +26,7 @@ import java.net.http.HttpResponse;
public final class MojangAuthentication { public final class MojangAuthentication {
public static MojangAccountAuthenticationAttempt login(String username, String password) { 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) { public static MojangAccountAuthenticationAttempt login(String clientToken, String username, String password) {
@ -81,7 +81,7 @@ public final class MojangAuthentication {
} }
public static String refresh(String accessToken) { 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) { public static String refresh(String clientToken, String accessToken) {