mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 20:59:12 +01:00
Retry this mess of connections again.
This commit is contained in:
parent
aa2710c573
commit
a51ce916ce
@ -69,7 +69,7 @@ public class ServerConnection extends GenericConnection {
|
|||||||
throw ex;
|
throw ex;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
InetSocketAddress def = BungeeCord.instance.config.getServer(null);
|
InetSocketAddress def = BungeeCord.instance.config.getServer(null);
|
||||||
if (retry && address != def) {
|
if (retry && !address.equals(def)) {
|
||||||
return connect(name, def, handshake, false);
|
return connect(name, def, handshake, false);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Could not connect to target server");
|
throw new RuntimeException("Could not connect to target server");
|
||||||
|
@ -28,6 +28,7 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
private Packet10HeldItem heldItem;
|
private Packet10HeldItem heldItem;
|
||||||
private int clientEntityId;
|
private int clientEntityId;
|
||||||
private int serverEntityId;
|
private int serverEntityId;
|
||||||
|
private volatile boolean reconnecting;
|
||||||
|
|
||||||
public UserConnection(Socket socket, PacketInputStream in, OutputStream out, Packet2Handshake handshake) {
|
public UserConnection(Socket socket, PacketInputStream in, OutputStream out, Packet2Handshake handshake) {
|
||||||
super(socket, in, out);
|
super(socket, in, out);
|
||||||
@ -43,6 +44,13 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
|
|
||||||
private void connect(String name, InetSocketAddress serverAddr) {
|
private void connect(String name, InetSocketAddress serverAddr) {
|
||||||
try {
|
try {
|
||||||
|
reconnecting = true;
|
||||||
|
|
||||||
|
if (server != null) {
|
||||||
|
out.write(new Packet9Respawn((byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT").getPacket());
|
||||||
|
out.write(new Packet9Respawn((byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT").getPacket());
|
||||||
|
}
|
||||||
|
|
||||||
ServerConnection newServer = ServerConnection.connect(name, serverAddr, handshake, server == null);
|
ServerConnection newServer = ServerConnection.connect(name, serverAddr, handshake, server == null);
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
clientEntityId = newServer.loginPacket.entityId;
|
clientEntityId = newServer.loginPacket.entityId;
|
||||||
@ -50,14 +58,14 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
upBridge = new UpstreamBridge();
|
upBridge = new UpstreamBridge();
|
||||||
upBridge.start();
|
upBridge.start();
|
||||||
} else {
|
} else {
|
||||||
downBridge.alive = false;
|
|
||||||
try {
|
try {
|
||||||
|
downBridge.interrupt();
|
||||||
downBridge.join();
|
downBridge.join();
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
}
|
}
|
||||||
|
|
||||||
server.disconnect("Quitting");
|
server.disconnect("Quitting");
|
||||||
out.write(new Packet9Respawn((byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT").getPacket());
|
|
||||||
out.write(new Packet9Respawn((byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT").getPacket());
|
|
||||||
Packet1Login login = newServer.loginPacket;
|
Packet1Login login = newServer.loginPacket;
|
||||||
serverEntityId = login.entityId;
|
serverEntityId = login.entityId;
|
||||||
out.write(new Packet9Respawn(login.dimension, login.difficulty, login.gameMode, (short) 256, login.levelType).getPacket());
|
out.write(new Packet9Respawn(login.dimension, login.difficulty, login.gameMode, (short) 256, login.levelType).getPacket());
|
||||||
@ -66,17 +74,14 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
newServer.out.write(heldItem.getPacket());
|
newServer.out.write(heldItem.getPacket());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
reconnecting = false;
|
||||||
downBridge = new DownstreamBridge();
|
downBridge = new DownstreamBridge();
|
||||||
server = newServer;
|
server = newServer;
|
||||||
downBridge.start();
|
downBridge.start();
|
||||||
} catch (KickException ex) {
|
} catch (KickException ex) {
|
||||||
destory(ex.getMessage());
|
destory(ex.getMessage());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (server == null) {
|
|
||||||
destory("Could not connect to server");
|
destory("Could not connect to server");
|
||||||
} else {
|
|
||||||
packetQueue.add(new Packet3Chat(ChatColor.YELLOW + "The server you selected is not up at the moment."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,8 +140,6 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
|
|
||||||
private class DownstreamBridge extends Thread {
|
private class DownstreamBridge extends Thread {
|
||||||
|
|
||||||
private volatile boolean alive = true;
|
|
||||||
|
|
||||||
public DownstreamBridge() {
|
public DownstreamBridge() {
|
||||||
super("Downstream Bridge - " + username);
|
super("Downstream Bridge - " + username);
|
||||||
}
|
}
|
||||||
@ -144,7 +147,7 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
while (alive) {
|
while (!reconnecting) {
|
||||||
byte[] packet = server.in.readPacket();
|
byte[] packet = server.in.readPacket();
|
||||||
boolean sendPacket = true;
|
boolean sendPacket = true;
|
||||||
|
|
||||||
@ -154,7 +157,7 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
if (message.tag.equals("RubberBand")) {
|
if (message.tag.equals("RubberBand")) {
|
||||||
String server = new String(message.data);
|
String server = new String(message.data);
|
||||||
connect(server);
|
connect(server);
|
||||||
sendPacket = false;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import net.md_5.bungee.ChatColor;
|
|||||||
import net.md_5.bungee.UserConnection;
|
import net.md_5.bungee.UserConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command to list and switch a player between availible servers.
|
* Command to list and switch a player between available servers.
|
||||||
*/
|
*/
|
||||||
public class CommandServer extends Command {
|
public class CommandServer extends Command {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user