Skip to content

Commit

Permalink
Fix: Brand message being sent too early (#5265)
Browse files Browse the repository at this point in the history
* Fix: Brand message not being sent, send lowercase locale, ensure the MCPL default listener comes first

* Refactor disconnect handling

* apparently default listeners aren't always first... huh

* fix issue with bundle cache attempting to check a null inventory
  • Loading branch information
onebeastchris authored Jan 12, 2025
1 parent 1267b2e commit 58e2f17
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SessionDisconnectEvent(@NonNull GeyserConnection connection, @NonNull Str
}

/**
* Sets the disconnect reason, thereby overriding th original reason.
* Sets the disconnect message shown to the Bedrock client.
*
* @param disconnectReason the reason for the disconnect
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import java.net.InetSocketAddress;

/**
* Called whenever Geyser gets pinged
* Called whenever Geyser gets pinged by a Bedrock client.
* <p>
* This event allows you to modify/obtain the MOTD, maximum player count, and current number of players online,
* Geyser will reply to the client with what was given.
* This event allows you to modify/obtain the MOTD, maximum player count, and current number of players online.
* Geyser will reply to the client with the information provided in this event.
*/
public interface GeyserBedrockPingEvent extends Event {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* <br>
* This event is mapped to the existence of Brigadier on the server.
*/
public class ServerDefineCommandsEvent extends ConnectionEvent implements Cancellable {
public final class ServerDefineCommandsEvent extends ConnectionEvent implements Cancellable {
private final Set<? extends CommandInfo> commands;
private boolean cancelled;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* Fired when the Java server sends a transfer request to a different Java server.
* Geyser Extensions can listen to this event and set a target server ip/port for Bedrock players to be transferred to.
*/
public class ServerTransferEvent extends ConnectionEvent {
public final class ServerTransferEvent extends ConnectionEvent {

private final String host;
private final int port;
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/org/geysermc/geyser/GeyserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.geysermc.geyser.entity.EntityDefinitions;
import org.geysermc.geyser.erosion.UnixSocketClientListener;
import org.geysermc.geyser.event.GeyserEventBus;
import org.geysermc.geyser.event.type.SessionDisconnectEventImpl;
import org.geysermc.geyser.extension.GeyserExtensionManager;
import org.geysermc.geyser.impl.MinecraftVersionImpl;
import org.geysermc.geyser.level.BedrockDimension;
Expand All @@ -86,6 +87,7 @@
import org.geysermc.geyser.scoreboard.ScoreboardUpdater;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.PendingMicrosoftAuthentication;
import org.geysermc.geyser.session.SessionDisconnectListener;
import org.geysermc.geyser.session.SessionManager;
import org.geysermc.geyser.session.cache.RegistryCache;
import org.geysermc.geyser.skin.FloodgateSkinUploader;
Expand All @@ -101,7 +103,6 @@
import org.geysermc.geyser.util.NewsHandler;
import org.geysermc.geyser.util.VersionCheckUtils;
import org.geysermc.geyser.util.WebUtils;
import org.geysermc.mcprotocollib.network.tcp.TcpSession;

import java.io.File;
import java.io.FileWriter;
Expand Down Expand Up @@ -266,6 +267,8 @@ public void initialize() {

// Register our general permissions when possible
eventBus.subscribe(this, GeyserRegisterPermissionsEvent.class, Permissions::register);
// Replace disconnect messages whenever necessary
eventBus.subscribe(this, SessionDisconnectEventImpl.class, SessionDisconnectListener::onSessionDisconnect);

startInstance();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
* Copyright (c) 2025 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,19 +23,26 @@
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.translator.protocol.java;
package org.geysermc.geyser.event.type;

import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundDisconnectPacket;
import lombok.Getter;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.event.bedrock.SessionDisconnectEvent;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.translator.text.MessageTranslator;

@Translator(packet = ClientboundDisconnectPacket.class)
public class JavaDisconnectTranslator extends PacketTranslator<ClientboundDisconnectPacket> {
/**
* A wrapper around the {@link SessionDisconnectEvent} that allows
* Geyser to access the underlying component when replacing disconnect messages.
*/
@Getter
public class SessionDisconnectEventImpl extends SessionDisconnectEvent {

private final Component reasonComponent;

@Override
public void translate(GeyserSession session, ClientboundDisconnectPacket packet) {
session.disconnect(MessageTranslator.convertMessage(packet.getReason(), session.locale()));
public SessionDisconnectEventImpl(@NonNull GeyserSession session, Component reason) {
super(session, MessageTranslator.convertToPlainText(reason, session.locale()));
this.reasonComponent = reason;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.RequiredArgsConstructor;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.GeyserLogger;
import org.geysermc.geyser.session.GeyserSession;

import java.util.stream.Stream;
Expand All @@ -45,16 +47,20 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
.findFirst()
.orElse(cause);

GeyserLogger logger = GeyserImpl.getInstance().getLogger();

if (!(rootCause instanceof IllegalArgumentException)) {
// Kick users that cause exceptions
session.getGeyser().getLogger().warning("Exception caught in session of" + session.bedrockUsername() + ": " + rootCause.getMessage());
logger.warning("Exception caught in session of" + session.bedrockUsername() + ": " + rootCause.getMessage());
session.disconnect("An internal error occurred!");
return;
}

// Kick users that try to send illegal packets
session.getGeyser().getLogger().warning(rootCause.getMessage());
logger.warning("Illegal packet from " + session.bedrockUsername() + ": " + rootCause.getMessage());
if (logger.isDebug()) {
cause.printStackTrace();
}
session.disconnect("Invalid packet received!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.mcprotocollib.network.packet.Packet;
import org.geysermc.mcprotocollib.network.tcp.TcpSession;
Expand All @@ -41,11 +42,11 @@ public void sendPacket(@NonNull Packet packet) {
this.session.send(packet);
}

public void disconnect(String reason) {
public void disconnect(Component reason) {
this.session.disconnect(reason);
}

public void disconnect(String reason, Throwable throwable) {
public void disconnect(Component reason, Throwable throwable) {
this.session.disconnect(reason, throwable);
}

Expand Down
Loading

0 comments on commit 58e2f17

Please sign in to comment.