Ejemplo n.º 1
0
        public List<Room> UserInsideRooms = new List<Room>(); //lista pokoi w których jest użytkownik (i mają dochodzić do niego wiadomości od innych)

        public MenuGlowne(User userfrommain, String serverAddrString, String serverPort)
        {
            InitializeComponent();
            this.thisWindow = this;
            this.user = userfrommain;
            this.serverAddrString = serverAddrString;
            this.serverPort = serverPort;
            serverAddr = IPAddress.Parse(serverAddrString);
                      
            Channels.Dispatcher.BeginInvoke(new Action(delegate()
            {
                Channels.ItemsSource = null;
                Channels.ItemsSource = Rooms;
            }));
            ActualRoom = Main;
            ActualRoom.IsInside = IRC.Room.inside.TAK;
            Rooms.Add(Main);
            setThreadedRoomName(Main.Name);
            UserInsideRooms.Add(Main);
            setThreadedChat(); //ustawiay chatbox na chat danego roomu

            //jeżeli klikniemy X (bez przycisku "wyjdź z serwera"
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);

            ConnectwithIP();
       }
Ejemplo n.º 2
0
        private void Channels_PreviewMouseDown(object sender, MouseButtonEventArgs e) //klikanie na listę kanałów zmienia chat
        {
            var item = ItemsControl.ContainerFromElement(Channels, e.OriginalSource as DependencyObject) as ListBoxItem;
            if (item != null)
            {

                ActualRoom = (Room)item.Content;
                UserInsideRooms.Add(ActualRoom);
                ActualRoom.IsInside = IRC.Room.inside.TAK;
                Channels.Dispatcher.BeginInvoke(new Action(delegate()
                {
                    Channels.ItemsSource = null;
                    Channels.ItemsSource = Rooms;
                }));
                setThreadedRoomName(ActualRoom.Name);
                setThreadedChat();
                Chat.ScrollToEnd();
                ActualRoom.NewMessages = IRC.Room.inside.NIE;
                
                
            }
        }
