Threading and ping improvements (#1870)

- Don't schedule for setting jumping on and off if cache chunks is enabled, since we don't need to know that
- Add a new setting to disable player ping forwarding. Hopefully this helps with timeouts.
This commit is contained in:
Camotoy 2021-02-10 12:18:31 -05:00 committed by GitHub
parent 1ec589fa35
commit b16e1d6b43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 43 additions and 28 deletions

View file

@ -56,10 +56,7 @@ import org.geysermc.connector.network.translators.world.WorldManager;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
import org.geysermc.connector.network.translators.world.block.entity.SkullBlockEntityTranslator;
import org.geysermc.connector.utils.DimensionUtils;
import org.geysermc.connector.utils.LanguageUtils;
import org.geysermc.connector.utils.LocaleUtils;
import org.geysermc.connector.utils.ResourcePack;
import org.geysermc.connector.utils.*;
import javax.naming.directory.Attribute;
import javax.naming.directory.InitialDirContext;
@ -190,6 +187,7 @@ public class GeyserConnector {
remoteServer = new RemoteServer(config.getRemote().getAddress(), remotePort);
authType = AuthType.getByName(config.getRemote().getAuthType());
CooldownUtils.setShowCooldown(config.isShowCooldown());
DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether
SkullBlockEntityTranslator.ALLOW_CUSTOM_SKULLS = config.isAllowCustomSkulls();

View file

@ -59,6 +59,8 @@ public interface GeyserConfiguration {
int getPingPassthroughInterval();
boolean isForwardPlayerPing();
int getMaxPlayers();
boolean isDebugMode();

View file

@ -74,6 +74,9 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
@JsonProperty("ping-passthrough-interval")
private int pingPassthroughInterval = 3;
@JsonProperty("forward-player-ping")
private boolean forwardPlayerPing = false;
@JsonProperty("max-players")
private int maxPlayers = 100;

View file

@ -170,6 +170,9 @@ public class GeyserSession implements CommandSender {
@Setter
private boolean sprinting;
/**
* Not updated if cache chunks is enabled.
*/
@Setter
private boolean jumping;
@ -567,8 +570,10 @@ public class GeyserSession implements CommandSender {
downstream.getSession().setFlag(BuiltinFlags.ENABLE_CLIENT_PROXY_PROTOCOL, true);
downstream.getSession().setFlag(BuiltinFlags.CLIENT_PROXIED_ADDRESS, upstream.getAddress());
}
// Let Geyser handle sending the keep alive
downstream.getSession().setFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, false);
if (connector.getConfig().isForwardPlayerPing()) {
// Let Geyser handle sending the keep alive
downstream.getSession().setFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, false);
}
downstream.getSession().addListener(new SessionAdapter() {
@Override
public void packetSending(PacketSendingEvent event) {

View file

@ -33,23 +33,25 @@ import org.geysermc.connector.network.translators.Translator;
import org.geysermc.floodgate.util.DeviceOS;
/**
* Used to send the keep alive packet back to the server
* Used to send the forwarded keep alive packet back to the server
*/
@Translator(packet = NetworkStackLatencyPacket.class)
public class BedrockNetworkStackLatencyTranslator extends PacketTranslator<NetworkStackLatencyPacket> {
@Override
public void translate(NetworkStackLatencyPacket packet, GeyserSession session) {
long pingId;
// so apparently, as of 1.16.200
// PS4 divides the network stack latency timestamp FOR US!!!
// WTF
if (session.getClientData().getDeviceOS().equals(DeviceOS.NX)) {
// Ignore the weird DeviceOS, our order is wrong and will be fixed in Floodgate 2.0
pingId = packet.getTimestamp();
} else {
pingId = packet.getTimestamp() / 1000;
if (session.getConnector().getConfig().isForwardPlayerPing()) {
long pingId;
// so apparently, as of 1.16.200
// PS4 divides the network stack latency timestamp FOR US!!!
// WTF
if (session.getClientData().getDeviceOS().equals(DeviceOS.NX)) {
// Ignore the weird DeviceOS, our order is wrong and will be fixed in Floodgate 2.0
pingId = packet.getTimestamp();
} else {
pingId = packet.getTimestamp() / 1000;
}
session.sendDownstreamPacket(new ClientKeepAlivePacket(pingId));
}
session.sendDownstreamPacket(new ClientKeepAlivePacket(pingId));
}
}

View file

@ -205,10 +205,11 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
session.getEntityCache().updateBossBars();
break;
case JUMP:
session.setJumping(true);
session.getConnector().getGeneralThreadPool().schedule(() -> {
session.setJumping(false);
}, 1, TimeUnit.SECONDS);
if (!session.getConnector().getConfig().isCacheChunks()) {
// Save the jumping status for determining teleport status
session.setJumping(true);
session.getConnector().getGeneralThreadPool().schedule(() -> session.setJumping(false), 1, TimeUnit.SECONDS);
}
break;
}
}

View file

@ -39,6 +39,9 @@ public class JavaKeepAliveTranslator extends PacketTranslator<ServerKeepAlivePac
@Override
public void translate(ServerKeepAlivePacket packet, GeyserSession session) {
if (!session.getConnector().getConfig().isForwardPlayerPing()) {
return;
}
NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket();
latencyPacket.setFromServer(true);
latencyPacket.setTimestamp(packet.getPingId() * 1000);

View file

@ -26,7 +26,6 @@
package org.geysermc.connector.utils;
import com.nukkitx.protocol.bedrock.packet.SetTitlePacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import java.util.concurrent.TimeUnit;
@ -36,11 +35,10 @@ import java.util.concurrent.TimeUnit;
* Much of the work here is from the wonderful folks from ViaRewind: https://github.com/ViaVersion/ViaRewind
*/
public class CooldownUtils {
private static boolean SHOW_COOLDOWN;
private final static boolean SHOW_COOLDOWN;
static {
SHOW_COOLDOWN = GeyserConnector.getInstance().getConfig().isShowCooldown();
public static void setShowCooldown(boolean showCooldown) {
SHOW_COOLDOWN = showCooldown;
}
/**
@ -116,5 +114,4 @@ public class CooldownUtils {
}
return builder.toString();
}
}

View file

@ -81,7 +81,11 @@ legacy-ping-passthrough: false
# Increase if you are getting BrokenPipe errors.
ping-passthrough-interval: 3
# Maximum amount of players that can connect
# Whether to forward player ping to the server. While enabling this will allow Bedrock players to have more accurate
# ping, it may also cause players to time out more easily.
forward-player-ping: false
# Maximum amount of players that can connect. This is only visual at this time and does not actually limit player count.
max-players: 100
# If debug messages should be sent through console