Пример #1
0
        private void v_HandlePacket(NetIncomingMessage msg)
        {
            try
            {
                IPacket packet = DeserializePacket(msg);

                if (packet is null)
                {
                    throw new Exception("Tried to parse a IPacket, but failed");
                }

                OnPacketReceived?.Invoke(packet);
                m_callbackRegistry.HandlePacket(packet);

                if (packet is DataPacket dataPacket)
                {
                    OnDataPacketReceived?.Invoke(dataPacket);
                }
                else if (packet is RequestPacket requestPacket)
                {
                    OnRequestPacketReceived?.Invoke(requestPacket);
                }
                else if (packet is ResponsePacket responsePacket)
                {
                    OnResponsePacketReceived?.Invoke(responsePacket);
                    m_requestRegistry.HandlePacket(responsePacket);
                }
            }
            catch (Exception e)
            {
                msg.SenderConnection.Deny(string.Format("Internal Error: {0}", e.ToString()));
            }
        }
Пример #2
0
        private void RegisterListeners()
        {
            UdpWrapper.OnPacketReceived += (object sender, UdpReceiveResult e) =>
            {
                var packet = SacnPacket.Parse(e.Buffer);
                switch (packet)
                {
                case DataPacket dataPacket:
                    OnDataPacketReceived?.Invoke(this, dataPacket);
                    break;

                case SynchronizationPacket syncPacket:
                    OnSynchronizationPacketReceived?.Invoke(this, syncPacket);
                    break;

                case UniverseDiscoveryPacket discoveryPacket:
                    OnUniverseDiscoveryPacketReceived?.Invoke(this, discoveryPacket);
                    break;
                }
            };
        }