Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        private void Receive(byte[] data)
        {
            try {
                object message = APlayProtocolDecoder.Decode(new BinaryInputStream(data));
                _logger.LogDebug($"[ID: {data[0]}] [Type: {message?.GetType().Name ?? "null"}]: " +
                                 $"{(message == null ? "null" : Newtonsoft.Json.JsonConvert.SerializeObject(message, Newtonsoft.Json.Formatting.Indented))}");

                if (message != null)
                {
                    Handle(message);
                }
            } catch (Exception e) {
                _logger.LogError(e);
            }
        }