2024-01-08 05:55:53 +00:00
|
|
|
open! Import
|
2024-01-21 20:04:08 +00:00
|
|
|
include Router_types
|
2024-01-08 03:28:31 +00:00
|
|
|
|
2024-01-21 20:04:08 +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)
|
|
|
|
|
2024-01-14 18:21:16 +00:00
|
|
|
let relay ~(from : user) (msg : Irc.Msg.t) tgts =
|
|
|
|
let msg =
|
|
|
|
if msg.prefix = No_prefix then
|
2024-01-21 20:04:08 +00:00
|
|
|
{ msg with prefix = User.prefix from }
|
2024-01-14 18:21:16 +00:00
|
|
|
else msg
|
|
|
|
in
|
|
|
|
let bcc u = Outbox.Bcc.add u.outbox in
|
|
|
|
let bcc_not_self u = if u != from then bcc u in
|
2024-01-21 20:04:08 +00:00
|
|
|
let bcc_channel c = List.iter bcc_not_self (Chan.members c) in
|
2024-01-14 18:21:16 +00:00
|
|
|
List.iter
|
|
|
|
(function
|
|
|
|
| `to_self -> bcc from
|
|
|
|
| `to_user tgt -> bcc tgt
|
|
|
|
| `to_chan tgt -> bcc_channel tgt
|
2024-01-21 20:04:08 +00:00
|
|
|
| `to_interested -> bcc from; List.iter bcc_channel (User.channels from))
|
2024-01-14 18:21:16 +00:00
|
|
|
tgts;
|
|
|
|
Outbox.Bcc.send_all msg
|