2021-11-20 21:34:30 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2021-11-20 21:34:30 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.session;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
import com.github.steveice10.mc.auth.data.GameProfile;
|
|
|
|
import com.github.steveice10.mc.auth.exception.request.InvalidCredentialsException;
|
|
|
|
import com.github.steveice10.mc.auth.exception.request.RequestException;
|
|
|
|
import com.github.steveice10.mc.auth.service.AuthenticationService;
|
|
|
|
import com.github.steveice10.mc.auth.service.MojangAuthenticationService;
|
|
|
|
import com.github.steveice10.mc.auth.service.MsaAuthenticationService;
|
|
|
|
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
|
|
|
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
|
|
|
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
|
|
|
import com.github.steveice10.mc.protocol.data.UnexpectedEncryptionException;
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
|
2022-03-15 17:34:56 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
|
2021-11-20 21:34:30 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
2022-03-15 17:34:56 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
2022-01-16 01:29:00 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.HandPreference;
|
2022-03-15 17:34:56 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
2022-01-16 01:29:00 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.setting.ChatVisibility;
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.setting.SkinPart;
|
2021-12-08 01:05:44 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.statistic.CustomStatistic;
|
2021-11-20 21:34:30 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.statistic.Statistic;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket;
|
2022-05-25 19:55:15 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
2022-01-16 01:29:00 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientInformationPacket;
|
2021-11-20 21:34:30 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket;
|
2021-11-23 03:14:41 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerAbilitiesPacket;
|
2022-03-15 17:34:56 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundUseItemPacket;
|
2021-11-20 21:34:30 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.login.serverbound.ServerboundCustomQueryPacket;
|
|
|
|
import com.github.steveice10.packetlib.BuiltinFlags;
|
2021-11-25 04:38:21 +00:00
|
|
|
import com.github.steveice10.packetlib.Session;
|
2023-06-17 01:46:32 +00:00
|
|
|
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
|
|
|
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
|
|
|
import com.github.steveice10.packetlib.event.session.PacketErrorEvent;
|
|
|
|
import com.github.steveice10.packetlib.event.session.PacketSendingEvent;
|
|
|
|
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
2021-11-20 21:34:30 +00:00
|
|
|
import com.github.steveice10.packetlib.packet.Packet;
|
|
|
|
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
|
|
|
import com.github.steveice10.packetlib.tcp.TcpSession;
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
import io.netty.channel.EventLoop;
|
2022-05-15 17:52:18 +00:00
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
2021-11-20 21:34:30 +00:00
|
|
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
|
|
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
2022-06-15 22:32:27 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
2021-11-20 21:34:30 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
|
|
|
import lombok.AccessLevel;
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2022-03-20 02:55:29 +00:00
|
|
|
import lombok.experimental.Accessors;
|
2023-04-15 16:54:30 +00:00
|
|
|
import org.checkerframework.checker.index.qual.NonNegative;
|
2022-05-25 19:55:15 +00:00
|
|
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
2023-04-15 16:54:30 +00:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2022-03-18 22:59:32 +00:00
|
|
|
import org.checkerframework.common.value.qual.IntRange;
|
2022-12-24 00:40:42 +00:00
|
|
|
import org.cloudburstmc.math.vector.*;
|
2022-12-21 00:47:45 +00:00
|
|
|
import org.cloudburstmc.nbt.NbtMap;
|
2023-06-17 01:46:32 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.BedrockDisconnectReasons;
|
2022-10-30 00:23:21 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.BedrockServerSession;
|
2022-12-23 21:18:48 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.data.*;
|
2023-02-14 22:09:48 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.data.command.CommandEnumData;
|
2022-10-30 00:23:21 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.data.command.CommandPermission;
|
2023-02-14 22:09:48 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.data.command.SoftEnumUpdateType;
|
2022-10-30 00:23:21 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
|
|
|
|
import org.cloudburstmc.protocol.bedrock.packet.*;
|
2022-12-24 00:40:42 +00:00
|
|
|
import org.cloudburstmc.protocol.common.DefinitionRegistry;
|
2022-12-23 21:18:48 +00:00
|
|
|
import org.cloudburstmc.protocol.common.util.OptionalBoolean;
|
2022-08-11 23:01:26 +00:00
|
|
|
import org.geysermc.api.util.BedrockPlatform;
|
|
|
|
import org.geysermc.api.util.InputMode;
|
|
|
|
import org.geysermc.api.util.UiProfile;
|
2023-07-02 21:00:46 +00:00
|
|
|
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
|
2023-06-17 01:56:50 +00:00
|
|
|
import org.geysermc.geyser.api.util.PlatformType;
|
2022-01-22 11:20:52 +00:00
|
|
|
import org.geysermc.cumulus.form.Form;
|
2022-05-29 21:39:40 +00:00
|
|
|
import org.geysermc.cumulus.form.util.FormBuilder;
|
2021-11-23 03:14:41 +00:00
|
|
|
import org.geysermc.floodgate.crypto.FloodgateCipher;
|
|
|
|
import org.geysermc.floodgate.util.BedrockData;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.Constants;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.GeyserImpl;
|
2021-11-23 03:14:41 +00:00
|
|
|
import org.geysermc.geyser.api.connection.GeyserConnection;
|
2023-04-15 16:54:30 +00:00
|
|
|
import org.geysermc.geyser.api.entity.type.GeyserEntity;
|
|
|
|
import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity;
|
2023-06-17 01:46:32 +00:00
|
|
|
import org.geysermc.geyser.api.event.bedrock.SessionLoginEvent;
|
2022-06-08 12:09:14 +00:00
|
|
|
import org.geysermc.geyser.api.network.AuthType;
|
2022-03-20 02:55:29 +00:00
|
|
|
import org.geysermc.geyser.api.network.RemoteServer;
|
2022-01-16 21:09:53 +00:00
|
|
|
import org.geysermc.geyser.command.GeyserCommandSource;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.configuration.EmoteOffhandWorkaroundOption;
|
2023-08-01 14:58:59 +00:00
|
|
|
import org.geysermc.geyser.configuration.GeyserConfiguration;
|
2022-07-03 01:17:14 +00:00
|
|
|
import org.geysermc.geyser.entity.EntityDefinitions;
|
2021-11-23 03:14:41 +00:00
|
|
|
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.entity.type.Entity;
|
|
|
|
import org.geysermc.geyser.entity.type.ItemFrameEntity;
|
|
|
|
import org.geysermc.geyser.entity.type.Tickable;
|
|
|
|
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
|
2023-03-30 19:44:55 +00:00
|
|
|
import org.geysermc.geyser.erosion.AbstractGeyserboundPacketHandler;
|
|
|
|
import org.geysermc.geyser.erosion.GeyserboundHandshakePacketHandler;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.inventory.Inventory;
|
|
|
|
import org.geysermc.geyser.inventory.PlayerInventory;
|
2022-02-21 21:11:51 +00:00
|
|
|
import org.geysermc.geyser.inventory.recipe.GeyserRecipe;
|
2022-04-21 01:22:02 +00:00
|
|
|
import org.geysermc.geyser.inventory.recipe.GeyserStonecutterData;
|
2022-12-29 20:10:40 +00:00
|
|
|
import org.geysermc.geyser.item.Items;
|
2022-05-24 23:16:40 +00:00
|
|
|
import org.geysermc.geyser.level.JavaDimension;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.level.WorldManager;
|
2021-11-23 03:14:41 +00:00
|
|
|
import org.geysermc.geyser.level.physics.CollisionManager;
|
2023-05-11 17:23:27 +00:00
|
|
|
import org.geysermc.geyser.network.GameProtocol;
|
2021-11-23 03:14:41 +00:00
|
|
|
import org.geysermc.geyser.network.netty.LocalSession;
|
|
|
|
import org.geysermc.geyser.registry.Registries;
|
|
|
|
import org.geysermc.geyser.registry.type.BlockMappings;
|
|
|
|
import org.geysermc.geyser.registry.type.ItemMappings;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.session.auth.AuthData;
|
|
|
|
import org.geysermc.geyser.session.auth.BedrockClientData;
|
2022-12-08 01:09:48 +00:00
|
|
|
import org.geysermc.geyser.session.cache.*;
|
2021-11-23 03:14:41 +00:00
|
|
|
import org.geysermc.geyser.skin.FloodgateSkinUploader;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.text.GeyserLocale;
|
|
|
|
import org.geysermc.geyser.text.MinecraftLocale;
|
2022-07-24 23:32:22 +00:00
|
|
|
import org.geysermc.geyser.text.TextDecoration;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
|
2021-11-23 03:14:41 +00:00
|
|
|
import org.geysermc.geyser.translator.text.MessageTranslator;
|
2022-06-08 12:09:14 +00:00
|
|
|
import org.geysermc.geyser.util.ChunkUtils;
|
|
|
|
import org.geysermc.geyser.util.DimensionUtils;
|
|
|
|
import org.geysermc.geyser.util.LoginEncryptionUtils;
|
2023-03-30 19:44:55 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
import java.net.ConnectException;
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
2022-05-25 19:55:15 +00:00
|
|
|
import java.time.Instant;
|
2022-12-24 00:40:42 +00:00
|
|
|
import java.util.*;
|
2021-11-20 21:34:30 +00:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2023-08-01 14:58:59 +00:00
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
2021-11-20 21:34:30 +00:00
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
@Getter
|
2022-01-16 21:09:53 +00:00
|
|
|
public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2022-10-30 00:23:21 +00:00
|
|
|
private final GeyserImpl geyser;
|
|
|
|
private final UpstreamSession upstream;
|
|
|
|
private DownstreamSession downstream;
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* The loop where all packets and ticking is processed to prevent concurrency issues.
|
|
|
|
* If this is manually called, ensure that any exceptions are properly handled.
|
|
|
|
*/
|
2022-10-30 00:23:21 +00:00
|
|
|
private final EventLoop eventLoop;
|
2021-11-20 21:34:30 +00:00
|
|
|
@Setter
|
|
|
|
private AuthData authData;
|
|
|
|
@Setter
|
|
|
|
private BedrockClientData clientData;
|
2022-04-21 01:37:50 +00:00
|
|
|
/**
|
|
|
|
* Used for Floodgate skin uploading
|
|
|
|
*/
|
|
|
|
@Setter
|
2023-06-03 09:47:50 +00:00
|
|
|
private List<String> certChainData;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2023-03-30 19:44:55 +00:00
|
|
|
@NotNull
|
|
|
|
@Setter
|
|
|
|
private AbstractGeyserboundPacketHandler erosionHandler;
|
|
|
|
|
2022-03-20 02:55:29 +00:00
|
|
|
@Accessors(fluent = true)
|
2021-11-20 21:34:30 +00:00
|
|
|
@Setter
|
2022-03-20 02:55:29 +00:00
|
|
|
private RemoteServer remoteServer;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
@Setter
|
|
|
|
private boolean microsoftAccount;
|
|
|
|
|
|
|
|
private final SessionPlayerEntity playerEntity;
|
|
|
|
|
|
|
|
private final AdvancementsCache advancementsCache;
|
|
|
|
private final BookEditCache bookEditCache;
|
|
|
|
private final ChunkCache chunkCache;
|
|
|
|
private final EntityCache entityCache;
|
|
|
|
private final EntityEffectCache effectCache;
|
|
|
|
private final FormCache formCache;
|
|
|
|
private final LodestoneCache lodestoneCache;
|
|
|
|
private final PistonCache pistonCache;
|
|
|
|
private final PreferencesCache preferencesCache;
|
2022-05-14 19:12:18 +00:00
|
|
|
private final SkullCache skullCache;
|
2021-11-20 21:34:30 +00:00
|
|
|
private final TagCache tagCache;
|
|
|
|
private final WorldCache worldCache;
|
|
|
|
|
2021-12-18 16:43:57 +00:00
|
|
|
@Setter
|
|
|
|
private TeleportCache unconfirmedTeleport;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
private final WorldBorder worldBorder;
|
|
|
|
/**
|
|
|
|
* Whether simulated fog has been sent to the client or not.
|
|
|
|
*/
|
|
|
|
private boolean isInWorldBorderWarningArea = false;
|
|
|
|
|
|
|
|
private final PlayerInventory playerInventory;
|
|
|
|
@Setter
|
|
|
|
private Inventory openInventory;
|
|
|
|
@Setter
|
|
|
|
private boolean closingInventory;
|
|
|
|
|
|
|
|
@Setter
|
|
|
|
private InventoryTranslator inventoryTranslator = InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use {@link #getNextItemNetId()} instead for consistency
|
|
|
|
*/
|
|
|
|
@Getter(AccessLevel.NONE)
|
|
|
|
private final AtomicInteger itemNetId = new AtomicInteger(2);
|
|
|
|
|
|
|
|
@Setter
|
|
|
|
private ScheduledFuture<?> craftingGridFuture;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores session collision
|
|
|
|
*/
|
|
|
|
private final CollisionManager collisionManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the block mappings for this specific version.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private BlockMappings blockMappings;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the item translations for this specific version.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private ItemMappings itemMappings;
|
|
|
|
|
|
|
|
private final Long2ObjectMap<ClientboundMapItemDataPacket> storedMaps = new Long2ObjectOpenHashMap<>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Required to decode biomes correctly.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private int biomeGlobalPalette;
|
|
|
|
/**
|
|
|
|
* Stores the map between Java and Bedrock biome network IDs.
|
|
|
|
*/
|
2023-04-09 19:11:46 +00:00
|
|
|
@Setter
|
|
|
|
private int[] biomeTranslations = null;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A map of Vector3i positions to Java entities.
|
|
|
|
* Used for translating Bedrock block actions to Java entity actions.
|
|
|
|
*/
|
|
|
|
private final Map<Vector3i, ItemFrameEntity> itemFrameCache = new Object2ObjectOpenHashMap<>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores a list of all lectern locations and their block entity tags.
|
2023-03-30 19:44:55 +00:00
|
|
|
* See {@link WorldManager#sendLecternData(GeyserSession, int, int, int)}
|
2021-11-20 21:34:30 +00:00
|
|
|
* for more information.
|
|
|
|
*/
|
|
|
|
private final Set<Vector3i> lecternCache;
|
|
|
|
|
2021-11-22 19:49:55 +00:00
|
|
|
/**
|
|
|
|
* A list of all players that have a player head on with a custom texture.
|
|
|
|
* Our workaround for these players is to give them a custom skin and geometry to emulate wearing a custom skull.
|
|
|
|
*/
|
|
|
|
private final Set<UUID> playerWithCustomHeads = new ObjectOpenHashSet<>();
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
@Setter
|
|
|
|
private boolean droppingLecternBook;
|
|
|
|
|
|
|
|
@Setter
|
|
|
|
private Vector2i lastChunkPosition = null;
|
2022-01-16 01:29:00 +00:00
|
|
|
@Setter
|
|
|
|
private int clientRenderDistance = -1;
|
|
|
|
private int serverRenderDistance;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2021-11-30 03:04:02 +00:00
|
|
|
// Exposed for GeyserConnect usage
|
|
|
|
protected boolean sentSpawnPacket;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
private boolean loggedIn;
|
|
|
|
private boolean loggingIn;
|
|
|
|
|
|
|
|
@Setter
|
|
|
|
private boolean spawned;
|
|
|
|
/**
|
|
|
|
* Accessed on the initial Java and Bedrock packet processing threads
|
|
|
|
*/
|
|
|
|
private volatile boolean closed;
|
|
|
|
|
|
|
|
@Setter
|
|
|
|
private GameMode gameMode = GameMode.SURVIVAL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keeps track of the world name for respawning.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private String worldName = null;
|
2022-12-13 18:53:28 +00:00
|
|
|
/**
|
|
|
|
* As of Java 1.19.3, the client only uses these for commands.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private String[] levels;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
private boolean sneaking;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the Java pose that the server and/or Geyser believes the player currently has.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private Pose pose = Pose.STANDING;
|
|
|
|
|
|
|
|
@Setter
|
|
|
|
private boolean sprinting;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the player is swimming in water.
|
|
|
|
* Used to update speed when crawling.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean swimmingInWater;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tracks the original speed attribute.
|
|
|
|
*
|
|
|
|
* We need to do this in order to emulate speeds when sneaking under 1.5-blocks-tall areas if the player isn't sneaking,
|
|
|
|
* and when crawling.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private float originalSpeedAttribute;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The dimension of the player.
|
|
|
|
* As all entities are in the same world, this can be safely applied to all other entities.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private String dimension = DimensionUtils.OVERWORLD;
|
2022-05-25 19:55:15 +00:00
|
|
|
@MonotonicNonNull
|
|
|
|
@Setter
|
|
|
|
private JavaDimension dimensionType = null;
|
2021-12-21 03:54:34 +00:00
|
|
|
/**
|
2022-05-24 23:16:40 +00:00
|
|
|
* All dimensions that the client could possibly connect to.
|
2021-12-21 03:54:34 +00:00
|
|
|
*/
|
2022-05-24 23:16:40 +00:00
|
|
|
private final Map<String, JavaDimension> dimensions = new Object2ObjectOpenHashMap<>(3);
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2022-07-24 23:32:22 +00:00
|
|
|
private final Int2ObjectMap<TextDecoration> chatTypes = new Int2ObjectOpenHashMap<>(7);
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
@Setter
|
|
|
|
private int breakingBlock;
|
|
|
|
|
|
|
|
@Setter
|
|
|
|
private Vector3i lastBlockPlacePosition;
|
|
|
|
|
|
|
|
@Setter
|
|
|
|
private String lastBlockPlacedId;
|
|
|
|
|
|
|
|
@Setter
|
|
|
|
private boolean interacting;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the last position of the block the player interacted with. This can either be a block that the client
|
|
|
|
* placed or an existing block the player interacted with (for example, a chest). <br>
|
|
|
|
* Initialized as (0, 0, 0) so it is always not-null.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private Vector3i lastInteractionBlockPosition = Vector3i.ZERO;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the position of the player the last time they interacted.
|
|
|
|
* Used to verify that the player did not move since their last interaction. <br>
|
|
|
|
* Initialized as (0, 0, 0) so it is always not-null.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private Vector3f lastInteractionPlayerPosition = Vector3f.ZERO;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The entity that the client is currently looking at.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private Entity mouseoverEntity;
|
|
|
|
|
|
|
|
@Setter
|
2022-02-21 21:11:51 +00:00
|
|
|
private Int2ObjectMap<GeyserRecipe> craftingRecipes;
|
2021-11-20 21:34:30 +00:00
|
|
|
private final AtomicInteger lastRecipeNetId;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves a list of all stonecutter recipes, for use in a stonecutter inventory.
|
|
|
|
* The key is the Java ID of the item; the values are all the possible outputs' Java IDs sorted by their string identifier
|
|
|
|
*/
|
|
|
|
@Setter
|
2022-04-21 01:22:02 +00:00
|
|
|
private Int2ObjectMap<GeyserStonecutterData> stonecutterRecipes;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2022-02-11 01:14:52 +00:00
|
|
|
/**
|
|
|
|
* Whether to work around 1.13's different behavior in villager trading menus.
|
|
|
|
*/
|
|
|
|
@Setter
|
2022-07-14 01:31:10 +00:00
|
|
|
private boolean emulatePost1_13Logic = true;
|
2022-01-30 16:15:07 +00:00
|
|
|
/**
|
|
|
|
* Starting in 1.17, Java servers expect the <code>carriedItem</code> parameter of the serverbound click container
|
|
|
|
* packet to be the current contents of the mouse after the transaction has been done. 1.16 expects the clicked slot
|
|
|
|
* contents before any transaction is done. With the current ViaVersion structure, if we do not send what 1.16 expects
|
|
|
|
* and send multiple click container packets, then successive transactions will be rejected.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean emulatePost1_16Logic = true;
|
2022-07-10 03:02:19 +00:00
|
|
|
@Setter
|
|
|
|
private boolean emulatePost1_18Logic = true;
|
2022-01-30 16:15:07 +00:00
|
|
|
|
2023-08-17 02:42:17 +00:00
|
|
|
/**
|
|
|
|
* Whether to emulate pre-1.20 smithing table behavior.
|
|
|
|
* Adapts ViaVersion's furnace UI to one Bedrock can use.
|
|
|
|
* See {@link org.geysermc.geyser.translator.inventory.OldSmithingTableTranslator}.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean oldSmithingTable = false;
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* The current attack speed of the player. Used for sending proper cooldown timings.
|
|
|
|
* Setting a default fixes cooldowns not showing up on a fresh world.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private double attackSpeed = 4.0d;
|
|
|
|
/**
|
|
|
|
* The time of the last hit. Used to gauge how long the cooldown is taking.
|
|
|
|
* This is a session variable in order to prevent more scheduled threads than necessary.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private long lastHitTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves if the client is steering left on a boat.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean steeringLeft;
|
|
|
|
/**
|
|
|
|
* Saves if the client is steering right on a boat.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean steeringRight;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store the last time the player interacted. Used to fix a right-click spam bug.
|
|
|
|
* See https://github.com/GeyserMC/Geyser/issues/503 for context.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private long lastInteractionTime;
|
|
|
|
|
|
|
|
/**
|
2022-06-24 20:48:28 +00:00
|
|
|
* Stores whether the player intended to place a bucket.
|
2021-11-20 21:34:30 +00:00
|
|
|
*/
|
|
|
|
@Setter
|
2022-06-24 20:48:28 +00:00
|
|
|
private boolean placedBucket;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to send a movement packet every three seconds if the player hasn't moved. Prevents timeouts when AFK in certain instances.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private long lastMovementTimestamp = System.currentTimeMillis();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to send a ServerboundMoveVehiclePacket for every PlayerInputPacket after idling on a boat/horse for more than 100ms
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private long lastVehicleMoveTimestamp = System.currentTimeMillis();
|
|
|
|
|
2022-03-15 17:34:56 +00:00
|
|
|
/**
|
|
|
|
* Counts how many ticks have occurred since an arm animation started.
|
2023-01-04 00:28:43 +00:00
|
|
|
* -1 means there is no active arm swing; -2 means an arm swing will start in a tick.
|
2022-03-15 17:34:56 +00:00
|
|
|
*/
|
|
|
|
private int armAnimationTicks = -1;
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* Controls whether the daylight cycle gamerule has been sent to the client, so the sun/moon remain motionless.
|
|
|
|
*/
|
|
|
|
private boolean daylightCycle = true;
|
|
|
|
|
|
|
|
private boolean reducedDebugInfo = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The op permission level set by the server
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private int opPermissionLevel = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the current player can fly
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean canFly = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the current player is flying
|
|
|
|
*/
|
|
|
|
private boolean flying = false;
|
|
|
|
|
2022-02-25 03:49:10 +00:00
|
|
|
@Setter
|
|
|
|
private boolean instabuild = false;
|
|
|
|
|
2022-07-10 17:33:39 +00:00
|
|
|
@Setter
|
|
|
|
private float flySpeed;
|
|
|
|
@Setter
|
|
|
|
private float walkSpeed;
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* Caches current rain status.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean raining = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caches current thunder status.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean thunder = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores a map of all statistics sent from the server.
|
|
|
|
* The server only sends new statistics back to us, so in order to show all statistics we need to cache existing ones.
|
|
|
|
*/
|
2022-06-15 22:32:27 +00:00
|
|
|
private final Object2IntMap<Statistic> statistics = new Object2IntOpenHashMap<>(0);
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether we're expecting statistics to be sent back to us.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean waitingForStatistics = false;
|
|
|
|
|
2023-07-02 21:00:46 +00:00
|
|
|
/**
|
|
|
|
* All fog effects that are currently applied to the client.
|
|
|
|
*/
|
|
|
|
private final Set<String> appliedFog = new HashSet<>();
|
2021-12-08 18:23:05 +00:00
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
private final Set<UUID> emotes;
|
|
|
|
|
2021-11-26 16:13:33 +00:00
|
|
|
/**
|
|
|
|
* Whether advanced tooltips will be added to the player's items.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean advancedTooltips = false;
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* The thread that will run every 50 milliseconds - one Minecraft tick.
|
|
|
|
*/
|
|
|
|
private ScheduledFuture<?> tickThread = null;
|
|
|
|
|
2022-06-24 20:48:28 +00:00
|
|
|
/**
|
|
|
|
* Used to return the player to their original rotation after using an item in BedrockInventoryTransactionTranslator
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private ScheduledFuture<?> lookBackScheduledFuture = null;
|
|
|
|
|
2022-12-22 18:19:46 +00:00
|
|
|
/**
|
|
|
|
* Used to return players back to their vehicles if the server doesn't want them unmounting.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private ScheduledFuture<?> mountVehicleScheduledFuture = null;
|
|
|
|
|
2023-08-01 14:58:59 +00:00
|
|
|
/**
|
|
|
|
* A cache of IDs from ClientboundKeepAlivePackets that have been sent to the Bedrock client, but haven't been returned to the server.
|
|
|
|
* Only used if {@link GeyserConfiguration#isForwardPlayerPing()} is enabled.
|
|
|
|
*/
|
|
|
|
private final Queue<Long> keepAliveCache = new ConcurrentLinkedQueue<>();
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
private MinecraftProtocol protocol;
|
|
|
|
|
2021-11-22 19:52:26 +00:00
|
|
|
public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop eventLoop) {
|
2021-11-20 21:34:30 +00:00
|
|
|
this.geyser = geyser;
|
|
|
|
this.upstream = new UpstreamSession(bedrockServerSession);
|
|
|
|
this.eventLoop = eventLoop;
|
|
|
|
|
2023-03-30 19:44:55 +00:00
|
|
|
this.erosionHandler = new GeyserboundHandshakePacketHandler(this);
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
this.advancementsCache = new AdvancementsCache(this);
|
|
|
|
this.bookEditCache = new BookEditCache(this);
|
|
|
|
this.chunkCache = new ChunkCache(this);
|
|
|
|
this.entityCache = new EntityCache(this);
|
|
|
|
this.effectCache = new EntityEffectCache();
|
|
|
|
this.formCache = new FormCache(this);
|
|
|
|
this.lodestoneCache = new LodestoneCache();
|
|
|
|
this.pistonCache = new PistonCache(this);
|
|
|
|
this.preferencesCache = new PreferencesCache(this);
|
2022-05-14 19:12:18 +00:00
|
|
|
this.skullCache = new SkullCache(this);
|
2021-11-20 21:34:30 +00:00
|
|
|
this.tagCache = new TagCache();
|
|
|
|
this.worldCache = new WorldCache(this);
|
|
|
|
|
|
|
|
this.worldBorder = new WorldBorder(this);
|
|
|
|
|
|
|
|
this.collisionManager = new CollisionManager(this);
|
|
|
|
|
|
|
|
this.playerEntity = new SessionPlayerEntity(this);
|
|
|
|
collisionManager.updatePlayerBoundingBox(this.playerEntity.getPosition());
|
|
|
|
|
|
|
|
this.playerInventory = new PlayerInventory();
|
|
|
|
this.openInventory = null;
|
|
|
|
this.craftingRecipes = new Int2ObjectOpenHashMap<>();
|
|
|
|
this.lastRecipeNetId = new AtomicInteger(1);
|
|
|
|
|
|
|
|
this.spawned = false;
|
|
|
|
this.loggedIn = false;
|
|
|
|
|
2023-03-30 19:44:55 +00:00
|
|
|
if (geyser.getWorldManager().shouldExpectLecternHandled(this)) {
|
2021-11-20 21:34:30 +00:00
|
|
|
// Unneeded on these platforms
|
|
|
|
this.lecternCache = null;
|
|
|
|
} else {
|
|
|
|
this.lecternCache = new ObjectOpenHashSet<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (geyser.getConfig().getEmoteOffhandWorkaround() != EmoteOffhandWorkaroundOption.NO_EMOTES) {
|
|
|
|
this.emotes = new HashSet<>();
|
|
|
|
geyser.getSessionManager().getSessions().values().forEach(player -> this.emotes.addAll(player.getEmotes()));
|
|
|
|
} else {
|
|
|
|
this.emotes = null;
|
|
|
|
}
|
|
|
|
|
2022-07-09 22:39:02 +00:00
|
|
|
this.remoteServer = geyser.defaultRemoteServer();
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send all necessary packets to load Bedrock into the server
|
|
|
|
*/
|
|
|
|
public void connect() {
|
|
|
|
startGame();
|
|
|
|
sentSpawnPacket = true;
|
|
|
|
|
|
|
|
// Set the hardcoded shield ID to the ID we just defined in StartGamePacket
|
2022-10-30 00:23:21 +00:00
|
|
|
// upstream.getSession().getHardcodedBlockingId().set(this.itemMappings.getStoredItems().shield().getBedrockId());
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2022-07-02 16:50:16 +00:00
|
|
|
if (GeyserImpl.getInstance().getConfig().isAddNonBedrockItems()) {
|
2021-11-20 21:34:30 +00:00
|
|
|
ItemComponentPacket componentPacket = new ItemComponentPacket();
|
2022-07-02 16:50:16 +00:00
|
|
|
componentPacket.getItems().addAll(itemMappings.getComponentItemData());
|
2021-11-20 21:34:30 +00:00
|
|
|
upstream.sendPacket(componentPacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
|
|
|
|
|
|
|
|
BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket();
|
|
|
|
biomeDefinitionListPacket.setDefinitions(Registries.BIOMES_NBT.get());
|
|
|
|
upstream.sendPacket(biomeDefinitionListPacket);
|
|
|
|
|
2022-05-07 15:11:21 +00:00
|
|
|
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
|
|
|
|
entityPacket.setIdentifiers(Registries.BEDROCK_ENTITY_IDENTIFIERS.get());
|
|
|
|
upstream.sendPacket(entityPacket);
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
CreativeContentPacket creativePacket = new CreativeContentPacket();
|
|
|
|
creativePacket.setContents(this.itemMappings.getCreativeItems());
|
|
|
|
upstream.sendPacket(creativePacket);
|
|
|
|
|
2022-11-18 17:36:18 +00:00
|
|
|
// Potion mixes are registered by default, as they are needed to be able to put ingredients into the brewing stand.
|
|
|
|
CraftingDataPacket craftingDataPacket = new CraftingDataPacket();
|
|
|
|
craftingDataPacket.setCleanRecipes(true);
|
2023-03-17 23:07:31 +00:00
|
|
|
craftingDataPacket.getPotionMixData().addAll(Registries.POTION_MIXES.forVersion(this.upstream.getProtocolVersion()));
|
2022-11-18 17:36:18 +00:00
|
|
|
upstream.sendPacket(craftingDataPacket);
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
|
|
|
|
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
|
|
|
upstream.sendPacket(playStatusPacket);
|
|
|
|
|
|
|
|
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
|
|
|
attributesPacket.setRuntimeEntityId(getPlayerEntity().getGeyserId());
|
|
|
|
// Default move speed
|
|
|
|
// Bedrock clients move very fast by default until they get an attribute packet correcting the speed
|
|
|
|
attributesPacket.setAttributes(Collections.singletonList(
|
|
|
|
new AttributeData("minecraft:movement", 0.0f, 1024f, 0.1f, 0.1f)));
|
|
|
|
upstream.sendPacket(attributesPacket);
|
|
|
|
|
|
|
|
GameRulesChangedPacket gamerulePacket = new GameRulesChangedPacket();
|
|
|
|
// Only allow the server to send health information
|
|
|
|
// Setting this to false allows natural regeneration to work false but doesn't break it being true
|
|
|
|
gamerulePacket.getGameRules().add(new GameRuleData<>("naturalregeneration", false));
|
|
|
|
// Don't let the client modify the inventory on death
|
|
|
|
// Setting this to true allows keep inventory to work if enabled but doesn't break functionality being false
|
|
|
|
gamerulePacket.getGameRules().add(new GameRuleData<>("keepinventory", true));
|
|
|
|
// Ensure client doesn't try and do anything funky; the server handles this for us
|
|
|
|
gamerulePacket.getGameRules().add(new GameRuleData<>("spawnradius", 0));
|
|
|
|
upstream.sendPacket(gamerulePacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void authenticate(String username) {
|
|
|
|
authenticate(username, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void authenticate(String username, String password) {
|
|
|
|
if (loggedIn) {
|
2021-11-20 23:29:46 +00:00
|
|
|
geyser.getLogger().severe(GeyserLocale.getLocaleStringLog("geyser.auth.already_loggedin", username));
|
2021-11-20 21:34:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
loggingIn = true;
|
|
|
|
|
|
|
|
// Use a future to prevent timeouts as all the authentication is handled sync
|
|
|
|
CompletableFuture.supplyAsync(() -> {
|
|
|
|
try {
|
|
|
|
if (password != null && !password.isEmpty()) {
|
|
|
|
AuthenticationService authenticationService;
|
|
|
|
if (microsoftAccount) {
|
|
|
|
authenticationService = new MsaAuthenticationService(GeyserImpl.OAUTH_CLIENT_ID);
|
|
|
|
} else {
|
|
|
|
authenticationService = new MojangAuthenticationService();
|
|
|
|
}
|
|
|
|
authenticationService.setUsername(username);
|
|
|
|
authenticationService.setPassword(password);
|
|
|
|
authenticationService.login();
|
|
|
|
|
|
|
|
GameProfile profile = authenticationService.getSelectedProfile();
|
|
|
|
if (profile == null) {
|
|
|
|
// Java account is offline
|
2021-11-20 23:29:46 +00:00
|
|
|
disconnect(GeyserLocale.getPlayerLocaleString("geyser.network.remote.invalid_account", clientData.getLanguageCode()));
|
2021-11-20 21:34:30 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protocol = new MinecraftProtocol(profile, authenticationService.getAccessToken());
|
|
|
|
} else {
|
|
|
|
// always replace spaces when using Floodgate,
|
|
|
|
// as usernames with spaces cause issues with Bungeecord's login cycle.
|
|
|
|
// However, this doesn't affect the final username as Floodgate is still in charge of that.
|
|
|
|
// So if you have (for example) replace spaces enabled on Floodgate the spaces will re-appear.
|
|
|
|
String validUsername = username;
|
2022-04-24 16:42:17 +00:00
|
|
|
if (this.remoteServer.authType() == AuthType.FLOODGATE) {
|
2021-11-20 21:34:30 +00:00
|
|
|
validUsername = username.replace(' ', '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
protocol = new MinecraftProtocol(validUsername);
|
|
|
|
}
|
|
|
|
} catch (InvalidCredentialsException | IllegalArgumentException e) {
|
2021-11-20 23:29:46 +00:00
|
|
|
geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.auth.login.invalid", username));
|
|
|
|
disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.login.invalid.kick", getClientData().getLanguageCode()));
|
2021-11-20 21:34:30 +00:00
|
|
|
} catch (RequestException ex) {
|
|
|
|
disconnect(ex.getMessage());
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}).whenComplete((aVoid, ex) -> {
|
|
|
|
if (ex != null) {
|
|
|
|
disconnect(ex.toString());
|
|
|
|
}
|
|
|
|
if (this.closed) {
|
|
|
|
if (ex != null) {
|
|
|
|
geyser.getLogger().error("", ex);
|
|
|
|
}
|
|
|
|
// Client disconnected during the authentication attempt
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-22 15:10:04 +00:00
|
|
|
try {
|
|
|
|
connectDownstream();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
2021-11-20 21:34:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-03 23:52:26 +00:00
|
|
|
public void authenticateWithRefreshToken(String refreshToken) {
|
2021-11-20 21:34:30 +00:00
|
|
|
if (loggedIn) {
|
2021-11-21 18:36:42 +00:00
|
|
|
geyser.getLogger().severe(GeyserLocale.getLocaleStringLog("geyser.auth.already_loggedin", getAuthData().name()));
|
2021-11-20 21:34:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
loggingIn = true;
|
|
|
|
|
|
|
|
CompletableFuture.supplyAsync(() -> {
|
2022-03-03 23:52:26 +00:00
|
|
|
MsaAuthenticationService service = new MsaAuthenticationService(GeyserImpl.OAUTH_CLIENT_ID);
|
|
|
|
service.setRefreshToken(refreshToken);
|
2021-11-20 21:34:30 +00:00
|
|
|
try {
|
2022-03-03 23:52:26 +00:00
|
|
|
service.login();
|
2021-11-20 21:34:30 +00:00
|
|
|
} catch (RequestException e) {
|
2022-08-09 18:06:53 +00:00
|
|
|
geyser.getLogger().error("Error while attempting to use refresh token for " + bedrockUsername() + "!", e);
|
2022-03-03 23:52:26 +00:00
|
|
|
return Boolean.FALSE;
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
2022-03-03 23:52:26 +00:00
|
|
|
|
|
|
|
GameProfile profile = service.getSelectedProfile();
|
|
|
|
if (profile == null) {
|
|
|
|
// Java account is offline
|
|
|
|
disconnect(GeyserLocale.getPlayerLocaleString("geyser.network.remote.invalid_account", clientData.getLanguageCode()));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protocol = new MinecraftProtocol(profile, service.getAccessToken());
|
2022-08-09 18:06:53 +00:00
|
|
|
geyser.saveRefreshToken(bedrockUsername(), service.getRefreshToken());
|
2022-03-03 23:52:26 +00:00
|
|
|
return Boolean.TRUE;
|
|
|
|
}).whenComplete((successful, ex) -> {
|
|
|
|
if (this.closed) {
|
2021-11-20 21:34:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-03-03 23:52:26 +00:00
|
|
|
if (successful == Boolean.FALSE) {
|
|
|
|
// The player is waiting for a spawn packet, so let's spawn them in now to show them forms
|
|
|
|
connect();
|
|
|
|
// Will be cached for after login
|
|
|
|
LoginEncryptionUtils.buildAndShowTokenExpiredWindow(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-22 15:10:04 +00:00
|
|
|
try {
|
|
|
|
connectDownstream();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
}
|
2021-11-20 21:34:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-03 23:52:26 +00:00
|
|
|
public void authenticateWithMicrosoftCode() {
|
|
|
|
authenticateWithMicrosoftCode(false);
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* Present a form window to the user asking to log in with another web browser
|
|
|
|
*/
|
2022-03-03 23:52:26 +00:00
|
|
|
public void authenticateWithMicrosoftCode(boolean offlineAccess) {
|
2021-11-20 21:34:30 +00:00
|
|
|
if (loggedIn) {
|
2021-11-21 18:36:42 +00:00
|
|
|
geyser.getLogger().severe(GeyserLocale.getLocaleStringLog("geyser.auth.already_loggedin", getAuthData().name()));
|
2021-11-20 21:34:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
loggingIn = true;
|
|
|
|
|
|
|
|
// This just looks cool
|
|
|
|
SetTimePacket packet = new SetTimePacket();
|
|
|
|
packet.setTime(16000);
|
|
|
|
sendUpstreamPacket(packet);
|
|
|
|
|
2022-02-26 20:45:56 +00:00
|
|
|
final PendingMicrosoftAuthentication.AuthenticationTask task = geyser.getPendingMicrosoftAuthentication().getOrCreateTask(
|
|
|
|
getAuthData().xuid()
|
|
|
|
);
|
|
|
|
task.setOnline(true);
|
|
|
|
task.resetTimer();
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2022-02-26 20:45:56 +00:00
|
|
|
if (task.getAuthentication().isDone()) {
|
|
|
|
onMicrosoftLoginComplete(task);
|
|
|
|
} else {
|
2022-03-03 23:52:26 +00:00
|
|
|
task.getCode(offlineAccess).whenComplete((response, ex) -> {
|
2022-02-26 20:45:56 +00:00
|
|
|
boolean connected = !closed;
|
|
|
|
if (ex != null) {
|
|
|
|
if (connected) {
|
|
|
|
geyser.getLogger().error("Failed to get Microsoft auth code", ex);
|
|
|
|
disconnect(ex.toString());
|
|
|
|
}
|
|
|
|
task.cleanup(); // error getting auth code -> clean up immediately
|
|
|
|
} else if (connected) {
|
|
|
|
LoginEncryptionUtils.buildAndShowMicrosoftCodeWindow(this, response);
|
|
|
|
task.getAuthentication().whenComplete((r, $) -> onMicrosoftLoginComplete(task));
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
2022-02-26 20:45:56 +00:00
|
|
|
});
|
|
|
|
}
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 23:52:26 +00:00
|
|
|
/**
|
|
|
|
* If successful, also begins connecting to the Java server.
|
|
|
|
*/
|
2022-02-26 20:45:56 +00:00
|
|
|
public boolean onMicrosoftLoginComplete(PendingMicrosoftAuthentication.AuthenticationTask task) {
|
|
|
|
if (closed) {
|
|
|
|
return false;
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
2022-02-26 20:45:56 +00:00
|
|
|
task.cleanup(); // player is online -> remove pending authentication immediately
|
|
|
|
Throwable ex = task.getLoginException();
|
|
|
|
if (ex != null) {
|
|
|
|
geyser.getLogger().error("Failed to log in with Microsoft code!", ex);
|
|
|
|
disconnect(ex.toString());
|
|
|
|
} else {
|
2022-03-03 23:52:26 +00:00
|
|
|
MsaAuthenticationService service = task.getMsaAuthenticationService();
|
|
|
|
GameProfile selectedProfile = service.getSelectedProfile();
|
2022-02-26 20:45:56 +00:00
|
|
|
if (selectedProfile == null) {
|
|
|
|
disconnect(GeyserLocale.getPlayerLocaleString(
|
|
|
|
"geyser.network.remote.invalid_account",
|
|
|
|
clientData.getLanguageCode()
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
this.protocol = new MinecraftProtocol(
|
|
|
|
selectedProfile,
|
2022-03-03 23:52:26 +00:00
|
|
|
service.getAccessToken()
|
2022-02-26 20:45:56 +00:00
|
|
|
);
|
2023-03-22 15:10:04 +00:00
|
|
|
try {
|
|
|
|
connectDownstream();
|
|
|
|
} catch (Throwable t) {
|
|
|
|
t.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
2022-03-03 23:52:26 +00:00
|
|
|
|
|
|
|
// Save our refresh token for later use
|
2022-08-09 18:06:53 +00:00
|
|
|
geyser.saveRefreshToken(bedrockUsername(), service.getRefreshToken());
|
2022-02-26 20:45:56 +00:00
|
|
|
return true;
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
2022-02-26 20:45:56 +00:00
|
|
|
}
|
|
|
|
return false;
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* After getting whatever credentials needed, we attempt to join the Java server.
|
|
|
|
*/
|
|
|
|
private void connectDownstream() {
|
2023-06-17 01:46:32 +00:00
|
|
|
SessionLoginEvent loginEvent = new SessionLoginEvent(this, remoteServer);
|
|
|
|
GeyserImpl.getInstance().eventBus().fire(loginEvent);
|
|
|
|
if (loginEvent.isCancelled()) {
|
|
|
|
String disconnectReason = loginEvent.disconnectReason() == null ?
|
|
|
|
BedrockDisconnectReasons.DISCONNECTED : loginEvent.disconnectReason();
|
|
|
|
disconnect(disconnectReason);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.remoteServer = loginEvent.remoteServer();
|
2022-04-24 16:42:17 +00:00
|
|
|
boolean floodgate = this.remoteServer.authType() == AuthType.FLOODGATE;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
// Start ticking
|
|
|
|
tickThread = eventLoop.scheduleAtFixedRate(this::tick, 50, 50, TimeUnit.MILLISECONDS);
|
|
|
|
|
2022-10-30 00:23:21 +00:00
|
|
|
TcpSession downstream;
|
2021-11-20 21:34:30 +00:00
|
|
|
if (geyser.getBootstrap().getSocketAddress() != null) {
|
|
|
|
// We're going to connect through the JVM and not through TCP
|
2022-03-20 02:55:29 +00:00
|
|
|
downstream = new LocalSession(this.remoteServer.address(), this.remoteServer.port(),
|
2022-06-05 18:12:36 +00:00
|
|
|
geyser.getBootstrap().getSocketAddress(), upstream.getAddress().getAddress().getHostAddress(),
|
2022-06-05 22:38:29 +00:00
|
|
|
this.protocol, this.protocol.createHelper());
|
2022-12-23 21:18:48 +00:00
|
|
|
this.downstream = new DownstreamSession(downstream);
|
2021-11-20 21:34:30 +00:00
|
|
|
} else {
|
2022-03-20 02:55:29 +00:00
|
|
|
downstream = new TcpClientSession(this.remoteServer.address(), this.remoteServer.port(), this.protocol);
|
2022-12-23 21:18:48 +00:00
|
|
|
this.downstream = new DownstreamSession(downstream);
|
2021-11-20 21:34:30 +00:00
|
|
|
disableSrvResolving();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (geyser.getConfig().getRemote().isUseProxyProtocol()) {
|
|
|
|
downstream.setFlag(BuiltinFlags.ENABLE_CLIENT_PROXY_PROTOCOL, true);
|
|
|
|
downstream.setFlag(BuiltinFlags.CLIENT_PROXIED_ADDRESS, upstream.getAddress());
|
|
|
|
}
|
|
|
|
if (geyser.getConfig().isForwardPlayerPing()) {
|
|
|
|
// Let Geyser handle sending the keep alive
|
|
|
|
downstream.setFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, false);
|
|
|
|
}
|
|
|
|
downstream.addListener(new SessionAdapter() {
|
|
|
|
@Override
|
|
|
|
public void packetSending(PacketSendingEvent event) {
|
|
|
|
//todo move this somewhere else
|
|
|
|
if (event.getPacket() instanceof ClientIntentionPacket) {
|
|
|
|
String addressSuffix;
|
|
|
|
if (floodgate) {
|
|
|
|
byte[] encryptedData;
|
|
|
|
|
|
|
|
try {
|
|
|
|
FloodgateSkinUploader skinUploader = geyser.getSkinUploader();
|
|
|
|
FloodgateCipher cipher = geyser.getCipher();
|
|
|
|
|
2022-01-28 12:08:10 +00:00
|
|
|
String bedrockAddress = upstream.getAddress().getAddress().getHostAddress();
|
|
|
|
// both BungeeCord and Velocity remove the IPv6 scope (if there is one) for Spigot
|
|
|
|
int ipv6ScopeIndex = bedrockAddress.indexOf('%');
|
|
|
|
if (ipv6ScopeIndex != -1) {
|
|
|
|
bedrockAddress = bedrockAddress.substring(0, ipv6ScopeIndex);
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
encryptedData = cipher.encryptFromString(BedrockData.of(
|
|
|
|
clientData.getGameVersion(),
|
2021-11-21 18:36:42 +00:00
|
|
|
authData.name(),
|
|
|
|
authData.xuid(),
|
2021-11-20 21:34:30 +00:00
|
|
|
clientData.getDeviceOs().ordinal(),
|
|
|
|
clientData.getLanguageCode(),
|
|
|
|
clientData.getUiProfile().ordinal(),
|
|
|
|
clientData.getCurrentInputMode().ordinal(),
|
2022-01-28 12:08:10 +00:00
|
|
|
bedrockAddress,
|
2021-11-20 21:34:30 +00:00
|
|
|
skinUploader.getId(),
|
2021-11-30 15:32:44 +00:00
|
|
|
skinUploader.getVerifyCode()
|
2021-11-20 21:34:30 +00:00
|
|
|
).toString());
|
|
|
|
} catch (Exception e) {
|
2021-11-20 23:29:46 +00:00
|
|
|
geyser.getLogger().error(GeyserLocale.getLocaleStringLog("geyser.auth.floodgate.encrypt_fail"), e);
|
|
|
|
disconnect(GeyserLocale.getPlayerLocaleString("geyser.auth.floodgate.encryption_fail", getClientData().getLanguageCode()));
|
2021-11-20 21:34:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
addressSuffix = '\0' + new String(encryptedData, StandardCharsets.UTF_8);
|
|
|
|
} else {
|
|
|
|
addressSuffix = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientIntentionPacket intentionPacket = event.getPacket();
|
|
|
|
|
|
|
|
String address;
|
|
|
|
if (geyser.getConfig().getRemote().isForwardHost()) {
|
|
|
|
address = clientData.getServerAddress().split(":")[0];
|
|
|
|
} else {
|
|
|
|
address = intentionPacket.getHostname();
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setPacket(intentionPacket.withHostname(address + addressSuffix));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void connected(ConnectedEvent event) {
|
|
|
|
loggingIn = false;
|
|
|
|
loggedIn = true;
|
|
|
|
|
|
|
|
if (downstream instanceof LocalSession) {
|
|
|
|
// Connected directly to the server
|
2021-11-20 23:29:46 +00:00
|
|
|
geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.network.remote.connect_internal",
|
2021-11-21 18:36:42 +00:00
|
|
|
authData.name(), protocol.getProfile().getName()));
|
2021-11-20 21:34:30 +00:00
|
|
|
} else {
|
|
|
|
// Connected to an IP address
|
2021-11-20 23:29:46 +00:00
|
|
|
geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.network.remote.connect",
|
2022-03-20 02:55:29 +00:00
|
|
|
authData.name(), protocol.getProfile().getName(), remoteServer.address()));
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UUID uuid = protocol.getProfile().getId();
|
|
|
|
if (uuid == null) {
|
|
|
|
// Set what our UUID *probably* is going to be
|
2022-04-24 16:42:17 +00:00
|
|
|
if (remoteServer.authType() == AuthType.FLOODGATE) {
|
2021-11-21 18:36:42 +00:00
|
|
|
uuid = new UUID(0, Long.parseLong(authData.xuid()));
|
2021-11-20 21:34:30 +00:00
|
|
|
} else {
|
|
|
|
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + protocol.getProfile().getName()).getBytes(StandardCharsets.UTF_8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
playerEntity.setUuid(uuid);
|
|
|
|
playerEntity.setUsername(protocol.getProfile().getName());
|
|
|
|
|
|
|
|
String locale = clientData.getLanguageCode();
|
|
|
|
|
|
|
|
// Let the user know there locale may take some time to download
|
|
|
|
// as it has to be extracted from a JAR
|
2021-11-20 23:29:46 +00:00
|
|
|
if (locale.equalsIgnoreCase("en_us") && !MinecraftLocale.LOCALE_MAPPINGS.containsKey("en_us")) {
|
2021-11-20 21:34:30 +00:00
|
|
|
// This should probably be left hardcoded as it will only show for en_us clients
|
|
|
|
sendMessage("Loading your locale (en_us); if this isn't already downloaded, this may take some time");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Download and load the language for the player
|
2021-11-20 23:29:46 +00:00
|
|
|
MinecraftLocale.downloadAndLoadLocale(locale);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disconnected(DisconnectedEvent event) {
|
|
|
|
loggingIn = false;
|
|
|
|
loggedIn = false;
|
|
|
|
|
|
|
|
String disconnectMessage;
|
|
|
|
Throwable cause = event.getCause();
|
|
|
|
if (cause instanceof UnexpectedEncryptionException) {
|
2022-04-24 16:42:17 +00:00
|
|
|
if (remoteServer.authType() != AuthType.FLOODGATE) {
|
2021-11-20 21:34:30 +00:00
|
|
|
// Server expects online mode
|
2022-01-16 21:09:53 +00:00
|
|
|
disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.authentication_type_mismatch", locale());
|
2021-11-20 21:34:30 +00:00
|
|
|
// Explain that they may be looking for Floodgate.
|
2021-11-20 23:29:46 +00:00
|
|
|
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog(
|
2021-11-20 21:34:30 +00:00
|
|
|
geyser.getPlatformType() == PlatformType.STANDALONE ?
|
|
|
|
"geyser.network.remote.floodgate_explanation_standalone"
|
|
|
|
: "geyser.network.remote.floodgate_explanation_plugin",
|
|
|
|
Constants.FLOODGATE_DOWNLOAD_LOCATION
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
// Likely that Floodgate is not configured correctly.
|
2022-01-16 21:09:53 +00:00
|
|
|
disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.floodgate_login_error", locale());
|
2021-11-20 21:34:30 +00:00
|
|
|
if (geyser.getPlatformType() == PlatformType.STANDALONE) {
|
2021-11-20 23:29:46 +00:00
|
|
|
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.remote.floodgate_login_error_standalone"));
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (cause instanceof ConnectException) {
|
|
|
|
// Server is offline, probably
|
2022-01-16 21:09:53 +00:00
|
|
|
disconnectMessage = GeyserLocale.getPlayerLocaleString("geyser.network.remote.server_offline", locale());
|
2021-11-20 21:34:30 +00:00
|
|
|
} else {
|
2023-03-13 03:51:51 +00:00
|
|
|
disconnectMessage = MessageTranslator.convertMessage(event.getReason());
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (downstream instanceof LocalSession) {
|
2021-11-21 18:36:42 +00:00
|
|
|
geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.network.remote.disconnect_internal", authData.name(), disconnectMessage));
|
2021-11-20 21:34:30 +00:00
|
|
|
} else {
|
2022-03-20 02:55:29 +00:00
|
|
|
geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.network.remote.disconnect", authData.name(), remoteServer.address(), disconnectMessage));
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
if (cause != null) {
|
|
|
|
cause.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
upstream.disconnect(disconnectMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-11-25 04:38:21 +00:00
|
|
|
public void packetReceived(Session session, Packet packet) {
|
2021-11-22 19:52:26 +00:00
|
|
|
Registries.JAVA_PACKET_TRANSLATORS.translate(packet.getClass(), packet, GeyserSession.this);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void packetError(PacketErrorEvent event) {
|
2021-11-20 23:29:46 +00:00
|
|
|
geyser.getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.network.downstream_error", event.getCause().getMessage()));
|
2021-11-20 21:34:30 +00:00
|
|
|
if (geyser.getConfig().isDebugMode())
|
|
|
|
event.getCause().printStackTrace();
|
|
|
|
event.setSuppress(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!daylightCycle) {
|
|
|
|
setDaylightCycle(true);
|
|
|
|
}
|
|
|
|
|
2022-06-05 22:38:29 +00:00
|
|
|
downstream.connect(false);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void disconnect(String reason) {
|
|
|
|
if (!closed) {
|
|
|
|
loggedIn = false;
|
|
|
|
if (downstream != null) {
|
|
|
|
downstream.disconnect(reason);
|
2022-03-06 03:32:38 +00:00
|
|
|
} else {
|
|
|
|
// Downstream's disconnect will fire an event that prints a log message
|
|
|
|
// Otherwise, we print a message here
|
2022-08-25 20:10:43 +00:00
|
|
|
String address = geyser.getConfig().isLogPlayerIpAddresses() ? upstream.getAddress().getAddress().toString() : "<IP address withheld>";
|
2022-03-06 03:32:38 +00:00
|
|
|
geyser.getLogger().info(GeyserLocale.getLocaleStringLog("geyser.network.disconnect", address, reason));
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
2022-03-06 03:32:38 +00:00
|
|
|
if (!upstream.isClosed()) {
|
2021-11-20 21:34:30 +00:00
|
|
|
upstream.disconnect(reason);
|
|
|
|
}
|
2022-03-06 03:32:38 +00:00
|
|
|
geyser.getSessionManager().removeSession(this);
|
2022-02-26 20:45:56 +00:00
|
|
|
if (authData != null) {
|
|
|
|
PendingMicrosoftAuthentication.AuthenticationTask task = geyser.getPendingMicrosoftAuthentication().getTask(authData.xuid());
|
|
|
|
if (task != null) {
|
|
|
|
task.setOnline(false);
|
|
|
|
}
|
|
|
|
}
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tickThread != null) {
|
|
|
|
tickThread.cancel(false);
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:44:55 +00:00
|
|
|
erosionHandler.close();
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
closed = true;
|
|
|
|
}
|
|
|
|
|
2022-12-18 02:05:41 +00:00
|
|
|
/**
|
|
|
|
* Moves task to the session event loop if already not in it. Otherwise, the task is automatically ran.
|
|
|
|
*/
|
|
|
|
public void ensureInEventLoop(Runnable runnable) {
|
|
|
|
if (eventLoop.inEventLoop()) {
|
|
|
|
runnable.run();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
executeInEventLoop(runnable);
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* Executes a task and prints a stack trace if an error occurs.
|
|
|
|
*/
|
|
|
|
public void executeInEventLoop(Runnable runnable) {
|
|
|
|
eventLoop.execute(() -> {
|
|
|
|
try {
|
|
|
|
runnable.run();
|
|
|
|
} catch (Throwable e) {
|
2022-08-09 18:06:53 +00:00
|
|
|
geyser.getLogger().error("Error thrown in " + this.bedrockUsername() + "'s event loop!", e);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedules a task and prints a stack trace if an error occurs.
|
|
|
|
*/
|
|
|
|
public ScheduledFuture<?> scheduleInEventLoop(Runnable runnable, long duration, TimeUnit timeUnit) {
|
|
|
|
return eventLoop.schedule(() -> {
|
|
|
|
try {
|
|
|
|
runnable.run();
|
|
|
|
} catch (Throwable e) {
|
2022-08-09 18:06:53 +00:00
|
|
|
geyser.getLogger().error("Error thrown in " + this.bedrockUsername() + "'s event loop!", e);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
}, duration, timeUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called every 50 milliseconds - one Minecraft tick.
|
|
|
|
*/
|
|
|
|
protected void tick() {
|
|
|
|
try {
|
|
|
|
pistonCache.tick();
|
|
|
|
// Check to see if the player's position needs updating - a position update should be sent once every 3 seconds
|
|
|
|
if (spawned && (System.currentTimeMillis() - lastMovementTimestamp) > 3000) {
|
|
|
|
// Recalculate in case something else changed position
|
|
|
|
Vector3d position = collisionManager.adjustBedrockPosition(playerEntity.getPosition(), playerEntity.isOnGround(), false);
|
|
|
|
// A null return value cancels the packet
|
|
|
|
if (position != null) {
|
|
|
|
ServerboundMovePlayerPosPacket packet = new ServerboundMovePlayerPosPacket(playerEntity.isOnGround(),
|
|
|
|
position.getX(), position.getY(), position.getZ());
|
|
|
|
sendDownstreamPacket(packet);
|
|
|
|
}
|
|
|
|
lastMovementTimestamp = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (worldBorder.isResizing()) {
|
|
|
|
worldBorder.resize();
|
|
|
|
}
|
|
|
|
|
2022-05-15 17:52:18 +00:00
|
|
|
boolean shouldShowFog = !worldBorder.isWithinWarningBoundaries();
|
|
|
|
if (shouldShowFog || worldBorder.isCloseToBorderBoundaries()) {
|
2021-11-20 21:34:30 +00:00
|
|
|
// Show particles representing where the world border is
|
|
|
|
worldBorder.drawWall();
|
|
|
|
// Set the mood
|
2022-05-15 17:52:18 +00:00
|
|
|
if (shouldShowFog && !isInWorldBorderWarningArea) {
|
2021-11-20 21:34:30 +00:00
|
|
|
isInWorldBorderWarningArea = true;
|
2021-12-08 18:23:05 +00:00
|
|
|
sendFog("minecraft:fog_crimson_forest");
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
2022-05-15 17:52:18 +00:00
|
|
|
}
|
|
|
|
if (!shouldShowFog && isInWorldBorderWarningArea) {
|
2021-11-20 21:34:30 +00:00
|
|
|
// Clear fog as we are outside the world border now
|
2021-12-08 18:23:05 +00:00
|
|
|
removeFog("minecraft:fog_crimson_forest");
|
2021-11-20 21:34:30 +00:00
|
|
|
isInWorldBorderWarningArea = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (Tickable entity : entityCache.getTickableEntities()) {
|
|
|
|
entity.tick();
|
|
|
|
}
|
2022-03-15 17:34:56 +00:00
|
|
|
|
2023-01-04 00:28:43 +00:00
|
|
|
if (armAnimationTicks >= 0) {
|
2022-03-15 17:34:56 +00:00
|
|
|
// As of 1.18.2 Java Edition, it appears that the swing time is dynamically updated depending on the
|
|
|
|
// player's effect status, but the animation can cut short if the duration suddenly decreases
|
|
|
|
// (from suddenly no longer having mining fatigue, for example)
|
|
|
|
// This math is referenced from Java Edition 1.18.2
|
|
|
|
int swingTotalDuration;
|
|
|
|
int hasteLevel = Math.max(effectCache.getHaste(), effectCache.getConduitPower());
|
|
|
|
if (hasteLevel > 0) {
|
|
|
|
swingTotalDuration = 6 - hasteLevel;
|
|
|
|
} else {
|
|
|
|
int miningFatigueLevel = effectCache.getMiningFatigue();
|
|
|
|
if (miningFatigueLevel > 0) {
|
|
|
|
swingTotalDuration = 6 + miningFatigueLevel * 2;
|
|
|
|
} else {
|
|
|
|
swingTotalDuration = 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (++armAnimationTicks >= swingTotalDuration) {
|
|
|
|
if (sneaking) {
|
|
|
|
// Attempt to re-activate blocking as our swing animation is up
|
|
|
|
if (attemptToBlock()) {
|
|
|
|
playerEntity.updateBedrockMetadata();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
armAnimationTicks = -1;
|
|
|
|
}
|
|
|
|
}
|
2021-11-20 21:34:30 +00:00
|
|
|
} catch (Throwable throwable) {
|
|
|
|
throwable.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAuthenticationData(AuthData authData) {
|
|
|
|
this.authData = authData;
|
|
|
|
}
|
|
|
|
|
2022-03-15 17:34:56 +00:00
|
|
|
public void startSneaking() {
|
|
|
|
// Toggle the shield, if there is no ongoing arm animation
|
|
|
|
// This matches Bedrock Edition behavior as of 1.18.12
|
2023-01-04 00:28:43 +00:00
|
|
|
if (armAnimationTicks < 0) {
|
2022-03-15 17:34:56 +00:00
|
|
|
attemptToBlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
setSneaking(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stopSneaking() {
|
|
|
|
disableBlocking();
|
|
|
|
|
|
|
|
setSneaking(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSneaking(boolean sneaking) {
|
2021-11-20 21:34:30 +00:00
|
|
|
this.sneaking = sneaking;
|
|
|
|
|
|
|
|
// Update pose and bounding box on our end
|
|
|
|
AttributeData speedAttribute;
|
|
|
|
if (!sneaking && (speedAttribute = adjustSpeed()) != null) {
|
|
|
|
// Update attributes since we're still "sneaking" under a 1.5-block-tall area
|
|
|
|
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
|
|
|
attributesPacket.setRuntimeEntityId(playerEntity.getGeyserId());
|
|
|
|
attributesPacket.setAttributes(Collections.singletonList(speedAttribute));
|
|
|
|
sendUpstreamPacket(attributesPacket);
|
|
|
|
// the server *should* update our pose once it has returned to normal
|
|
|
|
} else {
|
|
|
|
if (!flying) {
|
|
|
|
// The pose and bounding box should not be updated if the player is flying
|
|
|
|
setSneakingPose(sneaking);
|
|
|
|
}
|
|
|
|
collisionManager.updateScaffoldingFlags(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
playerEntity.updateBedrockMetadata();
|
|
|
|
|
|
|
|
if (mouseoverEntity != null) {
|
|
|
|
// Horses, etc can change their property depending on if you're sneaking
|
2022-02-25 03:49:10 +00:00
|
|
|
mouseoverEntity.updateInteractiveTag();
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSneakingPose(boolean sneaking) {
|
2021-12-24 00:49:58 +00:00
|
|
|
if (this.pose == Pose.SNEAKING && !sneaking) {
|
|
|
|
this.pose = Pose.STANDING;
|
|
|
|
playerEntity.setBoundingBoxHeight(playerEntity.getDefinition().height());
|
|
|
|
} else if (sneaking) {
|
|
|
|
this.pose = Pose.SNEAKING;
|
|
|
|
playerEntity.setBoundingBoxHeight(1.5f);
|
|
|
|
}
|
2021-11-20 21:34:30 +00:00
|
|
|
playerEntity.setFlag(EntityFlag.SNEAKING, sneaking);
|
|
|
|
}
|
|
|
|
|
2021-12-26 03:46:16 +00:00
|
|
|
public void setSwimming(boolean swimming) {
|
|
|
|
if (swimming) {
|
|
|
|
this.pose = Pose.SWIMMING;
|
|
|
|
playerEntity.setBoundingBoxHeight(0.6f);
|
|
|
|
} else {
|
|
|
|
this.pose = Pose.STANDING;
|
|
|
|
playerEntity.setBoundingBoxHeight(playerEntity.getDefinition().height());
|
|
|
|
}
|
|
|
|
playerEntity.setFlag(EntityFlag.SWIMMING, swimming);
|
|
|
|
playerEntity.updateBedrockMetadata();
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
public void setFlying(boolean flying) {
|
|
|
|
this.flying = flying;
|
|
|
|
|
|
|
|
if (sneaking) {
|
|
|
|
// update bounding box as it is not reduced when flying
|
|
|
|
setSneakingPose(!flying);
|
|
|
|
playerEntity.updateBedrockMetadata();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjusts speed if the player is crawling.
|
|
|
|
*
|
|
|
|
* @return not null if attributes should be updated.
|
|
|
|
*/
|
|
|
|
public AttributeData adjustSpeed() {
|
|
|
|
AttributeData currentPlayerSpeed = playerEntity.getAttributes().get(GeyserAttributeType.MOVEMENT_SPEED);
|
|
|
|
if (currentPlayerSpeed != null) {
|
2021-12-26 03:46:16 +00:00
|
|
|
if ((pose.equals(Pose.SNEAKING) && !sneaking && collisionManager.mustPlayerSneakHere()) ||
|
2021-11-20 21:34:30 +00:00
|
|
|
(!swimmingInWater && playerEntity.getFlag(EntityFlag.SWIMMING) && !collisionManager.isPlayerInWater())) {
|
|
|
|
// Either of those conditions means that Bedrock goes zoom when they shouldn't be
|
|
|
|
AttributeData speedAttribute = GeyserAttributeType.MOVEMENT_SPEED.getAttribute(originalSpeedAttribute / 3.32f);
|
|
|
|
playerEntity.getAttributes().put(GeyserAttributeType.MOVEMENT_SPEED, speedAttribute);
|
|
|
|
return speedAttribute;
|
|
|
|
} else if (originalSpeedAttribute != currentPlayerSpeed.getValue()) {
|
|
|
|
// Speed has reset to normal
|
|
|
|
AttributeData speedAttribute = GeyserAttributeType.MOVEMENT_SPEED.getAttribute(originalSpeedAttribute);
|
|
|
|
playerEntity.getAttributes().put(GeyserAttributeType.MOVEMENT_SPEED, speedAttribute);
|
|
|
|
return speedAttribute;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-03-15 17:34:56 +00:00
|
|
|
/**
|
|
|
|
* Checks to see if a shield is in either hand to activate blocking. If so, it sets the Bedrock client to display
|
|
|
|
* blocking and sends a packet to the Java server.
|
|
|
|
*/
|
|
|
|
private boolean attemptToBlock() {
|
|
|
|
ServerboundUseItemPacket useItemPacket;
|
2022-12-29 20:10:40 +00:00
|
|
|
if (playerInventory.getItemInHand().asItem() == Items.SHIELD) {
|
2022-07-10 03:02:19 +00:00
|
|
|
useItemPacket = new ServerboundUseItemPacket(Hand.MAIN_HAND, worldCache.nextPredictionSequence());
|
2022-12-29 20:10:40 +00:00
|
|
|
} else if (playerInventory.getOffhand().asItem() == Items.SHIELD) {
|
2022-07-10 03:02:19 +00:00
|
|
|
useItemPacket = new ServerboundUseItemPacket(Hand.OFF_HAND, worldCache.nextPredictionSequence());
|
2022-03-15 17:34:56 +00:00
|
|
|
} else {
|
|
|
|
// No blocking
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendDownstreamPacket(useItemPacket);
|
|
|
|
playerEntity.setFlag(EntityFlag.BLOCKING, true);
|
|
|
|
// Metadata should be updated later
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts ticking the amount of time that the Bedrock client has been swinging their arm, and disables blocking if
|
|
|
|
* blocking.
|
|
|
|
*/
|
|
|
|
public void activateArmAnimationTicking() {
|
|
|
|
armAnimationTicks = 0;
|
|
|
|
if (disableBlocking()) {
|
|
|
|
playerEntity.updateBedrockMetadata();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 00:28:43 +00:00
|
|
|
/**
|
|
|
|
* For https://github.com/GeyserMC/Geyser/issues/2113 and combating arm ticking activating being delayed in
|
|
|
|
* BedrockAnimateTranslator.
|
|
|
|
*/
|
|
|
|
public void armSwingPending() {
|
|
|
|
if (armAnimationTicks == -1) {
|
|
|
|
armAnimationTicks = -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 17:34:56 +00:00
|
|
|
/**
|
|
|
|
* Indicates to the client to stop blocking and tells the Java server the same.
|
|
|
|
*/
|
|
|
|
private boolean disableBlocking() {
|
|
|
|
if (playerEntity.getFlag(EntityFlag.BLOCKING)) {
|
|
|
|
ServerboundPlayerActionPacket releaseItemPacket = new ServerboundPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM,
|
2022-09-27 23:24:50 +00:00
|
|
|
Vector3i.ZERO, Direction.DOWN, 0);
|
2022-03-15 17:34:56 +00:00
|
|
|
sendDownstreamPacket(releaseItemPacket);
|
|
|
|
playerEntity.setFlag(EntityFlag.BLOCKING, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-02-15 05:17:14 +00:00
|
|
|
public void requestOffhandSwap() {
|
|
|
|
ServerboundPlayerActionPacket swapHandsPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, Vector3i.ZERO,
|
|
|
|
Direction.DOWN, 0);
|
|
|
|
sendDownstreamPacket(swapHandsPacket);
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* Will be overwritten for GeyserConnect.
|
|
|
|
*/
|
|
|
|
protected void disableSrvResolving() {
|
2022-10-30 00:23:21 +00:00
|
|
|
this.downstream.getSession().setFlag(BuiltinFlags.ATTEMPT_SRV_RESOLVE, false);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-08-11 23:01:26 +00:00
|
|
|
public String name() {
|
|
|
|
return null;
|
2022-03-18 22:59:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
@Override
|
|
|
|
public void sendMessage(String message) {
|
|
|
|
TextPacket textPacket = new TextPacket();
|
|
|
|
textPacket.setPlatformChatId("");
|
|
|
|
textPacket.setSourceName("");
|
|
|
|
textPacket.setXuid("");
|
|
|
|
textPacket.setType(TextPacket.Type.CHAT);
|
|
|
|
textPacket.setNeedsTranslation(false);
|
|
|
|
textPacket.setMessage(message);
|
|
|
|
|
|
|
|
upstream.sendPacket(textPacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isConsole() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-01-16 21:09:53 +00:00
|
|
|
public String locale() {
|
2021-11-20 21:34:30 +00:00
|
|
|
return clientData.getLanguageCode();
|
2022-05-25 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a chat message to the Java server.
|
|
|
|
*/
|
|
|
|
public void sendChat(String message) {
|
2022-11-22 22:13:59 +00:00
|
|
|
sendDownstreamPacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet()));
|
2022-05-25 19:55:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a command to the Java server.
|
|
|
|
*/
|
|
|
|
public void sendCommand(String command) {
|
2022-11-22 22:13:59 +00:00
|
|
|
sendDownstreamPacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet()));
|
2022-05-25 19:55:15 +00:00
|
|
|
}
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2022-01-16 01:29:00 +00:00
|
|
|
public void setServerRenderDistance(int renderDistance) {
|
|
|
|
this.serverRenderDistance = renderDistance;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket();
|
|
|
|
chunkRadiusUpdatedPacket.setRadius(renderDistance);
|
|
|
|
upstream.sendPacket(chunkRadiusUpdatedPacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
public InetSocketAddress getSocketAddress() {
|
|
|
|
return this.upstream.getAddress();
|
|
|
|
}
|
|
|
|
|
2023-02-23 18:11:18 +00:00
|
|
|
@Override
|
2022-08-11 23:01:26 +00:00
|
|
|
public boolean sendForm(@NonNull Form form) {
|
2021-11-20 21:34:30 +00:00
|
|
|
formCache.showForm(form);
|
2022-08-11 23:01:26 +00:00
|
|
|
return true;
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 18:11:18 +00:00
|
|
|
@Override
|
2022-08-11 23:01:26 +00:00
|
|
|
public boolean sendForm(@NonNull FormBuilder<?, ?, ?> formBuilder) {
|
2021-11-20 21:34:30 +00:00
|
|
|
formCache.showForm(formBuilder.build());
|
2022-08-11 23:01:26 +00:00
|
|
|
return true;
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 22:25:45 +00:00
|
|
|
/**
|
|
|
|
* @deprecated since Cumulus version 1.1, and will be removed when Cumulus 2.0 releases. Please use the new forms instead.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public void sendForm(org.geysermc.cumulus.Form<?> form) {
|
|
|
|
sendForm(form.newForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated since Cumulus version 1.1, and will be removed when Cumulus 2.0 releases. Please use the new forms instead.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2022-06-06 08:03:39 +00:00
|
|
|
public void sendForm(org.geysermc.cumulus.util.FormBuilder<?, ?> formBuilder) {
|
2022-06-05 22:25:45 +00:00
|
|
|
sendForm(formBuilder.build());
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
private void startGame() {
|
2022-12-29 20:10:40 +00:00
|
|
|
this.upstream.getCodecHelper().setItemDefinitions(this.itemMappings);
|
2022-12-24 00:40:42 +00:00
|
|
|
this.upstream.getCodecHelper().setBlockDefinitions((DefinitionRegistry) this.blockMappings); //FIXME
|
2022-10-30 03:02:11 +00:00
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
StartGamePacket startGamePacket = new StartGamePacket();
|
|
|
|
startGamePacket.setUniqueEntityId(playerEntity.getGeyserId());
|
|
|
|
startGamePacket.setRuntimeEntityId(playerEntity.getGeyserId());
|
|
|
|
startGamePacket.setPlayerGameType(switch (gameMode) {
|
|
|
|
case CREATIVE -> GameType.CREATIVE;
|
|
|
|
case ADVENTURE -> GameType.ADVENTURE;
|
|
|
|
default -> GameType.SURVIVAL;
|
|
|
|
});
|
|
|
|
startGamePacket.setPlayerPosition(Vector3f.from(0, 69, 0));
|
|
|
|
startGamePacket.setRotation(Vector2f.from(1, 1));
|
|
|
|
|
2022-04-21 01:37:50 +00:00
|
|
|
startGamePacket.setSeed(-1L);
|
2022-11-12 15:28:53 +00:00
|
|
|
startGamePacket.setDimensionId(DimensionUtils.javaToBedrock(chunkCache.getBedrockDimension()));
|
2021-11-20 21:34:30 +00:00
|
|
|
startGamePacket.setGeneratorId(1);
|
|
|
|
startGamePacket.setLevelGameType(GameType.SURVIVAL);
|
|
|
|
startGamePacket.setDifficulty(1);
|
|
|
|
startGamePacket.setDefaultSpawn(Vector3i.ZERO);
|
|
|
|
startGamePacket.setAchievementsDisabled(!geyser.getConfig().isXboxAchievementsEnabled());
|
|
|
|
startGamePacket.setCurrentTick(-1);
|
|
|
|
startGamePacket.setEduEditionOffers(0);
|
|
|
|
startGamePacket.setEduFeaturesEnabled(false);
|
|
|
|
startGamePacket.setRainLevel(0);
|
|
|
|
startGamePacket.setLightningLevel(0);
|
|
|
|
startGamePacket.setMultiplayerGame(true);
|
|
|
|
startGamePacket.setBroadcastingToLan(true);
|
|
|
|
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC);
|
|
|
|
startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC);
|
|
|
|
startGamePacket.setCommandsEnabled(!geyser.getConfig().isXboxAchievementsEnabled());
|
|
|
|
startGamePacket.setTexturePacksRequired(false);
|
|
|
|
startGamePacket.setBonusChestEnabled(false);
|
|
|
|
startGamePacket.setStartingWithMap(false);
|
|
|
|
startGamePacket.setTrustingPlayers(true);
|
|
|
|
startGamePacket.setDefaultPlayerPermission(PlayerPermission.MEMBER);
|
|
|
|
startGamePacket.setServerChunkTickRange(4);
|
|
|
|
startGamePacket.setBehaviorPackLocked(false);
|
|
|
|
startGamePacket.setResourcePackLocked(false);
|
|
|
|
startGamePacket.setFromLockedWorldTemplate(false);
|
|
|
|
startGamePacket.setUsingMsaGamertagsOnly(false);
|
|
|
|
startGamePacket.setFromWorldTemplate(false);
|
|
|
|
startGamePacket.setWorldTemplateOptionLocked(false);
|
2022-12-23 21:18:48 +00:00
|
|
|
startGamePacket.setSpawnBiomeType(SpawnBiomeType.DEFAULT);
|
|
|
|
startGamePacket.setCustomBiomeName("");
|
|
|
|
startGamePacket.setEducationProductionId("");
|
|
|
|
startGamePacket.setForceExperimentalGameplay(OptionalBoolean.empty());
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2022-07-09 22:39:02 +00:00
|
|
|
String serverName = geyser.getConfig().getBedrock().serverName();
|
2021-11-20 21:34:30 +00:00
|
|
|
startGamePacket.setLevelId(serverName);
|
|
|
|
startGamePacket.setLevelName(serverName);
|
|
|
|
|
|
|
|
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
|
|
|
|
// startGamePacket.setCurrentTick(0);
|
|
|
|
startGamePacket.setEnchantmentSeed(0);
|
|
|
|
startGamePacket.setMultiplayerCorrelationId("");
|
2022-07-02 16:50:16 +00:00
|
|
|
|
2022-12-29 20:10:40 +00:00
|
|
|
startGamePacket.setItemDefinitions(this.itemMappings.getItemDefinitions().values().stream().toList()); // TODO
|
2022-10-30 03:02:11 +00:00
|
|
|
// startGamePacket.setBlockPalette(this.blockMappings.getBedrockBlockPalette());
|
2022-07-02 16:50:16 +00:00
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
startGamePacket.setVanillaVersion("*");
|
|
|
|
startGamePacket.setInventoriesServerAuthoritative(true);
|
|
|
|
startGamePacket.setServerEngine(""); // Do we want to fill this in?
|
|
|
|
|
2022-05-25 23:41:31 +00:00
|
|
|
startGamePacket.setPlayerPropertyData(NbtMap.EMPTY);
|
|
|
|
startGamePacket.setWorldTemplateId(UUID.randomUUID());
|
|
|
|
|
2022-08-07 16:09:54 +00:00
|
|
|
startGamePacket.setChatRestrictionLevel(ChatRestrictionLevel.NONE);
|
|
|
|
|
2022-10-30 00:23:21 +00:00
|
|
|
startGamePacket.setAuthoritativeMovementMode(AuthoritativeMovementMode.CLIENT);
|
|
|
|
startGamePacket.setRewindHistorySize(0);
|
|
|
|
startGamePacket.setServerAuthoritativeBlockBreaking(false);
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2023-05-11 17:23:27 +00:00
|
|
|
if (GameProtocol.isPre1_20(this)) {
|
|
|
|
startGamePacket.getExperiments().add(new ExperimentData("next_major_update", true));
|
|
|
|
startGamePacket.getExperiments().add(new ExperimentData("sniffer", true));
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
upstream.sendPacket(startGamePacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the next Bedrock item network ID to use for a new item
|
|
|
|
*/
|
|
|
|
public int getNextItemNetId() {
|
|
|
|
return itemNetId.getAndIncrement();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void confirmTeleport(Vector3d position) {
|
2021-12-18 16:43:57 +00:00
|
|
|
if (unconfirmedTeleport == null) {
|
2021-11-20 21:34:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-18 16:43:57 +00:00
|
|
|
if (unconfirmedTeleport.canConfirm(position)) {
|
|
|
|
unconfirmedTeleport = null;
|
|
|
|
return;
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-18 16:43:57 +00:00
|
|
|
// Resend the teleport every few packets until Bedrock responds
|
|
|
|
unconfirmedTeleport.incrementUnconfirmedFor();
|
|
|
|
if (unconfirmedTeleport.shouldResend()) {
|
|
|
|
unconfirmedTeleport.resetUnconfirmedFor();
|
|
|
|
geyser.getLogger().debug("Resending teleport " + unconfirmedTeleport.getTeleportConfirmId());
|
|
|
|
getPlayerEntity().moveAbsolute(Vector3f.from(unconfirmedTeleport.getX(), unconfirmedTeleport.getY(), unconfirmedTeleport.getZ()),
|
|
|
|
unconfirmedTeleport.getYaw(), unconfirmedTeleport.getPitch(), playerEntity.isOnGround(), true);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue a packet to be sent to player.
|
|
|
|
*
|
|
|
|
* @param packet the bedrock packet from the NukkitX protocol lib
|
|
|
|
*/
|
|
|
|
public void sendUpstreamPacket(BedrockPacket packet) {
|
|
|
|
upstream.sendPacket(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a packet immediately to the player.
|
|
|
|
*
|
|
|
|
* @param packet the bedrock packet from the NukkitX protocol lib
|
|
|
|
*/
|
|
|
|
public void sendUpstreamPacketImmediately(BedrockPacket packet) {
|
|
|
|
upstream.sendPacketImmediately(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a packet to the remote server.
|
|
|
|
*
|
|
|
|
* @param packet the java edition packet from MCProtocolLib
|
|
|
|
*/
|
|
|
|
public void sendDownstreamPacket(Packet packet) {
|
|
|
|
if (!closed && this.downstream != null) {
|
2022-10-30 00:23:21 +00:00
|
|
|
Channel channel = this.downstream.getSession().getChannel();
|
2021-11-20 21:34:30 +00:00
|
|
|
if (channel == null) {
|
|
|
|
// Channel is only null before the connection has initialized
|
|
|
|
geyser.getLogger().warning("Tried to send a packet to the Java server too early!");
|
|
|
|
if (geyser.getConfig().isDebugMode()) {
|
|
|
|
Thread.dumpStack();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventLoop eventLoop = channel.eventLoop();
|
|
|
|
if (eventLoop.inEventLoop()) {
|
|
|
|
sendDownstreamPacket0(packet);
|
|
|
|
} else {
|
|
|
|
eventLoop.execute(() -> sendDownstreamPacket0(packet));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendDownstreamPacket0(Packet packet) {
|
|
|
|
if (protocol.getState().equals(ProtocolState.GAME) || packet.getClass() == ServerboundCustomQueryPacket.class) {
|
2022-10-30 00:23:21 +00:00
|
|
|
downstream.sendPacket(packet);
|
2021-11-20 21:34:30 +00:00
|
|
|
} else {
|
|
|
|
geyser.getLogger().debug("Tried to send downstream packet " + packet.getClass().getSimpleName() + " before connected to the server");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the cached value for the reduced debug info gamerule.
|
|
|
|
* If enabled, also hides the player's coordinates.
|
|
|
|
*
|
|
|
|
* @param value The new value for reducedDebugInfo
|
|
|
|
*/
|
|
|
|
public void setReducedDebugInfo(boolean value) {
|
|
|
|
reducedDebugInfo = value;
|
|
|
|
// Set the showCoordinates data. This is done because updateShowCoordinates() uses this gamerule as a variable.
|
|
|
|
preferencesCache.updateShowCoordinates();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the daylight cycle gamerule on the client
|
|
|
|
* This is used in the login screen along-side normal usage
|
|
|
|
*
|
|
|
|
* @param doCycle If the cycle should continue
|
|
|
|
*/
|
|
|
|
public void setDaylightCycle(boolean doCycle) {
|
|
|
|
sendGameRule("dodaylightcycle", doCycle);
|
|
|
|
// Save the value so we don't have to constantly send a daylight cycle gamerule update
|
|
|
|
this.daylightCycle = doCycle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a gamerule value to the client
|
|
|
|
*
|
|
|
|
* @param gameRule The gamerule to send
|
|
|
|
* @param value The value of the gamerule
|
|
|
|
*/
|
|
|
|
public void sendGameRule(String gameRule, Object value) {
|
|
|
|
GameRulesChangedPacket gameRulesChangedPacket = new GameRulesChangedPacket();
|
|
|
|
gameRulesChangedPacket.getGameRules().add(new GameRuleData<>(gameRule, value));
|
|
|
|
upstream.sendPacket(gameRulesChangedPacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given session's player has a permission
|
|
|
|
*
|
|
|
|
* @param permission The permission node to check
|
|
|
|
* @return true if the player has the requested permission, false if not
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean hasPermission(String permission) {
|
|
|
|
return geyser.getWorldManager().hasPermission(this, permission);
|
|
|
|
}
|
|
|
|
|
2022-07-10 17:33:39 +00:00
|
|
|
private static final Ability[] USED_ABILITIES = Ability.values();
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* Send an AdventureSettingsPacket to the client with the latest flags
|
|
|
|
*/
|
|
|
|
public void sendAdventureSettings() {
|
2022-07-10 17:33:39 +00:00
|
|
|
long bedrockId = playerEntity.getGeyserId();
|
2021-11-20 21:34:30 +00:00
|
|
|
// Set command permission if OP permission level is high enough
|
|
|
|
// This allows mobile players access to a GUI for doing commands. The commands there do not change above OPERATOR
|
|
|
|
// and all commands there are accessible with OP permission level 2
|
2022-10-30 00:23:21 +00:00
|
|
|
CommandPermission commandPermission = opPermissionLevel >= 2 ? CommandPermission.GAME_DIRECTORS : CommandPermission.ANY;
|
2021-11-20 21:34:30 +00:00
|
|
|
// Required to make command blocks destroyable
|
2022-07-10 17:33:39 +00:00
|
|
|
PlayerPermission playerPermission = opPermissionLevel >= 2 ? PlayerPermission.OPERATOR : PlayerPermission.MEMBER;
|
2021-11-20 21:34:30 +00:00
|
|
|
|
|
|
|
// Update the noClip and worldImmutable values based on the current gamemode
|
|
|
|
boolean spectator = gameMode == GameMode.SPECTATOR;
|
|
|
|
boolean worldImmutable = gameMode == GameMode.ADVENTURE || spectator;
|
|
|
|
|
2022-11-29 02:53:17 +00:00
|
|
|
UpdateAdventureSettingsPacket adventureSettingsPacket = new UpdateAdventureSettingsPacket();
|
|
|
|
adventureSettingsPacket.setNoMvP(false);
|
|
|
|
adventureSettingsPacket.setNoPvM(false);
|
|
|
|
adventureSettingsPacket.setImmutableWorld(worldImmutable);
|
|
|
|
adventureSettingsPacket.setShowNameTags(false);
|
|
|
|
adventureSettingsPacket.setAutoJump(true);
|
|
|
|
sendUpstreamPacket(adventureSettingsPacket);
|
2022-07-10 17:33:39 +00:00
|
|
|
|
2022-11-29 02:53:17 +00:00
|
|
|
UpdateAbilitiesPacket updateAbilitiesPacket = new UpdateAbilitiesPacket();
|
|
|
|
updateAbilitiesPacket.setUniqueEntityId(bedrockId);
|
|
|
|
updateAbilitiesPacket.setCommandPermission(commandPermission);
|
|
|
|
updateAbilitiesPacket.setPlayerPermission(playerPermission);
|
2022-07-10 17:33:39 +00:00
|
|
|
|
2022-11-29 02:53:17 +00:00
|
|
|
AbilityLayer abilityLayer = new AbilityLayer();
|
|
|
|
Set<Ability> abilities = abilityLayer.getAbilityValues();
|
|
|
|
if (canFly || spectator) {
|
|
|
|
abilities.add(Ability.MAY_FLY);
|
2022-07-10 17:33:39 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 02:53:17 +00:00
|
|
|
// Default stuff we have to fill in
|
|
|
|
abilities.add(Ability.BUILD);
|
|
|
|
abilities.add(Ability.MINE);
|
|
|
|
// Needed so you can drop items
|
|
|
|
abilities.add(Ability.DOORS_AND_SWITCHES);
|
2023-03-18 21:40:51 +00:00
|
|
|
// Required for lecterns to work (likely started around 1.19.10; confirmed on 1.19.70)
|
|
|
|
abilities.add(Ability.OPEN_CONTAINERS);
|
2022-11-29 02:53:17 +00:00
|
|
|
if (gameMode == GameMode.CREATIVE) {
|
|
|
|
// Needed so the client doesn't attempt to take away items
|
|
|
|
abilities.add(Ability.INSTABUILD);
|
|
|
|
}
|
2022-07-10 17:33:39 +00:00
|
|
|
|
2022-12-21 00:47:45 +00:00
|
|
|
if (commandPermission == CommandPermission.GAME_DIRECTORS) {
|
2022-11-29 02:53:17 +00:00
|
|
|
// Fixes a bug? since 1.19.11 where the player can change their gamemode in Bedrock settings and
|
|
|
|
// a packet is not sent to the server.
|
|
|
|
// https://github.com/GeyserMC/Geyser/issues/3191
|
|
|
|
abilities.add(Ability.OPERATOR_COMMANDS);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flying || spectator) {
|
|
|
|
if (spectator && !flying) {
|
|
|
|
// We're "flying locked" in this gamemode
|
|
|
|
flying = true;
|
|
|
|
ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(true);
|
|
|
|
sendDownstreamPacket(abilitiesPacket);
|
|
|
|
}
|
2022-11-29 02:53:17 +00:00
|
|
|
abilities.add(Ability.FLYING);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (spectator) {
|
2022-11-29 02:53:17 +00:00
|
|
|
abilities.add(Ability.NO_CLIP);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
2023-05-13 21:29:30 +00:00
|
|
|
// https://github.com/GeyserMC/Geyser/issues/3769 Setting Spectator mode ability layer
|
|
|
|
if (spectator) {
|
|
|
|
abilityLayer.setLayerType(AbilityLayer.Type.SPECTATOR);
|
|
|
|
} else {
|
|
|
|
abilityLayer.setLayerType(AbilityLayer.Type.BASE);
|
|
|
|
}
|
2022-11-29 02:53:17 +00:00
|
|
|
abilityLayer.setFlySpeed(flySpeed);
|
|
|
|
// https://github.com/GeyserMC/Geyser/issues/3139 as of 1.19.10
|
|
|
|
abilityLayer.setWalkSpeed(walkSpeed == 0f ? 0.01f : walkSpeed);
|
|
|
|
Collections.addAll(abilityLayer.getAbilitiesSet(), USED_ABILITIES);
|
2021-11-20 21:34:30 +00:00
|
|
|
|
2022-11-29 02:53:17 +00:00
|
|
|
updateAbilitiesPacket.getAbilityLayers().add(abilityLayer);
|
|
|
|
sendUpstreamPacket(updateAbilitiesPacket);
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-16 01:29:00 +00:00
|
|
|
private int getRenderDistance() {
|
|
|
|
if (clientRenderDistance != -1) {
|
|
|
|
// The client has sent a render distance
|
|
|
|
return clientRenderDistance;
|
|
|
|
}
|
|
|
|
return serverRenderDistance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc
|
|
|
|
private static final List<SkinPart> SKIN_PARTS = Arrays.asList(SkinPart.values());
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a packet to the server to indicate client render distance, locale, skin parts, and hand preference.
|
|
|
|
*/
|
|
|
|
public void sendJavaClientSettings() {
|
2022-02-10 14:17:27 +00:00
|
|
|
ServerboundClientInformationPacket clientSettingsPacket = new ServerboundClientInformationPacket(locale(),
|
2022-01-16 01:29:00 +00:00
|
|
|
getRenderDistance(), ChatVisibility.FULL, true, SKIN_PARTS,
|
|
|
|
HandPreference.RIGHT_HAND, false, true);
|
|
|
|
sendDownstreamPacket(clientSettingsPacket);
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
/**
|
|
|
|
* Used for updating statistic values since we only get changes from the server
|
|
|
|
*
|
|
|
|
* @param statistics Updated statistics values
|
|
|
|
*/
|
2022-08-11 23:01:26 +00:00
|
|
|
public void updateStatistics(@NonNull Object2IntMap<Statistic> statistics) {
|
2021-12-08 01:05:44 +00:00
|
|
|
if (this.statistics.isEmpty()) {
|
|
|
|
// Initialize custom statistics to 0, so that they appear in the form
|
|
|
|
for (CustomStatistic customStatistic : CustomStatistic.values()) {
|
|
|
|
this.statistics.put(customStatistic, 0);
|
|
|
|
}
|
|
|
|
}
|
2021-11-20 21:34:30 +00:00
|
|
|
this.statistics.putAll(statistics);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void refreshEmotes(List<UUID> emotes) {
|
|
|
|
this.emotes.addAll(emotes);
|
2021-11-22 19:52:26 +00:00
|
|
|
for (GeyserSession player : geyser.getSessionManager().getSessions().values()) {
|
2021-11-20 21:34:30 +00:00
|
|
|
List<UUID> pieces = new ArrayList<>();
|
|
|
|
for (UUID piece : emotes) {
|
|
|
|
if (!player.getEmotes().contains(piece)) {
|
|
|
|
pieces.add(piece);
|
|
|
|
}
|
|
|
|
player.getEmotes().add(piece);
|
|
|
|
}
|
|
|
|
EmoteListPacket emoteList = new EmoteListPacket();
|
|
|
|
emoteList.setRuntimeEntityId(player.getPlayerEntity().getGeyserId());
|
|
|
|
emoteList.getPieceIds().addAll(pieces);
|
|
|
|
player.sendUpstreamPacket(emoteList);
|
|
|
|
}
|
|
|
|
}
|
2021-12-08 18:23:05 +00:00
|
|
|
|
2022-02-25 03:49:10 +00:00
|
|
|
public boolean canUseCommandBlocks() {
|
|
|
|
return instabuild && opPermissionLevel >= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void playSoundEvent(SoundEvent sound, Vector3f position) {
|
|
|
|
LevelSoundEvent2Packet packet = new LevelSoundEvent2Packet();
|
|
|
|
packet.setPosition(position);
|
|
|
|
packet.setSound(sound);
|
|
|
|
packet.setIdentifier(":");
|
|
|
|
packet.setExtraData(-1);
|
|
|
|
sendUpstreamPacket(packet);
|
|
|
|
}
|
2022-06-05 18:12:36 +00:00
|
|
|
|
2022-07-03 01:17:14 +00:00
|
|
|
public float getEyeHeight() {
|
|
|
|
return switch (pose) {
|
|
|
|
case SNEAKING -> 1.27f;
|
|
|
|
case SWIMMING,
|
|
|
|
FALL_FLYING, // Elytra
|
|
|
|
SPIN_ATTACK -> 0.4f; // Trident spin attack
|
|
|
|
case SLEEPING -> 0.2f;
|
|
|
|
default -> EntityDefinitions.PLAYER.offset();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-11 23:01:26 +00:00
|
|
|
@Override
|
|
|
|
public String bedrockUsername() {
|
|
|
|
return authData.name();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @MonotonicNonNull String javaUsername() {
|
|
|
|
return playerEntity.getUsername();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UUID javaUuid() {
|
|
|
|
return playerEntity.getUuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String xuid() {
|
|
|
|
return authData.xuid();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NonNull String version() {
|
|
|
|
return clientData.getGameVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NonNull BedrockPlatform platform() {
|
|
|
|
return BedrockPlatform.values()[clientData.getDeviceOs().ordinal()]; //todo
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NonNull String languageCode() {
|
|
|
|
return locale();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NonNull UiProfile uiProfile() {
|
|
|
|
return UiProfile.values()[clientData.getUiProfile().ordinal()]; //todo
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NonNull InputMode inputMode() {
|
|
|
|
return InputMode.values()[clientData.getCurrentInputMode().ordinal()]; //todo
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLinked() {
|
|
|
|
return false; //todo
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("ConstantConditions") // Need to enforce the parameter annotations
|
|
|
|
@Override
|
|
|
|
public boolean transfer(@NonNull String address, @IntRange(from = 0, to = 65535) int port) {
|
|
|
|
if (address == null || address.isBlank()) {
|
|
|
|
throw new IllegalArgumentException("Server address cannot be null or blank");
|
|
|
|
} else if (port < 0 || port > 65535) {
|
|
|
|
throw new IllegalArgumentException("Server port must be between 0 and 65535, was " + port);
|
|
|
|
}
|
|
|
|
TransferPacket transferPacket = new TransferPacket();
|
|
|
|
transferPacket.setAddress(address);
|
|
|
|
transferPacket.setPort(port);
|
|
|
|
sendUpstreamPacket(transferPacket);
|
|
|
|
return true;
|
|
|
|
}
|
2023-01-25 16:05:04 +00:00
|
|
|
|
2023-04-15 16:54:30 +00:00
|
|
|
@Override
|
|
|
|
public @NonNull CompletableFuture<@Nullable GeyserEntity> entityByJavaId(@NonNegative int javaId) {
|
|
|
|
CompletableFuture<GeyserEntity> future = new CompletableFuture<>();
|
|
|
|
ensureInEventLoop(() -> future.complete(this.entityCache.getEntityByJavaId(javaId)));
|
|
|
|
return future;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId) {
|
|
|
|
Entity entity = (Entity) emoter;
|
|
|
|
if (entity.getSession() != this) {
|
|
|
|
throw new IllegalStateException("Given entity must be from this session!");
|
|
|
|
}
|
|
|
|
|
|
|
|
EmotePacket packet = new EmotePacket();
|
|
|
|
packet.setRuntimeEntityId(entity.getGeyserId());
|
2023-06-09 03:43:45 +00:00
|
|
|
packet.setXuid("");
|
|
|
|
packet.setPlatformId(""); // BDS sends empty
|
|
|
|
packet.setEmoteId(emoteId);
|
2023-04-15 16:54:30 +00:00
|
|
|
sendUpstreamPacket(packet);
|
|
|
|
}
|
|
|
|
|
2023-07-02 21:00:46 +00:00
|
|
|
@Override
|
|
|
|
public void shakeCamera(float intensity, float duration, @NonNull CameraShake type) {
|
|
|
|
CameraShakePacket packet = new CameraShakePacket();
|
|
|
|
packet.setIntensity(intensity);
|
|
|
|
packet.setDuration(duration);
|
|
|
|
packet.setShakeType(type == CameraShake.POSITIONAL ? CameraShakeType.POSITIONAL : CameraShakeType.ROTATIONAL);
|
|
|
|
packet.setShakeAction(CameraShakeAction.ADD);
|
|
|
|
sendUpstreamPacket(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void stopCameraShake() {
|
|
|
|
CameraShakePacket packet = new CameraShakePacket();
|
|
|
|
// CameraShakeAction.STOP removes all types regardless of the given type, but regardless it can't be null
|
|
|
|
packet.setShakeType(CameraShakeType.POSITIONAL);
|
|
|
|
packet.setShakeAction(CameraShakeAction.STOP);
|
|
|
|
sendUpstreamPacket(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendFog(String... fogNameSpaces) {
|
|
|
|
Collections.addAll(this.appliedFog, fogNameSpaces);
|
|
|
|
|
|
|
|
PlayerFogPacket packet = new PlayerFogPacket();
|
|
|
|
packet.getFogStack().addAll(this.appliedFog);
|
|
|
|
sendUpstreamPacket(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeFog(String... fogNameSpaces) {
|
|
|
|
if (fogNameSpaces.length == 0) {
|
|
|
|
this.appliedFog.clear();
|
|
|
|
} else {
|
|
|
|
for (String id : fogNameSpaces) {
|
|
|
|
this.appliedFog.remove(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PlayerFogPacket packet = new PlayerFogPacket();
|
|
|
|
packet.getFogStack().addAll(this.appliedFog);
|
|
|
|
sendUpstreamPacket(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NonNull Set<String> fogEffects() {
|
|
|
|
// Use a copy so that sendFog/removeFog can be called while iterating the returned set (avoid CME)
|
|
|
|
return Set.copyOf(this.appliedFog);
|
|
|
|
}
|
|
|
|
|
2023-04-06 17:26:28 +00:00
|
|
|
public void addCommandEnum(String name, String enums) {
|
2023-01-25 16:05:04 +00:00
|
|
|
softEnumPacket(name, SoftEnumUpdateType.ADD, enums);
|
|
|
|
}
|
|
|
|
|
2023-04-06 17:26:28 +00:00
|
|
|
public void removeCommandEnum(String name, String enums) {
|
2023-01-25 16:05:04 +00:00
|
|
|
softEnumPacket(name, SoftEnumUpdateType.REMOVE, enums);
|
|
|
|
}
|
|
|
|
|
2023-04-06 17:26:28 +00:00
|
|
|
private void softEnumPacket(String name, SoftEnumUpdateType type, String enums) {
|
2023-08-07 00:39:27 +00:00
|
|
|
// There is no need to send command enums if command suggestions are disabled
|
|
|
|
if (!this.geyser.getConfig().isCommandSuggestions()) {
|
|
|
|
return;
|
|
|
|
}
|
2023-01-25 16:05:04 +00:00
|
|
|
UpdateSoftEnumPacket packet = new UpdateSoftEnumPacket();
|
|
|
|
packet.setType(type);
|
2023-04-08 20:19:42 +00:00
|
|
|
packet.setSoftEnum(new CommandEnumData(name, Collections.singletonMap(enums, Collections.emptySet()), true));
|
2023-01-25 16:05:04 +00:00
|
|
|
sendUpstreamPacket(packet);
|
|
|
|
}
|
2021-11-20 21:34:30 +00:00
|
|
|
}
|