From 1ddef77eccfb1675823bf491a0e5f2dc331b1efa Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Mon, 8 Jul 2019 18:35:32 -0500 Subject: [PATCH] Get server to show up in server list --- .../geysermc/connector/GeyserConnector.java | 14 +++++ .../configuration/GeyserConfiguration.java | 3 +- .../ConnectorServerEventListener.java | 58 +++++++++++++++++++ connector/src/main/resources/config.yml | 2 + 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/listener/ConnectorServerEventListener.java diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index b6dc1d1e2..96b05845b 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 0bdd7bc8a..6e63fd557 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 000000000..265e46083 --- /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 8bd2fc5da..8e0c13d7e 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