Skip to content

Commit

Permalink
SRV improvements and improvements for GeyserConnect (GeyserMC#2048)
Browse files Browse the repository at this point in the history
- Individual per-player remote, port, and address
- Removal of RemoteServer class
- Do SRV lookup on startup and that's it
  • Loading branch information
Camotoy authored Mar 17, 2021
1 parent 3d4fff8 commit b176fc7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 61 deletions.
4 changes: 2 additions & 2 deletions connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.github.steveice10</groupId>
<groupId>com.github.GeyserMC</groupId>
<artifactId>PacketLib</artifactId>
<version>54f761c</version>
<version>b77a427</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- Move this exclusion back to MCProtocolLib it gets the latest PacketLib -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.metrics.Metrics;
import org.geysermc.connector.network.ConnectorServerEventHandler;
import org.geysermc.connector.network.remote.RemoteServer;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.BiomeTranslator;
import org.geysermc.connector.network.translators.EntityIdentifierRegistry;
Expand Down Expand Up @@ -97,9 +96,8 @@ public class GeyserConnector {

private static GeyserConnector instance;

private RemoteServer remoteServer;
@Setter
private AuthType authType;
private AuthType defaultAuthType;

private boolean shuttingDown = false;

Expand Down Expand Up @@ -166,7 +164,7 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
String remoteAddress = config.getRemote().getAddress();
int remotePort = config.getRemote().getPort();
// Filters whether it is not an IP address or localhost, because otherwise it is not possible to find out an SRV entry.
if ((config.isLegacyPingPassthrough() || platformType == PlatformType.STANDALONE) && !remoteAddress.matches(IP_REGEX) && !remoteAddress.equalsIgnoreCase("localhost")) {
if (!remoteAddress.matches(IP_REGEX) && !remoteAddress.equalsIgnoreCase("localhost")) {
try {
// Searches for a server address and a port from a SRV record of the specified host name
InitialDirContext ctx = new InitialDirContext();
Expand All @@ -186,8 +184,7 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
}
}

remoteServer = new RemoteServer(config.getRemote().getAddress(), remotePort);
authType = AuthType.getByName(config.getRemote().getAuthType());
defaultAuthType = AuthType.getByName(config.getRemote().getAuthType());

CooldownUtils.setShowCooldown(config.isShowCooldown());
DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether
Expand Down Expand Up @@ -334,8 +331,7 @@ public void run() {
generalThreadPool.shutdown();
bedrockServer.close();
players.clear();
remoteServer = null;
authType = null;
defaultAuthType = null;
this.getCommandManager().getCommands().clear();

bootstrap.getGeyserLogger().info(LanguageUtils.getLocaleStringLog("geyser.core.shutdown.done"));
Expand Down Expand Up @@ -371,6 +367,7 @@ public GeyserSession getPlayerByUuid(UUID uuid) {
* @param xuid the Xbox user identifier
* @return the player or <code>null</code> if there is no player online with this xuid
*/
@SuppressWarnings("unused") // API usage
public GeyserSession getPlayerByXuid(String xuid) {
for (GeyserSession session : players) {
if (session.getAuthData() != null && session.getAuthData().getXboxUUID().equals(xuid)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public boolean handle(LoginPacket loginPacket) {
public boolean handle(ResourcePackClientResponsePacket packet) {
switch (packet.getStatus()) {
case COMPLETED:
session.connect(connector.getRemoteServer());
session.connect();
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.connect", session.getAuthData().getName()));
break;

Expand Down Expand Up @@ -186,7 +186,7 @@ private boolean couldLoginUserByName(String bedrockUsername) {
public boolean handle(SetLocalPlayerAsInitializedPacket packet) {
LanguageUtils.loadGeyserLocale(session.getLocale());

if (!session.isLoggedIn() && !session.isLoggingIn() && session.getConnector().getAuthType() == AuthType.ONLINE) {
if (!session.isLoggedIn() && !session.isLoggingIn() && session.getRemoteAuthType() == AuthType.ONLINE) {
// TODO it is safer to key authentication on something that won't change (UUID, not username)
if (!couldLoginUserByName(session.getAuthData().getName())) {
LoginEncryptionUtils.showLoginWindow(session);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import org.geysermc.connector.entity.player.SkullPlayerEntity;
import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.inventory.PlayerInventory;
import org.geysermc.connector.network.remote.RemoteServer;
import org.geysermc.connector.network.session.auth.AuthData;
import org.geysermc.connector.network.session.auth.BedrockClientData;
import org.geysermc.connector.network.session.cache.*;
Expand Down Expand Up @@ -113,13 +112,21 @@ public class GeyserSession implements CommandSender {

private final GeyserConnector connector;
private final UpstreamSession upstream;
private RemoteServer remoteServer;
private Client downstream;
@Setter
private AuthData authData;
@Setter
private BedrockClientData clientData;

/* Setter for GeyserConnect */
@Setter
private String remoteAddress;
@Setter
private int remotePort;
@Setter
private AuthType remoteAuthType;
/* Setter for GeyserConnect */

@Deprecated
@Setter
private boolean microsoftAccount;
Expand Down Expand Up @@ -438,9 +445,14 @@ public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServ
});
}

public void connect(RemoteServer remoteServer) {
/**
* Send all necessary packets to load Bedrock into the server
*/
public void connect() {
startGame();
this.remoteServer = remoteServer;
this.remoteAddress = connector.getConfig().getRemote().getAddress();
this.remotePort = connector.getConfig().getRemote().getPort();
this.remoteAuthType = connector.getDefaultAuthType();

// Set the hardcoded shield ID to the ID we just defined in StartGamePacket
upstream.getSession().getHardcodedBlockingId().set(ItemRegistry.SHIELD.getBedrockId());
Expand Down Expand Up @@ -485,8 +497,8 @@ public void connect(RemoteServer remoteServer) {
}

public void login() {
if (connector.getAuthType() != AuthType.ONLINE) {
if (connector.getAuthType() == AuthType.OFFLINE) {
if (this.remoteAuthType != AuthType.ONLINE) {
if (this.remoteAuthType == AuthType.OFFLINE) {
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.offline"));
} else {
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.floodgate"));
Expand Down Expand Up @@ -595,7 +607,7 @@ private void attemptCodeAuthentication(MsaAuthenticationService msaAuthenticatio
* After getting whatever credentials needed, we attempt to join the Java server.
*/
private void connectDownstream() {
boolean floodgate = connector.getAuthType() == AuthType.FLOODGATE;
boolean floodgate = this.remoteAuthType == AuthType.FLOODGATE;
final PublicKey publicKey;

if (floodgate) {
Expand All @@ -618,7 +630,8 @@ private void connectDownstream() {
// Start ticking
tickThread = connector.getGeneralThreadPool().scheduleAtFixedRate(this::tick, 50, 50, TimeUnit.MILLISECONDS);

downstream = new Client(remoteServer.getAddress(), remoteServer.getPort(), protocol, new TcpSessionFactory());
downstream = new Client(this.remoteAddress, this.remotePort, protocol, new TcpSessionFactory());
disableSrvResolving();
if (connector.getConfig().getRemote().isUseProxyProtocol()) {
downstream.getSession().setFlag(BuiltinFlags.ENABLE_CLIENT_PROXY_PROTOCOL, true);
downstream.getSession().setFlag(BuiltinFlags.CLIENT_PROXIED_ADDRESS, upstream.getAddress());
Expand Down Expand Up @@ -666,7 +679,7 @@ public void connected(ConnectedEvent event) {
disconnect(LanguageUtils.getPlayerLocaleString("geyser.network.remote.invalid_account", clientData.getLanguageCode()));
return;
}
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.remote.connect", authData.getName(), protocol.getProfile().getName(), remoteServer.getAddress()));
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.remote.connect", authData.getName(), protocol.getProfile().getName(), remoteAddress));
playerEntity.setUuid(protocol.getProfile().getId());
playerEntity.setUsername(protocol.getProfile().getName());

Expand All @@ -687,7 +700,7 @@ public void connected(ConnectedEvent event) {
public void disconnected(DisconnectedEvent event) {
loggingIn = false;
loggedIn = false;
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.remote.disconnect", authData.getName(), remoteServer.getAddress(), event.getReason()));
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.remote.disconnect", authData.getName(), remoteAddress, event.getReason()));
if (event.getCause() != null) {
event.getCause().printStackTrace();
}
Expand All @@ -705,7 +718,7 @@ public void packetReceived(PacketReceivedEvent event) {
playerEntity.setUuid(profile.getId());

// Check if they are not using a linked account
if (connector.getAuthType() == AuthType.OFFLINE || playerEntity.getUuid().getMostSignificantBits() == 0) {
if (remoteAuthType == AuthType.OFFLINE || playerEntity.getUuid().getMostSignificantBits() == 0) {
SkinManager.handleBedrockSkin(playerEntity, clientData);
}
}
Expand Down Expand Up @@ -793,6 +806,13 @@ public void setSneaking(boolean sneaking) {
collisionManager.updateScaffoldingFlags();
}

/**
* Will be overwritten for GeyserConnect.
*/
protected void disableSrvResolving() {
this.downstream.getSession().setFlag(BuiltinFlags.ATTEMPT_SRV_RESOLVE, false);
}

@Override
public String getName() {
return authData.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private static GameProfileData loadBedrockOrOfflineSkin(GameProfile profile) {

String skinUrl = isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl();
String capeUrl = SkinProvider.EMPTY_CAPE.getTextureUrl();
if (("steve".equals(skinUrl) || "alex".equals(skinUrl)) && GeyserConnector.getInstance().getAuthType() != AuthType.ONLINE) {
if (("steve".equals(skinUrl) || "alex".equals(skinUrl)) && GeyserConnector.getInstance().getDefaultAuthType() != AuthType.ONLINE) {
GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(profile.getId());

if (session != null) {
Expand Down

0 comments on commit b176fc7

Please sign in to comment.