Пример #1
0
 /// <summary>
 /// Adds a channel to this server
 /// </summary>
 /// <remarks>
 /// May throw a <see cref="ChannelOperationException"/> if used incorrectly
 /// </remarks>
 /// <param name="channel">The channel to add</param>
 /// <returns>Returns true if channel was added successfully</returns>
 public bool AddChannel(IServerChannel channel)
 {
     if (!_channelMgr.AddChannel(channel))
     {
         return(false);
     }
     OnChannelCreated.Raise(this, new ChannelEventArgs(channel));
     channel.HostServer       = this;
     channel.OnPeerConnected += (sender, e) => OnPeerConnected.Raise(this, e);
     channel.PacketProcessor  = _channelMgr.GetMainChannel().PacketProcessor;
     return(true);
 }
Пример #2
0
        /// <summary>
        /// Creates a channel using <see cref="ChannelManager.CreateChannel{T}()"/> and adds it to this server
        /// </summary>
        /// <remarks>
        /// May throw a <see cref="ChannelOperationException"/> if used incorrectly
        /// </remarks>
        /// <code>
        /// CreateAndAddChannel{T}(ch => {
        ///     ch.Name = "Example";
        ///     ch.Port = 1000;
        ///     ...
        /// });
        /// </code>
        /// <typeparam name="T">The type of channel to create</typeparam>
        /// <param name="channelAction">An action to set channel data</param>
        /// <returns>Returns true if channel was created and added successfully</returns>
        public bool CreateAndAddChannel <T>(Action <T> channelAction) where T : IServerChannel
        {
            var channel = (IServerChannel)_channelMgr.CreateChannel <T>();

            channelAction((T)channel);
            if (!_channelMgr.AddChannel(channel))
            {
                return(false);
            }
            channel.HostServer = this;
            OnChannelCreated.Raise(this, new ChannelEventArgs(channel));
            channel.OnPeerConnected += OnPeerConnected;
            return(true);
        }