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