public MORZECommand recvCmd()
        {
            MORZECommand cmd = null;

            byte[] data;
            if (recv(m_header) == true)
            {
                data = recvdata();
                if (data != null)
                {
                    switch (m_header[0])
                    {
                    case 0x81:
                        cmd = new SMSRecvHello(data);
                        break;

                    case 0x82:    //message was recived
                        cmd = new MORZERecvMessages(m_account, data);
                        break;

                    case 0x85:
                        cmd = new MORZERecvSynKey(data);
                        break;
                    }
                }
            }
            return(cmd);
        }
示例#2
0
        private void thRecvCommand()
        {
            MORZERecvCommand rcmd;
            MORZECommand     cmd;

            try
            {
                do
                {
                    rcmd = new MORZERecvCommand(m_account, m_netStream);
                    cmd  = rcmd.recvCmd();
                    if (cmd != null)
                    {
                        SMSRecvHello rcvhl = null;
                        if (rcvhl == null && cmd is SMSRecvHello == true)
                        {
                            rcvhl = cmd as SMSRecvHello;
                            if (rcvhl.isValid(m_helloSign) == true)
                            {
                                OnConnectChange(true, string.Empty);
                            }
                            else
                            {
                                OnConnectChange(false, string.Empty);
                            }
                        }
                        //else if (rcvhl == null && cmd is SMSRecvHello == false)
                        //    OnConnectChange(false , "Неверный ответ сервера");
                    }
                    if (cmd != null && cmd is MORZERecvSynKey == true)
                    {
                        MORZERecvSynKey srvSync = cmd as MORZERecvSynKey;
                        srvSync.SetAsync(m_sendAsyngCmd, m_helloSign);
                        m_sendAsyngCmd.Dispose();
                        m_sendAsyngCmd = null;
                        m_sync         = srvSync.SyncCryptor;

                        if (OnConnected != null)
                        {
                            OnConnected();
                        }
                    }
                    if (cmd != null && cmd is MORZERecvMessages == true)
                    {//принято сообщение
                        MORZERecvMessages rm = cmd as MORZERecvMessages;
                        if (rm.isResponses == true)
                        {//есть ответные сообщения
                            List <SMSSendCommand> res = rm.Responses;
                            foreach (SMSSendCommand cm in res)
                            {
                                SMSSendExt setext = cm as SMSSendExt;
                                if (setext != null)
                                {
                                    setext.SMSNet = this;
                                }
                                cm.Send(m_netStream);
                            }
                        }
                    }
                } while (m_stop == false);
            }
            catch (Exception exp)
            {
                if (m_stop == false)
                {
                    OnConnectChange(false, exp.Message);
                }
            }
        }