diff --git a/lib/server/connection.ml b/lib/server/connection.ml index 65f3b2c..0052d6a 100644 --- a/lib/server/connection.ml +++ b/lib/server/connection.ml @@ -61,7 +61,8 @@ let reply t (num, params) = | None -> "*" in let always_trailing = match num with - | "256" | "301" | "311" | "312" | "314" | "319" | "332" | "353" -> true + | "256" | "301" | "302" | "311" | "312" | "314" | "319" | "332" + | "353" -> true | _ -> false in Outbox.send t.outbox @@ -660,6 +661,28 @@ let on_msg_whowas t nick count = list_whowas t nick limit; Ok () +let on_msg_userhost t nicks = + let* _me = require_registered t in + let results = + List.filter_map + (fun nick -> + try + let user = match name_type nick with + | `nick -> Router.find_user t.router nick + | `chan | `invalid -> raise Not_found + in + let isaway = match User.away user with + | Some _ -> '-' + | None -> '+' + in + Some (Fmt.str "%s=%c%s" (User.nick user) isaway user.userinfo.hostname) + with Not_found -> + None) + nicks + in + reply t ("302", [String.concat " " results]); + Ok () + (* welcome and quit *) @@ -916,12 +939,12 @@ let dispatch t = function | "WHOWAS", ([] | "" :: _) -> Error nonicknamegiven | "WHOWAS", [nick] -> on_msg_whowas t nick "" | "WHOWAS", nick :: count :: _ -> on_msg_whowas t nick count + | "USERHOST", nicks -> on_msg_userhost t nicks | ("USER" | "JOIN" | "NAMES" | "PART" | "KICK" | "MODE" | "WHO") as cmd, _ -> Error (needmoreparams cmd) | ("CONNECT" | "KILL" | "REHASH" | "RESTART" | "STATS" | "SQUIT" | "WALLOPS"), _ -> Error noprivileges (* TODO: "LIST" *) - (* TODO: "USERHOST" *) | cmd, _ -> Error (unknowncommand cmd)