Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce session server lookups #509

Merged
merged 12 commits into from
May 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ public final class Constants {
public static final int HANDSHAKE_PACKET_ID = 0;
public static final int LOGIN_SUCCESS_PACKET_ID = 2;
public static final int SET_COMPRESSION_PACKET_ID = 3;

public static final String DEFAULT_MINECRAFT_JAVA_SKIN_TEXTURE = "ewogICJ0aW1lc3RhbXAiIDogMTcxNTMwNTM4NDQwOSwKICAicHJvZmlsZUlkIiA6ICJjZDZkODYwMzRhMWI0YTgxYjhhN2E2Y2IyM2Y5MjI4MCIsCiAgInByb2ZpbGVOYW1lIiA6ICJKdWVsbGU5MTc5IiwKICAic2lnbmF0dXJlUmVxdWlyZWQiIDogdHJ1ZSwKICAidGV4dHVyZXMiIDogewogICAgIlNLSU4iIDogewogICAgICAidXJsIiA6ICJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzMxZjQ3N2ViMWE3YmVlZTYzMWMyY2E2NGQwNmY4ZjY4ZmE5M2EzMzg2ZDA0NDUyYWIyN2Y0M2FjZGYxYjYwY2IiCiAgICB9CiAgfQp9";
public static final String DEFAULT_MINECRAFT_JAVA_SKIN_SIGNATURE = "gUiXhG+rqQRpY2LEI3V81xOKtmuvqxZUZsqm5ojgTnUnWCAPY39H3SZV/p4C3+x4Yp1pBQCR24B1WCAXT8s1Pc3PPf0ptav2TOrn0+B40XJYlabx7m1Qd5tNmbzAAuZpmQ2kdprQom/KmtYJnxXgMHAEuOy4oW3n736ZTYlvDSZtXNcwElOIbg0Zq1Dis0Qm54MazDpYdC8VPm1twrrR6DAHSJeTAx99NBcVgKDEwnFEO+4ch4ATD0AboJq2Alfa81b2BZ8ko02rB6s4WP4/qG1yyNBanO1FnSqqNPoNXQT/+og6dWOW62dcu9OXAdTIaKJ9P+ER9Yyo6Tv5eQGSB7VikZIollYN2OZ2TPMyqqEouHjKAggQEdOb/avid08YMveQr9c7yW1Ay2JAF6BH6D0tmdZ4WQWZUT6xR98o88sUAIhSGbds+h8PbJdWhGa1MDT+hNEcUmWJ0Mui8CBWIrhJAzppgDbsZlX9mWjQEwJAtlcUe9BEeZV3EhriPr9dCg867ojV5yXjrv+G6fpPUy+Zkkg/u38APnGBsWtPU8jDEpLtsGjbe6L7v7AvJuRv4Q35YuRD2j+UXZROxmkVKc4/PV/3SC15ePhU397gicQ5E41kvjikIdYYdkjQoj2G2esEZmvqCWzAm1czPeH+FiemCYgscM2QcFe+rBV0GJw=";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.geysermc.floodgate.util.ReflectionUtils.setValue;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -38,6 +39,7 @@
import org.geysermc.floodgate.player.FloodgateHandshakeHandler;
import org.geysermc.floodgate.player.FloodgateHandshakeHandler.HandshakeResult;
import org.geysermc.floodgate.util.ClassNames;
import org.geysermc.floodgate.util.Constants;
import org.geysermc.floodgate.util.ProxyUtils;

public final class SpigotDataHandler extends CommonDataHandler {
Expand Down Expand Up @@ -171,6 +173,15 @@ private boolean checkAndHandleLogin(Object packet) throws Exception {
player.getCorrectUniqueId(), player.getCorrectUsername()
);

// Otherwise game server will try to fetch the skin from Mojang
gameProfile.getProperties().put(
"textures",
new Property("textures",
Constants.DEFAULT_MINECRAFT_JAVA_SKIN_TEXTURE,
Constants.DEFAULT_MINECRAFT_JAVA_SKIN_SIGNATURE
)
);

// we have to fake the offline player (login) cycle

if (ClassNames.IS_PRE_1_20_2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@
import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import net.kyori.adventure.text.Component;
import org.geysermc.floodgate.api.ProxyFloodgateApi;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.api.player.FloodgatePlayer;
import org.geysermc.floodgate.config.ProxyFloodgateConfig;
import org.geysermc.floodgate.util.Constants;
import org.geysermc.floodgate.util.LanguageManager;

public final class VelocityListener {
Expand All @@ -69,26 +70,21 @@ public final class VelocityListener {
INITIAL_MINECRAFT_CONNECTION = getFieldOfType(initialConnection, minecraftConnection);

// Since Velocity 3.1.0
Class<?> loginInboundConnection =
onebeastchris marked this conversation as resolved.
Show resolved Hide resolved
getPrefixedClassSilently("connection.client.LoginInboundConnection");
Class<?> loginInboundConnection = getPrefixedClassSilently(
"connection.client.LoginInboundConnection");
if (loginInboundConnection != null) {
INITIAL_CONNECTION_DELEGATE = getField(loginInboundConnection, "delegate");
Objects.requireNonNull(
INITIAL_CONNECTION_DELEGATE,
"initial inbound connection delegate cannot be null"
);
Objects.requireNonNull(INITIAL_CONNECTION_DELEGATE,
"initial inbound connection delegate cannot be null");
} else {
INITIAL_CONNECTION_DELEGATE = null;
}

CHANNEL = getFieldOfType(minecraftConnection, Channel.class);
}

private final Cache<InboundConnection, FloodgatePlayer> playerCache =
CacheBuilder.newBuilder()
.maximumSize(500)
.expireAfterAccess(20, TimeUnit.SECONDS)
.build();
private final Cache<InboundConnection, FloodgatePlayer> playerCache = CacheBuilder.newBuilder().maximumSize(
500).expireAfterAccess(20, TimeUnit.SECONDS).build();

@Inject private ProxyFloodgateConfig config;
@Inject private ProxyFloodgateApi api;
Expand Down Expand Up @@ -127,8 +123,7 @@ public void onPreLogin(PreLoginEvent event) {

if (kickMessage != null) {
event.setResult(
PreLoginEvent.PreLoginComponentResult.denied(Component.text(kickMessage))
);
PreLoginEvent.PreLoginComponentResult.denied(Component.text(kickMessage)));
return;
}

Expand All @@ -144,15 +139,13 @@ public void onGameProfileRequest(GameProfileRequestEvent event) {
if (player != null) {
playerCache.invalidate(event.getConnection());

GameProfile profile = new GameProfile(
player.getCorrectUniqueId(),
GameProfile profile = new GameProfile(player.getCorrectUniqueId(),
player.getCorrectUsername(),
Collections.emptyList()
List.of(new Property("textures", Constants.DEFAULT_MINECRAFT_JAVA_SKIN_TEXTURE,
Constants.DEFAULT_MINECRAFT_JAVA_SKIN_SIGNATURE))
// Otherwise game server will try to fetch the skin from Mojang
);
// The texture properties addition is to fix the February 2 2022 Mojang authentication changes
if (!config.isSendFloodgateData() && !player.isLinked()) {
profile = profile.addProperty(new Property("textures", "", ""));
}

event.setGameProfile(profile);
}
}
Expand Down