2019-07-24 20:12:42 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2019-07-24 20:12:42 +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.translator.protocol.java;
|
2019-07-24 20:12:42 +00:00
|
|
|
|
2023-09-29 21:14:49 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerSpawnInfo;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket;
|
2021-11-13 03:44:15 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
2022-10-30 00:23:21 +00:00
|
|
|
import org.cloudburstmc.protocol.bedrock.data.GameRuleData;
|
|
|
|
import org.cloudburstmc.protocol.bedrock.packet.GameRulesChangedPacket;
|
|
|
|
import org.cloudburstmc.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
2022-03-20 00:56:34 +00:00
|
|
|
import org.geysermc.floodgate.pluginmessage.PluginMessageChannels;
|
2022-03-20 02:55:29 +00:00
|
|
|
import org.geysermc.geyser.api.network.AuthType;
|
2022-05-26 23:34:27 +00:00
|
|
|
import org.geysermc.geyser.entity.type.player.SessionPlayerEntity;
|
2023-03-30 19:44:55 +00:00
|
|
|
import org.geysermc.geyser.erosion.GeyserboundHandshakePacketHandler;
|
2021-11-22 19:52:26 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
|
|
|
import org.geysermc.geyser.translator.protocol.Translator;
|
|
|
|
import org.geysermc.geyser.util.ChunkUtils;
|
|
|
|
import org.geysermc.geyser.util.DimensionUtils;
|
2023-09-06 22:13:19 +00:00
|
|
|
import org.geysermc.geyser.util.EntityUtils;
|
2022-05-24 23:16:40 +00:00
|
|
|
|
2021-11-13 03:44:15 +00:00
|
|
|
@Translator(packet = ClientboundLoginPacket.class)
|
2021-11-13 04:01:45 +00:00
|
|
|
public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket> {
|
2019-07-24 20:12:42 +00:00
|
|
|
|
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public void translate(GeyserSession session, ClientboundLoginPacket packet) {
|
2022-05-26 23:34:27 +00:00
|
|
|
SessionPlayerEntity entity = session.getPlayerEntity();
|
2019-12-27 11:29:46 +00:00
|
|
|
entity.setEntityId(packet.getEntityId());
|
2021-06-08 03:09:42 +00:00
|
|
|
|
2023-03-30 19:44:55 +00:00
|
|
|
if (session.getErosionHandler().isActive()) {
|
|
|
|
session.getErosionHandler().close();
|
|
|
|
session.setErosionHandler(new GeyserboundHandshakePacketHandler(session));
|
|
|
|
}
|
|
|
|
|
2023-09-29 21:14:49 +00:00
|
|
|
PlayerSpawnInfo spawnInfo = packet.getCommonPlayerSpawnInfo();
|
2022-05-25 19:55:15 +00:00
|
|
|
|
2020-07-05 23:33:05 +00:00
|
|
|
// If the player is already initialized and a join game packet is sent, they
|
|
|
|
// are swapping servers
|
|
|
|
if (session.isSpawned()) {
|
2023-09-29 21:14:49 +00:00
|
|
|
String fakeDim = DimensionUtils.getTemporaryDimension(session.getDimension(), spawnInfo.getDimension());
|
2020-07-05 23:33:05 +00:00
|
|
|
DimensionUtils.switchDimension(session, fakeDim);
|
2020-07-06 13:10:36 +00:00
|
|
|
|
2020-08-08 22:41:12 +00:00
|
|
|
session.getWorldCache().removeScoreboard();
|
2020-07-05 23:33:05 +00:00
|
|
|
}
|
2023-09-29 21:14:49 +00:00
|
|
|
session.setWorldName(spawnInfo.getWorldName());
|
2022-12-13 18:53:28 +00:00
|
|
|
session.setLevels(packet.getWorldNames());
|
2019-12-27 11:29:46 +00:00
|
|
|
|
2023-09-29 21:14:49 +00:00
|
|
|
session.setGameMode(spawnInfo.getGameMode());
|
2021-05-03 01:47:11 +00:00
|
|
|
|
2023-09-29 21:14:49 +00:00
|
|
|
String newDimension = spawnInfo.getDimension();
|
2022-05-25 22:44:33 +00:00
|
|
|
|
2021-11-13 16:03:55 +00:00
|
|
|
boolean needsSpawnPacket = !session.isSentSpawnPacket();
|
|
|
|
if (needsSpawnPacket) {
|
|
|
|
// The player has yet to spawn so let's do that using some of the information in this Java packet
|
|
|
|
session.setDimension(newDimension);
|
2022-11-12 15:28:53 +00:00
|
|
|
DimensionUtils.setBedrockDimension(session, newDimension);
|
2021-11-13 16:03:55 +00:00
|
|
|
session.connect();
|
2022-06-10 14:27:07 +00:00
|
|
|
|
|
|
|
// It is now safe to send these packets
|
|
|
|
session.getUpstream().sendPostStartGamePackets();
|
2021-11-13 16:03:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!needsSpawnPacket) {
|
|
|
|
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
2023-09-29 21:14:49 +00:00
|
|
|
playerGameTypePacket.setGamemode(EntityUtils.toBedrockGamemode(spawnInfo.getGameMode()).ordinal());
|
2021-11-13 16:03:55 +00:00
|
|
|
session.sendUpstreamPacket(playerGameTypePacket);
|
|
|
|
}
|
2019-09-16 01:25:16 +00:00
|
|
|
|
2023-09-29 21:14:49 +00:00
|
|
|
entity.setLastDeathPosition(spawnInfo.getLastDeathPos());
|
2022-05-26 23:34:27 +00:00
|
|
|
|
2021-11-19 01:44:03 +00:00
|
|
|
entity.updateBedrockMetadata();
|
2019-09-16 01:25:16 +00:00
|
|
|
|
2020-07-30 20:31:12 +00:00
|
|
|
// Send if client should show respawn screen
|
|
|
|
GameRulesChangedPacket gamerulePacket = new GameRulesChangedPacket();
|
|
|
|
gamerulePacket.getGameRules().add(new GameRuleData<>("doimmediaterespawn", !packet.isEnableRespawnScreen()));
|
|
|
|
session.sendUpstreamPacket(gamerulePacket);
|
|
|
|
|
2021-04-21 20:57:01 +00:00
|
|
|
session.setReducedDebugInfo(packet.isReducedDebugInfo());
|
|
|
|
|
2022-01-16 01:29:00 +00:00
|
|
|
session.setServerRenderDistance(packet.getViewDistance());
|
2019-12-28 13:35:21 +00:00
|
|
|
|
2023-09-29 21:14:49 +00:00
|
|
|
// send this again now that we know the server render distance
|
|
|
|
// as the bedrock client isn't required to send a render distance
|
2022-01-16 01:29:00 +00:00
|
|
|
session.sendJavaClientSettings();
|
2020-05-05 02:32:37 +00:00
|
|
|
|
2022-04-24 16:42:17 +00:00
|
|
|
if (session.remoteServer().authType() == AuthType.FLOODGATE) {
|
2022-03-20 00:56:34 +00:00
|
|
|
session.sendDownstreamPacket(new ServerboundCustomPayloadPacket("minecraft:register", PluginMessageChannels.getFloodgateRegisterData()));
|
2020-11-18 18:38:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 00:28:45 +00:00
|
|
|
if (!newDimension.equals(session.getDimension())) {
|
2020-08-10 02:43:57 +00:00
|
|
|
DimensionUtils.switchDimension(session, newDimension);
|
2021-12-08 18:23:05 +00:00
|
|
|
} else if (DimensionUtils.isCustomBedrockNetherId() && newDimension.equalsIgnoreCase(DimensionUtils.NETHER)) {
|
|
|
|
// If the player is spawning into the "fake" nether, send them some fog
|
2023-07-02 21:00:46 +00:00
|
|
|
session.sendFog(DimensionUtils.BEDROCK_FOG_HELL);
|
2019-12-28 13:35:21 +00:00
|
|
|
}
|
2022-11-11 16:10:08 +00:00
|
|
|
|
|
|
|
ChunkUtils.loadDimension(session);
|
2019-07-24 20:12:42 +00:00
|
|
|
}
|
|
|
|
}
|