Everything seems to work except switching bridges.
This commit is contained in:
parent
093f45463a
commit
68e1445b1e
@ -172,24 +172,21 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetSocketAddress getHostFor(String user, String requestedHost) {
|
public String getServerFor(String user, String requestedHost) {
|
||||||
String entry = user + ";" + requestedHost;
|
String server;
|
||||||
|
|
||||||
String hostLine;
|
|
||||||
if (forcedServers.containsKey(requestedHost)) {
|
if (forcedServers.containsKey(requestedHost)) {
|
||||||
hostLine = servers.get(forcedServers.get(requestedHost));
|
server = servers.get(forcedServers.get(requestedHost));
|
||||||
} else {
|
} else {
|
||||||
hostLine = reconnectLocations.get(entry);
|
server = reconnectLocations.get(user);
|
||||||
}
|
}
|
||||||
if (hostLine == null) {
|
if (server == null) {
|
||||||
hostLine = servers.get(defaultServerName);
|
server = servers.get(defaultServerName);
|
||||||
}
|
}
|
||||||
return Util.getAddr(hostLine);
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHostFor(UserConnection user, String host) {
|
public void setHostFor(UserConnection user, String server) {
|
||||||
String entry = user.username + ";" + Util.getAddr(user.handshake.host);
|
reconnectLocations.put(user.username, server);
|
||||||
reconnectLocations.put(entry, host);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InetSocketAddress getServer(String name) {
|
public InetSocketAddress getServer(String name) {
|
||||||
@ -198,7 +195,7 @@ public class Configuration {
|
|||||||
if (server != null) {
|
if (server != null) {
|
||||||
return Util.getAddr(server);
|
return Util.getAddr(server);
|
||||||
} else {
|
} else {
|
||||||
return Util.getAddr(servers.get(defaultServerName));
|
return getServer(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,9 @@ public class EncryptionUtil {
|
|||||||
return new PacketFDEncryptionRequest(hash, pubKey, verify);
|
return new PacketFDEncryptionRequest(hash, pubKey, verify);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SecretKey getSecret(PacketFCEncryptionResponse resp, PacketFDEncryptionRequest request) throws Exception {
|
public static SecretKey getSecret(PacketFCEncryptionResponse resp, PacketFDEncryptionRequest request) throws BadPaddingException, IllegalBlockSizeException,
|
||||||
|
IllegalStateException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
|
||||||
|
|
||||||
Cipher cipher = Cipher.getInstance("RSA");
|
Cipher cipher = Cipher.getInstance("RSA");
|
||||||
cipher.init(Cipher.DECRYPT_MODE, keys.getPrivate());
|
cipher.init(Cipher.DECRYPT_MODE, keys.getPrivate());
|
||||||
byte[] decrypted = cipher.doFinal(resp.verifyToken);
|
byte[] decrypted = cipher.doFinal(resp.verifyToken);
|
||||||
@ -113,7 +115,7 @@ public class EncryptionUtil {
|
|||||||
return hasher.doFinal(b);
|
return hasher.doFinal(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] getShared(SecretKey key, PublicKey pubkey) throws BadPaddingException, IllegalBlockSizeException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
|
public static byte[] getShared(SecretKey key, PublicKey pubkey) throws BadPaddingException, IllegalBlockSizeException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
|
||||||
Cipher cipher = Cipher.getInstance("RSA");
|
Cipher cipher = Cipher.getInstance("RSA");
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, pubkey);
|
cipher.init(Cipher.ENCRYPT_MODE, pubkey);
|
||||||
return cipher.doFinal(key.getEncoded());
|
return cipher.doFinal(key.getEncoded());
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.md_5.bungee;
|
package net.md_5.bungee;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@ -53,7 +52,7 @@ public class InitialHandler implements Runnable {
|
|||||||
|
|
||||||
UserConnection userCon = new UserConnection(socket, in, out, handshake);
|
UserConnection userCon = new UserConnection(socket, in, out, handshake);
|
||||||
userCon.register();
|
userCon.register();
|
||||||
userCon.connect(BungeeCord.instance.config.getHostFor(handshake.username, handshake.host));
|
userCon.connect(BungeeCord.instance.config.getServerFor(handshake.username, handshake.host));
|
||||||
break;
|
break;
|
||||||
case 0xFE:
|
case 0xFE:
|
||||||
throw new KickException(BungeeCord.instance.config.motd + ChatColor.COLOR_CHAR + BungeeCord.instance.connections.size() + ChatColor.COLOR_CHAR + BungeeCord.instance.config.maxPlayers);
|
throw new KickException(BungeeCord.instance.config.motd + ChatColor.COLOR_CHAR + BungeeCord.instance.connections.size() + ChatColor.COLOR_CHAR + BungeeCord.instance.config.maxPlayers);
|
||||||
|
@ -17,14 +17,16 @@ import org.bouncycastle.crypto.io.CipherOutputStream;
|
|||||||
|
|
||||||
public class ServerConnection extends GenericConnection {
|
public class ServerConnection extends GenericConnection {
|
||||||
|
|
||||||
|
public final String name;
|
||||||
public final Packet1Login loginPacket;
|
public final Packet1Login loginPacket;
|
||||||
|
|
||||||
public ServerConnection(Socket socket, PacketInputStream in, OutputStream out, Packet1Login loginPacket) {
|
public ServerConnection(String name, Socket socket, PacketInputStream in, OutputStream out, Packet1Login loginPacket) {
|
||||||
super(socket, in, out);
|
super(socket, in, out);
|
||||||
|
this.name = name;
|
||||||
this.loginPacket = loginPacket;
|
this.loginPacket = loginPacket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerConnection connect(InetSocketAddress address, Packet2Handshake handshake, boolean retry) {
|
public static ServerConnection connect(String name, InetSocketAddress address, Packet2Handshake handshake, boolean retry) {
|
||||||
try {
|
try {
|
||||||
Socket socket = new Socket();
|
Socket socket = new Socket();
|
||||||
socket.connect(address, BungeeCord.instance.config.timeout);
|
socket.connect(address, BungeeCord.instance.config.timeout);
|
||||||
@ -57,13 +59,13 @@ public class ServerConnection extends GenericConnection {
|
|||||||
}
|
}
|
||||||
Packet1Login login = new Packet1Login(loginResponse);
|
Packet1Login login = new Packet1Login(loginResponse);
|
||||||
|
|
||||||
return new ServerConnection(socket, in, out, login);
|
return new ServerConnection(name, socket, in, out, login);
|
||||||
} catch (KickException ex) {
|
} catch (KickException ex) {
|
||||||
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 != def) {
|
||||||
return connect(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");
|
||||||
}
|
}
|
||||||
|
@ -37,19 +37,16 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
|
|
||||||
public void connect(String server) {
|
public void connect(String server) {
|
||||||
InetSocketAddress addr = BungeeCord.instance.config.getServer(server);
|
InetSocketAddress addr = BungeeCord.instance.config.getServer(server);
|
||||||
if (addr == null) {
|
if (addr.equals(curServer())) {
|
||||||
sendMessage(ChatColor.RED + "Specified server does not exist");
|
sendMessage(ChatColor.RED + "You are already on this server");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
connect(addr);
|
connect(server, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect(InetSocketAddress serverAddr) {
|
private void connect(String name, InetSocketAddress serverAddr) {
|
||||||
try {
|
try {
|
||||||
ServerConnection newServer = ServerConnection.connect(serverAddr, handshake, true);
|
ServerConnection newServer = ServerConnection.connect(name, serverAddr, handshake, server == null);
|
||||||
if (downBridge != null) {
|
|
||||||
downBridge.interrupt();
|
|
||||||
}
|
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
clientEntityId = newServer.loginPacket.entityId;
|
clientEntityId = newServer.loginPacket.entityId;
|
||||||
out.write(newServer.loginPacket.getPacket());
|
out.write(newServer.loginPacket.getPacket());
|
||||||
@ -59,10 +56,10 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
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());
|
||||||
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());
|
||||||
out.write(new Packet46GameState((byte) 2, (byte) 0).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());
|
||||||
|
out.write(new Packet46GameState((byte) 2, (byte) 0).getPacket());
|
||||||
if (heldItem != null) {
|
if (heldItem != null) {
|
||||||
newServer.out.write(heldItem.getPacket());
|
newServer.out.write(heldItem.getPacket());
|
||||||
}
|
}
|
||||||
@ -85,20 +82,21 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
BungeeCord.instance.connections.put(username, this);
|
BungeeCord.instance.connections.put(username, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private InetSocketAddress curServer() {
|
||||||
|
return (server == null) ? null : new InetSocketAddress(server.socket.getInetAddress(), server.socket.getPort());
|
||||||
|
}
|
||||||
|
|
||||||
private void destory(String reason) {
|
private void destory(String reason) {
|
||||||
if (BungeeCord.instance.isRunning) {
|
if (BungeeCord.instance.isRunning) {
|
||||||
BungeeCord.instance.connections.remove(username);
|
BungeeCord.instance.connections.remove(username);
|
||||||
}
|
}
|
||||||
if (upBridge != null) {
|
|
||||||
upBridge.interrupt();
|
|
||||||
}
|
|
||||||
if (downBridge != null) {
|
|
||||||
downBridge.interrupt();
|
|
||||||
}
|
|
||||||
disconnect(reason);
|
disconnect(reason);
|
||||||
if (server != null) {
|
if (server != null) {
|
||||||
server.disconnect("Quitting");
|
server.disconnect("Quitting");
|
||||||
}
|
}
|
||||||
|
if (server != null) {
|
||||||
|
BungeeCord.instance.config.setHostFor(this, server.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -114,7 +112,7 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (!interrupted()) {
|
while (!socket.isClosed()) {
|
||||||
try {
|
try {
|
||||||
byte[] packet = in.readPacket();
|
byte[] packet = in.readPacket();
|
||||||
boolean sendPacket = true;
|
boolean sendPacket = true;
|
||||||
@ -151,7 +149,7 @@ public class UserConnection extends GenericConnection implements CommandSender {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (!interrupted()) {
|
while (!server.socket.isClosed()) {
|
||||||
try {
|
try {
|
||||||
byte[] packet = server.in.readPacket();
|
byte[] packet = server.in.readPacket();
|
||||||
boolean sendPacket = true;
|
boolean sendPacket = true;
|
||||||
|
@ -13,8 +13,8 @@ public class CommandServer extends Command {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UserConnection con = (UserConnection) sender;
|
UserConnection con = (UserConnection) sender;
|
||||||
|
Collection<String> servers = BungeeCord.instance.config.servers.keySet();
|
||||||
if (args.length <= 0) {
|
if (args.length <= 0) {
|
||||||
Collection<String> servers = BungeeCord.instance.config.servers.keySet();
|
|
||||||
StringBuilder serverList = new StringBuilder();
|
StringBuilder serverList = new StringBuilder();
|
||||||
for (String server : servers) {
|
for (String server : servers) {
|
||||||
serverList.append(server);
|
serverList.append(server);
|
||||||
@ -24,7 +24,11 @@ public class CommandServer extends Command {
|
|||||||
con.sendMessage(ChatColor.GOLD + "You may connect to the following servers at this time: " + serverList.toString());
|
con.sendMessage(ChatColor.GOLD + "You may connect to the following servers at this time: " + serverList.toString());
|
||||||
} else {
|
} else {
|
||||||
String server = args[0];
|
String server = args[0];
|
||||||
con.connect(server);
|
if (!servers.contains(server)) {
|
||||||
|
con.sendMessage(ChatColor.RED + "The specified server does not exist");
|
||||||
|
} else {
|
||||||
|
con.connect(server);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,6 @@ public class PacketCDClientStatus extends DefinedPacket {
|
|||||||
*/
|
*/
|
||||||
public PacketCDClientStatus(byte payload) {
|
public PacketCDClientStatus(byte payload) {
|
||||||
super(0xCD);
|
super(0xCD);
|
||||||
super.writeByte(payload);
|
writeByte(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user