talircd/lib/server/router.ml

36 lines
898 B
OCaml
Raw Normal View History

2024-01-08 05:55:53 +00:00
open! Import
include Router_types
2024-01-08 03:28:31 +00:00
type t = router
2024-01-10 02:20:16 +00:00
2024-01-08 03:28:31 +00:00
let make () =
2024-01-10 02:20:16 +00:00
{ users = Hashtbl.create 4096;
channels = Hashtbl.create 4096 }
2024-01-08 03:28:31 +00:00
2024-01-22 17:48:44 +00:00
let is_nick_available t nick =
Hashtbl.mem t.users (string_ci nick)
2024-01-08 03:28:31 +00:00
let find_user t nick =
2024-01-10 02:20:16 +00:00
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