private void MessagesTracer_OnMessageReceived(object sender, MessageReceivedEventArgs e) { OnEventHappened?.Invoke(null, new LogEventArgs() { message = e.normalizedMessage }); chatHistoryContainer.NewEntry(e.normalizedMessage); }
private void MessagesTracer_OnUserDisconnected(object sender, UserDisconnectedEventArgs e) { var message = $"User {e.username} disconnected."; OnEventHappened?.Invoke(this, new LogEventArgs() { message = message }); chatHistoryContainer.NewEntry(message); connectedUserEntries.RemoveAll(x => x.ipAddress.ToString().Equals(e.address.ToString()) ); }
private async Task ListenUntilUsernameReceived(IPAddress address, TcpClient connection) { int tries = 0; string currentUsername = connectedUserEntries.Find( x => x.ipAddress.ToString() == address.ToString()) .username; while (currentUsername == "Unknown") { await Task.Delay(150); currentUsername = connectedUserEntries.Find( x => x.ipAddress.ToString() == address.ToString()) .username; ++tries; if (tries > MaxWaitTries) { break; } } //if user for some reason didn't send the packet to identify himself, //mark him as 'unknown' and still chat with him. var message = $"User {currentUsername} connected."; OnEventHappened?.Invoke(this, new LogEventArgs() { message = message }); chatHistoryContainer.NewEntry(message); _ = Task.Run(() => messagesTracer.TraceConnectionMessages(connection, currentUsername, false)); await TryUpdateChatHistory(); }
private void EventHappened() { OnEventHappened.Invoke(); }