talircd/lib/server/router.ml

33 lines
827 B
OCaml

open! Import
include Router_types
type t = router
let make () =
{ users = Hashtbl.create 4096;
channels = Hashtbl.create 4096 }
let find_user t nick =
Hashtbl.find t.users (string_ci nick)
let find_chan t name =
Hashtbl.find t.channels (string_ci name)
let relay ~(from : user) (msg : Irc.Msg.t) tgts =
let msg =
if msg.prefix = No_prefix then
{ msg with prefix = User.prefix from }
else msg
in
let bcc u = Outbox.Bcc.add u.outbox in
let bcc_not_self u = if u != from then bcc u in
let bcc_channel c = List.iter bcc_not_self (Chan.members c) in
List.iter
(function
| `to_self -> bcc from
| `to_user tgt -> bcc tgt
| `to_chan tgt -> bcc_channel tgt
| `to_interested -> bcc from; List.iter bcc_channel (User.channels from))
tgts;
Outbox.Bcc.send_all msg