diff --git a/Cargo.lock b/Cargo.lock index cb89c3f..9ca3f9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -402,6 +402,7 @@ version = "0.2.0" dependencies = [ "aes-gcm", "base64 0.21.7", + "bevy", "igd", "local-ip-address", ] diff --git a/crates/bevnet/Cargo.toml b/crates/bevnet/Cargo.toml index 0399afe..e3dc782 100644 --- a/crates/bevnet/Cargo.toml +++ b/crates/bevnet/Cargo.toml @@ -16,3 +16,4 @@ local-ip-address = "0.5.7" aes-gcm = "0.10.3" base64 = "0.21.7" igd = "0.12.1" +bevy = "0.12.1" diff --git a/crates/bevnet/src/lib.rs b/crates/bevnet/src/lib.rs index 42aaa9a..7f79ceb 100644 --- a/crates/bevnet/src/lib.rs +++ b/crates/bevnet/src/lib.rs @@ -42,13 +42,14 @@ //! # } //! ``` -use std::collections::LinkedList; +use std::collections::{HashMap, LinkedList}; use std::io::{self, Read, Write}; use std::net::{IpAddr, Ipv4Addr, SocketAddrV4, TcpListener, TcpStream}; use aes_gcm::aead::{Aead, AeadCore, KeyInit, OsRng}; use aes_gcm::{Aes128Gcm, Key, Nonce}; use base64::prelude::*; +use bevy::prelude::*; use igd::{Gateway, PortMappingProtocol}; use local_ip_address::local_ip; @@ -367,3 +368,12 @@ impl Drop for Listener { .ok(); } } + +/// A resource that store the last event id used to register an [Event]. +/// +/// This is used to give an unique id to each event. +#[derive(Resource, Default)] +struct LastEventId(u16); + +/// An extension trait for the bevy [App] to allow registering network events. +pub trait NetworkAppExt {}