remove Irc. prefix from everything!!!!

This commit is contained in:
tali 2024-01-23 14:23:45 -05:00
parent aeeefeaf04
commit b58e690cfc
8 changed files with 63 additions and 60 deletions

View File

@ -9,7 +9,7 @@ let make ~name =
name_key = string_ci name;
topic = None;
members = Dllist.create ();
chan_mode = Irc.Mode.Set.empty;
chan_mode = Mode.Set.empty;
chan_limit = None;
chan_key = None;
}

View File

@ -9,8 +9,8 @@ type t = {
addr : sockaddr;
outbox : Outbox.t;
mutable user : User.t option;
mutable pending_nick : string option;
mutable pending_userinfo : Irc.userinfo option;
mutable pending_nick : name option;
mutable pending_userinfo : userinfo option;
}
let make ~router ~server_info ~addr = {
@ -40,7 +40,7 @@ let reply t (num, params) =
| None -> "*"
in
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 nosuchnick tgt = "401", [tgt; "No such nick/channel"]
@ -67,29 +67,29 @@ let require_registered t : User.t result =
(* 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 =
Irc.Mode.Set.normalize
Mode.Set.normalize
(User.mode user)
{ add = Irc.Mode.Set.remove `o add; rem }
{ add = Mode.Set.remove `o add; rem }
in
if chg <> Irc.Mode.Set.no_change then
let modestr = Fmt.str "%a" Irc.Mode.Set.pp_change chg in
let msg = Irc.Msg.make "MODE" [User.nick user; modestr] in
if chg <> Mode.Set.no_change then
let modestr = Fmt.str "%a" Mode.Set.pp_change chg in
let msg = Msg.make "MODE" [User.nick user; modestr] in
begin
Router.relay msg ~from:user [`to_self];
User.set_mode user mode;
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 =
Irc.Mode.Set.normalize
Mode.Set.normalize
(Chan.mode chan)
{ add; rem }
in
if chg <> Irc.Mode.Set.no_change then
let modestr = Fmt.str "%a" Irc.Mode.Set.pp_change chg in
let msg = Irc.Msg.make "MODE" [Chan.name chan; modestr] in
if chg <> Mode.Set.no_change then
let modestr = Fmt.str "%a" Mode.Set.pp_change chg in
let msg = Msg.make "MODE" [Chan.name chan; modestr] in
begin
Router.relay msg ~from [`to_chan chan; `to_self];
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
| `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
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_key chan (Some key);
end
| `unset ->
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
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_key chan None;
@ -113,14 +113,14 @@ let set_chan_key chan ~from = function
let set_chan_limit chan ~from = function
| `set lim ->
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
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_limit chan (Some lim);
end
| `unset ->
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
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_limit chan None;
@ -129,13 +129,13 @@ let set_chan_limit chan ~from = function
let on_get_user_mode user me =
let* () = if user != me then Error usersdontmatch_get else Ok () in
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* () = if user == me then Ok () else Error usersdontmatch_set in
let* chg = try Ok (Irc.Mode.Parse.user_modes modestr)
with Irc.Mode.Parse.Error ->
let* chg = try Ok (Mode.Parse.user_modes modestr)
with Mode.Parse.Error ->
(* 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
(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 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
| 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. *)
let _ = me, chan in
let* chg = try Ok (Irc.Mode.Parse.chan_modes modestr args)
with Irc.Mode.Parse.Error ->
let* chg = try Ok (Mode.Parse.chan_modes modestr args)
with Mode.Parse.Error ->
(* 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
(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* on_set, on_get =
try
match Irc.name_type name with
match name_type name with
| `nick ->
let u = Router.find_user t.router name in
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* tgt =
try
match Irc.name_type name with
match name_type name with
| `chan -> Ok (`chan (Router.find_chan t.router name))
| _ -> Ok (`user (Router.find_user t.router name))
with Not_found ->
@ -230,7 +230,7 @@ let on_msg_privmsg t name txt =
| `chan c -> Chan.name c, [`to_chan c]
| `user u -> User.nick u, [`to_user u]
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;
Ok ()
@ -250,7 +250,7 @@ let on_msg_names t name =
let* _me = require_registered t in
let* chan =
try
match Irc.name_type name with
match name_type name with
| `chan -> Ok (Router.find_chan t.router name)
| _ -> Error (nosuchchannel name)
with Not_found ->
@ -264,7 +264,7 @@ let join t user chan =
begin
(* TODO: check if already a member *)
(* 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.join chan user;
@ -284,7 +284,7 @@ let on_msg_join t name =
(* TODO: "0" parameter means part from all channels *)
let* chan =
try
match Irc.name_type name with
match name_type name with
| `chan -> Ok (Router.find_chan t.router name)
| _ -> Error (nosuchchannel name)
with Not_found ->
@ -305,7 +305,7 @@ let part t user chan ~reason =
begin
let always_trailing = Option.is_some 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];
end;
@ -328,7 +328,7 @@ let on_msg_part t name reason =
let* me = require_registered t in
let* chan =
try
match Irc.name_type name with
match name_type name with
| `chan -> Ok (Router.find_chan t.router name)
| `nick | `invalid -> raise Not_found
with Not_found ->
@ -344,12 +344,12 @@ let on_msg_part t name reason =
(* welcome and quit *)
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_version = Server_info.version t.server_info in
let s_created = Server_info.created 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 cmodes = modes conf.all_cmodes in
let pmodes = modes conf.all_pmodes in
@ -383,7 +383,7 @@ let on_msg_motd t =
let quit t me ~reason =
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];
User.unregister me ~router:t.router;
@ -431,7 +431,7 @@ let user_set_nick t me nick =
Error (nicknameinuse nick)
else
begin
let msg = Irc.Msg.make "NICK" [nick] in
let msg = Msg.make "NICK" [nick] in
Router.relay msg ~from:me [`to_interested];
User.unregister me ~router:t.router;
User.set_nick me nick;
@ -441,7 +441,7 @@ let user_set_nick t me nick =
let on_msg_nick t nick =
let* () =
match Irc.name_type nick with
match name_type nick with
| `nick -> Ok ()
| `chan | `invalid -> Error (erroneusnickname nick)
in
@ -498,7 +498,7 @@ let split_command_params cmd params =
let pp_args ppf (cmd, 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 |>
List.iter
(fun args ->

View File

@ -1,3 +1,4 @@
include Irc
module Dllist = Lwt_dllist
type sockaddr = Unix.sockaddr

View File

@ -3,8 +3,8 @@ open! Import
(* include (val Logging.sublogs logger "Outbox") *)
type t = {
stream : Irc.Msg.t Lwt_stream.t;
push : Irc.Msg.t option -> unit;
stream : Msg.t Lwt_stream.t;
push : Msg.t option -> unit;
mutable bcc_incl : bool;
}

View File

@ -18,7 +18,7 @@ let find_user t nick =
let find_chan t 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 =
if msg.prefix = No_prefix then
{ msg with prefix = User.prefix from }

View File

@ -5,19 +5,19 @@ let string_ci s = Case_insensitive (String.lowercase_ascii s)
type user = {
outbox : Outbox.t;
userinfo : Irc.userinfo;
mutable nick : Irc.name;
userinfo : userinfo;
mutable nick : name;
mutable nick_key : string_ci;
mutable user_mode : Irc.Mode.Set.t;
mutable user_mode : Mode.Set.t;
mutable membership : membership Dllist.t;
}
and chan = {
name : Irc.name;
name : name;
name_key : string_ci;
mutable topic : string option;
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_key : string option; (* +k *)
(* TODO: +b *)

View File

@ -18,10 +18,10 @@ let listener ~(port : int) ~(backlog : int) : (fd * sockaddr) Lwt_stream.t =
let accept () = sock >>= Lwt_unix.accept >|= Option.some in
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 rdbuf = Bytes.create 512 in
let gets () : Irc.Msg.t list option Lwt.t =
let gets () : Msg.t list option Lwt.t =
Lwt.catch
(fun () ->
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 ->
Buffer.add_subbytes chunk rdbuf 0 n;
(* 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.add_string chunk rest;
Lwt.return_some msgs)
@ -39,7 +39,7 @@ let reader (fd : fd) : Irc.Msg.t Lwt_stream.t =
in
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 =
if i >= Bytes.length bs then
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 on_msg msg =
Buffer.clear buf;
Irc.Msg.write buf msg;
Msg.write buf msg;
writeall (Buffer.to_bytes buf) 0
in
Lwt.catch

View File

@ -1,3 +1,5 @@
open! Import
type t = {
hostname : string;
created : string;
@ -7,11 +9,11 @@ type t = {
and conf = {
isupport : string list;
all_umodes : Irc.Mode.user list;
all_cmodes : Irc.Mode.chan_d list;
all_pmodes : [Irc.Mode.chan_a | Irc.Mode.chan_b | Irc.Mode.chan_c] list;
init_umode : Irc.Mode.Set.t;
init_cmode : Irc.Mode.Set.t;
all_umodes : Mode.user list;
all_cmodes : Mode.chan_d list;
all_pmodes : [Mode.chan_a | Mode.chan_b | Mode.chan_c] list;
init_umode : Mode.Set.t;
init_cmode : Mode.Set.t;
}
let isupport = [
@ -27,8 +29,8 @@ let default_conf = {
all_umodes = [`i; `o; `w];
all_cmodes = [`i; `m; `n; `s; `t];
all_pmodes = [`b; `k; `l; `o; `v];
init_umode = Irc.Mode.Set.of_list [`i; `w];
init_cmode = Irc.Mode.Set.of_list [`n; `s; `t];
init_umode = Mode.Set.of_list [`i; `w];
init_cmode = Mode.Set.of_list [`n; `s; `t];
}
let make ~hostname = {
@ -50,7 +52,7 @@ let version (_ : t) =
"0.0.0"
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 motd t = t.motd
let conf t = t.conf