From b2be6e590bd7aa520ae32cb56d9e7c85251e9c65 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Sat, 4 Mar 2017 21:49:51 +0000
Subject: [PATCH] [server] Start sorting out chunk synchronisation

---
 .../Client/Messages/ChunkUpdateMessage.cs     | 25 +++++++++++++++++++
 .../Client/Messages/ClientStatesMessage.cs    |  2 +-
 Nibriboard/Client/Messages/Message.cs         |  3 +++
 Nibriboard/Client/NibriClient.cs              | 10 +++++++-
 Nibriboard/Client/NibriClientManager.cs       |  4 +--
 Nibriboard/Nibriboard.csproj                  |  1 +
 Nibriboard/NibriboardServer.cs                |  2 +-
 Nibriboard/RippleSpace/ChunkReference.cs      |  1 +
 Nibriboard/RippleSpace/ClientState.cs         |  2 +-
 Nibriboard/RippleSpace/Plane.cs               |  1 +
 Nibriboard/RippleSpace/Reference.cs           |  2 +-
 11 files changed, 46 insertions(+), 7 deletions(-)
 create mode 100644 Nibriboard/Client/Messages/ChunkUpdateMessage.cs

diff --git a/Nibriboard/Client/Messages/ChunkUpdateMessage.cs b/Nibriboard/Client/Messages/ChunkUpdateMessage.cs
new file mode 100644
index 0000000..8664e18
--- /dev/null
+++ b/Nibriboard/Client/Messages/ChunkUpdateMessage.cs
@@ -0,0 +1,25 @@
+﻿using System;
+using System.Collections.Generic;
+
+using Nibriboard.RippleSpace;
+
+namespace Nibriboard.Client.Messages
+{
+	public class ChunkUpdateMessage : Message
+	{
+		List<Chunk> Chunks = new List<Chunk>();
+
+		public ChunkUpdateMessage()
+		{
+		}
+		/// <summary>
+		/// Creates a new ChunkUpdateMessaage containing the given list of chunks.
+		/// </summary>
+		/// <param name="chunks">Chunks.</param>
+		public ChunkUpdateMessage(params Chunk[] chunks)
+		{
+			Chunks = new List<Chunk>(chunks);
+		}
+	}
+}
+
diff --git a/Nibriboard/Client/Messages/ClientStatesMessage.cs b/Nibriboard/Client/Messages/ClientStatesMessage.cs
index c1457ad..f2dc1fd 100644
--- a/Nibriboard/Client/Messages/ClientStatesMessage.cs
+++ b/Nibriboard/Client/Messages/ClientStatesMessage.cs
@@ -1,7 +1,7 @@
 ﻿using System;
 using System.Collections.Generic;
 
-using RippleSpace;
+using Nibriboard.RippleSpace;
 
 namespace Nibriboard.Client.Messages
 {
diff --git a/Nibriboard/Client/Messages/Message.cs b/Nibriboard/Client/Messages/Message.cs
index 3df574c..b50a636 100644
--- a/Nibriboard/Client/Messages/Message.cs
+++ b/Nibriboard/Client/Messages/Message.cs
@@ -2,6 +2,9 @@
 
 namespace Nibriboard.Client.Messages
 {
+	/// <summary>
+	/// Represents a message that is passed between the client and server - in either direction.
+	/// </summary>
 	public class Message
 	{
 		/// <summary>
diff --git a/Nibriboard/Client/NibriClient.cs b/Nibriboard/Client/NibriClient.cs
index 8e273fb..f1a417d 100644
--- a/Nibriboard/Client/NibriClient.cs
+++ b/Nibriboard/Client/NibriClient.cs
@@ -9,7 +9,7 @@ using IotWeb.Common.Http;
 using Newtonsoft.Json;
 using SBRL.Utilities;
 using Nibriboard.Client.Messages;
-using RippleSpace;
+using Nibriboard.RippleSpace;
 
 namespace Nibriboard.Client
 {
@@ -273,5 +273,13 @@ namespace Nibriboard.Client
 			}
 			return result;
 		}
+
+		/// <summary>
+		/// Sends variable list of chunks to this client.
+		/// </summary>
+		protected async Task SendChunks(params ChunkReference[] chunkRefs)
+		{
+
+		}
 	}
 }
