Skip to content

Commit

Permalink
Merge pull request #44 from w3champions/W3C-239
Browse files Browse the repository at this point in the history
[W3C-239] De-anonymize player names for observers
  • Loading branch information
fluxxu authored Oct 5, 2024
2 parents ac6547d + f74b77e commit 2f65a89
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 28 deletions.
28 changes: 15 additions & 13 deletions crates/controller/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,9 @@ pub async fn serve(state: ControllerStateRef) -> Result<()> {
let mut listener = FloListener::bind_v4(flo_constants::CONTROLLER_SOCKET_PORT).await?;
tracing::info!("listening on port {}", listener.port());

while let Some(res) = listener
.incoming()
.try_next()
.await
.transpose()
{
while let Some(res) = listener.incoming().try_next().await.transpose() {
let mut stream = match res {
Ok(stream) => {
stream
}
Ok(stream) => stream,
Err(err) => {
tracing::error!("tcp accept: {err}");
continue;
Expand Down Expand Up @@ -247,10 +240,19 @@ async fn send_initial_state(
let node_id = game.node.as_ref().map(|node| node.id);

if game.mask_player_names {
for (idx, slot) in game.slots.iter_mut().enumerate() {
slot.player.as_mut().map(|v| {
v.name = format!("Player {}", idx + 1);
});
let is_ob = game
.slots
.iter_mut()
.find(|slot| slot.player.as_ref().map(|p| p.id) == Some(player_id))
.map(|slot| slot.settings.team == 24)
.unwrap_or_default();

if !is_ob {
for (idx, slot) in game.slots.iter_mut().enumerate() {
slot.player.as_mut().map(|v| {
v.name = format!("Player {}", idx + 1);
});
}
}
}

Expand Down
9 changes: 0 additions & 9 deletions crates/controller/src/game/state/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,6 @@ impl Handler<CreateGameAsBot> for GameRegistry {
})
.await?;

if game.mask_player_names {
for (idx, slot) in game.slots.iter_mut().enumerate() {
slot
.player
.as_mut()
.map(|v| v.name = format!("Player {}", idx + 1));
}
}

self.register(Register {
id: game.id,
status: GameStatus::Preparing,
Expand Down
1 change: 0 additions & 1 deletion crates/controller/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use std::net::{Ipv4Addr, SocketAddrV4};
use std::time::Duration;
use tonic::transport::Server;
use tonic::{Request, Response, Status};
use tower_http::classify::GrpcFailureClass;
use tower_http::trace::TraceLayer;
use tracing::Span;

Expand Down
49 changes: 47 additions & 2 deletions crates/controller/src/player/state/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,41 @@ impl Handler<PlayersReplaceGame> for PlayerRegistry {
use flo_net::proto::flo_connect::*;
let game_id = game.id;

struct MaskInfo {
ob_player_ids: Vec<i32>,
frame_game_info_masked: Frame,
}

let mask_info = if game.mask_player_names {
let mut game = game.clone();
for (idx, slot) in game.slots.iter_mut().enumerate() {
slot.player.as_mut().map(|v| {
v.name = format!("Player {}", idx + 1);
});
}
Some(MaskInfo {
ob_player_ids: game
.slots
.iter()
.filter_map(|v| {
if v.settings.team == 24 {
v.player.as_ref().map(|p| p.id)
} else {
None
}
})
.collect(),
frame_game_info_masked: PacketGameInfo {
game: Some(game.pack()?),
}
.encode_as_frame()?,
})
} else {
None
};

let frame_session_update = get_session_update_packet(Some(game.id)).encode_as_frame()?;
let frame_game_info = PacketGameInfo {
let frame_game_info_original = PacketGameInfo {
game: Some(game.pack()?),
}
.encode_as_frame()?;
Expand All @@ -170,7 +203,19 @@ impl Handler<PlayersReplaceGame> for PlayerRegistry {
mute_list: mute_list_map.remove(&player_id).unwrap_or_default(),
}
.encode_as_frame()?,
frame_game_info.clone(),
if let Some(MaskInfo {
frame_game_info_masked,
ob_player_ids,
}) = &mask_info
{
if ob_player_ids.contains(&player_id) {
frame_game_info_original.clone()
} else {
frame_game_info_masked.clone()
}
} else {
frame_game_info_original.clone()
},
];
entry.get_mut().game_id = Some(game_id);
if !entry.get_mut().try_send_frames(frames.into()) {
Expand Down
3 changes: 0 additions & 3 deletions crates/lan/src/mdns/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,3 @@ impl MdnsPublisher {
.map_err(|_| Error::BonjourUpdate("worker dead: recv".to_string()))
}
}

#[derive(Clone)]
pub struct GameInfoSender(Arc<mpsc::Sender<GameInfoRef>>);

0 comments on commit 2f65a89

Please sign in to comment.