Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +01:00
Finish ping-passthrough option
Dieser Commit ist enthalten in:
Ursprung
464e9cbd2a
Commit
58819ea9ce
@ -46,12 +46,14 @@ import org.geysermc.connector.network.remote.RemoteJavaServer;
|
||||
import org.geysermc.connector.network.translators.TranslatorsInit;
|
||||
import org.geysermc.connector.plugin.GeyserPluginLoader;
|
||||
import org.geysermc.connector.plugin.GeyserPluginManager;
|
||||
import org.geysermc.connector.thread.PingPassthroughThread;
|
||||
import org.geysermc.connector.utils.Toolbox;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GeyserConnector implements Connector {
|
||||
|
||||
@ -83,6 +85,9 @@ public class GeyserConnector implements Connector {
|
||||
@Getter
|
||||
private final ScheduledExecutorService generalThreadPool;
|
||||
|
||||
@Getter
|
||||
private PingPassthroughThread passthroughThread;
|
||||
|
||||
public static void main(String[] args) {
|
||||
instance = new GeyserConnector();
|
||||
}
|
||||
@ -138,6 +143,10 @@ public class GeyserConnector implements Connector {
|
||||
pluginManager = new GeyserPluginManager(new GeyserPluginLoader(this));
|
||||
pluginManager.getLoader().loadPlugins();
|
||||
|
||||
passthroughThread = new PingPassthroughThread(this);
|
||||
if (config.isPingPassthrough())
|
||||
generalThreadPool.scheduleAtFixedRate(passthroughThread, 1, 1, TimeUnit.SECONDS);
|
||||
|
||||
BedrockServer bedrockServer = new BedrockServer(new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort()));
|
||||
bedrockServer.setHandler(new ConnectorServerEventHandler(this));
|
||||
bedrockServer.bind().whenComplete((avoid, throwable) -> {
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package org.geysermc.connector.network;
|
||||
|
||||
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;
|
||||
@ -33,6 +34,7 @@ import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.configuration.GeyserConfiguration;
|
||||
import org.geysermc.connector.console.GeyserLogger;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.utils.MessageUtils;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
@ -56,16 +58,27 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
||||
GeyserConfiguration config = connector.getConfig();
|
||||
BedrockPong pong = new BedrockPong();
|
||||
pong.setEdition("MCPE");
|
||||
pong.setMotd(config.getBedrock().getMotd1());
|
||||
pong.setSubMotd(config.getBedrock().getMotd2());
|
||||
pong.setPlayerCount(2);
|
||||
pong.setMaximumPlayerCount(config.getMaxPlayers());
|
||||
pong.setGameType("Default");
|
||||
pong.setNintendoLimited(false);
|
||||
pong.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion());
|
||||
pong.setVersion("1.12.0");
|
||||
pong.setIpv4Port(19132);
|
||||
|
||||
if (connector.getConfig().isPingPassthrough()) {
|
||||
ServerStatusInfo serverInfo = connector.getPassthroughThread().getInfo();
|
||||
|
||||
if (serverInfo != null) {
|
||||
pong.setMotd(MessageUtils.getBedrockMessage(serverInfo.getDescription()));
|
||||
pong.setSubMotd(config.getBedrock().getMotd2());
|
||||
pong.setPlayerCount(serverInfo.getPlayerInfo().getOnlinePlayers());
|
||||
pong.setMaximumPlayerCount(serverInfo.getPlayerInfo().getMaxPlayers());
|
||||
}
|
||||
} else {
|
||||
pong.setPlayerCount(1);
|
||||
pong.setMaximumPlayerCount(config.getMaxPlayers());
|
||||
pong.setMotd(config.getBedrock().getMotd1());
|
||||
pong.setSubMotd(config.getBedrock().getMotd2());
|
||||
}
|
||||
return pong;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
package org.geysermc.connector.thread;
|
||||
|
||||
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.SubProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
||||
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler;
|
||||
import com.github.steveice10.packetlib.Client;
|
||||
import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
|
||||
public class PingPassthroughThread implements Runnable {
|
||||
|
||||
private GeyserConnector connector;
|
||||
|
||||
public PingPassthroughThread(GeyserConnector connector) {
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
@Getter
|
||||
private ServerStatusInfo info;
|
||||
|
||||
private Client client;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
this.client = new Client(connector.getConfig().getRemote().getAddress(), connector.getConfig().getRemote().getPort(), new MinecraftProtocol(SubProtocol.STATUS), new TcpSessionFactory());
|
||||
this.client.getSession().setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (ServerInfoHandler) (session, info) -> {
|
||||
this.info = info;
|
||||
this.client.getSession().disconnect(null);
|
||||
});
|
||||
|
||||
client.getSession().connect();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren