コード例 #1
0
ファイル: ServerPageWidget.cs プロジェクト: Muny/ChatterBox
        public void UpdateLabels()
        {
            ChatWidget widg = GetSelectedChat();

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

            UpdatePageLabel();
        }
コード例 #2
0
ファイル: ServerPageWidget.cs プロジェクト: Muny/ChatterBox
        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;
                }
            });
        }
コード例 #3
0
ファイル: ServerPageWidget.cs プロジェクト: Muny/ChatterBox
 void RemoveChatWidget(ChatWidget widget)
 {
     ConnectedUsers.Remove(widget.TargetUser);
     ChatsNotebook.Remove(widget);
 }
コード例 #4
0
ファイル: ServerPageWidget.cs プロジェクト: Muny/ChatterBox
 void AddChatWidget(ChatWidget widget)
 {
     ConnectedUsers.Add(widget.TargetUser, widget);
     ChatsNotebook.AppendPage(widget, widget.PageLabel);
     ChatsNotebook.ShowAll();
 }