예제 #1
0
        public override void DispatchEvent(IEvent evt)
        {
            if (evt.EventType != EventType.SHARED_OBJECT || !(evt is ISharedObjectMessage))
            {
                // Don't know how to handle this event.
                base.DispatchEvent(evt);
                return;
            }

            ISharedObjectMessage msg = (ISharedObjectMessage)evt;

            if (msg.HasSource)
            {
                BeginUpdate(msg.Source);
            }
            else
            {
                BeginUpdate();
            }

            try
            {
                foreach (ISharedObjectEvent sharedObjectEvent in msg.Events)
                {
                    switch (sharedObjectEvent.Type)
                    {
                    case SharedObjectEventType.SERVER_CONNECT:
                        if (!IsConnectionAllowed())
                        {
                            _so.ReturnError(StatusASO.SO_NO_READ_ACCESS);
                        }
                        else if (msg.HasSource)
                        {
                            IEventListener source = msg.Source;
                            if (source is RtmpConnection)
                            {
                                (source as RtmpConnection).RegisterBasicScope(this);
                            }
                            else
                            {
                                AddEventListener(source);
                            }
                        }
                        break;

                    case SharedObjectEventType.SERVER_DISCONNECT:
                        if (msg.HasSource)
                        {
                            IEventListener source = msg.Source;
                            if (source is RtmpConnection)
                            {
                                (source as RtmpConnection).UnregisterBasicScope(this);
                            }
                            else
                            {
                                RemoveEventListener(source);
                            }
                        }
                        break;

                    case SharedObjectEventType.SERVER_SET_ATTRIBUTE:
                        if (!IsWriteAllowed(sharedObjectEvent.Key, sharedObjectEvent.Value))
                        {
                            _so.ReturnAttributeValue(sharedObjectEvent.Key);
                            _so.ReturnError(StatusASO.SO_NO_WRITE_ACCESS);
                        }
                        else
                        {
                            SetAttribute(sharedObjectEvent.Key, sharedObjectEvent.Value);
                        }
                        break;

                    case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE:
                        if (!IsDeleteAllowed(sharedObjectEvent.Key))
                        {
                            _so.ReturnAttributeValue(sharedObjectEvent.Key);
                            _so.ReturnError(StatusASO.SO_NO_WRITE_ACCESS);
                        }
                        else
                        {
                            RemoveAttribute(sharedObjectEvent.Key);
                        }
                        break;

                    case SharedObjectEventType.SERVER_SEND_MESSAGE:
                        // Ignore request silently if not allowed
                        if (IsSendAllowed(sharedObjectEvent.Key, sharedObjectEvent.Value as IList))
                        {
                            SendMessage(sharedObjectEvent.Key, sharedObjectEvent.Value as IList);
                        }
                        break;

                    default:
                        log.Warn("Unknown SO event: " + sharedObjectEvent.Type.ToString());
                        break;
                    }
                }
            }
            finally
            {
                EndUpdate();
            }
        }