Esempio n. 1
0
        private void btnBoop_Click(object sender, EventArgs e)
        {
            //Try catch will go away in the future. Left in case somebody still has trouble with the server.

            try
            {
                //#endif

                //Fastest check first.
                if (lvFileList.Items.Count == 0)
                {
                    MessageBox.Show("Add some files first?", "No files to boop", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    lblFileMarker.Visible = true; //Added red boxes to point out the errors.
                    return;
                }


                string s3DSip = "";
                if (chkGuess.Checked)
                {
                    setStatusLabel("Guessing 3DS IP adress...");
                    s3DSip = NetUtil.IPv4.GetFirst3DS();
                    if (s3DSip == "")
                    {
                        MessageBox.Show("Cannot detect the 3DS in the network" + Environment.NewLine + "Try writing the IP adress manually", "Connection failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        lblIPMarker.Visible = true; //Added red boxes to point out the errors.
                        setStatusLabel("Ready");
                        return;
                    }
                }
                else
                {
                    if (NetUtil.IPv4.Validate(txt3DS.Text) == false)
                    {
                        MessageBox.Show("That doesn't look like an IP address." + Environment.NewLine + "An IP address looks something like this: 192.168.1.6" + Environment.NewLine + "(That is: Numbers DOT numbers DOT numbers DOT numbers)", "Error on the IP address", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        lblIPMarker.Visible = true; //Added red boxes to point out the errors.
                        setStatusLabel("Ready");
                        return;
                    }

                    s3DSip = txt3DS.Text;
                }

                // THE FIREWALL IS NO LONGER POKED!
                // THE SNEK IS FREE FROM THE HTTPLISTENER TIRANY!

                setStatusLabel("Opening the new and improved snek server...");
                enableControls(false);

                HTTPServer = new MyServer(8080, ActiveDir);
                HTTPServer.Start();


                System.Threading.Thread.Sleep(100);

                setStatusLabel("Opening socket to send the file list...");

                s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                IAsyncResult result = s.BeginConnect(s3DSip, 5000, null, null);
                result.AsyncWaitHandle.WaitOne(5000, true);

                if (!s.Connected)
                {
                    s.Close();
                    HTTPServer.Stop();
                    MessageBox.Show("Failed to connect to 3DS" + Environment.NewLine + "Please check:" + Environment.NewLine + "Did you write the right IP adress?" + Environment.NewLine + "Is FBI open and listening?", "Connection failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    lblIPMarker.Visible = true;
                    setStatusLabel("Ready");
                    enableControls(true);
                    return;
                }

                setStatusLabel("Sending the file list...");

                String message = "";
                foreach (var CIA in FilesToBoop)
                {
                    message += NetUtil.IPv4.Local + ":8080/" + Uri.EscapeUriString(Path.GetFileName(CIA)) + "\n";
                }

                //boop the info to the 3ds...
                byte[] Largo  = BitConverter.GetBytes((uint)Encoding.ASCII.GetBytes(message).Length);
                byte[] Adress = Encoding.ASCII.GetBytes(message);

                Array.Reverse(Largo); //Endian fix

                s.Send(AppendTwoByteArrays(Largo, Adress));

                setStatusLabel("Booping files... Please wait");
                s.BeginReceive(new byte[1], 0, 1, 0, new AsyncCallback(GotData), null); //Call me back when the 3ds says something.

//#if DEBUG
            }
            catch (Exception ex)
            {
                //Hopefully, some day we can have all the different exceptions handled... One can dream, right? *-*
                MessageBox.Show("Something went really wrong: " + Environment.NewLine + Environment.NewLine + "\"" + ex.Message + "\"" + Environment.NewLine + Environment.NewLine + "If this keeps happening, please take a screenshot of this message and post it on our github." + Environment.NewLine + Environment.NewLine + "The program will close now", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
//#endif
        }
Esempio n. 2
0
    protected void OnBoopBtnClicked(object sender, EventArgs e)
    {
        //TODO: Check network connection

        try
        {
            //Fastest check first.
            if (!FilesToBoop.Any())
            {
                //TODO: Throw error
                return;
            }

            if (NetUtils.Validate(targetIP.Text) == false)
            {
                //TODO: Throw error
                return;
            }

            string DSip       = targetIP.Text;
            int    ServerPort = Int32.Parse(Port.Text);

            // THE FIREWALL IS NO LONGER POKED!
            // THE SNEK IS FREE FROM THE HTTPLISTENER TIRANY!

            // setStatusLabel("Opening the new and improved snek server...");
            //   enableControls(false);
            Console.WriteLine("Active Dir");
            Console.WriteLine(ActiveDir);
            Console.WriteLine("Port");
            Console.WriteLine(ServerPort.ToString());
            string SafeDir = ActiveDir + "/";


            HTTPServer = new MyServer(ServerPort, ActiveDir);
            HTTPServer.Start();


            System.Threading.Thread.Sleep(100);

            //  setStatusLabel("Opening socket to send the file list...");

            s = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            IAsyncResult result = s.BeginConnect(DSip, 5000, null, null);
            result.AsyncWaitHandle.WaitOne(5000, true);

            if (!s.Connected)
            {
                s.Close();
                HTTPServer.Stop();
                //  MessageBox.Show("Failed to connect to 3DS" + Environment.NewLine + "Please check:" + Environment.NewLine + "Did you write the right IP adress?" + Environment.NewLine + "Is FBI open and listening?", "Connection failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //   lblIPMarker.Visible = true;
                //    setStatusLabel("Ready");
                //    enableControls(true);
                return;
            }

            //  setStatusLabel("Sending the file list...");

            String message       = "";
            String formattedPort = ":" + Port.Text + "/";

            foreach (var CIA in FilesToBoop)
            {
                message += NetUtils.GetLocalIPAddress() + formattedPort + System.Web.HttpUtility.UrlEncode(System.IO.Path.GetFileName(CIA)) + "\n";
            }

            //boop the info to the 3ds...
            byte[] Largo  = BitConverter.GetBytes((uint)Encoding.ASCII.GetBytes(message).Length);
            byte[] Adress = Encoding.ASCII.GetBytes(message);

            Array.Reverse(Largo);     //Endian fix

            s.Send(AppendTwoByteArrays(Largo, Adress));

            // setStatusLabel("Booping files... Please wait");
            s.BeginReceive(new byte[1], 0, 1, 0, new AsyncCallback(GotData), null);     //Call me back when the 3ds says something.

            //#if DEBUG
        }
        catch (Exception ex)
        {
            //Hopefully, some day we can have all the different exceptions handled... One can dream, right? *-*
            //   MessageBox.Show("Something went really wrong: " + Environment.NewLine + Environment.NewLine + "\"" + ex.Message + "\"" + Environment.NewLine + Environment.NewLine + "If this keeps happening, please take a screenshot of this message and post it on our github." + Environment.NewLine + Environment.NewLine + "The program will close now", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            Application.Quit();
        }
        //#endif
    }