Example #1
0
        public static void Run(Life life)
        {
            Hashtable chats = new Hashtable();

            if (life.Name == null)
                life.Name = "SEM_NOME";

            PeerNetwork com = new PeerNetwork(life);

            //cria Thread que fica verificando se os contatos estão online ou offline.
            com.VerifyContacts();

            thrServidor = new Thread(new ThreadStart(com.MakeAvailable));
            System.Console.WriteLine("You are now onLine: " +life.Name);
            thrServidor.IsBackground = true;
            thrServidor.Start();

            LifeLets.GUI.SovereChat chat = new LifeLets.GUI.SovereChat(life, chats);

            Thread thrServidor2 = new Thread(new ThreadStart(chat.Listen));
            thrServidor2.IsBackground = true;
            thrServidor2.Start();

            Thread thrServidor4 = new Thread(new ThreadStart(com.ContactListener));
            thrServidor4.IsBackground = true;
            thrServidor4.Start();

            new LLMainWindow(life, chats);
        }
        public LLViewPictureWindow(Life myLife)
        {
            this.myLife = myLife;

            Glade.XML gxml = new Glade.XML (null, "llviewpicturewindow.glade", "ViewPictureWindow", null);
            gxml.Autoconnect(this);
        }
        public LLAddContactWindow(Life myLife)
        {
            this.myLife = myLife;

            Glade.XML gxml = new Glade.XML (null, "llwindowaddcontact.glade", "LLWindowContact", null);
            gxml.Autoconnect(this);
            LLWindowContact.WindowPosition = WindowPosition.Center;
        }
Example #4
0
        public ChatWindow(Life life)
        {
            this.life = life;

               Application.Init();
               Glade.XML gxml = new Glade.XML (null, "soverechatwindow.glade", "windowSovereChat", null);
               gxml.Autoconnect (this);
               button5.Clicked +=  new EventHandler (quit);
               Application.Run();
        }
Example #5
0
        public LLCreditsWindow(Life life)
        {
            this.myLife = life;
            Glade.XML gxml = new Glade.XML (null, "LLCreditsWindow.glade", "windowCredits", null);

            gxml.Autoconnect(this);
            this.windowCredits.WindowPosition = WindowPosition.Center;

             System.Threading.Thread thrCredits = new System.Threading.Thread(new ThreadStart(this.moveText));
            thrCredits.IsBackground = true;
            thrCredits.Start();
        }
Example #6
0
        public Console2(Life life)
        {
            this.life = life;
            showPicture();

            while(true)
            {
                showHeader();

                if(!runOptions(life))
                        break;
            }
        }
Example #7
0
 public static string ConvertPicture(Life life)
 {
     //			if(life.Photo != null)
     //			{
     //				MemoryStream photoStream = new MemoryStream();
     //				life.Photo.Save(photoStream, life.Photo.RawFormat);
     //				return Convert.ToBase64String ( photoStream.GetBuffer() , 0 , (int) photoStream.Length);
     //			}
     //			else
     //			{
     //				throw (new Exception("Image error!"));
     //			}
     return null;
 }
Example #8
0
        public ContactsConsole(Life life)
        {
            this.life = life;

            listNicks();

             			if (!NickManage())
             				return;

            while(true)
            {
                showHeader();

                if(!runOptions(contact))
                        break;
            }
        }
Example #9
0
        public static void MainListener(Life life, int port)
        {
            TcpListener listener;

            listener = new TcpListener(port);
            listener.Start();

            while(true)
            {
                Socket connection = listener.AcceptSocket();

                NetworkStream socketstream = new NetworkStream( connection );

                BinaryReader reader = new BinaryReader(socketstream);

                string serviceName = reader.ReadString();

            /*
                TODO: Pesquisar como instanciar um objeto a partir de objeto Type;
                        Isso eliminará os "cases";

                NetworkBridge servico = new System.Type.GetType(serviceName))();

                servico.respondTo("");

            */				string response = "";
                string serviceData = reader.ReadString();

                switch (serviceName)
                {
                    case "NameService":
                        {
                            NameService service = new NameService(life);
                            response = service.respondTo(serviceData);
                            break;
                        }

                    default:{break;}
                }

                new BinaryWriter(socketstream).Write(response);

            }
        }
Example #10
0
 public void Init()
 {
     this.life = new Life();
 }
Example #11
0
        public static void GetPicture(string photoBase64, Life life)
        {
            //			if(photoBase64 != "")
            //			{
                /*MemoryStream str = new MemoryStream();

                str.Read(Convert.FromBase64String(photoBase64),0, (int) str.Length);
                */
            //				FileStream str = new FileStream("image.tmp", FileMode.Create);
            //				str.Write(Convert.FromBase64String(photoBase64),0, Convert.FromBase64String(photoBase64).GetLength(0));
            //				Image img = Image.FromFile("image.tmp");
            //
            //				img.Save("teste.bmp");
            //				System.Diagnostics.Process.Start(life.BrowserPath, "teste.bmp");
            //			}
            //			else
            //			{
            //				throw (new Exception("Image error!"));
            //			}
        }
Example #12
0
 public static void ShowPicture(Life life)
 {
     if (life.PathToPhoto != null)
     {
         System.Diagnostics.Process.Start(life.BrowserPath, life.PathToPhoto);
     }
 }
Example #13
0
        public static void rodar(Life life)
        {
            System.Console.WriteLine("\nMeu nome é: " + life.Name);

            string opcao = "";

            if (life.Name == null)
                life.Name = "SEM_NOME";

            PeerNetwork com = new PeerNetwork(life);

            //cria Thread que fica verificando se os contatos estão online ou offline.
            com.VerifyContacts();

            thrServidor = new Thread(new ThreadStart(com.MakeAvailable));
            System.Console.WriteLine("Voce esta OnLine: " +life.Name);
            thrServidor.IsBackground = true;
            thrServidor.Start();

            SovereChat chat = new SovereChat(life);

            Thread thrServidor2 = new Thread(new ThreadStart(chat.Listen));
            thrServidor2.IsBackground = true;
            thrServidor2.Start();

            Thread thrServidor4 = new Thread(new ThreadStart(com.ContactListener));
            thrServidor4.IsBackground = true;
            thrServidor4.Start();

            //return share files list.
            Thread thrServidor5 = new Thread(new ThreadStart(com.FilesNameListener));
            thrServidor5.IsBackground = true;
            thrServidor5.Start();

            //return file.
            Thread thrServidor6 = new Thread(new ThreadStart(com.FileListener));
            thrServidor6.IsBackground = true;
            thrServidor6.Start();

            while(opcao.ToUpper() != "S")
            {
                // My Funcitions
             	System.Console.WriteLine("\n\n " + life.Name + " What do you do ?");
                System.Console.WriteLine("N. Change Name");
                System.Console.WriteLine("L. Nickname List");
                System.Console.WriteLine("T. See  Photo");
                System.Console.WriteLine("F. Change Photo");
                System.Console.WriteLine("B. Change Default Browser's Path");
                System.Console.WriteLine("E. Sharing File List");
                System.Console.WriteLine("C. Connect");
                // On my contacts
                System.Console.WriteLine("A. Add contact/change nickname");
                System.Console.WriteLine("R. Remove Nickname");
                System.Console.WriteLine("D. Change trust degree");
                System.Console.WriteLine("J. Get Picture");
                System.Console.WriteLine("K. Get File");
                System.Console.WriteLine("P. FindIpAddress Contact");
                System.Console.WriteLine("Z . Navegation on Contacts");
                // System.Console.WriteLine("M. Start Chat"); only for GUI

                System.Console.WriteLine("S. Sair");

                opcao = System.Console.ReadLine();

                switch (opcao.ToUpper())
                {
                    case "A":
                    {
                        System.Console.Write("Digite o Apelido do seu novo Contato: ");
                        string nickname = System.Console.ReadLine();

                        System.Console.Write("Digite o IP de " + nickname + ": ");
                        string ip = System.Console.ReadLine();

                        life.AddContact(nickname,ip);
                        break;
                    }

                    case "D":
                    {
                        System.Console.Write("Type the NickName of your contact: ");
                        string nick = System.Console.ReadLine();

                        Contact contact = life.SearchContact(nick);

                        if(contact != null)
                        {
                            while(true)
                            {
                                try
                                {
                                    System.Console.Write("\nType the new trust degree ( 0 to 100 ): ");
                                    int trust = int.Parse(System.Console.ReadLine());

                                    if (trust >= 0 && trust <= 100)
                                        contact.Trust = trust;
                                    else
                                        throw(new System.Exception(""));
                                    break;
                                }
                                catch
                                {
                                    System.Console.WriteLine("Invalid option, try again!");
                                }
                            }
                        }
                        else
                        {
                                System.Console.WriteLine("Invalid NickName!");
                        }
                        break;
                    }

                    case "F":
                    {
                        System.Console.WriteLine("Enter path of pícture: ");
                        life.PathToPhoto = System.Console.ReadLine();
                        break;
                    }

                    case "T":
                    {
                        Photo.ShowPicture(life);
                        break;
                    }

                    case "J":
                    {
                     	System.Console.WriteLine("View Picture From: ");
                        string nickname = System.Console.ReadLine();

                        com.PictureRequest(nickname, life);

                        break;
                    }
                    case "C":
                    {
                        System.Console.WriteLine("Enter the nickname: ");
                        string nick = System.Console.ReadLine();
                        Contact contact = life.SearchContact(nick);
                        System.Console.WriteLine("Your buddy at [" + contact.IP + "] is " + PeerNetwork.RetrieveStatus(contact));

                    break;
                    }

                    case "N":
                    {
                        System.Console.WriteLine("Enter your real name: ");
                        life.Name = System.Console.ReadLine();
                        System.Console.Write("Your name is now : : ");
                        System.Console.WriteLine(life.Name);
                        break;
                    }
                    case "L":
                    {
                        System.Console.WriteLine("Yuors  Contacts so:");

                        IDictionaryEnumerator enumerator = life.Contacts.GetEnumerator();

                        while (enumerator.MoveNext())
                        {
                            System.Console.Write("    Apelido: ");
                            System.Console.Write(enumerator.Key);
                            System.Console.Write("    IP: ");
                            System.Console.Write(((Contact)enumerator.Value).IP);
                            System.Console.Write("	Trust degree:");
                            System.Console.Write(((Contact)enumerator.Value).Trust.ToString() + "%");
                            System.Console.Write("    Status: ");
                            System.Console.WriteLine(PeerNetwork.RetrieveStatus((Contact)enumerator.Value));
                        }

                        System.Console.WriteLine("--- FIM DA LISTA ---\n\n");
                        break;
                    }
            // This is only available on GUI
                    case "M":
                    {
                        //ChatWindow.Factory(life);

                        System.Console.WriteLine("Enter the Nickname of your contact:");
                        string nome = System.Console.ReadLine();
                        string ip = life.FindIpAddress(nome);
                        if (ip == null )
                        {
                            System.Console.WriteLine("Apelido não existe!!!");
                        }
                        else
                        {

                            SovereChat message = new SovereChat(ip,life.Name);

                        }
                        break;
                    }

                    case "P":
                    {
                        System.Console.WriteLine("Digite o Apelido:");
                        string nome = System.Console.ReadLine();
                        string ip = life.FindIpAddress(nome);
                        System.Console.WriteLine("-------->>Apelido : {0}  IP: {1} ", nome,ip);
                        break;
                    }
                    case "R":
                    {
                        System.Console.Write("Digite o Apelido que deseja remover: ");
                        string nickname = System.Console.ReadLine();

                        life.RemoveContact(nickname);
                        System.Console.Write(nickname + " foi removido da sua lista.");
                        break;
                    }

                    case "B":
                    {
                        System.Console.Write("Enter the new default browser's path: ");
                        string browserPath = System.Console.ReadLine();

                        life.BrowserPath = browserPath;
                        System.Console.Write(browserPath + " is your new browser's path.");
                        break;
                    }
                    case "Z":
                    {

                        // Passagem de 1 para o primeiro nível de trusting por ele ser vc mesmo o nível de confiança é total
                        Navigator.ConsoleNavigator(">",life.Contacts,100);

                        break;
                    }

                    case "E":
                    {
                        life.RetrieveFiles();

                        System.Console.WriteLine("Your sharing files are:");

                        IDictionaryEnumerator enumerator = life.Files.GetEnumerator();

                        while (enumerator.MoveNext())
                        {
                            System.Console.Write("    Name: ");
                            System.Console.WriteLine(enumerator.Key);
                        }

                        System.Console.WriteLine("--- END OF FILES LIST ---\n\n");

                        break;
                    }

                    case "K":
                    {

                        System.Console.WriteLine("Enter contact's nickname to get files:");
                        string nickname = System.Console.ReadLine();
                        Hashtable contactFiles = PeerNetwork.GetRemoteFilesNames(life.FindIpAddress(nickname));

                        System.Console.WriteLine("{0}'s sharing files are:",nickname);

                        IDictionaryEnumerator enumerator = contactFiles.GetEnumerator();

                        while (enumerator.MoveNext())
                            System.Console.WriteLine("    Name: " + enumerator.Key);

                        System.Console.WriteLine("--- END OF FILES LIST ---\n\n");

                        System.Console.WriteLine("Which file would you like to get?	");
                        string fileName = System.Console.ReadLine();

                        System.Console.WriteLine("Which name would you like to save it?");
                        string nameToSave = System.Console.ReadLine();

                        PeerNetwork.GetRemoteFiles(life.FindIpAddress(nickname),fileName, nameToSave, life.FilesPath);

                        System.Console.WriteLine("Sucessfull download of {0} executed!", fileName);

                        break;
                    }

                    default:
                    {
                        if (thrServidor != null)
                        {
                     		if (thrServidor.IsAlive)
                     			{
                     			//thrServidor.Interrupt();
                     			thrServidor.Abort();
                     			}
                     	}
                     	break;
                    }
                }
            }
        }
Example #14
0
        /*	public static void Send43Picture(NetworkStream output, string pic)
        {
            try
            {
                BinaryWriter writer = new BinaryWriter( output );

                writer.Write(pic);
            }
            catch(Exception ex)
            {
                throw(ex);
            }
        }

        */
        public void PictureRequest(string nickname, Life life)
        {
            string pictureString = network.CallService("picture", "", life.FindIpAddress(nickname));
                LifeLets.Lib.Photo.GetPicture(pictureString,life);
        }
Example #15
0
 //        public send()
 //        {
 //            SovereChat message = new SovereChat(ip,life.Nome);
 //            
 //        }
 public static void Factory(Life life)
 {
     new ChatWindow(life);
 }
Example #16
0
 public PeerNetwork(Life life)
 {
     this.life = life;
     network = new Network(2004);
 }
Example #17
0
 public SovereChat(Life vidaPar)
 {
     this.life = vidaPar;
 }
Example #18
0
        public LLChatWindow(Life myLife, string remoteIP)
        {
            this.myLife = myLife;
            this.remoteIP = remoteIP;
            this.chat = new LifeLets.GUI.SovereChat(remoteIP);

            Glade.XML gxml = new Glade.XML (null, "LLChatWindow.glade", "ChatWindow", null);
            //this.ChatWindow.DefaultWidth = 500;
            gxml.Autoconnect(this);
            btnExit.Clicked += new EventHandler (on_btnExit_clicked);
            btnOk.Clicked += new EventHandler (on_btnOk_clicked);
        }
