Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,38 @@ public synchronized String format(LogRecord lr) {

@Override
public void severe(String message) {
waitFor();
System.out.println(printConsole(ChatColor.DARK_RED + message, colored));
}

@Override
public void error(String message) {
waitFor();
System.out.println(printConsole(ChatColor.RED + message, colored));
}

@Override
public void warning(String message) {
waitFor();
System.out.println(printConsole(ChatColor.YELLOW + message, colored));
}

@Override
public void info(String message) {
waitFor();
System.out.println(printConsole(ChatColor.WHITE + message, colored));
}

@Override
public void debug(String message) {
waitFor();
System.out.println(printConsole(ChatColor.GRAY + message, colored));
}

private synchronized void waitFor() {

}

public void stop() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import com.nukkitx.protocol.bedrock.BedrockServerEventHandler;
import com.nukkitx.protocol.bedrock.BedrockServerSession;
import com.nukkitx.protocol.bedrock.v361.Bedrock_v361;
import org.geysermc.api.Geyser;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.network.session.GeyserSession;

import java.net.InetSocketAddress;
Expand All @@ -45,13 +47,13 @@ public ConnectorServerEventHandler(GeyserConnector connector) {

@Override
public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
System.out.println(inetSocketAddress + " tried to connect!");
GeyserLogger.DEFAULT.info(inetSocketAddress + " tried to connect!");
return true;
}

@Override
public BedrockPong onQuery(InetSocketAddress inetSocketAddress) {
System.out.println(inetSocketAddress + " has pinged you!");
GeyserLogger.DEFAULT.info(inetSocketAddress + " has pinged you!");
GeyserConfiguration config = connector.getConfig();
BedrockPong pong = new BedrockPong();
pong.setEdition("MCPE");
Expand All @@ -63,6 +65,7 @@ public BedrockPong onQuery(InetSocketAddress inetSocketAddress) {
pong.setNintendoLimited(false);
pong.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion());
pong.setVersion("1.12.0");
pong.setIpv4Port(19132);

return pong;
}
Expand All @@ -71,7 +74,7 @@ public BedrockPong onQuery(InetSocketAddress inetSocketAddress) {
public void onSessionCreation(BedrockServerSession bedrockServerSession) {
bedrockServerSession.setLogging(true);
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession)));
bedrockServerSession.addDisconnectHandler((x) -> System.out.println("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconected for reason " + x));
bedrockServerSession.addDisconnectHandler((x) -> GeyserLogger.DEFAULT.warning("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconnected for reason " + x));
bedrockServerSession.setPacketCodec(Bedrock_v361.V361_CODEC);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.github.steveice10.packetlib.packet.Packet;
import org.geysermc.api.Geyser;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.network.session.GeyserSession;

