From 2db8f29c74d11cefc9f0138e348a3b95c3eb051f Mon Sep 17 00:00:00 2001 From: ThePerkinrex Date: Tue, 17 Nov 2020 17:53:36 +0100 Subject: [PATCH] Add public lobbies --- protobuf/game.proto | 42 +-- server/src/db.rs | 37 ++- server/src/games/run.rs | 2 + server/src/grpc.rs | 122 ++++--- server/src/grpc/game.rs | 155 +++++---- server/src/logger/color_message.rs | 58 ++-- server/src/setup.sql | 3 +- unity/Assets/Scripts/Client.cs | 20 +- .../Editor}/BuildProtos.cs | 0 .../Editor}/BuildProtos.cs.meta | 2 +- unity/Assets/Scripts/MainMenuController.cs | 11 +- unity/Assets/Scripts/grpc/Game.cs | 299 ++++++++++++++---- unity/Assets/Scripts/grpc/GameGrpc.cs | 97 +++--- 13 files changed, 579 insertions(+), 269 deletions(-) rename unity/Assets/{EditorScripts => Scripts/Editor}/BuildProtos.cs (100%) rename unity/Assets/{EditorScripts => Scripts/Editor}/BuildProtos.cs.meta (83%) diff --git a/protobuf/game.proto b/protobuf/game.proto index 48dddad..7b90e66 100644 --- a/protobuf/game.proto +++ b/protobuf/game.proto @@ -2,41 +2,43 @@ syntax = "proto3"; package game; +// TODO Reorganize this file + // Connection utilities to get a client_id service Connection { rpc name(Null) returns(Name); rpc connect(Name) returns(UserID); rpc joinLobbyWithCode(LobbyCode) returns(Null); - rpc joinLobbyWithoutCode(Null) returns(LobbyCode); + rpc createLobby(LobbyConfig) returns(LobbyCode); + rpc getGames(Null) returns(stream Game); + rpc getPublicLobbies (Null) returns (stream LobbyCode); } // Lobby functionality (client_id required for most of them) service Lobby { - rpc getGames(Null) returns(stream Game); - rpc getCardImage(CardID) returns (Image); + rpc getCardImage(CardID) returns(Image); rpc vote(Vote) returns(Null); - rpc ready (Null) returns (Null); - rpc status (Null) returns (LobbyStatus); + rpc ready(Null) returns(Null); + rpc status(Null) returns(LobbyStatus); } -message UserID { - string id = 1; -} +message UserID { string id = 1; } -message Name { - string name = 1; +message Name { string name = 1; } + +message LobbyConfig { + bool public = 1; + // repeated uint32 allowed_games = 2; } message Null {} message CardID { - uint64 gameId = 1; + uint32 gameId = 1; string cardId = 2; } -message Image { - bytes content = 1; -} +message Image { bytes content = 1; } message LobbyCode { uint32 code = 1; } @@ -44,18 +46,18 @@ message Game { string name = 1; string version = 2; repeated string authors = 3; - uint64 id = 4; + uint32 id = 4; } message Vote { uint64 id = 1; } message LobbyStatus { - repeated Vote votes = 1; - repeated Player ready = 2; - bool isStarting = 3; + repeated Vote votes = 1; + repeated Player ready = 2; + bool isStarting = 3; } message Player { - string name = 1; - uint64 id = 2; + string name = 1; + uint32 id = 2; } \ No newline at end of file diff --git a/server/src/db.rs b/server/src/db.rs index 3c073b8..a8f78bb 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -1,5 +1,8 @@ -use sqlx::{pool::PoolConnection, prelude::*, query_unchecked, query_as, query_file_unchecked, SqliteConnection, SqlitePool}; -use tokio::stream::StreamExt; +use sqlx::{ + pool::PoolConnection, prelude::*, query_as, query_file_unchecked, query_unchecked, FromRow, + SqliteConnection, SqlitePool, +}; +// use tokio::stream::StreamExt; pub mod types; @@ -39,8 +42,7 @@ pub struct DbConnection { use uuid::Uuid; - -// TODO: return Results intead of crashing +// FIXME: return Results intead of crashing impl DbConnection { fn new(conn: PoolConnection) -> Self { Self { conn } @@ -60,19 +62,20 @@ impl DbConnection { uuid } - pub async fn users(&mut self) -> Vec { - query_as::<_, types::User>("SELECT UUID, Name FROM Users") - .fetch_all(&mut self.conn) - .await - .unwrap() - } + // pub async fn users(&mut self) -> Vec { + // query_as::<_, types::User>("SELECT UUID, Name FROM Users") + // .fetch_all(&mut self.conn) + // .await + // .unwrap() + // } - pub async fn create_lobby(&mut self) -> u32 { + pub async fn create_lobby(&mut self, public: bool) -> u32 { let id = rand::random(); self.conn .execute(query_unchecked!( - "INSERT INTO Lobbies(id) VALUES(?)", - id as i32 + "INSERT INTO Lobbies(id, public) VALUES(?, ?)", + id as i32, + public )) .await .unwrap(); // Server crashes if ids collide @@ -93,5 +96,11 @@ impl DbConnection { pub async fn close(self) { self.conn.close().await.unwrap(); } -} + pub async fn getPublicLobbies(&mut self) -> Vec { + query_as::<_, (i32,)>("SELECT ID FROM Lobbies WHERE Public = TRUE") + .fetch_all(&mut self.conn) + .await + .unwrap().into_iter().map(|(x,)| x as u32).collect() + } +} diff --git a/server/src/games/run.rs b/server/src/games/run.rs index 4ebc977..06b8301 100644 --- a/server/src/games/run.rs +++ b/server/src/games/run.rs @@ -25,7 +25,9 @@ struct Setup { } pub struct RunningGame { + #[allow(unused)] // TODO remove piles: HashMap, + #[allow(unused)] // TODO remove player_piles: Vec>, } diff --git a/server/src/grpc.rs b/server/src/grpc.rs index 348cd88..c5fde2b 100644 --- a/server/src/grpc.rs +++ b/server/src/grpc.rs @@ -4,17 +4,19 @@ use log::info; use std::sync::Arc; +#[allow(non_camel_case_types)] mod game; use game::connection_server::{Connection, ConnectionServer}; use game::lobby_server::{Lobby, LobbyServer}; -use game::{LobbyCode, Null, UserId, Name, CardId, Image}; +use game::{CardId, LobbyCode, Image, LobbyConfig, Name, Null, UserId}; use crate::db; pub struct ConnectionService { conn: Arc, - properties: Arc + properties: Arc, + games: Arc>, } #[tonic::async_trait] @@ -36,39 +38,71 @@ impl Connection for ConnectionService { ) -> Result, Status> { let uuid = client_id::get(request.metadata()).map_err(|x| match x { client_id::Error::NotSet => Status::failed_precondition("client_id must be set"), - client_id::Error::MalformedUuid => Status::failed_precondition("malformed client_id") + client_id::Error::MalformedUuid => Status::failed_precondition("malformed client_id"), })?; let lobby = request.get_ref().code; let mut conn = self.conn.acquire().await; conn.join_lobby(uuid, lobby).await; conn.close().await; - Ok(Response::new(Null{})) + Ok(Response::new(Null {})) } - async fn join_lobby_without_code( + async fn create_lobby( &self, - request: Request, + request: Request, ) -> Result, Status> { let uuid = client_id::get(request.metadata()).map_err(|x| match x { client_id::Error::NotSet => Status::failed_precondition("client_id must be set"), - client_id::Error::MalformedUuid => Status::failed_precondition("malformed client_id") + client_id::Error::MalformedUuid => Status::failed_precondition("malformed client_id"), })?; let mut conn = self.conn.acquire().await; - let lobby = conn.create_lobby().await; + let lobby = conn.create_lobby(request.into_inner().public).await; conn.join_lobby(uuid, lobby).await; conn.close().await; - Ok(Response::new(LobbyCode{code: lobby})) + Ok(Response::new(LobbyCode { code: lobby })) + } + + async fn name(&self, _request: Request) -> Result, Status> { + Ok(Response::new(game::Name { + name: self.properties.name.clone(), + })) + } + + type getGamesStream = mpsc::UnboundedReceiver>; + + async fn get_games(&self, _: Request) -> Result, Status> { + let (sender, receiver) = mpsc::unbounded_channel(); + for (id, game) in self.games.iter().enumerate() { + sender + .send(Ok(game::Game { + id: id as u32, + name: game.name.clone(), + version: game.version.clone(), + authors: game.authors.clone(), + })) + .unwrap(); + } + Ok(Response::new(receiver)) } - async fn name( + type getPublicLobbiesStream = mpsc::UnboundedReceiver>; + + async fn get_public_lobbies( &self, _request: Request, - ) -> Result, Status> { - Ok(Response::new(game::Name {name: self.properties.name.clone() })) + ) -> Result, Status> { + let (sender, receiver) = mpsc::unbounded_channel(); + let mut conn = self.conn.acquire().await; + for id in conn.getPublicLobbies().await { + sender + .send(Ok(LobbyCode{code: id})) + .unwrap(); + } + conn.close(); + Ok(Response::new(receiver)) } } - use tokio::sync::mpsc; pub struct LobbyService { @@ -78,55 +112,51 @@ pub struct LobbyService { #[tonic::async_trait] impl Lobby for LobbyService { - type getGamesStream = mpsc::UnboundedReceiver>; - - async fn get_games( - &self, - _: Request, - ) -> Result, Status> { - let (sender, receiver) = mpsc::unbounded_channel(); - for (id, game) in self.games.iter().enumerate() { - sender.send(Ok(game::Game {id: id as u64, name: game.name.clone(), version: game.version.clone(), authors: game.authors.clone()})).unwrap(); - } - Ok(Response::new(receiver)) - } - - async fn get_card_image(&self, request: tonic::Request) -> Result, tonic::Status> { + async fn get_card_image( + &self, + request: tonic::Request, + ) -> Result, tonic::Status> { let id = request.into_inner(); let game = &self.games.as_ref()[id.game_id as usize]; let card = game.get_card_path(&id.card_id); let mut buffer = Vec::new(); - image::open(&card).expect(&format!("Error loading the image in {:?}", card)).write_to(&mut buffer, image::ImageOutputFormat::Png).unwrap(); - Ok(Response::new(Image {content: buffer})) + image::open(&card) + .expect(&format!("Error loading the image in {:?}", card)) + .write_to(&mut buffer, image::ImageOutputFormat::Png) + .unwrap(); + Ok(Response::new(Image { content: buffer })) } - async fn vote( - &self, - request: Request, - ) -> Result, Status> { + async fn vote(&self, _request: Request) -> Result, Status> { todo!() } - async fn ready( - &self, - request: Request, - ) -> Result, Status> { + async fn ready(&self, _request: Request) -> Result, Status> { todo!() } - async fn status( - &self, - request: Request, - ) -> Result, Status> { + async fn status(&self, _request: Request) -> Result, Status> { todo!() } } -pub async fn start(pool: db::DbPool, games: Vec, properties: crate::server_properties::ServerProperties) { +pub async fn start( + pool: db::DbPool, + games: Vec, + properties: crate::server_properties::ServerProperties, +) { let arc = Arc::new(pool); let properties = Arc::new(properties); - let connection = ConnectionService { conn: arc.clone(), properties }; - let lobby = LobbyService {conn: arc.clone(), games: Arc::new(games)}; + let games = Arc::new(games); + let connection = ConnectionService { + conn: arc.clone(), + properties, + games: games.clone(), + }; + let lobby = LobbyService { + conn: arc.clone(), + games, + }; Server::builder() .add_service(ConnectionServer::new(connection)) @@ -137,9 +167,7 @@ pub async fn start(pool: db::DbPool, games: Vec, properties: } mod client_id { - pub fn get( - metadata: &tonic::metadata::MetadataMap, - ) -> Result { + pub fn get(metadata: &tonic::metadata::MetadataMap) -> Result { metadata .get("client_id") .ok_or(Error::NotSet) diff --git a/server/src/grpc/game.rs b/server/src/grpc/game.rs index 366d02f..b93794a 100644 --- a/server/src/grpc/game.rs +++ b/server/src/grpc/game.rs @@ -9,11 +9,17 @@ pub struct Name { pub name: std::string::String, } #[derive(Clone, PartialEq, ::prost::Message)] +pub struct LobbyConfig { + /// repeated uint32 allowed_games = 2; + #[prost(bool, tag = "1")] + pub public: bool, +} +#[derive(Clone, PartialEq, ::prost::Message)] pub struct Null {} #[derive(Clone, PartialEq, ::prost::Message)] pub struct CardId { - #[prost(uint64, tag = "1")] - pub game_id: u64, + #[prost(uint32, tag = "1")] + pub game_id: u32, #[prost(string, tag = "2")] pub card_id: std::string::String, } @@ -35,8 +41,8 @@ pub struct Game { pub version: std::string::String, #[prost(string, repeated, tag = "3")] pub authors: ::std::vec::Vec, - #[prost(uint64, tag = "4")] - pub id: u64, + #[prost(uint32, tag = "4")] + pub id: u32, } #[derive(Clone, PartialEq, ::prost::Message)] pub struct Vote { @@ -56,8 +62,8 @@ pub struct LobbyStatus { pub struct Player { #[prost(string, tag = "1")] pub name: std::string::String, - #[prost(uint64, tag = "2")] - pub id: u64, + #[prost(uint32, tag = "2")] + pub id: u32, } #[doc = r" Generated server implementations."] pub mod connection_server { @@ -78,10 +84,28 @@ pub mod connection_server { &self, request: tonic::Request, ) -> Result, tonic::Status>; - async fn join_lobby_without_code( + async fn create_lobby( &self, - request: tonic::Request, + request: tonic::Request, ) -> Result, tonic::Status>; + #[doc = "Server streaming response type for the getGames method."] + type getGamesStream: Stream> + + Send + + Sync + + 'static; + async fn get_games( + &self, + request: tonic::Request, + ) -> Result, tonic::Status>; + #[doc = "Server streaming response type for the getPublicLobbies method."] + type getPublicLobbiesStream: Stream> + + Send + + Sync + + 'static; + async fn get_public_lobbies( + &self, + request: tonic::Request, + ) -> Result, tonic::Status>; } #[doc = " Connection utilities to get a client_id"] #[derive(Debug)] @@ -203,16 +227,18 @@ pub mod connection_server { }; Box::pin(fut) } - "/game.Connection/joinLobbyWithoutCode" => { + "/game.Connection/createLobby" => { #[allow(non_camel_case_types)] - struct joinLobbyWithoutCodeSvc(pub Arc); - impl tonic::server::UnaryService for joinLobbyWithoutCodeSvc { + struct createLobbySvc(pub Arc); + impl tonic::server::UnaryService for createLobbySvc { type Response = super::LobbyCode; type Future = BoxFuture, tonic::Status>; - fn call(&mut self, request: tonic::Request) -> Self::Future { + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { let inner = self.0.clone(); - let fut = - async move { (*inner).join_lobby_without_code(request).await }; + let fut = async move { (*inner).create_lobby(request).await }; Box::pin(fut) } } @@ -220,7 +246,7 @@ pub mod connection_server { let fut = async move { let interceptor = inner.1.clone(); let inner = inner.0; - let method = joinLobbyWithoutCodeSvc(inner); + let method = createLobbySvc(inner); let codec = tonic::codec::ProstCodec::default(); let mut grpc = if let Some(interceptor) = interceptor { tonic::server::Grpc::with_interceptor(codec, interceptor) @@ -232,6 +258,66 @@ pub mod connection_server { }; Box::pin(fut) } + "/game.Connection/getGames" => { + #[allow(non_camel_case_types)] + struct getGamesSvc(pub Arc); + impl tonic::server::ServerStreamingService for getGamesSvc { + type Response = super::Game; + type ResponseStream = T::getGamesStream; + type Future = + BoxFuture, tonic::Status>; + fn call(&mut self, request: tonic::Request) -> Self::Future { + let inner = self.0.clone(); + let fut = async move { (*inner).get_games(request).await }; + Box::pin(fut) + } + } + let inner = self.inner.clone(); + let fut = async move { + let interceptor = inner.1; + let inner = inner.0; + let method = getGamesSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = if let Some(interceptor) = interceptor { + tonic::server::Grpc::with_interceptor(codec, interceptor) + } else { + tonic::server::Grpc::new(codec) + }; + let res = grpc.server_streaming(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/game.Connection/getPublicLobbies" => { + #[allow(non_camel_case_types)] + struct getPublicLobbiesSvc(pub Arc); + impl tonic::server::ServerStreamingService for getPublicLobbiesSvc { + type Response = super::LobbyCode; + type ResponseStream = T::getPublicLobbiesStream; + type Future = + BoxFuture, tonic::Status>; + fn call(&mut self, request: tonic::Request) -> Self::Future { + let inner = self.0.clone(); + let fut = async move { (*inner).get_public_lobbies(request).await }; + Box::pin(fut) + } + } + let inner = self.inner.clone(); + let fut = async move { + let interceptor = inner.1; + let inner = inner.0; + let method = getPublicLobbiesSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = if let Some(interceptor) = interceptor { + tonic::server::Grpc::with_interceptor(codec, interceptor) + } else { + tonic::server::Grpc::new(codec) + }; + let res = grpc.server_streaming(method, req).await; + Ok(res) + }; + Box::pin(fut) + } _ => Box::pin(async move { Ok(http::Response::builder() .status(200) @@ -269,15 +355,6 @@ pub mod lobby_server { #[doc = "Generated trait containing gRPC methods that should be implemented for use with LobbyServer."] #[async_trait] pub trait Lobby: Send + Sync + 'static { - #[doc = "Server streaming response type for the getGames method."] - type getGamesStream: Stream> - + Send - + Sync - + 'static; - async fn get_games( - &self, - request: tonic::Request, - ) -> Result, tonic::Status>; async fn get_card_image( &self, request: tonic::Request, @@ -328,36 +405,6 @@ pub mod lobby_server { fn call(&mut self, req: http::Request) -> Self::Future { let inner = self.inner.clone(); match req.uri().path() { - "/game.Lobby/getGames" => { - #[allow(non_camel_case_types)] - struct getGamesSvc(pub Arc); - impl tonic::server::ServerStreamingService for getGamesSvc { - type Response = super::Game; - type ResponseStream = T::getGamesStream; - type Future = - BoxFuture, tonic::Status>; - fn call(&mut self, request: tonic::Request) -> Self::Future { - let inner = self.0.clone(); - let fut = async move { (*inner).get_games(request).await }; - Box::pin(fut) - } - } - let inner = self.inner.clone(); - let fut = async move { - let interceptor = inner.1; - let inner = inner.0; - let method = getGamesSvc(inner); - let codec = tonic::codec::ProstCodec::default(); - let mut grpc = if let Some(interceptor) = interceptor { - tonic::server::Grpc::with_interceptor(codec, interceptor) - } else { - tonic::server::Grpc::new(codec) - }; - let res = grpc.server_streaming(method, req).await; - Ok(res) - }; - Box::pin(fut) - } "/game.Lobby/getCardImage" => { #[allow(non_camel_case_types)] struct getCardImageSvc(pub Arc); diff --git a/server/src/logger/color_message.rs b/server/src/logger/color_message.rs index 70973d7..bc3a5b1 100644 --- a/server/src/logger/color_message.rs +++ b/server/src/logger/color_message.rs @@ -1,36 +1,34 @@ -use crossterm::{ - cursor::{MoveRight, MoveToNextLine}, - event::{Event, KeyCode, KeyModifiers, MouseEvent}, - queue, - style::{Print, PrintStyledContent}, -}; +use crossterm::{queue, style::Print}; use std::io::Write; pub fn print_line(message: &String, use_colors: bool, stdout: &mut std::io::Stdout) { - if use_colors { - let mut s = String::new(); - let mut highlight = false; - for c in message.chars() { - - if c == '`' { - // queue!(stdout, Print(format!("{}`", highlight))).unwrap(); - if highlight { - let styled = format!("\x1B[{}m{}\x1B[0m", fern::colors::Color::Blue.to_fg_str(), s); - queue!(stdout, Print(styled)).unwrap(); - s = String::new(); - }else{ - queue!(stdout, Print(s)).unwrap(); - s = String::new(); - } - highlight = !highlight; - continue; - } + if use_colors { + let mut s = String::new(); + let mut highlight = false; + for c in message.chars() { + if c == '`' { + // queue!(stdout, Print(format!("{}`", highlight))).unwrap(); + if highlight { + let styled = format!( + "\x1B[{}m{}\x1B[0m", + fern::colors::Color::Blue.to_fg_str(), + s + ); + queue!(stdout, Print(styled)).unwrap(); + s = String::new(); + } else { + queue!(stdout, Print(s)).unwrap(); + s = String::new(); + } + highlight = !highlight; + continue; + } - s.push(c); - } - queue!(stdout, Print(&s)).unwrap(); - }else { - queue!(stdout, Print(message)).unwrap(); - } + s.push(c); + } + queue!(stdout, Print(&s)).unwrap(); + } else { + queue!(stdout, Print(message)).unwrap(); + } } diff --git a/server/src/setup.sql b/server/src/setup.sql index 8b959f7..90db7ab 100644 --- a/server/src/setup.sql +++ b/server/src/setup.sql @@ -11,7 +11,8 @@ CREATE TABLE Users ( ); CREATE TABLE Lobbies ( - ID INT NOT NULL UNIQUE PRIMARY KEY + ID INT NOT NULL UNIQUE PRIMARY KEY, + Public BOOLEAN DEFAULT false ); CREATE TABLE UsersInLobbies ( diff --git a/unity/Assets/Scripts/Client.cs b/unity/Assets/Scripts/Client.cs index 9c2be37..0c2bfde 100644 --- a/unity/Assets/Scripts/Client.cs +++ b/unity/Assets/Scripts/Client.cs @@ -50,9 +50,9 @@ public static class Client connection.joinLobbyWithCode(new Game.LobbyCode { Code = (uint)lobby }, new Metadata { new Metadata.Entry("client_id", connId) }); } - public string CreateLobby() + public string CreateLobby(bool isPublic) { - lobby = connection.joinLobbyWithoutCode(new Game.Null(), new Metadata { new Metadata.Entry("client_id", connId) }).Code; + lobby = connection.createLobby(new Game.LobbyConfig {Public = isPublic}, new Metadata { new Metadata.Entry("client_id", connId) }).Code; return Base32.ToString((uint)lobby); } @@ -68,9 +68,23 @@ public static class Client } } + public List getPublicLobbies() { + AsyncServerStreamingCall stream = connection.getPublicLobbies(new Game.Null()); + List l = new List(); + + while (runSync(stream.ResponseStream.MoveNext())) + { + Game.LobbyCode g = stream.ResponseStream.Current; + l.Add(Base32.ToString(g.Code)); + // Debug.Log("Received " + feature.ToString()); + } + // Debug.Log(stream.ResponseStream.Current); + return l; + } + public List getGames() { - AsyncServerStreamingCall stream = lobby_client.getGames(new Game.Null()); + AsyncServerStreamingCall stream = connection.getGames(new Game.Null()); List l = new List(); while (runSync(stream.ResponseStream.MoveNext())) diff --git a/unity/Assets/EditorScripts/BuildProtos.cs b/unity/Assets/Scripts/Editor/BuildProtos.cs similarity index 100% rename from unity/Assets/EditorScripts/BuildProtos.cs rename to unity/Assets/Scripts/Editor/BuildProtos.cs diff --git a/unity/Assets/EditorScripts/BuildProtos.cs.meta b/unity/Assets/Scripts/Editor/BuildProtos.cs.meta similarity index 83% rename from unity/Assets/EditorScripts/BuildProtos.cs.meta rename to unity/Assets/Scripts/Editor/BuildProtos.cs.meta index 1bfb8e1..e0b2459 100644 --- a/unity/Assets/EditorScripts/BuildProtos.cs.meta +++ b/unity/Assets/Scripts/Editor/BuildProtos.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d503170ae4972ff3db5f76af29a9d5d0 +guid: b147307868234ce40afbc5ba5dc4a020 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/unity/Assets/Scripts/MainMenuController.cs b/unity/Assets/Scripts/MainMenuController.cs index 96fecae..379a3dc 100644 --- a/unity/Assets/Scripts/MainMenuController.cs +++ b/unity/Assets/Scripts/MainMenuController.cs @@ -108,7 +108,7 @@ public class MainMenuController : MonoBehaviour { if (conn != null) { var lobby = conn.GetLobby(); if (lobby == null) { - lobby = conn.CreateLobby(); + lobby = conn.CreateLobby(true); mainMenu.SetActive(false); serverMenu.SetActive(false); lobbyMenu.SetActive(true); @@ -138,6 +138,13 @@ public class MainMenuController : MonoBehaviour { DestroyImmediate(serverScroll.transform.GetChild(i).gameObject); } // Simulate Lobbies in a Server + var conn = Client.GetConnection(); + if(conn != null) { + foreach(string lobby in conn.getPublicLobbies()) { + Debug.Log(lobby); + } + // conn.Close(); + } for (int i = 0; i < Random.Range(2, 15); i++) { var lobby = Instantiate(serverScroll.transform.GetChild(0), serverScroll.transform); lobby.GetComponentInChildren().text = "LBY" + Random.Range(0, 10) + Random.Range(0, 10) + Random.Range(0, 10); @@ -161,7 +168,9 @@ public class MainMenuController : MonoBehaviour { gameGO.GetComponentsInChildren()[2].text = string.Join(", ", game.Authors); gameGO.gameObject.SetActive(true); } + // conn.Close(); } + lobbyMenu.GetComponentInChildren().Reload(); } } diff --git a/unity/Assets/Scripts/grpc/Game.cs b/unity/Assets/Scripts/grpc/Game.cs index dabb116..e0317f4 100644 --- a/unity/Assets/Scripts/grpc/Game.cs +++ b/unity/Assets/Scripts/grpc/Game.cs @@ -25,28 +25,30 @@ namespace Game { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "CgpnYW1lLnByb3RvEgRnYW1lIhQKBlVzZXJJRBIKCgJpZBgBIAEoCSIUCgRO", - "YW1lEgwKBG5hbWUYASABKAkiBgoETnVsbCIoCgZDYXJkSUQSDgoGZ2FtZUlk", - "GAEgASgEEg4KBmNhcmRJZBgCIAEoCSIYCgVJbWFnZRIPCgdjb250ZW50GAEg", - "ASgMIhkKCUxvYmJ5Q29kZRIMCgRjb2RlGAEgASgNIkIKBEdhbWUSDAoEbmFt", - "ZRgBIAEoCRIPCgd2ZXJzaW9uGAIgASgJEg8KB2F1dGhvcnMYAyADKAkSCgoC", - "aWQYBCABKAQiEgoEVm90ZRIKCgJpZBgBIAEoBCJZCgtMb2JieVN0YXR1cxIZ", - "CgV2b3RlcxgBIAMoCzIKLmdhbWUuVm90ZRIbCgVyZWFkeRgCIAMoCzIMLmdh", - "bWUuUGxheWVyEhIKCmlzU3RhcnRpbmcYAyABKAgiIgoGUGxheWVyEgwKBG5h", - "bWUYASABKAkSCgoCaWQYAiABKAQyuAEKCkNvbm5lY3Rpb24SHgoEbmFtZRIK", - "LmdhbWUuTnVsbBoKLmdhbWUuTmFtZRIjCgdjb25uZWN0EgouZ2FtZS5OYW1l", - "GgwuZ2FtZS5Vc2VySUQSMAoRam9pbkxvYmJ5V2l0aENvZGUSDy5nYW1lLkxv", - "YmJ5Q29kZRoKLmdhbWUuTnVsbBIzChRqb2luTG9iYnlXaXRob3V0Q29kZRIK", - "LmdhbWUuTnVsbBoPLmdhbWUuTG9iYnlDb2RlMsIBCgVMb2JieRIkCghnZXRH", - "YW1lcxIKLmdhbWUuTnVsbBoKLmdhbWUuR2FtZTABEikKDGdldENhcmRJbWFn", - "ZRIMLmdhbWUuQ2FyZElEGgsuZ2FtZS5JbWFnZRIeCgR2b3RlEgouZ2FtZS5W", - "b3RlGgouZ2FtZS5OdWxsEh8KBXJlYWR5EgouZ2FtZS5OdWxsGgouZ2FtZS5O", - "dWxsEicKBnN0YXR1cxIKLmdhbWUuTnVsbBoRLmdhbWUuTG9iYnlTdGF0dXNi", - "BnByb3RvMw==")); + "YW1lEgwKBG5hbWUYASABKAkiHQoLTG9iYnlDb25maWcSDgoGcHVibGljGAEg", + "ASgIIgYKBE51bGwiKAoGQ2FyZElEEg4KBmdhbWVJZBgBIAEoDRIOCgZjYXJk", + "SWQYAiABKAkiGAoFSW1hZ2USDwoHY29udGVudBgBIAEoDCIZCglMb2JieUNv", + "ZGUSDAoEY29kZRgBIAEoDSJCCgRHYW1lEgwKBG5hbWUYASABKAkSDwoHdmVy", + "c2lvbhgCIAEoCRIPCgdhdXRob3JzGAMgAygJEgoKAmlkGAQgASgNIhIKBFZv", + "dGUSCgoCaWQYASABKAQiWQoLTG9iYnlTdGF0dXMSGQoFdm90ZXMYASADKAsy", + "Ci5nYW1lLlZvdGUSGwoFcmVhZHkYAiADKAsyDC5nYW1lLlBsYXllchISCgpp", + "c1N0YXJ0aW5nGAMgASgIIiIKBlBsYXllchIMCgRuYW1lGAEgASgJEgoKAmlk", + "GAIgASgNMo8CCgpDb25uZWN0aW9uEh4KBG5hbWUSCi5nYW1lLk51bGwaCi5n", + "YW1lLk5hbWUSIwoHY29ubmVjdBIKLmdhbWUuTmFtZRoMLmdhbWUuVXNlcklE", + "EjAKEWpvaW5Mb2JieVdpdGhDb2RlEg8uZ2FtZS5Mb2JieUNvZGUaCi5nYW1l", + "Lk51bGwSMQoLY3JlYXRlTG9iYnkSES5nYW1lLkxvYmJ5Q29uZmlnGg8uZ2Ft", + "ZS5Mb2JieUNvZGUSJAoIZ2V0R2FtZXMSCi5nYW1lLk51bGwaCi5nYW1lLkdh", + "bWUwARIxChBnZXRQdWJsaWNMb2JiaWVzEgouZ2FtZS5OdWxsGg8uZ2FtZS5M", + "b2JieUNvZGUwATKcAQoFTG9iYnkSKQoMZ2V0Q2FyZEltYWdlEgwuZ2FtZS5D", + "YXJkSUQaCy5nYW1lLkltYWdlEh4KBHZvdGUSCi5nYW1lLlZvdGUaCi5nYW1l", + "Lk51bGwSHwoFcmVhZHkSCi5nYW1lLk51bGwaCi5nYW1lLk51bGwSJwoGc3Rh", + "dHVzEgouZ2FtZS5OdWxsGhEuZ2FtZS5Mb2JieVN0YXR1c2IGcHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Game.UserID), global::Game.UserID.Parser, new[]{ "Id" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Game.Name), global::Game.Name.Parser, new[]{ "Name_" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Game.LobbyConfig), global::Game.LobbyConfig.Parser, new[]{ "Public" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Game.Null), global::Game.Null.Parser, null, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Game.CardID), global::Game.CardID.Parser, new[]{ "GameId", "CardId" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Game.Image), global::Game.Image.Parser, new[]{ "Content" }, null, null, null, null), @@ -405,6 +407,181 @@ namespace Game { } + public sealed partial class LobbyConfig : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new LobbyConfig()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Game.GameReflection.Descriptor.MessageTypes[2]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LobbyConfig() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LobbyConfig(LobbyConfig other) : this() { + public_ = other.public_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public LobbyConfig Clone() { + return new LobbyConfig(this); + } + + /// Field number for the "public" field. + public const int PublicFieldNumber = 1; + private bool public_; + /// + /// repeated uint32 allowed_games = 2; + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Public { + get { return public_; } + set { + public_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as LobbyConfig); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(LobbyConfig other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Public != other.Public) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Public != false) hash ^= Public.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Public != false) { + output.WriteRawTag(8); + output.WriteBool(Public); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Public != false) { + output.WriteRawTag(8); + output.WriteBool(Public); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Public != false) { + size += 1 + 1; + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(LobbyConfig other) { + if (other == null) { + return; + } + if (other.Public != false) { + Public = other.Public; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Public = input.ReadBool(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Public = input.ReadBool(); + break; + } + } + } + } + #endif + + } + public sealed partial class Null : pb::IMessage #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE , pb::IBufferMessage @@ -417,7 +594,7 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Game.GameReflection.Descriptor.MessageTypes[2]; } + get { return global::Game.GameReflection.Descriptor.MessageTypes[3]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -553,7 +730,7 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Game.GameReflection.Descriptor.MessageTypes[3]; } + get { return global::Game.GameReflection.Descriptor.MessageTypes[4]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -582,9 +759,9 @@ namespace Game { /// Field number for the "gameId" field. public const int GameIdFieldNumber = 1; - private ulong gameId_; + private uint gameId_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public ulong GameId { + public uint GameId { get { return gameId_; } set { gameId_ = value; @@ -623,7 +800,7 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (GameId != 0UL) hash ^= GameId.GetHashCode(); + if (GameId != 0) hash ^= GameId.GetHashCode(); if (CardId.Length != 0) hash ^= CardId.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -641,9 +818,9 @@ namespace Game { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (GameId != 0UL) { + if (GameId != 0) { output.WriteRawTag(8); - output.WriteUInt64(GameId); + output.WriteUInt32(GameId); } if (CardId.Length != 0) { output.WriteRawTag(18); @@ -658,9 +835,9 @@ namespace Game { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE [global::System.Diagnostics.DebuggerNonUserCodeAttribute] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (GameId != 0UL) { + if (GameId != 0) { output.WriteRawTag(8); - output.WriteUInt64(GameId); + output.WriteUInt32(GameId); } if (CardId.Length != 0) { output.WriteRawTag(18); @@ -675,8 +852,8 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (GameId != 0UL) { - size += 1 + pb::CodedOutputStream.ComputeUInt64Size(GameId); + if (GameId != 0) { + size += 1 + pb::CodedOutputStream.ComputeUInt32Size(GameId); } if (CardId.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(CardId); @@ -692,7 +869,7 @@ namespace Game { if (other == null) { return; } - if (other.GameId != 0UL) { + if (other.GameId != 0) { GameId = other.GameId; } if (other.CardId.Length != 0) { @@ -713,7 +890,7 @@ namespace Game { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 8: { - GameId = input.ReadUInt64(); + GameId = input.ReadUInt32(); break; } case 18: { @@ -735,7 +912,7 @@ namespace Game { _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 8: { - GameId = input.ReadUInt64(); + GameId = input.ReadUInt32(); break; } case 18: { @@ -761,7 +938,7 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Game.GameReflection.Descriptor.MessageTypes[4]; } + get { return global::Game.GameReflection.Descriptor.MessageTypes[5]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -933,7 +1110,7 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Game.GameReflection.Descriptor.MessageTypes[5]; } + get { return global::Game.GameReflection.Descriptor.MessageTypes[6]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1105,7 +1282,7 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Game.GameReflection.Descriptor.MessageTypes[6]; } + get { return global::Game.GameReflection.Descriptor.MessageTypes[7]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1168,9 +1345,9 @@ namespace Game { /// Field number for the "id" field. public const int IdFieldNumber = 4; - private ulong id_; + private uint id_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public ulong Id { + public uint Id { get { return id_; } set { id_ = value; @@ -1203,7 +1380,7 @@ namespace Game { if (Name.Length != 0) hash ^= Name.GetHashCode(); if (Version.Length != 0) hash ^= Version.GetHashCode(); hash ^= authors_.GetHashCode(); - if (Id != 0UL) hash ^= Id.GetHashCode(); + if (Id != 0) hash ^= Id.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -1229,9 +1406,9 @@ namespace Game { output.WriteString(Version); } authors_.WriteTo(output, _repeated_authors_codec); - if (Id != 0UL) { + if (Id != 0) { output.WriteRawTag(32); - output.WriteUInt64(Id); + output.WriteUInt32(Id); } if (_unknownFields != null) { _unknownFields.WriteTo(output); @@ -1251,9 +1428,9 @@ namespace Game { output.WriteString(Version); } authors_.WriteTo(ref output, _repeated_authors_codec); - if (Id != 0UL) { + if (Id != 0) { output.WriteRawTag(32); - output.WriteUInt64(Id); + output.WriteUInt32(Id); } if (_unknownFields != null) { _unknownFields.WriteTo(ref output); @@ -1271,8 +1448,8 @@ namespace Game { size += 1 + pb::CodedOutputStream.ComputeStringSize(Version); } size += authors_.CalculateSize(_repeated_authors_codec); - if (Id != 0UL) { - size += 1 + pb::CodedOutputStream.ComputeUInt64Size(Id); + if (Id != 0) { + size += 1 + pb::CodedOutputStream.ComputeUInt32Size(Id); } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); @@ -1292,7 +1469,7 @@ namespace Game { Version = other.Version; } authors_.Add(other.authors_); - if (other.Id != 0UL) { + if (other.Id != 0) { Id = other.Id; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); @@ -1322,7 +1499,7 @@ namespace Game { break; } case 32: { - Id = input.ReadUInt64(); + Id = input.ReadUInt32(); break; } } @@ -1352,7 +1529,7 @@ namespace Game { break; } case 32: { - Id = input.ReadUInt64(); + Id = input.ReadUInt32(); break; } } @@ -1374,7 +1551,7 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Game.GameReflection.Descriptor.MessageTypes[7]; } + get { return global::Game.GameReflection.Descriptor.MessageTypes[8]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1546,7 +1723,7 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Game.GameReflection.Descriptor.MessageTypes[8]; } + get { return global::Game.GameReflection.Descriptor.MessageTypes[9]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1768,7 +1945,7 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { - get { return global::Game.GameReflection.Descriptor.MessageTypes[9]; } + get { return global::Game.GameReflection.Descriptor.MessageTypes[10]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1808,9 +1985,9 @@ namespace Game { /// Field number for the "id" field. public const int IdFieldNumber = 2; - private ulong id_; + private uint id_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public ulong Id { + public uint Id { get { return id_; } set { id_ = value; @@ -1839,7 +2016,7 @@ namespace Game { public override int GetHashCode() { int hash = 1; if (Name.Length != 0) hash ^= Name.GetHashCode(); - if (Id != 0UL) hash ^= Id.GetHashCode(); + if (Id != 0) hash ^= Id.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -1860,9 +2037,9 @@ namespace Game { output.WriteRawTag(10); output.WriteString(Name); } - if (Id != 0UL) { + if (Id != 0) { output.WriteRawTag(16); - output.WriteUInt64(Id); + output.WriteUInt32(Id); } if (_unknownFields != null) { _unknownFields.WriteTo(output); @@ -1877,9 +2054,9 @@ namespace Game { output.WriteRawTag(10); output.WriteString(Name); } - if (Id != 0UL) { + if (Id != 0) { output.WriteRawTag(16); - output.WriteUInt64(Id); + output.WriteUInt32(Id); } if (_unknownFields != null) { _unknownFields.WriteTo(ref output); @@ -1893,8 +2070,8 @@ namespace Game { if (Name.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); } - if (Id != 0UL) { - size += 1 + pb::CodedOutputStream.ComputeUInt64Size(Id); + if (Id != 0) { + size += 1 + pb::CodedOutputStream.ComputeUInt32Size(Id); } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); @@ -1910,7 +2087,7 @@ namespace Game { if (other.Name.Length != 0) { Name = other.Name; } - if (other.Id != 0UL) { + if (other.Id != 0) { Id = other.Id; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); @@ -1932,7 +2109,7 @@ namespace Game { break; } case 16: { - Id = input.ReadUInt64(); + Id = input.ReadUInt32(); break; } } @@ -1954,7 +2131,7 @@ namespace Game { break; } case 16: { - Id = input.ReadUInt64(); + Id = input.ReadUInt32(); break; } } diff --git a/unity/Assets/Scripts/grpc/GameGrpc.cs b/unity/Assets/Scripts/grpc/GameGrpc.cs index f1b4e3e..cb41003 100644 --- a/unity/Assets/Scripts/grpc/GameGrpc.cs +++ b/unity/Assets/Scripts/grpc/GameGrpc.cs @@ -49,6 +49,8 @@ namespace Game { static readonly grpc::Marshaller __Marshaller_game_Name = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Name.Parser)); static readonly grpc::Marshaller __Marshaller_game_UserID = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.UserID.Parser)); static readonly grpc::Marshaller __Marshaller_game_LobbyCode = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.LobbyCode.Parser)); + static readonly grpc::Marshaller __Marshaller_game_LobbyConfig = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.LobbyConfig.Parser)); + static readonly grpc::Marshaller __Marshaller_game_Game = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Game.Parser)); static readonly grpc::Method __Method_name = new grpc::Method( grpc::MethodType.Unary, @@ -71,10 +73,24 @@ namespace Game { __Marshaller_game_LobbyCode, __Marshaller_game_Null); - static readonly grpc::Method __Method_joinLobbyWithoutCode = new grpc::Method( + static readonly grpc::Method __Method_createLobby = new grpc::Method( grpc::MethodType.Unary, __ServiceName, - "joinLobbyWithoutCode", + "createLobby", + __Marshaller_game_LobbyConfig, + __Marshaller_game_LobbyCode); + + static readonly grpc::Method __Method_getGames = new grpc::Method( + grpc::MethodType.ServerStreaming, + __ServiceName, + "getGames", + __Marshaller_game_Null, + __Marshaller_game_Game); + + static readonly grpc::Method __Method_getPublicLobbies = new grpc::Method( + grpc::MethodType.ServerStreaming, + __ServiceName, + "getPublicLobbies", __Marshaller_game_Null, __Marshaller_game_LobbyCode); @@ -103,7 +119,17 @@ namespace Game { throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); } - public virtual global::System.Threading.Tasks.Task joinLobbyWithoutCode(global::Game.Null request, grpc::ServerCallContext context) + public virtual global::System.Threading.Tasks.Task createLobby(global::Game.LobbyConfig request, grpc::ServerCallContext context) + { + throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); + } + + public virtual global::System.Threading.Tasks.Task getGames(global::Game.Null request, grpc::IServerStreamWriter responseStream, grpc::ServerCallContext context) + { + throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); + } + + public virtual global::System.Threading.Tasks.Task getPublicLobbies(global::Game.Null request, grpc::IServerStreamWriter responseStream, grpc::ServerCallContext context) { throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); } @@ -181,21 +207,37 @@ namespace Game { { return CallInvoker.AsyncUnaryCall(__Method_joinLobbyWithCode, null, options, request); } - public virtual global::Game.LobbyCode joinLobbyWithoutCode(global::Game.Null request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + public virtual global::Game.LobbyCode createLobby(global::Game.LobbyConfig request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + { + return createLobby(request, new grpc::CallOptions(headers, deadline, cancellationToken)); + } + public virtual global::Game.LobbyCode createLobby(global::Game.LobbyConfig request, grpc::CallOptions options) + { + return CallInvoker.BlockingUnaryCall(__Method_createLobby, null, options, request); + } + public virtual grpc::AsyncUnaryCall createLobbyAsync(global::Game.LobbyConfig request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + { + return createLobbyAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); + } + public virtual grpc::AsyncUnaryCall createLobbyAsync(global::Game.LobbyConfig request, grpc::CallOptions options) + { + return CallInvoker.AsyncUnaryCall(__Method_createLobby, null, options, request); + } + public virtual grpc::AsyncServerStreamingCall getGames(global::Game.Null request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) { - return joinLobbyWithoutCode(request, new grpc::CallOptions(headers, deadline, cancellationToken)); + return getGames(request, new grpc::CallOptions(headers, deadline, cancellationToken)); } - public virtual global::Game.LobbyCode joinLobbyWithoutCode(global::Game.Null request, grpc::CallOptions options) + public virtual grpc::AsyncServerStreamingCall getGames(global::Game.Null request, grpc::CallOptions options) { - return CallInvoker.BlockingUnaryCall(__Method_joinLobbyWithoutCode, null, options, request); + return CallInvoker.AsyncServerStreamingCall(__Method_getGames, null, options, request); } - public virtual grpc::AsyncUnaryCall joinLobbyWithoutCodeAsync(global::Game.Null request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + public virtual grpc::AsyncServerStreamingCall getPublicLobbies(global::Game.Null request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) { - return joinLobbyWithoutCodeAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); + return getPublicLobbies(request, new grpc::CallOptions(headers, deadline, cancellationToken)); } - public virtual grpc::AsyncUnaryCall joinLobbyWithoutCodeAsync(global::Game.Null request, grpc::CallOptions options) + public virtual grpc::AsyncServerStreamingCall getPublicLobbies(global::Game.Null request, grpc::CallOptions options) { - return CallInvoker.AsyncUnaryCall(__Method_joinLobbyWithoutCode, null, options, request); + return CallInvoker.AsyncServerStreamingCall(__Method_getPublicLobbies, null, options, request); } /// Creates a new instance of client from given ClientBaseConfiguration. protected override ConnectionClient NewInstance(ClientBaseConfiguration configuration) @@ -212,7 +254,9 @@ namespace Game { .AddMethod(__Method_name, serviceImpl.name) .AddMethod(__Method_connect, serviceImpl.connect) .AddMethod(__Method_joinLobbyWithCode, serviceImpl.joinLobbyWithCode) - .AddMethod(__Method_joinLobbyWithoutCode, serviceImpl.joinLobbyWithoutCode).Build(); + .AddMethod(__Method_createLobby, serviceImpl.createLobby) + .AddMethod(__Method_getGames, serviceImpl.getGames) + .AddMethod(__Method_getPublicLobbies, serviceImpl.getPublicLobbies).Build(); } /// Register service method with a service binder with or without implementation. Useful when customizing the service binding logic. @@ -224,7 +268,9 @@ namespace Game { serviceBinder.AddMethod(__Method_name, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.name)); serviceBinder.AddMethod(__Method_connect, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.connect)); serviceBinder.AddMethod(__Method_joinLobbyWithCode, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.joinLobbyWithCode)); - serviceBinder.AddMethod(__Method_joinLobbyWithoutCode, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.joinLobbyWithoutCode)); + serviceBinder.AddMethod(__Method_createLobby, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.createLobby)); + serviceBinder.AddMethod(__Method_getGames, serviceImpl == null ? null : new grpc::ServerStreamingServerMethod(serviceImpl.getGames)); + serviceBinder.AddMethod(__Method_getPublicLobbies, serviceImpl == null ? null : new grpc::ServerStreamingServerMethod(serviceImpl.getPublicLobbies)); } } @@ -265,20 +311,12 @@ namespace Game { return parser.ParseFrom(context.PayloadAsNewBuffer()); } - static readonly grpc::Marshaller __Marshaller_game_Null = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Null.Parser)); - static readonly grpc::Marshaller __Marshaller_game_Game = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Game.Parser)); static readonly grpc::Marshaller __Marshaller_game_CardID = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.CardID.Parser)); static readonly grpc::Marshaller __Marshaller_game_Image = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Image.Parser)); static readonly grpc::Marshaller __Marshaller_game_Vote = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Vote.Parser)); + static readonly grpc::Marshaller __Marshaller_game_Null = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Null.Parser)); static readonly grpc::Marshaller __Marshaller_game_LobbyStatus = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.LobbyStatus.Parser)); - static readonly grpc::Method __Method_getGames = new grpc::Method( - grpc::MethodType.ServerStreaming, - __ServiceName, - "getGames", - __Marshaller_game_Null, - __Marshaller_game_Game); - static readonly grpc::Method __Method_getCardImage = new grpc::Method( grpc::MethodType.Unary, __ServiceName, @@ -317,11 +355,6 @@ namespace Game { [grpc::BindServiceMethod(typeof(Lobby), "BindService")] public abstract partial class LobbyBase { - public virtual global::System.Threading.Tasks.Task getGames(global::Game.Null request, grpc::IServerStreamWriter responseStream, grpc::ServerCallContext context) - { - throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); - } - public virtual global::System.Threading.Tasks.Task getCardImage(global::Game.CardID request, grpc::ServerCallContext context) { throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); @@ -367,14 +400,6 @@ namespace Game { { } - public virtual grpc::AsyncServerStreamingCall getGames(global::Game.Null request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) - { - return getGames(request, new grpc::CallOptions(headers, deadline, cancellationToken)); - } - public virtual grpc::AsyncServerStreamingCall getGames(global::Game.Null request, grpc::CallOptions options) - { - return CallInvoker.AsyncServerStreamingCall(__Method_getGames, null, options, request); - } public virtual global::Game.Image getCardImage(global::Game.CardID request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) { return getCardImage(request, new grpc::CallOptions(headers, deadline, cancellationToken)); @@ -451,7 +476,6 @@ namespace Game { public static grpc::ServerServiceDefinition BindService(LobbyBase serviceImpl) { return grpc::ServerServiceDefinition.CreateBuilder() - .AddMethod(__Method_getGames, serviceImpl.getGames) .AddMethod(__Method_getCardImage, serviceImpl.getCardImage) .AddMethod(__Method_vote, serviceImpl.vote) .AddMethod(__Method_ready, serviceImpl.ready) @@ -464,7 +488,6 @@ namespace Game { /// An object implementing the server-side handling logic. public static void BindService(grpc::ServiceBinderBase serviceBinder, LobbyBase serviceImpl) { - serviceBinder.AddMethod(__Method_getGames, serviceImpl == null ? null : new grpc::ServerStreamingServerMethod(serviceImpl.getGames)); serviceBinder.AddMethod(__Method_getCardImage, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.getCardImage)); serviceBinder.AddMethod(__Method_vote, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.vote)); serviceBinder.AddMethod(__Method_ready, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.ready));