op users joining a fresh channel; list user prefixes

This commit is contained in:
tali 2024-01-24 13:17:59 -05:00
parent 5a463382d3
commit b49b1db26b
4 changed files with 50 additions and 20 deletions

View File

@ -31,5 +31,8 @@ let is_registered t ~router = Hashtbl.mem router.channels t.name_key
let members t = let members t =
Dllist.fold_r (fun m xs -> m.mem_user :: xs) t.members [] Dllist.fold_r (fun m xs -> m.mem_user :: xs) t.members []
let membership t =
Dllist.fold_r (fun m xs -> m :: xs) t.members []
let no_members t = let no_members t =
Dllist.is_empty t.members Dllist.is_empty t.members

View File

@ -121,6 +121,22 @@ let set_chan_limit chan ~from chg =
Router.relay msg ~from [`to_chan chan; `to_self]; Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_limit chan limit Chan.set_limit chan limit
let set_member_priv ~from (mem : Router.membership) (priv : Router.priv) =
let user = mem.mem_user in
let chan = mem.mem_chan in
(* let user = (mem : Router.membership).mem_user in *)
let modestr = match mem.mem_priv, priv with
| _, Voice -> "+v"
| _, Operator -> "+o"
| Voice, Normal -> "-v"
| Operator, Normal -> "-o"
| _, _ -> ""
in
if mem.mem_priv <> priv then
let msg = Msg.make "MODE" [Chan.name chan; modestr; User.nick user] in
Router.relay msg ~from [`to_chan chan; `to_self];
mem.mem_priv <- priv
let on_get_user_mode user me = let on_get_user_mode user me =
let* () = if user != me then Error usersdontmatch_get else Ok () in let* () = if user != me then Error usersdontmatch_get else Ok () in
Ok [ Ok [
@ -233,15 +249,19 @@ let on_msg_privmsg t name txt =
let list_names t chan = let list_names t chan =
let name = Chan.name chan in let name = Chan.name chan in
let sym = let sym = if Mode.Set.mem `s (Chan.mode chan) then "@" else "=" in
if Mode.Set.mem `s (Chan.mode chan) let mems =
then "@" List.map
else "=" (fun (m : Router.membership) ->
let nick = User.nick m.mem_user in
(* TODO: dont list users who are +i if you are not a member w/ them *)
_todo_validation_please ();
match m.mem_priv with
| Normal -> nick
| Voice -> "+" ^ nick
| Operator -> "@" ^ nick)
(Chan.membership chan)
in in
(* TODO: dont list users who are +i if you are not a member w/ them *)
_todo_validation_please ();
(* TODO: user membership prefix (@/+) *)
let mems = List.map User.nick (Chan.members chan) in
begin begin
(* TODO: concat member names until message becomes too long *) (* TODO: concat member names until message becomes too long *)
List.iter (fun nick -> reply t ("353", [sym; name; nick])) mems; List.iter (fun nick -> reply t ("353", [sym; name; nick])) mems;
@ -301,16 +321,14 @@ let on_msg_topic t name args =
Ok () Ok ()
let join t user chan = let join t user chan =
(* TODO: check channel mode +k, +l *)
_todo_validation_please ();
let msg = Msg.make "JOIN" [Chan.name chan] in let msg = Msg.make "JOIN" [Chan.name chan] in
Router.relay msg ~from:user [`to_chan chan; `to_self]; Router.relay msg ~from:user [`to_chan chan; `to_self];
Router.join chan user; let mem = Router.join chan user in
if not (Chan.is_registered chan ~router:t.router) then if not (Chan.is_registered chan ~router:t.router) then
begin begin
(* TODO: make founder +o / +q etc. *)
Chan.register chan ~router:t.router; Chan.register chan ~router:t.router;
set_chan_mode chan ~from:user ~add:t.server_info.conf.init_cmode; set_chan_mode chan ~from:user ~add:t.server_info.conf.init_cmode;
set_member_priv mem ~from:user Operator;
end end
let on_msg_join t name = let on_msg_join t name =
@ -329,13 +347,16 @@ let on_msg_join t name =
Ok (Chan.make ~name) Ok (Chan.make ~name)
in in
match Router.membership chan me with match Router.membership chan me with
| _already_a_member -> | _already_a_member -> Ok ()
Ok ()
| exception Not_found -> | exception Not_found ->
join t me chan; begin
get_topic t chan ~reply_if_missing:false; (* TODO: check channel mode +k, +l *)
list_names t chan; _todo_validation_please ();
Ok () join t me chan;
get_topic t chan ~reply_if_missing:false;
list_names t chan;
Ok ()
end
let leave t user chan ~why = let leave t user chan ~why =
let mem = Router.membership chan user in let mem = Router.membership chan user in

View File

@ -40,13 +40,14 @@ let join chan user =
let mem = { let mem = {
mem_chan = chan; mem_chan = chan;
mem_user = user; mem_user = user;
mem_priv = Normal;
mem_in_chan = None; mem_in_chan = None;
mem_in_user = None; mem_in_user = None;
} in } in
begin begin
mem.mem_in_chan <- Some (Dllist.add_r mem chan.members); mem.mem_in_chan <- Some (Dllist.add_r mem chan.members);
mem.mem_in_user <- Some (Dllist.add_r mem user.membership); mem.mem_in_user <- Some (Dllist.add_r mem user.membership);
(* TODO: return mem? *) mem
end end
let membership chan user = let membership chan user =

View File

@ -27,11 +27,16 @@ and chan = {
and membership = { and membership = {
mem_user : user; mem_user : user;
mem_chan : chan; mem_chan : chan;
mutable mem_priv : priv;
mutable mem_in_chan : membership Dllist.node option; mutable mem_in_chan : membership Dllist.node option;
mutable mem_in_user : membership Dllist.node option; mutable mem_in_user : membership Dllist.node option;
(* TODO: +o/+v (?) *)
} }
and priv =
| Normal
| Voice
| Operator
type router = { type router = {
users : (string_ci, user) Hashtbl.t; users : (string_ci, user) Hashtbl.t;
channels : (string_ci, chan) Hashtbl.t; channels : (string_ci, chan) Hashtbl.t;