Esempio n. 1
0
        public IndividualChatDriver(string username, string receiver, FileManager fm, NetworkStream netstream, Messagehandler mh, string key, string status)
        {
            isP2P                = true;
            this.username        = username;
            this.receiver        = receiver;
            this.fm              = fm;
            window               = new IndividualChatWindow(receiver);
            window.WindowState   = FormWindowState.Minimized;
            window.ShowInTaskbar = false;
            window.getStatusTextLabel().Text = status;
            spam = new SpamProtector();
            SetupListners();

            int NumberChars = key.Length;

            byte[] personalKey = new byte[NumberChars / 2];
            for (int i = 0; i < NumberChars; i += 2)
            {
                personalKey[i / 2] = System.Convert.ToByte(key.Substring(i, 2), 16);
            }

            writer      = new P2PWriter(netstream, personalKey);
            p2pListener = new P2PListener(netstream, receiver, personalKey);
            writer      = new P2PWriter(netstream, personalKey);

            mh.Subscribe(p2pListener);
            p2pListener.StartListen();

            new Thread(() => Application.Run(window)).Start();
            Thread.Sleep(10);
        }
Esempio n. 2
0
        public void SwitchToP2P(NetworkStream netStream, string key, Messagehandler mh)
        {
            if (window.InvokeRequired)
            {
                window.Invoke(new Action <NetworkStream, string, Messagehandler>(SwitchToP2P), new object[] { netStream, key, mh });
                return;
            }
            isP2P = true;
            int NumberChars = key.Length;

            byte[] personalKey = new byte[NumberChars / 2];
            for (int i = 0; i < NumberChars; i += 2)
            {
                personalKey[i / 2] = System.Convert.ToByte(key.Substring(i, 2), 16);
            }

            writer      = new P2PWriter(netStream, personalKey);
            p2pListener = new P2PListener(netStream, receiver, personalKey);
            writer      = new P2PWriter(netStream, personalKey);

            mh.Subscribe(p2pListener);
            p2pListener.StartListen();
            window.attachmentPanel.Visible = true;
            window.userStatusLabel.Text    = "Online";
        }
Esempio n. 3
0
        public void FileRequestRecieved(object sender, EventArgs e)
        {
            FileRequestArgs args   = (FileRequestArgs)e;
            bool            accept = true;

            //GUI STUFF HERE

            ((P2PWriter)writer).WriteFileResponse(MessageType.FileResponse, username, receiver, accept);
            if (accept)
            {
                p2pListener.StopListen();
                byte[] file = p2pListener.StartFileListener();
                p2pListener.StartListen();
                if (file != null)
                {
                    fm.SaveReceivedFile(file, args.filename, username);
                    //Fancy GUI stuff here, file received
                }
                else
                {
                    //Sad Gui stuff here, no file received
                }
            }
        }