diff --git a/Nibriboard/Client/NibriClientManager.cs b/Nibriboard/Client/NibriClientManager.cs
index de76266..b54199d 100644
--- a/Nibriboard/Client/NibriClientManager.cs
+++ b/Nibriboard/Client/NibriClientManager.cs
@@ -17,7 +17,7 @@ namespace Nibriboard.Client
 		/// <summary>
 		/// The ripple space manager that this client manager is connected to.
 		/// </summary>
-		public RippleSpaceManager SpaceManager;
+		public RippleSpaceManager SpaceManager { get; private set; }
 
 		private ClientSettings clientSettings;
 		public List<NibriClient> Clients = new List<NibriClient>();
@@ -46,7 +46,7 @@ namespace Nibriboard.Client
 			clientSettings = inClientSettings;
 			canceller = inCancellationToken;
 
-			spaceManager = inSpaceManager;
+			SpaceManager = inSpaceManager;
 		}
 
 		/// <summary>
diff --git a/Nibriboard/Nibriboard.csproj b/Nibriboard/Nibriboard.csproj
index 223b2bc..038f3a4 100644
--- a/Nibriboard/Nibriboard.csproj
+++ b/Nibriboard/Nibriboard.csproj
@@ -85,6 +85,7 @@
     <Compile Include="Client\Messages\ShutdownMessage.cs" />
     <Compile Include="Client\Messages\IdleDisconnectMessage.cs" />
     <Compile Include="Client\Messages\HeartbeatMessage.cs" />
+    <Compile Include="Client\Messages\ChunkUpdateMessage.cs" />
   </ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="ClientFiles\index.html" />
diff --git a/Nibriboard/NibriboardServer.cs b/Nibriboard/NibriboardServer.cs
index caff65f..ba65810 100644
--- a/Nibriboard/NibriboardServer.cs
+++ b/Nibriboard/NibriboardServer.cs
@@ -55,7 +55,7 @@ namespace Nibriboard
 			// Websocket setup
 			clientManager = new NibriClientManager(
 				clientSettings,
-				
+				planeManager,
 				clientManagerCanceller.Token
 			);
 			httpServer.AddWebSocketRequestHandler(
diff --git a/Nibriboard/RippleSpace/ChunkReference.cs b/Nibriboard/RippleSpace/ChunkReference.cs
index 2ac4c69..f14c749 100644
--- a/Nibriboard/RippleSpace/ChunkReference.cs
+++ b/Nibriboard/RippleSpace/ChunkReference.cs
@@ -1,6 +1,7 @@
 ﻿using System;
 using System.Security.Policy;
 using System.IO;
+
 namespace Nibriboard.RippleSpace
 {
 	/// <summary>
diff --git a/Nibriboard/RippleSpace/ClientState.cs b/Nibriboard/RippleSpace/ClientState.cs
index 8118a32..b8d03dc 100644
--- a/Nibriboard/RippleSpace/ClientState.cs
+++ b/Nibriboard/RippleSpace/ClientState.cs
@@ -4,7 +4,7 @@ using SBRL.Utilities;
 using Newtonsoft.Json;
 using SBRL.Utilities.Solutions;
 
-namespace RippleSpace
+namespace Nibriboard.RippleSpace
 {
 	/// <summary>
 	/// Represents a client's state at a particular point in time.
diff --git a/Nibriboard/RippleSpace/Plane.cs b/Nibriboard/RippleSpace/Plane.cs
index 21172ea..be7c171 100644
--- a/Nibriboard/RippleSpace/Plane.cs
+++ b/Nibriboard/RippleSpace/Plane.cs
@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
 using System.IO;
+
 namespace Nibriboard.RippleSpace
 {
 	/// <summary>
diff --git a/Nibriboard/RippleSpace/Reference.cs b/Nibriboard/RippleSpace/Reference.cs
index 3e19c13..5ea865e 100644
--- a/Nibriboard/RippleSpace/Reference.cs
+++ b/Nibriboard/RippleSpace/Reference.cs
@@ -1,5 +1,5 @@
 ﻿using System;
-using System.Security.Policy;
+
 namespace Nibriboard.RippleSpace
 {
 	/// <summary>
