feat(server): accept QUIC client connections

This commit is contained in:
Serkyo 2026-07-14 01:38:58 +02:00
parent e9d6854e7a
commit e941415836
3 changed files with 24 additions and 8 deletions

2
Cargo.lock generated
View file

@ -548,6 +548,7 @@ dependencies = [
"anyhow",
"ash-window",
"glam 0.33.2",
"net",
"raw-window-handle",
"renderer",
"serde_json",
@ -2421,6 +2422,7 @@ dependencies = [
"crossbeam-channel",
"glam 0.33.2",
"lru",
"net",
"serde_json",
"shared",
"tempfile",

View file

@ -14,6 +14,7 @@ bevy_ecs = "0.19"
crossbeam-channel = "0.5.16"
glam.workspace = true
lru = "0.18.1"
net = { version = "0.1.0", path = "../net" }
serde_json.workspace = true
shared = { path = "../shared" }
tracing.workspace = true

View file

@ -15,6 +15,8 @@ pub mod world_server;
use std::collections::HashSet;
use std::fs;
use std::net::{Ipv4Addr, SocketAddr};
use std::time::Duration;
use anyhow::Context;
use bevy_ecs::prelude::{Query, ResMut, Schedule, With, World};
@ -23,6 +25,7 @@ use shared::generator::{VoxelGenerator, WorldGenConfig};
use shared::world::{ChunkPos, EntityPos};
use tracing::{debug, info};
use net::NetworkServer;
use player::{Player, Position, ViewDistance};
use world_server::{ServerWorld, cylinder_chunks};
@ -116,16 +119,26 @@ fn main() -> anyhow::Result<()> {
}
info!("Initial region ready; granting player control");
// Drive several ticks, marching the dummy one chunk along +X between each. The manual movement stands in for network-driven player input and exists only to exercise load/unload as the anchor moves.
for step in 0..5 {
info!(step, "tick");
// Spawn the networking thread and bind the QUIC endpoint. The synchronous simulation loop below communicates with it only by draining events.
let bind = SocketAddr::from((Ipv4Addr::LOCALHOST, net::DEFAULT_PORT));
let (network, local_addr) = NetworkServer::spawn(
bind,
env!("CARGO_PKG_VERSION").to_owned(),
// Placeholder advisory tick rate.
20,
)
.context("spawning network server")?;
info!(%local_addr, "network endpoint listening");
// Authoritative simulation loop.
loop {
schedule.run(&mut world);
let mut movers = world.query_filtered::<&mut Position, With<Player>>();
for mut position in movers.iter_mut(&mut world) {
position.0.chunk.x += 1;
}
for event in network.poll_events() {
info!(?event, "network event");
}
Ok(())
// Advisory ~20 Hz cadence until the real tick scheduler lands.
std::thread::sleep(Duration::from_millis(50));
}
}