OnResponse() public abstract method

public abstract OnResponse ( BinaryReader reader ) : void
reader System.IO.BinaryReader
return void
Example #1
0
		private bool HandleRpcResult(ulong messageId, int sequence, BinaryReader messageReader, MTProtoRequest request)
		{
			uint code = messageReader.ReadUInt32();
			ulong requestId = messageReader.ReadUInt64();

			if (requestId == (ulong) request.MessageId)
				request.ConfirmReceived = true;

			//throw new NotImplementedException();
			/*
			lock (runningRequests)
			{
				if (!runningRequests.ContainsKey(requestId))
				{
					logger.warning("rpc response on unknown request: {0}", requestId);
					messageReader.BaseStream.Position -= 12;
					return false;
				}

				request = runningRequests[requestId];
				runningRequests.Remove(requestId);
			}
			*/

			uint innerCode = messageReader.ReadUInt32();
			if (innerCode == 0x2144ca19)
			{ // rpc_error
				int errorCode = messageReader.ReadInt32();
				string errorMessage = Serializers.String.read(messageReader);

				if (errorMessage.StartsWith("FLOOD_WAIT_"))
				{
					var resultString = Regex.Match(errorMessage, @"\d+").Value;
					var seconds = int.Parse(resultString);
					Debug.WriteLine($"Should wait {seconds} sec.");
					Thread.Sleep(1000*seconds);
				}
				else if (errorMessage.StartsWith("PHONE_MIGRATE_"))
				{
					var resultString = Regex.Match(errorMessage, @"\d+").Value;
					var dcIdx = int.Parse(resultString);
					var exception = new InvalidOperationException($"Your phone number registered to {dcIdx} dc. Please update settings. See https://github.com/sochix/TLSharp#i-get-an-error-migrate_x for details.");
					exception.Data.Add("dcId", dcIdx);
					throw exception;
				}
				else
				{
					throw new InvalidOperationException(errorMessage);
				}
				
			}
			else if (innerCode == 0x3072cfa1)
			{
				try
				{
					// gzip_packed
					byte[] packedData = Serializers.Bytes.read(messageReader);
					using (var packedStream = new MemoryStream(packedData, false))
					using (var zipStream = new GZipStream(packedStream, CompressionMode.Decompress))
					using (var compressedReader = new BinaryReader(zipStream))
					{
						request.OnResponse(compressedReader);
					}
				}
				catch (ZlibException ex)
				{
					
				}
			}
			else
			{
				messageReader.BaseStream.Position -= 4;

				request.OnResponse(messageReader);
			}

			return false;
		}
Example #2
0
		private bool HandleRpcResult(ulong messageId, int sequence, BinaryReader messageReader, MTProtoRequest request)
		{
			uint code = messageReader.ReadUInt32();
			ulong requestId = messageReader.ReadUInt64();

			if (requestId == (ulong) request.MessageId)
				request.ConfirmReceived = true;

			//throw new NotImplementedException();
			/*
			lock (runningRequests)
			{
				if (!runningRequests.ContainsKey(requestId))
				{
					logger.warning("rpc response on unknown request: {0}", requestId);
					messageReader.BaseStream.Position -= 12;
					return false;
				}

				request = runningRequests[requestId];
				runningRequests.Remove(requestId);
			}
			*/

			uint innerCode = messageReader.ReadUInt32();
			if (innerCode == 0x2144ca19)
			{ // rpc_error
				int errorCode = messageReader.ReadInt32();
				string errorMessage = Serializers.String.read(messageReader);

				if (errorMessage.StartsWith("FLOOD_WAIT_"))
				{
					var resultString = Regex.Match(errorMessage, @"\d+").Value;
					var seconds = int.Parse(resultString);
					Debug.WriteLine($"Should wait {seconds} sec.");
					Thread.Sleep(1000*seconds);
				}
				else
				{
					throw new InvalidOperationException(errorMessage);
				}
				
			}
			else if (innerCode == 0x3072cfa1)
			{
				// gzip_packed
				byte[] packedData = Serializers.Bytes.read(messageReader);
				using (MemoryStream packedStream = new MemoryStream(packedData, false))
				using (GZipStream zipStream = new GZipStream(packedStream, CompressionMode.Decompress))
				using (BinaryReader compressedReader = new BinaryReader(zipStream))
				{
					request.OnResponse(compressedReader);
				}
			}
			else
			{
				messageReader.BaseStream.Position -= 4;

				request.OnResponse(messageReader);
			}

			return false;
		}