forked from git-mirrors/GeyserConnect
Add config
This commit is contained in:
parent
61d3aca4af
commit
fc3b792e84
9 changed files with 106 additions and 35 deletions
|
@ -7,10 +7,10 @@
|
|||
[](http://discord.geysermc.org/)
|
||||
[](http://hits.dwyl.io/GeyserMC/GeyserMulti)-->
|
||||
|
||||
GeyserMulti is an easy way for bedrock clients to connect to any Java edition servers without having to run anything.
|
||||
GeyserMulti is an easy way for Bedrock Edition clients to connect to any Java Edition servers without having to run anything.
|
||||
|
||||
## What is GeyserMulti?
|
||||
GeyserMulti is a server that Minecraft: Bedrock Edition clients can connect to that allows for a list of Minecraft: Java Edition servers to be displayed and accessed through 1 public geyser instance. It is effectively a combination of [BedrockConnect](https://github.com/Pugmatt/BedrockConnect) and [Geyser](https://github.com/GeyserMC/Geyser).
|
||||
GeyserMulti is a server that Minecraft: Bedrock Edition clients can connect to that allows for a list of Minecraft: Java Edition servers to be displayed and accessed through 1 public Geyser instance. It is effectively a combination of [BedrockConnect](https://github.com/Pugmatt/BedrockConnect) and [Geyser](https://github.com/GeyserMC/Geyser).
|
||||
|
||||
**Please note, this project is still a work in progress and should not be used on production. Expect bugs!**
|
||||
|
||||
|
@ -22,6 +22,6 @@ GeyserMulti is a server that Minecraft: Bedrock Edition clients can connect to t
|
|||
- [ ] Add
|
||||
- [ ] Remove
|
||||
- [ ] Stop Geyser server after its idle for a while
|
||||
- [ ] Config file
|
||||
- [x] Config file
|
||||
- [ ] Fix server images not loading straight away on Win10
|
||||
- [ ] Better logging?
|
||||
|
|
30
src/main/java/org/geysermc/multi/GeyserMultiConfig.java
Normal file
30
src/main/java/org/geysermc/multi/GeyserMultiConfig.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package org.geysermc.multi;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class GeyserMultiConfig {
|
||||
private GeyserConfigSection geyser;
|
||||
|
||||
private int port;
|
||||
|
||||
@JsonProperty("max-players")
|
||||
private int maxPlayers;
|
||||
|
||||
private String motd;
|
||||
|
||||
@JsonProperty("debug-mode")
|
||||
private boolean debugMode;
|
||||
|
||||
@Getter
|
||||
public static class GeyserConfigSection {
|
||||
private int port;
|
||||
|
||||
@JsonProperty("debug-mode")
|
||||
private boolean debugMode;
|
||||
}
|
||||
}
|
|
@ -3,16 +3,15 @@ package org.geysermc.multi;
|
|||
import com.nukkitx.protocol.bedrock.*;
|
||||
import com.nukkitx.protocol.bedrock.v390.Bedrock_v390;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.connector.utils.FileUtils;
|
||||
import org.geysermc.multi.proxy.GeyserProxyBootstrap;
|
||||
import org.geysermc.multi.utils.Logger;
|
||||
import org.geysermc.multi.utils.Player;
|
||||
import org.geysermc.multi.utils.Server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
|
@ -42,9 +41,21 @@ public class MasterServer {
|
|||
@Getter
|
||||
private GeyserProxyBootstrap geyserProxy;
|
||||
|
||||
@Getter
|
||||
private GeyserMultiConfig geyserMultiConfig;
|
||||
|
||||
public MasterServer() {
|
||||
logger = new Logger();
|
||||
logger.setDebug(true);
|
||||
|
||||
try {
|
||||
File configFile = FileUtils.fileOrCopiedFromResource(new File("config.yml"), "config.yml", (x) -> x);
|
||||
this.geyserMultiConfig = FileUtils.loadConfig(configFile, GeyserMultiConfig.class);
|
||||
} catch (IOException ex) {
|
||||
logger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
logger.setDebug(geyserMultiConfig.isDebugMode());
|
||||
|
||||
this.instance = this;
|
||||
this.generalThreadPool = Executors.newScheduledThreadPool(32);
|
||||
|
@ -54,7 +65,7 @@ public class MasterServer {
|
|||
TimerTask task = new TimerTask() { public void run() { } };
|
||||
timer.scheduleAtFixedRate(task, 0L, 1000L);
|
||||
|
||||
start(19132);
|
||||
start(geyserMultiConfig.getPort());
|
||||
|
||||
logger.start();
|
||||
}
|
||||
|
@ -67,13 +78,13 @@ public class MasterServer {
|
|||
|
||||
bdPong = new BedrockPong();
|
||||
bdPong.setEdition("MCPE");
|
||||
bdPong.setMotd("My Server");
|
||||
bdPong.setMotd(geyserMultiConfig.getMotd());
|
||||
bdPong.setPlayerCount(0);
|
||||
bdPong.setMaximumPlayerCount(1337);
|
||||
bdPong.setMaximumPlayerCount(geyserMultiConfig.getMaxPlayers());
|
||||
bdPong.setGameType("Survival");
|
||||
bdPong.setIpv4Port(port);
|
||||
bdPong.setProtocolVersion(MasterServer.CODEC.getProtocolVersion());
|
||||
bdPong.setVersion(MasterServer.CODEC.getMinecraftVersion());
|
||||
bdPong.setVersion(null); // Server tries to connect either way and it looks better
|
||||
|
||||
bdServer.setHandler(new BedrockServerEventHandler() {
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.geysermc.multi.proxy;
|
|||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import org.apache.logging.log4j.core.util.IOUtils;
|
||||
import org.geysermc.common.PlatformType;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.bootstrap.GeyserBootstrap;
|
||||
|
@ -10,13 +11,14 @@ import org.geysermc.connector.command.CommandManager;
|
|||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
|
||||
import org.geysermc.connector.utils.FileUtils;
|
||||
import org.geysermc.multi.GeyserMultiConfig;
|
||||
import org.geysermc.multi.MasterServer;
|
||||
import org.geysermc.multi.utils.Logger;
|
||||
import org.geysermc.multi.utils.Server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GeyserProxyBootstrap implements GeyserBootstrap {
|
||||
|
||||
|
@ -35,8 +37,16 @@ public class GeyserProxyBootstrap implements GeyserBootstrap {
|
|||
// Read the static config from resources
|
||||
try {
|
||||
InputStream configFile = GeyserProxyBootstrap.class.getClassLoader().getResourceAsStream("proxy_config.yml");
|
||||
|
||||
// Grab the config as text and replace static strings to the main config variables
|
||||
String text = new BufferedReader(new InputStreamReader(configFile, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
|
||||
GeyserMultiConfig multiConfig = MasterServer.getInstance().getGeyserMultiConfig();
|
||||
text = text.replace("PORT", String.valueOf(multiConfig.getGeyser().getPort()));
|
||||
text = text.replaceAll("MOTD", multiConfig.getMotd());
|
||||
text = text.replace("PLAYERS", String.valueOf(multiConfig.getMaxPlayers()));
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
|
||||
geyserConfig = objectMapper.readValue(configFile, GeyserProxyConfiguration.class);
|
||||
geyserConfig = objectMapper.readValue(text, GeyserProxyConfiguration.class);
|
||||
} catch (IOException ex) {
|
||||
geyserLogger.severe("Failed to read proxy_config.yml! Make sure it's up to date and/or readable+writable!", ex);
|
||||
return;
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.geysermc.multi.proxy;
|
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.geysermc.connector.configuration.GeyserJacksonConfiguration;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package org.geysermc.multi.proxy;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.geysermc.multi.MasterServer;
|
||||
import org.geysermc.multi.utils.Logger;
|
||||
|
||||
@Log4j2
|
||||
public class GeyserProxyLogger extends Logger {
|
||||
/**
|
||||
* Disable debug messages
|
||||
* Disable debug messages depending on config
|
||||
*/
|
||||
public void debug(String message) { }
|
||||
public void debug(String message) {
|
||||
if (MasterServer.getInstance().getGeyserMultiConfig().getGeyser().isDebugMode())
|
||||
super.debug(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,14 @@ package org.geysermc.multi.utils;
|
|||
import lombok.extern.log4j.Log4j2;
|
||||
import net.minecrell.terminalconsole.SimpleTerminalConsole;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
import org.geysermc.common.ChatColor;
|
||||
import org.geysermc.connector.GeyserLogger;
|
||||
import org.geysermc.multi.MasterServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Log4j2
|
||||
public class Logger extends SimpleTerminalConsole implements GeyserLogger {
|
||||
|
||||
|
@ -62,16 +66,4 @@ public class Logger extends SimpleTerminalConsole implements GeyserLogger {
|
|||
public void setDebug(boolean debug) {
|
||||
Configurator.setLevel(log.getName(), debug ? org.apache.logging.log4j.Level.DEBUG : log.getLevel());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "CONSOLE";
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
info(message);
|
||||
}
|
||||
|
||||
public boolean isConsole() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
23
src/main/resources/config.yml
Normal file
23
src/main/resources/config.yml
Normal file
|
@ -0,0 +1,23 @@
|
|||
# --------------------------------
|
||||
# GeyserMulti Configuration File
|
||||
# --------------------------------
|
||||
|
||||
# The port that will listen for connections
|
||||
port: 19132
|
||||
|
||||
# If debug messages should be sent through console
|
||||
debug-mode: false
|
||||
|
||||
# Maximum amount of players that can connect
|
||||
max-players: 100
|
||||
|
||||
# MOTD to display
|
||||
motd: "GeyserMulti Proxy"
|
||||
|
||||
# Config for the geyser listener
|
||||
geyser:
|
||||
# The port that will listen for connections
|
||||
port: 19133
|
||||
|
||||
# If debug messages should be sent through console, has to be enabled in both places to work
|
||||
debug-mode: false
|
|
@ -11,10 +11,10 @@ bedrock:
|
|||
# The IP address that will listen for connections
|
||||
address: 0.0.0.0
|
||||
# The port that will listen for connections
|
||||
port: 19133
|
||||
port: PORT
|
||||
# The MOTD that will be broadcasted to Minecraft: Bedrock Edition clients. Irrelevant if "passthrough-motd" is set to true
|
||||
motd1: "GeyserMC"
|
||||
motd2: "Another GeyserMC forced host."
|
||||
motd1: "MOTD"
|
||||
motd2: "MOTD"
|
||||
remote:
|
||||
# The IP address of the remote (Java Edition) server
|
||||
address: 127.0.0.1
|
||||
|
@ -58,7 +58,7 @@ legacy-ping-passthrough: false
|
|||
ping-passthrough-interval: 3
|
||||
|
||||
# Maximum amount of players that can connect
|
||||
max-players: 100
|
||||
max-players: PLAYERS
|
||||
|
||||
# If debug messages should be sent through console
|
||||
debug-mode: false
|
||||
|
|
Loading…
Add table
Reference in a new issue