op users joining a fresh channel; list user prefixes
This commit is contained in:
parent
5a463382d3
commit
b49b1db26b
|
@ -31,5 +31,8 @@ let is_registered t ~router = Hashtbl.mem router.channels t.name_key
|
|||
let members t =
|
||||
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 =
|
||||
Dllist.is_empty t.members
|
||||
|
|
|
@ -121,6 +121,22 @@ let set_chan_limit chan ~from chg =
|
|||
Router.relay msg ~from [`to_chan chan; `to_self];
|
||||
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* () = if user != me then Error usersdontmatch_get else Ok () in
|
||||
Ok [
|
||||
|
@ -233,15 +249,19 @@ let on_msg_privmsg t name txt =
|
|||
|
||||
let list_names t chan =
|
||||
let name = Chan.name chan in
|
||||
let sym =
|
||||
if Mode.Set.mem `s (Chan.mode chan)
|
||||
then "@"
|
||||
else "="
|
||||
let sym = if Mode.Set.mem `s (Chan.mode chan) then "@" else "=" in
|
||||
let mems =
|
||||
List.map
|
||||
(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
|
||||
(* 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
|
||||
(* TODO: concat member names until message becomes too long *)
|
||||
List.iter (fun nick -> reply t ("353", [sym; name; nick])) mems;
|
||||
|
@ -301,16 +321,14 @@ let on_msg_topic t name args =
|
|||
Ok ()
|
||||
|
||||
let join t user chan =
|
||||
(* TODO: check channel mode +k, +l *)
|
||||
_todo_validation_please ();
|
||||
let msg = Msg.make "JOIN" [Chan.name chan] in
|
||||
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
|
||||
begin
|
||||
(* TODO: make founder +o / +q etc. *)
|
||||
Chan.register chan ~router:t.router;
|
||||
set_chan_mode chan ~from:user ~add:t.server_info.conf.init_cmode;
|
||||
set_member_priv mem ~from:user Operator;
|
||||
end
|
||||
|
||||
let on_msg_join t name =
|
||||
|
@ -329,13 +347,16 @@ let on_msg_join t name =
|
|||
Ok (Chan.make ~name)
|
||||
in
|
||||
match Router.membership chan me with
|
||||
| _already_a_member ->
|
||||
Ok ()
|
||||
| _already_a_member -> Ok ()
|
||||
| exception Not_found ->
|
||||
join t me chan;
|
||||
get_topic t chan ~reply_if_missing:false;
|
||||
list_names t chan;
|
||||
Ok ()
|
||||
begin
|
||||
(* TODO: check channel mode +k, +l *)
|
||||
_todo_validation_please ();
|
||||
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 mem = Router.membership chan user in
|
||||
|
|
|
@ -40,13 +40,14 @@ let join chan user =
|
|||
let mem = {
|
||||
mem_chan = chan;
|
||||
mem_user = user;
|
||||
mem_priv = Normal;
|
||||
mem_in_chan = None;
|
||||
mem_in_user = None;
|
||||
} in
|
||||
begin
|
||||
mem.mem_in_chan <- Some (Dllist.add_r mem chan.members);
|
||||
mem.mem_in_user <- Some (Dllist.add_r mem user.membership);
|
||||
(* TODO: return mem? *)
|
||||
mem
|
||||
end
|
||||
|
||||
let membership chan user =
|
||||
|
|
|
@ -27,11 +27,16 @@ and chan = {
|
|||
and membership = {
|
||||
mem_user : user;
|
||||
mem_chan : chan;
|
||||
mutable mem_priv : priv;
|
||||
mutable mem_in_chan : membership Dllist.node option;
|
||||
mutable mem_in_user : membership Dllist.node option;
|
||||
(* TODO: +o/+v (?) *)
|
||||
}
|
||||
|
||||
and priv =
|
||||
| Normal
|
||||
| Voice
|
||||
| Operator
|
||||
|
||||
type router = {
|
||||
users : (string_ci, user) Hashtbl.t;
|
||||
channels : (string_ci, chan) Hashtbl.t;
|
||||
|
|
Loading…
Reference in New Issue