diff --git a/examples/ramenkan/ramenkan.config.lua b/examples/ramenkan/ramenkan.config.lua index 9d56713..aa75da4 100644 --- a/examples/ramenkan/ramenkan.config.lua +++ b/examples/ramenkan/ramenkan.config.lua @@ -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 diff --git a/itte.lua b/itte.lua index f6be9fa..de80eb2 100644 --- a/itte.lua +++ b/itte.lua @@ -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