load MOTD from file

This commit is contained in:
tali 2024-02-01 13:28:31 -05:00
parent 4cc0e8a6e1
commit 6790c22c4a
4 changed files with 40 additions and 24 deletions

View File

@ -23,6 +23,8 @@ let () =
~timestamp:(not no_timestamp) ~timestamp:(not no_timestamp)
~namespace:(not no_namespace) ~namespace:(not no_namespace)
(* TODO: s-exp/json/toml config format *)
let port = let port =
try try
let port = int_of_string (Sys.getenv "IRC_PORT") in let port = int_of_string (Sys.getenv "IRC_PORT") in
@ -36,14 +38,18 @@ let hostname =
| Some x -> x | Some x -> x
| None -> "irc.tali.software" | None -> "irc.tali.software"
let motd_file =
match Sys.getenv_opt "IRC_MOTD" with
| Some x -> x
| None -> "./motd.txt"
let config : Server.config = { let config : Server.config = {
port; port;
hostname; hostname;
listen_backlog = 8; listen_backlog = 8;
ping_interval = 60; ping_interval = 60;
whowas_history_len = 1000; whowas_history_len = 1000;
motd_file;
(* TODO: motd *)
} }
let () = let () =

View File

@ -10,7 +10,7 @@ let listener ~(port : int) ~(listen_backlog : int) : (fd * sockaddr) Lwt_stream.
let sock : fd Lwt.t = let sock : fd Lwt.t =
let fd = Lwt_unix.socket PF_INET SOCK_STREAM 0 in let fd = Lwt_unix.socket PF_INET SOCK_STREAM 0 in
Lwt_unix.setsockopt fd SO_KEEPALIVE false; Lwt_unix.setsockopt fd SO_KEEPALIVE false;
Lwt_unix.setsockopt fd SO_REUSEPORT true; Lwt_unix.setsockopt fd SO_REUSEPORT false;
let srv_adr = Unix.ADDR_INET (Unix.inet_addr_any, port) in let srv_adr = Unix.ADDR_INET (Unix.inet_addr_any, port) in
let* () = Lwt_unix.bind fd srv_adr in let* () = Lwt_unix.bind fd srv_adr in
Lwt_unix.listen fd listen_backlog; Lwt_unix.listen fd listen_backlog;
@ -98,18 +98,32 @@ type config = {
ping_interval : int; ping_interval : int;
whowas_history_len : int; whowas_history_len : int;
hostname : string; hostname : string;
(* TODO: motd *) motd_file : string;
} }
let run { port; listen_backlog; ping_interval; let run { port; listen_backlog; ping_interval; whowas_history_len;
whowas_history_len; hostname } : unit Lwt.t hostname; motd_file } : unit Lwt.t
= =
let server_info = debug (fun m -> m "ping interval:@ %ds" ping_interval);
Server_info.make debug (fun m -> m "whowas history:@ %d" whowas_history_len);
~hostname
(* ~motd *) let* motd =
let* file = Lwt_io.open_file motd_file ~mode:Input in
let* lines = Lwt_io.read_lines file |> Lwt_stream.to_list in
let+ () = Lwt_io.close file in
debug (fun m -> m "motd file:@ %d lines" (List.length lines));
lines
in in
let server_info =
Server_info.make ()
~hostname
~motd
in
info (fun m -> m "hostname:@ %s" server_info.hostname);
info (fun m -> m "version:@ %s" server_info.version);
info (fun m -> m "created:@ %s" server_info.created);
let router : Router.t = let router : Router.t =
Router.make Router.make
~whowas_history_len ~whowas_history_len

View File

@ -37,22 +37,17 @@ let default_conf = {
init_cmode = Mode.Set.of_list [`n; `s; `t]; init_cmode = Mode.Set.of_list [`n; `s; `t];
} }
let make ~hostname = { let admin_info = "the admin of this server is @iitalics@octodon.social"
version = let version = "0.0.0"
(* TODO: generate version string at build time? *) (* TODO: generate version string at build time? *)
"0.0.0";
let make ?(conf = default_conf) ~hostname ~motd () = {
version = version;
created = Fmt.str "%a" pp_time (Ptime_clock.now ()); created = Fmt.str "%a" pp_time (Ptime_clock.now ());
hostname; hostname;
admin_info = admin_info;
(* TODO: make configurable *) motd;
"the admin of this server is @iitalics@octodon.social"; conf;
motd = [
(* TODO: load from file *)
"MEOW MEOW MEOW MEOW MEOW";
"meow meow meow meow meow";
"meowmeowmeowmeowmeowmeow";
];
conf = default_conf;
} }
let prefix t = Msg.Server_prefix t.hostname let prefix t = Msg.Server_prefix t.hostname

View File

@ -3,6 +3,7 @@ Description=tali IRCd
[Service] [Service]
Environment=IRC_HOSTNAME=irc.tali.software Environment=IRC_HOSTNAME=irc.tali.software
Environment=IRC_MOTD=/usr/local/share/talircd/motd
#Environment=IRC_PORT=6667 #Environment=IRC_PORT=6667
#Environment=LOG_LEVEL=DEBUG #Environment=LOG_LEVEL=DEBUG
ExecStart=/usr/local/bin/talircd ExecStart=/usr/local/bin/talircd