Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChatClient"/> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="manager">The manager.</param>
 public ChatClient(IConnection connection, ChatRoomManager manager)
 {
     this.connection = connection;
     this.manager    = manager;
     this.connection.Disconnected   += (sender, e) => this.LogOff();
     this.connection.PacketReceived += (sender, packet) => this.PacketReceived(packet);
     this.connection.BeginReceive();
     this.LastActivity = DateTime.Now;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChatClient" /> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="manager">The manager.</param>
        /// <param name="logger">The logger.</param>
        public ChatClient(IConnection connection, ChatRoomManager manager, ILogger <ChatClient> logger)
        {
            this.manager    = manager;
            this.logger     = logger;
            this.connection = connection;
            this.connection.PacketReceived += this.ReadPacket;
            this.connection.Disconnected   += (sender, e) => this.LogOff();

            this.LastActivity = DateTime.Now;
            this.connection.BeginReceive();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChatServerListener"/> class.
        /// </summary>
        /// <param name="port">The port.</param>
        public ChatServerListener(int port)
        {
            this.port    = port;
            this.manager = new ChatRoomManager();
            this.randomNumberGenerator = RandomNumberGenerator.Create();

            this.clientCleanupTimer          = new Timer(1000 * 60); // every 60 seconds
            this.clientCleanupTimer.Elapsed += this.ClientCleanupInactiveClients;
            this.clientCleanupTimer.Start();
            this.roomCleanupTimer          = new Timer(1000 * 5); // every 5 seconds
            this.roomCleanupTimer.Elapsed += this.ClientCleanupUnusedRooms;
            this.roomCleanupTimer.Start();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChatServer" /> class.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="addressResolver">The address resolver which returns the address on which the listener will be bound to.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="plugInManager">The plug in manager.</param>
 public ChatServer(ChatServerSettings settings, IIpAddressResolver addressResolver, ILoggerFactory loggerFactory, PlugInManager plugInManager)
 {
     this.loggerFactory               = loggerFactory;
     this.logger                      = loggerFactory.CreateLogger <ChatServer>();
     this.settings                    = settings;
     this.addressResolver             = addressResolver;
     this.manager                     = new ChatRoomManager(loggerFactory);
     this.randomNumberGenerator       = RandomNumberGenerator.Create();
     this.clientCleanupTimer          = new Timer(this.settings.ClientCleanUpInterval.TotalMilliseconds);
     this.clientCleanupTimer.Elapsed += this.ClientCleanupInactiveClients;
     this.clientCleanupTimer.Start();
     this.roomCleanupTimer          = new Timer(this.settings.RoomCleanUpInterval.TotalMilliseconds);
     this.roomCleanupTimer.Elapsed += this.ClientCleanupUnusedRooms;
     this.roomCleanupTimer.Start();
     foreach (var endpoint in this.settings.Endpoints)
     {
         var listener = new ChatServerListener(endpoint, plugInManager, loggerFactory);
         listener.ClientAccepted  += this.ChatClientAccepted;
         listener.ClientAccepting += this.ChatClientAccepting;
         this.listeners.Add(listener);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChatServer" /> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="addressResolver">The address resolver which returns the address on which the listener will be bound to.</param>
        public ChatServer(ChatServerSettings settings, IIpAddressResolver addressResolver)
        {
            this.settings                    = settings;
            this.addressResolver             = addressResolver;
            this.manager                     = new ChatRoomManager();
            this.randomNumberGenerator       = RandomNumberGenerator.Create();
            this.clientCleanupTimer          = new Timer(this.settings.ClientCleanUpInterval.TotalMilliseconds);
            this.clientCleanupTimer.Elapsed += this.ClientCleanupInactiveClients;
            this.clientCleanupTimer.Start();
            this.roomCleanupTimer          = new Timer(this.settings.RoomCleanUpInterval.TotalMilliseconds);
            this.roomCleanupTimer.Elapsed += this.ClientCleanupUnusedRooms;
            this.roomCleanupTimer.Start();
            var plugInManager = new PlugInManager();

            plugInManager.DiscoverAndRegisterPlugInsOf <INetworkEncryptionFactoryPlugIn>();
            foreach (var endpoint in this.settings.Endpoints)
            {
                var listener = new ChatServerListener(endpoint, plugInManager);
                listener.ClientAccepted  += this.ChatClientAccepted;
                listener.ClientAccepting += this.ChatClientAccepting;
                this.listeners.Add(listener);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChatClient"/> class.
 /// </summary>
 /// <param name="socket">The socket.</param>
 /// <param name="manager">The chat room manager.</param>
 public ChatClient(Socket socket, ChatRoomManager manager)
     : this(new Connection(socket, null, new Decryptor()), manager)
 {
 }