Ejemplo n.º 1
0
        private void HandleReceived_Connection(NecConnection connection, NecPacket packet)
        {
            if (!_connectionHandlers.ContainsKey(packet.id))
            {
                _Logger.LogUnknownIncomingPacket(connection, packet, _serverType);
                return;
            }

            IConnectionHandler connectionHandler = _connectionHandlers[packet.id];

            if (connectionHandler.expectedSize != NO_EXPECTED_SIZE && packet.data.Size < connectionHandler.expectedSize)
            {
                _Logger.Error(connection,
                              $"[{_serverType}] Ignoring Packed (Id:{packet.id}) is smaller ({packet.data.Size}) than expected ({connectionHandler.expectedSize})");
                return;
            }

            _Logger.LogIncomingPacket(connection, packet, _serverType);
            packet.data.SetPositionStart();
            try
            {
                connectionHandler.Handle(connection, packet);
            }
            catch (Exception ex)
            {
                _Logger.Exception(connection, ex);
            }
        }
Ejemplo n.º 2
0
        private void HandleReceived(ITcpSocket socket, byte[] data)
        {
            if (!socket.IsAlive)
            {
                return;
            }

            NecClient client;

            lock (_lock)
            {
                if (!_clients.ContainsKey(socket))
                {
                    _logger.Error(socket, $"[{_identity}] Client does not exist in lookup");
                    return;
                }

                client = _clients[socket];
            }

            List <NecPacket> packets = client.Receive(data);

            foreach (NecPacket packet in packets)
            {
                if (_handlers.ContainsKey(packet.Id))
                {
                    IHandler handler = _handlers[packet.Id];
                    if (handler.ExpectedSize != NoExpectedSize && packet.Data.Size < handler.ExpectedSize)
                    {
                        _logger.Error(client,
                                      $"[{_identity}] Ignoring Packed (Id:{packet.Id}) is smaller ({packet.Data.Size}) than expected ({handler.ExpectedSize})");
                        continue;
                    }

                    _logger.LogIncomingPacket(client, packet, _identity);
                    packet.Data.SetPositionStart();
                    try
                    {
                        handler.Handle(client, packet);
                    }
                    catch (Exception ex)
                    {
                        _logger.Exception(client, ex);
                    }
                }
                else
                {
                    _logger.LogUnknownIncomingPacket(client, packet, _identity);
                }
            }
        }