Skip to content

Commit edab17d

Browse files
committed
fix: store full ConnectionId in StreamLookup
1 parent 4c07665 commit edab17d

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

crates/hyperion/src/net/proxy.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ async fn handle_proxy_messages(
8787
match result {
8888
ArchivedProxyToServerMessage::PlayerConnect(message) => {
8989
let Ok(stream) = rkyv::deserialize::<u64, !>(&message.stream);
90+
let connection_id = ConnectionId::new(stream, proxy_id);
9091

9192
let (sender, receiver) = packet_channel::channel(DEFAULT_FRAGMENT_SIZE);
9293
if player_packet_sender.insert(stream, sender).is_some() {
@@ -105,14 +106,20 @@ async fn handle_proxy_messages(
105106
receiver,
106107
))
107108
.id();
108-
world
109+
let already_exists = world
109110
.get_resource_mut::<StreamLookup>()
110111
.expect("StreamLookup resource should exist")
111-
.insert(stream, player);
112+
.insert(connection_id, player)
113+
.is_some();
114+
115+
if already_exists {
116+
error!("StreamLookup contains duplicate connection id");
117+
}
112118
});
113119
}
114120
ArchivedProxyToServerMessage::PlayerDisconnect(message) => {
115121
let Ok(stream) = rkyv::deserialize::<u64, !>(&message.stream);
122+
let connection_id = ConnectionId::new(stream, proxy_id);
116123

117124
if player_packet_sender.remove(&stream).is_none() {
118125
error!(
@@ -121,17 +128,21 @@ async fn handle_proxy_messages(
121128
}
122129

123130
command_channel.push(move |world: &mut World| {
124-
let player = world
131+
let Some(player) = world
125132
.get_resource_mut::<StreamLookup>()
126133
.expect("StreamLookup resource should exist")
127-
.remove(&stream)
128-
.expect("player from PlayerDisconnect must exist in the stream lookup map");
134+
.remove(&connection_id)
135+
else {
136+
error!("player from PlayerDisconnect must exist in the stream lookup map");
137+
return;
138+
};
129139

130140
world.despawn(player);
131141
});
132142
}
133143
ArchivedProxyToServerMessage::PlayerPackets(message) => {
134144
let Ok(stream) = rkyv::deserialize::<u64, !>(&message.stream);
145+
let connection_id = ConnectionId::new(stream, proxy_id);
135146

136147
let Some(sender) = player_packet_sender.get_mut(&stream) else {
137148
error!(
@@ -158,9 +169,7 @@ async fn handle_proxy_messages(
158169
let compose = world
159170
.get_resource::<Compose>()
160171
.expect("Compose resource should exist");
161-
compose
162-
.io_buf()
163-
.shutdown(ConnectionId::new(stream, proxy_id));
172+
compose.io_buf().shutdown(connection_id);
164173
});
165174
}
166175
}

crates/hyperion/src/simulation/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ pub mod util;
4949

5050
#[derive(Resource, Default, Debug, Deref, DerefMut)]
5151
pub struct StreamLookup {
52-
/// The UUID of all players
53-
inner: FxHashMap<u64, Entity>,
52+
/// The connection id of all players
53+
inner: FxHashMap<ConnectionId, Entity>,
5454
}
5555

5656
#[derive(Component, Default, Debug, Deref, DerefMut)]

0 commit comments

Comments
 (0)