steamworks-rs icon indicating copy to clipboard operation
steamworks-rs copied to clipboard

Client doesn't recognize server disconnect

Open SetheenDev opened this issue 2 years ago • 1 comments

There doesn't appear to a callback a client can register to be made aware of server disconnect. The server listen socket can definitely detect disconnected clients but not the other way around. After pulling down this crate and adding some println statements, I do see NetConnectionStatusChanged events being published to a default NetworkingSocketsData.connection_callback handler but I don't see a way to register for this outside the library.

 NetConnectionStatusChanged { connection: 791123397, connection_info: NetConnectionInfo { identity_remote: Some(steamid:765xxx..), user_data: -1, listen_socket: None, state: Ok(ProblemDetectedLocally), end_reason: Some(MiscTimeout) }, old_state: Connected }

Whether the client is connected via p2p or ip doesn't matter. Am I missing something?

SetheenDev avatar Aug 15 '22 20:08 SetheenDev

I needed a quick and dirty solution to this. I forked, exposed some internal structs and reutilized a channel that wasn't doing anything. It's not pretty but am sharing if others stumble on this issue.

// connection health
if let Some(receiver) = connection.event_receiver.as_ref() {
    while match receiver.try_recv() {
        Ok(ev) => {
            match ev.state() {
                Ok(state) => {
                    println!("state: {:?}", state);
                    match state {
                        steamworks::networking_types::NetworkingConnectionState::None => {},
                        steamworks::networking_types::NetworkingConnectionState::Connecting => {},
                        steamworks::networking_types::NetworkingConnectionState::FindingRoute => {},
                        steamworks::networking_types::NetworkingConnectionState::Connected => {},
                        steamworks::networking_types::NetworkingConnectionState::ClosedByPeer => {},
                        steamworks::networking_types::NetworkingConnectionState::ProblemDetectedLocally => {
...

SetheenDev avatar Aug 19 '22 14:08 SetheenDev