Comment out all Netty related files
Done to allow 1.16 to compile
This commit is contained in:
@@ -46,7 +46,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftCli
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
@@ -329,123 +329,123 @@ public class ClientApi
|
||||
// networking //
|
||||
//============//
|
||||
|
||||
/** @param byteBuf is Netty's {@link ByteBuffer} wrapper. */
|
||||
public void serverMessageReceived(ByteBuf byteBuf)
|
||||
{
|
||||
if (!Config.Client.Advanced.Multiplayer.enableMultiverseNetworking.get())
|
||||
{
|
||||
// multiverse networking disabled, ignore anything sent from the server
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// either value can be set to true to debug the received byte stream
|
||||
boolean stopAndDisplayInputAsByteArray = false;
|
||||
boolean stopAndDisplayInputAsString = false;
|
||||
if (stopAndDisplayInputAsByteArray || stopAndDisplayInputAsString)
|
||||
{
|
||||
String messageString = "";
|
||||
if (stopAndDisplayInputAsByteArray)
|
||||
{
|
||||
int byteCount = byteBuf.readableBytes();
|
||||
byte[] arr = new byte[byteCount];
|
||||
StringBuilder stringBuilder = new StringBuilder("Server message received: [");
|
||||
for (int i = 0; i < byteCount; i++)
|
||||
{
|
||||
arr[i] = byteBuf.readByte();
|
||||
stringBuilder.append(arr[i]);
|
||||
}
|
||||
stringBuilder.append("]");
|
||||
|
||||
messageString = stringBuilder.toString();
|
||||
}
|
||||
else if (stopAndDisplayInputAsString)
|
||||
{
|
||||
messageString = byteBuf.toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
// this is logged as an error so it is easier to see in an Intellij log
|
||||
LOGGER.error(messageString);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// It is important to ensure malicious server input is ignored.
|
||||
if (this.serverNetworkingIsMalformed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// check that the incoming message is within the expected size
|
||||
short commandLength = byteBuf.readShort();
|
||||
if (commandLength < 1 || commandLength > 32)
|
||||
{
|
||||
LOGGER.error("Server command length ["+commandLength+"] outside the expected range of 1 to 32 (inclusive).");
|
||||
ClientApi.INSTANCE.serverNetworkingIsMalformed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// parse the command
|
||||
String eventType;
|
||||
try
|
||||
{
|
||||
eventType = byteBuf.readCharSequence(commandLength, StandardCharsets.UTF_8).toString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Server sent un-parsable command. Error: "+e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
switch (eventType)
|
||||
{
|
||||
case "ServerCommsEnabled":
|
||||
LOGGER.info("Server supports DH multiverse protocol.");
|
||||
ClientApi.INSTANCE.isServerCommunicationEnabled = true;
|
||||
KEYED_CLIENT_LEVEL_MANAGER.setUseOverrideWrapper(true);
|
||||
MC.executeOnRenderThread(() ->
|
||||
{
|
||||
// Unload the current world, since it may be wrong.
|
||||
// A followup WorldChanged event should be received from the server soon after this.
|
||||
LOGGER.info("Unloading current client level so the server can define the correct multiverse level.");
|
||||
this.clientLevelUnloadEvent((IClientLevelWrapper) MC.getWrappedClientWorld());
|
||||
});
|
||||
break;
|
||||
|
||||
case "LevelChanged":
|
||||
short levelKeyLength = byteBuf.readShort();
|
||||
if (levelKeyLength < 1 || levelKeyLength > 128) // TODO 128 should be put into a constant somewhere
|
||||
{
|
||||
LOGGER.error("Server [LevelChanged] command length ["+commandLength+"] outside the expected range of 1 to 128 (inclusive).");
|
||||
this.serverNetworkingIsMalformed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
String levelKey = byteBuf.readCharSequence(levelKeyLength, StandardCharsets.UTF_8).toString();
|
||||
if (!levelKey.matches("[a-zA-Z0-9_]+"))
|
||||
{
|
||||
LOGGER.error("Server sent invalid world key name, and is being ignored.");
|
||||
this.isServerCommunicationEnabled = false;
|
||||
this.serverNetworkingIsMalformed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Server level change event received, changing the level to ["+levelKey+"].");
|
||||
MC.executeOnRenderThread(() -> {
|
||||
if (MC.getWrappedClientWorld() != null)
|
||||
{
|
||||
this.clientLevelUnloadEvent((IClientLevelWrapper) MC.getWrappedClientWorld());
|
||||
}
|
||||
IServerKeyedClientLevel clientLevel = KEYED_CLIENT_LEVEL_MANAGER.getServerKeyedLevel(MC.getWrappedClientWorld(), levelKey);
|
||||
KEYED_CLIENT_LEVEL_MANAGER.setServerKeyedLevel(clientLevel);
|
||||
this.multiverseClientLevelLoadEvent(clientLevel);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
// /** @param byteBuf is Netty's {@link ByteBuffer} wrapper. */
|
||||
// public void serverMessageReceived(ByteBuf byteBuf)
|
||||
// {
|
||||
// if (!Config.Client.Advanced.Multiplayer.enableMultiverseNetworking.get())
|
||||
// {
|
||||
// // multiverse networking disabled, ignore anything sent from the server
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// // either value can be set to true to debug the received byte stream
|
||||
// boolean stopAndDisplayInputAsByteArray = false;
|
||||
// boolean stopAndDisplayInputAsString = false;
|
||||
// if (stopAndDisplayInputAsByteArray || stopAndDisplayInputAsString)
|
||||
// {
|
||||
// String messageString = "";
|
||||
// if (stopAndDisplayInputAsByteArray)
|
||||
// {
|
||||
// int byteCount = byteBuf.readableBytes();
|
||||
// byte[] arr = new byte[byteCount];
|
||||
// StringBuilder stringBuilder = new StringBuilder("Server message received: [");
|
||||
// for (int i = 0; i < byteCount; i++)
|
||||
// {
|
||||
// arr[i] = byteBuf.readByte();
|
||||
// stringBuilder.append(arr[i]);
|
||||
// }
|
||||
// stringBuilder.append("]");
|
||||
//
|
||||
// messageString = stringBuilder.toString();
|
||||
// }
|
||||
// else if (stopAndDisplayInputAsString)
|
||||
// {
|
||||
// messageString = byteBuf.toString(StandardCharsets.UTF_8);
|
||||
// }
|
||||
//
|
||||
// // this is logged as an error so it is easier to see in an Intellij log
|
||||
// LOGGER.error(messageString);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// // It is important to ensure malicious server input is ignored.
|
||||
// if (this.serverNetworkingIsMalformed)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // check that the incoming message is within the expected size
|
||||
// short commandLength = byteBuf.readShort();
|
||||
// if (commandLength < 1 || commandLength > 32)
|
||||
// {
|
||||
// LOGGER.error("Server command length ["+commandLength+"] outside the expected range of 1 to 32 (inclusive).");
|
||||
// ClientApi.INSTANCE.serverNetworkingIsMalformed = true;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // parse the command
|
||||
// String eventType;
|
||||
// try
|
||||
// {
|
||||
// eventType = byteBuf.readCharSequence(commandLength, StandardCharsets.UTF_8).toString();
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// LOGGER.error("Server sent un-parsable command. Error: "+e.getMessage());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// switch (eventType)
|
||||
// {
|
||||
// case "ServerCommsEnabled":
|
||||
// LOGGER.info("Server supports DH multiverse protocol.");
|
||||
// ClientApi.INSTANCE.isServerCommunicationEnabled = true;
|
||||
// KEYED_CLIENT_LEVEL_MANAGER.setUseOverrideWrapper(true);
|
||||
// MC.executeOnRenderThread(() ->
|
||||
// {
|
||||
// // Unload the current world, since it may be wrong.
|
||||
// // A followup WorldChanged event should be received from the server soon after this.
|
||||
// LOGGER.info("Unloading current client level so the server can define the correct multiverse level.");
|
||||
// this.clientLevelUnloadEvent((IClientLevelWrapper) MC.getWrappedClientWorld());
|
||||
// });
|
||||
// break;
|
||||
//
|
||||
// case "LevelChanged":
|
||||
// short levelKeyLength = byteBuf.readShort();
|
||||
// if (levelKeyLength < 1 || levelKeyLength > 128) // TODO 128 should be put into a constant somewhere
|
||||
// {
|
||||
// LOGGER.error("Server [LevelChanged] command length ["+commandLength+"] outside the expected range of 1 to 128 (inclusive).");
|
||||
// this.serverNetworkingIsMalformed = true;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// String levelKey = byteBuf.readCharSequence(levelKeyLength, StandardCharsets.UTF_8).toString();
|
||||
// if (!levelKey.matches("[a-zA-Z0-9_]+"))
|
||||
// {
|
||||
// LOGGER.error("Server sent invalid world key name, and is being ignored.");
|
||||
// this.isServerCommunicationEnabled = false;
|
||||
// this.serverNetworkingIsMalformed = true;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// LOGGER.info("Server level change event received, changing the level to ["+levelKey+"].");
|
||||
// MC.executeOnRenderThread(() -> {
|
||||
// if (MC.getWrappedClientWorld() != null)
|
||||
// {
|
||||
// this.clientLevelUnloadEvent((IClientLevelWrapper) MC.getWrappedClientWorld());
|
||||
// }
|
||||
// IServerKeyedClientLevel clientLevel = KEYED_CLIENT_LEVEL_MANAGER.getServerKeyedLevel(MC.getWrappedClientWorld(), levelKey);
|
||||
// KEYED_CLIENT_LEVEL_MANAGER.setServerKeyedLevel(clientLevel);
|
||||
// this.multiverseClientLevelLoadEvent(clientLevel);
|
||||
// });
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,152 +5,152 @@ import com.seibel.distanthorizons.core.network.messages.CloseMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.CloseReasonMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.HelloMessage;
|
||||
import com.seibel.distanthorizons.core.network.protocol.NetworkChannelInitializer;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
//import io.netty.bootstrap.Bootstrap;
|
||||
//import io.netty.channel.Channel;
|
||||
//import io.netty.channel.ChannelFuture;
|
||||
//import io.netty.channel.ChannelOption;
|
||||
//import io.netty.channel.EventLoopGroup;
|
||||
//import io.netty.channel.nio.NioEventLoopGroup;
|
||||
//import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class NetworkClient extends NetworkEventSource implements AutoCloseable
|
||||
public class NetworkClient //extends NetworkEventSource implements AutoCloseable
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
private enum EConnectionState
|
||||
{
|
||||
OPEN,
|
||||
RECONNECT,
|
||||
RECONNECT_FORCE,
|
||||
CLOSE_WAIT,
|
||||
CLOSED
|
||||
}
|
||||
|
||||
private static final int FAILURE_RECONNECT_DELAY_SEC = 5;
|
||||
private static final int FAILURE_RECONNECT_ATTEMPTS = 3;
|
||||
|
||||
// TODO move to payload of some sort
|
||||
private final InetSocketAddress address;
|
||||
|
||||
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
private final Bootstrap clientBootstrap = new Bootstrap()
|
||||
.group(this.workerGroup)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
.handler(new NetworkChannelInitializer(this.messageHandler));
|
||||
|
||||
private EConnectionState connectionState;
|
||||
private Channel channel;
|
||||
private int reconnectAttempts = FAILURE_RECONNECT_ATTEMPTS;
|
||||
|
||||
|
||||
|
||||
public NetworkClient(String host, int port)
|
||||
{
|
||||
this.address = new InetSocketAddress(host, port);
|
||||
|
||||
this.registerHandlers();
|
||||
this.connect();
|
||||
}
|
||||
|
||||
private void registerHandlers()
|
||||
{
|
||||
this.registerHandler(HelloMessage.class, (helloMessage, channelContext) ->
|
||||
{
|
||||
LOGGER.info("Connected to server: "+channelContext.channel().remoteAddress());
|
||||
});
|
||||
|
||||
this.registerHandler(CloseReasonMessage.class, (closeReasonMessage, channelContext) ->
|
||||
{
|
||||
LOGGER.info(closeReasonMessage.reason);
|
||||
this.connectionState = EConnectionState.CLOSE_WAIT;
|
||||
});
|
||||
|
||||
this.registerHandler(CloseMessage.class, (closeMessage, channelContext) ->
|
||||
{
|
||||
LOGGER.info("Disconnected from server: "+channelContext.channel().remoteAddress());
|
||||
if (this.connectionState == EConnectionState.CLOSE_WAIT)
|
||||
{
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void connect()
|
||||
{
|
||||
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) ->
|
||||
{
|
||||
if (!channelFuture.isSuccess())
|
||||
{
|
||||
LOGGER.warn("Connection failed: "+channelFuture.cause());
|
||||
return;
|
||||
}
|
||||
|
||||
this.channel.writeAndFlush(new HelloMessage());
|
||||
});
|
||||
|
||||
this.channel = connectFuture.channel();
|
||||
this. channel.closeFuture().addListener((ChannelFuture channelFuture) ->
|
||||
{
|
||||
switch (this.connectionState)
|
||||
{
|
||||
case OPEN:
|
||||
this.reconnectAttempts--;
|
||||
LOGGER.info("Reconnection attempts left: ["+this.reconnectAttempts+"] of ["+FAILURE_RECONNECT_ATTEMPTS+"].");
|
||||
if (this.reconnectAttempts == 0)
|
||||
{
|
||||
this.connectionState = EConnectionState.CLOSE_WAIT;
|
||||
return;
|
||||
}
|
||||
|
||||
this.connectionState = EConnectionState.RECONNECT;
|
||||
this.workerGroup.schedule(this::connect, FAILURE_RECONNECT_DELAY_SEC, TimeUnit.SECONDS);
|
||||
break;
|
||||
|
||||
case RECONNECT_FORCE:
|
||||
LOGGER.info("Reconnecting forcefully.");
|
||||
this.reconnectAttempts = FAILURE_RECONNECT_ATTEMPTS;
|
||||
|
||||
this.connectionState = EConnectionState.RECONNECT;
|
||||
this.workerGroup.schedule(this::connect, 0, TimeUnit.SECONDS);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** Kills the current connection, triggering auto-reconnection immediately. */
|
||||
public void reconnect()
|
||||
{
|
||||
this.connectionState = EConnectionState.RECONNECT_FORCE;
|
||||
this.channel.disconnect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
if (this.closeReason != null)
|
||||
{
|
||||
LOGGER.error(this.closeReason);
|
||||
}
|
||||
|
||||
if (this.connectionState == EConnectionState.CLOSED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.connectionState = EConnectionState.CLOSED;
|
||||
this.workerGroup.shutdownGracefully().syncUninterruptibly();
|
||||
this.channel.close().syncUninterruptibly();
|
||||
}
|
||||
// private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
//
|
||||
// private enum EConnectionState
|
||||
// {
|
||||
// OPEN,
|
||||
// RECONNECT,
|
||||
// RECONNECT_FORCE,
|
||||
// CLOSE_WAIT,
|
||||
// CLOSED
|
||||
// }
|
||||
//
|
||||
// private static final int FAILURE_RECONNECT_DELAY_SEC = 5;
|
||||
// private static final int FAILURE_RECONNECT_ATTEMPTS = 3;
|
||||
//
|
||||
// // TODO move to payload of some sort
|
||||
// private final InetSocketAddress address;
|
||||
//
|
||||
// private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
// private final Bootstrap clientBootstrap = new Bootstrap()
|
||||
// .group(this.workerGroup)
|
||||
// .channel(NioSocketChannel.class)
|
||||
// .option(ChannelOption.SO_KEEPALIVE, true)
|
||||
// .handler(new NetworkChannelInitializer(this.messageHandler));
|
||||
//
|
||||
// private EConnectionState connectionState;
|
||||
// private Channel channel;
|
||||
// private int reconnectAttempts = FAILURE_RECONNECT_ATTEMPTS;
|
||||
//
|
||||
//
|
||||
//
|
||||
// public NetworkClient(String host, int port)
|
||||
// {
|
||||
// this.address = new InetSocketAddress(host, port);
|
||||
//
|
||||
// this.registerHandlers();
|
||||
// this.connect();
|
||||
// }
|
||||
//
|
||||
// private void registerHandlers()
|
||||
// {
|
||||
// this.registerHandler(HelloMessage.class, (helloMessage, channelContext) ->
|
||||
// {
|
||||
// LOGGER.info("Connected to server: "+channelContext.channel().remoteAddress());
|
||||
// });
|
||||
//
|
||||
// this.registerHandler(CloseReasonMessage.class, (closeReasonMessage, channelContext) ->
|
||||
// {
|
||||
// LOGGER.info(closeReasonMessage.reason);
|
||||
// this.connectionState = EConnectionState.CLOSE_WAIT;
|
||||
// });
|
||||
//
|
||||
// this.registerHandler(CloseMessage.class, (closeMessage, channelContext) ->
|
||||
// {
|
||||
// LOGGER.info("Disconnected from server: "+channelContext.channel().remoteAddress());
|
||||
// if (this.connectionState == EConnectionState.CLOSE_WAIT)
|
||||
// {
|
||||
// this.close();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private void connect()
|
||||
// {
|
||||
// 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) ->
|
||||
// {
|
||||
// if (!channelFuture.isSuccess())
|
||||
// {
|
||||
// LOGGER.warn("Connection failed: "+channelFuture.cause());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// this.channel.writeAndFlush(new HelloMessage());
|
||||
// });
|
||||
//
|
||||
// this.channel = connectFuture.channel();
|
||||
// this. channel.closeFuture().addListener((ChannelFuture channelFuture) ->
|
||||
// {
|
||||
// switch (this.connectionState)
|
||||
// {
|
||||
// case OPEN:
|
||||
// this.reconnectAttempts--;
|
||||
// LOGGER.info("Reconnection attempts left: ["+this.reconnectAttempts+"] of ["+FAILURE_RECONNECT_ATTEMPTS+"].");
|
||||
// if (this.reconnectAttempts == 0)
|
||||
// {
|
||||
// this.connectionState = EConnectionState.CLOSE_WAIT;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// this.connectionState = EConnectionState.RECONNECT;
|
||||
// this.workerGroup.schedule(this::connect, FAILURE_RECONNECT_DELAY_SEC, TimeUnit.SECONDS);
|
||||
// break;
|
||||
//
|
||||
// case RECONNECT_FORCE:
|
||||
// LOGGER.info("Reconnecting forcefully.");
|
||||
// this.reconnectAttempts = FAILURE_RECONNECT_ATTEMPTS;
|
||||
//
|
||||
// this.connectionState = EConnectionState.RECONNECT;
|
||||
// this.workerGroup.schedule(this::connect, 0, TimeUnit.SECONDS);
|
||||
// break;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// /** Kills the current connection, triggering auto-reconnection immediately. */
|
||||
// public void reconnect()
|
||||
// {
|
||||
// this.connectionState = EConnectionState.RECONNECT_FORCE;
|
||||
// this.channel.disconnect();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void close()
|
||||
// {
|
||||
// if (this.closeReason != null)
|
||||
// {
|
||||
// LOGGER.error(this.closeReason);
|
||||
// }
|
||||
//
|
||||
// if (this.connectionState == EConnectionState.CLOSED)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// this.connectionState = EConnectionState.CLOSED;
|
||||
// this.workerGroup.shutdownGracefully().syncUninterruptibly();
|
||||
// this.channel.close().syncUninterruptibly();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
+39
-39
@@ -6,7 +6,7 @@ import com.seibel.distanthorizons.core.network.messages.HelloMessage;
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkMessage;
|
||||
import com.seibel.distanthorizons.core.network.protocol.MessageHandler;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -21,43 +21,43 @@ public abstract class NetworkEventSource implements AutoCloseable
|
||||
|
||||
|
||||
|
||||
public NetworkEventSource()
|
||||
{
|
||||
this.registerHandler(HelloMessage.class, (helloMessage, channelContext) ->
|
||||
{
|
||||
if (helloMessage.version != ModInfo.PROTOCOL_VERSION)
|
||||
{
|
||||
try
|
||||
{
|
||||
String closeReason = "Ignoring message from channel ["+channelContext.name()+"], due to version mismatch. Expected version: ["+ModInfo.PROTOCOL_VERSION+"], received version: ["+helloMessage.version+"].";
|
||||
LOGGER.info(closeReason);
|
||||
this.close(closeReason);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public <T extends INetworkMessage> void registerHandler(Class<T> clazz, BiConsumer<T, ChannelHandlerContext> handler) { this.messageHandler.registerHandler(clazz, handler); }
|
||||
|
||||
public <T extends INetworkMessage> void registerAckHandler(Class<T> clazz, Consumer<ChannelHandlerContext> handler)
|
||||
{
|
||||
this.messageHandler.registerHandler(AckMessage.class, (ackMessage, channelContext) ->
|
||||
{
|
||||
if (ackMessage.messageType == clazz)
|
||||
{
|
||||
handler.accept(channelContext);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void close(String reason) throws Exception
|
||||
{
|
||||
this.closeReason = reason;
|
||||
this.close();
|
||||
}
|
||||
// public NetworkEventSource()
|
||||
// {
|
||||
// this.registerHandler(HelloMessage.class, (helloMessage, channelContext) ->
|
||||
// {
|
||||
// if (helloMessage.version != ModInfo.PROTOCOL_VERSION)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// String closeReason = "Ignoring message from channel ["+channelContext.name()+"], due to version mismatch. Expected version: ["+ModInfo.PROTOCOL_VERSION+"], received version: ["+helloMessage.version+"].";
|
||||
// LOGGER.info(closeReason);
|
||||
// this.close(closeReason);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// public <T extends INetworkMessage> void registerHandler(Class<T> clazz, BiConsumer<T, ChannelHandlerContext> handler) { this.messageHandler.registerHandler(clazz, handler); }
|
||||
//
|
||||
// public <T extends INetworkMessage> void registerAckHandler(Class<T> clazz, Consumer<ChannelHandlerContext> handler)
|
||||
// {
|
||||
// this.messageHandler.registerHandler(AckMessage.class, (ackMessage, channelContext) ->
|
||||
// {
|
||||
// if (ackMessage.messageType == clazz)
|
||||
// {
|
||||
// handler.accept(channelContext);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// public void close(String reason) throws Exception
|
||||
// {
|
||||
// this.closeReason = reason;
|
||||
// this.close();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -5,99 +5,99 @@ import com.seibel.distanthorizons.core.network.messages.CloseReasonMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.CloseMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.HelloMessage;
|
||||
import com.seibel.distanthorizons.core.network.protocol.NetworkChannelInitializer;
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.logging.LogLevel;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
//import io.netty.bootstrap.ServerBootstrap;
|
||||
//import io.netty.channel.*;
|
||||
//import io.netty.channel.nio.NioEventLoopGroup;
|
||||
//import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
//import io.netty.handler.logging.LogLevel;
|
||||
//import io.netty.handler.logging.LoggingHandler;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class NetworkServer extends NetworkEventSource implements AutoCloseable
|
||||
public class NetworkServer //extends NetworkEventSource implements AutoCloseable
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
// TODO move to the config
|
||||
private final int port;
|
||||
|
||||
private final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||
private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
private Channel channel;
|
||||
private boolean isClosed = false;
|
||||
|
||||
|
||||
|
||||
public NetworkServer(int port)
|
||||
{
|
||||
this.port = port;
|
||||
|
||||
LOGGER.info("Starting server on port "+port);
|
||||
this.registerHandlers();
|
||||
this.bind();
|
||||
}
|
||||
|
||||
private void registerHandlers()
|
||||
{
|
||||
this.registerHandler(HelloMessage.class, (helloMessage, channelContext) ->
|
||||
{
|
||||
LOGGER.info("Client connected: "+channelContext.channel().remoteAddress());
|
||||
channelContext.channel().writeAndFlush(new HelloMessage());
|
||||
});
|
||||
|
||||
this.registerHandler(CloseMessage.class, (closeMessage, channelContext) ->
|
||||
{
|
||||
LOGGER.info("Client disconnected: "+channelContext.channel().remoteAddress());
|
||||
});
|
||||
}
|
||||
|
||||
private void bind()
|
||||
{
|
||||
ServerBootstrap bootstrap = new ServerBootstrap()
|
||||
.group(this.bossGroup, this.workerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.handler(new LoggingHandler(LogLevel.DEBUG))
|
||||
.childHandler(new NetworkChannelInitializer(this.messageHandler));
|
||||
|
||||
ChannelFuture bindFuture = bootstrap.bind(this.port);
|
||||
bindFuture.addListener((ChannelFuture channelFuture) ->
|
||||
{
|
||||
if (!channelFuture.isSuccess())
|
||||
{
|
||||
throw new RuntimeException("Failed to bind: " + channelFuture.cause());
|
||||
}
|
||||
|
||||
LOGGER.info("Server is started on port "+this.port);
|
||||
});
|
||||
|
||||
this.channel = bindFuture.channel();
|
||||
this.channel.closeFuture().addListener(future -> this.close());
|
||||
}
|
||||
|
||||
public void disconnectClient(ChannelHandlerContext ctx, String reason)
|
||||
{
|
||||
ctx.channel().config().setAutoRead(false);
|
||||
ctx.writeAndFlush(new CloseReasonMessage(reason))
|
||||
.addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
if (this.closeReason != null)
|
||||
{
|
||||
LOGGER.error(this.closeReason);
|
||||
}
|
||||
|
||||
if (this.isClosed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.isClosed = true;
|
||||
|
||||
LOGGER.info("Shutting down the network server.");
|
||||
this.workerGroup.shutdownGracefully().syncUninterruptibly();
|
||||
this.bossGroup.shutdownGracefully().syncUninterruptibly();
|
||||
LOGGER.info("Network server has been closed.");
|
||||
}
|
||||
// private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
//
|
||||
// // TODO move to the config
|
||||
// private final int port;
|
||||
//
|
||||
// private final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||
// private final EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
// private Channel channel;
|
||||
// private boolean isClosed = false;
|
||||
//
|
||||
//
|
||||
//
|
||||
// public NetworkServer(int port)
|
||||
// {
|
||||
// this.port = port;
|
||||
//
|
||||
// LOGGER.info("Starting server on port "+port);
|
||||
// this.registerHandlers();
|
||||
// this.bind();
|
||||
// }
|
||||
//
|
||||
// private void registerHandlers()
|
||||
// {
|
||||
// this.registerHandler(HelloMessage.class, (helloMessage, channelContext) ->
|
||||
// {
|
||||
// LOGGER.info("Client connected: "+channelContext.channel().remoteAddress());
|
||||
// channelContext.channel().writeAndFlush(new HelloMessage());
|
||||
// });
|
||||
//
|
||||
// this.registerHandler(CloseMessage.class, (closeMessage, channelContext) ->
|
||||
// {
|
||||
// LOGGER.info("Client disconnected: "+channelContext.channel().remoteAddress());
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private void bind()
|
||||
// {
|
||||
// ServerBootstrap bootstrap = new ServerBootstrap()
|
||||
// .group(this.bossGroup, this.workerGroup)
|
||||
// .channel(NioServerSocketChannel.class)
|
||||
// .handler(new LoggingHandler(LogLevel.DEBUG))
|
||||
// .childHandler(new NetworkChannelInitializer(this.messageHandler));
|
||||
//
|
||||
// ChannelFuture bindFuture = bootstrap.bind(this.port);
|
||||
// bindFuture.addListener((ChannelFuture channelFuture) ->
|
||||
// {
|
||||
// if (!channelFuture.isSuccess())
|
||||
// {
|
||||
// throw new RuntimeException("Failed to bind: " + channelFuture.cause());
|
||||
// }
|
||||
//
|
||||
// LOGGER.info("Server is started on port "+this.port);
|
||||
// });
|
||||
//
|
||||
// this.channel = bindFuture.channel();
|
||||
// this.channel.closeFuture().addListener(future -> this.close());
|
||||
// }
|
||||
//
|
||||
// public void disconnectClient(ChannelHandlerContext ctx, String reason)
|
||||
// {
|
||||
// ctx.channel().config().setAutoRead(false);
|
||||
// ctx.writeAndFlush(new CloseReasonMessage(reason))
|
||||
// .addListener(ChannelFutureListener.CLOSE);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void close()
|
||||
// {
|
||||
// if (this.closeReason != null)
|
||||
// {
|
||||
// LOGGER.error(this.closeReason);
|
||||
// }
|
||||
//
|
||||
// if (this.isClosed)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// this.isClosed = true;
|
||||
//
|
||||
// LOGGER.info("Shutting down the network server.");
|
||||
// this.workerGroup.shutdownGracefully().syncUninterruptibly();
|
||||
// this.bossGroup.shutdownGracefully().syncUninterruptibly();
|
||||
// LOGGER.info("Network server has been closed.");
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.seibel.distanthorizons.core.network.messages;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkMessage;
|
||||
import com.seibel.distanthorizons.core.network.protocol.MessageRegistry;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* Simple empty response message.
|
||||
@@ -17,10 +17,10 @@ public class AckMessage implements INetworkMessage
|
||||
public AckMessage() { }
|
||||
public AckMessage(Class<? extends INetworkMessage> messageType) { this.messageType = messageType; }
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf out) { out.writeInt(MessageRegistry.INSTANCE.getMessageId(this.messageType)); }
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in) { this.messageType = MessageRegistry.INSTANCE.getMessageClassById(in.readInt()); }
|
||||
// @Override
|
||||
// public void encode(ByteBuf out) { out.writeInt(MessageRegistry.INSTANCE.getMessageId(this.messageType)); }
|
||||
//
|
||||
// @Override
|
||||
// public void decode(ByteBuf in) { this.messageType = MessageRegistry.INSTANCE.getMessageClassById(in.readInt()); }
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,7 +1,7 @@
|
||||
package com.seibel.distanthorizons.core.network.messages;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* This is not a "real" message, and only used to indicate a disconnection.
|
||||
@@ -9,11 +9,11 @@ import io.netty.buffer.ByteBuf;
|
||||
*/
|
||||
public class CloseMessage implements INetworkMessage
|
||||
{
|
||||
@Override
|
||||
public void encode(ByteBuf out) { throw new UnsupportedOperationException("CloseMessage is not a real message, and must not be sent."); }
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in) { throw new UnsupportedOperationException("CloseMessage is not a real message, and must not be received."); }
|
||||
// @Override
|
||||
// public void encode(ByteBuf out) { throw new UnsupportedOperationException("CloseMessage is not a real message, and must not be sent."); }
|
||||
//
|
||||
// @Override
|
||||
// public void decode(ByteBuf in) { throw new UnsupportedOperationException("CloseMessage is not a real message, and must not be received."); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -2,7 +2,7 @@ package com.seibel.distanthorizons.core.network.messages;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkMessage;
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkObject;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class CloseReasonMessage implements INetworkMessage
|
||||
{
|
||||
@@ -13,10 +13,10 @@ public class CloseReasonMessage implements INetworkMessage
|
||||
public CloseReasonMessage() { }
|
||||
public CloseReasonMessage(String reason) { this.reason = reason; }
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf out) { INetworkObject.encodeString(this.reason, out); }
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in) { this.reason = INetworkObject.decodeString(in); }
|
||||
// @Override
|
||||
// public void encode(ByteBuf out) { INetworkObject.encodeString(this.reason, out); }
|
||||
//
|
||||
// @Override
|
||||
// public void decode(ByteBuf in) { this.reason = INetworkObject.decodeString(in); }
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -2,7 +2,7 @@ package com.seibel.distanthorizons.core.network.messages;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkMessage;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class HelloMessage implements INetworkMessage
|
||||
{
|
||||
@@ -10,10 +10,10 @@ public class HelloMessage implements INetworkMessage
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf out) { out.writeInt(this.version); }
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in) { this.version = in.readInt(); }
|
||||
// @Override
|
||||
// public void encode(ByteBuf out) { out.writeInt(this.version); }
|
||||
//
|
||||
// @Override
|
||||
// public void decode(ByteBuf in) { this.version = in.readInt(); }
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,7 +1,7 @@
|
||||
package com.seibel.distanthorizons.core.network.messages;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -14,14 +14,14 @@ public class PlayerUUIDMessage implements INetworkMessage
|
||||
public PlayerUUIDMessage() { }
|
||||
public PlayerUUIDMessage(UUID playerUUID) { this.playerUUID = playerUUID; }
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf out)
|
||||
{
|
||||
out.writeLong(this.playerUUID.getMostSignificantBits());
|
||||
out.writeLong(this.playerUUID.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in) { this.playerUUID = new UUID(in.readLong(), in.readLong()); }
|
||||
// @Override
|
||||
// public void encode(ByteBuf out)
|
||||
// {
|
||||
// out.writeLong(this.playerUUID.getMostSignificantBits());
|
||||
// out.writeLong(this.playerUUID.getLeastSignificantBits());
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void decode(ByteBuf in) { this.playerUUID = new UUID(in.readLong(), in.readLong()); }
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -3,7 +3,7 @@ package com.seibel.distanthorizons.core.network.messages;
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkObject;
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkMessage;
|
||||
import com.seibel.distanthorizons.core.network.objects.RemotePlayer;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class RemotePlayerConfigMessage implements INetworkMessage
|
||||
{
|
||||
@@ -14,10 +14,10 @@ public class RemotePlayerConfigMessage implements INetworkMessage
|
||||
public RemotePlayerConfigMessage() { }
|
||||
public RemotePlayerConfigMessage(RemotePlayer.Payload payload) { this.payload = payload; }
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf out) { this.payload.encode(out); }
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in) { this.payload = INetworkObject.decode(new RemotePlayer.Payload(), in); }
|
||||
// @Override
|
||||
// public void encode(ByteBuf out) { this.payload.encode(out); }
|
||||
//
|
||||
// @Override
|
||||
// public void decode(ByteBuf in) { this.payload = INetworkObject.decode(new RemotePlayer.Payload(), in); }
|
||||
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,21 +1,21 @@
|
||||
package com.seibel.distanthorizons.core.network.messages;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkMessage;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class RequestChunksMessage implements INetworkMessage
|
||||
{
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf out)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in)
|
||||
{
|
||||
|
||||
}
|
||||
// @Override
|
||||
// public void encode(ByteBuf out)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void decode(ByteBuf in)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
+8
-8
@@ -2,14 +2,14 @@ package com.seibel.distanthorizons.core.network.objects;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkObject;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
public class RemotePlayer
|
||||
{
|
||||
public IServerPlayerWrapper serverPlayer;
|
||||
public Payload payload;
|
||||
public ChannelHandlerContext channelContext;
|
||||
// public ChannelHandlerContext channelContext;
|
||||
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ public class RemotePlayer
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf out) { out.writeInt(this.renderDistance); }
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in) { this.renderDistance = in.readInt(); }
|
||||
// @Override
|
||||
// public void encode(ByteBuf out) { out.writeInt(this.renderDistance); }
|
||||
//
|
||||
// @Override
|
||||
// public void decode(ByteBuf in) { this.renderDistance = in.readInt(); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
+22
-22
@@ -1,31 +1,31 @@
|
||||
package com.seibel.distanthorizons.core.network.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public interface INetworkObject
|
||||
{
|
||||
void encode(ByteBuf out);
|
||||
|
||||
void decode(ByteBuf in);
|
||||
|
||||
static <T extends INetworkObject> T decode(T obj, ByteBuf inputByteBuf)
|
||||
{
|
||||
obj.decode(inputByteBuf);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static void encodeString(String inputString, ByteBuf outputByteBuf)
|
||||
{
|
||||
outputByteBuf.writeShort(inputString.length());
|
||||
outputByteBuf.writeBytes(inputString.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
static String decodeString(ByteBuf inputByteBuf)
|
||||
{
|
||||
int length = inputByteBuf.readShort();
|
||||
return inputByteBuf.readBytes(length).toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
// void encode(ByteBuf out);
|
||||
//
|
||||
// void decode(ByteBuf in);
|
||||
//
|
||||
// static <T extends INetworkObject> T decode(T obj, ByteBuf inputByteBuf)
|
||||
// {
|
||||
// obj.decode(inputByteBuf);
|
||||
// return obj;
|
||||
// }
|
||||
//
|
||||
// static void encodeString(String inputString, ByteBuf outputByteBuf)
|
||||
// {
|
||||
// outputByteBuf.writeShort(inputString.length());
|
||||
// outputByteBuf.writeBytes(inputString.getBytes(StandardCharsets.UTF_8));
|
||||
// }
|
||||
//
|
||||
// static String decodeString(ByteBuf inputByteBuf)
|
||||
// {
|
||||
// int length = inputByteBuf.readShort();
|
||||
// return inputByteBuf.readBytes(length).toString(StandardCharsets.UTF_8);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,18 +1,18 @@
|
||||
package com.seibel.distanthorizons.core.network.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
//import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MessageDecoder extends ByteToMessageDecoder
|
||||
public class MessageDecoder //extends ByteToMessageDecoder
|
||||
{
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext channelContext, ByteBuf inputByteBuf, List<Object> outputDecodedObjectList)
|
||||
{
|
||||
INetworkMessage message = MessageRegistry.INSTANCE.createMessage(inputByteBuf.readShort());
|
||||
outputDecodedObjectList.add(INetworkObject.decode(message, inputByteBuf));
|
||||
}
|
||||
// @Override
|
||||
// protected void decode(ChannelHandlerContext channelContext, ByteBuf inputByteBuf, List<Object> outputDecodedObjectList)
|
||||
// {
|
||||
// INetworkMessage message = MessageRegistry.INSTANCE.createMessage(inputByteBuf.readShort());
|
||||
// outputDecodedObjectList.add(INetworkObject.decode(message, inputByteBuf));
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,16 +1,16 @@
|
||||
package com.seibel.distanthorizons.core.network.protocol;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
//import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
public class MessageEncoder extends MessageToByteEncoder<INetworkMessage>
|
||||
public class MessageEncoder //extends MessageToByteEncoder<INetworkMessage>
|
||||
{
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext channelContext, INetworkMessage message, ByteBuf outputByteBuf) throws IllegalArgumentException
|
||||
{
|
||||
outputByteBuf.writeShort(MessageRegistry.INSTANCE.getMessageId(message));
|
||||
message.encode(outputByteBuf);
|
||||
}
|
||||
// @Override
|
||||
// protected void encode(ChannelHandlerContext channelContext, INetworkMessage message, ByteBuf outputByteBuf) throws IllegalArgumentException
|
||||
// {
|
||||
// outputByteBuf.writeShort(MessageRegistry.INSTANCE.getMessageId(message));
|
||||
// message.encode(outputByteBuf);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
+37
-37
@@ -2,9 +2,9 @@ package com.seibel.distanthorizons.core.network.protocol;
|
||||
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.network.messages.CloseMessage;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
//import io.netty.channel.ChannelHandler;
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
//import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -14,40 +14,40 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
public class MessageHandler extends SimpleChannelInboundHandler<INetworkMessage>
|
||||
//@ChannelHandler.Sharable
|
||||
public class MessageHandler //extends SimpleChannelInboundHandler<INetworkMessage>
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
private final Map<Class<? extends INetworkMessage>, List<BiConsumer<INetworkMessage, ChannelHandlerContext>>> handlers = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
public <T extends INetworkMessage> void registerHandler(Class<T> handlerClass, BiConsumer<T, ChannelHandlerContext> handlerImplementation)
|
||||
{
|
||||
this.handlers.computeIfAbsent(handlerClass, missingHandlerClass -> new LinkedList<>())
|
||||
.add((BiConsumer<INetworkMessage, ChannelHandlerContext>) handlerImplementation);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext channelContext, INetworkMessage message)
|
||||
{
|
||||
LOGGER.trace("Received message: "+message.getClass().getSimpleName());
|
||||
|
||||
List<BiConsumer<INetworkMessage, ChannelHandlerContext>> handlerList = this.handlers.get(message.getClass());
|
||||
if (handlerList == null)
|
||||
{
|
||||
LOGGER.warn("Unhandled message type: "+message.getClass().getSimpleName());
|
||||
return;
|
||||
}
|
||||
|
||||
for (BiConsumer<INetworkMessage, ChannelHandlerContext> handler : handlerList)
|
||||
{
|
||||
handler.accept(message, channelContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(@NotNull ChannelHandlerContext channelContext) { this.channelRead0(channelContext, new CloseMessage()); }
|
||||
// private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
//
|
||||
// private final Map<Class<? extends INetworkMessage>, List<BiConsumer<INetworkMessage, ChannelHandlerContext>>> handlers = new HashMap<>();
|
||||
//
|
||||
//
|
||||
//
|
||||
// public <T extends INetworkMessage> void registerHandler(Class<T> handlerClass, BiConsumer<T, ChannelHandlerContext> handlerImplementation)
|
||||
// {
|
||||
// this.handlers.computeIfAbsent(handlerClass, missingHandlerClass -> new LinkedList<>())
|
||||
// .add((BiConsumer<INetworkMessage, ChannelHandlerContext>) handlerImplementation);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void channelRead0(ChannelHandlerContext channelContext, INetworkMessage message)
|
||||
// {
|
||||
// LOGGER.trace("Received message: "+message.getClass().getSimpleName());
|
||||
//
|
||||
// List<BiConsumer<INetworkMessage, ChannelHandlerContext>> handlerList = this.handlers.get(message.getClass());
|
||||
// if (handlerList == null)
|
||||
// {
|
||||
// LOGGER.warn("Unhandled message type: "+message.getClass().getSimpleName());
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// for (BiConsumer<INetworkMessage, ChannelHandlerContext> handler : handlerList)
|
||||
// {
|
||||
// handler.accept(message, channelContext);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void channelInactive(@NotNull ChannelHandlerContext channelContext) { this.channelRead0(channelContext, new CloseMessage()); }
|
||||
|
||||
}
|
||||
|
||||
+24
-24
@@ -1,13 +1,13 @@
|
||||
package com.seibel.distanthorizons.core.network.protocol;
|
||||
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import io.netty.handler.codec.LengthFieldPrepender;
|
||||
//import io.netty.channel.*;
|
||||
//import io.netty.channel.socket.SocketChannel;
|
||||
//import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
//import io.netty.handler.codec.LengthFieldPrepender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/** used when creating a network channel */
|
||||
public class NetworkChannelInitializer extends ChannelInitializer<SocketChannel>
|
||||
public class NetworkChannelInitializer //extends ChannelInitializer<SocketChannel>
|
||||
{
|
||||
private final MessageHandler messageHandler;
|
||||
|
||||
@@ -15,23 +15,23 @@ public class NetworkChannelInitializer extends ChannelInitializer<SocketChannel>
|
||||
|
||||
public NetworkChannelInitializer(MessageHandler messageHandler) { this.messageHandler = messageHandler; }
|
||||
|
||||
@Override
|
||||
public void initChannel(@NotNull SocketChannel socketChannel)
|
||||
{
|
||||
ChannelPipeline pipeline = socketChannel.pipeline();
|
||||
|
||||
// Encoder
|
||||
pipeline.addLast(new LengthFieldPrepender(Short.BYTES));
|
||||
pipeline.addLast(new MessageEncoder());
|
||||
pipeline.addLast(new NetworkOutboundExceptionRouter());
|
||||
|
||||
// Decoder
|
||||
pipeline.addLast(new LengthFieldBasedFrameDecoder(Short.MAX_VALUE, 0, Short.BYTES, 0, Short.BYTES));
|
||||
pipeline.addLast(new MessageDecoder());
|
||||
|
||||
// Handler
|
||||
pipeline.addLast(this.messageHandler);
|
||||
pipeline.addLast(new NetworkExceptionHandler());
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void initChannel(@NotNull SocketChannel socketChannel)
|
||||
// {
|
||||
// ChannelPipeline pipeline = socketChannel.pipeline();
|
||||
//
|
||||
// // Encoder
|
||||
// pipeline.addLast(new LengthFieldPrepender(Short.BYTES));
|
||||
// pipeline.addLast(new MessageEncoder());
|
||||
// pipeline.addLast(new NetworkOutboundExceptionRouter());
|
||||
//
|
||||
// // Decoder
|
||||
// pipeline.addLast(new LengthFieldBasedFrameDecoder(Short.MAX_VALUE, 0, Short.BYTES, 0, Short.BYTES));
|
||||
// pipeline.addLast(new MessageDecoder());
|
||||
//
|
||||
// // Handler
|
||||
// pipeline.addLast(this.messageHandler);
|
||||
// pipeline.addLast(new NetworkExceptionHandler());
|
||||
// }
|
||||
//
|
||||
}
|
||||
|
||||
+9
-9
@@ -1,19 +1,19 @@
|
||||
package com.seibel.distanthorizons.core.network.protocol;
|
||||
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
//import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class NetworkExceptionHandler extends ChannelInboundHandlerAdapter
|
||||
public class NetworkExceptionHandler //extends ChannelInboundHandlerAdapter
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext channelContext, Throwable cause)
|
||||
{
|
||||
LOGGER.error("Exception caught in channel: ["+channelContext.name()+"].", cause);
|
||||
channelContext.close();
|
||||
}
|
||||
// @Override
|
||||
// public void exceptionCaught(ChannelHandlerContext channelContext, Throwable cause)
|
||||
// {
|
||||
// LOGGER.error("Exception caught in channel: ["+channelContext.name()+"].", cause);
|
||||
// channelContext.close();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,17 +1,17 @@
|
||||
package com.seibel.distanthorizons.core.network.protocol;
|
||||
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
//import io.netty.channel.ChannelFutureListener;
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
//import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
//import io.netty.channel.ChannelPromise;
|
||||
|
||||
public class NetworkOutboundExceptionRouter extends ChannelOutboundHandlerAdapter
|
||||
public class NetworkOutboundExceptionRouter //extends ChannelOutboundHandlerAdapter
|
||||
{
|
||||
@Override
|
||||
public void write(ChannelHandlerContext channelContext, Object messageObj, ChannelPromise promise) throws Exception
|
||||
{
|
||||
promise.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
||||
super.write(channelContext, messageObj, promise);
|
||||
}
|
||||
// @Override
|
||||
// public void write(ChannelHandlerContext channelContext, Object messageObj, ChannelPromise promise) throws Exception
|
||||
// {
|
||||
// promise.addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
||||
// super.write(channelContext, messageObj, promise);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
|
||||
private final ConcurrentHashMap<IClientLevelWrapper, DhClientLevel> levels;
|
||||
public final ClientOnlySaveStructure saveStructure;
|
||||
|
||||
private final NetworkClient networkClient;
|
||||
// private final NetworkClient networkClient;
|
||||
|
||||
// TODO why does this executor have 2 threads?
|
||||
public ExecutorService dhTickerThread = ThreadUtil.makeSingleThreadPool("DH Client World Ticker Thread", 2);
|
||||
@@ -50,12 +50,12 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
|
||||
if (Config.Client.Advanced.Multiplayer.enableServerNetworking.get())
|
||||
{
|
||||
// TODO server specific configs
|
||||
this.networkClient = new NetworkClient(MC_CLIENT.getCurrentServerIp(), 25049);
|
||||
// this.networkClient = new NetworkClient(MC_CLIENT.getCurrentServerIp(), 25049);
|
||||
this.registerNetworkHandlers();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.networkClient = null;
|
||||
// this.networkClient = null;
|
||||
}
|
||||
|
||||
LOGGER.info("Started DhWorld of type "+this.environment);
|
||||
@@ -63,26 +63,26 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
|
||||
|
||||
private void registerNetworkHandlers()
|
||||
{
|
||||
this.networkClient.registerHandler(HelloMessage.class, (msg, ctx) ->
|
||||
{
|
||||
ctx.writeAndFlush(new PlayerUUIDMessage(MC_CLIENT.getPlayerUUID()));
|
||||
});
|
||||
|
||||
// TODO Proper payload handling
|
||||
this.networkClient.registerAckHandler(PlayerUUIDMessage.class, ctx ->
|
||||
{
|
||||
ctx.writeAndFlush(new RemotePlayerConfigMessage(new RemotePlayer.Payload()));
|
||||
});
|
||||
this.networkClient.registerHandler(RemotePlayerConfigMessage.class, (msg, ctx) ->
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
this.networkClient.registerAckHandler(RemotePlayerConfigMessage.class, ctx ->
|
||||
{
|
||||
// TODO Actually request chunks
|
||||
ctx.writeAndFlush(new RequestChunksMessage());
|
||||
});
|
||||
// this.networkClient.registerHandler(HelloMessage.class, (msg, ctx) ->
|
||||
// {
|
||||
// ctx.writeAndFlush(new PlayerUUIDMessage(MC_CLIENT.getPlayerUUID()));
|
||||
// });
|
||||
//
|
||||
// // TODO Proper payload handling
|
||||
// this.networkClient.registerAckHandler(PlayerUUIDMessage.class, ctx ->
|
||||
// {
|
||||
// ctx.writeAndFlush(new RemotePlayerConfigMessage(new RemotePlayer.Payload()));
|
||||
// });
|
||||
// this.networkClient.registerHandler(RemotePlayerConfigMessage.class, (msg, ctx) ->
|
||||
// {
|
||||
//
|
||||
// });
|
||||
//
|
||||
// this.networkClient.registerAckHandler(RemotePlayerConfigMessage.class, ctx ->
|
||||
// {
|
||||
// // TODO Actually request chunks
|
||||
// ctx.writeAndFlush(new RequestChunksMessage());
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
@@ -157,10 +157,10 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
if (this.networkClient != null)
|
||||
{
|
||||
this.networkClient.close();
|
||||
}
|
||||
// if (this.networkClient != null)
|
||||
// {
|
||||
//// this.networkClient.close();
|
||||
// }
|
||||
|
||||
|
||||
this.saveAndFlush();
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@@ -25,9 +25,9 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
private final HashMap<IServerLevelWrapper, DhServerLevel> levels;
|
||||
public final LocalSaveStructure saveStructure;
|
||||
|
||||
private final NetworkServer networkServer;
|
||||
private final HashMap<UUID, RemotePlayer> playersByUUID;
|
||||
private final BiMap<ChannelHandlerContext, RemotePlayer> playersByConnection;
|
||||
// private final NetworkServer networkServer;
|
||||
// private final HashMap<UUID, RemotePlayer> playersByUUID;
|
||||
// private final BiMap<ChannelHandlerContext, RemotePlayer> playersByConnection;
|
||||
|
||||
|
||||
|
||||
@@ -39,73 +39,73 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
this.levels = new HashMap<>();
|
||||
|
||||
// TODO move to global payload once server specific configs are implemented
|
||||
this.networkServer = new NetworkServer(25049);
|
||||
this.playersByUUID = new HashMap<>();
|
||||
this.playersByConnection = HashBiMap.create();
|
||||
this.registerNetworkHandlers();
|
||||
// this.networkServer = new NetworkServer(25049);
|
||||
// this.playersByUUID = new HashMap<>();
|
||||
// this.playersByConnection = HashBiMap.create();
|
||||
// this.registerNetworkHandlers();
|
||||
|
||||
LOGGER.info("Started "+DhServerWorld.class.getSimpleName()+" of type "+this.environment);
|
||||
}
|
||||
|
||||
private void registerNetworkHandlers()
|
||||
{
|
||||
this.networkServer.registerHandler(CloseMessage.class, (closeMessage, channelContext) ->
|
||||
{
|
||||
RemotePlayer dhPlayer = this.playersByConnection.remove(channelContext);
|
||||
if (dhPlayer != null)
|
||||
{
|
||||
dhPlayer.channelContext = null;
|
||||
}
|
||||
});
|
||||
|
||||
this.networkServer.registerHandler(PlayerUUIDMessage.class, (playerUUIDMessage, channelContext) ->
|
||||
{
|
||||
RemotePlayer dhPlayer = this.playersByUUID.get(playerUUIDMessage.playerUUID);
|
||||
|
||||
if (dhPlayer == null)
|
||||
{
|
||||
this.networkServer.disconnectClient(channelContext, "Player is not logged in.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (dhPlayer.channelContext != null)
|
||||
{
|
||||
this.networkServer.disconnectClient(channelContext, "Another connection is already in use.");
|
||||
return;
|
||||
}
|
||||
|
||||
dhPlayer.channelContext = channelContext;
|
||||
this.playersByConnection.put(channelContext, dhPlayer);
|
||||
|
||||
channelContext.writeAndFlush(new AckMessage(PlayerUUIDMessage.class));
|
||||
});
|
||||
|
||||
this.networkServer.registerHandler(RemotePlayerConfigMessage.class, (dhRemotePlayerConfigMessage, channelContext) ->
|
||||
{
|
||||
// TODO Take notice of received payload and possibly echo back a constrained version
|
||||
channelContext.writeAndFlush(new AckMessage(RemotePlayerConfigMessage.class));
|
||||
});
|
||||
|
||||
this.networkServer.registerHandler(RequestChunksMessage.class, (msg, ctx) ->
|
||||
{
|
||||
LOGGER.info("RequestChunksMessage");
|
||||
// hasReceivedChunkRequest should be false somewhere ???
|
||||
// to avoid sending updates until client says at least something about its state
|
||||
});
|
||||
// this.networkServer.registerHandler(CloseMessage.class, (closeMessage, channelContext) ->
|
||||
// {
|
||||
// RemotePlayer dhPlayer = this.playersByConnection.remove(channelContext);
|
||||
// if (dhPlayer != null)
|
||||
// {
|
||||
// dhPlayer.channelContext = null;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// this.networkServer.registerHandler(PlayerUUIDMessage.class, (playerUUIDMessage, channelContext) ->
|
||||
// {
|
||||
// RemotePlayer dhPlayer = this.playersByUUID.get(playerUUIDMessage.playerUUID);
|
||||
//
|
||||
// if (dhPlayer == null)
|
||||
// {
|
||||
// this.networkServer.disconnectClient(channelContext, "Player is not logged in.");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (dhPlayer.channelContext != null)
|
||||
// {
|
||||
// this.networkServer.disconnectClient(channelContext, "Another connection is already in use.");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// dhPlayer.channelContext = channelContext;
|
||||
// this.playersByConnection.put(channelContext, dhPlayer);
|
||||
//
|
||||
// channelContext.writeAndFlush(new AckMessage(PlayerUUIDMessage.class));
|
||||
// });
|
||||
//
|
||||
// this.networkServer.registerHandler(RemotePlayerConfigMessage.class, (dhRemotePlayerConfigMessage, channelContext) ->
|
||||
// {
|
||||
// // TODO Take notice of received payload and possibly echo back a constrained version
|
||||
// channelContext.writeAndFlush(new AckMessage(RemotePlayerConfigMessage.class));
|
||||
// });
|
||||
//
|
||||
// this.networkServer.registerHandler(RequestChunksMessage.class, (msg, ctx) ->
|
||||
// {
|
||||
// LOGGER.info("RequestChunksMessage");
|
||||
// // hasReceivedChunkRequest should be false somewhere ???
|
||||
// // to avoid sending updates until client says at least something about its state
|
||||
// });
|
||||
}
|
||||
|
||||
public void addPlayer(IServerPlayerWrapper serverPlayer)
|
||||
{
|
||||
this.playersByUUID.put(serverPlayer.getUUID(), new RemotePlayer(serverPlayer));
|
||||
//this.playersByUUID.put(serverPlayer.getUUID(), new RemotePlayer(serverPlayer));
|
||||
}
|
||||
public void removePlayer(IServerPlayerWrapper serverPlayer)
|
||||
{
|
||||
RemotePlayer dhPlayer = this.playersByUUID.remove(serverPlayer.getUUID());
|
||||
ChannelHandlerContext channelContext = this.playersByConnection.inverse().remove(dhPlayer);
|
||||
if (channelContext != null)
|
||||
{
|
||||
this.networkServer.disconnectClient(channelContext, "You are being disconnected.");
|
||||
}
|
||||
// RemotePlayer dhPlayer = this.playersByUUID.remove(serverPlayer.getUUID());
|
||||
// ChannelHandlerContext channelContext = this.playersByConnection.inverse().remove(dhPlayer);
|
||||
// if (channelContext != null)
|
||||
// {
|
||||
// this.networkServer.disconnectClient(channelContext, "You are being disconnected.");
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,7 +166,7 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
this.networkServer.close();
|
||||
// this.networkServer.close();
|
||||
|
||||
for (DhServerLevel level : this.levels.values())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user