private void InitializeLatencyMonitor()
{
try
{
ServerUdpListener = SystemInfo.GetServerUdpListener(this);
}
catch (Exception)
{
WriteTimestampedLogEntry("LatencyMonitor.InitializeLatencyMonitor(): Failed to query server data port, retrying in 10 minutes.");
DelayCommand(600.0f, delegate() { InitializeLatencyMonitor(); });
return;
}
//
// Create a dummy object so that we may block on its SyncBlock.
// This object forms the lock for CurrentLatency, which we cannot
// directly use as boxing a new object would result in a new
// SyncBlock for every lock attempt.
//
CurrentLatencyLock = new int();
//
// Create the new UDP socket. This has to be done AFTER we get the
// UDP listener, for the get UDP listener code to work, as it finds
// the first UDP socket opened by nwn2server.
//
UdpSocket = new UdpClient(AddressFamily.InterNetwork);
//
// Set the default address to point to the server's local UDP
// listener.
//
UdpSocket.Connect(ServerUdpListener);
ALFA.Database Database = new ALFA.Database(this);
LocalServerId = Database.ACR_GetServerID();
//
// Start the latency measurement thread and the vault ping thread.
//
LatencyMeasurementThread = new Thread(LatencyMeasurementThreadRoutine);
LatencyMeasurementThread.Start();
VaultPingThread = new Thread(VaultPingThreadRoutine);
VaultPingThread.Start();
PollServerLatency();
WriteTimestampedLogEntry(String.Format("LatencyMonitor.InitializeLatencyMonitor(): Latency monitoring initialized on data port {0}.", ServerUdpListener));
}