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

View File

@ -10,7 +10,7 @@ let listener ~(port : int) ~(listen_backlog : int) : (fd * sockaddr) Lwt_stream.
let sock : fd Lwt.t =
let fd = Lwt_unix.socket PF_INET SOCK_STREAM 0 in
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* () = Lwt_unix.bind fd srv_adr in
Lwt_unix.listen fd listen_backlog;
@ -98,18 +98,32 @@ type config = {
ping_interval : int;
whowas_history_len : int;
hostname : string;
(* TODO: motd *)
motd_file : string;
}
let run { port; listen_backlog; ping_interval;
whowas_history_len; hostname } : unit Lwt.t
let run { port; listen_backlog; ping_interval; whowas_history_len;
hostname; motd_file } : unit Lwt.t
=
let server_info =
Server_info.make
~hostname
(* ~motd *)
debug (fun m -> m "ping interval:@ %ds" ping_interval);
debug (fun m -> m "whowas history:@ %d" whowas_history_len);
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
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 =
Router.make
~whowas_history_len

View File

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

View File

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