Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +01:00
Add position checker to prevent false movements
Sometimes this caused bugs on servers and made anticheats go wild. This should resolve most of the movement issues regarding that.
Dieser Commit ist enthalten in:
Ursprung
ef7800a739
Commit
fac7093bff
@ -33,6 +33,7 @@ import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||
import com.nukkitx.protocol.bedrock.data.EntityFlags;
|
||||
import com.nukkitx.protocol.bedrock.packet.AddEntityPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -136,7 +137,6 @@ public class Entity {
|
||||
this.movePending = true;
|
||||
}
|
||||
|
||||
|
||||
public EntityDataDictionary getMetadata() {
|
||||
EntityFlags flags = new EntityFlags();
|
||||
flags.setFlag(EntityFlag.HAS_GRAVITY, true);
|
||||
@ -169,6 +169,11 @@ public class Entity {
|
||||
updateAttributesPacket.setRuntimeEntityId(geyserId);
|
||||
updateAttributesPacket.setAttributes(attributes);
|
||||
session.getUpstream().sendPacket(updateAttributesPacket);
|
||||
|
||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||
entityDataPacket.setRuntimeEntityId(geyserId);
|
||||
entityDataPacket.getMetadata().putAll(getMetadata());
|
||||
session.getUpstream().sendPacket(entityDataPacket);
|
||||
}
|
||||
|
||||
// To be used at a later date
|
||||
|
@ -79,7 +79,8 @@ public enum EntityType {
|
||||
AGENT(56, 0f),
|
||||
VINDICATOR(57, 1.8f, 0.6f, 0.6f, 1.62f),
|
||||
PILLAGER(114, 1.8f, 0.6f, 0.6f, 1.62f),
|
||||
WANDERING_VILLAGER(118, 1.8f, 0.6f, 0.6f, 1.62f),
|
||||
WANDERING_TRADER(118, 1.8f, 0.6f, 0.6f, 1.62f),
|
||||
PHANTOM(58, 0.5f, 0.9f, 0.9f, 0.6f),
|
||||
RAVAGER(59, 1.9f, 1.2f),
|
||||
|
||||
ARMOR_STAND(61, 0f),
|
||||
|
@ -25,9 +25,11 @@
|
||||
|
||||
package org.geysermc.connector.network.translators.bedrock;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3f;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
@ -42,6 +44,15 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
if (!session.isLoggedIn())
|
||||
return;
|
||||
|
||||
if (!isValidMove(session, packet.getMode(), entity.getPosition(), packet.getPosition())) {
|
||||
session.getConnector().getLogger().info("Recalculating position...");
|
||||
recalculatePosition(session, entity, entity.getPosition());
|
||||
return;
|
||||
}
|
||||
|
||||
ClientPlayerPositionRotationPacket playerPositionRotationPacket = new ClientPlayerPositionRotationPacket(
|
||||
packet.isOnGround(), packet.getPosition().getX(), Math.ceil((packet.getPosition().getY() - EntityType.PLAYER.getOffset()) * 2) / 2,
|
||||
packet.getPosition().getZ(), packet.getRotation().getY(), packet.getRotation().getX());
|
||||
@ -59,4 +70,46 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
||||
if (!colliding)
|
||||
session.getDownstream().getSession().send(playerPositionRotationPacket);
|
||||
}
|
||||
|
||||
public boolean isValidMove(GeyserSession session, MovePlayerPacket.Mode mode, Vector3f currentPosition, Vector3f newPosition) {
|
||||
if (mode != MovePlayerPacket.Mode.NORMAL)
|
||||
return true;
|
||||
|
||||
double xRange = newPosition.getX() - currentPosition.getX();
|
||||
double yRange = newPosition.getY() - currentPosition.getY();
|
||||
double zRange = newPosition.getZ() - currentPosition.getZ();
|
||||
|
||||
if (xRange < 0)
|
||||
xRange = -xRange;
|
||||
if (yRange < 0)
|
||||
yRange = -yRange;
|
||||
if (zRange < 0)
|
||||
zRange = -zRange;
|
||||
|
||||
if (xRange > 10 || yRange > 10 || zRange > 10) {
|
||||
session.getConnector().getLogger().warning(session.getName() + " moved too quickly." +
|
||||
" current position: " + currentPosition + ", new position: " + newPosition);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void recalculatePosition(GeyserSession session, Entity entity, Vector3f currentPosition) {
|
||||
// Gravity might need to be reset...
|
||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
entityDataPacket.getMetadata().putAll(entity.getMetadata());
|
||||
session.getUpstream().sendPacket(entityDataPacket);
|
||||
|
||||
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
movePlayerPacket.setPosition(entity.getPosition());
|
||||
movePlayerPacket.setRotation(entity.getRotation());
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
|
||||
movePlayerPacket.setOnGround(true);
|
||||
entity.setMovePending(false);
|
||||
session.getUpstream().sendPacket(movePlayerPacket);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,13 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
||||
import org.geysermc.connector.console.GeyserLogger;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.network.translators.TranslatorsInit;
|
||||
@ -43,11 +49,6 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
||||
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
||||
session.getUpstream().sendPacketImmediately(bedrockPacket);
|
||||
|
||||
int gamemode = packet.getGameMode().ordinal();
|
||||
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
||||
playerGameTypePacket.setGamemode(gamemode);
|
||||
session.getUpstream().sendPacket(playerGameTypePacket);
|
||||
|
||||
Vector3f pos = new Vector3f(0, 0, 0);
|
||||
int chunkX = pos.getFloorX() >> 4;
|
||||
int chunkZ = pos.getFloorZ() >> 4;
|
||||
@ -64,6 +65,25 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
||||
}
|
||||
}
|
||||
|
||||
session.getJavaPacketCache().getCachedValues().put("java_join_packet", packet);
|
||||
PlayStatusPacket playStatus = new PlayStatusPacket();
|
||||
playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
|
||||
session.getUpstream().sendPacketImmediately(playStatus);
|
||||
|
||||
Entity entity = session.getPlayerEntity();
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
session.getPlayerEntity().setEntityId(packet.getEntityId());
|
||||
|
||||
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
||||
playerGameTypePacket.setGamemode(packet.getGameMode().ordinal());
|
||||
session.getUpstream().sendPacket(playerGameTypePacket);
|
||||
|
||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
entityDataPacket.getMetadata().putAll(entity.getMetadata());
|
||||
session.getUpstream().sendPacket(entityDataPacket);
|
||||
|
||||
// session.setSpawned(true);
|
||||
}
|
||||
}
|
||||
|
@ -27,12 +27,9 @@ package org.geysermc.connector.network.translators.java.entity.player;
|
||||
|
||||
import com.flowpowered.math.vector.Vector3f;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
||||
import org.geysermc.connector.console.GeyserLogger;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
@ -51,30 +48,18 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
||||
return;
|
||||
|
||||
if (!session.isSpawned()) {
|
||||
ServerJoinGamePacket javaJoinPacket = (ServerJoinGamePacket) session.getJavaPacketCache().getCachedValues().remove("java_join_packet");
|
||||
|
||||
PlayStatusPacket playStatus = new PlayStatusPacket();
|
||||
playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
|
||||
session.getUpstream().sendPacketImmediately(playStatus);
|
||||
|
||||
entity.moveAbsolute(new Vector3f(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ()), packet.getPitch(), packet.getYaw());
|
||||
|
||||
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
||||
playerGameTypePacket.setGamemode(javaJoinPacket.getGameMode().ordinal());
|
||||
session.getUpstream().sendPacket(playerGameTypePacket);
|
||||
|
||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
entityDataPacket.getMetadata().putAll(entity.getMetadata());
|
||||
|
||||
session.getUpstream().sendPacket(entityDataPacket);
|
||||
session.getPlayerEntity().setEntityId(javaJoinPacket.getEntityId());
|
||||
|
||||
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
movePlayerPacket.setPosition(new Vector3f(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ()));
|
||||
movePlayerPacket.setRotation(new Vector3f(packet.getPitch(), packet.getYaw(), 0));
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
|
||||
movePlayerPacket.setOnGround(true);
|
||||
entity.setMovePending(false);
|
||||
|
||||
@ -82,6 +67,7 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
||||
session.setSpawned(true);
|
||||
|
||||
GeyserLogger.DEFAULT.info("Spawned player at " + packet.getX() + " " + packet.getY() + " " + packet.getZ());
|
||||
return;
|
||||
}
|
||||
|
||||
entity.moveAbsolute(new Vector3f(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ()), packet.getPitch(), packet.getYaw());
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren