Add a config to disable multiverse networking

This commit is contained in:
James Seibel
2023-07-23 17:35:05 -05:00
parent a00cfbb7de
commit af5bb351e8
3 changed files with 54 additions and 14 deletions
@@ -736,6 +736,17 @@ public class Config
+ "")
.build();
public static ConfigEntry<Boolean> enableMultiverseNetworking = new ConfigEntry.Builder<Boolean>()
.set(true)
.comment(""
+ "If true Distant Horizons will attempt to communicate with the connected \n"
+ "server in order to improve multiverse support. \n"
+ "If you experience network issues when attempting to join a server, disable this option. \n"
+ "\n"
+ "Note: this requires setup on the server in order to function. \n"
+ "")
.build();
}
public static class MultiThreading
@@ -85,6 +85,8 @@ public class NetworkClient extends NetworkEventSource implements AutoCloseable
LOGGER.info("Connecting to server: "+this.address);
this.connectionState = EConnectionState.OPEN;
// FIXME sometimes this causes the MC connection to crash
// this might happen if the URL can't be converted to a IP (IE UnknownHostException)
ChannelFuture connectFuture = this.clientBootstrap.connect(this.address);
connectFuture.addListener((ChannelFuture channelFuture) ->
{
@@ -1,5 +1,6 @@
package com.seibel.distanthorizons.core.world;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
import com.seibel.distanthorizons.core.level.IDhLevel;
@@ -32,9 +33,13 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
// TODO why does this executor have 2 threads?
public ExecutorService dhTickerThread = ThreadUtil.makeSingleThreadPool("DH Client World Ticker Thread", 2);
public EventLoop eventLoop = new EventLoop(this.dhTickerThread, this::_clientTick);
//==============//
// constructors //
//==============//
public DhClientWorld()
{
super(EWorldEnvironment.Client_Only);
@@ -42,32 +47,50 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
this.saveStructure = new ClientOnlySaveStructure();
this.levels = new ConcurrentHashMap<>();
// TODO server specific configs
this.networkClient = new NetworkClient(MC_CLIENT.getCurrentServerIp(), 25049);
registerNetworkHandlers();
if (Config.Client.Advanced.Multiplayer.enableMultiverseNetworking.get())
{
// TODO server specific configs
this.networkClient = new NetworkClient(MC_CLIENT.getCurrentServerIp(), 25049);
this.registerNetworkHandlers();
}
else
{
this.networkClient = null;
}
LOGGER.info("Started DhWorld of type "+this.environment);
}
private void registerNetworkHandlers() {
networkClient.registerHandler(HelloMessage.class, (msg, ctx) -> {
private void registerNetworkHandlers()
{
this.networkClient.registerHandler(HelloMessage.class, (msg, ctx) ->
{
ctx.writeAndFlush(new PlayerUUIDMessage(MC_CLIENT.getPlayerUUID()));
});
// TODO Proper payload handling
networkClient.registerAckHandler(PlayerUUIDMessage.class, ctx -> {
this.networkClient.registerAckHandler(PlayerUUIDMessage.class, ctx ->
{
ctx.writeAndFlush(new RemotePlayerConfigMessage(new RemotePlayer.Payload()));
});
networkClient.registerHandler(RemotePlayerConfigMessage.class, (msg, ctx) -> {
this.networkClient.registerHandler(RemotePlayerConfigMessage.class, (msg, ctx) ->
{
});
networkClient.registerAckHandler(RemotePlayerConfigMessage.class, ctx -> {
this.networkClient.registerAckHandler(RemotePlayerConfigMessage.class, ctx ->
{
// TODO Actually request chunks
ctx.writeAndFlush(new RequestChunksMessage());
});
}
//=========//
// methods //
//=========//
@Override
public DhClientLevel getOrLoadLevel(ILevelWrapper wrapper)
{
@@ -134,7 +157,11 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
@Override
public void close()
{
this.networkClient.close();
if (this.networkClient != null)
{
this.networkClient.close();
}
this.saveAndFlush();
for (DhClientLevel dhClientLevel : this.levels.values())