Example #1
0
        /// <summary>
        /// Sends variable list of chunks to this client.
        /// Automatically fetches the chunks by reference from the current plane.
        /// </summary>
        /// <param name="chunkRefs">The references of the chunks to send.</param>
        protected async Task SendChunks(IEnumerable <ChunkReference> chunkRefs)
        {
            if (CurrentPlane == default(Plane))
            {
                await Send(new ExceptionMessage(1, "You're not on a plane yet, so you can't request chunks. " +
                                                "Try joining a plane and sending that request again."));

                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));
            }

            Log.WriteLine("[NibriClient#{0}/SendChunks] Sending {1} chunks", Id, updateMessage.Chunks.Count);
            await Send(updateMessage);
        }
Example #2
0
        protected void handleChunkUpdateEvent(object sender, MultiChunkUpdateEventArgs eventArgs)
        {
            Log.WriteLine(
                "[NibriClient#{0}] Sending {0} chunk updates (for {1})",
                Id,
                eventArgs.UpdatedChunks.Count(),
                string.Join(", ", eventArgs.UpdatedChunks.Select((Chunk chunk) => chunk.Location))
                );
            ChunkUpdateMessage clientNotification = new ChunkUpdateMessage()
            {
                Chunks = new List <Chunk>(eventArgs.UpdatedChunks)
            };

            Send(clientNotification).Wait();
        }