Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into floodgate-2.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	connector/src/main/java/org/geysermc/connector/GeyserConnector.java
#	connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java
  • Loading branch information
Tim203 committed May 26, 2021
2 parents cfa2805 + 4734ce2 commit 776fc4e
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 85 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ Take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set
- Structure block UI

## What can't be fixed
The following things cannot be fixed without changes to Bedrock. As of now, they are not fixable in Geyser.

- Custom heads in inventories
- Clickable links in chat
- Glowing effect

Do note that some things require the [GeyserOptionalPack](https://github.com/GeyserMC/Geyser/wiki/GeyserOptionalPack) in order to function, such as custom armor stand poses.
There are a few things Geyser is unable to support due to various differences between Minecraft Bedrock and Java. For a list of these limitations, see the [Current Limitations](https://github.com/GeyserMC/Geyser/wiki/Current-Limitations) page.

## Compiling
1. Clone the repo to your computer
Expand Down
17 changes: 14 additions & 3 deletions bootstrap/bungeecord/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.16-R0.4-SNAPSHOT</version>
<version>1.16-R0.5-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -66,8 +66,10 @@
<shadedPattern>org.geysermc.platform.bungeecord.shaded.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>org.geysermc.platform.bungeecord.shaded.netty</shadedPattern>
<!-- This is not used because relocating breaks natives, but we must include it
or else we get ClassDefNotFound -->
<pattern>io.netty.channel.kqueue</pattern>
<shadedPattern>org.geysermc.platform.bungeecord.shaded.io.netty.channel.kqueue</shadedPattern>
</relocation>
<relocation>
<pattern>org.reflections</pattern>
Expand Down Expand Up @@ -98,6 +100,15 @@
<excludes>
<exclude>com.google.code.gson:*</exclude>
<exclude>org.yaml:*</exclude>
<exclude>io.netty:netty-transport-native-epoll:*</exclude>
<exclude>io.netty:netty-transport-native-unix-common:*</exclude>
<exclude>io.netty:netty-handler:*</exclude>
<exclude>io.netty:netty-common:*</exclude>
<exclude>io.netty:netty-buffer:*</exclude>
<exclude>io.netty:netty-resolver:*</exclude>
<exclude>io.netty:netty-transport:*</exclude>
<exclude>io.netty:netty-codec:*</exclude>
<exclude>io.netty:netty-resolver-dns:*</exclude>
</excludes>
</artifactSet>
</configuration>
Expand Down
18 changes: 14 additions & 4 deletions bootstrap/spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@
</goals>
<configuration>
<relocations>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>org.geysermc.platform.spigot.shaded.netty</shadedPattern>
</relocation>
<relocation>
<pattern>it.unimi.dsi.fastutil</pattern>
<shadedPattern>org.geysermc.platform.spigot.shaded.fastutil</shadedPattern>
Expand Down Expand Up @@ -109,6 +105,20 @@
<excludes>
<exclude>com.google.code.gson:*</exclude>
<exclude>org.yaml:*</exclude>
<!-- We cannot shade Netty, or else native libraries will not load -->
<!-- Needed because older Spigot builds do not provide the haproxy module -->
<exclude>io.netty:netty-transport-native-epoll:*</exclude>
<exclude>io.netty:netty-transport-native-unix-common:*</exclude>
<exclude>io.netty:netty-transport-native-kqueue:*</exclude>
<exclude>io.netty:netty-handler:*</exclude>
<exclude>io.netty:netty-common:*</exclude>
<exclude>io.netty:netty-buffer:*</exclude>
<exclude>io.netty:netty-resolver:*</exclude>
<exclude>io.netty:netty-transport:*</exclude>
<exclude>io.netty:netty-codec:*</exclude>
<exclude>io.netty:netty-codec-dns:*</exclude>
<exclude>io.netty:netty-resolver-dns:*</exclude>
<exclude>io.netty:netty-resolver-dns-native-macos:*</exclude>
</excludes>
</artifactSet>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ public void onEnable() {
ex.printStackTrace();
}

try {
// Required for the Cloudburst Network dependency to initialize.
Class.forName("io.netty.channel.kqueue.KQueue");
} catch (ClassNotFoundException e) {
// While we could support these older versions, the downside is not having KQueue working at all
// And since there are alternative ways to get Geyser working for these aging platforms, it's not worth it.
getLogger().severe("*********************************************");
getLogger().severe("");
getLogger().severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.unsupported_server.header"));
getLogger().severe(LanguageUtils.getLocaleStringLog("geyser.bootstrap.unsupported_server.message", "1.12.2"));
getLogger().severe("");
getLogger().severe("*********************************************");

Bukkit.getPluginManager().disablePlugin(this);
return;
}

// By default this should be localhost but may need to be changed in some circumstances
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
geyserConfig.setAutoconfiguredRemote(true);
Expand Down
1 change: 1 addition & 0 deletions bootstrap/velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<exclude>io.netty:netty-resolver:*</exclude>
<exclude>io.netty:netty-transport:*</exclude>
<exclude>io.netty:netty-codec:*</exclude>
<exclude>io.netty:netty-codec-haproxy:*</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.ow2.asm:*</exclude>
<!-- Exclude all Kyori dependencies except the legacy NBT serializer -->
Expand Down
4 changes: 2 additions & 2 deletions connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<dependency>
<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>26201a4</version>
<version>8c204eb</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand All @@ -153,7 +153,7 @@
<dependency>
<groupId>com.github.GeyserMC</groupId>
<artifactId>PacketLib</artifactId>
<version>b77a427</version>
<version>6e5dea9</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- Move this exclusion back to MCProtocolLib it gets the latest PacketLib -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import com.nukkitx.network.raknet.RakNetConstants;
import com.nukkitx.network.util.EventLoops;
import com.nukkitx.protocol.bedrock.BedrockServer;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.kqueue.KQueue;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.common.PlatformType;
Expand Down Expand Up @@ -211,7 +213,7 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
}
}

CooldownUtils.setShowCooldown(config.getShowCooldown());
CooldownUtils.setDefaultShowCooldown(config.getShowCooldown());
DimensionUtils.changeBedrockNetherId(config.isAboveBedrockNetherBuilding()); // Apply End dimension ID workaround to Nether
SkullBlockEntityTranslator.ALLOW_CUSTOM_SKULLS = config.isAllowCustomSkulls();

Expand All @@ -226,6 +228,19 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
EventLoops.commonGroup(),
enableProxyProtocol
);

if (config.isDebugMode()) {
logger.debug("EventLoop type: " + EventLoops.getChannelType());
if (EventLoops.getChannelType() == EventLoops.ChannelType.NIO) {
if (System.getProperties().contains("disableNativeEventLoop")) {
logger.debug("EventLoop type is NIO because native event loops are disabled.");
} else {
logger.debug("Reason for no Epoll: " + Epoll.unavailabilityCause().toString());
logger.debug("Reason for no KQueue: " + KQueue.unavailabilityCause().toString());
}
}
}

bedrockServer.setHandler(new ConnectorServerEventHandler(this));
bedrockServer.bind().whenComplete((avoid, throwable) -> {
if (throwable == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@
import com.github.steveice10.mc.protocol.packet.login.client.LoginPluginResponsePacket;
import com.github.steveice10.mc.protocol.packet.login.server.LoginSuccessPacket;
import com.github.steveice10.packetlib.BuiltinFlags;
import com.github.steveice10.packetlib.Client;
import com.github.steveice10.packetlib.event.session.*;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
import com.github.steveice10.packetlib.tcp.TcpClientSession;
import com.nukkitx.math.GenericMath;
import com.nukkitx.math.vector.*;
import com.nukkitx.protocol.bedrock.BedrockPacket;
Expand Down Expand Up @@ -115,7 +114,7 @@ public class GeyserSession implements CommandSender {

private final GeyserConnector connector;
private final UpstreamSession upstream;
private Client downstream;
private TcpClientSession downstream;
@Setter
private AuthData authData;
@Setter
Expand All @@ -141,6 +140,7 @@ public class GeyserSession implements CommandSender {
private ChunkCache chunkCache;
private EntityCache entityCache;
private EntityEffectCache effectCache;
private final PreferencesCache preferencesCache;
private final TagCache tagCache;
private WorldCache worldCache;
private FormCache formCache;
Expand Down Expand Up @@ -445,6 +445,7 @@ public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServ
this.chunkCache = new ChunkCache(this);
this.entityCache = new EntityCache(this);
this.effectCache = new EntityEffectCache();
this.preferencesCache = new PreferencesCache(this);
this.tagCache = new TagCache();
this.worldCache = new WorldCache(this);
this.formCache = new FormCache(this);
Expand Down Expand Up @@ -578,7 +579,7 @@ public void authenticate(String username, String password) {
authenticationService.setPassword(password);
authenticationService.login();

protocol = new MinecraftProtocol(authenticationService);
protocol = new MinecraftProtocol(authenticationService.getSelectedProfile(), authenticationService.getAccessToken());
} else {
protocol = new MinecraftProtocol(username);
}
Expand Down Expand Up @@ -636,7 +637,7 @@ private void attemptCodeAuthentication(MsaAuthenticationService msaAuthenticatio
}
try {
msaAuthenticationService.login();
protocol = new MinecraftProtocol(msaAuthenticationService);
protocol = new MinecraftProtocol(msaAuthenticationService.getSelectedProfile(), msaAuthenticationService.getAccessToken());

connectDownstream();
} catch (RequestException e) {
Expand All @@ -658,17 +659,17 @@ private void connectDownstream() {
// Start ticking
tickThread = connector.getGeneralThreadPool().scheduleAtFixedRate(this::tick, 50, 50, TimeUnit.MILLISECONDS);

downstream = new Client(this.remoteAddress, this.remotePort, protocol, new TcpSessionFactory());
downstream = new TcpClientSession(this.remoteAddress, this.remotePort, protocol);
disableSrvResolving();
if (connector.getConfig().getRemote().isUseProxyProtocol()) {
downstream.getSession().setFlag(BuiltinFlags.ENABLE_CLIENT_PROXY_PROTOCOL, true);
downstream.getSession().setFlag(BuiltinFlags.CLIENT_PROXIED_ADDRESS, upstream.getAddress());
downstream.setFlag(BuiltinFlags.ENABLE_CLIENT_PROXY_PROTOCOL, true);
downstream.setFlag(BuiltinFlags.CLIENT_PROXIED_ADDRESS, upstream.getAddress());
}
if (connector.getConfig().isForwardPlayerPing()) {
// Let Geyser handle sending the keep alive
downstream.getSession().setFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, false);
downstream.setFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, false);
}
downstream.getSession().addListener(new SessionAdapter() {
downstream.addListener(new SessionAdapter() {
@Override
public void packetSending(PacketSendingEvent event) {
//todo move this somewhere else
Expand Down Expand Up @@ -805,15 +806,15 @@ public void packetError(PacketErrorEvent event) {
if (!daylightCycle) {
setDaylightCycle(true);
}
downstream.getSession().connect();
downstream.connect();
connector.addPlayer(this);
}

public void disconnect(String reason) {
if (!closed) {
loggedIn = false;
if (downstream != null && downstream.getSession() != null) {
downstream.getSession().disconnect(reason);
if (downstream != null) {
downstream.disconnect(reason);
}
if (upstream != null && !upstream.isClosed()) {
connector.getPlayers().remove(this);
Expand Down Expand Up @@ -941,7 +942,7 @@ public boolean adjustSpeed() {
* Will be overwritten for GeyserConnect.
*/
protected void disableSrvResolving() {
this.downstream.getSession().setFlag(BuiltinFlags.ATTEMPT_SRV_RESOLVE, false);
this.downstream.setFlag(BuiltinFlags.ATTEMPT_SRV_RESOLVE, false);
}

@Override
Expand Down Expand Up @@ -1197,8 +1198,8 @@ public void sendUpstreamPacketImmediately(BedrockPacket packet) {
* @param packet the java edition packet from MCProtocolLib
*/
public void sendDownstreamPacket(Packet packet) {
if (downstream != null && downstream.getSession() != null && (protocol.getSubProtocol().equals(SubProtocol.GAME) || packet.getClass() == LoginPluginResponsePacket.class)) {
downstream.getSession().send(packet);
if (downstream != null && (protocol.getSubProtocol().equals(SubProtocol.GAME) || packet.getClass() == LoginPluginResponsePacket.class)) {
downstream.send(packet);
} else {
connector.getLogger().debug("Tried to send downstream packet " + packet.getClass().getSimpleName() + " before connected to the server");
}
Expand All @@ -1213,7 +1214,7 @@ public void sendDownstreamPacket(Packet packet) {
public void setReducedDebugInfo(boolean value) {
reducedDebugInfo = value;
// Set the showCoordinates data. This is done because updateShowCoordinates() uses this gamerule as a variable.
getWorldCache().updateShowCoordinates();
preferencesCache.updateShowCoordinates();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void checkForSend() {
packet = null;
return;
}
session.getDownstream().getSession().send(packet);
session.sendDownstreamPacket(packet);
packet = null;
lastBookUpdate = System.currentTimeMillis();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2019-2021 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.session.cache;

import lombok.Getter;
import lombok.Setter;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.CooldownUtils;

@Getter
public class PreferencesCache {
private final GeyserSession session;

/**
* True if the client prefers being shown their coordinates, regardless if they're being shown or not.
* This will be true everytime the client joins the server because neither the client nor server store the preference permanently.
*/
@Setter
private boolean prefersShowCoordinates = true;
/**
* If the client's preference will be ignored, this will return false.
*/
private boolean allowShowCoordinates;

/**
* Which CooldownType the client prefers. Initially set to {@link CooldownUtils#getDefaultShowCooldown()}.
*/
@Setter
private CooldownUtils.CooldownType cooldownPreference = CooldownUtils.getDefaultShowCooldown();

public PreferencesCache(GeyserSession session) {
this.session = session;
}

/**
* Tell the client to hide or show the coordinates.
*
* If {@link #prefersShowCoordinates} is true, coordinates will be shown, unless either of the following conditions apply: <br>
* <br>
* {@link GeyserSession#reducedDebugInfo} is enabled
* {@link GeyserConfiguration#isShowCoordinates()} is disabled
*/
public void updateShowCoordinates() {
allowShowCoordinates = !session.isReducedDebugInfo() && session.getConnector().getConfig().isShowCoordinates();
session.sendGameRule("showcoordinates", allowShowCoordinates && prefersShowCoordinates);
}
}
Loading

0 comments on commit 776fc4e

Please sign in to comment.