Try to handle pings better

- Send a pong anyway if no ping request was detected after 120s
- (ramenkan) minor text adjustments
trunk
mio 2022-04-04 04:31:52 +00:00
parent e9927fb1d7
commit 971b758524
2 changed files with 13 additions and 2 deletions

View File

@ -15,7 +15,7 @@ ramen.noodle_shapes = {
}
ramen.broths = {
"miso", "spicy miso", "soy sauce", "grilled soy sauce and Rishiri kelp",
"miso", "spicy miso", "soy sauce", "soy sauce and grilled Rishiri kelp",
"salt", "salt and soy sauce",
}
@ -393,6 +393,7 @@ itte_config = {
-- Custom variables
itte_config.ramen = ramen
itte_config.messages.announce = "Now serving! "
itte_config.messages.serve = "{{ramen}} ⊂(・▽・⊂)"
itte_config.messages.special = "**SPECIAL!!!** {{ramen}} " ..
"☆*:・゚ o(^ ∀ ^ o)"
@ -428,7 +429,7 @@ function h.ramen(cxt, msg)
-- Scheduled task recipients
if msg.recipients ~= nil then
recipients = msg.recipients
intro = "Now serving! "
intro = itte_config.messages.announce
end
-- 1% chance of special set

View File

@ -294,6 +294,7 @@ function itte.init_socket(name, svr)
cap_checked = false,
ns_checked = false,
authed = false,
ping_time = 0,
}
-- Connect
@ -836,6 +837,7 @@ function itte.listen(name, str)
-- Respond to server ping
if util.is_substr(str, cxt.cmds.ping.check) then
cxt.state.ping_time = os.time()
util.debug(itte.config.debugs.listen[1], str, itte.config.debug)
itte.send_command(cxt.con, string.gsub(str, cxt.cmds.ping.check,
cxt.cmds.ping.resp))
@ -880,9 +882,17 @@ itte.docs.add_listener = [[ (context_table)
]]
function itte.add_listener(cxt)
local data, status = cxt.con:receive()
local delta = os.time() - cxt.state.ping_time
if data ~= nil then
itte.listen(cxt.name, data)
-- Send a pong every 120s in case the ping request was lost, e.g. during high
-- system load. Servers may send a ping request every ~90s. Disconnects from
-- ping timeouts occur at ~2m30s.
elseif (cxt.state.ping_time > 0) and (delta > 120) then
itte.send_command(cxt.con, cxt.cmds.ping.resp)
cxt.state.ping_time = os.time()
elseif status == "closed" then
itte.disconnect_server(cxt.name)
end