diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index b6dc1d1e..96b05845 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -17,6 +17,7 @@ package org.geysermc.connector; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.nukkitx.protocol.bedrock.BedrockPacketCodec; +import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.v354.Bedrock_v354; import lombok.Getter; import org.geysermc.api.ChatColor; @@ -29,6 +30,7 @@ import org.geysermc.connector.command.GeyserCommandMap; import org.geysermc.connector.configuration.GeyserConfiguration; import org.geysermc.connector.console.ConsoleCommandReader; import org.geysermc.connector.console.GeyserLogger; +import org.geysermc.connector.network.listener.ConnectorServerEventListener; import org.geysermc.connector.plugin.GeyserPluginLoader; import org.geysermc.connector.plugin.GeyserPluginManager; @@ -36,6 +38,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.InetSocketAddress; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -110,6 +113,17 @@ public class GeyserConnector implements Connector { pluginManager = new GeyserPluginManager(new GeyserPluginLoader(this)); pluginManager.getLoader().loadPlugins(); + + BedrockServer bedrockServer = new BedrockServer(new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort())); + bedrockServer.setHandler(new ConnectorServerEventListener(this)); + bedrockServer.bind().whenComplete((avoid, throwable) -> { + if (throwable == null) { + logger.info("Started RakNet on " + config.getBedrock().getAddress() + ":" + config.getBedrock().getPort()); + } else { + logger.severe("Failed to start RakNet on " + config.getBedrock().getAddress() + ":" + config.getBedrock().getPort()); + throwable.printStackTrace(); + } + }).join(); } public void shutdown() { diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java index 0bdd7bc8..6e63fd55 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java @@ -26,5 +26,6 @@ public class GeyserConfiguration { @JsonProperty("ping-passthrough") private boolean pingPassthrough; - + @JsonProperty("max-players") + private int maxPlayers; } \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/network/listener/ConnectorServerEventListener.java b/connector/src/main/java/org/geysermc/connector/network/listener/ConnectorServerEventListener.java new file mode 100644 index 00000000..265e4608 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/listener/ConnectorServerEventListener.java @@ -0,0 +1,58 @@ +/* + * GNU LESSER GENERAL PUBLIC LICENSE + * Version 3, 29 June 2007 + * + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + * + * You can view the LICENCE file for details. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.network.listener; + +import com.nukkitx.protocol.bedrock.BedrockPong; +import com.nukkitx.protocol.bedrock.BedrockServerEventHandler; +import com.nukkitx.protocol.bedrock.BedrockServerSession; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.configuration.GeyserConfiguration; + +import java.net.InetSocketAddress; + +public class ConnectorServerEventListener implements BedrockServerEventHandler { + + private GeyserConnector connector; + + public ConnectorServerEventListener(GeyserConnector connector) { + this.connector = connector; + } + + @Override + public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) { + return true; + } + + @Override + public BedrockPong onQuery(InetSocketAddress inetSocketAddress) { + GeyserConfiguration config = connector.getConfig(); + BedrockPong pong = new BedrockPong(); + pong.setEdition("MCPE"); + pong.setMotd(config.getBedrock().getMotd1()); + pong.setSubMotd(config.getBedrock().getMotd2()); + pong.setPlayerCount(0); + pong.setMaximumPlayerCount(config.getMaxPlayers()); + pong.setGameType("Default"); + pong.setNintendoLimited(false); + pong.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion()); + + return pong; + } + + @Override + public void onSessionCreation(BedrockServerSession bedrockServerSession) { + + } +} \ No newline at end of file diff --git a/connector/src/main/resources/config.yml b/connector/src/main/resources/config.yml index 8bd2fc5d..8e0c13d7 100644 --- a/connector/src/main/resources/config.yml +++ b/connector/src/main/resources/config.yml @@ -24,6 +24,8 @@ remote: # Relay the MOTD, player count and max players from the remote server ping-passthrough: false +# Maximum amount of players that can connect +max-players: 100