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); } } } }
public object Add(string tag, string value) { var rval = new ComTagValue(tag, value); Tvl.Add(rval); return(rval); }
public object AddEmpty() { var rval = new ComTagValue(); Tvl.Add(rval); return(rval); }
public ITwsTagValue Add(string tag, string value) { var rval = new TagValue(tag, value); Tvl.Add(rval); return(rval); }
public ITwsTagValue AddEmpty() { var rval = new TagValue(); Tvl.Add(rval); return(rval); }
public static List <Tvl> ReadTvl(MemoryStream _data, int tvlscount) { if (tvlscount == 0) { throw new Exception("0 tvls"); } List <Tvl> _tvls = new List <Tvl>(); while ((_data.Length != _data.Position && tvlscount == -1) || tvlscount-- > 0) { Tvl _Tvl = new Tvl(); _Tvl.type = _data.ReadUInt16(); int length = _data.ReadUInt16(); if (length > 0) { _Tvl.data = _data.Read(length); } _tvls.Add(_Tvl); } return(_tvls); }
public void SendMessage(Im im) { try { if (_ConnectionStatus != ConnectionStatus.Connected) { throw new Exception("Not Connected"); } Flap _Flap = new Flap { _ICQ = this }; _Flap.ch = 2; _Flap._Snac.ID1 = 4; _Flap._Snac.ID2 = 6; _Flap.WriteSnac(); _Dictionary.Add(_Flap._Snac.req, im); _Flap._data.Write("00 00 00 00 00 00 00 00 00 01".Hex()); byte[] sendto = ASCIIEncoding.ASCII.GetBytes(im.uin); _Flap._data.WriteByte((byte)sendto.Length); _Flap._data.Write(sendto); _Flap._data.Write(new byte[] { 0, 6, 0, 0 }); Tvl _Tvl02 = new Tvl() { data = new byte[] { 05, 01, 00, 02, 01, 01 }, type = 2 }; Tvl _Tvl0101 = new Tvl() { type = 257, data = ("\0\0\0\0" + im.msg).ToBytes() }; _Tvl02.data = _Tvl02.data.Join(_Tvl0101.ToBytes()); _Flap._Tvls.Add(_Tvl02); _Flap.WriteTvl().Send(); im.Status = MessageStatus.Sending; im._DateTime = DateTime.Now; } catch (IOException) { Trace2(_uin + "Error msg send failed"); } }
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++; }
public Tvl GetTvl(ushort type) { Tvl _Tvl = _Tvls.SingleOrDefault(a => a.type == type); return(_Tvl); }