aboutsummaryrefslogtreecommitdiff
path: root/server/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/main.rs')
-rw-r--r--server/src/main.rs32
1 files changed, 13 insertions, 19 deletions
diff --git a/server/src/main.rs b/server/src/main.rs
index 3fbefaf8..3bf39f5a 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -33,7 +33,7 @@ use tokio::{
net::{TcpListener, TcpStream},
spawn,
sync::{RwLock, broadcast},
- time::interval,
+ time::{interval, sleep},
};
use tokio_tungstenite::{WebSocketStream, tungstenite::Message};
@@ -51,9 +51,9 @@ pub(crate) struct Args {
/// Map name to use as lobby
#[arg(long, default_value = "lobby")]
lobby: String,
- /// Inactivity kick timeout in seconds
+ /// Inactivity timeout in seconds
#[arg(long, default_value_t = 60.)]
- inactivity_kick_timeout: f32,
+ inactivity_timeout: f32,
/// Registers this server to the public server registry
#[arg(long)]
#[cfg(feature = "register")]
@@ -125,7 +125,7 @@ async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> {
let (tx, _) = broadcast::channel::<PacketC>(128 * 1024);
let config = ServerConfig {
- inactivity_kick_timeout: args.inactivity_kick_timeout,
+ inactivity_timeout: args.inactivity_timeout,
lobby: args.lobby,
};
@@ -214,14 +214,9 @@ async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> {
Ok(packet) => {
if send_packet(id, &mut sock, packet).await { break; };
},
- Err(e) => {
- broadcast_rx = broadcast_rx.resubscribe();
- warn!("{id} Client was lagging; resubscribed: {e}");
- let packet = PacketC::ServerMessage {
- message: trm!("s.state.overflow_resubscribe"),
- error: true,
- };
- if send_packet(id, &mut sock, packet).await { break; };
+ Err(_) => {
+ warn!("{id} Broadcast packet channel overflowed");
+ state.write().await.disconnect(id, Some(trm!("s.disconnect_reason.channel_overflow")));
}
},
Some(Ok(message)) = sock.next() => {
@@ -229,7 +224,8 @@ async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> {
Message::Text(line) if line.len() < 8196 => match serde_json::from_str(&line) {
Ok(p) => p,
Err(e) => {
- warn!("{id} Invalid json packet: {e}");
+ warn!("{id} Invalid packet: {e}");
+ state.write().await.disconnect(id, Some(trm!("s.disconnect_reason.invalid_packet", s = e.to_string())));
break;
}
},
@@ -243,7 +239,7 @@ async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> {
if matches!(
packet,
- PacketS::Movement { .. } | PacketS::ReplayTick { .. }
+ PacketS::Movement { .. } | PacketS::ReplayTick { .. } | PacketS::Keepalive
) {
trace!("{id} <- {packet:?}");
} else {
@@ -252,7 +248,7 @@ async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> {
let packet_out = match state.write().await.packet_in_outer(id, packet) {
Ok(packets) => packets,
Err(e) => {
- warn!("Client error: {e}");
+ warn!("{id} Packet error: {e}");
vec![PacketC::ServerMessage {
message: e.into(),
error: true,
@@ -265,10 +261,8 @@ async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> {
}
};
}
- state
- .write()
- .await
- .disconnect(id, hurrycurry_protocol::Message::Text(String::default()));
+ state.write().await.disconnect(id, None);
+ sleep(Duration::from_millis(100)).await; // avoids potential godot bug where disconnect packets are lost
});
}
Ok(())