forked from GeyserMC/Geyser
Rewrite Ping Passthrough (#468)
* Fix ping passthrough on BungeeCord * Initial implementation of direct ping passthrough * Finished implementation of direct ping passthrough * Remove test for something else entirely * Fix standalone * Add config option for ping passthrough interval * Use GeyserPingInfo to reduce methods * Add querying; modify ping passthrough * Add separate config options for passthrough MOTD and player counts * Convert all plugin bootstraps to use internal ping events to that other plugins can handle ping modifications * Small changes * Fix invalid packet spawm * Add legacy ping passthrough option * Fix BungeeCord * Proper UUID for BungeeCord, thanks @theminecoder * Update config version and messages * Merge master... again * Add missing javadocs and minor changes Co-authored-by: James Harrison <james@fasttortoise.co.uk> Co-authored-by: theminecoder <theminecoder.dev@gmail.com> Co-authored-by: Redned <redned235@gmail.com>
This commit is contained in:
parent
59da87a10f
commit
99f69b3a7d
26 changed files with 1108 additions and 106 deletions
|
@ -32,7 +32,7 @@ import java.util.Map;
|
|||
public interface GeyserConfiguration {
|
||||
|
||||
// Modify this when you update the config
|
||||
int CURRENT_CONFIG_VERSION = 2;
|
||||
int CURRENT_CONFIG_VERSION = 3;
|
||||
|
||||
IBedrockConfiguration getBedrock();
|
||||
|
||||
|
@ -42,7 +42,13 @@ public interface GeyserConfiguration {
|
|||
|
||||
boolean isCommandSuggestions();
|
||||
|
||||
boolean isPingPassthrough();
|
||||
boolean isPassthroughMotd();
|
||||
|
||||
boolean isPassthroughPlayerCounts();
|
||||
|
||||
boolean isLegacyPingPassthrough();
|
||||
|
||||
int getPingPassthroughInterval();
|
||||
|
||||
int getMaxPlayers();
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.geysermc.connector.network.remote.RemoteServer;
|
|||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.Translators;
|
||||
import org.geysermc.connector.network.translators.world.WorldManager;
|
||||
import org.geysermc.connector.thread.PingPassthroughThread;
|
||||
import org.geysermc.connector.utils.DimensionUtils;
|
||||
import org.geysermc.connector.utils.DockerCheck;
|
||||
import org.geysermc.connector.utils.Toolbox;
|
||||
|
@ -71,7 +70,6 @@ public class GeyserConnector {
|
|||
private boolean shuttingDown = false;
|
||||
|
||||
private final ScheduledExecutorService generalThreadPool;
|
||||
private PingPassthroughThread passthroughThread;
|
||||
|
||||
private BedrockServer bedrockServer;
|
||||
private PlatformType platformType;
|
||||
|
@ -111,10 +109,6 @@ public class GeyserConnector {
|
|||
remoteServer = new RemoteServer(config.getRemote().getAddress(), config.getRemote().getPort());
|
||||
authType = AuthType.getByName(config.getRemote().getAuthType());
|
||||
|
||||
passthroughThread = new PingPassthroughThread(this);
|
||||
if (config.isPingPassthrough())
|
||||
generalThreadPool.scheduleAtFixedRate(passthroughThread, 1, 1, TimeUnit.SECONDS);
|
||||
|
||||
if (config.isAboveBedrockNetherBuilding())
|
||||
DimensionUtils.changeBedrockNetherId(); // Apply End dimension ID workaround to Nether
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
package org.geysermc.connector.bootstrap;
|
||||
|
||||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||
import org.geysermc.connector.GeyserConfiguration;
|
||||
import org.geysermc.connector.GeyserLogger;
|
||||
import org.geysermc.connector.command.CommandManager;
|
||||
|
@ -67,6 +68,13 @@ public interface GeyserBootstrap {
|
|||
*/
|
||||
CommandManager getGeyserCommandManager();
|
||||
|
||||
/**
|
||||
* Returns the current PingPassthrough manager
|
||||
*
|
||||
* @return The current PingPassthrough manager
|
||||
*/
|
||||
IGeyserPingPassthrough getGeyserPingPassthrough();
|
||||
|
||||
/**
|
||||
* Returns the current WorldManager
|
||||
*
|
||||
|
|
|
@ -25,11 +25,12 @@
|
|||
|
||||
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;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
||||
import com.nukkitx.protocol.bedrock.*;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import org.geysermc.common.ping.GeyserPingInfo;
|
||||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||
import org.geysermc.connector.GeyserConfiguration;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
|
@ -39,7 +40,7 @@ import java.net.InetSocketAddress;
|
|||
|
||||
public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
||||
|
||||
private GeyserConnector connector;
|
||||
private final GeyserConnector connector;
|
||||
|
||||
public ConnectorServerEventHandler(GeyserConnector connector) {
|
||||
this.connector = connector;
|
||||
|
@ -56,29 +57,39 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||
connector.getLogger().debug(inetSocketAddress + " has pinged you!");
|
||||
|
||||
GeyserConfiguration config = connector.getConfig();
|
||||
ServerStatusInfo serverInfo = connector.getPassthroughThread().getInfo();
|
||||
|
||||
GeyserPingInfo pingInfo = null;
|
||||
if (config.isPassthroughMotd() || config.isPassthroughPlayerCounts()) {
|
||||
IGeyserPingPassthrough pingPassthrough = connector.getBootstrap().getGeyserPingPassthrough();
|
||||
pingInfo = pingPassthrough.getPingInformation();
|
||||
}
|
||||
|
||||
BedrockPong pong = new BedrockPong();
|
||||
pong.setEdition("MCPE");
|
||||
pong.setGameType("Default");
|
||||
pong.setNintendoLimited(false);
|
||||
pong.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion());
|
||||
pong.setVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion());
|
||||
pong.setVersion(null); // Server tries to connect either way and it looks better
|
||||
pong.setIpv4Port(config.getBedrock().getPort());
|
||||
if (connector.getConfig().isPingPassthrough() && serverInfo != null) {
|
||||
String[] motd = MessageUtils.getBedrockMessage(serverInfo.getDescription()).split("\n");
|
||||
|
||||
if (config.isPassthroughMotd() && pingInfo != null && pingInfo.motd != null) {
|
||||
String[] motd = MessageUtils.getBedrockMessage(Message.fromString(pingInfo.motd)).split("\n");
|
||||
String mainMotd = motd[0]; // First line of the motd.
|
||||
String subMotd = (motd.length != 1) ? motd[1] : ""; // Second line of the motd if present, otherwise blank.
|
||||
|
||||
pong.setMotd(mainMotd.trim());
|
||||
pong.setSubMotd(subMotd.trim()); // Trimmed to shift it to the left, prevents the universe from collapsing on us just because we went 2 characters over the text box's limit.
|
||||
pong.setPlayerCount(serverInfo.getPlayerInfo().getOnlinePlayers());
|
||||
pong.setMaximumPlayerCount(serverInfo.getPlayerInfo().getMaxPlayers());
|
||||
} else {
|
||||
pong.setMotd(config.getBedrock().getMotd1());
|
||||
pong.setSubMotd(config.getBedrock().getMotd2());
|
||||
}
|
||||
|
||||
if (config.isPassthroughPlayerCounts() && pingInfo != null) {
|
||||
pong.setPlayerCount(pingInfo.currentPlayerCount);
|
||||
pong.setMaximumPlayerCount(pingInfo.maxPlayerCount);
|
||||
} else {
|
||||
pong.setPlayerCount(connector.getPlayers().size());
|
||||
pong.setMaximumPlayerCount(config.getMaxPlayers());
|
||||
pong.setMotd(config.getBedrock().getMotd1());
|
||||
pong.setMotd(config.getBedrock().getMotd2());
|
||||
}
|
||||
|
||||
//Bedrock will not even attempt a connection if the client thinks the server is full
|
||||
|
@ -105,4 +116,9 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||
});
|
||||
bedrockServerSession.setPacketCodec(GeyserConnector.BEDROCK_PACKET_CODEC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnhandledDatagram(ChannelHandlerContext ctx, DatagramPacket packet) {
|
||||
new QueryPacketHandler(connector, packet.sender(), packet.content());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,268 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.connector.network;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import org.geysermc.common.ping.GeyserPingInfo;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.utils.MessageUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class QueryPacketHandler {
|
||||
|
||||
public static final byte HANDSHAKE = 0x09;
|
||||
public static final byte STATISTICS = 0x00;
|
||||
|
||||
private GeyserConnector connector;
|
||||
private InetSocketAddress sender;
|
||||
private byte type;
|
||||
private int sessionId;
|
||||
private byte[] token;
|
||||
|
||||
/**
|
||||
* The Query packet handler instance
|
||||
* @param connector Geyser Connector
|
||||
* @param sender The Sender IP/Port for the Query
|
||||
* @param buffer The Query data
|
||||
*/
|
||||
public QueryPacketHandler(GeyserConnector connector, InetSocketAddress sender, ByteBuf buffer) {
|
||||
if(!isQueryPacket(buffer))
|
||||
return;
|
||||
|
||||
this.connector = connector;
|
||||
this.sender = sender;
|
||||
this.type = buffer.readByte();
|
||||
this.sessionId = buffer.readInt();
|
||||
|
||||
regenerateToken();
|
||||
handle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the packet is in fact a query packet
|
||||
* @param buffer Query data
|
||||
* @return if the packet is a query packet
|
||||
*/
|
||||
private boolean isQueryPacket(ByteBuf buffer) {
|
||||
return (buffer.readableBytes() >= 2) ? buffer.readUnsignedShort() == 65277 : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the query
|
||||
*/
|
||||
private void handle() {
|
||||
switch (type) {
|
||||
case HANDSHAKE:
|
||||
sendToken();
|
||||
case STATISTICS:
|
||||
sendQueryData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the token to the sender
|
||||
*/
|
||||
private void sendToken() {
|
||||
ByteBuf reply = ByteBufAllocator.DEFAULT.ioBuffer(10);
|
||||
reply.writeByte(HANDSHAKE);
|
||||
reply.writeInt(sessionId);
|
||||
reply.writeBytes(getTokenString(this.token, this.sender.getAddress()));
|
||||
reply.writeByte(0);
|
||||
|
||||
sendPacket(reply);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the query data to the sender
|
||||
*/
|
||||
private void sendQueryData() {
|
||||
ByteBuf reply = ByteBufAllocator.DEFAULT.ioBuffer(64);
|
||||
reply.writeByte(STATISTICS);
|
||||
reply.writeInt(sessionId);
|
||||
|
||||
// Game Info
|
||||
reply.writeBytes(getGameData());
|
||||
|
||||
// Players
|
||||
reply.writeBytes(getPlayers());
|
||||
|
||||
sendPacket(reply);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the game data for the query
|
||||
* @return the game data for the query
|
||||
*/
|
||||
private byte[] getGameData() {
|
||||
ByteArrayOutputStream query = new ByteArrayOutputStream();
|
||||
|
||||
GeyserPingInfo pingInfo = null;
|
||||
String motd;
|
||||
String currentPlayerCount;
|
||||
String maxPlayerCount;
|
||||
|
||||
if (connector.getConfig().isPassthroughMotd() || connector.getConfig().isPassthroughPlayerCounts()) {
|
||||
pingInfo = connector.getBootstrap().getGeyserPingPassthrough().getPingInformation();
|
||||
}
|
||||
|
||||
if (connector.getConfig().isPassthroughMotd() && pingInfo != null) {
|
||||
String[] javaMotd = MessageUtils.getBedrockMessage(Message.fromString(pingInfo.motd)).split("\n");
|
||||
motd = javaMotd[0].trim(); // First line of the motd.
|
||||
} else {
|
||||
motd = connector.getConfig().getBedrock().getMotd1();
|
||||
}
|
||||
|
||||
// If passthrough player counts is enabled lets get players from the server
|
||||
if (connector.getConfig().isPassthroughPlayerCounts() && pingInfo != null) {
|
||||
currentPlayerCount = String.valueOf(pingInfo.currentPlayerCount);
|
||||
maxPlayerCount = String.valueOf(pingInfo.maxPlayerCount);
|
||||
} else {
|
||||
currentPlayerCount = String.valueOf(connector.getPlayers().size());
|
||||
maxPlayerCount = String.valueOf(connector.getConfig().getMaxPlayers());
|
||||
}
|
||||
|
||||
// Create a hashmap of all game data needed in the query
|
||||
Map<String, String> gameData = new HashMap<String, String>();
|
||||
gameData.put("hostname", motd);
|
||||
gameData.put("gametype", "SMP");
|
||||
gameData.put("game_id", "MINECRAFT");
|
||||
gameData.put("version", GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion());
|
||||
gameData.put("plugins", "");
|
||||
gameData.put("map", GeyserConnector.NAME);
|
||||
gameData.put("numplayers", currentPlayerCount);
|
||||
gameData.put("maxplayers", maxPlayerCount);
|
||||
gameData.put("hostport", String.valueOf(connector.getConfig().getBedrock().getPort()));
|
||||
gameData.put("hostip", connector.getConfig().getBedrock().getAddress());
|
||||
|
||||
try {
|
||||
// Blank Buffer Bytes
|
||||
query.write("GeyserMC".getBytes());
|
||||
query.write((byte) 0x00);
|
||||
query.write((byte) 128);
|
||||
query.write((byte) 0x00);
|
||||
|
||||
// Fills the game data
|
||||
for(Map.Entry<String, String> entry : gameData.entrySet()) {
|
||||
query.write(entry.getKey().getBytes());
|
||||
query.write((byte) 0x00);
|
||||
query.write(entry.getValue().getBytes());
|
||||
query.write((byte) 0x00);
|
||||
}
|
||||
|
||||
// Final byte to show the end of the game data
|
||||
query.write(new byte[]{0x00, 0x01});
|
||||
return query.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] getPlayers() {
|
||||
ByteArrayOutputStream query = new ByteArrayOutputStream();
|
||||
|
||||
GeyserPingInfo pingInfo = null;
|
||||
if (connector.getConfig().isPassthroughMotd() || connector.getConfig().isPassthroughPlayerCounts()) {
|
||||
pingInfo = connector.getBootstrap().getGeyserPingPassthrough().getPingInformation();
|
||||
}
|
||||
|
||||
try {
|
||||
// Start the player section
|
||||
query.write("player_".getBytes());
|
||||
query.write(new byte[]{0x00, 0x00});
|
||||
|
||||
// Fill player names
|
||||
if(pingInfo != null) {
|
||||
for (String username : pingInfo.getPlayers()) {
|
||||
query.write(username.getBytes());
|
||||
query.write((byte) 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
// Final byte to show the end of the player data
|
||||
query.write((byte) 0x00);
|
||||
return query.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a packet to the sender
|
||||
* @param data packet data
|
||||
*/
|
||||
private void sendPacket(ByteBuf data) {
|
||||
connector.getBedrockServer().getRakNet().send(sender, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerates a token
|
||||
*/
|
||||
public void regenerateToken() {
|
||||
byte[] token = new byte[16];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
token[i] = (byte) new Random().nextInt(255);
|
||||
}
|
||||
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an MD5 token for the current IP/Port.
|
||||
* This should reset every 30 seconds but a new one is generated per instance
|
||||
* Seems wasteful to code something in to clear it when it has no use.
|
||||
* @param token the token
|
||||
* @param address the address
|
||||
* @return an MD5 token for the current IP/Port
|
||||
*/
|
||||
public static byte[] getTokenString(byte[] token, InetAddress address) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
digest.update(address.toString().getBytes(StandardCharsets.UTF_8));
|
||||
digest.update(token);
|
||||
return Arrays.copyOf(digest.digest(), 4);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return ByteBuffer.allocate(4).putInt(ThreadLocalRandom.current().nextInt()).array();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.connector.ping;
|
||||
|
||||
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.handler.ServerInfoHandler;
|
||||
import com.github.steveice10.packetlib.Client;
|
||||
import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
|
||||
import org.geysermc.common.ping.GeyserPingInfo;
|
||||
import org.geysermc.connector.GeyserConfiguration;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.GeyserLogger;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runnable {
|
||||
|
||||
private GeyserConnector connector;
|
||||
|
||||
public GeyserLegacyPingPassthrough(GeyserConnector connector) {
|
||||
this.connector = connector;
|
||||
this.pingInfo = new GeyserPingInfo(null, 0, 0);
|
||||
}
|
||||
|
||||
private GeyserPingInfo pingInfo;
|
||||
|
||||
private Client client;
|
||||
|
||||
/**
|
||||
* Start legacy ping passthrough thread
|
||||
* @param connector GeyserConnector
|
||||
* @return GeyserPingPassthrough, or null if not initialized
|
||||
*/
|
||||
public static IGeyserPingPassthrough init(GeyserConnector connector) {
|
||||
if (connector.getConfig().isPassthroughMotd() || connector.getConfig().isPassthroughPlayerCounts()) {
|
||||
GeyserLegacyPingPassthrough pingPassthrough = new GeyserLegacyPingPassthrough(connector);
|
||||
// Ensure delay is not zero
|
||||
int interval = (connector.getConfig().getPingPassthroughInterval() == 0) ? 1 : connector.getConfig().getPingPassthroughInterval();
|
||||
connector.getLogger().debug("Scheduling ping passthrough at an interval of " + interval + " second(s).");
|
||||
connector.getGeneralThreadPool().scheduleAtFixedRate(pingPassthrough, 1, interval, TimeUnit.SECONDS);
|
||||
return pingPassthrough;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeyserPingInfo getPingInformation() {
|
||||
return pingInfo;
|
||||
}
|
||||
|
||||
@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.pingInfo = new GeyserPingInfo(info.getDescription().getFullText(), info.getPlayerInfo().getOnlinePlayers(), info.getPlayerInfo().getMaxPlayers());
|
||||
this.client.getSession().disconnect(null);
|
||||
});
|
||||
|
||||
client.getSession().connect();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.connector.ping;
|
||||
|
||||
import org.geysermc.common.ping.GeyserPingInfo;
|
||||
|
||||
/**
|
||||
* Interface that retrieves ping passthrough information from the Java server
|
||||
*/
|
||||
public interface IGeyserPingPassthrough {
|
||||
|
||||
/**
|
||||
* Get the MOTD of the server displayed on the multiplayer screen
|
||||
* @return string of the MOTD
|
||||
*/
|
||||
GeyserPingInfo getPingInformation();
|
||||
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 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
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ bedrock:
|
|||
address: 0.0.0.0
|
||||
# The port that will listen for connections
|
||||
port: 19132
|
||||
# The MOTD that will be broadcasted to Minecraft: Bedrock Edition clients
|
||||
# The MOTD that will be broadcasted to Minecraft: Bedrock Edition clients. Irrelevant if "passthrough-motd" is set to true
|
||||
motd1: "GeyserMC"
|
||||
motd2: "Another GeyserMC forced host."
|
||||
remote:
|
||||
|
@ -45,8 +45,17 @@ floodgate-key-file: public-key.pem
|
|||
# Disabling this will prevent command suggestions from being sent and solve freezing for Bedrock clients.
|
||||
command-suggestions: true
|
||||
|
||||
# Relay the MOTD, player count and max players from the remote server
|
||||
ping-passthrough: false
|
||||
# The following two options enable "ping passthrough" - the MOTD and/or player count gets retrieved from the Java server.
|
||||
# Relay the MOTD from the remote server to Bedrock players.
|
||||
passthrough-motd: false
|
||||
# Relay the player count and max players from the remote server to Bedrock players.
|
||||
passthrough-player-counts: false
|
||||
# Enable LEGACY ping passthrough. There is no need to enable this unless your MOTD or player count does not appear properly.
|
||||
# This option does nothing on standalone.
|
||||
legacy-ping-passthrough: false
|
||||
# How often to ping the remote server, in seconds. Only relevant for standalone or legacy ping passthrough.
|
||||
# Increase if you are getting BrokenPipe errors.
|
||||
ping-passthrough-interval: 3
|
||||
|
||||
# Maximum amount of players that can connect
|
||||
max-players: 100
|
||||
|
@ -94,4 +103,4 @@ metrics:
|
|||
uuid: generateduuid
|
||||
|
||||
# DO NOT TOUCH!
|
||||
config-version: 1
|
||||
config-version: 3
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a67cc940c0d47874c833ffeb58f38e33eabfcc33
|
||||
Subproject commit a7963d0a0236b1c47eea21718ac50706139d90cc
|
Loading…
Add table
Add a link
Reference in a new issue