No known key found for this signature in database
GPG Key ID: 1F45A7C4BFB41607
6 changed files with
30 additions and
7 deletions
README.md
protobuf/game.proto
server/src/db.rs
server/src/games/run.rs
server/src/server/game.rs
server/src/server/grpc/game.rs
@ -110,4 +110,4 @@ See for example the `shuffle` function, which is provided by the environment.
Go to the [rhai book ](https://schungx.github.io/rhai/language/index.html ) for the language reference.
### Common errors:
* When taking more cards than are available from a pile, `()` (null or undefined) is returned, that happens for example when too many people try to play a game where a specific number of cards from a deck are give to each player, and there are too many players for the amount of cards in the deck
* When taking more cards than are available from a pile, `()` (null or undefined) is returned, that happens for example when too many people try to play a game where a specific number of cards from a deck are given to each player, and there are too many players for the amount of cards in the deck
@ -1,7 +1,7 @@
syntax = "proto3" ;
import "google/protobuf/empty.proto" ;
/ / import "common.proto" ;
import "common.proto" ;
package game ;
@ -54,7 +54,8 @@ message MessageStatus {
map < string , Pile > piles = 1 ;
}
Piles commonPiles = 1 ;
repeated Piles playerPiles = 2 ;
uint32 currentTurn = 3 ;
Piles commonPiles = 1 ; / / { a : [ "" ] , b : [ "" ] }
repeated Piles playerPiles = 2 ; / / [ { . . . } , { . . . } ]
repeated common.Name names = 3 ;
uint32 currentTurn = 4 ;
}
@ -96,6 +96,17 @@ impl Db {
. unwrap ( )
}
// FIXME: return Results intead of crashing
pub fn get_name_for_uuid ( & mut self , uuid : Uuid ) -> String {
let mut prepared = self . conn . prepare_cached ( "SELECT Name FROM Users WHERE UUID = ?" ) . unwrap ( ) ;
prepared
. query ( params ! [ uuid . as_bytes ( ) . to_vec ( ) ] )
. and_then ( | mut r | {
r . next ( ) . and_then ( | r | r . unwrap ( ) . get ::< _ , String > ( 0 ) )
} )
. unwrap ( )
}
// FIXME: return Results intead of crashing
pub fn create_lobby ( & mut self , public : bool ) -> u32 {
let id = rand ::random ( ) ;
@ -24,7 +24,7 @@ pub struct RunningGame {
functions : Functions ,
current_player : Player ,
data : HashMap < String , serde_json ::Value > ,
players : HashMap < Uuid , u32 > ,
pub players : HashMap < Uuid , u32 > ,
}
// TODO add errors
@ -139,6 +139,12 @@ impl game_server::Game for GameService {
}
} ;
let game = & game_lock . 1 ;
let mut names = vec ! [ ] ;
for ( uuid , id ) in & game . players {
names . push ( ( conn . get_name_for_uuid ( uuid . clone ( ) ) . await , * id ) )
}
names . sort_by ( | ( _ , a ) , ( _ , b ) | a . cmp ( b ) ) ;
let names = names . into_iter ( ) . map ( | ( x , _ ) | super ::grpc ::common ::Name { name : x } ) . collect ( ) ;
let status = MessageStatus {
current_turn : game . get_current_player ( ) ,
common_piles : Some ( Piles {
@ -164,6 +170,7 @@ impl game_server::Game for GameService {
. collect ( ) ,
} ) ,
player_piles : vec ! [ ] ,
names ,
} ;
Ok ( Response ::new ( status ) )
}
@ -51,11 +51,15 @@ pub struct CardId {
}
#[ derive(Clone, PartialEq, ::prost::Message) ]
pub struct MessageStatus {
/// {a: [""], b:[""]}
#[ prost(message, optional, tag = " 1 " ) ]
pub common_piles : ::std ::option ::Option < message_status ::Piles > ,
/// [{...}, {...}]
#[ prost(message, repeated, tag = " 2 " ) ]
pub player_piles : ::std ::vec ::Vec < message_status ::Piles > ,
#[ prost(uint32, tag = " 3 " ) ]
#[ prost(message, repeated, tag = " 3 " ) ]
pub names : ::std ::vec ::Vec < super ::common ::Name > ,
#[ prost(uint32, tag = " 4 " ) ]
pub current_turn : u32 ,
}
pub mod message_status {