mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
[server] Add BroadcastPlane
This commit is contained in:
parent
e8beaec1c3
commit
3442639631
2 changed files with 32 additions and 5 deletions
|
@ -42,7 +42,7 @@ namespace Nibriboard.Client
|
|||
/// <summary>
|
||||
/// The plane that this client is currently on.
|
||||
/// </summary>
|
||||
private Plane currentPlane;
|
||||
public Plane CurrentPlane;
|
||||
|
||||
/// <summary>
|
||||
/// The underlying websocket connection to the client.
|
||||
|
@ -304,13 +304,13 @@ namespace Nibriboard.Client
|
|||
protected ClientStatesMessage GenerateClientStateUpdate()
|
||||
{
|
||||
ClientStatesMessage result = new ClientStatesMessage();
|
||||
foreach (NibriClient client in manager.Clients)
|
||||
foreach (NibriClient otherClient in manager.Clients)
|
||||
{
|
||||
// Don't include ourselves in the update message!
|
||||
if (client == this)
|
||||
if (otherClient == this)
|
||||
continue;
|
||||
|
||||
result.ClientStates.Add(client.GenerateStateSnapshot());
|
||||
result.ClientStates.Add(otherClient.GenerateStateSnapshot());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -320,7 +320,12 @@ namespace Nibriboard.Client
|
|||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,29 @@ namespace Nibriboard.Client
|
|||
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()
|
||||
{
|
||||
while (true) {
|
||||
|
|
Loading…
Reference in a new issue