1
0
Fork 0

[server] Add BroadcastPlane

This commit is contained in:
Starbeamrainbowlabs 2017-03-20 18:28:56 +00:00
parent e8beaec1c3
commit 3442639631
2 changed files with 32 additions and 5 deletions

View File

@ -42,7 +42,7 @@ namespace Nibriboard.Client
/// <summary> /// <summary>
/// The plane that this client is currently on. /// The plane that this client is currently on.
/// </summary> /// </summary>
private Plane currentPlane; public Plane CurrentPlane;
/// <summary> /// <summary>
/// The underlying websocket connection to the client. /// The underlying websocket connection to the client.
@ -304,13 +304,13 @@ namespace Nibriboard.Client
protected ClientStatesMessage GenerateClientStateUpdate() protected ClientStatesMessage GenerateClientStateUpdate()
{ {
ClientStatesMessage result = new ClientStatesMessage(); ClientStatesMessage result = new ClientStatesMessage();
foreach (NibriClient client in manager.Clients) foreach (NibriClient otherClient in manager.Clients)
{ {
// Don't include ourselves in the update message! // Don't include ourselves in the update message!
if (client == this) if (otherClient == this)
continue; continue;
result.ClientStates.Add(client.GenerateStateSnapshot()); result.ClientStates.Add(otherClient.GenerateStateSnapshot());
} }
return result; return result;
} }
@ -320,7 +320,12 @@ namespace Nibriboard.Client
/// </summary> /// </summary>
protected async Task SendChunks(params ChunkReference[] chunkRefs) protected async Task SendChunks(params ChunkReference[] chunkRefs)
{ {
if(CurrentPlane == default(Plane))
{
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.");
return;
}
} }
} }
} }

View File

@ -90,7 +90,29 @@ namespace Nibriboard.Client
client.Send(message); client.Send(message);
} }
} }
/// <summary>
/// Sends a message to everyone on the same plane as the sender, except the sender themselves.
/// </summary>
/// <param name="sendingClient">The sending client.</param>
/// <param name="message">The message to send.</param>
public void BroadcastPlane(NibriClient sendingClient, Message message)
{
foreach(NibriClient client in Clients)
{
// Don't send the message to the sender
if(client == sendingClient)
continue;
// Only send the message to others on the same plane
if(client.CurrentPlane != sendingClient.CurrentPlane)
continue;
client.Send(message);
}
}
/// <summary>
/// Periodically tidies up the client list, disconnecting old clients.
/// </summary>
private async Task ClientMaintenanceMonkey() private async Task ClientMaintenanceMonkey()
{ {
while (true) { while (true) {