Example #19
0
 public SovereChat(Life myLife, Hashtable chats)
 {
     this.chats = chats;
        this.myLife = myLife;
 }
Example #20
0
 public LLTrustWindow(Life life)
 {
     this.myLife = life;
     Glade.XML gxml = new Glade.XML (null, "llTrustWindow.glade", "WindowTrust", null);
     gxml.Autoconnect(this);
 }
Example #21
0
        public LLMainWindow(Life myLife, Hashtable chats)
        {
            this.myLife = myLife;
            this.chats = chats;
            this.contactTree = new Hashtable();

            Application.Init();

            Glade.XML gxml = new Glade.XML ("gui.glade", "MainWindow");
            gxml.Autoconnect (this);

            TreeViewMount();

            this.scrolledMainWindow.Show();
            this.MainWindow.ShowAll();
            this.MainWindow.DeleteEvent += new DeleteEventHandler(delete);

            // thread para ficar fazendo atualização da lista de contatos
            System.Threading.Thread thrServidor4 = new System.Threading.Thread(new ThreadStart(this.refreshContactList));
            thrServidor4.IsBackground = true;
            thrServidor4.Start();

              		this.RefreshFromLife();
            Application.Run();
        }
Example #22
0
 public LLChangeName(Life life, LLMainWindow mw)
 {
     this.myLife = life;
     this.mainWindow = mw;
     Glade.XML gxml = new Glade.XML (null, "LLChangeName.glade", "ChangeName", null);
     gxml.Autoconnect(this);
     ChangeName.WindowPosition = WindowPosition.Center;
 }
Example #23
0
 public MyNickname(Life life)
 {
 }