3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 00:00:41 +01:00

Close remote java connection when bedrock player leaves.

Dieser Commit ist enthalten in:
SupremeMortal 2019-09-13 14:37:31 +01:00
Ursprung 9a9f67b45f
Commit ab55050d11
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: DDBB25F8EE4FA29A
4 geänderte Dateien mit 29 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -29,6 +29,8 @@ import org.geysermc.api.command.CommandSender;
import org.geysermc.api.session.AuthData;
import org.geysermc.api.window.FormWindow;
import java.net.InetSocketAddress;
public interface Player extends CommandSender {
/**
@ -68,4 +70,11 @@ public interface Player extends CommandSender {
* @param id the id of the window
*/
void sendForm(FormWindow window, int id);
/**
* Returns the current hostname and port the player is connected with.
*
* @return player's socket address.
*/
InetSocketAddress getSocketAddress();
}

Datei anzeigen

@ -173,10 +173,12 @@ public class GeyserConnector implements Connector {
public void addPlayer(Player player) {
players.put(player.getAuthenticationData().getName(), player);
players.put(player.getAuthenticationData().getUUID(), player);
players.put(player.getSocketAddress(), player);
}
public void removePlayer(Player player) {
players.remove(player.getAuthenticationData().getName());
players.remove(player.getAuthenticationData().getUUID());
players.remove(player.getSocketAddress());
}
}

Datei anzeigen

@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.nukkitx.protocol.bedrock.BedrockPong;
import com.nukkitx.protocol.bedrock.BedrockServerEventHandler;
import com.nukkitx.protocol.bedrock.BedrockServerSession;
import org.geysermc.api.Player;
import org.geysermc.api.events.PingEvent;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.configuration.GeyserConfiguration;
@ -102,7 +103,14 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
public void onSessionCreation(BedrockServerSession bedrockServerSession) {
bedrockServerSession.setLogging(true);
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession)));
bedrockServerSession.addDisconnectHandler((x) -> GeyserLogger.DEFAULT.warning("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconnected for reason " + x));
bedrockServerSession.addDisconnectHandler(disconnectReason -> {
GeyserLogger.DEFAULT.info("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconnected for reason " + disconnectReason);
Player player = connector.getPlayers().get(bedrockServerSession.getAddress());
if (player != null) {
player.disconnect(disconnectReason.name());
}
});
bedrockServerSession.setPacketCodec(GeyserConnector.BEDROCK_PACKET_CODEC);
}
}

Datei anzeigen

@ -60,14 +60,15 @@ import org.geysermc.connector.network.session.cache.*;
import org.geysermc.connector.network.translators.Registry;
import org.geysermc.connector.utils.Toolbox;
import java.net.InetSocketAddress;
import java.util.UUID;
@Getter
public class GeyserSession implements PlayerSession, Player {
private GeyserConnector connector;
private final GeyserConnector connector;
private final BedrockServerSession upstream;
private RemoteServer remoteServer;
private BedrockServerSession upstream;
private Client downstream;
@ -179,7 +180,7 @@ public class GeyserSession implements PlayerSession, Player {
if (downstream != null && downstream.getSession() != null) {
downstream.getSession().disconnect(reason);
}
if (upstream != null) {
if (upstream != null && !upstream.isClosed()) {
upstream.disconnect(reason);
}
}
@ -241,6 +242,11 @@ public class GeyserSession implements PlayerSession, Player {
windowCache.showWindow(window, id);
}
@Override
public InetSocketAddress getSocketAddress() {
return this.upstream.getAddress();
}
public void sendForm(FormWindow window) {
windowCache.showWindow(window);
}