Class: MudServer::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, controller = MudServer::DefaultController) ⇒ Session

Returns a new instance of Session.



5
6
7
8
# File 'lib/session.rb', line 5

def initialize(connection, controller = MudServer::DefaultController)
  bootstrap_settings(connection, controller)
  start
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



3
4
5
# File 'lib/session.rb', line 3

def connection
  @connection
end

#controllerObject

Returns the value of attribute controller.



3
4
5
# File 'lib/session.rb', line 3

def controller
  @controller
end

#input_threadObject

Returns the value of attribute input_thread.



3
4
5
# File 'lib/session.rb', line 3

def input_thread
  @input_thread
end

#ip_addrObject

Returns the value of attribute ip_addr.



3
4
5
# File 'lib/session.rb', line 3

def ip_addr
  @ip_addr
end

Instance Method Details

#bootstrap_settings(connection, controller) ⇒ Object



10
11
12
13
14
# File 'lib/session.rb', line 10

def bootstrap_settings(connection, controller)
  @connection   = connection
  @ip_addr      = @connection.peeraddr[-1]
  @controller   = controller.new(self)
end

#startObject



16
17
18
19
20
21
22
# File 'lib/session.rb', line 16

def start
  @input_thread = Thread.new(@connection) do |client|
    while (client_input = client.gets.chomp)
      @controller.get_text client_input
    end
  end
end