talircd/lib/server/userbase.ml

40 lines
755 B
OCaml

type privmsg = {
pm_from : string;
pm_text : string;
}
type user = {
mutable nick : string option;
inbox : notif Lwt_stream.t;
push_inbox : (notif option -> unit);
}
and notif = privmsg
let make_user () =
let inbox, push_inbox = Lwt_stream.create () in
{ nick = None; inbox; push_inbox }
let notify u no = u.push_inbox (Some no)
type t = {
users : (string, user) Hashtbl.t
(* TODO: channels *)
}
let make () =
{ users = Hashtbl.create 4096 }
let register t ~nick ~user =
if Hashtbl.mem t.users nick then
`inuse
else begin
Option.iter (Hashtbl.remove t.users) user.nick;
Hashtbl.add t.users nick user;
user.nick <- Some nick;
`ok
end
let leave t user =
Option.iter (Hashtbl.remove t.users) user.nick