From ea4a8b9b15059ab43fcc091491aea31840d8f05c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 15 Dec 2017 20:05:18 +0000 Subject: [PATCH] [server] Send clients any chunk they ask for, as they probably know better than we do which ones they need --- Nibriboard/Client/NibriClient.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Nibriboard/Client/NibriClient.cs b/Nibriboard/Client/NibriClient.cs index daf1273..b18de53 100644 --- a/Nibriboard/Client/NibriClient.cs +++ b/Nibriboard/Client/NibriClient.cs @@ -366,18 +366,10 @@ namespace Nibriboard.Client /// The message to process. protected async Task handleChunkUpdateRequestMessage(ChunkUpdateRequestMessage message) { - chunkCache.Remove(message.ForgottenChunksAsReferences(this.CurrentPlane)); + List requestedChunkRefs = message.ForgottenChunksAsReferences(this.CurrentPlane); + chunkCache.Remove(requestedChunkRefs); - ChunkUpdateMessage response = new ChunkUpdateMessage(); - List missingChunks = ChunkTools.GetContainingChunkReferences(CurrentPlane, CurrentViewPort); - missingChunks = chunkCache.FindMissing(missingChunks); - - await SendChunks(missingChunks); - /*response.Chunks = await CurrentPlane.FetchChunks(missingChunks); - Console.WriteLine(JsonConvert.SerializeObject(response)); - Send(response);*/ - - chunkCache.Add(missingChunks); + await SendChunks(requestedChunkRefs); } /// @@ -553,6 +545,14 @@ namespace Nibriboard.Client return; } + if(chunkRefs.Count() == 0) { + Log.WriteLine("[NibriClient#{0}/SendChunks] Can't send 0 chunks!", Id); + return; + } + + // Keep track of the fact that we've sent the client a bunch of chunks + chunkCache.Add(chunkRefs); + ChunkUpdateMessage updateMessage = new ChunkUpdateMessage(); foreach(ChunkReference chunkRef in chunkRefs) updateMessage.Chunks.Add(await CurrentPlane.FetchChunk(chunkRef));