remove Irc. prefix from everything!!!!
This commit is contained in:
parent
aeeefeaf04
commit
b58e690cfc
|
@ -9,7 +9,7 @@ let make ~name =
|
||||||
name_key = string_ci name;
|
name_key = string_ci name;
|
||||||
topic = None;
|
topic = None;
|
||||||
members = Dllist.create ();
|
members = Dllist.create ();
|
||||||
chan_mode = Irc.Mode.Set.empty;
|
chan_mode = Mode.Set.empty;
|
||||||
chan_limit = None;
|
chan_limit = None;
|
||||||
chan_key = None;
|
chan_key = None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ type t = {
|
||||||
addr : sockaddr;
|
addr : sockaddr;
|
||||||
outbox : Outbox.t;
|
outbox : Outbox.t;
|
||||||
mutable user : User.t option;
|
mutable user : User.t option;
|
||||||
mutable pending_nick : string option;
|
mutable pending_nick : name option;
|
||||||
mutable pending_userinfo : Irc.userinfo option;
|
mutable pending_userinfo : userinfo option;
|
||||||
}
|
}
|
||||||
|
|
||||||
let make ~router ~server_info ~addr = {
|
let make ~router ~server_info ~addr = {
|
||||||
|
@ -40,7 +40,7 @@ let reply t (num, params) =
|
||||||
| None -> "*"
|
| None -> "*"
|
||||||
in
|
in
|
||||||
Outbox.send t.outbox
|
Outbox.send t.outbox
|
||||||
(Irc.Msg.make ~prefix num (target :: params))
|
(Msg.make ~prefix num (target :: params))
|
||||||
|
|
||||||
let tryagain cmd = "263", [cmd; "Please wait a while and try again."]
|
let tryagain cmd = "263", [cmd; "Please wait a while and try again."]
|
||||||
let nosuchnick tgt = "401", [tgt; "No such nick/channel"]
|
let nosuchnick tgt = "401", [tgt; "No such nick/channel"]
|
||||||
|
@ -67,29 +67,29 @@ let require_registered t : User.t result =
|
||||||
|
|
||||||
(* modes *)
|
(* modes *)
|
||||||
|
|
||||||
let set_user_mode ?(add = Irc.Mode.Set.empty) ?(rem = Irc.Mode.Set.empty) user =
|
let set_user_mode ?(add = Mode.Set.empty) ?(rem = Mode.Set.empty) user =
|
||||||
let mode, chg =
|
let mode, chg =
|
||||||
Irc.Mode.Set.normalize
|
Mode.Set.normalize
|
||||||
(User.mode user)
|
(User.mode user)
|
||||||
{ add = Irc.Mode.Set.remove `o add; rem }
|
{ add = Mode.Set.remove `o add; rem }
|
||||||
in
|
in
|
||||||
if chg <> Irc.Mode.Set.no_change then
|
if chg <> Mode.Set.no_change then
|
||||||
let modestr = Fmt.str "%a" Irc.Mode.Set.pp_change chg in
|
let modestr = Fmt.str "%a" Mode.Set.pp_change chg in
|
||||||
let msg = Irc.Msg.make "MODE" [User.nick user; modestr] in
|
let msg = Msg.make "MODE" [User.nick user; modestr] in
|
||||||
begin
|
begin
|
||||||
Router.relay msg ~from:user [`to_self];
|
Router.relay msg ~from:user [`to_self];
|
||||||
User.set_mode user mode;
|
User.set_mode user mode;
|
||||||
end
|
end
|
||||||
|
|
||||||
let set_chan_mode ~from ?(add = Irc.Mode.Set.empty) ?(rem = Irc.Mode.Set.empty) chan =
|
let set_chan_mode ~from ?(add = Mode.Set.empty) ?(rem = Mode.Set.empty) chan =
|
||||||
let mode, chg =
|
let mode, chg =
|
||||||
Irc.Mode.Set.normalize
|
Mode.Set.normalize
|
||||||
(Chan.mode chan)
|
(Chan.mode chan)
|
||||||
{ add; rem }
|
{ add; rem }
|
||||||
in
|
in
|
||||||
if chg <> Irc.Mode.Set.no_change then
|
if chg <> Mode.Set.no_change then
|
||||||
let modestr = Fmt.str "%a" Irc.Mode.Set.pp_change chg in
|
let modestr = Fmt.str "%a" Mode.Set.pp_change chg in
|
||||||
let msg = Irc.Msg.make "MODE" [Chan.name chan; modestr] in
|
let msg = Msg.make "MODE" [Chan.name chan; modestr] in
|
||||||
begin
|
begin
|
||||||
Router.relay msg ~from [`to_chan chan; `to_self];
|
Router.relay msg ~from [`to_chan chan; `to_self];
|
||||||
Chan.set_mode chan mode;
|
Chan.set_mode chan mode;
|
||||||
|
@ -97,14 +97,14 @@ let set_chan_mode ~from ?(add = Irc.Mode.Set.empty) ?(rem = Irc.Mode.Set.empty)
|
||||||
|
|
||||||
let set_chan_key chan ~from = function
|
let set_chan_key chan ~from = function
|
||||||
| `set key ->
|
| `set key ->
|
||||||
let msg = Irc.Msg.make "MODE" [Chan.name chan; "+k"; key] ~always_trailing:true in
|
let msg = Msg.make "MODE" [Chan.name chan; "+k"; key] ~always_trailing:true in
|
||||||
begin
|
begin
|
||||||
Router.relay msg ~from [`to_chan chan; `to_self];
|
Router.relay msg ~from [`to_chan chan; `to_self];
|
||||||
Chan.set_key chan (Some key);
|
Chan.set_key chan (Some key);
|
||||||
end
|
end
|
||||||
| `unset ->
|
| `unset ->
|
||||||
if Chan.key chan <> None then
|
if Chan.key chan <> None then
|
||||||
let msg = Irc.Msg.make "MODE" [Chan.name chan; "-k"; "*"] in
|
let msg = Msg.make "MODE" [Chan.name chan; "-k"; "*"] in
|
||||||
begin
|
begin
|
||||||
Router.relay msg ~from [`to_chan chan; `to_self];
|
Router.relay msg ~from [`to_chan chan; `to_self];
|
||||||
Chan.set_key chan None;
|
Chan.set_key chan None;
|
||||||
|
@ -113,14 +113,14 @@ let set_chan_key chan ~from = function
|
||||||
let set_chan_limit chan ~from = function
|
let set_chan_limit chan ~from = function
|
||||||
| `set lim ->
|
| `set lim ->
|
||||||
if Chan.limit chan <> Some lim then
|
if Chan.limit chan <> Some lim then
|
||||||
let msg = Irc.Msg.make "MODE" [Chan.name chan; "+l"; string_of_int lim] in
|
let msg = Msg.make "MODE" [Chan.name chan; "+l"; string_of_int lim] in
|
||||||
begin
|
begin
|
||||||
Router.relay msg ~from [`to_chan chan; `to_self];
|
Router.relay msg ~from [`to_chan chan; `to_self];
|
||||||
Chan.set_limit chan (Some lim);
|
Chan.set_limit chan (Some lim);
|
||||||
end
|
end
|
||||||
| `unset ->
|
| `unset ->
|
||||||
if Chan.limit chan <> None then
|
if Chan.limit chan <> None then
|
||||||
let msg = Irc.Msg.make "MODE" [Chan.name chan; "-l"] in
|
let msg = Msg.make "MODE" [Chan.name chan; "-l"] in
|
||||||
begin
|
begin
|
||||||
Router.relay msg ~from [`to_chan chan; `to_self];
|
Router.relay msg ~from [`to_chan chan; `to_self];
|
||||||
Chan.set_limit chan None;
|
Chan.set_limit chan None;
|
||||||
|
@ -129,13 +129,13 @@ let set_chan_limit chan ~from = function
|
||||||
let on_get_user_mode user me =
|
let on_get_user_mode user me =
|
||||||
let* () = if user != me then Error usersdontmatch_get else Ok () in
|
let* () = if user != me then Error usersdontmatch_get else Ok () in
|
||||||
Ok [
|
Ok [
|
||||||
"221", [Fmt.str "+%a" Irc.Mode.Set.pp (User.mode me)]
|
"221", [Fmt.str "+%a" Mode.Set.pp (User.mode me)]
|
||||||
]
|
]
|
||||||
|
|
||||||
let on_set_user_mode user me modestr _args =
|
let on_set_user_mode user me modestr _args =
|
||||||
let* () = if user == me then Ok () else Error usersdontmatch_set in
|
let* () = if user == me then Ok () else Error usersdontmatch_set in
|
||||||
let* chg = try Ok (Irc.Mode.Parse.user_modes modestr)
|
let* chg = try Ok (Mode.Parse.user_modes modestr)
|
||||||
with Irc.Mode.Parse.Error ->
|
with Mode.Parse.Error ->
|
||||||
(* TODO: "If one or more modes sent are not implemented on the server, the server
|
(* TODO: "If one or more modes sent are not implemented on the server, the server
|
||||||
MUST apply the modes that are implemented, and then send the ERR_UMODEUNKNOWNFLAG
|
MUST apply the modes that are implemented, and then send the ERR_UMODEUNKNOWNFLAG
|
||||||
(501) in reply along with the MODE message." *)
|
(501) in reply along with the MODE message." *)
|
||||||
|
@ -146,7 +146,7 @@ let on_set_user_mode user me modestr _args =
|
||||||
|
|
||||||
let on_get_chan_mode chan _me =
|
let on_get_chan_mode chan _me =
|
||||||
let rpls = [
|
let rpls = [
|
||||||
["324", [Chan.name chan; Fmt.str "+%a" Irc.Mode.Set.pp (Chan.mode chan)]];
|
["324", [Chan.name chan; Fmt.str "+%a" Mode.Set.pp (Chan.mode chan)]];
|
||||||
|
|
||||||
begin match Chan.limit chan with
|
begin match Chan.limit chan with
|
||||||
| Some lim -> ["324", [Chan.name chan; "+l"; string_of_int lim]]
|
| Some lim -> ["324", [Chan.name chan; "+l"; string_of_int lim]]
|
||||||
|
@ -170,8 +170,8 @@ let on_set_chan_mode chan me modestr args =
|
||||||
MUST NOT process the message, and ERR_CHANOPRIVSNEEDED (482) numeric is returned. *)
|
MUST NOT process the message, and ERR_CHANOPRIVSNEEDED (482) numeric is returned. *)
|
||||||
let _ = me, chan in
|
let _ = me, chan in
|
||||||
|
|
||||||
let* chg = try Ok (Irc.Mode.Parse.chan_modes modestr args)
|
let* chg = try Ok (Mode.Parse.chan_modes modestr args)
|
||||||
with Irc.Mode.Parse.Error ->
|
with Mode.Parse.Error ->
|
||||||
(* TODO: "If one or more modes sent are not implemented on the server, the server
|
(* TODO: "If one or more modes sent are not implemented on the server, the server
|
||||||
MUST apply the modes that are implemented, and then send the ERR_UMODEUNKNOWNFLAG
|
MUST apply the modes that are implemented, and then send the ERR_UMODEUNKNOWNFLAG
|
||||||
(501) in reply along with the MODE message." *)
|
(501) in reply along with the MODE message." *)
|
||||||
|
@ -189,7 +189,7 @@ let on_msg_mode t name args =
|
||||||
let* me = require_registered t in
|
let* me = require_registered t in
|
||||||
let* on_set, on_get =
|
let* on_set, on_get =
|
||||||
try
|
try
|
||||||
match Irc.name_type name with
|
match name_type name with
|
||||||
| `nick ->
|
| `nick ->
|
||||||
let u = Router.find_user t.router name in
|
let u = Router.find_user t.router name in
|
||||||
Ok (on_set_user_mode u, on_get_user_mode u)
|
Ok (on_set_user_mode u, on_get_user_mode u)
|
||||||
|
@ -215,7 +215,7 @@ let on_msg_privmsg t name txt =
|
||||||
let* me = require_registered t in
|
let* me = require_registered t in
|
||||||
let* tgt =
|
let* tgt =
|
||||||
try
|
try
|
||||||
match Irc.name_type name with
|
match name_type name with
|
||||||
| `chan -> Ok (`chan (Router.find_chan t.router name))
|
| `chan -> Ok (`chan (Router.find_chan t.router name))
|
||||||
| _ -> Ok (`user (Router.find_user t.router name))
|
| _ -> Ok (`user (Router.find_user t.router name))
|
||||||
with Not_found ->
|
with Not_found ->
|
||||||
|
@ -230,7 +230,7 @@ let on_msg_privmsg t name txt =
|
||||||
| `chan c -> Chan.name c, [`to_chan c]
|
| `chan c -> Chan.name c, [`to_chan c]
|
||||||
| `user u -> User.nick u, [`to_user u]
|
| `user u -> User.nick u, [`to_user u]
|
||||||
in
|
in
|
||||||
let msg = Irc.Msg.make "PRIVMSG" [name; txt] ~always_trailing:true in
|
let msg = Msg.make "PRIVMSG" [name; txt] ~always_trailing:true in
|
||||||
Router.relay msg ~from:me dst;
|
Router.relay msg ~from:me dst;
|
||||||
Ok ()
|
Ok ()
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ let on_msg_names t name =
|
||||||
let* _me = require_registered t in
|
let* _me = require_registered t in
|
||||||
let* chan =
|
let* chan =
|
||||||
try
|
try
|
||||||
match Irc.name_type name with
|
match name_type name with
|
||||||
| `chan -> Ok (Router.find_chan t.router name)
|
| `chan -> Ok (Router.find_chan t.router name)
|
||||||
| _ -> Error (nosuchchannel name)
|
| _ -> Error (nosuchchannel name)
|
||||||
with Not_found ->
|
with Not_found ->
|
||||||
|
@ -264,7 +264,7 @@ let join t user chan =
|
||||||
begin
|
begin
|
||||||
(* TODO: check if already a member *)
|
(* TODO: check if already a member *)
|
||||||
(* TODO: check channel mode +k, +l *)
|
(* TODO: check channel mode +k, +l *)
|
||||||
let msg = Irc.Msg.make "JOIN" [Chan.name chan] in
|
let msg = Msg.make "JOIN" [Chan.name chan] in
|
||||||
Router.relay msg ~from:user [`to_chan chan; `to_self];
|
Router.relay msg ~from:user [`to_chan chan; `to_self];
|
||||||
|
|
||||||
Router.join chan user;
|
Router.join chan user;
|
||||||
|
@ -284,7 +284,7 @@ let on_msg_join t name =
|
||||||
(* TODO: "0" parameter means part from all channels *)
|
(* TODO: "0" parameter means part from all channels *)
|
||||||
let* chan =
|
let* chan =
|
||||||
try
|
try
|
||||||
match Irc.name_type name with
|
match name_type name with
|
||||||
| `chan -> Ok (Router.find_chan t.router name)
|
| `chan -> Ok (Router.find_chan t.router name)
|
||||||
| _ -> Error (nosuchchannel name)
|
| _ -> Error (nosuchchannel name)
|
||||||
with Not_found ->
|
with Not_found ->
|
||||||
|
@ -305,7 +305,7 @@ let part t user chan ~reason =
|
||||||
begin
|
begin
|
||||||
let always_trailing = Option.is_some reason in
|
let always_trailing = Option.is_some reason in
|
||||||
let reason = Option.to_list reason in
|
let reason = Option.to_list reason in
|
||||||
let msg = Irc.Msg.make "PART" (Chan.name chan :: reason) ~always_trailing in
|
let msg = Msg.make "PART" (Chan.name chan :: reason) ~always_trailing in
|
||||||
Router.relay msg ~from:user [`to_chan chan; `to_self];
|
Router.relay msg ~from:user [`to_chan chan; `to_self];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ let on_msg_part t name reason =
|
||||||
let* me = require_registered t in
|
let* me = require_registered t in
|
||||||
let* chan =
|
let* chan =
|
||||||
try
|
try
|
||||||
match Irc.name_type name with
|
match name_type name with
|
||||||
| `chan -> Ok (Router.find_chan t.router name)
|
| `chan -> Ok (Router.find_chan t.router name)
|
||||||
| `nick | `invalid -> raise Not_found
|
| `nick | `invalid -> raise Not_found
|
||||||
with Not_found ->
|
with Not_found ->
|
||||||
|
@ -344,12 +344,12 @@ let on_msg_part t name reason =
|
||||||
(* welcome and quit *)
|
(* welcome and quit *)
|
||||||
|
|
||||||
let about t me =
|
let about t me =
|
||||||
let who = Irc.Msg.prefix_string (User.prefix me) in
|
let who = Msg.prefix_string (User.prefix me) in
|
||||||
let s_hostname = Server_info.hostname t.server_info in
|
let s_hostname = Server_info.hostname t.server_info in
|
||||||
let s_version = Server_info.version t.server_info in
|
let s_version = Server_info.version t.server_info in
|
||||||
let s_created = Server_info.created t.server_info in
|
let s_created = Server_info.created t.server_info in
|
||||||
let conf = Server_info.conf t.server_info in
|
let conf = Server_info.conf t.server_info in
|
||||||
let modes l = String.of_seq (List.to_seq l |> Seq.map Irc.Mode.to_char) in
|
let modes l = String.of_seq (List.to_seq l |> Seq.map Mode.to_char) in
|
||||||
let umodes = modes conf.all_umodes in
|
let umodes = modes conf.all_umodes in
|
||||||
let cmodes = modes conf.all_cmodes in
|
let cmodes = modes conf.all_cmodes in
|
||||||
let pmodes = modes conf.all_pmodes in
|
let pmodes = modes conf.all_pmodes in
|
||||||
|
@ -383,7 +383,7 @@ let on_msg_motd t =
|
||||||
|
|
||||||
let quit t me ~reason =
|
let quit t me ~reason =
|
||||||
begin
|
begin
|
||||||
let msg = Irc.Msg.make "QUIT" [User.nick me; reason] ~always_trailing:true in
|
let msg = Msg.make "QUIT" [User.nick me; reason] ~always_trailing:true in
|
||||||
Router.relay msg ~from:me [`to_interested];
|
Router.relay msg ~from:me [`to_interested];
|
||||||
|
|
||||||
User.unregister me ~router:t.router;
|
User.unregister me ~router:t.router;
|
||||||
|
@ -431,7 +431,7 @@ let user_set_nick t me nick =
|
||||||
Error (nicknameinuse nick)
|
Error (nicknameinuse nick)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
let msg = Irc.Msg.make "NICK" [nick] in
|
let msg = Msg.make "NICK" [nick] in
|
||||||
Router.relay msg ~from:me [`to_interested];
|
Router.relay msg ~from:me [`to_interested];
|
||||||
User.unregister me ~router:t.router;
|
User.unregister me ~router:t.router;
|
||||||
User.set_nick me nick;
|
User.set_nick me nick;
|
||||||
|
@ -441,7 +441,7 @@ let user_set_nick t me nick =
|
||||||
|
|
||||||
let on_msg_nick t nick =
|
let on_msg_nick t nick =
|
||||||
let* () =
|
let* () =
|
||||||
match Irc.name_type nick with
|
match name_type nick with
|
||||||
| `nick -> Ok ()
|
| `nick -> Ok ()
|
||||||
| `chan | `invalid -> Error (erroneusnickname nick)
|
| `chan | `invalid -> Error (erroneusnickname nick)
|
||||||
in
|
in
|
||||||
|
@ -498,7 +498,7 @@ let split_command_params cmd params =
|
||||||
let pp_args ppf (cmd, params) =
|
let pp_args ppf (cmd, params) =
|
||||||
Fmt.pf ppf "@[%s@ %a@]" cmd (Fmt.list (Fmt.fmt "%S") ~sep:Fmt.sp) params
|
Fmt.pf ppf "@[%s@ %a@]" cmd (Fmt.list (Fmt.fmt "%S") ~sep:Fmt.sp) params
|
||||||
|
|
||||||
let on_msg t (msg : Irc.Msg.t) : unit =
|
let on_msg t (msg : Msg.t) : unit =
|
||||||
split_command_params msg.command msg.params |>
|
split_command_params msg.command msg.params |>
|
||||||
List.iter
|
List.iter
|
||||||
(fun args ->
|
(fun args ->
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
include Irc
|
||||||
module Dllist = Lwt_dllist
|
module Dllist = Lwt_dllist
|
||||||
|
|
||||||
type sockaddr = Unix.sockaddr
|
type sockaddr = Unix.sockaddr
|
||||||
|
|
|
@ -3,8 +3,8 @@ open! Import
|
||||||
(* include (val Logging.sublogs logger "Outbox") *)
|
(* include (val Logging.sublogs logger "Outbox") *)
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
stream : Irc.Msg.t Lwt_stream.t;
|
stream : Msg.t Lwt_stream.t;
|
||||||
push : Irc.Msg.t option -> unit;
|
push : Msg.t option -> unit;
|
||||||
mutable bcc_incl : bool;
|
mutable bcc_incl : bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ let find_user t nick =
|
||||||
let find_chan t name =
|
let find_chan t name =
|
||||||
Hashtbl.find t.channels (string_ci name)
|
Hashtbl.find t.channels (string_ci name)
|
||||||
|
|
||||||
let relay ~(from : user) (msg : Irc.Msg.t) tgts =
|
let relay ~(from : user) (msg : Msg.t) tgts =
|
||||||
let msg =
|
let msg =
|
||||||
if msg.prefix = No_prefix then
|
if msg.prefix = No_prefix then
|
||||||
{ msg with prefix = User.prefix from }
|
{ msg with prefix = User.prefix from }
|
||||||
|
|
|
@ -5,19 +5,19 @@ let string_ci s = Case_insensitive (String.lowercase_ascii s)
|
||||||
|
|
||||||
type user = {
|
type user = {
|
||||||
outbox : Outbox.t;
|
outbox : Outbox.t;
|
||||||
userinfo : Irc.userinfo;
|
userinfo : userinfo;
|
||||||
mutable nick : Irc.name;
|
mutable nick : name;
|
||||||
mutable nick_key : string_ci;
|
mutable nick_key : string_ci;
|
||||||
mutable user_mode : Irc.Mode.Set.t;
|
mutable user_mode : Mode.Set.t;
|
||||||
mutable membership : membership Dllist.t;
|
mutable membership : membership Dllist.t;
|
||||||
}
|
}
|
||||||
|
|
||||||
and chan = {
|
and chan = {
|
||||||
name : Irc.name;
|
name : name;
|
||||||
name_key : string_ci;
|
name_key : string_ci;
|
||||||
mutable topic : string option;
|
mutable topic : string option;
|
||||||
mutable members : membership Dllist.t;
|
mutable members : membership Dllist.t;
|
||||||
mutable chan_mode : Irc.Mode.Set.t; (* +imstn *)
|
mutable chan_mode : Mode.Set.t; (* +imstn *)
|
||||||
mutable chan_limit : int option; (* +l *)
|
mutable chan_limit : int option; (* +l *)
|
||||||
mutable chan_key : string option; (* +k *)
|
mutable chan_key : string option; (* +k *)
|
||||||
(* TODO: +b *)
|
(* TODO: +b *)
|
||||||
|
|
|
@ -18,10 +18,10 @@ let listener ~(port : int) ~(backlog : int) : (fd * sockaddr) Lwt_stream.t =
|
||||||
let accept () = sock >>= Lwt_unix.accept >|= Option.some in
|
let accept () = sock >>= Lwt_unix.accept >|= Option.some in
|
||||||
Lwt_stream.from accept
|
Lwt_stream.from accept
|
||||||
|
|
||||||
let reader (fd : fd) : Irc.Msg.t Lwt_stream.t =
|
let reader (fd : fd) : Msg.t Lwt_stream.t =
|
||||||
let chunk = Buffer.create 512 in
|
let chunk = Buffer.create 512 in
|
||||||
let rdbuf = Bytes.create 512 in
|
let rdbuf = Bytes.create 512 in
|
||||||
let gets () : Irc.Msg.t list option Lwt.t =
|
let gets () : Msg.t list option Lwt.t =
|
||||||
Lwt.catch
|
Lwt.catch
|
||||||
(fun () ->
|
(fun () ->
|
||||||
Lwt_unix.read fd rdbuf 0 (Bytes.length rdbuf) >>= function
|
Lwt_unix.read fd rdbuf 0 (Bytes.length rdbuf) >>= function
|
||||||
|
@ -29,7 +29,7 @@ let reader (fd : fd) : Irc.Msg.t Lwt_stream.t =
|
||||||
| n ->
|
| n ->
|
||||||
Buffer.add_subbytes chunk rdbuf 0 n;
|
Buffer.add_subbytes chunk rdbuf 0 n;
|
||||||
(* if Buffer.length chunk > 200_000 then panic *)
|
(* if Buffer.length chunk > 200_000 then panic *)
|
||||||
let msgs, rest = Irc.Msg.parse (Buffer.contents chunk) in
|
let msgs, rest = Msg.parse (Buffer.contents chunk) in
|
||||||
Buffer.clear chunk;
|
Buffer.clear chunk;
|
||||||
Buffer.add_string chunk rest;
|
Buffer.add_string chunk rest;
|
||||||
Lwt.return_some msgs)
|
Lwt.return_some msgs)
|
||||||
|
@ -39,7 +39,7 @@ let reader (fd : fd) : Irc.Msg.t Lwt_stream.t =
|
||||||
in
|
in
|
||||||
Lwt_stream.from gets |> Lwt_stream.map_list Fun.id
|
Lwt_stream.from gets |> Lwt_stream.map_list Fun.id
|
||||||
|
|
||||||
let writer (fd : fd) (obox : Irc.Msg.t Lwt_stream.t) : unit Lwt.t =
|
let writer (fd : fd) (obox : Msg.t Lwt_stream.t) : unit Lwt.t =
|
||||||
let rec writeall bs i =
|
let rec writeall bs i =
|
||||||
if i >= Bytes.length bs then
|
if i >= Bytes.length bs then
|
||||||
Lwt.return_unit
|
Lwt.return_unit
|
||||||
|
@ -50,7 +50,7 @@ let writer (fd : fd) (obox : Irc.Msg.t Lwt_stream.t) : unit Lwt.t =
|
||||||
let buf = Buffer.create 512 in
|
let buf = Buffer.create 512 in
|
||||||
let on_msg msg =
|
let on_msg msg =
|
||||||
Buffer.clear buf;
|
Buffer.clear buf;
|
||||||
Irc.Msg.write buf msg;
|
Msg.write buf msg;
|
||||||
writeall (Buffer.to_bytes buf) 0
|
writeall (Buffer.to_bytes buf) 0
|
||||||
in
|
in
|
||||||
Lwt.catch
|
Lwt.catch
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
open! Import
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
hostname : string;
|
hostname : string;
|
||||||
created : string;
|
created : string;
|
||||||
|
@ -7,11 +9,11 @@ type t = {
|
||||||
|
|
||||||
and conf = {
|
and conf = {
|
||||||
isupport : string list;
|
isupport : string list;
|
||||||
all_umodes : Irc.Mode.user list;
|
all_umodes : Mode.user list;
|
||||||
all_cmodes : Irc.Mode.chan_d list;
|
all_cmodes : Mode.chan_d list;
|
||||||
all_pmodes : [Irc.Mode.chan_a | Irc.Mode.chan_b | Irc.Mode.chan_c] list;
|
all_pmodes : [Mode.chan_a | Mode.chan_b | Mode.chan_c] list;
|
||||||
init_umode : Irc.Mode.Set.t;
|
init_umode : Mode.Set.t;
|
||||||
init_cmode : Irc.Mode.Set.t;
|
init_cmode : Mode.Set.t;
|
||||||
}
|
}
|
||||||
|
|
||||||
let isupport = [
|
let isupport = [
|
||||||
|
@ -27,8 +29,8 @@ let default_conf = {
|
||||||
all_umodes = [`i; `o; `w];
|
all_umodes = [`i; `o; `w];
|
||||||
all_cmodes = [`i; `m; `n; `s; `t];
|
all_cmodes = [`i; `m; `n; `s; `t];
|
||||||
all_pmodes = [`b; `k; `l; `o; `v];
|
all_pmodes = [`b; `k; `l; `o; `v];
|
||||||
init_umode = Irc.Mode.Set.of_list [`i; `w];
|
init_umode = Mode.Set.of_list [`i; `w];
|
||||||
init_cmode = Irc.Mode.Set.of_list [`n; `s; `t];
|
init_cmode = Mode.Set.of_list [`n; `s; `t];
|
||||||
}
|
}
|
||||||
|
|
||||||
let make ~hostname = {
|
let make ~hostname = {
|
||||||
|
@ -50,7 +52,7 @@ let version (_ : t) =
|
||||||
"0.0.0"
|
"0.0.0"
|
||||||
|
|
||||||
let hostname t = t.hostname
|
let hostname t = t.hostname
|
||||||
let prefix t = Irc.Msg.Server_prefix t.hostname
|
let prefix t = Msg.Server_prefix t.hostname
|
||||||
let created t = t.created
|
let created t = t.created
|
||||||
let motd t = t.motd
|
let motd t = t.motd
|
||||||
let conf t = t.conf
|
let conf t = t.conf
|
||||||
|
|
Loading…
Reference in New Issue