private void Handle(string sender, byte[] data) { try { object message = APlayProtocolDecoder.Decode(new BinaryInputStream(data)); // if (sender == "CLIENT_0" && message is APlayStringMessage msg) { // msg.GetDataAsDecodedJson()["path"] = ((string)msg.GetDataAsDecodedJson()["path"]).Replace("❌FLOWFEHLER❌", "ALPHA"); // } _logger.LogSuccess($"[{sender}] [ID: {data[0]}] Message processed: {message?.GetType().Name ?? "null"}"); if (message != null) { _logger.LogCritical(Newtonsoft.Json.JsonConvert.SerializeObject(message, Newtonsoft.Json.Formatting.Indented)); } data = APlayProtocolEncoder.Encode(message); if (sender == "Client_0") { _client.GetStream().Write(data, 0, data.Length); } else { _stream.Write(data, 0, data.Length); } } catch (Exception e) { _logger.LogError(e); } }
public async void Send(object message) { try { // Console.WriteLine(JsonConvert.SerializeObject(message)); byte[] binary = APlayProtocolEncoder.Encode(message); if (binary == null || binary.Length == 0) { _logger.LogDebug($"Encoded is null!"); return; } await _stream.WriteAsync(binary, 0, binary.Length); } catch (Exception e) { _logger.LogError(e); } }