Exemple #1
0
 private void MessagesTracer_OnMessageReceived(object sender, MessageReceivedEventArgs e)
 {
     OnEventHappened?.Invoke(null, new LogEventArgs()
     {
         message = e.normalizedMessage
     });
     chatHistoryContainer.NewEntry(e.normalizedMessage);
 }
Exemple #2
0
        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())
                                           );
        }
Exemple #3
0
        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();
        }
Exemple #4
0
 private void EventHappened()
 {
     OnEventHappened.Invoke();
 }