diff --git a/src/client/Master/Data/MasterGetServersEntry.cs b/src/client/Master/Data/MasterGetServersEntry.cs new file mode 100644 index 0000000..56118de --- /dev/null +++ b/src/client/Master/Data/MasterGetServersEntry.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace NPSharp.Master.Data +{ + public class MasterGetServersEntry + { + internal MasterGetServersEntry(byte[] data) + { + if (data.Length < 4 || data.Length % 2 > 0) + throw new ArgumentException("Data length must be at least 4 bytes of IP address and can afterwards only contain full 2 byte segments of ushort port data."); + + IP = new IPAddress(data.Take(4).ToArray()); + Ports = new ushort[(data.Length - 4) % sizeof(ushort)]; + for (var i = 4; i < data.Length; i += sizeof(ushort)) + { + Ports[(i - 4)/2] = (ushort) IPAddress.NetworkToHostOrder((short) BitConverter.ToUInt16(data, i)); + } + } + + internal MasterGetServersEntry(IPAddress ip, ushort[] ports) + { + IP = ip; + Ports = ports; + } + + public IPAddress IP { get; private set; } + + public ushort[] Ports { get; set; } + } +} diff --git a/src/client/NPSharp.Client.csproj b/src/client/NPSharp.Client.csproj index 57db580..56e611f 100644 --- a/src/client/NPSharp.Client.csproj +++ b/src/client/NPSharp.Client.csproj @@ -45,6 +45,7 @@ +