aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-09-24 00:45:28 +0200
committermetamuffin <metamuffin@disroot.org>2024-09-24 00:45:28 +0200
commitb344a0d4d87eabafa61acc8946643af395d81b8c (patch)
tree9ef5d0553843fd8bf697dc6d7b7d56e5372c6abf
parent1f5954da4c7e8af341c456093c5542e9ae201e3d (diff)
downloadhurrycurry-b344a0d4d87eabafa61acc8946643af395d81b8c.tar
hurrycurry-b344a0d4d87eabafa61acc8946643af395d81b8c.tar.bz2
hurrycurry-b344a0d4d87eabafa61acc8946643af395d81b8c.tar.zst
optional upnp, mdns and register support
-rw-r--r--server/Cargo.toml14
-rw-r--r--server/src/main.rs18
-rw-r--r--server/src/network/mdns.rs17
-rw-r--r--server/src/network/mod.rs5
4 files changed, 45 insertions, 9 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml
index ef14fddd..978de4c6 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -17,7 +17,7 @@ serde_yml = "0.0.11"
rand = "0.9.0-alpha.2"
shlex = "1.3.0"
clap = { version = "4.5.15", features = ["derive"] }
-reqwest = { version = "0.12.7", default-features = false, features = [
+reqwest = { version = "0.12.7", optional = true, default-features = false, features = [
"json",
"http2",
"charset",
@@ -26,10 +26,16 @@ reqwest = { version = "0.12.7", default-features = false, features = [
pollster = "0.3.0"
bincode = "2.0.0-rc.3"
xdg = "2.5.2"
-igd = { version = "0.12.1", features = ["aio"] }
-get_if_addrs = "0.5.3"
-mdns-sd = "0.11.4"
+igd = { version = "0.12.1", optional = true, features = ["aio"] }
+get_if_addrs = { version = "0.5.3", optional = true }
+mdns-sd = { version = "0.11.4", optional = true }
hurrycurry-protocol = { path = "protocol" }
hurrycurry-client-lib = { path = "client-lib" }
hurrycurry-bot = { path = "bot" }
+
+[features]
+default = ["mdns", "register", "upnp"]
+mdns = ["dep:mdns-sd", "dep:get_if_addrs"]
+register = ["dep:reqwest"]
+upnp = ["dep:igd", "dep:get_if_addrs"]
diff --git a/server/src/main.rs b/server/src/main.rs
index 087bd9d7..b72a961b 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -21,7 +21,6 @@ use futures_util::{SinkExt, StreamExt};
use hurrycurry_protocol::{PacketC, PacketS, BINCODE_CONFIG, VERSION};
use hurrycurry_server::{
data::DATA_DIR,
- network::{mdns::mdns_loop, register::Register, upnp::upnp_loop},
server::{GameServerExt, Server},
trm, ConnectionID,
};
@@ -60,21 +59,27 @@ pub(crate) struct Args {
#[arg(long)]
register: bool,
/// Enables the mDNS responder for local network discovery
+ #[cfg(feature = "mdns")]
#[arg(long)]
mdns: bool,
// Enables automatic gateway port forwarding using UPnP
+ #[cfg(feature = "upnp")]
#[arg(long)]
upnp: bool,
/// Server name
+ #[cfg(any(feature = "register", feature = "mdns"))]
#[arg(long, short = 'N', default_value = "A Hurry Curry! Server")]
server_name: String,
/// Uri for connecting remotely for registry submission
+ #[cfg(feature = "register")]
#[arg(long)]
register_uri: Option<String>,
/// Do not register using IPv4
+ #[cfg(feature = "register")]
#[arg(long)]
register_disable_ip4: bool,
/// Do not register using IPv6
+ #[cfg(feature = "register")]
#[arg(long)]
register_disable_ip6: bool,
}
@@ -130,8 +135,9 @@ async fn run(args: Args) -> anyhow::Result<()> {
state.load(state.index.generate("lobby").await?, None);
let state = Arc::new(RwLock::new(state));
+ #[cfg(feature = "register")]
if args.register {
- let r = Register::new(
+ let r = hurrycurry_server::network::register::Register::new(
args.server_name.clone(),
args.listen.port(),
args.register_uri,
@@ -141,11 +147,15 @@ async fn run(args: Args) -> anyhow::Result<()> {
);
tokio::task::spawn(r.register_loop());
}
+ #[cfg(feature = "upnp")]
if args.upnp {
- tokio::task::spawn(upnp_loop(args.listen.port()));
+ tokio::task::spawn(hurrycurry_server::network::upnp::upnp_loop(
+ args.listen.port(),
+ ));
}
+ #[cfg(feature = "mdns")]
if args.mdns {
- tokio::task::spawn(mdns_loop(
+ tokio::task::spawn(hurrycurry_server::network::mdns::mdns_loop(
args.server_name.clone(),
args.listen.port(),
state.clone(),
diff --git a/server/src/network/mdns.rs b/server/src/network/mdns.rs
index 870ae7ec..43f7bc91 100644
--- a/server/src/network/mdns.rs
+++ b/server/src/network/mdns.rs
@@ -1,3 +1,20 @@
+/*
+ Hurry Curry! - a game about cooking
+ Copyright 2024 metamuffin
+
+ 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, version 3 of the License only.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
use crate::server::Server;
use anyhow::Result;
use get_if_addrs::get_if_addrs;
diff --git a/server/src/network/mod.rs b/server/src/network/mod.rs
index b7ffc15e..ce11082d 100644
--- a/server/src/network/mod.rs
+++ b/server/src/network/mod.rs
@@ -15,6 +15,9 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+#[cfg(feature = "mdns")]
+pub mod mdns;
+#[cfg(feature = "register")]
pub mod register;
+#[cfg(feature = "upnp")]
pub mod upnp;
-pub mod mdns;