Skip to content

Commit

Permalink
Release 0.15 (#130)
Browse files Browse the repository at this point in the history
- Write overflow and server-lock-up protection
(related to #67)

- Sequenced Message Channels thanks to @cBournhonesque !
(from #112 and myself)

- FAQ thanks to @cBournhonesque 
(#114)

- Unit and Tuple Replicate Components / Messages thanks to @cBournhonesque
(#115 & #117)

- New `Server.broadcast_message()` function thanks to @cBournhonesque
(#126)

- New `UserScope.include_all()` and `UserScope.exclude_all()` functions, thanks to @cBournhonesque
(#127 and myself) (#122)

- Non-blocking packet sending in `naia_client_socket`, thanks to @mvlabat !
(#116)

- Fix #94

- Fix #123

- More helpful error messages for #131

- More helpful error messages for #128

- Multiple dependency versions updated
  • Loading branch information
connorcarpenter authored Jan 29, 2023
1 parent 3b2abbf commit a162e53
Show file tree
Hide file tree
Showing 108 changed files with 2,426 additions and 1,055 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
uses: actions/checkout@v3

- name: Cache crates
uses: Swatinem/rust-cache@v1
uses: Swatinem/rust-cache@v2

- name: Clippy
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
uses: actions/checkout@v3

- name: Cache crates
uses: Swatinem/rust-cache@v1
uses: Swatinem/rust-cache@v2

- name: Clippy
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
uses: actions/checkout@v3

- name: Cache crates
uses: Swatinem/rust-cache@v1
uses: Swatinem/rust-cache@v2

- name: Clippy
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
uses: actions/checkout@v3

- name: Cache crates
uses: Swatinem/rust-cache@v1
uses: Swatinem/rust-cache@v2

- name: Clippy
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
uses: actions/checkout@v3

- name: Cache crates
uses: Swatinem/rust-cache@v1
uses: Swatinem/rust-cache@v2

- name: Clippy
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -233,7 +233,7 @@ jobs:
run: rustup target add wasm32-unknown-unknown

- name: Cache crates
uses: Swatinem/rust-cache@v1
uses: Swatinem/rust-cache@v2

- name: Clippy
uses: actions-rs/cargo@v1
Expand Down
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Bevy_Demo_Client__Linux___RUN_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/runConfigurations/Test_Serde.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/runConfigurations/Test_Shared.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Latest Version](https://img.shields.io/crates/v/naia-server.svg)](https://crates.io/crates/naia-server)
[![API Documentation](https://docs.rs/naia-server/badge.svg)](https://docs.rs/naia-server)
![](https://tokei.rs/b1/github/naia-rs/naia)
![](https://tokei.rs/b1/github/naia-lib/naia)
[![Discord chat](https://img.shields.io/discord/764975354913619988.svg?label=discord%20chat)](https://discord.gg/fD6QCtX)
[![MIT/Apache][s3]][l3]

Expand All @@ -22,6 +22,8 @@ Any help is very welcome, please get in touch! I am open to any criticism / feed

Currently guaranteed to work on Web & Linux, although Windows & MacOS have been reported working as well. Please file issues if you find inconsistencies and I'll do what I can.

For more detailed information, please look at the [FAQ](https://github.com/naia-lib/naia/faq/).

## Demos

More comprehensive documentation / tutorials are on their way, but for now, the best way to get started with naia is to go through the basic demo, which demonstrates most of the functionality.
Expand Down Expand Up @@ -58,9 +60,4 @@ To run the WebRTC client demo on Web: (that will be able to communicate with a W

To run a miniquad client you will require the following be installed

sudo apt-get install libxi-dev libgl1-mesa-dev

### A big thanks to our generous Sponsor for making this work sustainable:
<a href="https://meetkai.com">
<img src="assets/sponsors/meetkai_metaverse_banner_purple_900x250.png" width="600" height="166" />
</a>
sudo apt-get install libxi-dev libgl1-mesa-dev
4 changes: 2 additions & 2 deletions adapters/bevy/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.14.0"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia_client & Bevy interop"
homepage = "https://github.com/naia-rs/naia"
repository = "https://github.com/naia-rs/naia"
homepage = "https://github.com/naia-lib/naia"
repository = "https://github.com/naia-lib/naia"
license = "MIT OR Apache-2.0"
edition = "2021"

Expand Down
12 changes: 7 additions & 5 deletions adapters/bevy/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use bevy_ecs::{
};

use naia_client::{
shared::{ChannelIndex, Protocolize, ReplicateSafe},
Client as NaiaClient, EntityRef,
shared::{
ChannelIndex, EntityDoesNotExistError, EntityHandle, EntityHandleConverter, Protocolize,
ReplicateSafe,
},
Client as NaiaClient, EntityRef, NaiaClientError,
};

use naia_bevy_shared::{WorldProxy, WorldRef};
use naia_client::shared::{EntityHandle, EntityHandleConverter};

use super::state::State;

Expand Down Expand Up @@ -63,7 +65,7 @@ impl<'a, P: Protocolize, C: ChannelIndex> Client<'a, P, C> {
self.client.is_connecting()
}

pub fn server_address(&self) -> SocketAddr {
pub fn server_address(&self) -> Result<SocketAddr, NaiaClientError> {
self.client.server_address()
}

Expand Down Expand Up @@ -112,7 +114,7 @@ impl<'a, P: Protocolize, C: ChannelIndex> EntityHandleConverter<Entity> for Clie
self.client.handle_to_entity(entity_handle)
}

fn entity_to_handle(&self, entity: &Entity) -> EntityHandle {
fn entity_to_handle(&self, entity: &Entity) -> Result<EntityHandle, EntityDoesNotExistError> {
self.client.entity_to_handle(entity)
}
}
4 changes: 2 additions & 2 deletions adapters/bevy/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.14.0"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia_server & Bevy interop"
homepage = "https://github.com/naia-rs/naia"
repository = "https://github.com/naia-rs/naia"
homepage = "https://github.com/naia-lib/naia"
repository = "https://github.com/naia-lib/naia"
license = "MIT OR Apache-2.0"
edition = "2021"

Expand Down
10 changes: 8 additions & 2 deletions adapters/bevy/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use naia_server::{
ServerAddrs, UserKey, UserMut, UserRef, UserScopeMut,
};

use crate::shared::EntityHandle;
use naia_bevy_shared::{WorldProxy, WorldRef};

use crate::shared::{EntityDoesNotExistError, EntityHandle};

use super::{commands::Command, entity_mut::EntityMut, state::State};

// Server
Expand Down Expand Up @@ -72,6 +73,11 @@ impl<'world, 'state, P: Protocolize, C: ChannelIndex> Server<'world, 'state, P,
self.server.send_message(user_key, channel, message)
}

/// Sends a message to all connected users using a given channel
pub fn broadcast_message<R: ReplicateSafe<P>>(&mut self, channel: C, message: &R) {
self.server.broadcast_message(channel, message);
}

//// Updates ////

pub fn scope_checks(&self) -> Vec<(RoomKey, UserKey, Entity)> {
Expand Down Expand Up @@ -192,7 +198,7 @@ impl<'world, 'state, P: Protocolize, C: ChannelIndex> EntityHandleConverter<Enti
self.server.handle_to_entity(entity_handle)
}

fn entity_to_handle(&self, entity: &Entity) -> EntityHandle {
fn entity_to_handle(&self, entity: &Entity) -> Result<EntityHandle, EntityDoesNotExistError> {
self.server.entity_to_handle(entity)
}
}
4 changes: 2 additions & 2 deletions adapters/bevy/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.14.0"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia & Bevy interop, functionality shared by client & server versions"
homepage = "https://github.com/naia-rs/naia"
repository = "https://github.com/naia-rs/naia"
homepage = "https://github.com/naia-lib/naia"
repository = "https://github.com/naia-lib/naia"
license = "MIT OR Apache-2.0"
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions adapters/hecs/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.14.0"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia_client & Hecs interop"
homepage = "https://github.com/naia-rs/naia"
repository = "https://github.com/naia-rs/naia"
homepage = "https://github.com/naia-lib/naia"
repository = "https://github.com/naia-lib/naia"
keywords = ["wasm", "webrtc", "udp", "networking", "gamedev"]
categories = ["network-programming", "game-development", "wasm", "web-programming"]
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions adapters/hecs/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.14.0"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia_server & Hecs interop"
homepage = "https://github.com/naia-rs/naia"
repository = "https://github.com/naia-rs/naia"
homepage = "https://github.com/naia-lib/naia"
repository = "https://github.com/naia-lib/naia"
keywords = ["wasm", "webrtc", "udp", "networking", "gamedev"]
categories = ["network-programming", "game-development", "wasm", "web-programming"]
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions adapters/hecs/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.14.0"
authors = ["connorcarpenter <[email protected]>"]
workspace = "../../.."
description = "Library to faciliate naia & Hecs interop, functionality shared by client & server versions"
homepage = "https://github.com/naia-rs/naia"
repository = "https://github.com/naia-rs/naia"
homepage = "https://github.com/naia-lib/naia"
repository = "https://github.com/naia-lib/naia"
keywords = ["wasm", "webrtc", "udp", "networking", "gamedev"]
categories = ["network-programming", "game-development", "wasm", "web-programming"]
license = "MIT OR Apache-2.0"
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["connorcarpenter <[email protected]>"]
workspace = ".."
description = "Provides a cross-platform client that can send/receive messages to/from a server, and has a pool of in-scope entities/components that is synced with the server."
documentation = "https://docs.rs/naia-client"
homepage = "https://github.com/naia-rs/naia"
repository = "https://github.com/naia-rs/naia"
homepage = "https://github.com/naia-lib/naia"
repository = "https://github.com/naia-lib/naia"
readme = "../README.md"
keywords = ["wasm", "webrtc", "udp", "networking", "gamedev"]
categories = ["network-programming", "game-development", "wasm", "web-programming"]
Expand Down
48 changes: 37 additions & 11 deletions client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::{collections::VecDeque, hash::Hash, marker::PhantomData, net::SocketAddr};

use log::warn;

#[cfg(feature = "bevy_support")]
use bevy_ecs::prelude::Resource;

use naia_client_socket::Socket;

pub use naia_shared::{
serde::{BitReader, BitWriter, Serde},
ChannelIndex, ConnectionConfig, EntityHandle, EntityHandleConverter, PacketType, PingConfig,
PingIndex, ProtocolKindType, Protocolize, ReplicateSafe, SharedConfig, SocketConfig,
StandardHeader, Tick, Timer, Timestamp, WorldMutType, WorldRefType,
ChannelIndex, ConnectionConfig, EntityDoesNotExistError, EntityHandle, EntityHandleConverter,
PacketType, PingConfig, PingIndex, ProtocolKindType, Protocolize, ReplicateSafe, SharedConfig,
SocketConfig, StandardHeader, Tick, Timer, Timestamp, WorldMutType, WorldRefType,
};

use crate::{
Expand Down Expand Up @@ -112,7 +114,13 @@ impl<P: Protocolize, E: Copy + Eq + Hash, C: ChannelIndex> Client<P, E, C> {

for _ in 0..10 {
let mut writer = self.handshake_manager.write_disconnect();
self.io.send_writer(&mut writer);
match self.io.send_writer(&mut writer) {
Ok(()) => {}
Err(_) => {
// TODO: pass this on and handle above
warn!("Client Error: Cannot send disconnect packet to Server");
}
}
}

self.disconnect_internal();
Expand Down Expand Up @@ -229,8 +237,8 @@ impl<P: Protocolize, E: Copy + Eq + Hash, C: ChannelIndex> Client<P, E, C> {
// Connection

/// Get the address currently associated with the Server
pub fn server_address(&self) -> SocketAddr {
self.io.server_addr_unwrapped()
pub fn server_address(&self) -> Result<SocketAddr, NaiaClientError> {
self.io.server_addr()
}

/// Gets the average Round Trip Time measured to the Server
Expand Down Expand Up @@ -299,7 +307,13 @@ impl<P: Protocolize, E: Copy + Eq + Hash, C: ChannelIndex> Client<P, E, C> {
}

// send packet
self.io.send_writer(&mut writer);
match self.io.send_writer(&mut writer) {
Ok(()) => {}
Err(_) => {
// TODO: pass this on and handle above
warn!("Client Error: Cannot send heartbeat packet to Server");
}
}
server_connection.base.mark_sent();
}

Expand All @@ -321,7 +335,13 @@ impl<P: Protocolize, E: Copy + Eq + Hash, C: ChannelIndex> Client<P, E, C> {
server_connection.ping_manager.write_ping(&mut writer);

// send packet
self.io.send_writer(&mut writer);
match self.io.send_writer(&mut writer) {
Ok(()) => {}
Err(_) => {
// TODO: pass this on and handle above
warn!("Client Error: Cannot send ping packet to Server");
}
}
server_connection.base.mark_sent();
}

Expand Down Expand Up @@ -393,7 +413,13 @@ impl<P: Protocolize, E: Copy + Eq + Hash, C: ChannelIndex> Client<P, E, C> {
ping_index.ser(&mut writer);

// send packet
self.io.send_writer(&mut writer);
match self.io.send_writer(&mut writer) {
Ok(()) => {}
Err(_) => {
// TODO: pass this on and handle above
warn!("Client Error: Cannot send pong packet to Server");
}
}
server_connection.base.mark_sent();
}
PacketType::Pong => {
Expand Down Expand Up @@ -493,7 +519,7 @@ impl<P: Protocolize, E: Copy + Eq + Hash, C: ChannelIndex> Client<P, E, C> {

fn server_address_unwrapped(&self) -> SocketAddr {
// NOTE: may panic if the connection is not yet established!
self.io.server_addr_unwrapped()
self.io.server_addr().expect("connection not established!")
}
}

Expand All @@ -508,7 +534,7 @@ impl<P: Protocolize, E: Copy + Eq + Hash, C: ChannelIndex> EntityHandleConverter
connection.entity_manager.handle_to_entity(entity_handle)
}

fn entity_to_handle(&self, entity: &E) -> EntityHandle {
fn entity_to_handle(&self, entity: &E) -> Result<EntityHandle, EntityDoesNotExistError> {
let connection = self
.server_connection
.as_ref()
Expand Down
Loading

0 comments on commit a162e53

Please sign in to comment.