Exemplo n.º 1
0
        /// <summary>
        /// Initializes the event handlers.
        /// </summary>
        private void InitializeEventHandlers()
        {
            foreach (var item in this.allEventHandlers)
            {
                BotEventHandler handler = null;

                // try to get the value
                try
                {
                    handler = item.Value;
                }
                catch (CompositionException ex)
                {
                    ReportPluginCompositionError(ex);
                    continue;
                }

                // handler is valid, process it
                var attribute = item.Value.GetHandlerAttribute();
                var target = PluginHandle.Get(handler);
                var eventData = new EventData(attribute.PacketType, target, handler, attribute);

                // add system handlers to a specific list
                if (item.Value.IsSystemPlugin())
                    this.eventHandlerBag[attribute.PacketType].SystemHandlers.Add(eventData);
                else
                    this.eventHandlerBag[attribute.PacketType].Handlers.Add(eventData);

                // save plugin reference
                AddPluginToRunningList(target);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the event handler.
        /// </summary>
        /// <param name="handler">The handler.</param>
        /// <param name="packet">The packet.</param>
        public void ExecuteEventHandler(EventData eventData, ServerPacket packet)
        {
            string ns = null;
            if (!string.IsNullOrEmpty(packet.param))
                ns = MessageHelper.DeformatChat(packet.param);

            var eventPacket = new EventPacket(packet);
            var context = GenerateContext(eventPacket, eventData.Target);
            var handler = eventData.EventHandler;

            try
            {
                handler(eventPacket, context);
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                console.WriteLine("Error occured. See bot log for details.", Style.Error);
            }
        }