Class NetUtility
Static class containing utilities used for the in-game network system.
Inherited Members
Namespace: SociallyDistant.Core.OS.Network
Assembly: SociallyDistant.Framework.dll
Syntax
public static class NetUtility
Fields
LoopbackSubnet
A Subnet value representing the 127.0.0.0/8 network range, used for loopback addresses.
Declaration
public static readonly Subnet LoopbackSubnet
Field Value
| Type | Description |
|---|---|
| Subnet |
MaxPacketsPerSimulation
The maximum number of packets a given network node will process during a single simulation update. Queueing more than this amount of packets before the next simulation update may cause the game to lag.
Declaration
public const int MaxPacketsPerSimulation = 16384
Field Value
| Type | Description |
|---|---|
| int |
Properties
LoopbackAddress
Value that should evaluate to 127.0.0.1, the most-common loopback address.
Declaration
public static uint LoopbackAddress { get; }
Property Value
| Type | Description |
|---|---|
| uint |
Methods
CountBits(uint)
Count the number of bits set in an unsigned integer.
Declaration
public static int CountBits(uint value)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | value | Any number. |
Returns
| Type | Description |
|---|---|
| int | A number indicating the amount of bits set in the given number. |
Remarks
By the way, this entire game is just bits and bytes flowing through pipes and wires.
GetMacAddressString(long)
Get the MAC address string representing a given number.
Declaration
public static string GetMacAddressString(long macAddress)
Parameters
| Type | Name | Description |
|---|---|---|
| long | macAddress | Any 64-bit integer. |
Returns
| Type | Description |
|---|---|
| string | A MAC address string representing the given number. |
Remarks
Generally, a MAC address in real life contains 6 bytes of actual data. As such, only the first 6 bytes (48 bits) of the provided number are taken into account.
This means that, given a value of 0xffffaabbccddeeff, a string of aa:bb:cc:dd:ee:ff should be returned.
GetNetworkAddressString(uint)
Get the IPv4 string representation of a network address.
Declaration
public static string GetNetworkAddressString(uint networkAddress)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | networkAddress | Any 32-bit integer representing a network address. |
Returns
| Type | Description |
|---|---|
| string | The text representation of the given address. |
GetRandomMacAddress()
Generate a random MAC address, storing it in a 64-bit integer.
Declaration
public static long GetRandomMacAddress()
Returns
| Type | Description |
|---|---|
| long | A number representing the random MAC address. |
TryParseCidrNotation(string?, out Subnet)
Attempt to parse the CIDR representation of a network.
Declaration
public static bool TryParseCidrNotation(string? cidrNotation, out Subnet subnet)
Parameters
| Type | Name | Description |
|---|---|---|
| string | cidrNotation | A string containing a range of IP addresses in CIDR notation. |
| Subnet | subnet | If parsing was successful, a Subnet value representing the range of addresses in the network. |
Returns
| Type | Description |
|---|---|
| bool | True if the parsing was successful, false otherwise. |
TryParseMacAddress(string, out long)
Attempt to parse a MAC address string.
Declaration
public static bool TryParseMacAddress(string macAddressString, out long macAddress)
Parameters
| Type | Name | Description |
|---|---|---|
| string | macAddressString | A string representing a network MAC address. |
| long | macAddress | If parsing was successful, will be set to the value of the MAC address. |
Returns
| Type | Description |
|---|---|
| bool | True if parsing was successful, false otherwise. |
TryParseNetworkAddress(string?, out uint)
Try to parse an IP address.
Declaration
public static bool TryParseNetworkAddress(string? networkAddressString, out uint networkAddress)
Parameters
| Type | Name | Description |
|---|---|---|
| string | networkAddressString | The string representation of an IPv4 address. |
| uint | networkAddress | The parsed IP address, or 0 if parsing failed. |
Returns
| Type | Description |
|---|---|
| bool | True if parsing was successful. |