/**
* Copyright 2018 The Nakama Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Nakama
{
using System;
using System.Net.Security;
///
/// A group of options to configure the Client.
///
public sealed class ClientOptions
{
///
/// The default host address used by the client.
///
public const string DefaultHost = "127.0.0.1";
///
/// The default port used by the client.
///
public const int DefaultPort = 7350;
///
/// The default server key used to authenticate with the server.
///
public const string DefaultServerKey = "defaultkey";
///
/// Enable automatic compression with requests in the client.
///
public bool AutomaticCompression { get; set; }
///
/// Enable automatic decompression with responses in the client.
///
public bool AutomaticDecompression { get; set; }
///
/// Enable SSL scheme with the client.
///
public bool EnableSsl { get; set; }
///
/// The host address of the server the client will connect.
///
public string Host { get; set; }
///
/// The port number of the server the client will connect.
///
public int Port { get; set; }
///
/// Verifies the remote Secure Sockets Layer (SSL) certificate used for authentication.
///
public RemoteCertificateValidationCallback ServerCertificateValidationCallback { get; set; }
///
/// The number of retries the client will use with each request.
///
public int Retries { get; set; }
///
/// The default timeout for each request attempt to the server.
///
public TimeSpan Timeout { get; set; }
///
/// The server key which should be used to authenticate with the server.
///
public string ServerKey { get; set; }
public ClientOptions()
{
AutomaticCompression = false;
AutomaticDecompression = false; // Does not work with Mono AOT on Android.
EnableSsl = false;
Host = DefaultHost;
Port = DefaultPort;
Retries = 3;
Timeout = TimeSpan.FromSeconds(5);
ServerCertificateValidationCallback = delegate { return true; };
ServerKey = DefaultServerKey;
}
internal void ValidateOptions()
{
if (Retries < 0)
{
throw new ArgumentException("Retries must be zero or greater.");
}
if (ServerCertificateValidationCallback == null)
{
throw new ArgumentException("ServerCertificateValidationCallback cannot be null.");
}
}
internal ClientOptions Clone()
{
return new ClientOptions
{
AutomaticCompression = AutomaticCompression,
AutomaticDecompression = AutomaticDecompression,
EnableSsl = EnableSsl,
Host = Host,
Port = Port,
Retries = Retries,
Timeout = Timeout,
ServerCertificateValidationCallback = ServerCertificateValidationCallback,
ServerKey = ServerKey
};
}
}
}