/// <summary> /// Callback for when a connection had disconnected /// </summary> protected void MasterClient_OnDisconnect(MasterClient client) { // Remove client, and call OnUpdate Event try { // Release this stream's AsyncEventArgs to the object pool base.Release(client.Stream); // Remove client from online list if (Clients.TryRemove(client.ConnectionID, out client) && !client.Disposed) { client.Dispose(); } } catch (Exception e) { Program.ErrorLog.Write("An Error occured at [MasterServer.OnDisconnect] : Generating Exception Log"); ExceptionHandler.GenerateExceptionLog(e); } }
/// <summary> /// Accepts a TcpClient, and begin the serverlist fetching process for the client. /// This method is executed when the user updates his server browser ingame /// </summary> protected override void ProcessAccept(GamespyTcpStream Stream) { // Get our connection id long ConID = Interlocked.Increment(ref ConnectionCounter); MasterClient client; // End the operation and display the received data on // the console. try { // Convert the TcpClient to a MasterClient client = new MasterClient(Stream, ConID); Clients.TryAdd(client.ConnectionID, client); // Start receiving data Stream.BeginReceive(); } catch (ObjectDisposedException) // Ignore { // Remove client Clients.TryRemove(ConID, out client); } catch (IOException) // Connection closed before a TcpClientStream could be made { // Remove client Clients.TryRemove(ConID, out client); } catch (Exception e) { // Remove client Clients.TryRemove(ConID, out client); // Report error Program.ErrorLog.Write("NOTICE: An Error occured at [MstrServer.AcceptClient] : Generating Exception Log"); ExceptionHandler.GenerateExceptionLog(e); } }