#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "bevy_packet_schedules")]
pub use bevy_ecs;
#[cfg(all(feature = "bevy_packet_schedules", not(any(feature = "sd_bincode"))))]
compile_error!("feature \"bevy_packet_schedules\" needs one serializer");
use std::time::Duration;
use internal::{
messages::{ENCRYPTION_SPACE, NONCE_SIZE, UDP_BUFFER_SIZE},
SentMessagePart, MESSAGE_CHANNEL_SIZE,
};
pub use internal::messages::{DeserializedMessage, MessagePartId};
use crate::{internal::utils::RttProperties, packets::SerializedPacketList};
#[cfg(any(feature = "server", feature = "client"))]
pub(crate) mod internal;
#[cfg(not(any(feature = "server", feature = "client")))]
#[allow(dead_code)]
pub(crate) mod internal;
pub mod packets;
#[cfg(feature = "client")]
#[cfg_attr(docsrs, doc(cfg(feature = "client")))]
pub mod client;
#[cfg(feature = "server")]
#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
pub mod server;
#[cfg(feature = "auth_tcp")]
pub mod auth_tcp;
#[cfg(feature = "auth_tls")]
pub mod auth_tls;
pub struct MessagingProperties {
pub part_limit: usize,
pub timeout_interpretation: Duration,
pub disconnect_reason_resend_delay: Duration,
pub disconnect_reason_resend_cancel: Duration,
pub initial_next_message_part_id: MessagePartId,
pub initial_latency: Duration,
pub packet_loss_rtt_properties: RttProperties,
pub max_tick_bytes_len: usize,
}
impl Default for MessagingProperties {
fn default() -> Self {
Self {
part_limit: UDP_BUFFER_SIZE - MESSAGE_CHANNEL_SIZE - NONCE_SIZE - ENCRYPTION_SPACE,
timeout_interpretation: Duration::from_secs(10),
disconnect_reason_resend_delay: Duration::from_secs(3),
disconnect_reason_resend_cancel: Duration::from_secs(10),
initial_next_message_part_id: 1,
initial_latency: Duration::from_millis(50),
packet_loss_rtt_properties: RttProperties::new(0.125, 0.25),
max_tick_bytes_len: usize::MAX,
}
}
}
pub struct ReadHandlerProperties {
pub target_tasks_size: u16,
}
impl Default for ReadHandlerProperties {
fn default() -> ReadHandlerProperties {
ReadHandlerProperties {
target_tasks_size: 16u16,
}
}
}
pub struct LimitedMessage {
list: SerializedPacketList,
}
impl LimitedMessage {
pub fn try_new(list: SerializedPacketList) -> Result<Self, ()> {
if list.bytes.len() > UDP_BUFFER_SIZE - MESSAGE_CHANNEL_SIZE - NONCE_SIZE - ENCRYPTION_SPACE
{
Err(())
} else {
Ok(LimitedMessage { list })
}
}
#[cfg(not(feature = "no_panics"))]
pub fn new(list: SerializedPacketList) -> Self {
LimitedMessage::try_new(list).expect("Message reached the maximum byte length.")
}
pub(crate) fn to_list(self) -> SerializedPacketList {
self.list
}
#[cfg(feature = "server")]
pub(crate) fn clone(message: &LimitedMessage) -> LimitedMessage {
LimitedMessage {
list: SerializedPacketList {
bytes: message.list.bytes.clone(),
},
}
}
}