Esempio n. 1
0
        private void _parseData()
        {
            var eventString = string.Empty;
            var stateString = string.Empty;

            try
            {
                using (var memoryStream = new MemoryStream(_buffer.BufferData, false))
                    using (var br = new BinaryReader(memoryStream, Encoding.ASCII))
                    {
                        br.ReadBytes(2); // skip two unknown bytes Approved by ZLOFENIX

                        // read message length
                        var messageLength = br.ReadUInt16();

                        // check, we got the full message or not
                        if (_buffer.Size < messageLength - _messageHeaderSize)
                        {
                            return;
                        }

                        // read and parse message data
                        var eventStringLength = br.ReadByte();

                        eventString = br.ReadCountedString(eventStringLength)
                                      .Trim();

                        var stateStringLength = br.ReadUInt16();

                        stateString = br.ReadCountedString(stateStringLength)
                                      .Trim();

                        //    .Replace('\0'.ToString(), string.Empty);

                        // normalize state string
                        stateString = Uri.UnescapeDataString(stateString);
                    }
            }
            catch (Exception ex)
            {
                _logger.Error($"{nameof(_parseData)} message {ex.Message}");
            }

            _buffer.Clear();

            // parse string to game state
            var state = _GameStateParser.ParseStates(eventString, stateString);

            // raise event
            _OnPipeEvent(state);
        }
Esempio n. 2
0
        private void _EndAsyncEvent(IAsyncResult iar)
        {
            var ar            = (AsyncResult)iar;
            var invokedMethod = (EventHandler <ZGamePipeArgs>)ar.AsyncDelegate;

            try
            {
                invokedMethod.EndInvoke(iar);
            }
            catch (Exception ex)
            {
                _logger.Error($"Pipe event handler throws exception. MSG: {ex.Message}");
                throw new Exception("Pipe event handler throws exception.", ex);
            }
        }
Esempio n. 3
0
        public async Task <ZStatsBase> GetStatsAsync(ZGame game)
        {
            ZStatsBase stats = null;

            var request  = ZRequestFactory.CreateStatsRequest(game);
            var response = await ZRouter.GetResponseAsync(request);

            if (response.StatusCode != ZResponseStatusCode.Ok)
            {
                _logger.Error($"Request fail {request}");
            }
            else
            {
                switch (game)
                {
                case ZGame.BF3: stats = _parser.ParseBF3Stats(response.ResponsePackets); break;

                case ZGame.BF4: stats = _parser.ParseBF4Stats(response.ResponsePackets); break;
                }
            }

            return(stats);
        }