Skip to content

Commit

Permalink
Implement INFO command
Browse files Browse the repository at this point in the history
currently returns:
- copyright info
- author info
- website and irc channel
- version
- commit datetime
  • Loading branch information
internet-catte authored and spb committed Jul 2, 2024
1 parent 7d27069 commit a16f32b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sable_ircd/info.txt
Original file line number Diff line number Diff line change
@@ -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

19 changes: 19 additions & 0 deletions sable_ircd/src/command/handlers/info.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
1 change: 1 addition & 0 deletions sable_ircd/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod handlers {
mod ban;
mod cap;
mod chathistory;
mod info;
mod invite;
mod join;
mod kick;
Expand Down
3 changes: 3 additions & 0 deletions sable_ircd/src/messages/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
5 changes: 5 additions & 0 deletions sable_ircd/src/server/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct RawClientServerConfig {
pub struct ServerInfoStrings {
pub motd: Option<Vec<String>>, // Linewise to not repeatedly split
pub admin_info: Option<AdminInfo>,
pub info: Vec<String>,
}

impl ServerInfoStrings {
Expand All @@ -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(),
})
}

Expand Down

0 comments on commit a16f32b

Please sign in to comment.