From 8348f2dc1faf6c27038e84a7d305fef3aed6edfb Mon Sep 17 00:00:00 2001 From: tali Date: Tue, 30 Jan 2024 21:37:30 -0500 Subject: [PATCH] respond to client PING messages --- lib/server/connection.ml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/server/connection.ml b/lib/server/connection.ml index 1cb3227..35f90e7 100644 --- a/lib/server/connection.ml +++ b/lib/server/connection.ml @@ -541,6 +541,21 @@ let on_msg_motd t = motd t; Ok () +let on_msg_ping t token = + let* _me = require_registered t in + match token with + | None -> Ok () + | Some token -> + let prefix = Server_info.prefix t.server_info in + Outbox.send t.outbox + (Msg.make ~prefix "PONG" [t.server_info.hostname; token] + ~always_trailing:true); + Ok () + +let on_msg_pong t _token = + let* _me = require_registered t in + Ok () + let welcome t me = let whoami = Msg.prefix_string (User.prefix me) in let s_hostname = t.server_info.hostname in @@ -655,6 +670,8 @@ let dispatch t = function | "USER", unm :: _ :: _ :: rnm :: _ -> on_msg_user t unm rnm | "QUIT", reason -> on_msg_quit t (concat_args reason) | "MOTD", _ -> on_msg_motd t + | "PING", args -> on_msg_ping t (concat_args args) + | "PONG", args -> on_msg_pong t (concat_args args) | "PRIVMSG", ([] | "" :: _) -> Error norecipient | "PRIVMSG", ([_] | _ :: "" :: _) -> Error notexttosend | "PRIVMSG", tgt :: msg :: _ -> on_msg_privmsg t tgt msg