mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 00:47:26 -04:00
More custom exceptions
This commit is contained in:
parent
ae685e9068
commit
e24b657c3f
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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()));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user