Module: GameServer::Client
Instance Method Summary
collapse
#log, #log_exception, #with_exception_logging
Instance Method Details
#find_controller(name) ⇒ Object
33
34
35
36
37
|
# File 'lib/client.rb', line 33
def find_controller(name)
"#{self.class.name}::#{name.to_s.camelize}Controller".constantize
rescue NameError
"#{self.class.name}::NilController".constantize
end
|
#receive_data(data) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/client.rb', line 20
def receive_data(data)
@data ||= ""
@data += data
if data =~ /\000\n$/
all_data = @data
@data = ""
all_data.gsub!("\000",'').split(/\n/).each do |string|
request = GameServer::RequestParser.new(string).parse
receive_request(request)
end
end
end
|
#receive_request(request) ⇒ Object
4
5
6
7
8
|
# File 'lib/client.rb', line 4
def receive_request(request)
find_controller(request.name).new(self, request).run
rescue Exception => e
log_exception e
end
|
#send_json(object) ⇒ Object
15
16
17
|
# File 'lib/client.rb', line 15
def send_json(object)
send_line object.to_json
end
|
#send_line(string) ⇒ Object
10
11
12
13
|
# File 'lib/client.rb', line 10
def send_line(string)
log "send_line #{string}\n"
send_data(string + "\n")
end
|