Module: Msn::Protocol
- Includes:
- EventMachine::Protocols::LineText2
- Included in:
- NotificationServer, Switchboard
- Defined in:
- lib/msn/protocol.rb
Overview
Instance Method Summary
(collapse)
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(name, *args)
110
111
112
|
# File 'lib/msn/protocol.rb', line 110
def method_missing(name, *args)
send_command name.upcase, *args
end
|
Instance Method Details
- (Object) answer_challenge(challenge_string)
67
68
69
|
# File 'lib/msn/protocol.rb', line 67
def answer_challenge(challenge_string)
send_payload_command "QRY", Msn::Challenge::ProductId, Msn::Challenge.challenge(challenge_string)
end
|
- (Object) clear_event(kind)
106
107
108
|
# File 'lib/msn/protocol.rb', line 106
def clear_event(kind)
@event_handlers.delete kind
end
|
- (Object) handle_event(header, data = nil)
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/msn/protocol.rb', line 56
def handle_event(, data = nil)
return unless @event_handlers
handler = @event_handlers[[0]]
if handler
Fiber.new do
handler.call , data
end.resume
end
end
|
- (Object) handle_normal_command(pieces)
35
36
37
38
39
40
41
|
# File 'lib/msn/protocol.rb', line 35
def handle_normal_command(pieces)
if fiber = @command_fibers.delete(pieces[1].to_i)
fiber.resume pieces
else
handle_event pieces
end
end
|
- (Object) handle_payload_command(pieces)
43
44
45
46
47
48
|
# File 'lib/msn/protocol.rb', line 43
def handle_payload_command(pieces)
@header = pieces
size = pieces.last.to_i
set_binary_mode size
end
|
- (Object) on_event(kind, &block)
101
102
103
104
|
# File 'lib/msn/protocol.rb', line 101
def on_event(kind, &block)
@event_handlers ||= {}
@event_handlers[kind] = block
end
|
- (Object) post_init
5
6
7
8
|
# File 'lib/msn/protocol.rb', line 5
def post_init
@trid = 1
@command_fibers = {}
end
|
- (Object) receive_binary_data(data)
50
51
52
53
54
|
# File 'lib/msn/protocol.rb', line 50
def receive_binary_data(data)
Msn::Messenger.log_info "<<* #{data}"
handle_event @header, data
end
|
- (Object) receive_line(line)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/msn/protocol.rb', line 10
def receive_line(line)
Msn::Messenger.log_info "<< #{line}"
pieces = line.split(' ')
case pieces[0]
when 'CHL'
answer_challenge pieces[2]
when 'RNG'
handle_event pieces
when 'MSG', 'NOT', 'GCF', 'UBX'
handle_payload_command pieces
when 'QRY'
when 'ADL', 'RML'
if pieces[2] == 'OK'
handle_normal_command pieces
else
handle_payload_command pieces
end
else
handle_normal_command pieces
end
end
|
- (Object) send_command(command, *args)
71
72
73
74
75
76
77
78
|
# File 'lib/msn/protocol.rb', line 71
def send_command(command, *args)
@command_fibers[@trid] = Fiber.current
text = "#{command} #{@trid} #{args.join ' '}\r\n"
send_command_internal text
Fiber.yield
end
|
- (Object) send_command_internal(text)
94
95
96
97
98
99
|
# File 'lib/msn/protocol.rb', line 94
def send_command_internal(text)
Msn::Messenger.log_info ">> #{text}"
send_data text
@trid += 1
@trid - 1
end
|
- (Object) send_payload_command(command, *args)
80
81
82
83
84
|
# File 'lib/msn/protocol.rb', line 80
def send_payload_command(command, *args)
payload = args.pop
args.push payload.length
send_command_internal "#{command} #{@trid} #{args.join ' '}\r\n#{payload}"
end
|
- (Object) send_payload_command_and_wait(command, *args)
86
87
88
89
90
91
92
|
# File 'lib/msn/protocol.rb', line 86
def send_payload_command_and_wait(command, *args)
@command_fibers[@trid] = Fiber.current
send_payload_command command, *args
Fiber.yield
end
|