Token verification for separated bungee and server

This commit is contained in:
ayunami2000 2022-07-31 15:14:17 -04:00
parent f09b903b7d
commit ba8a32a85b
4 changed files with 26 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
@ -131,6 +132,7 @@ public class BungeeCord extends ProxyServer {
private final Logger logger;
private Collection<Command> banCommands;
public AuthSystem authSystem;
public String tokenVerify;
public static BungeeCord getInstance() {
return (BungeeCord) ProxyServer.getInstance();
@ -244,6 +246,7 @@ public class BungeeCord extends ProxyServer {
this.authSystem = new AuthSystem(this.config.getAuthInfo());
this.getPluginManager().registerCommand(null, new CommandChangePassword(this.authSystem));
}
this.tokenVerify = Optional.ofNullable(System.getenv("YEEISH_TOKEN")).orElse(this.config.getTokenVerify());
if (this.reconnectHandler == null) {
this.reconnectHandler = new SQLReconnectHandler();
}

View File

@ -28,6 +28,7 @@ public class Configuration {
private boolean onlineMode;
private boolean voiceEnabled;
private boolean protocolSupport;
private String tokenVerify;
private int playerLimit;
private String name;
private boolean showBanType;
@ -63,6 +64,7 @@ public class Configuration {
this.onlineMode = false;
this.voiceEnabled = adapter.getBoolean("voice_enabled", true);
this.protocolSupport = adapter.getBoolean("protocol_support_fix", false);
this.tokenVerify = adapter.getString("token_verify", "");
this.playerLimit = adapter.getInt("player_limit", this.playerLimit);
this.name = adapter.getString("server_name", EaglercraftBungee.name + " Server");
this.showBanType = adapter.getBoolean("display_ban_type_on_kick", false);
@ -129,6 +131,10 @@ public class Configuration {
return protocolSupport;
}
public String getTokenVerify() {
return tokenVerify;
}
public String getServerName() {
return name;
}

View File

@ -128,6 +128,15 @@ public class InitialHandler extends PacketHandler implements PendingConnection {
this.disconnect("Go fuck yourself");
return;
}
if (BungeeCord.getInstance().tokenVerify.isEmpty()) {
String hostname = handshake.getHost();
if (hostname.contains(":")) {
handshake.setHost(hostname.substring(0, hostname.indexOf(':')));
}
} else {
handshake.setHost(BungeeCord.getInstance().tokenVerify);
handshake.setPort(0);
}
InetAddress sc;
synchronized(WebSocketProxy.localToRemote) {
sc = WebSocketProxy.localToRemote.get(this.ch.getHandle().remoteAddress());

View File

@ -45,6 +45,14 @@ public class Packet2Handshake extends DefinedPacket {
this.procolVersion = (byte)b;
}
public void setHost(String h) {
this.host = h;
}
public void setPort(int p) {
this.port = p;
}
public String getUsername() {
return this.username;
}