Revision fccfdfb9
Added by Marc Dequènes about 14 years ago
- ID fccfdfb932e84ab5735ffc5a33c7b520e313e9e5
lib/cyborghood/cyborg/conversation.rb | ||
---|---|---|
if respond_to? method
|
||
send(method, message)
|
||
else
|
||
send_error_protocol("unknown action")
|
||
send_error_protocol "unknown action"
|
||
end
|
||
end
|
||
|
||
... | ... | |
recv_message.create_reply("ANNOUNCE OK").send
|
||
end
|
||
|
||
def send_error_protocol(message = nil)
|
||
# message can be nil if nothing could be parsed (or we may close the conversation, dunno)
|
||
# TODO
|
||
# @conversation.set_error_status
|
||
# @conversation.send_peer("ERROR PROTO", { :error => msg || "" })
|
||
def send_error_protocol(error, fatal = false)
|
||
@conversation.thread('system').new_message("ERROR PROTOCOL", { :error => error }).send
|
||
@conversation.set_error_status(fatal)
|
||
end
|
||
|
||
def send_error_action(recv_message, message)
|
||
recv_message.create_reply("ERROR ACTION", { :error => message }).send
|
||
end
|
||
|
||
def send_reply_ack(recv_message)
|
||
recv_message.create_reply("REPLY ACK").send
|
||
end
|
||
|
||
def send_quit_decline(recv_message, reason)
|
||
recv_message.create_reply("QUIT LEAVING", { :reason => reason }).send
|
||
def send_reply_decline(recv_message, reason)
|
||
recv_message.create_reply("REPLY DECLINE", { :reason => reason }).send
|
||
end
|
||
|
||
def send_reply_result(recv_message, result)
|
||
recv_message.create_reply("REPLY ACK", { :result => result }).send
|
||
end
|
||
|
||
def send_quit_decline(reason)
|
||
@conversation.thread('system').new_message("QUIT LEAVING", { :reason => reason }).send
|
||
end
|
||
|
||
def send_quit_leaving
|
||
conversation.thread('system').new_message("QUIT LEAVING").send
|
||
@conversation.thread('system').new_message("QUIT LEAVING").send
|
||
end
|
||
end
|
||
|
||
... | ... | |
|
||
send_reply
|
||
|
||
# TODO: properly QUIT
|
||
check_errors
|
||
end
|
||
|
||
def check_errors
|
||
@error_count += 1 if @receive_error
|
||
|
||
msg_quit = nil
|
||
if @error_count >= MAXIMUM_ERROR_COUNT
|
||
reply_fatal_error "too much errors, terminating"
|
||
msg_quit = "too much errors, terminating"
|
||
elsif @fatal_error
|
||
msg_quit = "previous fatal error"
|
||
end
|
||
|
||
unless msg_quit.nil?
|
||
send_quit_decline msg_quit
|
||
close_connection_after_writing
|
||
end
|
||
close_connection_after_writing if @fatal_error
|
||
end
|
||
|
||
def receive_message(message)
|
||
... | ... | |
|
||
def receive_error(msg)
|
||
logger.error "Error [#{identifier}]: #{msg}"
|
||
@error_count += 1
|
||
end
|
||
|
||
def unbind
|
||
... | ... | |
|
||
def reply_syntax_error(msg = nil)
|
||
logger.error "Protocol error [#{identifier}]: syntax error (#{msg})"
|
||
set_error_status
|
||
|
||
msg = "syntax error" + (msg ? ": " + msg : "")
|
||
@protocol.send_error_protocol(msg)
|
||
... | ... | |
|
||
def reply_fatal_error(msg = nil)
|
||
logger.error "Protocol error [#{identifier}]: fatal error (#{msg})"
|
||
set_error_status(true)
|
||
|
||
msg = "fatal error" + (msg ? ": " + msg : "")
|
||
@protocol.send_error_protocol(msg)
|
||
@protocol.send_error_protocol(msg, true)
|
||
end
|
||
|
||
def enter_split_mode(message)
|
Also available in: Unified diff
[evol] conversation/bot protocol rework §4 (refs #30)