Ejemplo n.º 1
0
        //This method Accepts new connection and
        //First it receives the welcome massage from the client,
        //Then it sends the Current date time to the Client.
        public void StartListen()
        {
            while (Running && numErr < 5)
            {
                //Accept a new connection
                try
                {
                    Socket mySocket = myListener.AcceptSocket();
                    if (MySockets.Count() < _socketindex + 1)
                    {
                        MySockets.Add(mySocket);
                    }
                    else
                    {
                        MySockets[_socketindex] = mySocket;
                    }

                    if (mySocket.Connected)
                    {
                        mySocket.NoDelay           = true;
                        mySocket.ReceiveBufferSize = 8192;
                        mySocket.ReceiveTimeout    = iSpyServer.Default.ServerReceiveTimeout;

                        try
                        {
                            //make a byte array and receive data from the client
                            string sBuffer;
                            string sHttpVersion;

                            Byte[] bReceive = new Byte[1024];
                            mySocket.Receive(bReceive);
                            sBuffer = Encoding.ASCII.GetString(bReceive);

                            if (sBuffer.Substring(0, 4) == "TALK")
                            {
                                var socket = mySocket;
                                var feed   = new Thread(p => AudioIn(socket));
                                _socketindex++;
                                feed.Start();
                                continue;
                            }

                            if (sBuffer.Substring(0, 3) != "GET")
                            {
                                continue;
                            }

                            int iStartPos = sBuffer.IndexOf("HTTP", 1);

                            sHttpVersion = sBuffer.Substring(iStartPos, 8);


                            int cid = -1, vid = -1, camid = -1;
                            int w = -1, h = -1;

                            string qs = sBuffer.Substring(4);
                            qs = qs.Substring(0, qs.IndexOf(" ")).Trim('/').Trim('?');
                            string[] nvs = qs.Split('&');

                            foreach (string s in nvs)
                            {
                                string[] nv = s.Split('=');
                                switch (nv[0].ToLower())
                                {
                                case "c":
                                    cid = Convert.ToInt32(nv[1]);
                                    break;

                                case "w":
                                    w = Convert.ToInt32(nv[1]);
                                    break;

                                case "h":
                                    h = Convert.ToInt32(nv[1]);
                                    break;

                                case "camid":
                                    camid = Convert.ToInt32(nv[1]);     //mjpeg
                                    break;

                                case "micid":
                                    vid = Convert.ToInt32(nv[1]);
                                    break;
                                }
                            }
                            if (cid != -1)
                            {
                                SendLiveFeed(cid, w, h, sHttpVersion, ref mySocket);
                            }
                            else
                            {
                                if (camid != -1)
                                {
                                    CameraWindow cw = Parent.GetCameraWindow(Convert.ToInt32(camid));
                                    if (cw.Camobject.settings.active)
                                    {
                                        String sResponse = "";

                                        sResponse += "HTTP/1.1 200 OK\r\n";
                                        sResponse += "Server: iSpy\r\n";
                                        sResponse += "Expires: 0\r\n";
                                        sResponse += "Pragma: no-cache\r\n";
                                        sResponse += "Content-Type: multipart/x-mixed-replace;boundary=--myboundary";


                                        Byte[] bSendData = Encoding.ASCII.GetBytes(sResponse);
                                        SendToBrowser(bSendData, mySocket);
                                        cw.OutSockets.Add(mySocket);
                                        _socketindex++;
                                        continue;
                                    }
                                }
                                else
                                {
                                    if (vid != -1)
                                    {
                                        VolumeLevel vl = Parent.GetMicrophone(Convert.ToInt32(vid));
                                        if (vl != null)
                                        {
                                            String sResponse = "";

                                            sResponse += "HTTP/1.1 200 OK\r\n";
                                            sResponse += "Server: iSpy\r\n";
                                            sResponse += "Expires: 0\r\n";
                                            sResponse += "Pragma: no-cache\r\n";
                                            sResponse += "Content-Type: multipart/x-mixed-replace;boundary=--myboundary";
                                            sResponse += "\r\n\r\n";
                                            Byte[] bSendData = Encoding.ASCII.GetBytes(sResponse);
                                            SendToBrowser(bSendData, mySocket);
                                            vl.OutSockets.Add(mySocket);

                                            _socketindex++;
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        string _resp = "iSpy server is running";
                                        SendHeader(sHttpVersion, "", _resp.Length, " 200 OK", 0, ref mySocket);
                                        SendToBrowser(_resp, ref mySocket);
                                    }
                                }
                            }
                            numErr = 0;
                        }
                        catch (SocketException ex)
                        {
                            System.Diagnostics.Debug.WriteLine("Server Error (socket): " + ex.Message);
                            MainForm.LogExceptionToFile(ex);
                            numErr++;
                        }
                        mySocket.Close();
                        mySocket = null;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Server Error (generic): " + ex.Message);
                    MainForm.LogExceptionToFile(ex);
                    numErr++;
                }
            }
        }
Ejemplo n.º 2
0
 internal void DisplayMicrophone(objectsMicrophone mic)
 {
     var micControl = new VolumeLevel(mic);
     SetMicrophoneEvents(micControl);
     micControl.BackColor = iSpyServer.Default.BackColor;
     _pnlCameras.Controls.Add(micControl);
     micControl.Location = new Point(mic.x, mic.y);
     micControl.Size = new Size(mic.width, mic.height);
     micControl.BringToFront();
     if (mic.settings.active)
         micControl.Enable();
 }
Ejemplo n.º 3
0
        private void RemoveMicrophone(VolumeLevel volumeControl)
        {
            volumeControl.Disable();
            _pnlCameras.Controls.Remove(volumeControl);

            if (!_closing)
            {
                VolumeLevel control = volumeControl;
                objectsMicrophone om = Microphones.SingleOrDefault(p => p.id == control.Micobject.id);
                foreach (objectsCamera oc in Cameras.Where(p => p.settings.micpair == om.id).ToList())
                {
                    oc.settings.micpair = -1;
                }
                if (om != null)
                    Microphones.Remove(om);
                SetNewStartPosition();
                NeedsSync = true;
            }
            Application.DoEvents();
            volumeControl.Dispose();
        }
Ejemplo n.º 4
0
 private void SetMicrophoneEvents(VolumeLevel vw)
 {
     vw.DoubleClick += VolumeControlDoubleClick;
     vw.KeyDown += VolumeControl_KeyDown;
     vw.MouseEnter += VolumeControl_MouseEnter;
     vw.MouseDown += VolumeControlMouseDown;
     vw.MouseUp += VolumeControl_MouseUp;
     vw.MouseLeave += VolumeControl_MouseLeave;
     vw.MouseMove += VolumeControlMouseMove;
 }
Ejemplo n.º 5
0
        private void AddMicrophone(int audioSourceIndex)
        {
            var om = new objectsMicrophone
                         {
                             alerts = new objectsMicrophoneAlerts(),
                             detector = new objectsMicrophoneDetector(),
                             notifications = new objectsMicrophoneNotifications(),
                             recorder = new objectsMicrophoneRecorder(),
                             schedule = new objectsMicrophoneSchedule
                                            {
                                                entries
                                                    =
                                                    new objectsMicrophoneScheduleEntry
                                                    [
                                                    0
                                                    ]
                                            }
                         };
            om.settings = new objectsMicrophoneSettings();

            om.id = -1;
            om.directory = RandomString(5);
            om.x = 0;
            om.y = 0;
            om.width = 160;
            om.height = 40;
            om.name = "";
            om.description = "";
            om.newrecordingcount = 0;

            int port = 257;
            foreach (objectsMicrophone om2 in Microphones)
            {
                if (om2.port > port)
                    port = om2.port + 1;
            }
            om.port = port;

            om.settings.typeindex = 0;
            if (audioSourceIndex == 2)
                om.settings.typeindex = 1;
            om.settings.deletewav = true;
            om.settings.ffmpeg = iSpyServer.Default.FFMPEG_Microphone;
            om.settings.buffer = 4;
            om.settings.samples = 22050;
            om.settings.bits = 16;
            om.settings.channels = 1;
            om.settings.decompress = true;
            om.settings.smsnumber = MobileNumber;
            om.settings.emailaddress = EmailAddress;
            om.settings.active = false;
            om.settings.notifyondisconnect = false;

            om.detector.sensitivity = 60;
            om.detector.nosoundinterval = 30;
            om.detector.soundinterval = 0;
            om.detector.recordondetect = true;

            om.alerts.mode = "sound";
            om.alerts.minimuminterval = 60;
            om.alerts.executefile = "";
            om.alerts.active = false;
            om.alerts.alertoptions = "false,false";

            om.recorder.inactiverecord = 5;
            om.recorder.maxrecordtime = 900;

            om.notifications.sendemail = false;
            om.notifications.sendsms = false;

            om.schedule.active = false;

            var volumeControl = new VolumeLevel(om) {BackColor = iSpyServer.Default.BackColor};
            _pnlCameras.Controls.Add(volumeControl);

            volumeControl.Location = new Point(om.x, om.y);
            volumeControl.Size = new Size(160, 40);
            volumeControl.BringToFront();
            SetMicrophoneEvents(volumeControl);

            var am = new AddMicrophone {VolumeLevel = volumeControl};
            am.ShowDialog(this);

            if (am.DialogResult == DialogResult.OK)
            {
                am.VolumeLevel.Micobject.id = iSpyServer.Default.NextMicrophoneID;
                iSpyServer.Default.NextMicrophoneID++;
                Microphones.Add(om);
                SetNewStartPosition();
                NeedsSync = true;
            }
            else
            {
                volumeControl.Disable();
                _pnlCameras.Controls.Remove(volumeControl);
                volumeControl.Dispose();
            }
            am.Dispose();
        }