start protobufs

This commit is contained in:
Adam 2024-11-15 19:39:48 -05:00
parent 1a8aabb7bf
commit a4ec55ae23
5 changed files with 172 additions and 38 deletions

103
Cargo.lock generated
View file

@ -235,9 +235,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]] [[package]]
name = "axum" name = "axum"
version = "0.7.7" version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "504e3947307ac8326a5437504c517c4b56716c9d98fac0028c2acc7ca47d70ae" checksum = "49c41b948da08fb481a94546cd874843adc1142278b0af4badf9b1b78599d68d"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"axum-core", "axum-core",
@ -810,6 +810,16 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
dependencies = [
"libc",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "event-listener" name = "event-listener"
version = "5.3.1" version = "5.3.1"
@ -837,6 +847,18 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1" checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1"
[[package]]
name = "fastrand"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4"
[[package]]
name = "fixedbitset"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.35" version = "1.0.35"
@ -1118,6 +1140,12 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.3.9" version = "0.3.9"
@ -1894,6 +1922,8 @@ name = "lib"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"prost",
"prost-build",
"rand", "rand",
"serde", "serde",
"tracing", "tracing",
@ -1911,6 +1941,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfae20f6b19ad527b550c223fddc3077a547fc70cda94b9b566575423fd303ee" checksum = "bfae20f6b19ad527b550c223fddc3077a547fc70cda94b9b566575423fd303ee"
[[package]]
name = "linux-raw-sys"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
[[package]] [[package]]
name = "litemap" name = "litemap"
version = "0.7.3" version = "0.7.3"
@ -2030,6 +2066,12 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "multimap"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03"
[[package]] [[package]]
name = "next_tuple" name = "next_tuple"
version = "0.1.0-rc1" version = "0.1.0-rc1"
@ -2197,6 +2239,16 @@ version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "petgraph"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db"
dependencies = [
"fixedbitset",
"indexmap 2.6.0",
]
[[package]] [[package]]
name = "phf" name = "phf"
version = "0.11.2" version = "0.11.2"
@ -2407,6 +2459,27 @@ dependencies = [
"prost-derive", "prost-derive",
] ]
[[package]]
name = "prost-build"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15"
dependencies = [
"bytes",
"heck",
"itertools",
"log",
"multimap",
"once_cell",
"petgraph",
"prettyplease",
"prost",
"prost-types",
"regex",
"syn",
"tempfile",
]
[[package]] [[package]]
name = "prost-derive" name = "prost-derive"
version = "0.13.3" version = "0.13.3"
@ -2643,6 +2716,19 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
[[package]]
name = "rustix"
version = "0.38.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.18" version = "1.0.18"
@ -3020,6 +3106,19 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "tempfile"
version = "3.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c"
dependencies = [
"cfg-if",
"fastrand",
"once_cell",
"rustix",
"windows-sys 0.59.0",
]
[[package]] [[package]]
name = "thaw" name = "thaw"
version = "0.4.0-beta4" version = "0.4.0-beta4"

View file

@ -5,6 +5,10 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.86" anyhow = "1.0.86"
prost = "0"
rand = "0.8.5" rand = "0.8.5"
serde = "1.0.204" serde = "1.0.204"
tracing = "0.1.40" tracing = "0.1.40"
[build-dependencies]
prost-build = "0"

View file

