Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GeyserMC/Geyser into serv…
Browse files Browse the repository at this point in the history
…er-inventory
  • Loading branch information
Camotoy committed Feb 11, 2021
2 parents 66bb162 + b16e1d6 commit aaeca23
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import lombok.Getter;
import net.minecrell.terminalconsole.TerminalConsoleAppender;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Logger;
Expand Down Expand Up @@ -167,11 +168,6 @@ public void onEnable(boolean useGui, String configFilename) {
this.onEnable();
}

public void onEnable(boolean useGui) {
this.useGui = useGui;
this.onEnable();
}

@Override
public void onEnable() {
Logger logger = (Logger) LogManager.getRootLogger();
Expand Down Expand Up @@ -213,6 +209,9 @@ public void onEnable() {
}
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);

// Allow libraries like Protocol to have their debug information passthrough
logger.get().setLevel(geyserConfig.isDebugMode() ? Level.DEBUG : Level.INFO);

connector = GeyserConnector.start(PlatformType.STANDALONE, this);
geyserCommandManager = new GeyserCommandManager(connector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@
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;
Expand Down Expand Up @@ -190,6 +187,7 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public interface GeyserConfiguration {

int getPingPassthroughInterval();

boolean isForwardPlayerPing();

int getMaxPlayers();

boolean isDebugMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class BoatEntity extends Entity {
*/
private static final String BUOYANCY_DATA = "{\"apply_gravity\":true,\"base_buoyancy\":1.0,\"big_wave_probability\":0.02999999932944775," +
"\"big_wave_speed\":10.0,\"drag_down_on_buoyancy_removed\":0.0,\"liquid_blocks\":[\"minecraft:water\"," +
"\"minecraft:flowing_water\"],\"simulate_waves\":false}}";
"\"minecraft:flowing_water\"],\"simulate_waves\":false}";

private boolean isPaddlingLeft;
private float paddleTimeLeft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ public class GeyserSession implements CommandSender {
@Setter
private boolean sprinting;

/**
* Not updated if cache chunks is enabled.
*/
@Setter
private boolean jumping;

Expand Down Expand Up @@ -611,8 +614,10 @@ private void connectDownstream() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.github.steveice10.packetlib.packet.Packet;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.FileUtils;
Expand Down Expand Up @@ -89,12 +90,15 @@ public static void init() {
public <P extends T> boolean translate(Class<? extends P> clazz, P packet, GeyserSession session) {
if (!session.getUpstream().isClosed() && !session.isClosed()) {
try {
if (translators.containsKey(clazz)) {
((PacketTranslator<P>) translators.get(clazz)).translate(packet, session);
PacketTranslator<P> translator = (PacketTranslator<P>) translators.get(clazz);
if (translator != null) {
translator.translate(packet, session);
return true;
} else {
if (!IGNORED_PACKETS.contains(clazz))
if ((GeyserConnector.getInstance().getPlatformType() != PlatformType.STANDALONE || !(packet instanceof BedrockPacket)) && !IGNORED_PACKETS.contains(clazz)) {
// Other debug logs already take care of Bedrock packets for us if on standalone
GeyserConnector.getInstance().getLogger().debug("Could not find packet for " + (packet.toString().length() > 25 ? packet.getClass().getSimpleName() : packet));
}
}
} catch (Throwable ex) {
GeyserConnector.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.network.translator.packet.failed", packet.getClass().getSimpleName()), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,25 @@
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ public void translate(PlayerActionPacket packet, GeyserSession session) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,11 +35,10 @@
* 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;
}

/**
Expand Down Expand Up @@ -116,5 +114,4 @@ private static String getTitle(GeyserSession session) {
}
return builder.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static void generateAssetCache() {
ASSET_MAP.put(entry.getKey(), asset);
}
} catch (Exception e) {
GeyserConnector.getInstance().getLogger().info(LanguageUtils.getLocaleStringLog("geyser.locale.fail.asset_cache", (!e.getMessage().isEmpty() ? e.getMessage() : e.getStackTrace())));
GeyserConnector.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.locale.fail.asset_cache", (!e.getMessage().isEmpty() ? e.getMessage() : e.getStackTrace())));
}
}

Expand Down Expand Up @@ -260,7 +260,7 @@ private static void downloadEN_US(File localeFile) {
// Delete the nolonger needed client/server jar
Files.delete(tmpFilePath);
} catch (Exception e) {
throw new AssertionError(LanguageUtils.getLocaleStringLog("geyser.locale.fail.en_us"), e);
GeyserConnector.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.locale.fail.en_us"), e);
}
}

Expand Down
6 changes: 5 additions & 1 deletion connector/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aaeca23

Please sign in to comment.