Class: Handle

Inherits:
Object show all
Defined in:
lib/handle.rb

Overview

This class handles connections. It stores session information about the connection. It keeps track of where the connection is currently sending it’s input to.

Constant Summary collapse

Log =
Log4r::Logger.new 'handle'
@@handles =

All of the connections.

[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(peer) ⇒ Handle

Returns a new instance of Handle.



18
19
20
21
22
# File 'lib/handle.rb', line 18

def initialize peer
	self.session = {:handle=>self}
	self.peer = peer
	self.route = MudController
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



11
12
13
# File 'lib/handle.rb', line 11

def args
  @args
end

#default_commandObject

Returns the value of attribute default_command.



11
12
13
# File 'lib/handle.rb', line 11

def default_command
  @default_command
end

#peerObject

Returns the value of attribute peer.



11
12
13
# File 'lib/handle.rb', line 11

def peer
  @peer
end

#redirectObject

Returns the value of attribute redirect.



11
12
13
# File 'lib/handle.rb', line 11

def redirect
  @redirect
end

#routeObject

Returns the value of attribute route.



11
12
13
# File 'lib/handle.rb', line 11

def route
  @route
end

#sessionObject

Returns the value of attribute session.



11
12
13
# File 'lib/handle.rb', line 11

def session
  @session
end

Class Method Details

.this(s) ⇒ Object



13
14
15
16
# File 'lib/handle.rb', line 13

def Handle.this s
	@@handles << h = Handle.new(s)
	h.start_handling
end

Instance Method Details

#message(message_string) ⇒ Object



48
49
50
# File 'lib/handle.rb', line 48

def message(message_string)
	peer.puts message_string
end

#puts(string) ⇒ Object



52
53
54
55
# File 'lib/handle.rb', line 52

def puts(string)
	peer.puts(string)
rescue Error
end

#shutdownObject



57
58
59
60
# File 'lib/handle.rb', line 57

def shutdown()
	read_and_write = 2
	peer.shutdown(read_and_write)
end

#start_handlingObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/handle.rb', line 24

def start_handling
	response = Muding.run("begin", self)

	while true
		update_route(response) if response
		if self.redirect
			response = Muding.run(self.args, self) 
		else
			response = Muding.run(peer.gets, self) #blocks on peer.gets
		end
	end

rescue Errno::EPIPE
	Log.info "Connection " + self.object_id.to_s + " Severed"
end

#update_route(response) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/handle.rb', line 40

def update_route(response)
	self.route = response.new_route if response.new_route
	self.default_command = nil
	self.default_command = response.default_command if response.default_command
	self.redirect = response.redirect
	self.args = response.args
end