/// <summary> /// Handles incoming messages and checks for message chunks, /// which are then read into the appropriate LargeMessageHandler /// </summary> /// <param name="messageSize"></param> private void HandleReceivedMessage(int messageSize, byte[] data = null) { byte[] source = null; if (data is null) { source = socketBuff; } else { source = data; } MessageType type = (MessageType)source[4]; if (type == MessageType.InputData) { byte[] input = new byte[5]; Buffer.BlockCopy(source, 5, input, 0, 5); InputDataReceived?.Invoke(this, input); return; } else if (type == MessageType.MessagePart) { HandleMessageChunkReceived(new MessageChunkMessage(socketBuff)); return; } HandleMessage(source); }
private void PipeReadCallback(IAsyncResult ar) { try { int bytesIn = pRead.EndRead(ar); if (bytesIn == 0) { throw new Exception("Pipe disconnected"); } int pSize = BitConverter.ToInt32(pipeBuff, 0); if (pSize >= 10240) { pipeBuff = new byte[pSize + 1]; ISLogger.Write("Pipe size set to " + (pSize + 1)); } if (pRead.Read(pipeBuff, 0, pSize) == 0) { throw new Exception("Pipe disconnected"); } switch ((IPCMessageType)pipeBuff[0]) { case IPCMessageType.Input: InputDataReceived?.Invoke(this, new ISInputData((ISInputCode)pipeBuff[1], BitConverter.ToInt16(pipeBuff, 2), BitConverter.ToInt16(pipeBuff, 4))); break; case IPCMessageType.CopyToClipboard: CopyToClipboardReceived?.Invoke(this, Encoding.Unicode.GetString(pipeBuff, 1, pipeBuff.Length - 1)); pipeBuff = new byte[10240]; //We need to make sure that the string doesnt sit in the buffer //So that remaining text is not copied after a short string break; default: ISLogger.Write("IPC->Unexpected message type " + (IPCMessageType)pipeBuff[0]); break; } if (pipeBuff.Length != 10240) { pipeBuff = new byte[10240]; } pRead.BeginRead(pipeBuff, 0, 4, PipeReadCallback, null); }catch (Exception ex) { if (closed) { return; } ISLogger.Write("Anon IPC Exception!\n {0}", ex.Message); ISLogger.Write("Source: " + ex.Source); ISLogger.Write("Trace: " + ex.StackTrace); } }
void IObserver <ListenerReceivedMessageArgs> .OnNotified(object sender, ListenerReceivedMessageArgs eventArgs) { if (_listenerReceivedMessage != null) { _listenerReceivedMessage.Invoke(this, eventArgs); } var gamepad = JsonUtility.FromJson <GamePad>(eventArgs.StreamMessage); _inputDataReceivedArgs.GamePadData = gamepad; if (InputDataReceived != null) { InputDataReceived.Invoke(this, _inputDataReceivedArgs); } }
protected void HandleInputData(byte[] input) { InputDataReceived?.Invoke(this, input); }