summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaindropsSys <raindrops@equestria.dev>2024-05-19 18:39:18 +0200
committerRaindropsSys <raindrops@equestria.dev>2024-05-19 18:39:18 +0200
commit520b89511a12de95af9b6c7a65f0fbcf47b92d09 (patch)
treedf331a2b13e44149f4d9ef924ac9d109e5aafdf7
parentdfa0895f994972c6218f62acd3762445b321fcb0 (diff)
downloadwhere-rs-520b89511a12de95af9b6c7a65f0fbcf47b92d09.tar.gz
where-rs-520b89511a12de95af9b6c7a65f0fbcf47b92d09.tar.bz2
where-rs-520b89511a12de95af9b6c7a65f0fbcf47b92d09.zip
Updated 10 files, added 2 files, deleted where-shared/Cargo.toml and renamed 3 files
-rw-r--r--.idea/where-rs.iml2
-rw-r--r--Cargo.lock17
-rw-r--r--Cargo.toml2
-rwxr-xr-xbuild.sh21
-rw-r--r--where-rs/Cargo.toml4
-rw-r--r--where-rs/src/main.rs2
-rw-r--r--where-rs/src/servers.rs4
-rw-r--r--where-rs/src/ui.rs2
-rw-r--r--where-shared/Cargo.toml9
-rw-r--r--whered/Cargo.toml9
-rw-r--r--whered/src/args.rs9
-rw-r--r--whered/src/main.rs39
-rw-r--r--whrd/Cargo.toml13
-rw-r--r--whrd/src/error.rs (renamed from where-shared/src/error.rs)0
-rw-r--r--whrd/src/lib.rs (renamed from where-shared/src/lib.rs)0
-rw-r--r--whrd/src/parse.rs (renamed from where-shared/src/parse.rs)0
16 files changed, 92 insertions, 41 deletions
diff --git a/.idea/where-rs.iml b/.idea/where-rs.iml
index b37ad1d..9778462 100644
--- a/.idea/where-rs.iml
+++ b/.idea/where-rs.iml
@@ -4,8 +4,8 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/where-rs/src" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/where-shared/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/whered/src" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/whrd/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
diff --git a/Cargo.lock b/Cargo.lock
index e9ef8c9..a5ba44f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -686,27 +686,28 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
[[package]]
name = "where-rs"
-version = "1.0.0-rc"
+version = "1.0.0-rc.1"
dependencies = [
"chrono",
"clap",
"serde",
"toml",
- "where-shared",
+ "whrd",
]
[[package]]
-name = "where-shared"
-version = "1.0.0"
+name = "whered"
+version = "1.0.0-rc.1"
dependencies = [
- "coreutils_core",
+ "clap",
+ "whrd",
]
[[package]]
-name = "whered"
-version = "0.2.0"
+name = "whrd"
+version = "1.0.0-rc.1"
dependencies = [
- "where-shared",
+ "coreutils_core",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index b7cd93b..a8b5c47 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,5 @@
[workspace]
-members = [ "where-rs", "whered", "where-shared"]
+members = ["where-rs", "whered", "whrd"]
resolver = "2"
[profile.release]
diff --git a/build.sh b/build.sh
index 8db4259..d6dc2eb 100755
--- a/build.sh
+++ b/build.sh
@@ -2,12 +2,15 @@
whered_version=$(cargo pkgid whered | tr "#" " " | awk '{print $2;}')
where_version=$(cargo pkgid where-rs | tr "#" " " | awk '{print $2;}')
+rustc_version=$(rustc --version | awk '{print $2;}')
cargo clean
cargo build --target aarch64-apple-darwin --release
cargo build --target x86_64-apple-darwin --release
cargo build --target x86_64-unknown-linux-gnu --release
+# aarch64-apple-darwin
+
curl -v --header "PRIVATE-TOKEN: $(cat ~/.deploy.txt)" \
--header "Content-Type: multipart/form-data" \
--upload-file ./target/aarch64-apple-darwin/release/whered \
@@ -20,6 +23,13 @@ https://source.equestria.dev/api/v4/projects/178/packages/generic/where/$where_v
curl -v --header "PRIVATE-TOKEN: $(cat ~/.deploy.txt)" \
--header "Content-Type: multipart/form-data" \
+--upload-file ./target/aarch64-apple-darwin/release/libwhrd.dylib \
+https://source.equestria.dev/api/v4/projects/178/packages/generic/libwhrd/$where_version-rustc.$rustc_version/libwhrd-darwin-aarch64.dylib
+
+# x86_64-apple-darwin
+
+curl -v --header "PRIVATE-TOKEN: $(cat ~/.deploy.txt)" \
+--header "Content-Type: multipart/form-data" \
--upload-file ./target/x86_64-apple-darwin/release/whered \
https://source.equestria.dev/api/v4/projects/178/packages/generic/whered/$whered_version/whered-darwin-x86_64
@@ -30,8 +40,10 @@ https://source.equestria.dev/api/v4/projects/178/packages/generic/where/$where_v
curl -v --header "PRIVATE-TOKEN: $(cat ~/.deploy.txt)" \
--header "Content-Type: multipart/form-data" \
---upload-file ./target/aarch64-unknown-linux-gnu/release/whered \
-https://source.equestria.dev/api/v4/projects/178/packages/generic/whered/$whered_version/whered-linux-aarch64
+--upload-file ./target/x86_64-apple-darwin/release/libwhrd.dylib \
+https://source.equestria.dev/api/v4/projects/178/packages/generic/libwhrd/$where_version-rustc.$rustc_version/libwhrd-darwin-x86_64.dylib
+
+# x86_64-unknown-linux-gnu
curl -v --header "PRIVATE-TOKEN: $(cat ~/.deploy.txt)" \
--header "Content-Type: multipart/form-data" \
@@ -42,3 +54,8 @@ curl -v --header "PRIVATE-TOKEN: $(cat ~/.deploy.txt)" \
--header "Content-Type: multipart/form-data" \
--upload-file ./target/x86_64-unknown-linux-gnu/release/where \
https://source.equestria.dev/api/v4/projects/178/packages/generic/where/$where_version/where-linux-x86_64
+
+curl -v --header "PRIVATE-TOKEN: $(cat ~/.deploy.txt)" \
+--header "Content-Type: multipart/form-data" \
+--upload-file ./target/x86_64-unknown-linux-gnu/release/libwhrd.so \
+https://source.equestria.dev/api/v4/projects/178/packages/generic/libwhrd/$where_version-rustc.$rustc_version/libwhrd-linux-x86_64.so
diff --git a/where-rs/Cargo.toml b/where-rs/Cargo.toml
index 33aa5bf..9b21470 100644
--- a/where-rs/Cargo.toml
+++ b/where-rs/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "where-rs"
-version = "1.0.0-rc"
+version = "1.0.0-rc.1"
edition = "2021"
description = "A small Rust client for the WHRD/UDP protocol, to access a list of logged in users on multiple systems at once."
authors = ["Raindrops", "ryze132"]
@@ -10,7 +10,7 @@ name = "where"
path = "src/main.rs"
[dependencies]
-where-shared = { path = "../where-shared" }
+whrd = { path = "../whrd" }
chrono = "0.4.35"
toml = "0.8.12"
serde = { version = "1.0.197", features = ["derive"] }
diff --git a/where-rs/src/main.rs b/where-rs/src/main.rs
index ce6a8bc..a63c16d 100644
--- a/where-rs/src/main.rs
+++ b/where-rs/src/main.rs
@@ -5,7 +5,7 @@ mod args;
use clap::Parser;
use args::Args;
-use where_shared::error::WhereResult;
+use whrd::error::WhereResult;
use config::{Config, Server};
fn main() {
diff --git a/where-rs/src/servers.rs b/where-rs/src/servers.rs
index 9f112f8..edf714a 100644
--- a/where-rs/src/servers.rs
+++ b/where-rs/src/servers.rs
@@ -1,8 +1,8 @@
use std::io::ErrorKind;
use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
use std::time::Duration;
-use where_shared::error::{WhereError, WhereResult};
-use where_shared::{MAX_PAYLOAD_LENGTH, SessionCollection, WHERED_MAGIC};
+use whrd::error::{WhereError, WhereResult};
+use whrd::{MAX_PAYLOAD_LENGTH, SessionCollection, WHERED_MAGIC};
use crate::config::{GlobalConfig, Server};
impl Server {
diff --git a/where-rs/src/ui.rs b/where-rs/src/ui.rs
index c35d778..572d8ba 100644
--- a/where-rs/src/ui.rs
+++ b/where-rs/src/ui.rs
@@ -1,5 +1,5 @@
use chrono::DateTime;
-use where_shared::Session;
+use whrd::Session;
use crate::config::GlobalConfig;
pub fn print_summary(mut sessions: Vec<Session>, config: GlobalConfig) {
diff --git a/where-shared/Cargo.toml b/where-shared/Cargo.toml
deleted file mode 100644
index 8393906..0000000
--- a/where-shared/Cargo.toml
+++ /dev/null
@@ -1,9 +0,0 @@
-[package]
-name = "where-shared"
-version = "1.0.0"
-edition = "2021"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-coreutils_core = "0.1.1"
diff --git a/whered/Cargo.toml b/whered/Cargo.toml
index 1be6eb8..8c2a4ac 100644
--- a/whered/Cargo.toml
+++ b/whered/Cargo.toml
@@ -1,9 +1,10 @@
[package]
name = "whered"
-version = "0.2.0"
+version = "1.0.0-rc.1"
edition = "2021"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+description = "A small Rust server for the WHRD/UDP protocol, to access a list of logged in users on multiple systems at once."
+authors = ["Raindrops", "ryze132"]
[dependencies]
-where-shared = { path = "../where-shared" }
+whrd = { path = "../whrd" }
+clap = { version = "4.5.3", features = ["derive"] }
diff --git a/whered/src/args.rs b/whered/src/args.rs
new file mode 100644
index 0000000..b3f93f0
--- /dev/null
+++ b/whered/src/args.rs
@@ -0,0 +1,9 @@
+use clap::Parser;
+
+#[derive(Parser, Debug)]
+#[command(name = "whered", version, about)]
+pub struct Args {
+ /// Specify a custom listen address from the default 0.0.0.0:15
+ #[arg(short = 'l', long)]
+ pub listen_addr: Option<String>,
+}
diff --git a/whered/src/main.rs b/whered/src/main.rs
index 61e010f..9d2c808 100644
--- a/whered/src/main.rs
+++ b/whered/src/main.rs
@@ -1,21 +1,40 @@
+mod args;
+
+use args::Args;
use std::net::{SocketAddr, UdpSocket};
-use where_shared::error::WhereResult;
-use where_shared::{SessionCollection, WHERED_MAGIC};
+use std::process;
+use std::str::FromStr;
+use clap::Parser;
+use whrd::error::{WhereError, WhereResult};
+use whrd::{SessionCollection, WHERED_MAGIC};
fn main() {
- if let Err(e) = run_server() {
+ let args = Args::parse();
+ let listen_addr = args.listen_addr.unwrap_or(String::from("0.0.0.0:15"));
+
+ if let Err(e) = run_server(&listen_addr) {
eprintln!("whered: {}", e);
- std::process::exit(1);
+ process::exit(1);
}
}
-fn run_server() -> WhereResult<()> {
- let socket = UdpSocket::bind(SocketAddr::from(([0, 0, 0, 0], 15)))?;
- println!("Now listening on 0.0.0.0:15");
+fn run_server(listen_addr: &str) -> WhereResult<()> {
+ let socket_addr_result = SocketAddr::from_str(listen_addr);
- loop {
- if let Err(e) = handle_request(&socket) {
- eprintln!("whered: {}", e);
+ match socket_addr_result {
+ Ok(socket_addr) => {
+ let socket = UdpSocket::bind(socket_addr)?;
+ println!("Now listening on {} port {}/udp", socket_addr.ip(), socket_addr.port());
+
+ loop {
+ if let Err(e) = handle_request(&socket) {
+ eprintln!("whered: {}", e);
+ }
+ }
+ }
+ Err(e) => {
+ eprintln!("whered: {}", WhereError::from(e));
+ process::exit(1);
}
}
}
diff --git a/whrd/Cargo.toml b/whrd/Cargo.toml
new file mode 100644
index 0000000..adb0635
--- /dev/null
+++ b/whrd/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "whrd"
+version = "1.0.0-rc.1"
+edition = "2021"
+description = "A Rust library to work with the WHRD/UDP protocol, a protocol to access a list of logged in users on multiple systems at once."
+authors = ["Raindrops", "ryze132"]
+
+[lib]
+name = "whrd"
+crate-type = ["dylib", "lib"]
+
+[dependencies]
+coreutils_core = "0.1.1"
diff --git a/where-shared/src/error.rs b/whrd/src/error.rs
index 931aefe..931aefe 100644
--- a/where-shared/src/error.rs
+++ b/whrd/src/error.rs
diff --git a/where-shared/src/lib.rs b/whrd/src/lib.rs
index 8ff483d..8ff483d 100644
--- a/where-shared/src/lib.rs
+++ b/whrd/src/lib.rs
diff --git a/where-shared/src/parse.rs b/whrd/src/parse.rs
index 83542d8..83542d8 100644
--- a/where-shared/src/parse.rs
+++ b/whrd/src/parse.rs