1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

[server] Send clients any chunk they ask for, as they probably know better than we do which ones they need

This commit is contained in:
Starbeamrainbowlabs 2017-12-15 20:05:18 +00:00
parent b4bd60ab59
commit ea4a8b9b15
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -366,18 +366,10 @@ namespace Nibriboard.Client
/// <param name="message">The message to process.</param> /// <param name="message">The message to process.</param>
protected async Task handleChunkUpdateRequestMessage(ChunkUpdateRequestMessage message) protected async Task handleChunkUpdateRequestMessage(ChunkUpdateRequestMessage message)
{ {
chunkCache.Remove(message.ForgottenChunksAsReferences(this.CurrentPlane)); List<ChunkReference> requestedChunkRefs = message.ForgottenChunksAsReferences(this.CurrentPlane);
chunkCache.Remove(requestedChunkRefs);
ChunkUpdateMessage response = new ChunkUpdateMessage(); await SendChunks(requestedChunkRefs);
List<ChunkReference> 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);
} }
/// <summary> /// <summary>
@ -553,6 +545,14 @@ namespace Nibriboard.Client
return; 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(); ChunkUpdateMessage updateMessage = new ChunkUpdateMessage();
foreach(ChunkReference chunkRef in chunkRefs) foreach(ChunkReference chunkRef in chunkRefs)
updateMessage.Chunks.Add(await CurrentPlane.FetchChunk(chunkRef)); updateMessage.Chunks.Add(await CurrentPlane.FetchChunk(chunkRef));