@ -1,65 +1,94 @@
use prost::Message;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashSet; use std::collections::HashSet;
/// Judge decision /// Judge decision
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Serialize, Deserialize, Message)]
pub struct JudgeDecisionRequest { pub struct JudgeDecisionRequest {
#[prost(string, tag = "1")]
pub game_id: String, pub game_id: String,
#[prost(string, repeated, tag = "2")]
pub winning_cards: Vec<String>, pub winning_cards: Vec<String>,
} }
/// White Card Meta
#[derive(Clone, Message, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct WhiteCardMeta {
#[prost(string, tag = "1")]
pub uuid: String,
#[prost(string, tag = "2")]
pub text: String,
}
/// Judge entry
#[derive(Clone, Message, Serialize, Deserialize)]
pub struct JudgeEntry {
#[prost(message, repeated, tag = "1")]
pub cards_to_judge: Vec<WhiteCardMeta>,
}
/// Judge round /// Judge round
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Message, Serialize, Deserialize)]
pub struct JudgeRound { pub struct JudgeRound {
pub cards_to_judge: Vec<Vec<WhiteCardMeta>>, #[prost(message, repeated, tag = "1")]
pub entries: Vec<JudgeEntry>,
} }
/// Delete game request /// Delete game request
#[derive(Debug, Serialize, Deserialize)] #[derive(Message, Serialize, Deserialize)]
pub struct GameDeleteRequest { pub struct GameDeleteRequest {
#[prost(string, tag = "1")]
pub delete_game_id: String, pub delete_game_id: String,
} }
/// Game join request /// Game join request
#[derive(Debug, Serialize, Deserialize)] #[derive(Message, Serialize, Deserialize)]
pub struct GameJoinRequest { pub struct GameJoinRequest {
#[prost(string, tag = "1")]
pub id: String, pub id: String,
} }
/// Player Move Request /// Player Move Request
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Message, Serialize, Deserialize)]
pub struct PlayerMoveRequest { pub struct PlayerMoveRequest {
#[prost(string, tag = "1")]
pub game_id: String, pub game_id: String,
#[prost(string, repeated, tag = "2")]
pub card_ids: Vec<String>, pub card_ids: Vec<String>,
} }
/// White Card Meta
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct WhiteCardMeta {
pub uuid: String,
pub text: String,
}
/// Game Player Meta /// Game Player Meta
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Message, Serialize, Deserialize)]
pub struct GamePlayerMeta { pub struct GamePlayerMeta {
#[prost(string, tag = "1")]
pub name: String, pub name: String,
pub score: usize, #[prost(uint32, tag = "2")]
pub score: u32,
#[prost(bool, tag = "3")]
pub submitted: bool, pub submitted: bool,
} }
/// Game meta /// Game meta
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Message, Serialize, Deserialize)]
pub struct GameMeta { pub struct GameMeta {
#[prost(string, tag = "1")]
pub uuid: String, pub uuid: String,
#[prost(string, tag = "2")]
pub name: String, pub name: String,
#[prost(string, tag = "3")]
pub host: String, pub host: String,
#[prost(message, repeated, tag = "4")]
pub players: Vec<GamePlayerMeta>, pub players: Vec<GamePlayerMeta>,
#[prost(string, tag = "5")]
pub czar: String, pub czar: String,
#[prost(bytes, tag = "6")]
pub packs: Vec<u8>, pub packs: Vec<u8>,
pub white_count: usize, #[prost(uint32, tag = "7")]
pub black_count: usize, pub white_count: u32,
pub white_discard_count: usize, #[prost(uint32, tag = "8")]
pub black_count: u32,
#[prost(uint32, tag = "9")]
pub white_discard_count: u32,
} }
/// Game state meta /// Game state meta

View file

@ -208,24 +208,26 @@ impl Game {
} }
Ok(Some(( Ok(Some((
JudgeRound { JudgeRound {
cards_to_judge: self entries: self
.judge_pile_meta .judge_pile_meta
.keys() .keys()
.into_iter() .into_iter()
.map(|group| { .map(|group| {
group JudgeEntry {
.iter() cards_to_judge: group
.map(|id| { .iter()
let card = self.judge_pile.get(id).unwrap().clone(); .map(|id| {
// TODO: Make sure card exists let card = self.judge_pile.get(id).unwrap().clone();
WhiteCardMeta { // TODO: Make sure card exists
uuid: card.uuid.to_string(), WhiteCardMeta {
text: card.text.clone(), uuid: card.uuid.to_string(),
} text: card.text.clone(),
}) }
.collect() })
.collect(),
}
}) })
.collect(), .collect::<Vec<JudgeEntry>>(),
}, },
self.czar.read().unwrap().uuid.clone(), self.czar.read().unwrap().uuid.clone(),
))) )))

View file

@ -202,7 +202,7 @@ impl GameHandler {
.values() .values()
.map(|player| GamePlayerMeta { .map(|player| GamePlayerMeta {
name: player.user.read().unwrap().name.clone(), name: player.user.read().unwrap().name.clone(),
score: player.black.len(), score: player.black.len().try_into().unwrap(),
submitted: this_game submitted: this_game
.judge_pile_meta .judge_pile_meta
.values() .values()
@ -220,9 +220,9 @@ impl GameHandler {
players: players.clone(), players: players.clone(),
czar: this_game.czar.read().unwrap().name.clone(), czar: this_game.czar.read().unwrap().name.clone(),
packs: this_game.packs.clone(), packs: this_game.packs.clone(),
white_count: this_game.white.len(), white_count: this_game.white.len().try_into().unwrap(),
black_count: this_game.black.len(), black_count: this_game.black.len().try_into().unwrap(),
white_discard_count: this_game.white_discard.len(), white_discard_count: this_game.white_discard.len().try_into().unwrap(),
}; };
// Send user's update // Send user's update