import java.util.HashMap;
Expand All @@ -47,7 +48,7 @@ public <P extends T> void translate(Class<P> clazz, P p, GeyserSession s) {
try {
((BiConsumer<P, GeyserSession>) JAVA.MAP.get(clazz)).accept(p, s);
} catch (NullPointerException e) {
System.err.println("could not translate packet" + p.getClass().getSimpleName());
GeyserLogger.DEFAULT.warning("could not translate packet " + p.getClass().getSimpleName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,82 @@
package org.geysermc.connector.network.translators;

import com.flowpowered.math.vector.Vector2f;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3f;
import com.flowpowered.math.vector.Vector3i;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTOutputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
import com.nukkitx.protocol.bedrock.data.GameRule;
import com.nukkitx.protocol.bedrock.packet.*;
import com.nukkitx.protocol.bedrock.v340.serializer.FullChunkDataSerializer_v340;
import com.nukkitx.protocol.bedrock.v340.serializer.ResourcePackChunkDataSerializer_v340;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import org.geysermc.connector.utils.GeyserUtils;
import org.geysermc.connector.utils.Toolbox;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;

public class TranslatorsInit {
private static final CompoundTag EMPTY_TAG = CompoundTagBuilder.builder().buildRootTag();
private static final byte[] EMPTY_LEVEL_CHUNK_DATA;

static {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
outputStream.write(new byte[258]); // Biomes + Border Size + Extra Data Size

try (NBTOutputStream stream = NbtUtils.createNetworkWriter(outputStream)) {
stream.write(EMPTY_TAG);
}

EMPTY_LEVEL_CHUNK_DATA = outputStream.toByteArray();
}catch (IOException e) {
throw new AssertionError("Unable to generate empty level chunk data");
}
}

public static void start() {
addLoginPackets();
}

private static void addLoginPackets() {
Registry.add(ServerJoinGamePacket.class, (x, y) -> {
Registry.add(ServerJoinGamePacket.class, (packet, session) -> {
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();

bedrockPacket.setUniqueEntityId(x.getEntityId());

y.getUpstream().sendPacketImmediately(bedrockPacket);
bedrockPacket.setUniqueEntityId(packet.getEntityId());

System.out.println(y.getUpstream().isClosed());
session.getUpstream().sendPacketImmediately(bedrockPacket);

StartGamePacket startGamePacket = new StartGamePacket();
startGamePacket.setUniqueEntityId(x.getEntityId());
startGamePacket.setRuntimeEntityId(x.getEntityId());
startGamePacket.setPlayerGamemode(x.getGameMode().ordinal());
startGamePacket.setUniqueEntityId(packet.getEntityId());
startGamePacket.setRuntimeEntityId(packet.getEntityId());
startGamePacket.setPlayerGamemode(packet.getGameMode().ordinal());
startGamePacket.setPlayerPosition(new Vector3f(0, 0, 0));
startGamePacket.setRotation(new Vector2f(1, 1));

startGamePacket.setSeed(1111);
startGamePacket.setDimensionId(0);
startGamePacket.setGeneratorId(0);
startGamePacket.setLevelGamemode(x.getGameMode().ordinal());
startGamePacket.setLevelGamemode(packet.getGameMode().ordinal());
startGamePacket.setDifficulty(1);
startGamePacket.setDefaultSpawn(new Vector3i(0, 0, 0));
startGamePacket.setAcheivementsDisabled(true);
startGamePacket.setTime(1300);
startGamePacket.setTime(0);
startGamePacket.setEduLevel(false);
startGamePacket.setEduFeaturesEnabled(false);
startGamePacket.setRainLevel(0);
startGamePacket.setLightningLevel(0);
startGamePacket.setMultiplayerGame(false);
startGamePacket.setMultiplayerGame(true);
startGamePacket.setBroadcastingToLan(true);
startGamePacket.getGamerules().add((new GameRule("showcoordinates", true)));
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.FRIENDS_OF_FRIENDS);
startGamePacket.setXblBroadcastMode(GamePublishSetting.FRIENDS_OF_FRIENDS);
startGamePacket.getGamerules().add(new GameRule<>("showcoordinates", true));
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC);
startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC);
startGamePacket.setCommandsEnabled(true);
startGamePacket.setTexturePacksRequired(false);
startGamePacket.setBonusChestEnabled(false);
Expand All @@ -93,48 +119,61 @@ private static void addLoginPackets() {
startGamePacket.setLevelId("oerjhii");
startGamePacket.setWorldName("world");
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
startGamePacket.setCurrentTick(1);
startGamePacket.setEnchantmentSeed(1);
startGamePacket.setCurrentTick(0);
startGamePacket.setEnchantmentSeed(0);
startGamePacket.setMultiplayerCorrelationId("");
startGamePacket.setCachedPalette(Toolbox.CACHED_PALLETE);
startGamePacket.setItemEntries(Toolbox.ITEMS);

y.getUpstream().sendPacketImmediately(startGamePacket);

System.out.println(y.getUpstream().isClosed());
session.getUpstream().sendPacket(startGamePacket);

Vector3f pos = new Vector3f(0, 0, 0);

int chunkX = pos.getFloorX() >> 4;

int chunkZ = pos.getFloorX() >> 4;
int chunkZ = pos.getFloorZ() >> 4;

for (int x1 = -3; x1 < 3; x1++) {
for (int x = -3; x < 3; x++) {

for (int z = -3; z < 3; z++) {

LevelChunkPacket data = new LevelChunkPacket();

data.setChunkX(chunkX + x1);

data.setChunkX(chunkX + x);
data.setChunkZ(chunkZ + z);
data.setSubChunksLength(0);

data.setData(new byte[0]);
data.setData(EMPTY_LEVEL_CHUNK_DATA);

y.getUpstream().sendPacketImmediately(data);

System.out.println(y.getUpstream().isClosed());
session.getUpstream().sendPacketImmediately(data);

}

}

PlayStatusPacket packet = new PlayStatusPacket();

packet.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
PlayStatusPacket packet1 = new PlayStatusPacket();

y.getUpstream().sendPacket(packet);
packet1.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);

System.out.println(y.getUpstream().isClosed());
session.getUpstream().sendPacket(packet1);
});
}

private static byte[] empty(byte[] b, Vector2i pos) {
ByteBuf by = Unpooled.buffer();

GeyserUtils.writePEChunkCoord(by, pos);

return by.array();
}

private static class CanWriteToBB extends ByteArrayOutputStream {

CanWriteToBB() {
super(8192);
}

void writeTo(ByteBuf buf) {
buf.writeBytes(super.buf, 0, super.count);
}
}
}
Loading