Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions framework_crates/bones_framework/src/networking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use {

use crate::input::PlayerControls as PlayerControlsTrait;

pub use iroh;

pub mod input;
pub mod lan;
pub mod online;
Expand Down
23 changes: 10 additions & 13 deletions framework_crates/bones_framework/src/networking/lan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ static LAN_MATCHMAKER: Lazy<LanMatchmaker> = Lazy::new(|| {
static MDNS: Lazy<ServiceDaemon> =
Lazy::new(|| ServiceDaemon::new().expect("Couldn't start MDNS service discovery thread."));

const MDNS_SERVICE_TYPE: &str = "_jumpy._udp.local.";

#[derive(DerefMut, Deref)]
struct Pinger(BiChannelClient<PingerRequest, PingerResponse>);

Expand Down Expand Up @@ -86,6 +84,9 @@ pub fn stop_server(server: &ServerInfo) {
if let Err(err) = stop_server_by_name(server.service.get_fullname()) {
warn!("Lan: failed to stop server: {err:?}");
}
LAN_MATCHMAKER
.try_send(LanMatchmakerRequest::StopServer)
.unwrap();
}

/// Stop hosting a server specified by name. (Use [`ServiceInfo::get_fullname()`].)
Expand Down Expand Up @@ -168,6 +169,7 @@ pub fn wait_game_start() -> Option<NetworkMatchSocket> {

/// Update server pings and turn on service discovery.
pub fn prepare_to_join(
service_type: &str,
servers: &mut Vec<ServerInfo>,
service_discovery_recv: &mut Option<ServiceDiscoveryReceiver>,
ping_update_timer: &Timer,
Expand Down Expand Up @@ -195,7 +197,7 @@ pub fn prepare_to_join(

let events = service_discovery_recv.get_or_insert_with(|| {
ServiceDiscoveryReceiver(
MDNS.browse(MDNS_SERVICE_TYPE)
MDNS.browse(service_type)
.expect("Couldn't start service discovery"),
)
});
Expand All @@ -222,6 +224,7 @@ pub fn prepare_to_join(
/// only then the returned `bool` is `true`.
pub async fn prepare_to_host<'a>(
host_info: &'a mut Option<ServerInfo>,
service_type: &str,
service_name: &str,
) -> (bool, &'a mut ServerInfo) {
let create_service_info = || async {
Expand All @@ -236,16 +239,10 @@ pub async fn prepare_to_host<'a>(
let mut props = std::collections::HashMap::default();
let addr_encoded = hex::encode(postcard::to_stdvec(&my_addr).unwrap());
props.insert("node-addr".to_string(), addr_encoded);
let service = mdns_sd::ServiceInfo::new(
MDNS_SERVICE_TYPE,
service_name,
service_name,
"",
port,
props,
)
.unwrap()
.enable_addr_auto();
let service =
mdns_sd::ServiceInfo::new(service_type, service_name, service_name, "", port, props)
.unwrap()
.enable_addr_auto();
ServerInfo {
service,
ping: None,
Expand Down