More custom exceptions

This commit is contained in:
Bixilon 2020-11-03 20:07:19 +01:00
parent ae685e9068
commit e24b657c3f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 113 additions and 11 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

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

@ -187,7 +187,7 @@ 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()));
} }
})); }));
} }

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;
@ -160,7 +161,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

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