Ejemplo n.º 3
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            
            try
            {
                /* retrieve the SocketStateObject */
                state = (SocketStateObject)ar.AsyncState;
                Socket socketFd = state.m_SocketFd;
                
                /* read data */
                int size = socketFd.EndReceive(ar);
                //Console.Out.WriteLine("Read data");
                
                
                if (size > 0)
                {
                    state.m_StringBuilder.Append(Encoding.ASCII.GetString(state.m_DataBuf, 0, size));
                    //reszta danych
                    
                    if (!(state.m_StringBuilder.ToString().IndexOf("<end>") > 0))
                    {
                        socketFd.BeginReceive(state.m_DataBuf, 0, state.m_DataBuf.Length, 0,
                                                 new AsyncCallback(ReceiveCallback), state);
                    }    
              }
                                 
                if(state.m_StringBuilder.ToString().IndexOf("<end>") > 0)
                {  
                    if (state.m_StringBuilder.Length > 1)
                    {
                        Console.Out.WriteLine(state.m_StringBuilder.ToString());
                        /* all the data has arrived */
                        if (state.m_StringBuilder.ToString().IndexOf("<new_message>") == 0)//znalazł wzorzec
                        {
                            
                            String tochat = state.m_StringBuilder.ToString().Remove(0, 14);
                            tochat = tochat.Remove(tochat.Length - 5, 5);
                            String roomname = tochat.Substring(tochat.IndexOf("<")+1,tochat.Length-tochat.IndexOf("<")-2);
                            tochat=tochat.Substring(0,tochat.IndexOf("<")-1);
                            
                            Boolean insideRoom = false;

                            foreach (Room room in UserInsideRooms)
                            {
                                if(room.Name==roomname)
                                {
                                    insideRoom = true;
                                    break;
                                }
                            }

                            if (insideRoom == true)
                            {

                                dodajChat(tochat);
                                setThreadedChat();
                                //Console.Out.WriteLine(ActualRoom.ChatText);
                                if (roomname != ActualRoom.Name)
                                //dodajemy powiadomienie że coś nowego
                                {
                                    
                                    foreach (Room room in Rooms)
                                    {
                                        if (roomname == room.Name)
                                        {
                                            dodajChat(tochat);
                                            room.NewMessages = IRC.Room.inside.TAK;//nowe wiadomośći w tym pokoju 
                                            break;
                                        }
                                    }
                                }
                            }

                        }
                        else if (state.m_StringBuilder.ToString().IndexOf("<room_list>") == 0)
                        {
                            String roomlist = state.m_StringBuilder.ToString().Remove(0, 11);
                            int x = 0;
                            String roomname = String.Empty;
                            int roomOccupancy = 0;
                            bool koniec = false;
                            foreach (string s in roomlist.Split('>'))
                            {
                                //Console.Out.WriteLine(s);
                                if (s == "<end")
                                { koniec = true; }
                                if (koniec == false)
                                {
                                    String s1 = s.Remove(0, 1);

                                    if (x % 2 == 0)
                                    { roomname = s1; }
                                    else { roomOccupancy = Int32.Parse(s1); }

                                    if (x % 2 != 0)
                                    {
                                        Room NewRoom = new Room(roomname, roomOccupancy);
                                        Channels.Dispatcher.BeginInvoke(new Action(delegate()
                                        {
                                            Rooms.Add(NewRoom);
                                            Channels.ItemsSource = null;
                                            Channels.ItemsSource = Rooms;
                                        }));
                                    }
                                    x++;
                                }
                            }
                       }
                        else if (state.m_StringBuilder.ToString().IndexOf("<new_room>") == 0)
                        {
                            Console.Out.WriteLine(state.m_StringBuilder.ToString());
                            String roomlist = state.m_StringBuilder.ToString().Remove(0, 10);
                            int x = 0;
                            String roomname = String.Empty;
                            int roomOccupancy = 0;
                            bool koniec = false;
                            foreach (string s in roomlist.Split('>'))
                            {
                                Console.Out.WriteLine(s);
                                if (s == "<end")
                                { koniec = true; }
                                if (koniec == false)
                                {
                                    String s1 = s.Remove(0, 1);

                                    if (x % 2 == 0)
                                    { roomname = s1; }
                                    else { roomOccupancy = Int32.Parse(s1); }
                                }
                                x++;
                            }
                            bool juzistnieje=false;

                            foreach(Room room in Rooms)
                            {
                                if(room.Name==roomname)
                                { juzistnieje = true; }
                            }

                            if(juzistnieje==false)
                            {
                            Room NewRoom = new Room(roomname, roomOccupancy);
                            
                            Channels.Dispatcher.BeginInvoke(new Action(delegate ()
                            {
                                Rooms.Add(NewRoom);
                                Channels.ItemsSource = null;
                                Channels.ItemsSource = Rooms;
                            }));
                            
                            Console.Out.WriteLine(NewRoom.Name);
                            }
                        }
                    }

                    state.m_StringBuilder.Clear(); //po odczytaniu czyścimy
                    
                    Console.Out.WriteLine("Czytam kolejną wiadomość");
                 
                    ReadData();
                    
                }
          }
            catch (Exception exc)
            {
                MessageBox.Show("Exception Receive Callback  :\t\n" + exc.Message.ToString());
                setThreadedTextBox("Wyjdź z serwera i spróbuj ponownie!");
            }
          }
Ejemplo n.º 4
0
        private void ExitRoom_Click(object sender, RoutedEventArgs e)
        {
            UserInsideRooms.Remove(ActualRoom);
            ActualRoom.IsInside = IRC.Room.inside.NIE;
            ActualRoom.ChatText = "";

           
            Channels.ItemsSource = null;
            Channels.ItemsSource = Rooms;
            ActualRoom = Main;
            setThreadedRoomName(ActualRoom.Name);
            ActualRoom.NewMessages = IRC.Room.inside.NIE;//nie ma nowcyh wiadomości, bo je odczytaliśmy
            setThreadedChat();
            Chat.ScrollToEnd();

        }