werewolves/werewolves-proto/src/message/host.rs

85 lines
2.0 KiB
Rust
Raw Normal View History

use core::num::NonZeroU8;
use serde::{Deserialize, Serialize};
use crate::{
character::CharacterId,
error::GameError,
game::{GameOver, GameSettings},
message::{
2025-10-03 00:00:39 +01:00
CharacterIdentity,
night::{ActionPrompt, ActionResponse, ActionResult},
},
player::PlayerId,
};
use super::{CharacterState, PlayerState};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostMessage {
GetState,
Lobby(HostLobbyMessage),
InGame(HostGameMessage),
ForceRoleAckFor(CharacterId),
NewLobby,
Echo(ServerToHostMessage),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostGameMessage {
Day(HostDayMessage),
Night(HostNightMessage),
PreviousState,
GetState,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostNightMessage {
ActionResponse(ActionResponse),
Next,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostDayMessage {
Execute,
MarkForExecution(CharacterId),
}
impl From<HostDayMessage> for HostGameMessage {
fn from(value: HostDayMessage) -> Self {
HostGameMessage::Day(value)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HostLobbyMessage {
GetState,
Kick(PlayerId),
SetPlayerNumber(PlayerId, NonZeroU8),
GetGameSettings,
SetGameSettings(GameSettings),
2025-10-07 01:47:59 +01:00
SetQrMode(bool),
Start,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, werewolves_macros::Titles)]
pub enum ServerToHostMessage {
Disconnect,
Daytime {
characters: Box<[CharacterState]>,
marked: Box<[CharacterId]>,
day: NonZeroU8,
},
ActionPrompt(ActionPrompt),
ActionResult(Option<CharacterIdentity>, ActionResult),
Lobby(Box<[PlayerState]>),
2025-10-07 01:47:59 +01:00
QrMode(bool),
GameSettings(GameSettings),
Error(GameError),
GameOver(GameOver),
WaitingForRoleRevealAcks {
ackd: Box<[CharacterIdentity]>,
waiting: Box<[CharacterIdentity]>,
},
}