mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
Add files I missed
This commit is contained in:
parent
abbcb7a8c8
commit
504f8daed2
5 changed files with 105 additions and 1 deletions
21
Nibriboard/Client/Messages/HandshakeRequestMessage.cs
Normal file
21
Nibriboard/Client/Messages/HandshakeRequestMessage.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace Nibriboard.Client.Messages
|
||||||
|
{
|
||||||
|
public class HandshakeRequestMessage : Message
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The initial visible area on the client's screen.
|
||||||
|
/// Very useful for determining which chunks we should send a client when they first connect.
|
||||||
|
/// </summary>
|
||||||
|
public Rectangle InitialViewport = new Rectangle(
|
||||||
|
0, 0,
|
||||||
|
1366, 768
|
||||||
|
);
|
||||||
|
|
||||||
|
public HandshakeRequestMessage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
Nibriboard/Client/Messages/Message.cs
Normal file
13
Nibriboard/Client/Messages/Message.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Nibriboard.Client.Messages
|
||||||
|
{
|
||||||
|
public class Message
|
||||||
|
{
|
||||||
|
public readonly DateTime TimeSent = DateTime.Now;
|
||||||
|
|
||||||
|
public Message()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ namespace Nibriboard.Client
|
||||||
|
|
||||||
private Dictionary<string, Type> messageEventTypes = new Dictionary<string, Type>()
|
private Dictionary<string, Type> messageEventTypes = new Dictionary<string, Type>()
|
||||||
{
|
{
|
||||||
|
["handshake"] =
|
||||||
};
|
};
|
||||||
|
|
||||||
public NibriClient(NibriClientManager inManager, WebSocket inClient)
|
public NibriClient(NibriClientManager inManager, WebSocket inClient)
|
||||||
|
|
30
Nibriboard/Utilities/JsonUtilities.cs
Normal file
30
Nibriboard/Utilities/JsonUtilities.cs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace SBRL.Utilities
|
||||||
|
{
|
||||||
|
public static class JsonUtilities
|
||||||
|
{
|
||||||
|
public static T DeserializeProperty<T>(string json, string targetPropertyName)
|
||||||
|
{
|
||||||
|
using (StringReader stringReader = new StringReader(json))
|
||||||
|
using (JsonTextReader jsonReader = new JsonTextReader(stringReader))
|
||||||
|
{
|
||||||
|
while (jsonReader.Read())
|
||||||
|
{
|
||||||
|
if (jsonReader.TokenType == JsonToken.PropertyName
|
||||||
|
&& (string)jsonReader.Value == targetPropertyName)
|
||||||
|
{
|
||||||
|
jsonReader.Read();
|
||||||
|
|
||||||
|
JsonSerializer serializer = new JsonSerializer();
|
||||||
|
return serializer.Deserialize<T>(jsonReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
40
Nibriboard/Utilities/PointExtensions.cs
Normal file
40
Nibriboard/Utilities/PointExtensions.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace SBRL.Utilities
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A selection of extensions to the System.Drawing.Point class to make things easier :)
|
||||||
|
/// </summary>
|
||||||
|
public static class PointExtensions
|
||||||
|
{
|
||||||
|
public static Point Add(this Point a, Point b)
|
||||||
|
{
|
||||||
|
return new Point(
|
||||||
|
a.X + b.X,
|
||||||
|
a.Y + b.X
|
||||||
|
);
|
||||||
|
}
|
||||||
|
public static Point Subtract(this Point a, Point b)
|
||||||
|
{
|
||||||
|
return new Point(
|
||||||
|
a.X - b.X,
|
||||||
|
a.Y - b.X
|
||||||
|
);
|
||||||
|
}
|
||||||
|
public static Point Divide(this Point a, int b)
|
||||||
|
{
|
||||||
|
return new Point(
|
||||||
|
a.X / b,
|
||||||
|
a.Y / b
|
||||||
|
);
|
||||||
|
}
|
||||||
|
public static Point Multiply(this Point a, int b)
|
||||||
|
{
|
||||||
|
return new Point(
|
||||||
|
a.X * b,
|
||||||
|
a.Y * b
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue