/// <summary> /// Create a new netcode.io server. /// </summary> /// <param name="bindAddress">The address to bind to.</param> /// <param name="protocolId">The protocol ID. This should be unique to your game or application.</param> /// <param name="privateKey">The symmetric private key used between your clients and the dedicated servers.</param> /// <param name="time">The starting time for the server as a double value. Normally this will be 0 in the constructor.</param> public Server(string bindAddress, UInt64 protocolId, byte[] privateKey, double time) { NetcodeLibrary.Init(); if (privateKey == null) { throw new ArgumentNullException(nameof(privateKey)); } if (privateKey.Length != netcodeNATIVE.NETCODE_KEY_BYTES) { throw new ArgumentException( $"The private symmetric key must be {netcodeNATIVE.NETCODE_KEY_BYTES} bytes long.", nameof(privateKey)); } var unmanagedPrivateKey = Marshal.AllocHGlobal(privateKey.Length); Marshal.Copy(privateKey, 0, unmanagedPrivateKey, privateKey.Length); _server = netcodeNATIVE.netcode_server_create( bindAddress, protocolId, unmanagedPrivateKey, time); Marshal.FreeHGlobal(unmanagedPrivateKey); if (_server == null) { throw new InvalidOperationException("Unable to create native netcode.io server"); } }
/// <summary> /// Create a new netcode.io client. /// </summary> /// <param name="bindAddress">The address to bind to.</param> /// <param name="time">The starting time for the server as a double value. Normally this will be 0 in the constructor.</param> public Client(string bindAddress, double time) { NetcodeLibrary.Init(); _client = netcodeNATIVE.netcode_client_create(bindAddress, time); }