forked from git-mirrors/GeyserConnect
Add virtual host support
This commit is contained in:
parent
49461a6253
commit
ccfea684c4
4 changed files with 64 additions and 5 deletions
|
@ -65,6 +65,8 @@ public class GeyserConnectConfig {
|
||||||
@JsonProperty("custom-servers")
|
@JsonProperty("custom-servers")
|
||||||
private CustomServersSection customServers;
|
private CustomServersSection customServers;
|
||||||
|
|
||||||
|
private VirtualHostSection vhost;
|
||||||
|
|
||||||
public void checkRemoteIP() {
|
public void checkRemoteIP() {
|
||||||
if ("auto".equals(remoteAddress)) {
|
if ("auto".equals(remoteAddress)) {
|
||||||
remoteAddress = WebUtils.getBody("https://icanhazip.com/").trim();
|
remoteAddress = WebUtils.getBody("https://icanhazip.com/").trim();
|
||||||
|
@ -111,4 +113,12 @@ public class GeyserConnectConfig {
|
||||||
private String host;
|
private String host;
|
||||||
private int port;
|
private int port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static class VirtualHostSection {
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
@JsonProperty("base-domain")
|
||||||
|
private String baseDomain;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.geysermc.common.window.response.SimpleFormResponse;
|
||||||
import org.geysermc.connect.ui.FormID;
|
import org.geysermc.connect.ui.FormID;
|
||||||
import org.geysermc.connect.ui.UIHandler;
|
import org.geysermc.connect.ui.UIHandler;
|
||||||
import org.geysermc.connect.utils.Player;
|
import org.geysermc.connect.utils.Player;
|
||||||
|
import org.geysermc.connect.utils.Server;
|
||||||
import org.geysermc.connector.entity.attribute.AttributeType;
|
import org.geysermc.connector.entity.attribute.AttributeType;
|
||||||
import org.geysermc.connector.network.BedrockProtocol;
|
import org.geysermc.connector.network.BedrockProtocol;
|
||||||
import org.geysermc.connector.network.session.auth.BedrockClientData;
|
import org.geysermc.connector.network.session.auth.BedrockClientData;
|
||||||
|
@ -210,6 +211,44 @@ public class PacketHandler implements BedrockPacketHandler {
|
||||||
|
|
||||||
masterServer.getLogger().debug("Player initialized: " + player.getDisplayName());
|
masterServer.getLogger().debug("Player initialized: " + player.getDisplayName());
|
||||||
|
|
||||||
|
// Handle the virtual host if specified
|
||||||
|
GeyserConnectConfig.VirtualHostSection vhost = MasterServer.getInstance().getGeyserConnectConfig().getVhost();
|
||||||
|
if (vhost.isEnabled()) {
|
||||||
|
String domain = player.getClientData().getServerAddress().split(":")[0];
|
||||||
|
if (!domain.equals(vhost.getBaseDomain()) && domain.endsWith("." + vhost.getBaseDomain())) {
|
||||||
|
String address = "";
|
||||||
|
int port = 25565;
|
||||||
|
boolean online = true;
|
||||||
|
|
||||||
|
// Parse the address used
|
||||||
|
String[] domainParts = domain.replaceFirst("\\." + vhost.getBaseDomain() + "$", "").split("._");
|
||||||
|
for (int i = 0; i < domainParts.length; i++) {
|
||||||
|
String part = domainParts[i];
|
||||||
|
if (i == 0) {
|
||||||
|
address = part;
|
||||||
|
} else if (part.startsWith("p")) {
|
||||||
|
port = Integer.parseInt(part.substring(1));
|
||||||
|
} else if (part.startsWith("o")) {
|
||||||
|
online = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// They didn't specify an address so disconnect them
|
||||||
|
if (address.startsWith("_")) {
|
||||||
|
session.disconnect("disconnectionScreen.invalidIP");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log the virtual host usage
|
||||||
|
masterServer.getLogger().info(player.getDisplayName() + " is using virtualhost: " + address + ":" + port + (!online ? " (offline)" : ""));
|
||||||
|
|
||||||
|
// Send the player to the wanted server
|
||||||
|
player.sendToServer(new Server(address, port, online, false));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String message = "";
|
String message = "";
|
||||||
try {
|
try {
|
||||||
File messageFile = FileUtils.fileOrCopiedFromResource(new File(MasterServer.getInstance().getGeyserConnectConfig().getWelcomeFile()), "welcome.txt", (x) -> x);
|
File messageFile = FileUtils.fileOrCopiedFromResource(new File(MasterServer.getInstance().getGeyserConnectConfig().getWelcomeFile()), "welcome.txt", (x) -> x);
|
||||||
|
|
|
@ -241,7 +241,7 @@ public class UIHandler {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
player.getSession().disconnect("disconnectionScreen.disconnected");
|
player.getSession().disconnect("disconnectionScreen.disconnected");
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
player.getSession().disconnect("disconnectionScreen.disconnected");
|
player.getSession().disconnect("disconnectionScreen.disconnected");
|
||||||
|
|
|
@ -63,8 +63,7 @@ servers:
|
||||||
port: 19132
|
port: 19132
|
||||||
bedrock: true
|
bedrock: true
|
||||||
category: OFFICIAL
|
category: OFFICIAL
|
||||||
imageUrl: >-
|
imageUrl: 'https://pbs.twimg.com/profile_images/1275867042583896066/UMPF5nTM_400x400.jpg'
|
||||||
https://pbs.twimg.com/profile_images/1275867042583896066/UMPF5nTM_400x400.jpg
|
|
||||||
|
|
||||||
- name: Lifeboat Network
|
- name: Lifeboat Network
|
||||||
address: 63.143.54.198
|
address: 63.143.54.198
|
||||||
|
@ -85,8 +84,7 @@ servers:
|
||||||
port: 19132
|
port: 19132
|
||||||
bedrock: true
|
bedrock: true
|
||||||
category: OFFICIAL
|
category: OFFICIAL
|
||||||
imageUrl: >-
|
imageUrl: 'https://pbs.twimg.com/profile_images/1332400307050045441/MHQvGEUP_400x400.jpg'
|
||||||
https://pbs.twimg.com/profile_images/1332400307050045441/MHQvGEUP_400x400.jpg
|
|
||||||
|
|
||||||
- name: Official Geyser Test Server
|
- name: Official Geyser Test Server
|
||||||
address: test.geysermc.org
|
address: test.geysermc.org
|
||||||
|
@ -113,3 +111,15 @@ custom-servers:
|
||||||
database: "geyser_connect"
|
database: "geyser_connect"
|
||||||
host: "localhost"
|
host: "localhost"
|
||||||
port: 3306
|
port: 3306
|
||||||
|
|
||||||
|
# Enable virtual hosts to be specified to skip the server list
|
||||||
|
# Allows people to connect using addresses like
|
||||||
|
# hypixel.net._p25565.example.com
|
||||||
|
# hypixel.net.example.com
|
||||||
|
# hypixel.net._o.example.com - For offline mode
|
||||||
|
vhost:
|
||||||
|
# Should this be enabled
|
||||||
|
enabled: false
|
||||||
|
|
||||||
|
# The base domain pointing to the server
|
||||||
|
base-domain: example.com
|
||||||
|
|
Loading…
Add table
Reference in a new issue