コード例 #1
0
ファイル: Switchboard.cs プロジェクト: CylanceSPEAR/REcon2016
        public void Add(Modem modem, string phoneNumber)
        {
            if (modem == null || phoneNumber == null)
                throw new ArgumentNullException();
            else if (!IsDialable(phoneNumber))
                throw new ArgumentException();

            lock (this._DirectoryLock)
            {
                this._Directory.Add(phoneNumber, new Subscriber(modem));

                modem.Dial += OnDial;
                modem.Answer += OnAnswer;
                modem.Hangup += OnHangup;
            }
        }
コード例 #2
0
ファイル: Modem.cs プロジェクト: CylanceSPEAR/REcon2016
        private void DoHangup()
        {
            Modem peer;
            lock (this._StateLock)
            {
                peer = this._Peer;

                this._Peer = null;
                this._State = ModemState.Command;
            }

            if (peer != null)
            {
                peer.ChannelBreak();
                this.Hangup(this);
            }
        }
コード例 #3
0
ファイル: Modem.cs プロジェクト: CylanceSPEAR/REcon2016
        private void DoDial(string phoneNumber)
        {
            Modem peer = null;
            ConnectResult result = this.Dial(this, phoneNumber, ref peer);

            if (result == ConnectResult.Connect && peer != null)
            {
                peer.OnOOBReceived(OOBSignal.Ring);
            }

            Thread.Sleep(1000);

            switch (result)
            {
                case ConnectResult.Connect:
                    this.ChannelWrite(ConnectMessage);

                    lock (this._StateLock)
                    {
                        this._Peer = peer;
                        this._State = ModemState.Data;
                    }
                    break;

                case ConnectResult.NoDialtone:
                    this.ChannelWrite(NoDialtoneMessage);
                    break;

                case ConnectResult.NoAnswer:
                    this.ChannelWrite(NoAnswerMessage);
                    break;

                case ConnectResult.Busy:
                    this.ChannelWrite(BusyMessage);
                    break;
            }
        }
コード例 #4
0
ファイル: Modem.cs プロジェクト: CylanceSPEAR/REcon2016
        private void DoAnswer()
        {
            Modem peer = null;

            if (this.Answer(this, ref peer))
            {
                lock (this._StateLock)
                {
                    this._Peer = peer;

                    this._State = ModemState.Data;
                    this._Ringing = false;
                }
            }
        }
コード例 #5
0
ファイル: Switchboard.cs プロジェクト: CylanceSPEAR/REcon2016
        public ConnectResult Connect(string callerPhoneNumber, string dstPhoneNumber, out Modem modem)
        {
            lock (this._DirectoryLock)
            {
                Subscriber caller;
                Subscriber dst;

                if (!this._Directory.TryGetValue(callerPhoneNumber, out caller))
                    throw new ArgumentException();

                if (caller.OffHook)
                {
                    modem = null;
                    return ConnectResult.NoDialtone;  // "NO DIALTONE"
                }

                caller.OffHook = true;

                if (!this._Directory.TryGetValue(dstPhoneNumber, out dst))
                {
                    caller.OffHook = false;
                    modem = null;
                    return ConnectResult.NoAnswer;  // "NO ANSWER"
                }
                else if (dst.OffHook)
                {
                    caller.OffHook = false;
                    modem = null;
                    return ConnectResult.Busy;  // "BUSY"
                }

                dst.OffHook = true;

                caller.Peer = dst;
                dst.Peer = caller;

                modem = dst.Modem;
                return ConnectResult.Connect;  // "CONNECT"
            } //lock
        }
コード例 #6
0
ファイル: Switchboard.cs プロジェクト: CylanceSPEAR/REcon2016
 public Subscriber(Modem modem)
 {
     this.Modem = modem;
     this.Peer = null;
 }
コード例 #7
0
ファイル: Switchboard.cs プロジェクト: CylanceSPEAR/REcon2016
 private void OnHangup(Modem sender)
 {
     this.Disconnect(sender.PhoneNumber);
 }
コード例 #8
0
ファイル: Switchboard.cs プロジェクト: CylanceSPEAR/REcon2016
 private ConnectResult OnDial(Modem sender, string phoneNumber, ref Modem peer)
 {
     return this.Connect(sender.PhoneNumber, phoneNumber, out peer);
 }
コード例 #9
0
ファイル: Switchboard.cs プロジェクト: CylanceSPEAR/REcon2016
        private bool OnAnswer(Modem sender, ref Modem peer)
        {
            lock (this._DirectoryLock)
            {
                Subscriber receiver;

                if (!this._Directory.TryGetValue(sender.PhoneNumber, out receiver))
                    throw new ArgumentException();

                if (receiver == null || receiver.Peer == null)
                    return false;

                peer = receiver.Peer.Modem;
            }

            return (peer != null);
        }