diff --git a/sable_ircd/info.txt b/sable_ircd/info.txt new file mode 100644 index 0000000..9817c34 --- /dev/null +++ b/sable_ircd/info.txt @@ -0,0 +1,16 @@ +Sable -- + +Copyright (c) 2021-2024 Sable Development Team + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Source code is available at: https://github.com/Libera-Chat/sable + +A list of contributors can be found in the git log. + +Visit the Sable website at: https://sable.chat/ +Visit us on IRC at irc.libera.chat #libera-dev + diff --git a/sable_ircd/src/command/handlers/info.rs b/sable_ircd/src/command/handlers/info.rs new file mode 100644 index 0000000..95a28c9 --- /dev/null +++ b/sable_ircd/src/command/handlers/info.rs @@ -0,0 +1,19 @@ +use super::*; + +#[command_handler("INFO")] +/// Syntax: INFO +fn info_handler(response: &dyn CommandResponse, server: &ClientServer) -> CommandResult { + let node = server.node(); + let version = node.version(); + let commit_date = node.commit_date(); + + for line in &server.info_strings.info { + response.numeric(make_numeric!(Info, line)); + } + response.numeric(make_numeric!(Info, &format!("Version: {version}"))); + response.numeric(make_numeric!(Info, &format!("Commit date: {commit_date}"))); + // TODO: send configuration info to opers + // see: https://github.com/solanum-ircd/solanum/blob/main/modules/m_info.c#L788 + response.numeric(make_numeric!(EndOfInfo)); + Ok(()) +} diff --git a/sable_ircd/src/command/mod.rs b/sable_ircd/src/command/mod.rs index eb63bcc..ea9a18a 100644 --- a/sable_ircd/src/command/mod.rs +++ b/sable_ircd/src/command/mod.rs @@ -42,6 +42,7 @@ mod handlers { mod ban; mod cap; mod chathistory; + mod info; mod invite; mod join; mod kick; diff --git a/sable_ircd/src/messages/numeric.rs b/sable_ircd/src/messages/numeric.rs index f25950f..4b3b9ac 100644 --- a/sable_ircd/src/messages/numeric.rs +++ b/sable_ircd/src/messages/numeric.rs @@ -67,6 +67,9 @@ define_messages! { 381(YoureOper) => { () => "You are now an IRC operator" }, + 371(Info) => { (line: &str) => ":{line}" }, + 374(EndOfInfo) => { () => ":End of /INFO list" }, + 401(NoSuchTarget) => { (unknown: &str) => "{unknown} :No such nick/channel" }, 402(NoSuchServer) => { (server_name: &ServerName) => "{server_name} :No such server" }, diff --git a/sable_ircd/src/server/config.rs b/sable_ircd/src/server/config.rs index 0f32e31..76fabc6 100644 --- a/sable_ircd/src/server/config.rs +++ b/sable_ircd/src/server/config.rs @@ -30,6 +30,7 @@ pub struct RawClientServerConfig { pub struct ServerInfoStrings { pub motd: Option>, // Linewise to not repeatedly split pub admin_info: Option, + pub info: Vec, } impl ServerInfoStrings { @@ -38,6 +39,10 @@ impl ServerInfoStrings { motd: Self::get_info(&raw_info.motd, "motd")? .map(|file| file.lines().map(|v| v.to_string()).collect()), admin_info: raw_info.admin.clone(), + info: include_str!("../../info.txt") + .lines() + .map(|v| v.to_string()) + .collect(), }) }