mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
fix some reconnecting bugs, todo for position (1 coordinate buggy)
This commit is contained in:
parent
ff679a36d1
commit
6a4e83bc28
@ -48,6 +48,7 @@ public class Minosoft {
|
||||
Log.info(String.format("Loaded config file (version=%s)", config.getInteger(GameConfiguration.CONFIG_VERSION)));
|
||||
// set log level from config
|
||||
Log.setLevel(LogLevel.byName(config.getString(GameConfiguration.GENERAL_LOG_LEVEL)));
|
||||
Log.info(String.format("Logging info with level: %s", Log.getLevel().name()));
|
||||
|
||||
checkClientToken();
|
||||
|
||||
|
@ -35,8 +35,8 @@ public class Connection {
|
||||
private final int port;
|
||||
private final Network network;
|
||||
private final PacketHandler handler;
|
||||
private final PluginChannelHandler pluginChannelHandler;
|
||||
private final ArrayList<ClientboundPacket> handlingQueue;
|
||||
private PluginChannelHandler pluginChannelHandler;
|
||||
Thread handleThread;
|
||||
ProtocolVersion version = ProtocolVersion.VERSION_1_7_10; // default
|
||||
private Player player;
|
||||
@ -49,14 +49,13 @@ public class Connection {
|
||||
network = new Network(this);
|
||||
handlingQueue = new ArrayList<>();
|
||||
handler = new PacketHandler(this);
|
||||
pluginChannelHandler = new PluginChannelHandler(this);
|
||||
registerDefaultChannels();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an server ping to the server (player count, motd, ...)
|
||||
*/
|
||||
public void ping() {
|
||||
Log.info(String.format("Pinging server: %s:%d", host, port));
|
||||
reason = ConnectionReason.PING;
|
||||
network.connect();
|
||||
}
|
||||
@ -65,6 +64,7 @@ public class Connection {
|
||||
* Tries to connect to the server and login
|
||||
*/
|
||||
public void connect() {
|
||||
Log.info(String.format("Connecting to server: %s:%d", host, port));
|
||||
if (reason == null) {
|
||||
// first get version, then login
|
||||
reason = ConnectionReason.GET_VERSION;
|
||||
@ -97,7 +97,7 @@ public class Connection {
|
||||
network.startPacketThread();
|
||||
startHandlingThread();
|
||||
ConnectionState next = ((reason == ConnectionReason.CONNECT) ? ConnectionState.LOGIN : ConnectionState.STATUS);
|
||||
network.sendPacket(new PacketHandshake(getHost(), getPort(), next, next == ConnectionState.STATUS ? -1 : getVersion().getVersion()));
|
||||
network.sendPacket(new PacketHandshake(getHost(), getPort(), next, (next == ConnectionState.STATUS) ? -1 : getVersion().getVersion()));
|
||||
// after sending it, switch to next state
|
||||
setConnectionState(next);
|
||||
break;
|
||||
@ -108,7 +108,14 @@ public class Connection {
|
||||
break;
|
||||
case LOGIN:
|
||||
network.sendPacket(new PacketLoginStart(player));
|
||||
pluginChannelHandler = new PluginChannelHandler(this);
|
||||
registerDefaultChannels();
|
||||
break;
|
||||
case DISCONNECTED:
|
||||
if (reason == ConnectionReason.GET_VERSION) {
|
||||
setReason(ConnectionReason.CONNECT);
|
||||
connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ public class Network {
|
||||
private Cipher cipherEncrypt;
|
||||
private Cipher cipherDecrypt;
|
||||
private Thread packetThread;
|
||||
Thread socketThread;
|
||||
private boolean connected;
|
||||
|
||||
public Network(Connection c) {
|
||||
@ -60,7 +61,7 @@ public class Network {
|
||||
// everything sent for now, waiting for data
|
||||
// add to queue
|
||||
// Could not connect
|
||||
Thread socketThread = new Thread(() -> {
|
||||
socketThread = new Thread(() -> {
|
||||
try {
|
||||
socket = new Socket(connection.getHost(), connection.getPort());
|
||||
connected = true;
|
||||
|
@ -176,8 +176,21 @@ public class InByteBuffer {
|
||||
}
|
||||
|
||||
public BlockPosition readPosition() {
|
||||
//ToDo: here is something wrong with z :(
|
||||
Long raw = readLong();
|
||||
return new BlockPosition(Long.valueOf(raw >>> 38).intValue(), Long.valueOf(raw & 0xFFF).shortValue(), Long.valueOf(raw << 26 >>> 38).intValue());
|
||||
int x = (int) (raw >> 38);
|
||||
short y = (short) (raw & 0xFFF);
|
||||
int z = (int) (raw >> 12) & 0x3FFFFFF;
|
||||
if (x >= (2 ^ 25)) {
|
||||
x -= 2 ^ 26;
|
||||
}
|
||||
if (y >= (2 ^ 11)) {
|
||||
y -= 2 ^ 12;
|
||||
}
|
||||
if (z >= (2 ^ 25)) {
|
||||
z -= 2 ^ 26;
|
||||
}
|
||||
return new BlockPosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,8 +67,6 @@ public class PacketHandler {
|
||||
// reconnect...
|
||||
connection.disconnect();
|
||||
Log.info(String.format("Server is running on version %s, reconnecting...", connection.getVersion().getName()));
|
||||
connection.setReason(ConnectionReason.CONNECT);
|
||||
connection.connect();
|
||||
break;
|
||||
case CONNECT:
|
||||
// do nothing
|
||||
|
Loading…
x
Reference in New Issue
Block a user