Add MasterGetServersEntry data class.

feature-npv2
Icedream 2014-07-05 19:41:59 +02:00
parent d90ceaf1dc
commit c89d93b147
2 changed files with 36 additions and 0 deletions

View File

@ -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; }
}
}

View File

@ -45,6 +45,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Authentication\SessionAuthenticationClient.cs" /> <Compile Include="Authentication\SessionAuthenticationClient.cs" />
<Compile Include="Authentication\SessionAuthenticationResult.cs" /> <Compile Include="Authentication\SessionAuthenticationResult.cs" />
<Compile Include="Master\Data\MasterGetServersEntry.cs" />
<Compile Include="Master\Data\MasterGetServersKeywords.cs" /> <Compile Include="Master\Data\MasterGetServersKeywords.cs" />
<Compile Include="Master\Messages\Client\MasterGetServersMessage.cs" /> <Compile Include="Master\Messages\Client\MasterGetServersMessage.cs" />
<Compile Include="Master\DedicatedServerEntry.cs" /> <Compile Include="Master\DedicatedServerEntry.cs" />