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:
parent
972834080b
commit
e6a024bb5b
2 changed files with 50 additions and 8 deletions
|
|
@ -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) {
|
||||||
|
|
|
||||||
22
src/main.rs
22
src/main.rs
|
|
@ -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),
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue