From 8dd9439b9430053b6666949dc9dba9383b405957 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 07 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 +++ a/Cargo.lock @@ -125,6 +125,29 @@ ] [[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" @@ -272,6 +295,27 @@ version = "0.1.4" 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" @@ -393,6 +437,16 @@ dependencies = [ "cxx", "cxx-build", +] + +[[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]] @@ -405,6 +459,18 @@ "thiserror", "tokio", "tokio-util", +] + +[[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]] @@ -451,6 +517,12 @@ dependencies = [ "cc", ] + +[[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" @@ -542,6 +614,12 @@ version = "1.17.0" 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" @@ -634,6 +712,20 @@ version = "0.6.28" 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" @@ -712,6 +804,12 @@ "libc", "winapi", ] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -781,6 +879,7 @@ "actix-rt", "anyhow", "chrono", + "clap", "futures", "irc-proto", "itertools", diff --git a/Cargo.toml b/Cargo.toml index 9cfaf7b..749a597 100644 --- a/Cargo.toml +++ a/Cargo.toml @@ -10,6 +10,7 @@ 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 +++ a/src/client.rs @@ -1,11 +1,12 @@ use std::{collections::HashMap, time::Duration}; 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 @@ 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(_) => {} -- rgit 0.1.5