mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-11-23 07:16:39 +01:00
Close remote java connection when bedrock player leaves.
This commit is contained in:
parent
9a9f67b45f
commit
ab55050d11
4 changed files with 29 additions and 4 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue