picking up project again. Fixing rspec errors first
This commit is contained in:
+15
-16
@@ -176,19 +176,17 @@ module Game
|
||||
# The entry point for all messages that arrive from a client. The
|
||||
# payload must be a hash decoded from JSON and contain a `type` field.
|
||||
#
|
||||
# @param client [TCPSocket] The socket that the client used.
|
||||
# @param command [Hash] The parsed client command
|
||||
#
|
||||
# @return [String] JSON-encoded response
|
||||
#
|
||||
def parse_command(command)
|
||||
def parse_command(client, command)
|
||||
return error_response('Player not registered!') unless command['player_id']
|
||||
|
||||
case command['type']
|
||||
when 'dbg'
|
||||
# Debugger - do nothing in production
|
||||
{ 'type' => 'ok', 'payload' => 'debugging' }.to_json
|
||||
when 'hello'
|
||||
error_response('Hello command should already have been handled.')
|
||||
parse_hello(client, command)
|
||||
when 'query'
|
||||
parse_query(command)
|
||||
when 'command'
|
||||
@@ -233,7 +231,18 @@ module Game
|
||||
# @return [String] JSON-encoded error response
|
||||
#
|
||||
def error_response(request_id, msg)
|
||||
{ 'type' => 'error', 'request_id', => id, 'payload' => msg }.to_json
|
||||
{ 'type' => 'error', 'request_id' => id, 'payload' => msg }.to_json
|
||||
end
|
||||
|
||||
##
|
||||
# Return an update response to the client
|
||||
def update_response(request_id, domain, payload)
|
||||
{'type' => 'update', 'domain' => domain, 'request_id' => request_id, 'payload' => payload}.to_json
|
||||
end
|
||||
|
||||
# Return an event response to the client
|
||||
def event_response(request_id, domain, payload)
|
||||
{'type' => 'event', 'domain' => domain, 'request_id' => request_id, 'payload' => payload}.to_json
|
||||
end
|
||||
|
||||
##
|
||||
@@ -367,16 +376,6 @@ module Game
|
||||
@players.find { |p| p.player_id == player_id } || false
|
||||
end
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# PRIVATE HELPERS - kept simple for the test-suite
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
private
|
||||
|
||||
def error_response(msg)
|
||||
{ 'type' => 'error', 'payload' => msg }.to_json
|
||||
end
|
||||
|
||||
def load_players(ids)
|
||||
ids.map { |id| Player.load_from_id(id) }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user