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

[server] Get nibri clients to listen for chunk updates and send them down the wire

This commit is contained in:
Starbeamrainbowlabs 2017-04-16 15:19:59 +01:00
parent ce3197dd98
commit 48c2011500

View file

@ -288,16 +288,28 @@ namespace Nibriboard.Client
/// </summary> /// </summary>
protected Task handlePlaneChangeMessage(PlaneChangeMessage message) protected Task handlePlaneChangeMessage(PlaneChangeMessage message)
{ {
// Create a new plane with the specified name if it doesn't exist already
if(manager.SpaceManager[message.NewPlaneName] == default(Plane)) if(manager.SpaceManager[message.NewPlaneName] == default(Plane))
throw new NotImplementedException(); // todo create a new plane here throw new NotImplementedException("Plane creation hasn't been implemented yet"); // todo create a new plane here
// Remove the event listener from the old plane if there is indeed an old plane to remove it from
if(CurrentPlane != null)
CurrentPlane.OnChunkUpdate -= handleChunkUpdateEvent;
// Swap out the current plane
CurrentPlane = manager.SpaceManager[message.NewPlaneName];
// Attach a listener to the new plane
CurrentPlane.OnChunkUpdate += handleChunkUpdateEvent;
// Tell the client that the switchove all went according to plan
message.IsOK = true; message.IsOK = true;
Send(message); Send(message);
return Task.CompletedTask; return Task.CompletedTask;
} }
/// <summary>
/// Handles requests from clients for chunk updates.
/// </summary>
/// <param name="message">The message to process.</param>
protected async Task handleChunkUpdateRequestMessage(ChunkUpdateRequestMessage message) protected async Task handleChunkUpdateRequestMessage(ChunkUpdateRequestMessage message)
{ {
chunkCache.Remove(message.ForgottenChunks); chunkCache.Remove(message.ForgottenChunks);
@ -316,6 +328,7 @@ namespace Nibriboard.Client
/// <summary> /// <summary>
/// Handles an incoming cursor position message from the client.. /// Handles an incoming cursor position message from the client..
/// </summary> /// </summary>
/// <param name="message">The message to process.</param>
protected Task handleCursorPositionMessage(CursorPositionMessage message) { protected Task handleCursorPositionMessage(CursorPositionMessage message) {
AbsoluteCursorPosition = message.AbsCursorPosition; AbsoluteCursorPosition = message.AbsCursorPosition;
@ -361,6 +374,18 @@ namespace Nibriboard.Client
#endregion #endregion
#region RippleSpace Event Handlers
protected void handleChunkUpdateEvent(object sender, ChunkUpdateEventArgs eventArgs)
{
ChunkUpdateMessage clientNotification = new ChunkUpdateMessage() {
Chunks = new List<Chunk>() { sender as Chunk }
};
Send(clientNotification);
}
#endregion
/// <summary> /// <summary>
/// Generates an update message that contains information about the locations and states of all connected clients. /// Generates an update message that contains information about the locations and states of all connected clients.