aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-30 16:52:41 +0100
committermetamuffin <metamuffin@disroot.org>2025-10-30 19:35:02 +0100
commitd861319090fa6378aabf4fd102566083b915c1a5 (patch)
tree2c86887cb3c2dcbb0a04df3619ffdae451841d14 /server
parent3f81613f752befe2a54e5d3cff4c856c3adb6e26 (diff)
downloadhurrycurry-d861319090fa6378aabf4fd102566083b915c1a5.tar
hurrycurry-d861319090fa6378aabf4fd102566083b915c1a5.tar.bz2
hurrycurry-d861319090fa6378aabf4fd102566083b915c1a5.tar.zst
Add disconnect reasons
Diffstat (limited to 'server')
-rw-r--r--server/protocol/src/lib.rs4
-rw-r--r--server/src/main.rs5
-rw-r--r--server/src/state.rs8
3 files changed, 14 insertions, 3 deletions
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs
index 09134a4f..15911dd3 100644
--- a/server/protocol/src/lib.rs
+++ b/server/protocol/src/lib.rs
@@ -294,6 +294,10 @@ pub enum PacketC {
item: ItemIndex,
success: bool,
},
+
+ Disconnect {
+ reason: Message,
+ },
Redirect {
uri: Vec<String>,
},
diff --git a/server/src/main.rs b/server/src/main.rs
index 9ee58a41..3fbefaf8 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -265,7 +265,10 @@ async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> {
}
};
}
- state.write().await.disconnect(id);
+ state
+ .write()
+ .await
+ .disconnect(id, hurrycurry_protocol::Message::Text(String::default()));
});
}
Ok(())
diff --git a/server/src/state.rs b/server/src/state.rs
index fc97a7d1..1b42243f 100644
--- a/server/src/state.rs
+++ b/server/src/state.rs
@@ -39,7 +39,7 @@ impl Server {
}
}
for cid in idle_kick {
- self.disconnect(cid);
+ self.disconnect(cid, trm!("s.disconnect_reason.inactivity_kick"));
}
if !self.paused {
@@ -119,8 +119,9 @@ impl Server {
(init, broadcast_rx, replies_rx)
}
- pub fn disconnect(&mut self, conn: ConnectionID) {
+ pub fn disconnect(&mut self, conn: ConnectionID, reason: Message) {
if let Some(cd) = self.connections.get(&conn) {
+ let _ = cd.replies.try_send(PacketC::Disconnect { reason });
for player in cd.players.clone() {
let _ = self.packet_in_outer(conn, PacketS::Leave { player });
}
@@ -182,6 +183,9 @@ impl Server {
| PacketS::Movement { boost: true, .. } => {
self.connections.get_mut(&conn).unwrap().last_player_input = 0.;
}
+ PacketS::Movement { dir, .. } if dir.length() > 0.5 => {
+ self.connections.get_mut(&conn).unwrap().last_player_input = 0.;
+ }
_ => (),
}
self.packet_in(Some(conn), packet, &mut replies)?;