Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/reuseport' into debug
Browse files Browse the repository at this point in the history
  • Loading branch information
onebeastchris committed Apr 18, 2024
2 parents 38eda27 + 4313be1 commit c5ccaa3
Show file tree
Hide file tree
Showing 34 changed files with 699 additions and 71 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Take a look [here](https://wiki.geysermc.org/geyser/setup/) for how to set up Ge
## What's Left to be Added/Fixed
- Near-perfect movement (to the point where anticheat on large servers is unlikely to ban you)
- Some Entity Flags
- Structure block UI

## What can't be fixed
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://wiki.geysermc.org/geyser/current-limitations/) page.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ dependencies {
}

repositories {
// mavenLocal()
maven("https://repo.opencollab.dev/maven-releases/")
maven("https://repo.opencollab.dev/maven-snapshots/")
maven("https://jitpack.io")
Expand Down
4 changes: 4 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ plugins {
}

dependencies {
constraints {
implementation(libs.raknet) // Ensure protocol does not override the RakNet version
}

api(projects.common)
api(projects.api)

Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class DumpInfo {
private final GeyserConfiguration config;
private final Floodgate floodgate;
private final Object2IntMap<DeviceOs> userPlatforms;
private final int connectionAttempts;
private final HashInfo hashInfo;
private final RamInfo ramInfo;
private LogsInfo logsInfo;
Expand Down Expand Up @@ -129,6 +130,8 @@ public DumpInfo(boolean addLog) {
userPlatforms.put(device, userPlatforms.getOrDefault(device, 0) + 1);
}

this.connectionAttempts = GeyserImpl.getInstance().getGeyserServer().getConnectionAttempts();

this.bootstrapInfo = GeyserImpl.getInstance().getBootstrap().getDumpInfo();

this.flagsInfo = new FlagsInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public enum GeyserAttributeType {
MAX_HEALTH("minecraft:generic.max_health", null, 0f, 1024f, 20f),

// Bedrock Attributes
ABSORPTION(null, "minecraft:absorption", 0f, Float.MAX_VALUE, 0f),
ABSORPTION(null, "minecraft:absorption", 0f, 1024f, 0f),
EXHAUSTION(null, "minecraft:player.exhaustion", 0f, 5f, 0f),
EXPERIENCE(null, "minecraft:player.experience", 0f, 1f, 0f),
EXPERIENCE_LEVEL(null, "minecraft:player.level", 0f, 24791.00f, 0f),
Expand All @@ -66,6 +66,10 @@ public enum GeyserAttributeType {
private final float maximum;
private final float defaultValue;

public AttributeData getAttribute() {
return getAttribute(defaultValue);
}

public AttributeData getAttribute(float value) {
return getAttribute(value, maximum);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,9 @@ public void addAdditionalSpawnData(AddEntityPacket addEntityPacket) {

/**
* Despawns the entity
*
* @return can be deleted
*/
public boolean despawnEntity() {
if (!valid) return true;
public void despawnEntity() {
if (!valid) return;

for (Entity passenger : passengers) { // Make sure all passengers on the despawned entity are updated
if (passenger == null) continue;
Expand All @@ -218,7 +216,6 @@ public boolean despawnEntity() {
session.sendUpstreamPacket(removeEntityPacket);

valid = false;
return true;
}

public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ protected void moveAbsoluteImmediate(Vector3f position, float yaw, float pitch,

@Override
public void tick() {
if (removedInVoid()) {
return;
}
moveAbsoluteImmediate(tickMovement(position), getYaw(), getPitch(), getHeadYaw(), false, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ private void sendSplashSound(GeyserSession session) {

@Override
public void tick() {
if (removedInVoid()) {
return;
}
if (hooked || !isInAir() && !isInWater() || isOnGround()) {
motion = Vector3f.ZERO;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void spawnEntity() {

@Override
public void tick() {
if (isInWater()) {
if (removedInVoid() || isInWater()) {
return;
}
if (!isOnGround() || (motion.getX() * motion.getX() + motion.getZ() * motion.getZ()) > 0.00001) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void setItemRotation(IntEntityMetadata entityMetadata) {
}

@Override
public boolean despawnEntity() {
public void despawnEntity() {
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(bedrockPosition);
Expand All @@ -161,7 +161,6 @@ public boolean despawnEntity() {
session.getItemFrameCache().remove(bedrockPosition, this);

valid = false;
return true;
}

private NbtMap getDefaultTag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public ThrowableEntity(GeyserSession session, int entityId, long geyserId, UUID
*/
@Override
public void tick() {
if (removedInVoid()) {
return;
}
moveAbsoluteImmediate(position.add(motion), getYaw(), getPitch(), getHeadYaw(), isOnGround(), false);
float drag = getDrag();
float gravity = getGravity();
Expand Down Expand Up @@ -170,14 +173,14 @@ protected boolean isInWater() {
}

@Override
public boolean despawnEntity() {
public void despawnEntity() {
if (definition.entityType() == EntityType.ENDER_PEARL) {
LevelEventPacket particlePacket = new LevelEventPacket();
particlePacket.setType(LevelEvent.PARTICLE_TELEPORT);
particlePacket.setPosition(position);
session.sendUpstreamPacket(particlePacket);
}
return super.despawnEntity();
super.despawnEntity();
}

@Override
Expand All @@ -191,4 +194,17 @@ public void moveAbsolute(Vector3f position, float yaw, float pitch, float headYa
moveAbsoluteImmediate(position, yaw, pitch, headYaw, isOnGround, teleported);
lastJavaPosition = position;
}

/**
* Removes the entity if it is 64 blocks below the world.
*
* @return true if the entity was removed
*/
public boolean removedInVoid() {
if (position.getY() < session.getDimensionType().minY() - 64) {
session.getEntityCache().removeEntity(this);
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ public void spawnEntity() {
}

@Override
public boolean despawnEntity() {
public void despawnEntity() {
if (secondEntity != null) {
secondEntity.despawnEntity();
}
return super.despawnEntity();
super.despawnEntity();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ public void addAdditionalSpawnData(AddEntityPacket addEntityPacket) {
}

@Override
public boolean despawnEntity() {
public void despawnEntity() {
for (EnderDragonPartEntity part : allParts) {
part.despawnEntity();
}
return super.despawnEntity();
super.despawnEntity();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.cloudburstmc.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity;
import org.geysermc.geyser.entity.EntityDefinitions;
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.LivingEntity;
import org.geysermc.geyser.entity.type.living.animal.tameable.ParrotEntity;
Expand Down Expand Up @@ -283,7 +284,7 @@ public void setAbsorptionHearts(FloatEntityMetadata entityMetadata) {
attributesPacket.setRuntimeEntityId(geyserId);
// Setting to a higher maximum since plugins/datapacks can probably extend the Bedrock soft limit
attributesPacket.setAttributes(Collections.singletonList(
new AttributeData("minecraft:absorption", 0.0f, 1024f, entityMetadata.getPrimitiveValue(), 0.0f)));
GeyserAttributeType.ABSORPTION.getAttribute(entityMetadata.getPrimitiveValue())));
session.sendUpstreamPacket(attributesPacket);
}

Expand All @@ -307,7 +308,7 @@ public void setRightParrot(EntityMetadata<CompoundTag, ?> entityMetadata) {
* Sets the parrot occupying the shoulder. Bedrock Edition requires a full entity whereas Java Edition just
* spawns it from the NBT data provided
*/
private void setParrot(CompoundTag tag, boolean isLeft) {
protected void setParrot(CompoundTag tag, boolean isLeft) {
if (tag != null && !tag.isEmpty()) {
if ((isLeft && leftParrot != null) || (!isLeft && rightParrot != null)) {
// No need to update a parrot's data when it already exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import lombok.Getter;
Expand Down Expand Up @@ -255,13 +256,51 @@ public UUID getTabListUuid() {
return session.getAuthData().uuid();
}

@Override
public void setAbsorptionHearts(FloatEntityMetadata entityMetadata) {
// The bedrock client can glitch when sending a health and absorption attribute in the same tick
// This can happen when switching servers. Resending the absorption attribute fixes the issue
attributes.put(GeyserAttributeType.ABSORPTION, GeyserAttributeType.ABSORPTION.getAttribute(entityMetadata.getPrimitiveValue()));
super.setAbsorptionHearts(entityMetadata);
}

public void resetMetadata() {
// Reset all metadata to their default values
// This is used when a player respawns
this.flags.clear();
this.initializeMetadata();

// Reset air
this.resetAir();

// Explicitly reset all metadata not handled by initializeMetadata
setParrot(null, true);
setParrot(null, false);

// Absorption is metadata in java edition
attributes.remove(GeyserAttributeType.ABSORPTION);
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
attributesPacket.setRuntimeEntityId(geyserId);
attributesPacket.setAttributes(Collections.singletonList(
GeyserAttributeType.ABSORPTION.getAttribute(0f)));
session.sendUpstreamPacket(attributesPacket);

dirtyMetadata.put(EntityDataTypes.EFFECT_COLOR, 0);
dirtyMetadata.put(EntityDataTypes.EFFECT_AMBIENCE, (byte) 0);
dirtyMetadata.put(EntityDataTypes.FREEZING_EFFECT_STRENGTH, 0f);

silent = false;
}

public void resetAttributes() {
attributes.clear();
maxHealth = GeyserAttributeType.MAX_HEALTH.getDefaultValue();

UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
attributesPacket.setRuntimeEntityId(geyserId);
attributesPacket.setAttributes(Collections.singletonList(
GeyserAttributeType.MOVEMENT_SPEED.getAttribute()));
session.sendUpstreamPacket(attributesPacket);
}

public void resetAir() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
import java.util.function.IntFunction;
import java.util.function.Supplier;

import static org.cloudburstmc.netty.channel.raknet.RakConstants.*;
import static org.cloudburstmc.netty.channel.raknet.RakConstants.DEFAULT_GLOBAL_PACKET_LIMIT;
import static org.cloudburstmc.netty.channel.raknet.RakConstants.DEFAULT_PACKET_LIMIT;

public final class GeyserServer {
private static final boolean PRINT_DEBUG_PINGS = Boolean.parseBoolean(System.getProperty("Geyser.PrintPingsInDebugMode", "true"));
Expand Down Expand Up @@ -111,6 +112,10 @@ public final class GeyserServer {

private ChannelFuture[] bootstrapFutures;

// Keep track of connection attempts for dump info
@Getter
private int connectionAttempts = 0;

/**
* The port to broadcast in the pong. This can be different from the port the server is bound to, e.g. due to port forwarding.
*/
Expand Down Expand Up @@ -220,11 +225,6 @@ private ServerBootstrap createBootstrap() {
int rakPacketLimit = positivePropOrDefault("Geyser.RakPacketLimit", DEFAULT_PACKET_LIMIT);
this.geyser.getLogger().debug("Setting RakNet packet limit to " + rakPacketLimit);

boolean isWhitelistedProxyProtocol = this.geyser.getConfig().getBedrock().isEnableProxyProtocol()
&& !this.geyser.getConfig().getBedrock().getProxyProtocolWhitelistedIPs().isEmpty();
int rakOfflinePacketLimit = positivePropOrDefault("Geyser.RakOfflinePacketLimit", isWhitelistedProxyProtocol ? Integer.MAX_VALUE : DEFAULT_OFFLINE_PACKET_LIMIT);
this.geyser.getLogger().debug("Setting RakNet offline packet limit to " + rakOfflinePacketLimit);

int rakGlobalPacketLimit = positivePropOrDefault("Geyser.RakGlobalPacketLimit", DEFAULT_GLOBAL_PACKET_LIMIT);
this.geyser.getLogger().debug("Setting RakNet global packet limit to " + rakGlobalPacketLimit);

Expand All @@ -234,8 +234,8 @@ private ServerBootstrap createBootstrap() {
.option(RakChannelOption.RAK_HANDLE_PING, true)
.option(RakChannelOption.RAK_MAX_MTU, this.geyser.getConfig().getMtu())
.option(RakChannelOption.RAK_PACKET_LIMIT, rakPacketLimit)
.option(RakChannelOption.RAK_OFFLINE_PACKET_LIMIT, rakOfflinePacketLimit)
.option(RakChannelOption.RAK_GLOBAL_PACKET_LIMIT, rakGlobalPacketLimit)
.option(RakChannelOption.RAK_SEND_COOKIE, true)
.childHandler(serverInitializer);
}

Expand All @@ -251,6 +251,7 @@ public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
}

if (!isWhitelistedIP) {
connectionAttempts++;
return false;
}
}
Expand All @@ -273,10 +274,12 @@ public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
geyser.eventBus().fire(requestEvent);
if (requestEvent.isCancelled()) {
geyser.getLogger().debug("Connection request from " + ip + " was cancelled using the API!");
connectionAttempts++;
return false;
}

geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.network.attempt_connect", ip));
geyser.getLogger().debug(GeyserLocale.getLocaleStringLog("geyser.network.attempt_connect", ip));
connectionAttempts++;
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static void registerBedrockBlocks() {
builder.remove("version"); // Remove all nbt tags which are not needed for differentiating states
builder.remove("name_hash"); // Quick workaround - was added in 1.19.20
builder.remove("network_id"); // Added in 1.19.80 - ????
builder.remove("block_id"); // Added in 1.20.60 //TODO verify this can be just removed
builder.remove("block_id"); // Added in 1.20.60
//noinspection UnstableApiUsage
builder.putCompound("states", statesInterner.intern((NbtMap) builder.remove("states")));
vanillaBlockStates.set(i, builder.build());
Expand Down Expand Up @@ -229,6 +229,7 @@ private static void registerBedrockBlocks() {
Map<NbtMap, BlockDefinition> itemFrames = new Object2ObjectOpenHashMap<>();

Set<BlockDefinition> jigsawDefinitions = new ObjectOpenHashSet<>();
Map<String, BlockDefinition> structureBlockDefinitions = new Object2ObjectOpenHashMap<>();

BlockMappings.BlockMappingsBuilder builder = BlockMappings.builder();
while (blocksIterator.hasNext()) {
Expand Down Expand Up @@ -272,6 +273,18 @@ private static void registerBedrockBlocks() {
jigsawDefinitions.add(bedrockDefinition);
}

if (javaId.contains("structure_block")) {
int modeIndex = javaId.indexOf("mode=");
if (modeIndex != -1) {
int startIndex = modeIndex + 5; // Length of "mode=" is 5
int endIndex = javaId.indexOf("]", startIndex);
if (endIndex != -1) {
String modeValue = javaId.substring(startIndex, endIndex);
structureBlockDefinitions.put(modeValue.toUpperCase(), bedrockDefinition);
}
}
}

boolean waterlogged = entry.getKey().contains("waterlogged=true")
|| javaId.contains("minecraft:bubble_column") || javaId.contains("minecraft:kelp") || javaId.contains("seagrass");

Expand Down Expand Up @@ -358,6 +371,7 @@ private static void registerBedrockBlocks() {
.itemFrames(itemFrames)
.flowerPotBlocks(flowerPotBlocks)
.jigsawStates(jigsawDefinitions)
.structureBlockStates(structureBlockDefinitions)
.remappedVanillaIds(remappedVanillaIds)
.blockProperties(customBlockProperties)
.customBlockStateDefinitions(customBlockStateDefinitions)
Expand Down
Loading

0 comments on commit c5ccaa3

Please sign in to comment.