mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-10-26 14:00:22 +00:00
clients joining should no longer block acception runtime
This commit is contained in:
1 parent
3fedcf5bd5
commit
e1b9f2b969
1 file changed
+16
-3
+16
-3
@@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex, atomic::{AtomicBool, Ordering}};
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use tokio::net::{TcpListener, UdpSocket};
|
use tokio::net::{TcpListener, UdpSocket};
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::{JoinHandle, JoinSet};
|
||||||
|
|
||||||
use num_enum::IntoPrimitive;
|
use num_enum::IntoPrimitive;
|
||||||
|
|
||||||
@@ -70,17 +70,22 @@ impl Server {
|
|||||||
let clients_incoming_ref = Arc::clone(&clients_incoming);
|
let clients_incoming_ref = Arc::clone(&clients_incoming);
|
||||||
debug!("Client acception runtime starting...");
|
debug!("Client acception runtime starting...");
|
||||||
let connect_runtime_handle = tokio::spawn(async move {
|
let connect_runtime_handle = tokio::spawn(async move {
|
||||||
|
let mut set = JoinSet::new();
|
||||||
loop {
|
loop {
|
||||||
match tcp_listener_ref.accept().await {
|
match tcp_listener_ref.accept().await {
|
||||||
Ok((mut socket, addr)) => {
|
Ok((mut socket, addr)) => {
|
||||||
info!("New client connected: {:?}", addr);
|
info!("New client connected: {:?}", addr);
|
||||||
|
|
||||||
|
let cfg_ref = config_ref.clone();
|
||||||
|
let ci_ref = clients_incoming_ref.clone();
|
||||||
|
|
||||||
|
set.spawn(async move {
|
||||||
socket.set_nodelay(true);
|
socket.set_nodelay(true);
|
||||||
|
|
||||||
let mut client = Client::new(socket);
|
let mut client = Client::new(socket);
|
||||||
match client.authenticate(&config_ref).await {
|
match client.authenticate(&cfg_ref).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let mut lock = clients_incoming_ref
|
let mut lock = ci_ref
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|e| error!("{:?}", e))
|
.map_err(|e| error!("{:?}", e))
|
||||||
.expect("Failed to acquire lock on mutex!");
|
.expect("Failed to acquire lock on mutex!");
|
||||||
@@ -93,9 +98,17 @@ impl Server {
|
|||||||
client.kick("Failed to authenticate player!").await;
|
client.kick("Failed to authenticate player!").await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Err(e) => error!("Failed to accept incoming connection: {:?}", e),
|
Err(e) => error!("Failed to accept incoming connection: {:?}", e),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if set.is_empty() == false {
|
||||||
|
tokio::select!(
|
||||||
|
_ = set.join_next() => {},
|
||||||
|
_ = tokio::time::sleep(tokio::time::Duration::from_secs(1)) => {},
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
debug!("Client acception runtime started!");
|
debug!("Client acception runtime started!");
|
||||||
|
|||||||
Reference in new issue
Block a user