Example #1
0
        public void UpdateLabels()
        {
            ChatWidget widg = GetSelectedChat();

            if (widg != null)
            {
                widg.MarkRead();
            }

            UpdatePageLabel();
        }
Example #2
0
        void Client_DataReceived(object sender, DataReceivedEventArgs e)
        {
            Gtk.Application.Invoke(delegate
            {
                Console.WriteLine($"[<-] {e.Data}");

                Packets.IPacket packet;

                try
                {
                    packet = ParserPacket.ParsePacket(e.Data);
                }
                catch (ParsePacketException ex)
                {
                    Console.WriteLine(ex.ToString());
                    return;
                }

                switch (packet.Command)
                {
                case PacketType.Connected:
                    {
                        ChatWidget broadcastWidget = new ChatWidget(true, "Broadcast", client.SendPacket);
                        AddChatWidget(broadcastWidget);

                        // we want the list of users...

                        client.SendPacket(new PacketListUsers());
                    }
                    break;

                case PacketType.Disconnected:
                    {
                        // handle leaving server
                    }
                    break;

                case PacketType.ChatReceived:
                    {
                        PacketChatReceived chatPak = (PacketChatReceived)packet;

                        ShowBroadcastMessage(chatPak.FromUser, chatPak.Message);
                    }
                    break;

                case PacketType.WhisperReceived:
                    {
                        PacketWhisperReceived whispPak = (PacketWhisperReceived)packet;

                        if (!ConnectedUsers.ContainsKey(whispPak.FromUser))
                        {
                            AddChatWidget(new ChatWidget(false, whispPak.FromUser, client.SendPacket));
                        }

                        ConnectedUsers[whispPak.FromUser].NewMessage(whispPak.FromUser, whispPak.Message);
                        UpdatePageLabel();
                    }
                    break;

                case PacketType.WhisperSent:
                    {
                        PacketWhisperSent whispPak = (PacketWhisperSent)packet;

                        ConnectedUsers[whispPak.ToUser].NewMessage(Username, whispPak.Message);
                        UpdatePageLabel();
                    }
                    break;

                case PacketType.Users:
                    {
                        PacketUsers usersPak = (PacketUsers)packet;

                        foreach (string user in usersPak.Users)
                        {
                            ChatWidget widget = new ChatWidget(false, user, client.SendPacket);
                            AddChatWidget(widget);
                        }
                    }
                    break;

                case PacketType.UserJoined:
                    {
                        PacketUserJoined usrJnPak = (PacketUserJoined)packet;

                        if (!ConnectedUsers.ContainsKey(usrJnPak.Username))
                        {
                            AddChatWidget(new ChatWidget(false, usrJnPak.Username, client.SendPacket));

                            ShowBroadcastMessage("server", $"User '{usrJnPak.Username}' joined the server.");
                        }
                    }
                    break;

                case PacketType.UserLeft:
                    {
                        PacketUserLeft usrLfPak = (PacketUserLeft)packet;

                        if (ConnectedUsers.ContainsKey(usrLfPak.Username))
                        {
                            ShowBroadcastMessage("server", $"User '{usrLfPak.Username}' left the server.");

                            RemoveChatWidget(ConnectedUsers[usrLfPak.Username]);
                        }
                    }
                    break;

                case PacketType.Error:
                    {
                        PacketError errPak = (PacketError)packet;

                        ShowBroadcastMessage("ERROR", errPak.Message);
                    }
                    break;

                case PacketType.FatalError:
                    {
                        PacketFatalError errPak = (PacketFatalError)packet;

                        ShowBroadcastMessage("FATAL ERROR", errPak.Message);
                    }
                    break;
                }
            });
        }
Example #3
0
 void RemoveChatWidget(ChatWidget widget)
 {
     ConnectedUsers.Remove(widget.TargetUser);
     ChatsNotebook.Remove(widget);
 }
Example #4
0
 void AddChatWidget(ChatWidget widget)
 {
     ConnectedUsers.Add(widget.TargetUser, widget);
     ChatsNotebook.AppendPage(widget, widget.PageLabel);
     ChatsNotebook.ShowAll();
 }