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:
parent
73e30f3027
commit
494b0561bb
3 changed files with 47 additions and 0 deletions
30
Nibriboard/Client/Messages/HandshakeResponseMessage.cs
Normal file
30
Nibriboard/Client/Messages/HandshakeResponseMessage.cs
Normal 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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -71,6 +71,10 @@ namespace Nibriboard.Client
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The absolute cursor position.</value>
|
/// <value>The absolute cursor position.</value>
|
||||||
public Vector2 AbsoluteCursorPosition { get; private set; } = Vector2.Zero;
|
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
|
#region Core Setup & Message Routing Logic
|
||||||
|
|
||||||
|
@ -173,6 +177,18 @@ namespace Nibriboard.Client
|
||||||
AbsoluteCursorPosition = message.InitialAbsCursorPosition;
|
AbsoluteCursorPosition = message.InitialAbsCursorPosition;
|
||||||
|
|
||||||
// Tell everyone else about the new client
|
// 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());
|
Send(GenerateClientStateUpdate());
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<Compile Include="Client\Messages\ClientStatesMessage.cs" />
|
<Compile Include="Client\Messages\ClientStatesMessage.cs" />
|
||||||
<Compile Include="Utilities\ColourHSL.cs" />
|
<Compile Include="Utilities\ColourHSL.cs" />
|
||||||
<Compile Include="Utilities\ToStringJsonConverter.cs" />
|
<Compile Include="Utilities\ToStringJsonConverter.cs" />
|
||||||
|
<Compile Include="Client\Messages\HandshakeResponseMessage.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="ClientFiles\index.html" />
|
<EmbeddedResource Include="ClientFiles\index.html" />
|
||||||
|
|
Loading…
Reference in a new issue