Module: Alchemist::EventMachine::ClientProtocol
- Defined in:
- lib/alchemist/event_machine/client_protocol.rb
Instance Method Summary collapse
- #appear ⇒ Object
- #create(element) ⇒ Object
- #describe(symbol) ⇒ Object
- #dispatch_command(command, data = nil) ⇒ Object
- #east ⇒ Object
- #element(symbol, name) ⇒ Object
- #forge(ingred_1, ingred_2, result) ⇒ Object
- #formulate(ingred_1, ingred_2, result, name) ⇒ Object
- #handle_appeared ⇒ Object
- #handle_avatars(message) ⇒ Object
- #handle_basics(message) ⇒ Object
- #handle_compounds(message) ⇒ Object
- #handle_element(message) ⇒ Object
- #handle_error(message) ⇒ Object
- #handle_hello ⇒ Object
- #handle_inventory(message) ⇒ Object
- #handle_location(message) ⇒ Object
- #handle_messages(message) ⇒ Object
- #handle_noelement(message) ⇒ Object
- #handle_see(message) ⇒ Object
-
#handle_welcome ⇒ Object
Clients should implement the various handle_* methods to take action in response to serve updates.
-
#login(name) ⇒ Object
Clients can call these methods to send commands to the server.
- #look ⇒ Object
- #message(number, string) ⇒ Object
- #move(direction) ⇒ Object
- #north ⇒ Object
- #put(element) ⇒ Object
- #read ⇒ Object
- #receive_data(data) ⇒ Object
-
#receive_line(line) ⇒ Object
Command framing and dispatch.
- #request_basics ⇒ Object
- #request_compounds ⇒ Object
- #request_inventory ⇒ Object
- #request_location ⇒ Object
- #south ⇒ Object
- #take ⇒ Object
- #west ⇒ Object
- #who ⇒ Object
Instance Method Details
#appear ⇒ Object
28 29 30 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 28 def appear send_data "appear\n" end |
#create(element) ⇒ Object
85 86 87 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 85 def create(element) send_data "create #{element}\n" end |
#describe(symbol) ⇒ Object
93 94 95 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 93 def describe(symbol) send_data "describe #{symbol}\n" end |
#dispatch_command(command, data = nil) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 146 def dispatch_command(command, data = nil) case command when "Welcome" then handle_welcome when "hello" then handle_hello when "appeared" then handle_appeared when "see" then handle_see data when "inventory" then handle_inventory data when "basics" then handle_basics data when "compounds" then handle_compounds data when "error" then handle_error data when "messages" then data when "avatars" then handle_avatars data when "location" then handle_location data when "element" then handle_element data when "noelement" then handle_noelement data end end |
#east ⇒ Object
73 74 75 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 73 def east move 'east' end |
#element(symbol, name) ⇒ Object
89 90 91 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 89 def element(symbol, name) send_data "element #{symbol} #{name}\n" end |
#forge(ingred_1, ingred_2, result) ⇒ Object
97 98 99 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 97 def forge(ingred_1, ingred_2, result) send_data "forge #{ingred_1} #{ingred_2} #{result}\n" end |
#formulate(ingred_1, ingred_2, result, name) ⇒ Object
101 102 103 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 101 def formulate(ingred_1, ingred_2, result, name) send_data "formulate #{ingred_1} #{ingred_2} #{result} #{name}\n" end |
#handle_appeared ⇒ Object
9 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 9 def handle_appeared;end |
#handle_avatars(message) ⇒ Object
15 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 15 def handle_avatars();end |
#handle_basics(message) ⇒ Object
12 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 12 def handle_basics();end |
#handle_compounds(message) ⇒ Object
13 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 13 def handle_compounds();end |
#handle_element(message) ⇒ Object
18 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 18 def handle_element();end |
#handle_error(message) ⇒ Object
17 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 17 def handle_error();end |
#handle_hello ⇒ Object
8 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 8 def handle_hello;end |
#handle_inventory(message) ⇒ Object
11 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 11 def handle_inventory();end |
#handle_location(message) ⇒ Object
16 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 16 def handle_location();end |
#handle_messages(message) ⇒ Object
14 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 14 def ();end |
#handle_noelement(message) ⇒ Object
19 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 19 def handle_noelement();end |
#handle_see(message) ⇒ Object
10 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 10 def handle_see();end |
#handle_welcome ⇒ Object
Clients should implement the various handle_* methods to take action in response to serve updates
7 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 7 def handle_welcome;end |
#login(name) ⇒ Object
Clients can call these methods to send commands to the server
23 24 25 26 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 23 def login(name) send_data name send_data "\n" end |
#look ⇒ Object
36 37 38 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 36 def look send_data "look\n" end |
#message(number, string) ⇒ Object
105 106 107 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 105 def (number, string) send_data "message #{number} #{string}\n" end |
#move(direction) ⇒ Object
60 61 62 63 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 60 def move(direction) send_data direction send_data "\n" end |
#north ⇒ Object
65 66 67 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 65 def north move 'north' end |
#put(element) ⇒ Object
81 82 83 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 81 def put(element) send_data "put #{element}\n" end |
#read ⇒ Object
40 41 42 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 40 def read send_data "read\n" end |
#receive_data(data) ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 113 def receive_data(data) @buffer ||= '' @buffer << data while @buffer =~ /^.*?\n/ line = $& receive_line line @buffer[0,line.length] = '' end end |
#receive_line(line) ⇒ Object
Command framing and dispatch
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 126 def receive_line(line) if @lines_to_read @response << line @lines_to_read -= 1 if @lines_to_read <= 0 @lines_to_read = nil dispatch_command @command, @response @command = nil @response = nil end elsif line =~ /^(see|messages|avatars) (\d+)$/ @command = $1 @lines_to_read = $2.to_i @response = '' else dispatch_command *line.split(' ',2) end end |
#request_basics ⇒ Object
48 49 50 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 48 def request_basics send_data "basics\n" end |
#request_compounds ⇒ Object
52 53 54 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 52 def request_compounds send_data "compounds\n" end |
#request_inventory ⇒ Object
44 45 46 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 44 def request_inventory send_data "inventory\n" end |
#request_location ⇒ Object
32 33 34 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 32 def request_location send_data "location\n" end |
#south ⇒ Object
69 70 71 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 69 def south move 'south' end |
#take ⇒ Object
109 110 111 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 109 def take send_data "take\n" end |
#west ⇒ Object
77 78 79 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 77 def west move 'west' end |
#who ⇒ Object
56 57 58 |
# File 'lib/alchemist/event_machine/client_protocol.rb', line 56 def who send_data "who\n" end |