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

[server] Properly respond to handshake requests.

This commit is contained in:
Starbeamrainbowlabs 2017-02-19 11:33:03 +00:00
parent 73e30f3027
commit 494b0561bb
3 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,30 @@
using System;
using Newtonsoft.Json;
using SBRL.Utilities;
using SBRL.Utilities.Solutions;
namespace Nibriboard.Client.Messages
{
/// <summary>
/// Holds the server's response to a HandshakeRequest.
/// </summary>
public class HandshakeResponseMessage : Message
{
/// <summary>
/// The id that the server is assigning to the nibri client.
/// </summary>
public int Id;
/// <summary>
/// The colour that the server is assigning to the nibri client.
/// </summary>
[JsonConverter(typeof(ToStringJsonConverter))]
public ColourHSL Colour;
public HandshakeResponseMessage()
{
}
}
}

View file

@ -71,6 +71,10 @@ namespace Nibriboard.Client
/// </summary>
/// <value>The absolute cursor position.</value>
public Vector2 AbsoluteCursorPosition { get; private set; } = Vector2.Zero;
/// <summary>
/// This client's colour. Used to tell multiple clients apart visually.
/// </summary>
public readonly ColourHSL Colour = ColourHSL.RandomSaturated();
#region Core Setup & Message Routing Logic
@ -173,6 +177,18 @@ namespace Nibriboard.Client
AbsoluteCursorPosition = message.InitialAbsCursorPosition;
// Tell everyone else about the new client
ClientStatesMessage newClientNotification = new ClientStatesMessage();
newClientNotification.ClientStates.Add(GenerateStateSnapshot());
manager.Broadcast(newClientNotification);
// Send the new client a response to their handshake request
HandshakeResponseMessage handshakeResponse = new HandshakeResponseMessage();
handshakeResponse.Id = Id;
handshakeResponse.Colour = Colour;
Send(handshakeResponse);
// Tell the new client about everyone else who's connected
// FUTURE: If we need to handle a large number of connections, we should generate this message based on the chunks surrounding the client
Send(GenerateClientStateUpdate());
return Task.CompletedTask;

View file

@ -81,6 +81,7 @@
<Compile Include="Client\Messages\ClientStatesMessage.cs" />
<Compile Include="Utilities\ColourHSL.cs" />
<Compile Include="Utilities\ToStringJsonConverter.cs" />
<Compile Include="Client\Messages\HandshakeResponseMessage.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ClientFiles\index.html" />