1
0
Fork 0
mirror of https://codeberg.org/demostf/sync.git synced 2026-06-03 16:44:07 +02:00

only send state to user that joined

This commit is contained in:
Robin Appelman 2019-10-27 19:31:35 +01:00
commit e6a024bb5b
2 changed files with 50 additions and 8 deletions

View file

@ -123,6 +123,42 @@ fn integration_tests() {
play: true, play: true,
}, },
); );
// owner reconnecting
std::mem::drop(owner);
let mut owner2 = test.get_client();
send(
&mut owner2,
SyncCommand::Create {
session: "foo",
token: "bar",
},
);
send(
&mut owner2,
SyncCommand::Play {
session: "foo",
play: false,
},
);
assert_receive(
&mut client,
SyncCommand::Play {
session: "foo",
play: false,
},
);
assert_receive(
&mut client2,
SyncCommand::Play {
session: "foo",
play: false,
},
);
} }
fn send<T: std::io::Write>(client: &mut Client<T>, command: SyncCommand) { fn send<T: std::io::Write>(client: &mut Client<T>, command: SyncCommand) {

View file

@ -85,15 +85,21 @@ fn handle_command(
session: session_name, session: session_name,
} => match sessions.borrow_mut().get_mut(*session_name) { } => match sessions.borrow_mut().get_mut(*session_name) {
Some(session) => { Some(session) => {
let _ = sender.send(
&serde_json::to_string(&SyncCommand::Tick {
tick: session.tick,
session: session_name,
})
.unwrap(),
);
let _ = sender.send(
&serde_json::to_string(&SyncCommand::Play {
play: session.playing,
session: session_name,
})
.unwrap(),
);
session.join(sender); session.join(sender);
session.send_command(&SyncCommand::Tick {
tick: session.tick,
session: session_name,
});
session.send_command(&SyncCommand::Play {
play: session.playing,
session: session_name,
});
} }
None => println!("session {} not found", session_name), None => println!("session {} not found", session_name),
}, },