private static void ListenForClients(int port) { if (_listenThread == null || !_listenThread.IsAlive) { return; } StartListenOnPort(port); while (_listenThread != null && _listenThread.IsAlive && _tcpListener != null && _tcpListener.Server != null) { if (_tcpListener.Pending()) { // Wait for a connection TcpClient client = _tcpListener.AcceptTcpClient(); // We got one, create a thread for it Socket s = client.Client; Logging.Write("Bot with address " + IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString()) + " has connected."); ClientThread cThread = new ClientThread(); Thread clientThread = new Thread(new ParameterizedThreadStart(cThread.HandleClientComm)); clientThread.Start(client); } else { Thread.Sleep(200); if (_cleanupTimer.IsReady) // Every 5 seconds, we drop the head event from the list { lock (_myLock) { if (_globalList.Count > 0) { MimesisHelpers.MimesisEvent evt = _globalList[0]; _globalList.Remove(evt); } } _cleanupTimer.Reset(); } // Now check if mount status changed bool update = false; if (MountTask.OnGroundMount()) { if (_myMountStatus != MountCapacity.Ground) { update = true; } _myMountStatus = MountCapacity.Ground; } else if (MountTask.OnFlyMount()) { if (_myMountStatus != MountCapacity.Fly) { update = true; } _myMountStatus = MountCapacity.Fly; } else if (MountTask.OnAquaticMount()) { if (_myMountStatus != MountCapacity.Swimm) { update = true; } _myMountStatus = MountCapacity.Swimm; } else if (_myMountStatus != MountCapacity.Feet) { update = true; _myMountStatus = MountCapacity.Feet; } if (update) { EventMount(); } } } }