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:
Ursprung
9a9f67b45f
Commit
ab55050d11
@ -29,6 +29,8 @@ import org.geysermc.api.command.CommandSender;
|
|||||||
import org.geysermc.api.session.AuthData;
|
import org.geysermc.api.session.AuthData;
|
||||||
import org.geysermc.api.window.FormWindow;
|
import org.geysermc.api.window.FormWindow;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
public interface Player extends CommandSender {
|
public interface Player extends CommandSender {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,4 +70,11 @@ public interface Player extends CommandSender {
|
|||||||
* @param id the id of the window
|
* @param id the id of the window
|
||||||
*/
|
*/
|
||||||
void sendForm(FormWindow window, int id);
|
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) {
|
public void addPlayer(Player player) {
|
||||||
players.put(player.getAuthenticationData().getName(), player);
|
players.put(player.getAuthenticationData().getName(), player);
|
||||||
players.put(player.getAuthenticationData().getUUID(), player);
|
players.put(player.getAuthenticationData().getUUID(), player);
|
||||||
|
players.put(player.getSocketAddress(), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePlayer(Player player) {
|
public void removePlayer(Player player) {
|
||||||
players.remove(player.getAuthenticationData().getName());
|
players.remove(player.getAuthenticationData().getName());
|
||||||
players.remove(player.getAuthenticationData().getUUID());
|
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.BedrockPong;
|
||||||
import com.nukkitx.protocol.bedrock.BedrockServerEventHandler;
|
import com.nukkitx.protocol.bedrock.BedrockServerEventHandler;
|
||||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||||
|
import org.geysermc.api.Player;
|
||||||
import org.geysermc.api.events.PingEvent;
|
import org.geysermc.api.events.PingEvent;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.configuration.GeyserConfiguration;
|
import org.geysermc.connector.configuration.GeyserConfiguration;
|
||||||
@ -102,7 +103,14 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||||||
public void onSessionCreation(BedrockServerSession bedrockServerSession) {
|
public void onSessionCreation(BedrockServerSession bedrockServerSession) {
|
||||||
bedrockServerSession.setLogging(true);
|
bedrockServerSession.setLogging(true);
|
||||||
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession)));
|
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);
|
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.network.translators.Registry;
|
||||||
import org.geysermc.connector.utils.Toolbox;
|
import org.geysermc.connector.utils.Toolbox;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class GeyserSession implements PlayerSession, Player {
|
public class GeyserSession implements PlayerSession, Player {
|
||||||
|
|
||||||
private GeyserConnector connector;
|
private final GeyserConnector connector;
|
||||||
|
private final BedrockServerSession upstream;
|
||||||
private RemoteServer remoteServer;
|
private RemoteServer remoteServer;
|
||||||
private BedrockServerSession upstream;
|
|
||||||
|
|
||||||
private Client downstream;
|
private Client downstream;
|
||||||
|
|
||||||
@ -179,7 +180,7 @@ public class GeyserSession implements PlayerSession, Player {
|
|||||||
if (downstream != null && downstream.getSession() != null) {
|
if (downstream != null && downstream.getSession() != null) {
|
||||||
downstream.getSession().disconnect(reason);
|
downstream.getSession().disconnect(reason);
|
||||||
}
|
}
|
||||||
if (upstream != null) {
|
if (upstream != null && !upstream.isClosed()) {
|
||||||
upstream.disconnect(reason);
|
upstream.disconnect(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,6 +242,11 @@ public class GeyserSession implements PlayerSession, Player {
|
|||||||
windowCache.showWindow(window, id);
|
windowCache.showWindow(window, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InetSocketAddress getSocketAddress() {
|
||||||
|
return this.upstream.getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
public void sendForm(FormWindow window) {
|
public void sendForm(FormWindow window) {
|
||||||
windowCache.showWindow(window);
|
windowCache.showWindow(window);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren