summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock183
-rw-r--r--Cargo.toml3
-rw-r--r--src/main.rs51
3 files changed, 232 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f1490e7..80f04ae 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9,6 +9,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
+name = "anstream"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
+dependencies = [
+ "anstyle",
+ "anstyle-parse",
+ "anstyle-query",
+ "anstyle-wincon",
+ "colorchoice",
+ "is-terminal",
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
+
+[[package]]
+name = "anstyle-parse"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee"
+dependencies = [
+ "utf8parse",
+]
+
+[[package]]
+name = "anstyle-query"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
+dependencies = [
+ "windows-sys 0.48.0",
+]
+
+[[package]]
+name = "anstyle-wincon"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
+dependencies = [
+ "anstyle",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
name = "approx"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -118,6 +167,48 @@ dependencies = [
]
[[package]]
+name = "clap"
+version = "4.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "93aae7a4192245f70fe75dd9157fc7b4a5bf53e88d30bd4396f7d8f9284d5acc"
+dependencies = [
+ "clap_builder",
+ "clap_derive",
+ "once_cell",
+]
+
+[[package]]
+name = "clap_builder"
+version = "4.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4f423e341edefb78c9caba2d9c7f7687d0e72e89df3ce3394554754393ac3990"
+dependencies = [
+ "anstream",
+ "anstyle",
+ "bitflags",
+ "clap_lex",
+ "strsim",
+]
+
+[[package]]
+name = "clap_derive"
+version = "4.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "191d9573962933b4027f932c600cd252ce27a8ad5979418fe78e43c07996f27b"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.18",
+]
+
+[[package]]
+name = "clap_lex"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
+
+[[package]]
name = "cloudabi"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -141,6 +232,12 @@ dependencies = [
]
[[package]]
+name = "colorchoice"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
+
+[[package]]
name = "convert_case"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -287,6 +384,27 @@ dependencies = [
]
[[package]]
+name = "errno"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a"
+dependencies = [
+ "errno-dragonfly",
+ "libc",
+ "windows-sys 0.48.0",
+]
+
+[[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 = "flate2"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -426,6 +544,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
+name = "heck"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
+
+[[package]]
name = "hermit-abi"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -435,6 +559,12 @@ dependencies = [
]
[[package]]
+name = "hermit-abi"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
+
+[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -451,6 +581,29 @@ dependencies = [
]
[[package]]
+name = "io-lifetimes"
+version = "1.0.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
+dependencies = [
+ "hermit-abi 0.3.1",
+ "libc",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
+name = "is-terminal"
+version = "0.4.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
+dependencies = [
+ "hermit-abi 0.3.1",
+ "io-lifetimes",
+ "rustix",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
name = "jobserver"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -483,6 +636,12 @@ dependencies = [
]
[[package]]
+name = "linux-raw-sys"
+version = "0.3.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
+
+[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -690,7 +849,7 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
- "hermit-abi",
+ "hermit-abi 0.2.6",
"libc",
]
@@ -925,6 +1084,20 @@ dependencies = [
]
[[package]]
+name = "rustix"
+version = "0.37.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d"
+dependencies = [
+ "bitflags",
+ "errno",
+ "io-lifetimes",
+ "libc",
+ "linux-raw-sys",
+ "windows-sys 0.48.0",
+]
+
+[[package]]
name = "serde"
version = "1.0.163"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1042,6 +1215,8 @@ dependencies = [
name = "texmodbot"
version = "0.1.0"
dependencies = [
+ "clap",
+ "futures-util",
"mt_auth",
"mt_net",
"tokio",
@@ -1131,6 +1306,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
+name = "utf8parse"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
+
+[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 351bca9..e72b83e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -2,8 +2,11 @@
name = "texmodbot"
version = "0.1.0"
edition = "2021"
+description = "Extract texture modifiers from minetest servers to obtain test data for texture modifier parsers"
[dependencies]
mt_net = { git = "https://github.com/minetest-rust/mt_net", features = ["conn", "client"] }
tokio = { version = "1.25.0", features = ["rt", "rt-multi-thread", "signal"] }
mt_auth = { git = "https://github.com/minetest-rust/mt_auth" }
+clap = { version = "4.3.0", features = ["derive"] }
+futures-util = "0.3.28"
diff --git a/src/main.rs b/src/main.rs
index dc29774..da84133 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,14 +1,46 @@
+use clap::Parser;
+use futures_util::future::OptionFuture;
use mt_net::{ReceiverExt, SenderExt, ToCltPkt, ToSrvPkt};
+use std::pin::Pin;
+use std::time::Duration;
+use tokio::time::{sleep, Sleep};
+
+#[derive(Parser, Debug)]
+#[clap(version, about, long_about = None)]
+struct Args {
+ /// Server address. Format: address:port
+ #[clap(value_parser)]
+ address: String,
+
+ /// Quit QUIT_AFTER seconds after authentication
+ #[clap(short, long, value_parser)]
+ quit_after: Option<f32>,
+
+ /// Player name
+ #[clap(short, long, value_parser, default_value = "texmodbot")]
+ username: String,
+
+ /// Password
+ #[clap(short, long, value_parser, default_value = "owo")]
+ password: String,
+}
#[tokio::main]
async fn main() {
- let (tx, mut rx, worker) = mt_net::connect(&std::env::args().nth(1).expect("missing argument"))
- .await
- .unwrap();
+ let Args {
+ address,
+ quit_after,
+ username,
+ password,
+ } = Args::parse();
- let mut auth = mt_auth::Auth::new(tx.clone(), "texmodbot", "owo", "en_US");
+ let (tx, mut rx, worker) = mt_net::connect(&address).await.unwrap();
+
+ let mut auth = mt_auth::Auth::new(tx.clone(), username, password, "en_US");
let worker = tokio::spawn(worker.run());
+ let mut quit_sleep: Option<Pin<Box<Sleep>>> = None;
+
loop {
tokio::select! {
pkt = rx.recv() => match pkt {
@@ -35,6 +67,14 @@ async fn main() {
println!("{texture}");
}
});
+
+ quit_sleep = quit_after.and_then(|x| {
+ if x >= 0.0 {
+ Some(Box::pin(sleep(Duration::from_secs_f32(x))))
+ } else {
+ None
+ }
+ });
}
Kick(reason) => {
eprintln!("kicked: {reason}");
@@ -56,6 +96,9 @@ async fn main() {
.await
.unwrap();
},
+ Some(_) = OptionFuture::from(quit_sleep.as_mut()) => {
+ tx.close();
+ }
_ = tokio::signal::ctrl_c() => {
tx.close();
}