mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
registries/start some packets
This commit is contained in:
parent
c1662eccc4
commit
43f6dcc2f4
6 changed files with 16064 additions and 1 deletions
|
@ -32,8 +32,10 @@ import org.geysermc.connector.console.ConsoleCommandReader;
|
|||
import org.geysermc.connector.console.GeyserLogger;
|
||||
import org.geysermc.connector.network.ConnectorServerEventHandler;
|
||||
import org.geysermc.connector.network.remote.RemoteJavaServer;
|
||||
import org.geysermc.connector.network.translators.TranslatorsInit;
|
||||
import org.geysermc.connector.plugin.GeyserPluginLoader;
|
||||
import org.geysermc.connector.plugin.GeyserPluginManager;
|
||||
import org.geysermc.connector.utils.Toolbox;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -111,6 +113,10 @@ public class GeyserConnector implements Connector {
|
|||
shutdown();
|
||||
}
|
||||
|
||||
Toolbox.CACHED_PALLETE.array();
|
||||
|
||||
TranslatorsInit.start();
|
||||
|
||||
commandMap = new GeyserCommandMap(this);
|
||||
|
||||
remoteServer = new RemoteJavaServer(config.getRemote().getAddress(), config.getRemote().getPort());
|
||||
|
|
|
@ -28,6 +28,7 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Getter;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.network.remote.RemoteJavaServer;
|
||||
import org.geysermc.connector.network.translators.Registry;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -72,7 +73,7 @@ public class GeyserSession implements PlayerSession {
|
|||
|
||||
@Override
|
||||
public void packetReceived(PacketReceivedEvent event) {
|
||||
// TODO: Implement translator code here
|
||||
Registry.JAVA.translate(event.getPacket().getClass(), event.getPacket());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package org.geysermc.connector.network.translators;
|
||||
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Registry<T> {
|
||||
private final Map<Class<? extends T>, Consumer<? extends T>> MAP = new HashMap<>();
|
||||
|
||||
public static final Registry<Packet> JAVA = new Registry<>();
|
||||
|
||||
public static <T extends Packet> void add(Class<T> clazz, Consumer<T> translator) {
|
||||
JAVA.MAP.put(clazz, translator);
|
||||
}
|
||||
|
||||
public <P extends T> void translate(Class<P> clazz, P p) {
|
||||
try {
|
||||
((Consumer<P>) JAVA.MAP.get(clazz)).accept(p);
|
||||
} catch (NullPointerException e) {
|
||||
System.err.println("could not translate packet" + p.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package org.geysermc.connector.network.translators;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2f;
|
||||
import com.flowpowered.math.vector.Vector3f;
|
||||
import com.flowpowered.math.vector.Vector3i;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
||||
import com.nukkitx.protocol.bedrock.data.GameRule;
|
||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||
import org.geysermc.connector.utils.Toolbox;
|
||||
|
||||
public class TranslatorsInit {
|
||||
public static void start() {
|
||||
|
||||
}
|
||||
|
||||
private static void addLoginPackets() {
|
||||
Registry.add(ServerJoinGamePacket.class, (x) -> {
|
||||
StartGamePacket startGamePacket = new StartGamePacket();
|
||||
startGamePacket.setUniqueEntityId(x.getEntityId());
|
||||
startGamePacket.setRuntimeEntityId(x.getEntityId());
|
||||
startGamePacket.setPlayerGamemode(x.getGameMode().ordinal());
|
||||
startGamePacket.setPlayerPosition(new Vector3f(-249, 67, -275));
|
||||
startGamePacket.setRotation(new Vector2f(1, 1));
|
||||
|
||||
startGamePacket.setSeed(1111);
|
||||
startGamePacket.setDimensionId(0);
|
||||
startGamePacket.setGeneratorId(0);
|
||||
startGamePacket.setLevelGamemode(x.getGameMode().ordinal());
|
||||
startGamePacket.setDifficulty(1);
|
||||
startGamePacket.setDefaultSpawn(new Vector3i(-249, 67, -275));
|
||||
startGamePacket.setAcheivementsDisabled(true);
|
||||
startGamePacket.setTime(1300);
|
||||
startGamePacket.setEduLevel(false);
|
||||
startGamePacket.setEduFeaturesEnabled(false);
|
||||
startGamePacket.setRainLevel(0);
|
||||
startGamePacket.setLightningLevel(0);
|
||||
startGamePacket.setMultiplayerGame(false);
|
||||
startGamePacket.setBroadcastingToLan(true);
|
||||
startGamePacket.getGamerules().add((new GameRule("showcoordinates", true)));
|
||||
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.FRIENDS_OF_FRIENDS);
|
||||
startGamePacket.setXblBroadcastMode(GamePublishSetting.FRIENDS_OF_FRIENDS);
|
||||
startGamePacket.setCommandsEnabled(true);
|
||||
startGamePacket.setTexturePacksRequired(false);
|
||||
startGamePacket.setBonusChestEnabled(false);
|
||||
startGamePacket.setStartingWithMap(false);
|
||||
startGamePacket.setTrustingPlayers(true);
|
||||
startGamePacket.setDefaultPlayerPermission(1);
|
||||
startGamePacket.setServerChunkTickRange(4);
|
||||
startGamePacket.setBehaviorPackLocked(false);
|
||||
startGamePacket.setResourcePackLocked(false);
|
||||
startGamePacket.setFromLockedWorldTemplate(false);
|
||||
startGamePacket.setUsingMsaGamertagsOnly(false);
|
||||
startGamePacket.setFromWorldTemplate(false);
|
||||
startGamePacket.setWorldTemplateOptionLocked(false);
|
||||
|
||||
startGamePacket.setLevelId("oerjhii");
|
||||
startGamePacket.setWorldName("world");
|
||||
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
|
||||
startGamePacket.setCurrentTick(1);
|
||||
startGamePacket.setEnchantmentSeed(1);
|
||||
startGamePacket.setMultiplayerCorrelationId("");
|
||||
startGamePacket.setCachedPalette(Toolbox.CACHED_PALLETE);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package org.geysermc.connector.utils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||
import com.nukkitx.network.VarInts;
|
||||
import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Toolbox {
|
||||
static {
|
||||
|
||||
InputStream stream = Toolbox.class.getClassLoader().getResourceAsStream("cached_pallete.json");
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
ArrayList<LinkedHashMap<String, Object>> entries = new ArrayList<>();
|
||||
|
||||
try {
|
||||
entries = mapper.readValue(stream, ArrayList.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ByteBuf b = Unpooled.buffer();
|
||||
|
||||
VarInts.writeInt(b, entries.size());
|
||||
|
||||
for (Map<String, Object> e : entries) {
|
||||
BedrockUtils.writeString(b, (String) e.get("name"));
|
||||
b.writeShortLE((Integer) e.get("data"));
|
||||
}
|
||||
|
||||
CACHED_PALLETE = b;
|
||||
|
||||
}
|
||||
|
||||
public static final ByteBuf CACHED_PALLETE;
|
||||
|
||||
}
|
15917
connector/src/main/resources/cached_pallete.json
Normal file
15917
connector/src/main/resources/cached_pallete.json
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue