1
0
Fork 0

[server] Update the nibri client to be plane-aware

This commit is contained in:
Starbeamrainbowlabs 2017-03-20 18:34:34 +00:00
parent 525399a0a6
commit 535c0436de
2 changed files with 17 additions and 4 deletions

View File

@ -7,7 +7,7 @@ namespace Nibriboard.Client.Messages
{ {
public class ChunkUpdateMessage : Message public class ChunkUpdateMessage : Message
{ {
List<Chunk> Chunks = new List<Chunk>(); public List<Chunk> Chunks = new List<Chunk>();
public ChunkUpdateMessage() public ChunkUpdateMessage()
{ {

View File

@ -61,6 +61,9 @@ namespace Nibriboard.Client
/// Whether this nibri client is still connected. /// Whether this nibri client is still connected.
/// </summary> /// </summary>
public bool Connected = true; public bool Connected = true;
/// <summary>
/// Fires when this nibri client disconnects.
/// </summary>
public event NibriDisconnectedEvent Disconnected; public event NibriDisconnectedEvent Disconnected;
/// <summary> /// <summary>
@ -291,7 +294,7 @@ namespace Nibriboard.Client
// TODO: Buffer these updates and send them about 5 times a second // TODO: Buffer these updates and send them about 5 times a second
ClientStatesMessage updateMessage = new ClientStatesMessage(); ClientStatesMessage updateMessage = new ClientStatesMessage();
updateMessage.ClientStates.Add(this.GenerateStateSnapshot()); updateMessage.ClientStates.Add(this.GenerateStateSnapshot());
manager.Broadcast(this, updateMessage); manager.BroadcastPlane(this, updateMessage);
return Task.CompletedTask; return Task.CompletedTask;
} }
@ -299,7 +302,7 @@ namespace Nibriboard.Client
/// <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.
/// Automatically omits information about the current client. /// Automatically omits information about the current client, and clients on other planes.
/// </summary> /// </summary>
/// <returns>The client state update message.</returns> /// <returns>The client state update message.</returns>
protected ClientStatesMessage GenerateClientStateUpdate() protected ClientStatesMessage GenerateClientStateUpdate()
@ -310,6 +313,9 @@ namespace Nibriboard.Client
// Don't include ourselves in the update message! // Don't include ourselves in the update message!
if (otherClient == this) if (otherClient == this)
continue; continue;
// Only include other nibri clients on our plane
if(otherClient.CurrentPlane != CurrentPlane)
continue;
result.ClientStates.Add(otherClient.GenerateStateSnapshot()); result.ClientStates.Add(otherClient.GenerateStateSnapshot());
} }
@ -318,15 +324,22 @@ namespace Nibriboard.Client
/// <summary> /// <summary>
/// Sends variable list of chunks to this client. /// Sends variable list of chunks to this client.
/// Automatically fetches the chunks by reference from the current plane.
/// </summary> /// </summary>
protected async Task SendChunks(params ChunkReference[] chunkRefs) protected async Task SendChunks(params ChunkReference[] chunkRefs)
{ {
if(CurrentPlane == default(Plane)) if(CurrentPlane == default(Plane))
{ {
Send(new ExceptionMessage("You're not on a plane yet, so you can't request chunks." + Send(new ExceptionMessage("You're not on a plane yet, so you can't request chunks." +
"Try joining a plane and sending that request again."); "Try joining a plane and sending that request again."));
return; return;
} }
ChunkUpdateMessage updateMessage = new ChunkUpdateMessage();
foreach(ChunkReference chunkRef in chunkRefs)
updateMessage.Chunks.Add(await CurrentPlane.FetchChunk(chunkRef));
Send(updateMessage);
} }
} }
} }