Fix compilation
This commit is contained in:
@@ -24,6 +24,7 @@ import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass;
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.*;
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.network.plugin.PluginChannelMessage;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiDebugRendering;
|
||||
import com.seibel.distanthorizons.api.enums.rendering.EDhApiRendererMode;
|
||||
@@ -52,6 +53,7 @@ import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -325,9 +327,9 @@ public class ClientApi
|
||||
// networking //
|
||||
//============//
|
||||
|
||||
public void pluginMessageReceived(ByteBuf byteBuf)
|
||||
public void pluginMessageReceived(@NotNull PluginChannelMessage message)
|
||||
{
|
||||
this.pluginChannelApi.handlePacket(byteBuf);
|
||||
this.pluginChannelApi.session.tryHandleMessage(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-6
@@ -30,7 +30,7 @@ public class ClientPluginChannelApi
|
||||
private final Consumer<IClientLevelWrapper> levelUnloadHandler;
|
||||
private final Consumer<IServerKeyedClientLevel> multiverseLevelLoadHandler;
|
||||
|
||||
private PluginChannelSession session;
|
||||
public PluginChannelSession session;
|
||||
|
||||
|
||||
public boolean allowLoadingLevel()
|
||||
@@ -89,9 +89,4 @@ public class ClientPluginChannelApi
|
||||
KEYED_CLIENT_LEVEL_MANAGER.disable();
|
||||
}
|
||||
|
||||
public void handlePacket(ByteBuf buffer)
|
||||
{
|
||||
this.session.decodeAndHandle(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiLevelLo
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiLevelUnloadEvent;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.generation.DhLightingEngine;
|
||||
import com.seibel.distanthorizons.core.network.plugin.PluginChannelMessage;
|
||||
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
@@ -38,6 +39,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This holds the methods that should be called by the host mod loader (Fabric,
|
||||
@@ -178,14 +180,14 @@ public class ServerApi
|
||||
}
|
||||
}
|
||||
|
||||
public void pluginMessageReceived(IServerPlayerWrapper player, ByteBuf buffer)
|
||||
public void pluginMessageReceived(IServerPlayerWrapper player, @NotNull PluginChannelMessage message)
|
||||
{
|
||||
IDhServerWorld serverWorld = SharedApi.getIDhServerWorld();
|
||||
if (serverWorld instanceof DhServerWorld) // TODO add support for DhClientServerWorld's (lan worlds) as well
|
||||
{
|
||||
LOGGER.debug("Player " + player.getUUID() + " sent plugin message: " + buffer.toString());
|
||||
((DhServerWorld) serverWorld).handlePluginMessage(player, buffer);
|
||||
LOGGER.debug("Player " + player.getUUID() + " sent plugin message: " + message);
|
||||
((DhServerWorld) serverWorld).remotePlayerConnectionHandler.handlePluginMessage(player, message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -201,13 +201,8 @@ public class FullDataSourceProviderV2
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public Map<Long, Long> getTimestampsForRange(long startPos, long endPos)
|
||||
public Map<Long, Long> getTimestampsForRange(byte detailLevel, int startPosX, int startPosZ, int endPosX, int endPosZ)
|
||||
{
|
||||
if (DhSectionPos.getDetailLevel(startPos) != DhSectionPos.getDetailLevel(endPos))
|
||||
{
|
||||
throw new IllegalArgumentException("Start and end must have the same detail level");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
PreparedStatement preparedStatement = this.repo.createPreparedStatement(
|
||||
@@ -217,14 +212,14 @@ public class FullDataSourceProviderV2
|
||||
"AND PosX BETWEEN ? AND ? " +
|
||||
"AND PosZ BETWEEN ? AND ?;"
|
||||
);
|
||||
preparedStatement.setInt(1, DhSectionPos.getDetailLevel(startPos) - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
|
||||
preparedStatement.setInt(2, DhSectionPos.getX(startPos));
|
||||
preparedStatement.setInt(3, DhSectionPos.getX(endPos));
|
||||
preparedStatement.setInt(4, DhSectionPos.getZ(startPos));
|
||||
preparedStatement.setInt(5, DhSectionPos.getZ(endPos));
|
||||
preparedStatement.setInt(1, detailLevel - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL);
|
||||
preparedStatement.setInt(2, startPosX);
|
||||
preparedStatement.setInt(3, endPosX);
|
||||
preparedStatement.setInt(4, startPosZ);
|
||||
preparedStatement.setInt(5, endPosZ);
|
||||
|
||||
return this.repo.query(preparedStatement).stream().collect(Collectors.toMap(
|
||||
row -> DhSectionPos.encode(DhSectionPos.getDetailLevel(startPos), (int) row.get("PosX"), (int) row.get("PosZ")),
|
||||
row -> DhSectionPos.encode(detailLevel, (int) row.get("PosX"), (int) row.get("PosZ")),
|
||||
row -> (long) row.get("LastModifiedUnixDateTime"))
|
||||
);
|
||||
}
|
||||
|
||||
+9
-5
@@ -43,7 +43,7 @@ public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvide
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public FullDataSourceV2 get(DhSectionPos pos)
|
||||
public FullDataSourceV2 get(long pos)
|
||||
{
|
||||
FullDataSourceV2 fullDataSource = super.get(pos);
|
||||
if (fullDataSource == null || this.dataRefreshQueue == null)
|
||||
@@ -51,11 +51,15 @@ public class RemoteFullDataSourceProvider extends GeneratedFullDataSourceProvide
|
||||
return fullDataSource;
|
||||
}
|
||||
|
||||
Map<DhSectionPos, Long> timestamps = this.getTimestampsForRange(
|
||||
pos.getMinCornerPos(DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL),
|
||||
pos.getMaxCornerPos(DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL)
|
||||
int posToMinimumDetailScale = (DhSectionPos.getDetailLevel(pos) - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL + 1);
|
||||
Map<Long, Long> timestamps = this.getTimestampsForRange(
|
||||
DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL,
|
||||
DhSectionPos.getX(pos) * posToMinimumDetailScale,
|
||||
DhSectionPos.getZ(pos) * posToMinimumDetailScale,
|
||||
(DhSectionPos.getX(pos) + 1) * posToMinimumDetailScale - 1,
|
||||
(DhSectionPos.getZ(pos) + 1) * posToMinimumDetailScale - 1
|
||||
);
|
||||
for (Map.Entry<DhSectionPos, Long> entry : timestamps.entrySet())
|
||||
for (Map.Entry<Long, Long> entry : timestamps.entrySet())
|
||||
{
|
||||
this.dataRefreshQueue.submitRequest(entry.getKey(), entry.getValue(), this.delayedFullDataSourceSaveCache::queueDataSourceForUpdateAndSave);
|
||||
}
|
||||
|
||||
+1
-8
@@ -1,6 +1,5 @@
|
||||
package com.seibel.distanthorizons.core.generation;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.generation.tasks.IWorldGenTaskTracker;
|
||||
import com.seibel.distanthorizons.core.generation.tasks.WorldGenResult;
|
||||
@@ -8,18 +7,12 @@ import com.seibel.distanthorizons.core.level.IDhClientLevel;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.multiplayer.client.AbstractFullDataRequestQueue;
|
||||
import com.seibel.distanthorizons.core.multiplayer.client.ClientNetworkState;
|
||||
import com.seibel.distanthorizons.core.network.exceptions.RateLimitedException;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.render.renderer.IDebugRenderable;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import io.netty.channel.ChannelException;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class WorldRemoteGenerationQueue extends AbstractFullDataRequestQueue implements IFullDataSourceRetrievalQueue, IDebugRenderable
|
||||
{
|
||||
@@ -59,7 +52,7 @@ public class WorldRemoteGenerationQueue extends AbstractFullDataRequestQueue imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<WorldGenResult> submitGenTask(DhSectionPos sectionPos, byte requiredDataDetail, IWorldGenTaskTracker tracker)
|
||||
public CompletableFuture<WorldGenResult> submitGenTask(long sectionPos, byte requiredDataDetail, IWorldGenTaskTracker tracker)
|
||||
{
|
||||
return super.submitRequest(sectionPos, tracker.getChunkDataConsumer())
|
||||
.thenApply(result -> result
|
||||
|
||||
@@ -276,7 +276,7 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel
|
||||
|
||||
|
||||
@Override
|
||||
public void onWorldGenTaskComplete(DhSectionPos pos)
|
||||
public void onWorldGenTaskComplete(long pos)
|
||||
{
|
||||
DebugRenderer.makeParticle(
|
||||
new DebugRenderer.BoxParticle(
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.seibel.distanthorizons.core.network.plugin.PluginChannelSession;
|
||||
import com.seibel.distanthorizons.core.network.plugin.TrackableMessage;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
@@ -63,7 +64,7 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
|
||||
private final RemotePlayerConnectionHandler remotePlayerConnectionHandler;
|
||||
|
||||
private final ConcurrentLinkedQueue<IServerPlayerWrapper> worldGenLoopingQueue = new ConcurrentLinkedQueue<>();
|
||||
private final ConcurrentMap<DhSectionPos, IncompleteDataSourceEntry> incompleteDataSources = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Long, IncompleteDataSourceEntry> incompleteDataSources = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Long, IncompleteDataSourceEntry> fullDataRequests = new ConcurrentHashMap<>();
|
||||
|
||||
public DhServerLevel(AbstractSaveStructure saveStructure, IServerLevelWrapper serverLevelWrapper, RemotePlayerConnectionHandler remotePlayerConnectionHandler)
|
||||
@@ -220,7 +221,7 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
|
||||
this.chunkToLodBuilder.tick();
|
||||
|
||||
// Send finished data source requests
|
||||
for (Map.Entry<DhSectionPos, IncompleteDataSourceEntry> mapEntry : this.incompleteDataSources.entrySet())
|
||||
for (Map.Entry<Long, IncompleteDataSourceEntry> mapEntry : this.incompleteDataSources.entrySet())
|
||||
{
|
||||
IncompleteDataSourceEntry entry = mapEntry.getValue();
|
||||
|
||||
@@ -266,7 +267,7 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
|
||||
}
|
||||
|
||||
Vec3d playerPosition = serverPlayerState.serverPlayer().getPosition();
|
||||
int distanceFromPlayer = data.getPos().getManhattanBlockDistance(new DhBlockPos2D((int) playerPosition.x, (int) playerPosition.z)) / 16;
|
||||
int distanceFromPlayer = DhSectionPos.getManhattanBlockDistance(data.getPos(), new DhBlockPos2D((int) playerPosition.x, (int) playerPosition.z)) / 16;
|
||||
if (distanceFromPlayer >= serverPlayerState.serverPlayer().getViewDistance() &&
|
||||
distanceFromPlayer <= serverPlayerState.config.getRenderDistanceRadius())
|
||||
{
|
||||
@@ -352,7 +353,7 @@ public class DhServerLevel extends AbstractDhLevel implements IDhServerLevel
|
||||
@Override
|
||||
public boolean hasSkyLight() { return this.serverLevelWrapper.hasSkyLight(); }
|
||||
|
||||
private void trySetGeneratedDataSourceToEntry(IncompleteDataSourceEntry entry, DhSectionPos pos)
|
||||
private void trySetGeneratedDataSourceToEntry(IncompleteDataSourceEntry entry, long pos)
|
||||
{
|
||||
this.serverside.fullDataFileHandler.getAsync(pos).thenAccept(fullDataSource -> {
|
||||
if (this.serverside.fullDataFileHandler.isFullyGenerated(fullDataSource.columnGenerationSteps))
|
||||
|
||||
+15
-15
@@ -48,7 +48,7 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
|
||||
|
||||
private volatile CompletableFuture<Void> closingFuture = null;
|
||||
|
||||
protected final ConcurrentMap<DhSectionPos, RequestQueueEntry> waitingTasks = new ConcurrentHashMap<>();
|
||||
protected final ConcurrentMap<Long, RequestQueueEntry> waitingTasks = new ConcurrentHashMap<>();
|
||||
private final Semaphore pendingTasksSemaphore = new Semaphore(Short.MAX_VALUE, true);
|
||||
|
||||
private final F3Screen.NestedMessage f3Message = new F3Screen.NestedMessage(this::f3Log);
|
||||
@@ -56,7 +56,7 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
|
||||
private final AtomicInteger failedRequests = new AtomicInteger();
|
||||
private final ConfigEntry<Boolean> showDebugWireframeConfig;
|
||||
|
||||
private final Set<DhSectionPos> alreadyRequestedPositions = ConcurrentHashMap.newKeySet();
|
||||
private final Set<Long> alreadyRequestedPositions = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private final SupplierBasedRateLimiter<Void> rateLimiter = new SupplierBasedRateLimiter<>(this::getRequestConcurrencyLimit);
|
||||
|
||||
@@ -82,13 +82,13 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
|
||||
DebugRenderer.register(this, this.showDebugWireframeConfig);
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> submitRequest(DhSectionPos sectionPos, Consumer<FullDataSourceV2> chunkDataConsumer)
|
||||
public CompletableFuture<Boolean> submitRequest(long sectionPos, Consumer<FullDataSourceV2> chunkDataConsumer)
|
||||
{
|
||||
return this.submitRequest(sectionPos, null, chunkDataConsumer);
|
||||
}
|
||||
public CompletableFuture<Boolean> submitRequest(DhSectionPos sectionPos, @Nullable Long clientTimestamp, Consumer<FullDataSourceV2> chunkDataConsumer)
|
||||
public CompletableFuture<Boolean> submitRequest(long sectionPos, @Nullable Long clientTimestamp, Consumer<FullDataSourceV2> chunkDataConsumer)
|
||||
{
|
||||
LodUtil.assertTrue(sectionPos.getDetailLevel() == DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL, "Only highest-detail sections are allowed.");
|
||||
LodUtil.assertTrue(DhSectionPos.getDetailLevel(sectionPos) == DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL, "Only highest-detail sections are allowed.");
|
||||
|
||||
// check if this is a duplicate task
|
||||
if (this.alreadyRequestedPositions.contains(sectionPos))
|
||||
@@ -104,9 +104,9 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
|
||||
return entry.future;
|
||||
}
|
||||
|
||||
protected int posDistanceSquared(DhBlockPos2D targetPos, DhSectionPos pos)
|
||||
protected int posDistanceSquared(DhBlockPos2D targetPos, long pos)
|
||||
{
|
||||
return (int) pos.getCenterBlockPos().distSquared(targetPos);
|
||||
return (int) DhSectionPos.getCenterBlockPos(pos).distSquared(targetPos);
|
||||
}
|
||||
|
||||
public synchronized boolean tick(DhBlockPos2D targetPos)
|
||||
@@ -132,14 +132,14 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
|
||||
return true;
|
||||
}
|
||||
|
||||
public void removeRetrievalRequestIf(Function<DhSectionPos, Boolean> removeIf)
|
||||
public void removeRetrievalRequestIf(DhSectionPos.ICancelablePrimitiveLongConsumer removeIf)
|
||||
{
|
||||
for (Map.Entry<DhSectionPos, RequestQueueEntry> mapEntry : this.waitingTasks.entrySet())
|
||||
for (Map.Entry<Long, RequestQueueEntry> mapEntry : this.waitingTasks.entrySet())
|
||||
{
|
||||
DhSectionPos pos = mapEntry.getKey();
|
||||
long pos = mapEntry.getKey();
|
||||
RequestQueueEntry entry = mapEntry.getValue();
|
||||
|
||||
if (removeIf.apply(pos))
|
||||
if (removeIf.accept(pos))
|
||||
{
|
||||
entry.future.cancel(false);
|
||||
if (entry.request != null)
|
||||
@@ -153,7 +153,7 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
|
||||
|
||||
private void sendNewRequest(DhBlockPos2D targetPos)
|
||||
{
|
||||
Map.Entry<DhSectionPos, RequestQueueEntry> mapEntry = this.waitingTasks.entrySet().stream()
|
||||
Map.Entry<Long, RequestQueueEntry> mapEntry = this.waitingTasks.entrySet().stream()
|
||||
.filter(task -> task.getValue().request == null)
|
||||
.reduce(null, (a, b) -> {
|
||||
if (a == null)
|
||||
@@ -163,7 +163,7 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
|
||||
|
||||
if (b.getValue().priority < a.getValue().priority)
|
||||
{
|
||||
Map.Entry<DhSectionPos, RequestQueueEntry> temp = b;
|
||||
Map.Entry<Long, RequestQueueEntry> temp = b;
|
||||
b = a;
|
||||
a = temp;
|
||||
}
|
||||
@@ -180,7 +180,7 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
|
||||
return;
|
||||
}
|
||||
|
||||
DhSectionPos sectionPos = mapEntry.getKey();
|
||||
long sectionPos = mapEntry.getKey();
|
||||
RequestQueueEntry entry = mapEntry.getValue();
|
||||
|
||||
CompletableFuture<FullDataSourceResponseMessage> request = this.networkState.getSession().sendRequest(new FullDataSourceRequestMessage(this.level.getLevelWrapper(), sectionPos, entry.updateTimestamp), FullDataSourceResponseMessage.class);
|
||||
@@ -308,7 +308,7 @@ public abstract class AbstractFullDataRequestQueue implements IDebugRenderable,
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<DhSectionPos, RequestQueueEntry> mapEntry : this.waitingTasks.entrySet())
|
||||
for (Map.Entry<Long, RequestQueueEntry> mapEntry : this.waitingTasks.entrySet())
|
||||
{
|
||||
r.renderBox(new DebugRenderer.Box(mapEntry.getKey(), -32f, 64f, 0.05f,
|
||||
mapEntry.getValue().request != null ? Color.red
|
||||
|
||||
+6
-3
@@ -2,8 +2,9 @@ package com.seibel.distanthorizons.core.multiplayer.server;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.distanthorizons.core.network.plugin.PluginChannelMessage;
|
||||
import com.seibel.distanthorizons.core.network.plugin.PluginChannelSession;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -17,9 +18,11 @@ public class RemotePlayerConnectionHandler
|
||||
private final ConcurrentMap<IServerPlayerWrapper, ServerPlayerState> connectedPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public void handlePluginMessage(IServerPlayerWrapper player, ByteBuf buffer)
|
||||
public void handlePluginMessage(IServerPlayerWrapper player, PluginChannelMessage message)
|
||||
{
|
||||
this.connectedPlayers.get(player).session.decodeAndHandle(buffer);
|
||||
PluginChannelSession session = this.connectedPlayers.get(player).session;
|
||||
message.setSession(session);
|
||||
session.tryHandleMessage(message);
|
||||
}
|
||||
|
||||
public ServerPlayerState getConnectedPlayer(IServerPlayerWrapper player)
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ public class FullDataPartialUpdateMessage extends PluginChannelMessage implement
|
||||
public void decode(ByteBuf in)
|
||||
{
|
||||
this.levelName = this.readString(in);
|
||||
this.dataSourceDto = INetworkObject.readToObject(new FullDataSourceV2DTO(), in);
|
||||
this.dataSourceDto = INetworkObject.decodeToInstance(new FullDataSourceV2DTO(), in);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -32,7 +32,7 @@ public class FullDataSourceRequestMessage extends TrackableMessage implements IL
|
||||
{
|
||||
private String levelName;
|
||||
|
||||
public DhSectionPos sectionPos;
|
||||
public long sectionPos;
|
||||
|
||||
/** Only present when requesting for changes. */
|
||||
@Nullable
|
||||
@@ -42,7 +42,7 @@ public class FullDataSourceRequestMessage extends TrackableMessage implements IL
|
||||
public String getLevelName() { return this.levelName; }
|
||||
|
||||
public FullDataSourceRequestMessage() {}
|
||||
public FullDataSourceRequestMessage(ILevelWrapper levelWrapper, DhSectionPos sectionPos, @Nullable Long clientTimestamp)
|
||||
public FullDataSourceRequestMessage(ILevelWrapper levelWrapper, long sectionPos, @Nullable Long clientTimestamp)
|
||||
{
|
||||
this.levelName = levelWrapper.getDimensionType().getDimensionName();
|
||||
this.sectionPos = sectionPos;
|
||||
@@ -53,7 +53,7 @@ public class FullDataSourceRequestMessage extends TrackableMessage implements IL
|
||||
public void encode0(ByteBuf out)
|
||||
{
|
||||
this.writeString(this.levelName, out);
|
||||
this.sectionPos.encode(out);
|
||||
out.writeLong(this.sectionPos);
|
||||
if (this.writeOptional(out, this.clientTimestamp))
|
||||
{
|
||||
out.writeLong(this.clientTimestamp);
|
||||
@@ -64,7 +64,7 @@ public class FullDataSourceRequestMessage extends TrackableMessage implements IL
|
||||
public void decode0(ByteBuf in)
|
||||
{
|
||||
this.levelName = this.readString(in);
|
||||
this.sectionPos = INetworkObject.readToObject(DhSectionPos.zero(), in);
|
||||
this.sectionPos = in.readLong();
|
||||
this.clientTimestamp = this.readOptional(in, in::readLong);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ public class FullDataSourceResponseMessage extends TrackableMessage
|
||||
@Override
|
||||
public void decode0(ByteBuf in)
|
||||
{
|
||||
this.dataSourceDto = this.readOptional(in, () -> INetworkObject.readToObject(new FullDataSourceV2DTO(), in));
|
||||
this.dataSourceDto = this.readOptional(in, () -> INetworkObject.decodeToInstance(new FullDataSourceV2DTO(), in));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -36,6 +36,6 @@ public class RemotePlayerConfigMessage extends PluginChannelMessage
|
||||
public void encode(ByteBuf out) { this.payload.encode(out); }
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf in) { this.payload = INetworkObject.readToObject(new MultiplayerConfig(), in); }
|
||||
public void decode(ByteBuf in) { this.payload = INetworkObject.decodeToInstance(new MultiplayerConfig(), in); }
|
||||
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ public abstract class PluginChannelMessage implements INetworkObject
|
||||
return this.session;
|
||||
}
|
||||
|
||||
public void setConnection(PluginChannelSession connection)
|
||||
public void setSession(PluginChannelSession connection)
|
||||
{
|
||||
if (this.session != null)
|
||||
{
|
||||
|
||||
+6
-19
@@ -10,7 +10,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSende
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -43,7 +42,7 @@ public class PluginChannelSession extends NetworkEventSource
|
||||
}
|
||||
|
||||
|
||||
public void decodeAndHandle(ByteBuf byteBuf)
|
||||
public void tryHandleMessage(PluginChannelMessage message)
|
||||
{
|
||||
if (this.closeReason.get() != null)
|
||||
{
|
||||
@@ -52,31 +51,19 @@ public class PluginChannelSession extends NetworkEventSource
|
||||
|
||||
try
|
||||
{
|
||||
int version = byteBuf.readShort();
|
||||
if (version != ModInfo.PROTOCOL_VERSION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PluginChannelMessage msg = PluginMessageRegistry.INSTANCE.createMessage(byteBuf.readUnsignedShort());
|
||||
msg.decode(byteBuf);
|
||||
msg.session = this;
|
||||
|
||||
this.handleMessage(msg);
|
||||
this.handleMessage(message);
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.error("Failed to handle the message. New messages will be ignored.", e);
|
||||
LOGGER.error("Buffer: " + byteBuf.toString());
|
||||
byteBuf.resetReaderIndex();
|
||||
LOGGER.error("Buffer contents: " + ByteBufUtil.hexDump(byteBuf));
|
||||
LOGGER.error("Message: " + message);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
public <TResponse extends TrackableMessage> CompletableFuture<TResponse> sendRequest(TrackableMessage msg, Class<TResponse> responseClass)
|
||||
{
|
||||
msg.setConnection(this);
|
||||
msg.setSession(this);
|
||||
CompletableFuture<TResponse> responseFuture = this.createRequest(msg, responseClass);
|
||||
this.sendMessage(msg);
|
||||
return responseFuture;
|
||||
@@ -94,11 +81,11 @@ public class PluginChannelSession extends NetworkEventSource
|
||||
|
||||
if (this.serverPlayer != null)
|
||||
{
|
||||
PACKET_SENDER.sendPluginPacketServer(this.serverPlayer, encoder);
|
||||
PACKET_SENDER.sendPluginPacketServer(this.serverPlayer, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
PACKET_SENDER.sendPluginPacketClient(encoder);
|
||||
PACKET_SENDER.sendPluginPacketClient(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ public interface INetworkObject
|
||||
|
||||
void decode(ByteBuf in);
|
||||
|
||||
static <T extends INetworkObject> T readToObject(T obj, ByteBuf inputByteBuf)
|
||||
static <T extends INetworkObject> T decodeToInstance(T obj, ByteBuf inputByteBuf)
|
||||
{
|
||||
obj.decode(inputByteBuf);
|
||||
return obj;
|
||||
@@ -135,7 +135,7 @@ public interface INetworkObject
|
||||
// Primitives must be added manually here
|
||||
this.put(Integer.class, new Codec((obj, out) -> out.writeInt((int)obj), (obj, in) -> in.readInt()));
|
||||
|
||||
this.put(INetworkObject.class, new Codec(INetworkObject::encode, INetworkObject::readToObject));
|
||||
this.put(INetworkObject.class, new Codec(INetworkObject::encode, INetworkObject::decodeToInstance));
|
||||
this.put(Map.Entry.class, new Codec(
|
||||
(obj, out) -> {
|
||||
Map.Entry<?, ?> entry = (Entry<?, ?>) obj;
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.seibel.distanthorizons.core.level.DhServerLevel;
|
||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||
import com.seibel.distanthorizons.core.multiplayer.server.RemotePlayerConnectionHandler;
|
||||
import com.seibel.distanthorizons.core.multiplayer.server.ServerPlayerState;
|
||||
import com.seibel.distanthorizons.core.network.plugin.PluginChannelMessage;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
@@ -39,7 +40,7 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
private final HashMap<IServerLevelWrapper, DhServerLevel> levels;
|
||||
public final LocalSaveStructure saveStructure;
|
||||
|
||||
private final RemotePlayerConnectionHandler remotePlayerConnectionHandler;
|
||||
public final RemotePlayerConnectionHandler remotePlayerConnectionHandler;
|
||||
|
||||
|
||||
//==============//
|
||||
@@ -74,6 +75,7 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
level.registerNetworkHandlers(playerState);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayer(IServerPlayerWrapper serverPlayer)
|
||||
{
|
||||
this.getLevel(serverPlayer.getLevel()).removePlayer(serverPlayer);
|
||||
@@ -81,15 +83,14 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld
|
||||
|
||||
// If player's left, session is already closed
|
||||
}
|
||||
|
||||
public void changePlayerLevel(IServerPlayerWrapper player, IServerLevelWrapper origin, IServerLevelWrapper dest)
|
||||
{
|
||||
this.getLevel(dest).addPlayer(player);
|
||||
this.getLevel(origin).removePlayer(player);
|
||||
}
|
||||
public void handlePluginMessage(IServerPlayerWrapper player, ByteBuf buffer)
|
||||
{
|
||||
this.remotePlayerConnectionHandler.handlePluginMessage(player, buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public DhServerLevel getOrLoadLevel(@NotNull ILevelWrapper wrapper)
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package com.seibel.distanthorizons.core.wrapperInterfaces.misc;
|
||||
|
||||
import com.seibel.distanthorizons.core.network.plugin.PluginChannelMessage;
|
||||
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@@ -7,7 +8,7 @@ import java.util.function.Consumer;
|
||||
|
||||
public interface IPluginPacketSender extends IBindable
|
||||
{
|
||||
void sendPluginPacketClient(Consumer<ByteBuf> encoder);
|
||||
void sendPluginPacketServer(IServerPlayerWrapper serverPlayer, Consumer<ByteBuf> encoder);
|
||||
void sendPluginPacketClient(PluginChannelMessage message);
|
||||
void sendPluginPacketServer(IServerPlayerWrapper serverPlayer, PluginChannelMessage message);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user