Exemple #1
0
        private void ReadMsg1(Flap _Flap)
        {
            _Flap._data.Read(8); //cookie
            int channel = _Flap._data.ReadUInt16();

            if (channel == 1)
            {
                //readuserinfo
                int    len = _Flap._data.ReadB();
                string uin = _Flap._data.Read(len).ToStr();
                _Flap._data.ReadUInt16(); //WarningLevel
                int tvlcount = _Flap._data.ReadUInt16();
                _Flap.ReadTvl(tvlcount);
                _Flap.ReadTvl(); //readTvltoend
                Tvl _Tvl = _Flap.GetTvl(0x0002);
                using (MemoryStream _MemoryStream = new MemoryStream(_Tvl.data))
                    while (_MemoryStream.Position != _MemoryStream.Length)
                    {
                        int id = _MemoryStream.ReadB();
                        _MemoryStream.ReadB(); //version
                        byte[] _bytes = _MemoryStream.Read(_MemoryStream.ReadUInt16());
                        if (id == 1)           //identifier
                        {
                            ReadMsg2(_bytes, uin, _Flap);
                        }
                    }
            }
        }
Exemple #2
0
        private void StartListen()
        {
            try
            {
                try
                {
                    Connect();
                }
                catch (IOException) { throw new ExceptionB("conn error2"); }
                catch (SocketException) { throw new ExceptionB("conn error2"); }
                Thread.Sleep(2000);
                _ConnectionStatus = ConnectionStatus.Connected;
                Trace2(Trace("Connected " + _uin));
                while (true)
                {
                    Flap _Flap = new Flap {
                        _ICQ = this
                    };
                    _Flap.Receive();
                    Trace("FlapReceived");
                    Trace(_Flap._data.ToArray().ToHex());
                    Trace("Snac Type Of" + _Flap.ch);
                    switch (_Flap.ch)
                    {
                    default:
                        break;

                    case 2:
                    {
                        _Flap.ReadSnac();
                        if (_Flap._Snac.ID1 == 4)
                        {
                            Im _Im = null;
                            if (_Dictionary.Keys.Contains(_Flap._Snac.req))
                            {
                                _Im = _Dictionary[_Flap._Snac.req];
                            }

                            if (_Flap._Snac.ID2 == 7)         //message
                            {
                                ReadMsg1(_Flap);
                            }
                            if (_Flap._Snac.ID2 == 12 && _Im != null)         //accepted
                            {
                                _Im.Status = MessageStatus.AcceptedForDelivery;
                                OnMessageStatusChanged(_Im);
                                _Dictionary.Remove(_Flap._Snac.req);
                            }
                            if (_Flap._Snac.ID2 == 1 && _Im != null)
                            {
                                _Im.Status = MessageStatus.UnknownError;
                                _Dictionary.Remove(_Flap._Snac.req);
                                int errorcode = _Flap._data.ReadUInt16();
                                _Flap.ReadTvl();
                                int subcode = 0;
                                Tvl _Tvl    = _Flap.GetTvl(0x0008);
                                if (_Tvl != null)
                                {
                                    subcode = BitConverter.ToUInt16(_Tvl.data.ReverseA(2), 0);
                                }
                                switch (errorcode)
                                {
                                case 0x0004:
                                    _Im.Status = MessageStatus.BuddyOffline;
                                    break;

                                case 0x0010:
                                    _Im.Status = MessageStatus.BuddyBlocked;
                                    break;
                                }
                                switch (subcode)
                                {
                                case 0x000E:
                                    _Im.Status = MessageStatus.OfflineMessagesNotSupported;
                                    break;

                                case 0x000F:
                                    _Im.Status = MessageStatus.OfflineStorageFull;
                                    break;
                                }
                                OnMessageStatusChanged(_Im);
                            }
                        }
                    }
                    break;
                    }
                }
            }
            catch (ExecutionEngineException) { }
            catch (IOException e)
            {
                Trace(e);
                Thread.Sleep(1000);
                _ConnectionStatus = ConnectionStatus.Kicked;
            }
            catch (SocketException e)
            {
                Trace(e);
                Thread.Sleep(1000);
                _ConnectionStatus = ConnectionStatus.Kicked;
            }
            catch (ExceptionB e)
            {
                Trace(e);
                Thread.Sleep(15000);
                if (ConnectionStatus.LoginError == _oldConnectionStatus)
                {
                    Thread.Sleep(16 * 1000 * 60);
                }
                _ConnectionStatus = ConnectionStatus.LoginError;
            }
            errors++;
        }