From 8dd9439b9430053b6666949dc9dba9383b405957 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 7 Jan 2023 22:40:58 +0000 Subject: [PATCH] Implement VERSION command --- Cargo.lock | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/client.rs | 18 ++++++++++++++++-- 3 files changed, 116 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8acb4e0..bf50ed2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,6 +125,29 @@ dependencies = [ ] [[package]] +name = "clap" +version = "4.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +dependencies = [ + "bitflags", + "clap_lex", + "is-terminal", + "once_cell", + "strsim", + "termcolor", +] + +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", +] + +[[package]] name = "codespan-reporting" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -274,6 +297,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" [[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] name = "futures" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -396,6 +440,16 @@ dependencies = [ ] [[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] name = "irc-proto" version = "0.15.0" source = "git+https://github.com/JordanForks/irc#923e080f2408ae301135e82549cff80e92aaa844" @@ -408,6 +462,18 @@ dependencies = [ ] [[package]] +name = "is-terminal" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", +] + +[[package]] name = "itertools" version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -453,6 +519,12 @@ dependencies = [ ] [[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + +[[package]] name = "lock_api" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -544,6 +616,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + +[[package]] name = "overload" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -636,6 +714,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] +name = "rustix" +version = "0.36.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] name = "ryu" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -714,6 +806,12 @@ dependencies = [ ] [[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] name = "syn" version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -781,6 +879,7 @@ dependencies = [ "actix-rt", "anyhow", "chrono", + "clap", "futures", "irc-proto", "itertools", diff --git a/Cargo.toml b/Cargo.toml index 9cfaf7b..749a597 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ actix = "0.13" actix-rt = "2.7" anyhow = "1.0" chrono = "0.4" +clap = { version = "4.0", features = ["cargo"] } futures = "0.3" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } diff --git a/src/client.rs b/src/client.rs index 5c4088e..07e17b7 100644 --- a/src/client.rs +++ b/src/client.rs @@ -4,8 +4,9 @@ use actix::{ fut::wrap_future, io::WriteHandler, Actor, ActorContext, ActorFutureExt, Addr, AsyncContext, Context, Handler, MessageResult, ResponseActFuture, Running, StreamHandler, WrapFuture, }; +use clap::{crate_name, crate_version}; use futures::FutureExt; -use irc_proto::{error::ProtocolError, ChannelExt, Command, Message}; +use irc_proto::{error::ProtocolError, ChannelExt, Command, Message, Response, Prefix}; use tokio::time::Instant; use tracing::{debug, error, info_span, instrument, warn, Instrument, Span}; @@ -439,7 +440,20 @@ impl StreamHandler> for Client { Command::NOTICE(_, _) => {} Command::MOTD(_) => {} Command::LUSERS(_, _) => {} - Command::VERSION(_) => {} + Command::VERSION(_) => { + self.writer.write(Message { + tags: None, + prefix: Some(Prefix::ServerName(SERVER_NAME.to_string())), + command: Command::Response( + Response::RPL_VERSION, + vec![ + self.connection.nick.to_string(), + format!("{}-{}", crate_name!(), crate_version!()), + SERVER_NAME.to_string(), + ], + ), + }); + } Command::STATS(_, _) => {} Command::LINKS(_, _) => {} Command::TIME(_) => {} -- libgit2 1.7.2