From c35c90fcb10f5bf7c1bc42cb8c79e0567d38246a Mon Sep 17 00:00:00 2001 From: tali Date: Thu, 25 Jan 2024 18:55:03 -0500 Subject: [PATCH] add handling +o/+v/-o/-v commands in channels --- lib/server/connection.ml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/server/connection.ml b/lib/server/connection.ml index 509da39..a2272c1 100644 --- a/lib/server/connection.ml +++ b/lib/server/connection.ml @@ -175,12 +175,12 @@ let on_get_chan_mode chan _me = ] in Ok (List.flatten rpls) -let on_set_chan_mode chan me modestr args = +let on_set_chan_mode chan me modestr args ~router = (* TODO: If is given, the user sending the command MUST have appropriate channel privileges on the target channel to change the modes given. If a user does not have appropriate privileges to change modes on the target channel, the server MUST NOT process the message, and ERR_CHANOPRIVSNEEDED (482) numeric is returned. *) - let _ = me, chan in + _todo_validation_please (); let* chg = try Ok (Mode.Parse.chan_modes modestr args) with Mode.Parse.Error -> @@ -193,7 +193,24 @@ let on_set_chan_mode chan me modestr args = set_chan_mode chan ~from:me ~add:chg.chan_modes.add ~rem:chg.chan_modes.rem; Option.iter (set_chan_key chan ~from:me) chg.chan_key; Option.iter (set_chan_limit chan ~from:me) chg.chan_limit; - (* TODO: ban/op/voice *) + + List.iter + (fun (op, mode, nick) -> + try + let user = Router.find_user router nick in + let mem = Router.membership chan user in + let priv = match mode with `o -> Router.Operator | `v -> Voice in + match op with + | `add -> + set_member_priv mem priv ~from:me + | `rem -> + if mem.mem_priv = priv then + set_member_priv mem Normal ~from:me + with Not_found -> + ()) + chg.chan_privs; + + (* TODO: ban (+b) *) Ok [] @@ -207,7 +224,7 @@ let on_msg_mode t name args = Ok (on_set_user_mode u, on_get_user_mode u) | `chan -> let c = Router.find_chan t.router name in - Ok (on_set_chan_mode c, on_get_chan_mode c) + Ok (on_set_chan_mode c ~router:t.router, on_get_chan_mode c) | `invalid -> raise Not_found with Not_found -> Error (nosuchnick name)