Sha256: c50f78ad5178fc15a1c0288a3ffa4b526d1fe3fd447086f8a697e0832ff1610d

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

module Marvin
  module IRC
    module Server
      
      # Server utilities
      autoload :NamedStore,         'marvin/irc/server/named_store'
      
      # Store each user
      UserStore = NamedStore.new(:nicks, :user) do
        def nick_taken?(nick)
          has_key?(nick)
        end
        
        def each_user_except(user)
          self.each_user do |u|
            yield u unless user == u 
          end
        end
      end
      
      # Store each channel
      ChannelStore = NamedStore.new(:names, :channel)
      
      autoload :Channel,            'marvin/irc/server/channel'
      # The actual network connection
      autoload :BaseConnection,     'marvin/irc/server/base_connection'
      # An our implementations of protocol-specific stuff.
      autoload :AbstractConnection, 'marvin/irc/server/abstract_connection'
      autoload :UserConnection,     'marvin/irc/server/user_connection'
      autoload :ServerConnection,   'marvin/irc/server/server_connection'
      # Extensions for each part
      autoload :User,               'marvin/irc/server/user'
      
      # call start_server w/ the default options
      # and inside an EM::run block.
      def self.run
        EventMachine::run do
          Marvin::Logger.info "Starting server..."
          start_server :bind_addr => "0.0.0.0"
        end
      end
      
      # Starts the server with a set of given options
      def self.start_server(opts = {})
        opts[:started_at] ||= Time.now
        opts[:host]       ||= self.host_name
        opts[:port]       ||= 6667
        EventMachine::start_server(opts[:bind_addr] || opts[:host], opts[:port], BaseConnection, opts)
      end
      
      def self.host_name
        @@host_name ||= Socket.gethostname
      end
      
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
Sutto-marvin-0.2.0 lib/marvin/irc/server.rb
Sutto-marvin-0.2.1 lib/marvin/irc/server.rb
Sutto-marvin-0.2.2 lib/marvin/irc/server.rb