role ack fix
This commit is contained in:
parent
c96e019071
commit
242691a05f
|
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
lobby::{Lobby, LobbyPlayers},
|
lobby::{Lobby, LobbyPlayers},
|
||||||
runner::{IdentifiedClientMessage, Message},
|
runner::{IdentifiedClientMessage, Message},
|
||||||
};
|
};
|
||||||
|
use futures::SinkExt;
|
||||||
use tokio::{sync::broadcast::Receiver, time::Instant};
|
use tokio::{sync::broadcast::Receiver, time::Instant};
|
||||||
use werewolves_proto::{
|
use werewolves_proto::{
|
||||||
error::GameError,
|
error::GameError,
|
||||||
|
|
@ -142,6 +143,41 @@ impl GameRunner {
|
||||||
Message::Host(_) => {
|
Message::Host(_) => {
|
||||||
(update_host)(&acks, &mut self.comms);
|
(update_host)(&acks, &mut self.comms);
|
||||||
}
|
}
|
||||||
|
Message::Client(IdentifiedClientMessage {
|
||||||
|
identity:
|
||||||
|
Identification {
|
||||||
|
player_id,
|
||||||
|
public: _,
|
||||||
|
},
|
||||||
|
message: ClientMessage::GetState,
|
||||||
|
}) => {
|
||||||
|
let sender =
|
||||||
|
if let Some(sender) = self.joined_players.get_sender(&player_id).await {
|
||||||
|
sender
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if acks.iter().any(|(c, d)| c.player_id() == &player_id && *d) {
|
||||||
|
// already ack'd just disconnect
|
||||||
|
sender.send(ServerMessage::Disconnect).log_debug();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(char) = self
|
||||||
|
.game
|
||||||
|
.village()
|
||||||
|
.characters()
|
||||||
|
.iter()
|
||||||
|
.find(|c| c.player_id() == &player_id)
|
||||||
|
{
|
||||||
|
sender
|
||||||
|
.send(ServerMessage::GameStart {
|
||||||
|
role: char.role().initial_shown_role(),
|
||||||
|
})
|
||||||
|
.log_debug();
|
||||||
|
} else if let Some(sender) = self.joined_players.get_sender(&player_id).await {
|
||||||
|
sender.send(ServerMessage::GameInProgress).log_debug();
|
||||||
|
}
|
||||||
|
}
|
||||||
Message::Client(IdentifiedClientMessage {
|
Message::Client(IdentifiedClientMessage {
|
||||||
identity:
|
identity:
|
||||||
Identification {
|
Identification {
|
||||||
|
|
@ -159,6 +195,9 @@ impl GameRunner {
|
||||||
.log_debug();
|
.log_debug();
|
||||||
}
|
}
|
||||||
(update_host)(&acks, &mut self.comms);
|
(update_host)(&acks, &mut self.comms);
|
||||||
|
if let Some(sender) = self.joined_players.get_sender(&player_id).await {
|
||||||
|
sender.send(ServerMessage::Disconnect).log_debug();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Message::Client(IdentifiedClientMessage {
|
Message::Client(IdentifiedClientMessage {
|
||||||
identity:
|
identity:
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,39 @@ $client_shadow_color_2: hsl(240, 55%, 61%);
|
||||||
$client_filter: drop-shadow(5px 5px 0 $client_shadow_color) drop-shadow(5px 5px 0 $client_shadow_color_2);
|
$client_filter: drop-shadow(5px 5px 0 $client_shadow_color) drop-shadow(5px 5px 0 $client_shadow_color_2);
|
||||||
|
|
||||||
|
|
||||||
|
@mixin flexbox() {
|
||||||
|
display: -webkit-box;
|
||||||
|
display: -moz-box;
|
||||||
|
display: -ms-flexbox;
|
||||||
|
display: -webkit-flex;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@mixin flex($values) {
|
||||||
|
-webkit-box-flex: $values;
|
||||||
|
-moz-box-flex: $values;
|
||||||
|
-webkit-flex: $values;
|
||||||
|
-ms-flex: $values;
|
||||||
|
flex: $values;
|
||||||
|
}
|
||||||
|
|
||||||
|
@mixin order($val) {
|
||||||
|
-webkit-box-ordinal-group: $val;
|
||||||
|
-moz-box-ordinal-group: $val;
|
||||||
|
-ms-flex-order: $val;
|
||||||
|
-webkit-order: $val;
|
||||||
|
order: $val;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrapper {
|
||||||
|
@include flexbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
.item {
|
||||||
|
@include flex(1 200px);
|
||||||
|
@include order(2);
|
||||||
|
}
|
||||||
|
|
||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
@ -738,12 +771,49 @@ input {
|
||||||
zoom: 200%;
|
zoom: 200%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.game-start-role {
|
||||||
|
@extend .column-list;
|
||||||
|
text-align: center;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
&>button {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
width: min(5cm, 30vw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.client-lobby-player-list {
|
.client-lobby-player-list {
|
||||||
|
@extend .column-list;
|
||||||
|
gap: 10px;
|
||||||
|
|
||||||
|
&>button {
|
||||||
|
width: 90vw;
|
||||||
|
align-self: center;
|
||||||
|
$leave_color: rgba(255, 0, 0, 0.6);
|
||||||
|
color: $leave_color;
|
||||||
|
border: 1px solid $leave_color;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: $leave_color;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
margin-bottom: 1cm;
|
||||||
|
}
|
||||||
|
|
||||||
|
&>.list-actual {
|
||||||
@extend .row-list;
|
@extend .row-list;
|
||||||
|
align-items: stretch;
|
||||||
|
align-content: stretch;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
&>* {
|
&>* {
|
||||||
|
width: 4cm;
|
||||||
border: 1px solid white;
|
border: 1px solid white;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
@ -754,3 +824,5 @@ input {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,11 @@ pub fn Client2(ClientProps { auto_join }: &ClientProps) -> Html {
|
||||||
let connection = use_mut_ref(|| Connection2::new(client_state.setter(), ident.clone(), recv));
|
let connection = use_mut_ref(|| Connection2::new(client_state.setter(), ident.clone(), recv));
|
||||||
|
|
||||||
let content = match &*client_state {
|
let content = match &*client_state {
|
||||||
ClientEvent2::Disconnected => html! {<p>{"disconnected"}</p>},
|
ClientEvent2::Disconnected => html! {
|
||||||
|
<div class="column-list">
|
||||||
|
<p>{"disconnected"}</p>
|
||||||
|
</div>
|
||||||
|
},
|
||||||
ClientEvent2::Connecting => {
|
ClientEvent2::Connecting => {
|
||||||
if let Err(err) = connection
|
if let Err(err) = connection
|
||||||
.try_borrow_mut()
|
.try_borrow_mut()
|
||||||
|
|
@ -307,7 +311,7 @@ pub fn Client2(ClientProps { auto_join }: &ClientProps) -> Html {
|
||||||
html! {
|
html! {
|
||||||
<div class="game-start-role">
|
<div class="game-start-role">
|
||||||
<p>{format!("Your role: {role_title}")}</p>
|
<p>{format!("Your role: {role_title}")}</p>
|
||||||
<button onclick={on_click}>{"got it"}</button>
|
<Button on_click={on_click}>{"got it"}</Button>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -349,11 +353,11 @@ pub fn Client2(ClientProps { auto_join }: &ClientProps) -> Html {
|
||||||
};
|
};
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
<div class="column-list gap">
|
<div class="client-lobby-player-list">
|
||||||
{player}
|
{player}
|
||||||
<h2>{"there are currently "}{players.len()}{" players in the lobby"}</h2>
|
<h2>{"there are currently "}{players.len()}{" players in the lobby"}</h2>
|
||||||
{button}
|
{button}
|
||||||
<div class="client-lobby-player-list">
|
<div class="list-actual">
|
||||||
{player_list}
|
{player_list}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ fn main() {
|
||||||
document.query_selector("app").unwrap().unwrap(),
|
document.query_selector("app").unwrap().unwrap(),
|
||||||
)]
|
)]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain((2..17).map(|num| {
|
.chain((1..=2).map(|num| {
|
||||||
(
|
(
|
||||||
PlayerId::from_u128(num as u128),
|
PlayerId::from_u128(num as u128),
|
||||||
format!("player {num}"),
|
format!("player {num}"),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue