Sending some responses
Rejoin is horribly broken
This commit is contained in:
+11
-1
@@ -3,18 +3,22 @@ package com.seibel.distanthorizons.core.file.fullDatafile;
|
||||
import com.seibel.distanthorizons.core.dataObjects.fullData.sources.interfaces.IFullDataSource;
|
||||
import com.seibel.distanthorizons.core.file.structure.AbstractSaveStructure;
|
||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.network.ChildNetworkEventSource;
|
||||
import com.seibel.distanthorizons.core.network.NetworkClient;
|
||||
import com.seibel.distanthorizons.core.network.future.NetworkRequestTracker;
|
||||
import com.seibel.distanthorizons.core.network.messages.ChunkRequestMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.ChunkResponseMessage;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class RemoteFullDataFileHandler extends FullDataFileHandler
|
||||
{
|
||||
protected static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
private final NetworkClient networkClient;
|
||||
private final NetworkRequestTracker<ChunkResponseMessage, DhSectionPos> chunkRequestTracker;
|
||||
|
||||
@@ -28,8 +32,14 @@ public class RemoteFullDataFileHandler extends FullDataFileHandler
|
||||
public CompletableFuture<IFullDataSource> read(DhSectionPos pos) {
|
||||
// TODO: LOD data file updating is probably incomplete
|
||||
return super.read(pos).thenCompose((fullDataSource) -> {
|
||||
CompletableFuture<ChunkResponseMessage> responseFuture = chunkRequestTracker.sendRequest(networkClient.getChannel(), new ChunkRequestMessage(pos))
|
||||
.exceptionally(throwable -> {
|
||||
LOGGER.error(throwable);
|
||||
return null;
|
||||
});
|
||||
responseFuture.thenAccept(response -> LOGGER.info("ChunkResponseMessage "+response.dhSectionPos));
|
||||
|
||||
FullDataMetaFile metaFile = this.getLoadOrMakeFile(pos, true);
|
||||
CompletableFuture<ChunkResponseMessage> responseFuture = chunkRequestTracker.sendRequest(networkClient.getChannel(), new ChunkRequestMessage(pos));
|
||||
return onDataFileUpdate(fullDataSource, metaFile, iFullDataSource -> {}, iFullDataSource -> true);
|
||||
});
|
||||
}
|
||||
|
||||
+1
-2
@@ -58,9 +58,8 @@ public class NetworkRequestTracker
|
||||
}
|
||||
|
||||
private void completeAllExceptionally(Channel channel, Throwable cause) {
|
||||
for (CompletableFuture<TResponse> responseFuture : pendingFutures.row(channel).values()) {
|
||||
for (CompletableFuture<TResponse> responseFuture : pendingFutures.row(channel).values())
|
||||
responseFuture.completeExceptionally(cause);
|
||||
};
|
||||
pendingFutures.row(channel).clear();
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package com.seibel.distanthorizons.core.network.messages;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.future.IFutureTrackableNetworkMessage;
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkObject;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@@ -19,12 +20,12 @@ public class ChunkRequestMessage implements IFutureTrackableNetworkMessage<DhSec
|
||||
@Override
|
||||
public void encode(ByteBuf out)
|
||||
{
|
||||
|
||||
dhSectionPos.encode(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in)
|
||||
{
|
||||
|
||||
dhSectionPos = INetworkObject.decode(new DhSectionPos((byte)0, 0, 0), in);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -1,6 +1,7 @@
|
||||
package com.seibel.distanthorizons.core.network.messages;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.future.IFutureTrackableNetworkMessage;
|
||||
import com.seibel.distanthorizons.core.network.protocol.INetworkObject;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@@ -16,13 +17,15 @@ public class ChunkResponseMessage implements IFutureTrackableNetworkMessage<DhSe
|
||||
|
||||
@Override public DhSectionPos getRequestKey() { return dhSectionPos; }
|
||||
|
||||
@Override public void encode(ByteBuf out)
|
||||
@Override
|
||||
public void encode(ByteBuf out)
|
||||
{
|
||||
|
||||
dhSectionPos.encode(out);
|
||||
}
|
||||
|
||||
@Override public void decode(ByteBuf in)
|
||||
@Override
|
||||
public void decode(ByteBuf in)
|
||||
{
|
||||
|
||||
dhSectionPos = INetworkObject.decode(new DhSectionPos((byte)0, 0, 0), in);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -30,6 +30,7 @@ public class MessageRegistry
|
||||
this.registerMessage(PlayerUUIDMessage.class, PlayerUUIDMessage::new);
|
||||
this.registerMessage(RemotePlayerConfigMessage.class, RemotePlayerConfigMessage::new);
|
||||
this.registerMessage(ChunkRequestMessage.class, ChunkRequestMessage::new);
|
||||
this.registerMessage(ChunkResponseMessage.class, ChunkResponseMessage::new);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,12 +52,21 @@ public class MessageRegistry
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid message ID");
|
||||
throw new IllegalArgumentException("Invalid message ID: "+messageId);
|
||||
}
|
||||
}
|
||||
|
||||
public int getMessageId(INetworkMessage message) { return this.getMessageId(message.getClass()); }
|
||||
|
||||
public int getMessageId(Class<? extends INetworkMessage> messageClass) { return this.classToId.get(messageClass); }
|
||||
public int getMessageId(Class<? extends INetworkMessage> messageClass) {
|
||||
try
|
||||
{
|
||||
return this.classToId.get(messageClass);
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
throw new IllegalArgumentException("Message does not have ID assigned to it: "+messageClass.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
|
||||
|
||||
networkClient.registerAckHandler(RemotePlayerConfigMessage.class, ctx -> {
|
||||
// TODO Actually request chunks
|
||||
ctx.writeAndFlush(new ChunkRequestMessage(new DhSectionPos(new DhBlockPos2D(0, 0))));
|
||||
// ctx.writeAndFlush(new ChunkRequestMessage(new DhSectionPos(new DhBlockPos2D(0, 0))));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user