add member count, check +l or error on join
This commit is contained in:
parent
e7978a01f3
commit
3ab60bc4c0
|
@ -9,6 +9,7 @@ let make ~name =
|
|||
name_key = string_ci name;
|
||||
topic = None;
|
||||
members = Dllist.create ();
|
||||
member_count = 0;
|
||||
chan_mode = Mode.Set.empty;
|
||||
chan_limit = None;
|
||||
chan_key = None;
|
||||
|
@ -37,5 +38,9 @@ let membership t =
|
|||
let membership_when f t =
|
||||
Dllist.fold_r (fun m xs -> if f m then m :: xs else xs) t.members []
|
||||
|
||||
let no_members t =
|
||||
Dllist.is_empty t.members
|
||||
let is_empty t =
|
||||
t.member_count = 0
|
||||
|
||||
let is_full t = match t.chan_limit with
|
||||
| Some n -> t.member_count >= n
|
||||
| None -> false
|
||||
|
|
|
@ -63,6 +63,7 @@ let notonchannel chan = "442", [chan; "You're not on that channel"]
|
|||
let notregistered = "451", ["You have not registered"]
|
||||
let needmoreparams cmd = "461", [cmd; "Not enough parameters"]
|
||||
let alreadyregistered = "462", ["Unauthorized command (already registered)"]
|
||||
let channelisfull chan = "471", [chan; "Cannot join channel (+l)"]
|
||||
let chanoprivsneeded chan = "482", [chan; "You're not channel operator"]
|
||||
let modeunknownflag = "501", ["Didn't understand MODE command"]
|
||||
let usersdontmatch_set = "502", ["Can't change mode for other users"]
|
||||
|
@ -411,9 +412,10 @@ let on_msg_join t name =
|
|||
match Router.membership chan me with
|
||||
| _already_a_member -> Ok ()
|
||||
| exception Not_found ->
|
||||
begin
|
||||
if Chan.is_full chan then
|
||||
Error (channelisfull (Chan.name chan))
|
||||
else begin
|
||||
(* TODO: +k *)
|
||||
(* TODO: check chan user limit (+l) *)
|
||||
_todo_validation_please ();
|
||||
join t me chan;
|
||||
get_topic t chan ~reply_if_missing:false;
|
||||
|
@ -435,8 +437,7 @@ let leave t user chan ~why =
|
|||
Router.relay msg ~from:user [`to_chan chan; `to_self]
|
||||
end;
|
||||
Router.part mem;
|
||||
(* TODO: if user was op then choose a new op? *)
|
||||
if Chan.no_members chan then
|
||||
if Chan.is_empty chan then
|
||||
begin
|
||||
debug (fun m -> m "recycling empty channel %S" (Chan.name chan));
|
||||
Chan.unregister chan ~router:t.router;
|
||||
|
|
|
@ -47,6 +47,7 @@ let join chan user =
|
|||
begin
|
||||
mem.mem_in_chan <- Some (Dllist.add_r mem chan.members);
|
||||
mem.mem_in_user <- Some (Dllist.add_r mem user.membership);
|
||||
chan.member_count <- succ chan.member_count;
|
||||
mem
|
||||
end
|
||||
|
||||
|
@ -60,6 +61,7 @@ let part mem =
|
|||
Dllist.remove (Option.get mem.mem_in_chan);
|
||||
mem.mem_in_user <- None;
|
||||
mem.mem_in_chan <- None;
|
||||
mem.mem_chan.member_count <- pred mem.mem_chan.member_count;
|
||||
with Invalid_argument _ ->
|
||||
warn (fun m -> m "part (%S,%S): already removed"
|
||||
(Chan.name mem.mem_chan) (User.nick mem.mem_user))
|
||||
|
|
|
@ -17,6 +17,7 @@ and chan = {
|
|||
name_key : string_ci;
|
||||
mutable topic : string option;
|
||||
mutable members : membership Dllist.t;
|
||||
mutable member_count : int;
|
||||
mutable chan_mode : Mode.Set.t; (* +imstn *)
|
||||
mutable chan_limit : int option; (* +l *)
|
||||
mutable chan_key : string option; (* +k *)
|
||||
|
|
Loading…
Reference in New Issue