diff --git a/protobuf/game.proto b/protobuf/game.proto index f093a43..3db2c20 100644 --- a/protobuf/game.proto +++ b/protobuf/game.proto @@ -4,24 +4,28 @@ package game; // Interface exported by the server. service Connection { - rpc joinLobbyWithCode(LobbyCode) returns(Result); + rpc connect(Username) returns(UserID); + rpc joinLobbyWithCode(LobbyCode) returns(Null); rpc joinLobbyWithoutCode(Null) returns(LobbyCode); } service Lobby { rpc getGames(Null) returns(stream Game); - rpc vote(Vote) returns(Result); - rpc ready (Null) returns (Result); + rpc vote(Vote) returns(Null); + rpc ready (Null) returns (Null); rpc status (Null) returns (LobbyStatus); } -message Null {} +message UserID { + string id = 1; +} -message Result { - enum Result { OK = 0; ERROR = 1; } - Result res = 1; +message Username { + string name = 1; } +message Null {} + message LobbyCode { uint32 code = 1; } message Game { diff --git a/server/.env b/server/.env new file mode 100644 index 0000000..39bbbe7 --- /dev/null +++ b/server/.env @@ -0,0 +1 @@ +DATABASE_URL="sqlite:db.sqlite" \ No newline at end of file diff --git a/server/.gitignore b/server/.gitignore index 869df07..b755a01 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -1,2 +1,4 @@ /target -Cargo.lock \ No newline at end of file +Cargo.lock +db.sqlite* +/games \ No newline at end of file diff --git a/server/Cargo.toml b/server/Cargo.toml index 6a66058..d586d82 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -7,10 +7,25 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -grpc = "0.8.2" -protobuf = "2.18.0" -grpc-protobuf = "0.8.2" -# futures = "~0.3" +# Utilities +rand = "0.7.3" +uuid = {version = "0.8.1", features = ["v4"]} +tokio = {version = "0.2", features = ["full"]} + +# Game loading +rhai = {version = "0.19.4", features = ["serde"]} +serde_json = "1.0.59" +serde = "1.0.117" +schemars = "0.8.0" + + +# GRPC stack +tonic = "0.3" +prost = "0.6" + +# Database (SQLite) +sqlx = { version = "0.3", default-features = false, features = [ "runtime-tokio", "macros", "sqlite" ] } [build-dependencies] -protoc-rust-grpc = "0.8.2" \ No newline at end of file +# Grpc codegen +tonic-build = "0.3" \ No newline at end of file diff --git a/server/build.rs b/server/build.rs index a724616..e52fffb 100644 --- a/server/build.rs +++ b/server/build.rs @@ -1,14 +1,17 @@ use std::fs::read_dir; -fn main() { +fn main() -> Result<(), Box> { + let mut files = Vec::new(); for f in read_dir("../protobuf").unwrap() { - if let Ok(f) =f { + if let Ok(f) = f { if f.path().is_file() && f.path().extension().map(|x| x == "proto").unwrap_or(false) { - if let Err(e) = protoc_rust_grpc::Codegen::new().include("../protobuf").input(f.path()).out_dir("src/grpc").rust_protobuf(true).run() { - eprintln!("PROTOC Error:\n{}", e); - std::process::exit(1) - } + files.push(f.path()); } } } -} \ No newline at end of file + tonic_build::configure() + .build_client(false) + .out_dir("src/grpc") + .compile(&files, &["../protobuf".into()])?; + Ok(()) +} diff --git a/server/schema/game-config.json b/server/schema/game-config.json new file mode 100644 index 0000000..35fecd8 --- /dev/null +++ b/server/schema/game-config.json @@ -0,0 +1,76 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Config", + "type": "object", + "required": [ + "available_cards", + "name", + "piles", + "player_piles", + "script" + ], + "properties": { + "authors": { + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "available_cards": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Card" + } + }, + "name": { + "type": "string" + }, + "piles": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Pile" + } + }, + "player_piles": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/Pile" + } + }, + "script": { + "type": "string" + }, + "version": { + "default": "0.0.0", + "type": "string" + } + }, + "definitions": { + "Card": { + "type": "object", + "required": [ + "image" + ], + "properties": { + "image": { + "type": "string" + } + }, + "additionalProperties": true + }, + "Pile": { + "type": "object", + "properties": { + "cards": { + "default": [], + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": true + } + } +} \ No newline at end of file diff --git a/server/src/db.rs b/server/src/db.rs new file mode 100644 index 0000000..d0ee19a --- /dev/null +++ b/server/src/db.rs @@ -0,0 +1,97 @@ +use sqlx::{pool::PoolConnection, prelude::*, query, query_as, query_file, SqliteConnection, SqlitePool}; +use tokio::stream::StreamExt; + +pub mod types; + +pub struct DbPool { + pool: SqlitePool, +} + +impl DbPool { + pub async fn new() -> Self { + // std::env::set_var("DATABASE_URL", ); + let pool = SqlitePool::new("sqlite:db.sqlite").await.unwrap(); + + let mut conn = pool.acquire().await.unwrap(); + + query_file!("src/setup.sql") + .execute(&mut conn) + .await + .unwrap(); + + Self { pool } + } + + pub async fn acquire(&self) -> DbConnection { + DbConnection::new(self.pool.acquire().await.unwrap()) + } +} + +// impl Drop for DbPool { +// fn drop(&mut self) { +// tokio::runtime::Handle::current().block_on(future) +// } +// } + +pub struct DbConnection { + conn: PoolConnection, +} + +use uuid::Uuid; + + +// TODO: return Results intead of crashing +impl DbConnection { + fn new(conn: PoolConnection) -> Self { + Self { conn } + } + + pub async fn add_user(&mut self, name: T) -> Uuid { + let uuid = Uuid::new_v4(); + // println!("{:?}", uuid.as_bytes().to_vec()); + self.conn + .execute(query!( + "INSERT INTO Users(uuid, name) VALUES(?, ?)", + uuid.as_bytes().to_vec(), + name.to_string() + )) + .await + .unwrap(); // Server crashes if uuids collide + 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 create_lobby(&mut self) -> u32 { + let id = rand::random(); + self.conn + .execute(query!( + "INSERT INTO Lobbies(id) VALUES(?)", + id as i32 + )) + .await + .unwrap(); // Server crashes if ids collide + id + } + + pub async fn join_lobby(&mut self, user: Uuid, lobby: u32) { + self.conn + .execute(query!( + "INSERT INTO UsersInLobbies(UserId, LobbyId) VALUES(?, ?)", + user.as_bytes().to_vec(), + lobby as i32 + )) + .await + .unwrap(); // Server crashes if ids collide + } + + pub async fn close(self) { + self.conn.close().await.unwrap(); + } +} + diff --git a/server/src/db/types.rs b/server/src/db/types.rs new file mode 100644 index 0000000..4118956 --- /dev/null +++ b/server/src/db/types.rs @@ -0,0 +1,27 @@ +use uuid::Uuid; +use sqlx::{prelude::*, sqlite::SqliteRow}; + +pub struct User{ + pub name: String, + pub uuid: Uuid +} + +impl<'a> FromRow<'a, SqliteRow<'a>> for User { + fn from_row(row: &SqliteRow<'a>) -> sqlx::Result { + let uuid: String = row.try_get("UUID")?; + // println!("{:?}", uuid.as_bytes()); + Ok(Self {uuid: Uuid::from_slice(uuid.as_bytes()).map_err(|x| sqlx::Error::Decode(Box::new(x)))?, name: row.try_get("Name")?}) + } +} + +impl std::fmt::Display for User { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}[{}]", self.name, self.uuid) + } +} + +impl std::fmt::Debug for User { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self) + } +} \ No newline at end of file diff --git a/server/src/games/config.rs b/server/src/games/config.rs new file mode 100644 index 0000000..9ffb3d3 --- /dev/null +++ b/server/src/games/config.rs @@ -0,0 +1,90 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use std::path::PathBuf; + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +pub struct Config { + pub name: String, + #[serde(default = "default_version")] + pub version: String, + #[serde(default)] + pub authors: Vec, + pub script: String, + pub available_cards: HashMap, + pub piles: HashMap, + pub player_piles: HashMap, +} + +fn default_version() -> String { + "0.0.0".into() +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +pub struct Card { + pub image: PathBuf, + #[serde(flatten)] + pub other: HashMap, +} + +#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)] +pub struct Pile { + #[serde(default)] + pub cards: Vec, + #[serde(flatten)] + pub other: HashMap, +} + +impl Pile { + pub fn from_rhai_map(map: rhai::Map) -> Result> { + // println!("{}", map.get("cards") + // .ok_or("Pile doesn't have property cards")?.type_name()); + let cards: Vec = + rhai::serde::from_dynamic(map.get("cards").ok_or("Pile doesn't have property cards")?)?; + + let other_fallible: Vec>> = + map.into_iter() + .map(|(x, v)| (x.to_string(), v)) + .filter(|(s, _)| s != &"cards".to_string()) + .map(|(k, v)| Ok((k, rhai::serde::from_dynamic::(&v)?))) + .collect(); + + let mut other = HashMap::new(); + + for x in other_fallible { + let (k, v) = x?; + other.insert(k, v); + } + + Ok(Self { cards, other }) + } +} + +impl Config { + pub fn load + std::fmt::Debug>(file: P) -> Self { + serde_json::from_reader(std::fs::File::open(&file).unwrap()) + .map_err(|e| { + eprintln!( + "Malformed game defintion file @ {}", + file.as_ref().display() + ); + eprintln!("JSON Error: {}", e); + panic!() + }) + .unwrap() + } +} + +pub fn setup() { + if cfg!(debug_assertions) { + if let Ok(e) = std::env::var("CARGO_MANIFEST_DIR") { + std::fs::write( + AsRef::::as_ref(&e) + .join("schema") + .join("game-config.json"), + serde_json::to_string_pretty(&schemars::schema_for!(Config)).unwrap(), + ) + .unwrap() + } + } +} diff --git a/server/src/games/mod.rs b/server/src/games/mod.rs new file mode 100644 index 0000000..e4b0010 --- /dev/null +++ b/server/src/games/mod.rs @@ -0,0 +1,72 @@ +use rhai::AST; + +use std::fs::read_dir; +mod config; +mod run; + +#[derive(Clone)] +pub struct Game { + name: String, + version: String, + authors: Vec, + ast: AST, + conf: config::Config, +} + + +impl Game { + pub fn load + std::fmt::Debug>(folder: P) -> Self { + // config::setup(); + + let conf = config::Config::load(folder.as_ref().join("game.json")); + + let ast = rhai::Engine::new().compile_file(folder.as_ref().join(&conf.script)).unwrap(); + println!("AST: {:?}", ast); + Self { conf: conf.clone(), name: conf.name, version: conf.version, authors: conf.authors, ast } + } + + // pub fn name(&self) -> String { + // self.name.clone() + // } + // pub fn version(&self) -> String { + // self.version.clone() + // } + // pub fn authors(&self) -> Vec { + // self.authors.clone() + // } + + pub fn run(&self, players: u32) -> run::RunningGame { + run::RunningGame::new(self.ast.clone(), &self.conf, players) + } +} + +impl std::fmt::Display for Game { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{} [{}]{}", self.name, self.version, if self.authors.is_empty() {String::new()} else {format!(" by {}", self.authors.join(", "))}) + } +} + +impl std::fmt::Debug for Game { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self) + } +} + +pub fn load_games() -> Vec { + config::setup(); + let mut games = Vec::new(); + for file in read_dir("games").unwrap() { + if let Ok(folder) = file { + if folder.path().is_dir() { + for file in read_dir(folder.path()).unwrap() { + if let Ok(file) = file { + if file.file_name().to_str().unwrap() == "game.json" { + games.push(Game::load(folder.path())) + } + } + } + } + } + } + games +} \ No newline at end of file diff --git a/server/src/games/run.rs b/server/src/games/run.rs new file mode 100644 index 0000000..bf1fbfa --- /dev/null +++ b/server/src/games/run.rs @@ -0,0 +1,66 @@ +use rand::seq::SliceRandom; +use rhai::{ + serde::{from_dynamic, to_dynamic}, + Dynamic, Engine, Func, Map, RegisterResultFn, AST, +}; +use serde::{Deserialize, Serialize}; + +use std::collections::HashMap; + +use super::config::{Config, Pile}; + +fn shuffle_pile(pile: Map) -> Result> { + let mut pile = Pile::from_rhai_map(pile)?; + let mut rng = rand::thread_rng(); + pile.cards.shuffle(&mut rng); + to_dynamic(pile) +} + + +#[derive(Debug, Serialize, Deserialize, Clone)] +struct Setup { + piles: HashMap, + player_piles: Vec>, + players: u32, +} + +pub struct RunningGame { + piles: HashMap, + player_piles: Vec>, +} + +impl RunningGame { + pub fn new(ast: AST, conf: &Config, players: u32) -> Self { + let mut engine = Engine::new(); + engine.register_result_fn("shuffle", shuffle_pile); + let setup = Func::<(Dynamic,), Dynamic>::create_from_ast(engine, ast, "setup"); + + let piles = conf.piles.clone(); + let player_piles = vec![conf.player_piles.clone(); players as usize]; + let Setup { + piles, + player_piles, + players: _, + } = from_dynamic( + &setup( + to_dynamic(Setup { + piles, + player_piles, + players, + }) + .unwrap(), + ) + .unwrap(), + ) + .unwrap(); + Self { + piles, + player_piles, + } + // Self {setup: Box::new(Func::<(Vec, Vec>), ()>::create_from_ast(engine, ast, "setup"))} + } + + // pub fn setup(&self) { + // (self.setup)().unwrap() + // } +} diff --git a/server/src/grpc.rs b/server/src/grpc.rs index 383be5a..8e12e45 100644 --- a/server/src/grpc.rs +++ b/server/src/grpc.rs @@ -1,10 +1,88 @@ -pub mod game; -pub mod game_grpc; +use tonic::{transport::Server, Request, Response, Status}; -// use grpc::ServerBuilder; +use std::sync::Arc; -// pub fn start() { -// // let mut s = ServerBuilder::new(); -// // s.add_service(game_grpc::ConnectionServer::new_service_def(handler)) -// // let server = s.build().unwrap(); -// } \ No newline at end of file +mod game; + +use game::connection_server::{Connection, ConnectionServer}; +use game::{LobbyCode, Null, UserId, Username}; + +use crate::db; + +pub struct ConnectionService { + conn: Arc, +} + +#[tonic::async_trait] +impl Connection for ConnectionService { + async fn connect(&self, request: Request) -> Result, Status> { + let name = request.into_inner().name; + let mut conn = self.conn.acquire().await; + let uuid = conn.add_user(&name).await; + println!("Connected {}[{}]", name, uuid); + conn.close().await; + Ok(Response::new(UserId { + id: uuid.to_hyphenated().to_string(), + })) + } + + async fn join_lobby_with_code( + &self, + 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") + })?; + 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{})) + } + + async fn join_lobby_without_code( + &self, + 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") + })?; + let mut conn = self.conn.acquire().await; + let lobby = conn.create_lobby().await; + conn.join_lobby(uuid, lobby).await; + conn.close().await; + Ok(Response::new(LobbyCode{code: lobby})) + } +} + +pub async fn start(pool: db::DbPool) { + let arc = Arc::new(pool); + let connection = ConnectionService { conn: arc.clone() }; + + Server::builder() + .add_service(ConnectionServer::new(connection)) + .serve("0.0.0.0:50052".parse().unwrap()) + .await + .unwrap(); +} + +mod client_id { + pub fn get( + metadata: &tonic::metadata::MetadataMap, + ) -> Result { + metadata + .get("client_id") + .ok_or(Error::NotSet) + .and_then(|x| { + uuid::Uuid::parse_str(x.to_str().map_err(|_| Error::MalformedUuid)?) + .map_err(|_| Error::MalformedUuid) + }) + } + + pub enum Error { + MalformedUuid, + NotSet, + } +} diff --git a/server/src/grpc/game.rs b/server/src/grpc/game.rs index 18d4f99..e42b3dd 100644 --- a/server/src/grpc/game.rs +++ b/server/src/grpc/game.rs @@ -1,1396 +1,428 @@ -// This file is generated by rust-protobuf 2.18.0. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![allow(unused_attributes)] -#![rustfmt::skip] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `game.proto` - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_18_0; - -#[derive(PartialEq,Clone,Default)] -pub struct Null { - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a Null { - fn default() -> &'a Null { - ::default_instance() - } -} - -impl Null { - pub fn new() -> Null { - ::std::default::Default::default() - } -} - -impl ::protobuf::Message for Null { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Null { - Null::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let fields = ::std::vec::Vec::new(); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "Null", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static Null { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(Null::new) - } -} - -impl ::protobuf::Clear for Null { - fn clear(&mut self) { - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Null { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Null { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Result { - // message fields - pub res: Result_Result, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a Result { - fn default() -> &'a Result { - ::default_instance() - } -} - -impl Result { - pub fn new() -> Result { - ::std::default::Default::default() - } - - // .game.Result.Result res = 1; - - - pub fn get_res(&self) -> Result_Result { - self.res - } - pub fn clear_res(&mut self) { - self.res = Result_Result::OK; - } - - // Param is passed by value, moved - pub fn set_res(&mut self, v: Result_Result) { - self.res = v; - } -} - -impl ::protobuf::Message for Result { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.res, 1, &mut self.unknown_fields)? - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.res != Result_Result::OK { - my_size += ::protobuf::rt::enum_size(1, self.res); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if self.res != Result_Result::OK { - os.write_enum(1, ::protobuf::ProtobufEnum::value(&self.res))?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Result { - Result::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( - "res", - |m: &Result| { &m.res }, - |m: &mut Result| { &mut m.res }, - )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "Result", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static Result { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(Result::new) - } -} - -impl ::protobuf::Clear for Result { - fn clear(&mut self) { - self.res = Result_Result::OK; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Result { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Result { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) - } -} - -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum Result_Result { - OK = 0, - ERROR = 1, -} - -impl ::protobuf::ProtobufEnum for Result_Result { - fn value(&self) -> i32 { - *self as i32 - } - - fn from_i32(value: i32) -> ::std::option::Option { - match value { - 0 => ::std::option::Option::Some(Result_Result::OK), - 1 => ::std::option::Option::Some(Result_Result::ERROR), - _ => ::std::option::Option::None - } - } - - fn values() -> &'static [Self] { - static values: &'static [Result_Result] = &[ - Result_Result::OK, - Result_Result::ERROR, - ]; - values - } - - fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new_pb_name::("Result.Result", file_descriptor_proto()) - }) - } -} - -impl ::std::marker::Copy for Result_Result { -} - -impl ::std::default::Default for Result_Result { - fn default() -> Self { - Result_Result::OK - } -} - -impl ::protobuf::reflect::ProtobufValue for Result_Result { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) - } -} - -#[derive(PartialEq,Clone,Default)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UserId { + #[prost(string, tag = "1")] + pub id: std::string::String, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Username { + #[prost(string, tag = "1")] + pub name: std::string::String, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Null {} +#[derive(Clone, PartialEq, ::prost::Message)] pub struct LobbyCode { - // message fields + #[prost(uint32, tag = "1")] pub code: u32, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a LobbyCode { - fn default() -> &'a LobbyCode { - ::default_instance() - } -} - -impl LobbyCode { - pub fn new() -> LobbyCode { - ::std::default::Default::default() - } - - // uint32 code = 1; - - - pub fn get_code(&self) -> u32 { - self.code - } - pub fn clear_code(&mut self) { - self.code = 0; - } - - // Param is passed by value, moved - pub fn set_code(&mut self, v: u32) { - self.code = v; - } -} - -impl ::protobuf::Message for LobbyCode { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint32()?; - self.code = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.code != 0 { - my_size += ::protobuf::rt::value_size(1, self.code, ::protobuf::wire_format::WireTypeVarint); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if self.code != 0 { - os.write_uint32(1, self.code)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> LobbyCode { - LobbyCode::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( - "code", - |m: &LobbyCode| { &m.code }, - |m: &mut LobbyCode| { &mut m.code }, - )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "LobbyCode", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static LobbyCode { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(LobbyCode::new) - } -} - -impl ::protobuf::Clear for LobbyCode { - fn clear(&mut self) { - self.code = 0; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for LobbyCode { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for LobbyCode { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) - } } - -#[derive(PartialEq,Clone,Default)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct Game { - // message fields - pub name: ::std::string::String, - pub version: ::std::string::String, - pub authors: ::protobuf::RepeatedField<::std::string::String>, + #[prost(string, tag = "1")] + pub name: std::string::String, + #[prost(string, tag = "2")] + pub version: std::string::String, + #[prost(string, repeated, tag = "3")] + pub authors: ::std::vec::Vec, + #[prost(uint64, tag = "4")] pub id: u64, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a Game { - fn default() -> &'a Game { - ::default_instance() - } } - -impl Game { - pub fn new() -> Game { - ::std::default::Default::default() - } - - // string name = 1; - - - pub fn get_name(&self) -> &str { - &self.name - } - pub fn clear_name(&mut self) { - self.name.clear(); - } - - // Param is passed by value, moved - pub fn set_name(&mut self, v: ::std::string::String) { - self.name = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_name(&mut self) -> &mut ::std::string::String { - &mut self.name - } - - // Take field - pub fn take_name(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.name, ::std::string::String::new()) - } - - // string version = 2; - - - pub fn get_version(&self) -> &str { - &self.version - } - pub fn clear_version(&mut self) { - self.version.clear(); - } - - // Param is passed by value, moved - pub fn set_version(&mut self, v: ::std::string::String) { - self.version = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_version(&mut self) -> &mut ::std::string::String { - &mut self.version - } - - // Take field - pub fn take_version(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.version, ::std::string::String::new()) - } - - // repeated string authors = 3; - - - pub fn get_authors(&self) -> &[::std::string::String] { - &self.authors - } - pub fn clear_authors(&mut self) { - self.authors.clear(); - } - - // Param is passed by value, moved - pub fn set_authors(&mut self, v: ::protobuf::RepeatedField<::std::string::String>) { - self.authors = v; - } - - // Mutable pointer to the field. - pub fn mut_authors(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { - &mut self.authors - } - - // Take field - pub fn take_authors(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { - ::std::mem::replace(&mut self.authors, ::protobuf::RepeatedField::new()) - } - - // uint64 id = 4; - - - pub fn get_id(&self) -> u64 { - self.id - } - pub fn clear_id(&mut self) { - self.id = 0; - } - - // Param is passed by value, moved - pub fn set_id(&mut self, v: u64) { - self.id = v; - } -} - -impl ::protobuf::Message for Game { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; - }, - 2 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.version)?; - }, - 3 => { - ::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.authors)?; - }, - 4 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.id = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.name.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.name); - } - if !self.version.is_empty() { - my_size += ::protobuf::rt::string_size(2, &self.version); - } - for value in &self.authors { - my_size += ::protobuf::rt::string_size(3, &value); - }; - if self.id != 0 { - my_size += ::protobuf::rt::value_size(4, self.id, ::protobuf::wire_format::WireTypeVarint); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.name.is_empty() { - os.write_string(1, &self.name)?; - } - if !self.version.is_empty() { - os.write_string(2, &self.version)?; - } - for v in &self.authors { - os.write_string(3, &v)?; - }; - if self.id != 0 { - os.write_uint64(4, self.id)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Game { - Game::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "name", - |m: &Game| { &m.name }, - |m: &mut Game| { &mut m.name }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "version", - |m: &Game| { &m.version }, - |m: &mut Game| { &mut m.version }, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "authors", - |m: &Game| { &m.authors }, - |m: &mut Game| { &mut m.authors }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "id", - |m: &Game| { &m.id }, - |m: &mut Game| { &mut m.id }, - )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "Game", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static Game { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(Game::new) - } -} - -impl ::protobuf::Clear for Game { - fn clear(&mut self) { - self.name.clear(); - self.version.clear(); - self.authors.clear(); - self.id = 0; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Game { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Game { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] +#[derive(Clone, PartialEq, ::prost::Message)] pub struct Vote { - // message fields + #[prost(uint64, tag = "1")] pub id: u64, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, } - -impl<'a> ::std::default::Default for &'a Vote { - fn default() -> &'a Vote { - ::default_instance() - } -} - -impl Vote { - pub fn new() -> Vote { - ::std::default::Default::default() - } - - // uint64 id = 1; - - - pub fn get_id(&self) -> u64 { - self.id - } - pub fn clear_id(&mut self) { - self.id = 0; - } - - // Param is passed by value, moved - pub fn set_id(&mut self, v: u64) { - self.id = v; - } +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct LobbyStatus { + #[prost(message, repeated, tag = "1")] + pub votes: ::std::vec::Vec, + #[prost(message, repeated, tag = "2")] + pub ready: ::std::vec::Vec, + #[prost(bool, tag = "3")] + pub is_starting: bool, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Player { + #[prost(string, tag = "1")] + pub name: std::string::String, + #[prost(uint64, tag = "2")] + pub id: u64, } - -impl ::protobuf::Message for Vote { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.id = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; +#[doc = r" Generated server implementations."] +pub mod connection_server { + #![allow(unused_variables, dead_code, missing_docs)] + use tonic::codegen::*; + #[doc = "Generated trait containing gRPC methods that should be implemented for use with ConnectionServer."] + #[async_trait] + pub trait Connection: Send + Sync + 'static { + async fn connect( + &self, + request: tonic::Request, + ) -> Result, tonic::Status>; + async fn join_lobby_with_code( + &self, + request: tonic::Request, + ) -> Result, tonic::Status>; + async fn join_lobby_without_code( + &self, + request: tonic::Request, + ) -> Result, tonic::Status>; + } + #[doc = " Interface exported by the server."] + #[derive(Debug)] + pub struct ConnectionServer { + inner: _Inner, + } + struct _Inner(Arc, Option); + impl ConnectionServer { + pub fn new(inner: T) -> Self { + let inner = Arc::new(inner); + let inner = _Inner(inner, None); + Self { inner } } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if self.id != 0 { - my_size += ::protobuf::rt::value_size(1, self.id, ::protobuf::wire_format::WireTypeVarint); + pub fn with_interceptor(inner: T, interceptor: impl Into) -> Self { + let inner = Arc::new(inner); + let inner = _Inner(inner, Some(interceptor.into())); + Self { inner } } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if self.id != 0 { - os.write_uint64(1, self.id)?; + impl Service> for ConnectionServer + where + T: Connection, + B: HttpBody + Send + Sync + 'static, + B::Error: Into + Send + 'static, + { + type Response = http::Response; + type Error = Never; + type Future = BoxFuture; + fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { + Poll::Ready(Ok(())) } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Vote { - Vote::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "id", - |m: &Vote| { &m.id }, - |m: &mut Vote| { &mut m.id }, - )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "Vote", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static Vote { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(Vote::new) - } -} - -impl ::protobuf::Clear for Vote { - fn clear(&mut self) { - self.id = 0; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Vote { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Vote { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct LobbyStatus { - // message fields - pub votes: ::protobuf::RepeatedField, - pub ready: ::protobuf::RepeatedField, - pub isStarting: bool, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a LobbyStatus { - fn default() -> &'a LobbyStatus { - ::default_instance() - } -} - -impl LobbyStatus { - pub fn new() -> LobbyStatus { - ::std::default::Default::default() - } - - // repeated .game.Vote votes = 1; - - - pub fn get_votes(&self) -> &[Vote] { - &self.votes - } - pub fn clear_votes(&mut self) { - self.votes.clear(); - } - - // Param is passed by value, moved - pub fn set_votes(&mut self, v: ::protobuf::RepeatedField) { - self.votes = v; - } - - // Mutable pointer to the field. - pub fn mut_votes(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.votes - } - - // Take field - pub fn take_votes(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.votes, ::protobuf::RepeatedField::new()) - } - - // repeated .game.Player ready = 2; - - - pub fn get_ready(&self) -> &[Player] { - &self.ready - } - pub fn clear_ready(&mut self) { - self.ready.clear(); - } - - // Param is passed by value, moved - pub fn set_ready(&mut self, v: ::protobuf::RepeatedField) { - self.ready = v; - } - - // Mutable pointer to the field. - pub fn mut_ready(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.ready - } - - // Take field - pub fn take_ready(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.ready, ::protobuf::RepeatedField::new()) - } - - // bool isStarting = 3; - - - pub fn get_isStarting(&self) -> bool { - self.isStarting - } - pub fn clear_isStarting(&mut self) { - self.isStarting = false; - } - - // Param is passed by value, moved - pub fn set_isStarting(&mut self, v: bool) { - self.isStarting = v; - } -} - -impl ::protobuf::Message for LobbyStatus { - fn is_initialized(&self) -> bool { - for v in &self.votes { - if !v.is_initialized() { - return false; - } - }; - for v in &self.ready { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.votes)?; - }, - 2 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.ready)?; - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + fn call(&mut self, req: http::Request) -> Self::Future { + let inner = self.inner.clone(); + match req.uri().path() { + "/game.Connection/connect" => { + #[allow(non_camel_case_types)] + struct connectSvc(pub Arc); + impl tonic::server::UnaryService for connectSvc { + type Response = super::UserId; + type Future = BoxFuture, tonic::Status>; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = self.0.clone(); + let fut = async move { (*inner).connect(request).await }; + Box::pin(fut) + } + } + let inner = self.inner.clone(); + let fut = async move { + let interceptor = inner.1.clone(); + let inner = inner.0; + let method = connectSvc(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.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/game.Connection/joinLobbyWithCode" => { + #[allow(non_camel_case_types)] + struct joinLobbyWithCodeSvc(pub Arc); + impl tonic::server::UnaryService for joinLobbyWithCodeSvc { + type Response = super::Null; + type Future = BoxFuture, tonic::Status>; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = self.0.clone(); + let fut = async move { (*inner).join_lobby_with_code(request).await }; + Box::pin(fut) + } + } + let inner = self.inner.clone(); + let fut = async move { + let interceptor = inner.1.clone(); + let inner = inner.0; + let method = joinLobbyWithCodeSvc(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.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/game.Connection/joinLobbyWithoutCode" => { + #[allow(non_camel_case_types)] + struct joinLobbyWithoutCodeSvc(pub Arc); + impl tonic::server::UnaryService for joinLobbyWithoutCodeSvc { + type Response = super::LobbyCode; + type Future = BoxFuture, tonic::Status>; + 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 }; + Box::pin(fut) + } } - let tmp = is.read_bool()?; - self.isStarting = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; + let inner = self.inner.clone(); + let fut = async move { + let interceptor = inner.1.clone(); + let inner = inner.0; + let method = joinLobbyWithoutCodeSvc(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.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => Box::pin(async move { + Ok(http::Response::builder() + .status(200) + .header("grpc-status", "12") + .body(tonic::body::BoxBody::empty()) + .unwrap()) + }), + } } - ::std::result::Result::Ok(()) } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - for value in &self.votes { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; - for value in &self.ready { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; - if self.isStarting != false { - my_size += 2; + impl Clone for ConnectionServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { inner } } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - for v in &self.votes { - os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }; - for v in &self.ready { - os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }; - if self.isStarting != false { - os.write_bool(3, self.isStarting)?; + impl Clone for _Inner { + fn clone(&self) -> Self { + Self(self.0.clone(), self.1.clone()) } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> LobbyStatus { - LobbyStatus::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "votes", - |m: &LobbyStatus| { &m.votes }, - |m: &mut LobbyStatus| { &mut m.votes }, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "ready", - |m: &LobbyStatus| { &m.ready }, - |m: &mut LobbyStatus| { &mut m.ready }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "isStarting", - |m: &LobbyStatus| { &m.isStarting }, - |m: &mut LobbyStatus| { &mut m.isStarting }, - )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "LobbyStatus", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static LobbyStatus { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(LobbyStatus::new) - } -} - -impl ::protobuf::Clear for LobbyStatus { - fn clear(&mut self) { - self.votes.clear(); - self.ready.clear(); - self.isStarting = false; - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for LobbyStatus { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for LobbyStatus { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Player { - // message fields - pub name: ::std::string::String, - pub id: u64, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a Player { - fn default() -> &'a Player { - ::default_instance() - } -} - -impl Player { - pub fn new() -> Player { - ::std::default::Default::default() } - - // string name = 1; - - - pub fn get_name(&self) -> &str { - &self.name - } - pub fn clear_name(&mut self) { - self.name.clear(); - } - - // Param is passed by value, moved - pub fn set_name(&mut self, v: ::std::string::String) { - self.name = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_name(&mut self) -> &mut ::std::string::String { - &mut self.name - } - - // Take field - pub fn take_name(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.name, ::std::string::String::new()) - } - - // uint64 id = 2; - - - pub fn get_id(&self) -> u64 { - self.id - } - pub fn clear_id(&mut self) { - self.id = 0; - } - - // Param is passed by value, moved - pub fn set_id(&mut self, v: u64) { - self.id = v; - } -} - -impl ::protobuf::Message for Player { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.id = tmp; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; + impl std::fmt::Debug for _Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) } - ::std::result::Result::Ok(()) } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if !self.name.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.name); + impl tonic::transport::NamedService for ConnectionServer { + const NAME: &'static str = "game.Connection"; + } +} +#[doc = r" Generated server implementations."] +pub mod lobby_server { + #![allow(unused_variables, dead_code, missing_docs)] + use tonic::codegen::*; + #[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 vote( + &self, + request: tonic::Request, + ) -> Result, tonic::Status>; + async fn ready( + &self, + request: tonic::Request, + ) -> Result, tonic::Status>; + async fn status( + &self, + request: tonic::Request, + ) -> Result, tonic::Status>; + } + #[derive(Debug)] + pub struct LobbyServer { + inner: _Inner, + } + struct _Inner(Arc, Option); + impl LobbyServer { + pub fn new(inner: T) -> Self { + let inner = Arc::new(inner); + let inner = _Inner(inner, None); + Self { inner } } - if self.id != 0 { - my_size += ::protobuf::rt::value_size(2, self.id, ::protobuf::wire_format::WireTypeVarint); + pub fn with_interceptor(inner: T, interceptor: impl Into) -> Self { + let inner = Arc::new(inner); + let inner = _Inner(inner, Some(interceptor.into())); + Self { inner } } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.name.is_empty() { - os.write_string(1, &self.name)?; + impl Service> for LobbyServer + where + T: Lobby, + B: HttpBody + Send + Sync + 'static, + B::Error: Into + Send + 'static, + { + type Response = http::Response; + type Error = Never; + type Future = BoxFuture; + fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { + Poll::Ready(Ok(())) } - if self.id != 0 { - os.write_uint64(2, self.id)?; + 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/vote" => { + #[allow(non_camel_case_types)] + struct voteSvc(pub Arc); + impl tonic::server::UnaryService for voteSvc { + type Response = super::Null; + type Future = BoxFuture, tonic::Status>; + fn call(&mut self, request: tonic::Request) -> Self::Future { + let inner = self.0.clone(); + let fut = async move { (*inner).vote(request).await }; + Box::pin(fut) + } + } + let inner = self.inner.clone(); + let fut = async move { + let interceptor = inner.1.clone(); + let inner = inner.0; + let method = voteSvc(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.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/game.Lobby/ready" => { + #[allow(non_camel_case_types)] + struct readySvc(pub Arc); + impl tonic::server::UnaryService for readySvc { + type Response = super::Null; + type Future = BoxFuture, tonic::Status>; + fn call(&mut self, request: tonic::Request) -> Self::Future { + let inner = self.0.clone(); + let fut = async move { (*inner).ready(request).await }; + Box::pin(fut) + } + } + let inner = self.inner.clone(); + let fut = async move { + let interceptor = inner.1.clone(); + let inner = inner.0; + let method = readySvc(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.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/game.Lobby/status" => { + #[allow(non_camel_case_types)] + struct statusSvc(pub Arc); + impl tonic::server::UnaryService for statusSvc { + type Response = super::LobbyStatus; + type Future = BoxFuture, tonic::Status>; + fn call(&mut self, request: tonic::Request) -> Self::Future { + let inner = self.0.clone(); + let fut = async move { (*inner).status(request).await }; + Box::pin(fut) + } + } + let inner = self.inner.clone(); + let fut = async move { + let interceptor = inner.1.clone(); + let inner = inner.0; + let method = statusSvc(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.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => Box::pin(async move { + Ok(http::Response::builder() + .status(200) + .header("grpc-status", "12") + .body(tonic::body::BoxBody::empty()) + .unwrap()) + }), + } } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Player { - Player::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "name", - |m: &Player| { &m.name }, - |m: &mut Player| { &mut m.name }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "id", - |m: &Player| { &m.id }, - |m: &mut Player| { &mut m.id }, - )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "Player", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static Player { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(Player::new) + impl Clone for LobbyServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { inner } + } } -} - -impl ::protobuf::Clear for Player { - fn clear(&mut self) { - self.name.clear(); - self.id = 0; - self.unknown_fields.clear(); + impl Clone for _Inner { + fn clone(&self) -> Self { + Self(self.0.clone(), self.1.clone()) + } } -} - -impl ::std::fmt::Debug for Player { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) + impl std::fmt::Debug for _Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } } -} - -impl ::protobuf::reflect::ProtobufValue for Player { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) + impl tonic::transport::NamedService for LobbyServer { + const NAME: &'static str = "game.Lobby"; } } - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\ngame.proto\x12\x04game\"\x06\n\x04Null\"L\n\x06Result\x12%\n\x03res\ - \x18\x01\x20\x01(\x0e2\x13.game.Result.ResultR\x03res\"\x1b\n\x06Result\ - \x12\x06\n\x02OK\x10\0\x12\t\n\x05ERROR\x10\x01\"\x1f\n\tLobbyCode\x12\ - \x12\n\x04code\x18\x01\x20\x01(\rR\x04code\"^\n\x04Game\x12\x12\n\x04nam\ - e\x18\x01\x20\x01(\tR\x04name\x12\x18\n\x07version\x18\x02\x20\x01(\tR\ - \x07version\x12\x18\n\x07authors\x18\x03\x20\x03(\tR\x07authors\x12\x0e\ - \n\x02id\x18\x04\x20\x01(\x04R\x02id\"\x16\n\x04Vote\x12\x0e\n\x02id\x18\ - \x01\x20\x01(\x04R\x02id\"s\n\x0bLobbyStatus\x12\x20\n\x05votes\x18\x01\ - \x20\x03(\x0b2\n.game.VoteR\x05votes\x12\"\n\x05ready\x18\x02\x20\x03(\ - \x0b2\x0c.game.PlayerR\x05ready\x12\x1e\n\nisStarting\x18\x03\x20\x01(\ - \x08R\nisStarting\",\n\x06Player\x12\x12\n\x04name\x18\x01\x20\x01(\tR\ - \x04name\x12\x0e\n\x02id\x18\x02\x20\x01(\x04R\x02id2u\n\nConnection\x12\ - 2\n\x11joinLobbyWithCode\x12\x0f.game.LobbyCode\x1a\x0c.game.Result\x123\ - \n\x14joinLobbyWithoutCode\x12\n.game.Null\x1a\x0f.game.LobbyCode2\x9b\ - \x01\n\x05Lobby\x12$\n\x08getGames\x12\n.game.Null\x1a\n.game.Game0\x01\ - \x12\x20\n\x04vote\x12\n.game.Vote\x1a\x0c.game.Result\x12!\n\x05ready\ - \x12\n.game.Null\x1a\x0c.game.Result\x12'\n\x06status\x12\n.game.Null\ - \x1a\x11.game.LobbyStatusb\x06proto3\ -"; - -static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) -} diff --git a/server/src/grpc/game_grpc.rs b/server/src/grpc/game_grpc.rs deleted file mode 100644 index ea09f55..0000000 --- a/server/src/grpc/game_grpc.rs +++ /dev/null @@ -1,234 +0,0 @@ -// This file is generated. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - - -// server interface - -pub trait Connection { - fn join_lobby_with_code(&self, o: ::grpc::ServerHandlerContext, req: ::grpc::ServerRequestSingle, resp: ::grpc::ServerResponseUnarySink) -> ::grpc::Result<()>; - - fn join_lobby_without_code(&self, o: ::grpc::ServerHandlerContext, req: ::grpc::ServerRequestSingle, resp: ::grpc::ServerResponseUnarySink) -> ::grpc::Result<()>; -} - -// client - -pub struct ConnectionClient { - grpc_client: ::std::sync::Arc<::grpc::Client>, -} - -impl ::grpc::ClientStub for ConnectionClient { - fn with_client(grpc_client: ::std::sync::Arc<::grpc::Client>) -> Self { - ConnectionClient { - grpc_client: grpc_client, - } - } -} - -impl ConnectionClient { - pub fn join_lobby_with_code(&self, o: ::grpc::RequestOptions, req: super::game::LobbyCode) -> ::grpc::SingleResponse { - let descriptor = ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Connection/joinLobbyWithCode"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }); - self.grpc_client.call_unary(o, req, descriptor) - } - - pub fn join_lobby_without_code(&self, o: ::grpc::RequestOptions, req: super::game::Null) -> ::grpc::SingleResponse { - let descriptor = ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Connection/joinLobbyWithoutCode"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }); - self.grpc_client.call_unary(o, req, descriptor) - } -} - -// server - -pub struct ConnectionServer; - - -impl ConnectionServer { - pub fn new_service_def(handler: H) -> ::grpc::rt::ServerServiceDefinition { - let handler_arc = ::std::sync::Arc::new(handler); - ::grpc::rt::ServerServiceDefinition::new("/game.Connection", - vec![ - ::grpc::rt::ServerMethod::new( - ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Connection/joinLobbyWithCode"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }), - { - let handler_copy = handler_arc.clone(); - ::grpc::rt::MethodHandlerUnary::new(move |ctx, req, resp| (*handler_copy).join_lobby_with_code(ctx, req, resp)) - }, - ), - ::grpc::rt::ServerMethod::new( - ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Connection/joinLobbyWithoutCode"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }), - { - let handler_copy = handler_arc.clone(); - ::grpc::rt::MethodHandlerUnary::new(move |ctx, req, resp| (*handler_copy).join_lobby_without_code(ctx, req, resp)) - }, - ), - ], - ) - } -} - -// server interface - -pub trait Lobby { - fn get_games(&self, o: ::grpc::ServerHandlerContext, req: ::grpc::ServerRequestSingle, resp: ::grpc::ServerResponseSink) -> ::grpc::Result<()>; - - fn vote(&self, o: ::grpc::ServerHandlerContext, req: ::grpc::ServerRequestSingle, resp: ::grpc::ServerResponseUnarySink) -> ::grpc::Result<()>; - - fn ready(&self, o: ::grpc::ServerHandlerContext, req: ::grpc::ServerRequestSingle, resp: ::grpc::ServerResponseUnarySink) -> ::grpc::Result<()>; - - fn status(&self, o: ::grpc::ServerHandlerContext, req: ::grpc::ServerRequestSingle, resp: ::grpc::ServerResponseUnarySink) -> ::grpc::Result<()>; -} - -// client - -pub struct LobbyClient { - grpc_client: ::std::sync::Arc<::grpc::Client>, -} - -impl ::grpc::ClientStub for LobbyClient { - fn with_client(grpc_client: ::std::sync::Arc<::grpc::Client>) -> Self { - LobbyClient { - grpc_client: grpc_client, - } - } -} - -impl LobbyClient { - pub fn get_games(&self, o: ::grpc::RequestOptions, req: super::game::Null) -> ::grpc::StreamingResponse { - let descriptor = ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Lobby/getGames"), - streaming: ::grpc::rt::GrpcStreaming::ServerStreaming, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }); - self.grpc_client.call_server_streaming(o, req, descriptor) - } - - pub fn vote(&self, o: ::grpc::RequestOptions, req: super::game::Vote) -> ::grpc::SingleResponse { - let descriptor = ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Lobby/vote"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }); - self.grpc_client.call_unary(o, req, descriptor) - } - - pub fn ready(&self, o: ::grpc::RequestOptions, req: super::game::Null) -> ::grpc::SingleResponse { - let descriptor = ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Lobby/ready"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }); - self.grpc_client.call_unary(o, req, descriptor) - } - - pub fn status(&self, o: ::grpc::RequestOptions, req: super::game::Null) -> ::grpc::SingleResponse { - let descriptor = ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Lobby/status"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }); - self.grpc_client.call_unary(o, req, descriptor) - } -} - -// server - -pub struct LobbyServer; - - -impl LobbyServer { - pub fn new_service_def(handler: H) -> ::grpc::rt::ServerServiceDefinition { - let handler_arc = ::std::sync::Arc::new(handler); - ::grpc::rt::ServerServiceDefinition::new("/game.Lobby", - vec![ - ::grpc::rt::ServerMethod::new( - ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Lobby/getGames"), - streaming: ::grpc::rt::GrpcStreaming::ServerStreaming, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }), - { - let handler_copy = handler_arc.clone(); - ::grpc::rt::MethodHandlerServerStreaming::new(move |ctx, req, resp| (*handler_copy).get_games(ctx, req, resp)) - }, - ), - ::grpc::rt::ServerMethod::new( - ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Lobby/vote"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }), - { - let handler_copy = handler_arc.clone(); - ::grpc::rt::MethodHandlerUnary::new(move |ctx, req, resp| (*handler_copy).vote(ctx, req, resp)) - }, - ), - ::grpc::rt::ServerMethod::new( - ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Lobby/ready"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }), - { - let handler_copy = handler_arc.clone(); - ::grpc::rt::MethodHandlerUnary::new(move |ctx, req, resp| (*handler_copy).ready(ctx, req, resp)) - }, - ), - ::grpc::rt::ServerMethod::new( - ::grpc::rt::ArcOrStatic::Static(&::grpc::rt::MethodDescriptor { - name: ::grpc::rt::StringOrStatic::Static("/game.Lobby/status"), - streaming: ::grpc::rt::GrpcStreaming::Unary, - req_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - resp_marshaller: ::grpc::rt::ArcOrStatic::Static(&::grpc_protobuf::MarshallerProtobuf), - }), - { - let handler_copy = handler_arc.clone(); - ::grpc::rt::MethodHandlerUnary::new(move |ctx, req, resp| (*handler_copy).status(ctx, req, resp)) - }, - ), - ], - ) - } -} diff --git a/server/src/main.rs b/server/src/main.rs index 08ba134..ee90a10 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,6 +1,17 @@ mod grpc; +mod db; +mod games; -fn main() { +#[tokio::main] +async fn main() { // protobuf::route_guide_grpc::RouteGuid - println!("Hello, world!"); + let games = games::load_games(); + println!("{:?}", games); + games[0].run(4); + // let pool = db::DbPool::new().await; + // let mut conn = pool.acquire().await; + // println!("{}", conn.add_user("Hi").await); + // println!("{:?}", conn.users().await); + // conn.close().await; + // grpc::start(pool).await; } diff --git a/server/src/setup.sql b/server/src/setup.sql new file mode 100644 index 0000000..a486aab --- /dev/null +++ b/server/src/setup.sql @@ -0,0 +1,34 @@ +-- Add migration script here + +DROP TABLE IF EXISTS `UsersInLobbies`; +DROP TABLE IF EXISTS `Users`; +DROP TABLE IF EXISTS `Lobbies`; + + +CREATE TABLE Users ( + UUID CHAR(16) NOT NULL UNIQUE PRIMARY KEY, + Name VARCHAR(255) NOT NULL + -- LobbyID INT NULL, + -- FOREIGN KEY (LobbyID) REFERENCES Lobbies(ID) +); + +CREATE TABLE Lobbies ( + ID INT NOT NULL UNIQUE PRIMARY KEY +); + +CREATE TABLE UsersInLobbies ( + LobbyID INT NOT NULL, + UserID CHAR(16) NOT NULL UNIQUE, + FOREIGN KEY (LobbyID) REFERENCES Lobbies(ID), + FOREIGN KEY (UserID) REFERENCES Users(UUID) +); + +-- INSERT INTO Users(UUID, Name) VALUES("0123456789abcdef", "Hi"); +-- INSERT INTO Lobbies(ID) VALUES(0); +-- INSERT INTO Users(UUID, Name) VALUES("0123456789abcdff", "Hi2"); + +-- INSERT INTO UsersInLobbies(UserID,LobbyID) VALUES("0123456789abcdff", 0); + +-- INSERT INTO Users(UUID, Name) VALUES("0123456789abcdfe", "Hi3"); + +-- INSERT INTO UsersInLobbies(UserID,LobbyID) VALUES("0123456789abcdfe", 1); \ No newline at end of file diff --git a/unity/Assets/Scripts/Base32.cs b/unity/Assets/Scripts/Base32.cs new file mode 100644 index 0000000..60fefa3 --- /dev/null +++ b/unity/Assets/Scripts/Base32.cs @@ -0,0 +1,51 @@ +// using UnityEngine; + +public static class Base32 +{ + private const string CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; + public static string ToString(uint number) + { + uint quotient = number / 32; + uint remainder = number % 32; + string res = CHARS[(int)remainder].ToString(); + // Debug.Log(res); + // Debug.Log("Q " + quotient); + // Debug.Log("R " + remainder + " > " + res); + if (quotient > 0) + { + res = ToString(quotient) + res; + } + return res; + } + + public static uint FromString(string s) + { + + uint res = 0; + if (s.Length > 0) + { + for (int i = 0; i < s.Length; i++) + { + uint pow = UIntPow(32, (uint)i); + // Debug.Log(); + res += ((uint)CHARS.IndexOf(s[s.Length - 1 - i])) * pow; + // Debug.Log(i + ":" + pow + " | " + s[i] + " " + CHARS.IndexOf(s[s.Length - 1 - i]) + " > " + res); + } + } + return res; + } + + private static uint UIntPow(uint x, uint pow) + { + uint ret = 1; + while (pow != 0) + { + if ((pow & 1) == 1) + ret *= x; + x *= x; + pow >>= 1; + } + return ret; + } + +} \ No newline at end of file diff --git a/unity/Assets/Scripts/Base32.cs.meta b/unity/Assets/Scripts/Base32.cs.meta new file mode 100644 index 0000000..21c2215 --- /dev/null +++ b/unity/Assets/Scripts/Base32.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35e876ff614b5e8f5b1cc702b9502b5c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/unity/Assets/Scripts/Card.cs b/unity/Assets/Scripts/Card.cs index b997dba..b47c8a7 100644 --- a/unity/Assets/Scripts/Card.cs +++ b/unity/Assets/Scripts/Card.cs @@ -36,7 +36,13 @@ public class Card : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler{ } } public void OnClickCard() { + // var conn = Client.GetConnection(); + // if (conn != null) { + // Debug.Log(conn.GetLobby()); + // Debug.Log(conn.CreateLobby()); + // } if ((!preparingCard || cardBeingPrepared != gameObject) && !thrown) { + cardBeingPrepared = gameObject; SetPreview(); preparingCard = true; diff --git a/unity/Assets/Scripts/Client.cs b/unity/Assets/Scripts/Client.cs index 81a41b7..833d597 100644 --- a/unity/Assets/Scripts/Client.cs +++ b/unity/Assets/Scripts/Client.cs @@ -1,13 +1,68 @@ -using UnityEngine; using Grpc.Core; -using Game; - -public class Client: MonoBehaviour +// using UnityEngine; +public static class Client { - public void Run() { - Channel channel = new Channel("127.0.0.1:50052", ChannelCredentials.Insecure); - var client = new Connection.ConnectionClient(channel); - // Client code goes here - channel.ShutdownAsync().Wait(); + private static Connection reference; + + public static void Connect(string name) + { + reference = new Connection(name); + } + + public static ref Connection GetConnection() + { + return ref reference; + } + + public static void CloseConnection() + { + if (reference != null) + { + reference.Close(); + reference = null; + } + } + + public class Connection // : MonoBehaviour + { + private Game.Connection.ConnectionClient connection; + private Channel channel; + private string connId; + private uint? lobby = null; + public Connection(string user) + { + channel = new Channel("127.0.0.1:50052", ChannelCredentials.Insecure); + connection = new Game.Connection.ConnectionClient(channel); + connId = connection.connect(new Game.Username { Name = user }).Id; + } + + public void JoinLobby(string code) + { + lobby = Base32.FromString(code); + connection.joinLobbyWithCode(new Game.LobbyCode { Code = (uint)lobby }, new Metadata { new Metadata.Entry("client_id", connId) }); + } + + public string CreateLobby() + { + lobby = connection.joinLobbyWithoutCode(new Game.Null(), new Metadata { new Metadata.Entry("client_id", connId) }).Code; + return Base32.ToString((uint)lobby); + } + + public string GetLobby() + { + if (lobby != null) + { + return Base32.ToString((uint)lobby); + } + else + { + return null; + } + } + + public void Close() + { + channel.ShutdownAsync().Wait(); + } } -} \ No newline at end of file +} diff --git a/unity/Assets/Scripts/DeckGenerator.cs b/unity/Assets/Scripts/DeckGenerator.cs index d07e662..009dd1c 100644 --- a/unity/Assets/Scripts/DeckGenerator.cs +++ b/unity/Assets/Scripts/DeckGenerator.cs @@ -23,6 +23,7 @@ public class DeckGenerator : MonoBehaviour private string defaultbg; // Start is called before the first frame update void Start() { + // Client.Connect("PooPoo2"); if(deckUI && cardPrefab && deckFileName != "") { string path = Application.streamingAssetsPath + "/" + deckFileName; var deckFile = new TextAsset(File.ReadAllText(path)); diff --git a/unity/Assets/Scripts/grpc/Game.cs b/unity/Assets/Scripts/grpc/Game.cs index 20b99ad..4e28a91 100644 --- a/unity/Assets/Scripts/grpc/Game.cs +++ b/unity/Assets/Scripts/grpc/Game.cs @@ -24,25 +24,27 @@ namespace Game { static GameReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( - "CgpnYW1lLnByb3RvEgRnYW1lIgYKBE51bGwiRwoGUmVzdWx0EiAKA3JlcxgB", - "IAEoDjITLmdhbWUuUmVzdWx0LlJlc3VsdCIbCgZSZXN1bHQSBgoCT0sQABIJ", - "CgVFUlJPUhABIhkKCUxvYmJ5Q29kZRIMCgRjb2RlGAEgASgNIkIKBEdhbWUS", - "DAoEbmFtZRgBIAEoCRIPCgd2ZXJzaW9uGAIgASgJEg8KB2F1dGhvcnMYAyAD", - "KAkSCgoCaWQYBCABKAQiEgoEVm90ZRIKCgJpZBgBIAEoBCJZCgtMb2JieVN0", - "YXR1cxIZCgV2b3RlcxgBIAMoCzIKLmdhbWUuVm90ZRIbCgVyZWFkeRgCIAMo", - "CzIMLmdhbWUuUGxheWVyEhIKCmlzU3RhcnRpbmcYAyABKAgiIgoGUGxheWVy", - "EgwKBG5hbWUYASABKAkSCgoCaWQYAiABKAQydQoKQ29ubmVjdGlvbhIyChFq", - "b2luTG9iYnlXaXRoQ29kZRIPLmdhbWUuTG9iYnlDb2RlGgwuZ2FtZS5SZXN1", - "bHQSMwoUam9pbkxvYmJ5V2l0aG91dENvZGUSCi5nYW1lLk51bGwaDy5nYW1l", - "LkxvYmJ5Q29kZTKbAQoFTG9iYnkSJAoIZ2V0R2FtZXMSCi5nYW1lLk51bGwa", - "Ci5nYW1lLkdhbWUwARIgCgR2b3RlEgouZ2FtZS5Wb3RlGgwuZ2FtZS5SZXN1", - "bHQSIQoFcmVhZHkSCi5nYW1lLk51bGwaDC5nYW1lLlJlc3VsdBInCgZzdGF0", - "dXMSCi5nYW1lLk51bGwaES5nYW1lLkxvYmJ5U3RhdHVzYgZwcm90bzM=")); + "CgpnYW1lLnByb3RvEgRnYW1lIhQKBlVzZXJJRBIKCgJpZBgBIAEoCSIYCghV", + "c2VybmFtZRIMCgRuYW1lGAEgASgJIgYKBE51bGwiGQoJTG9iYnlDb2RlEgwK", + "BGNvZGUYASABKA0iQgoER2FtZRIMCgRuYW1lGAEgASgJEg8KB3ZlcnNpb24Y", + "AiABKAkSDwoHYXV0aG9ycxgDIAMoCRIKCgJpZBgEIAEoBCISCgRWb3RlEgoK", + "AmlkGAEgASgEIlkKC0xvYmJ5U3RhdHVzEhkKBXZvdGVzGAEgAygLMgouZ2Ft", + "ZS5Wb3RlEhsKBXJlYWR5GAIgAygLMgwuZ2FtZS5QbGF5ZXISEgoKaXNTdGFy", + "dGluZxgDIAEoCCIiCgZQbGF5ZXISDAoEbmFtZRgBIAEoCRIKCgJpZBgCIAEo", + "BDKcAQoKQ29ubmVjdGlvbhInCgdjb25uZWN0Eg4uZ2FtZS5Vc2VybmFtZRoM", + "LmdhbWUuVXNlcklEEjAKEWpvaW5Mb2JieVdpdGhDb2RlEg8uZ2FtZS5Mb2Ji", + "eUNvZGUaCi5nYW1lLk51bGwSMwoUam9pbkxvYmJ5V2l0aG91dENvZGUSCi5n", + "YW1lLk51bGwaDy5nYW1lLkxvYmJ5Q29kZTKXAQoFTG9iYnkSJAoIZ2V0R2Ft", + "ZXMSCi5nYW1lLk51bGwaCi5nYW1lLkdhbWUwARIeCgR2b3RlEgouZ2FtZS5W", + "b3RlGgouZ2FtZS5OdWxsEh8KBXJlYWR5EgouZ2FtZS5OdWxsGgouZ2FtZS5O", + "dWxsEicKBnN0YXR1cxIKLmdhbWUuTnVsbBoRLmdhbWUuTG9iYnlTdGF0dXNi", + "BnByb3RvMw==")); 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.Username), global::Game.Username.Parser, new[]{ "Name" }, 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.Result), global::Game.Result.Parser, new[]{ "Res" }, null, new[]{ typeof(global::Game.Result.Types.Result) }, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Game.LobbyCode), global::Game.LobbyCode.Parser, new[]{ "Code" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Game.Game), global::Game.Game.Parser, new[]{ "Name", "Version", "Authors", "Id" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Game.Vote), global::Game.Vote.Parser, new[]{ "Id" }, null, null, null, null), @@ -54,15 +56,15 @@ namespace Game { } #region Messages - public sealed partial class Null : pb::IMessage + public sealed partial class UserID : pb::IMessage #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE , pb::IBufferMessage #endif { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Null()); + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new UserID()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } + public static pb::MessageParser Parser { get { return _parser; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { @@ -75,41 +77,55 @@ namespace Game { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public Null() { + public UserID() { OnConstruction(); } partial void OnConstruction(); [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public Null(Null other) : this() { + public UserID(UserID other) : this() { + id_ = other.id_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public Null Clone() { - return new Null(this); + public UserID Clone() { + return new UserID(this); + } + + /// Field number for the "id" field. + public const int IdFieldNumber = 1; + private string id_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Id { + get { return id_; } + set { + id_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { - return Equals(other as Null); + return Equals(other as UserID); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool Equals(Null other) { + public bool Equals(UserID other) { if (ReferenceEquals(other, null)) { return false; } if (ReferenceEquals(other, this)) { return true; } + if (Id != other.Id) return false; return Equals(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; + if (Id.Length != 0) hash ^= Id.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -126,6 +142,10 @@ namespace Game { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else + if (Id.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Id); + } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -135,6 +155,10 @@ namespace Game { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE [global::System.Diagnostics.DebuggerNonUserCodeAttribute] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Id.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Id); + } if (_unknownFields != null) { _unknownFields.WriteTo(ref output); } @@ -144,6 +168,9 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; + if (Id.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Id); + } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -151,10 +178,13 @@ namespace Game { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(Null other) { + public void MergeFrom(UserID other) { if (other == null) { return; } + if (other.Id.Length != 0) { + Id = other.Id; + } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -169,6 +199,10 @@ namespace Game { default: _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; + case 10: { + Id = input.ReadString(); + break; + } } } #endif @@ -183,6 +217,10 @@ namespace Game { default: _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; + case 10: { + Id = input.ReadString(); + break; + } } } } @@ -190,15 +228,15 @@ namespace Game { } - public sealed partial class Result : pb::IMessage + public sealed partial class Username : pb::IMessage #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE , pb::IBufferMessage #endif { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Result()); + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Username()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } + public static pb::MessageParser Parser { get { return _parser; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pbr::MessageDescriptor Descriptor { @@ -211,55 +249,55 @@ namespace Game { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public Result() { + public Username() { OnConstruction(); } partial void OnConstruction(); [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public Result(Result other) : this() { - res_ = other.res_; + public Username(Username other) : this() { + name_ = other.name_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public Result Clone() { - return new Result(this); + public Username Clone() { + return new Username(this); } - /// Field number for the "res" field. - public const int ResFieldNumber = 1; - private global::Game.Result.Types.Result res_ = global::Game.Result.Types.Result.Ok; + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private string name_ = ""; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public global::Game.Result.Types.Result Res { - get { return res_; } + public string Name { + get { return name_; } set { - res_ = value; + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { - return Equals(other as Result); + return Equals(other as Username); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool Equals(Result other) { + public bool Equals(Username other) { if (ReferenceEquals(other, null)) { return false; } if (ReferenceEquals(other, this)) { return true; } - if (Res != other.Res) return false; + if (Name != other.Name) return false; return Equals(_unknownFields, other._unknownFields); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode() { int hash = 1; - if (Res != global::Game.Result.Types.Result.Ok) hash ^= Res.GetHashCode(); + if (Name.Length != 0) hash ^= Name.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -276,9 +314,9 @@ namespace Game { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (Res != global::Game.Result.Types.Result.Ok) { - output.WriteRawTag(8); - output.WriteEnum((int) Res); + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); } if (_unknownFields != null) { _unknownFields.WriteTo(output); @@ -289,9 +327,9 @@ namespace Game { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE [global::System.Diagnostics.DebuggerNonUserCodeAttribute] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (Res != global::Game.Result.Types.Result.Ok) { - output.WriteRawTag(8); - output.WriteEnum((int) Res); + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); } if (_unknownFields != null) { _unknownFields.WriteTo(ref output); @@ -302,8 +340,8 @@ namespace Game { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; - if (Res != global::Game.Result.Types.Result.Ok) { - size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Res); + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); @@ -312,12 +350,12 @@ namespace Game { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(Result other) { + public void MergeFrom(Username other) { if (other == null) { return; } - if (other.Res != global::Game.Result.Types.Result.Ok) { - Res = other.Res; + if (other.Name.Length != 0) { + Name = other.Name; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -333,8 +371,8 @@ namespace Game { default: _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; - case 8: { - Res = (global::Game.Result.Types.Result) input.ReadEnum(); + case 10: { + Name = input.ReadString(); break; } } @@ -351,8 +389,8 @@ namespace Game { default: _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; - case 8: { - Res = (global::Game.Result.Types.Result) input.ReadEnum(); + case 10: { + Name = input.ReadString(); break; } } @@ -360,17 +398,141 @@ namespace Game { } #endif - #region Nested types - /// Container for nested types declared in the Result message type. + } + + public sealed partial class Null : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Null()); + 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 Null() { + OnConstruction(); + } + + partial void OnConstruction(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static partial class Types { - public enum Result { - [pbr::OriginalName("OK")] Ok = 0, - [pbr::OriginalName("ERROR")] Error = 1, + public Null(Null other) : this() { + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Null Clone() { + return new Null(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Null); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Null other) { + if (ReferenceEquals(other, null)) { + return false; } + if (ReferenceEquals(other, this)) { + return true; + } + return Equals(_unknownFields, other._unknownFields); + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + 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 (_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 (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Null other) { + if (other == null) { + return; + } + _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; + } + } + #endif } - #endregion + + #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; + } + } + } + #endif } @@ -386,7 +548,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] @@ -558,7 +720,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] @@ -827,7 +989,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] @@ -999,7 +1161,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] @@ -1221,7 +1383,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] diff --git a/unity/Assets/Scripts/grpc/GameGrpc.cs b/unity/Assets/Scripts/grpc/GameGrpc.cs index 510649f..57c9a39 100644 --- a/unity/Assets/Scripts/grpc/GameGrpc.cs +++ b/unity/Assets/Scripts/grpc/GameGrpc.cs @@ -45,16 +45,24 @@ namespace Game { return parser.ParseFrom(context.PayloadAsNewBuffer()); } + static readonly grpc::Marshaller __Marshaller_game_Username = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Username.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_Result = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Result.Parser)); static readonly grpc::Marshaller __Marshaller_game_Null = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Null.Parser)); - static readonly grpc::Method __Method_joinLobbyWithCode = new grpc::Method( + static readonly grpc::Method __Method_connect = new grpc::Method( + grpc::MethodType.Unary, + __ServiceName, + "connect", + __Marshaller_game_Username, + __Marshaller_game_UserID); + + static readonly grpc::Method __Method_joinLobbyWithCode = new grpc::Method( grpc::MethodType.Unary, __ServiceName, "joinLobbyWithCode", __Marshaller_game_LobbyCode, - __Marshaller_game_Result); + __Marshaller_game_Null); static readonly grpc::Method __Method_joinLobbyWithoutCode = new grpc::Method( grpc::MethodType.Unary, @@ -73,7 +81,12 @@ namespace Game { [grpc::BindServiceMethod(typeof(Connection), "BindService")] public abstract partial class ConnectionBase { - public virtual global::System.Threading.Tasks.Task joinLobbyWithCode(global::Game.LobbyCode request, grpc::ServerCallContext context) + public virtual global::System.Threading.Tasks.Task connect(global::Game.Username request, grpc::ServerCallContext context) + { + throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); + } + + public virtual global::System.Threading.Tasks.Task joinLobbyWithCode(global::Game.LobbyCode request, grpc::ServerCallContext context) { throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); } @@ -108,19 +121,35 @@ namespace Game { { } - public virtual global::Game.Result joinLobbyWithCode(global::Game.LobbyCode request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + public virtual global::Game.UserID connect(global::Game.Username request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + { + return connect(request, new grpc::CallOptions(headers, deadline, cancellationToken)); + } + public virtual global::Game.UserID connect(global::Game.Username request, grpc::CallOptions options) + { + return CallInvoker.BlockingUnaryCall(__Method_connect, null, options, request); + } + public virtual grpc::AsyncUnaryCall connectAsync(global::Game.Username request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + { + return connectAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); + } + public virtual grpc::AsyncUnaryCall connectAsync(global::Game.Username request, grpc::CallOptions options) + { + return CallInvoker.AsyncUnaryCall(__Method_connect, null, options, request); + } + public virtual global::Game.Null joinLobbyWithCode(global::Game.LobbyCode request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) { return joinLobbyWithCode(request, new grpc::CallOptions(headers, deadline, cancellationToken)); } - public virtual global::Game.Result joinLobbyWithCode(global::Game.LobbyCode request, grpc::CallOptions options) + public virtual global::Game.Null joinLobbyWithCode(global::Game.LobbyCode request, grpc::CallOptions options) { return CallInvoker.BlockingUnaryCall(__Method_joinLobbyWithCode, null, options, request); } - public virtual grpc::AsyncUnaryCall joinLobbyWithCodeAsync(global::Game.LobbyCode request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + public virtual grpc::AsyncUnaryCall joinLobbyWithCodeAsync(global::Game.LobbyCode request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) { return joinLobbyWithCodeAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); } - public virtual grpc::AsyncUnaryCall joinLobbyWithCodeAsync(global::Game.LobbyCode request, grpc::CallOptions options) + public virtual grpc::AsyncUnaryCall joinLobbyWithCodeAsync(global::Game.LobbyCode request, grpc::CallOptions options) { return CallInvoker.AsyncUnaryCall(__Method_joinLobbyWithCode, null, options, request); } @@ -152,6 +181,7 @@ namespace Game { public static grpc::ServerServiceDefinition BindService(ConnectionBase serviceImpl) { return grpc::ServerServiceDefinition.CreateBuilder() + .AddMethod(__Method_connect, serviceImpl.connect) .AddMethod(__Method_joinLobbyWithCode, serviceImpl.joinLobbyWithCode) .AddMethod(__Method_joinLobbyWithoutCode, serviceImpl.joinLobbyWithoutCode).Build(); } @@ -162,7 +192,8 @@ namespace Game { /// An object implementing the server-side handling logic. public static void BindService(grpc::ServiceBinderBase serviceBinder, ConnectionBase serviceImpl) { - serviceBinder.AddMethod(__Method_joinLobbyWithCode, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.joinLobbyWithCode)); + 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)); } @@ -204,7 +235,6 @@ namespace Game { 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_Vote = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Vote.Parser)); - static readonly grpc::Marshaller __Marshaller_game_Result = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Game.Result.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( @@ -214,19 +244,19 @@ namespace Game { __Marshaller_game_Null, __Marshaller_game_Game); - static readonly grpc::Method __Method_vote = new grpc::Method( + static readonly grpc::Method __Method_vote = new grpc::Method( grpc::MethodType.Unary, __ServiceName, "vote", __Marshaller_game_Vote, - __Marshaller_game_Result); + __Marshaller_game_Null); - static readonly grpc::Method __Method_ready = new grpc::Method( + static readonly grpc::Method __Method_ready = new grpc::Method( grpc::MethodType.Unary, __ServiceName, "ready", __Marshaller_game_Null, - __Marshaller_game_Result); + __Marshaller_game_Null); static readonly grpc::Method __Method_status = new grpc::Method( grpc::MethodType.Unary, @@ -250,12 +280,12 @@ namespace Game { throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); } - public virtual global::System.Threading.Tasks.Task vote(global::Game.Vote request, grpc::ServerCallContext context) + public virtual global::System.Threading.Tasks.Task vote(global::Game.Vote request, grpc::ServerCallContext context) { throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); } - public virtual global::System.Threading.Tasks.Task ready(global::Game.Null request, grpc::ServerCallContext context) + public virtual global::System.Threading.Tasks.Task ready(global::Game.Null request, grpc::ServerCallContext context) { throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, "")); } @@ -298,35 +328,35 @@ namespace Game { { return CallInvoker.AsyncServerStreamingCall(__Method_getGames, null, options, request); } - public virtual global::Game.Result vote(global::Game.Vote request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + public virtual global::Game.Null vote(global::Game.Vote request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) { return vote(request, new grpc::CallOptions(headers, deadline, cancellationToken)); } - public virtual global::Game.Result vote(global::Game.Vote request, grpc::CallOptions options) + public virtual global::Game.Null vote(global::Game.Vote request, grpc::CallOptions options) { return CallInvoker.BlockingUnaryCall(__Method_vote, null, options, request); } - public virtual grpc::AsyncUnaryCall voteAsync(global::Game.Vote request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) + public virtual grpc::AsyncUnaryCall voteAsync(global::Game.Vote request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) { return voteAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); } - public virtual grpc::AsyncUnaryCall voteAsync(global::Game.Vote request, grpc::CallOptions options) + public virtual grpc::AsyncUnaryCall voteAsync(global::Game.Vote request, grpc::CallOptions options) { return CallInvoker.AsyncUnaryCall(__Method_vote, null, options, request); } - public virtual global::Game.Result ready(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.Null ready(global::Game.Null request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) { return ready(request, new grpc::CallOptions(headers, deadline, cancellationToken)); } - public virtual global::Game.Result ready(global::Game.Null request, grpc::CallOptions options) + public virtual global::Game.Null ready(global::Game.Null request, grpc::CallOptions options) { return CallInvoker.BlockingUnaryCall(__Method_ready, null, options, request); } - public virtual grpc::AsyncUnaryCall readyAsync(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::AsyncUnaryCall readyAsync(global::Game.Null request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) { return readyAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken)); } - public virtual grpc::AsyncUnaryCall readyAsync(global::Game.Null request, grpc::CallOptions options) + public virtual grpc::AsyncUnaryCall readyAsync(global::Game.Null request, grpc::CallOptions options) { return CallInvoker.AsyncUnaryCall(__Method_ready, null, options, request); } @@ -371,8 +401,8 @@ namespace Game { public static void BindService(grpc::ServiceBinderBase serviceBinder, LobbyBase serviceImpl) { serviceBinder.AddMethod(__Method_getGames, serviceImpl == null ? null : new grpc::ServerStreamingServerMethod(serviceImpl.getGames)); - serviceBinder.AddMethod(__Method_vote, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.vote)); - serviceBinder.AddMethod(__Method_ready, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.ready)); + serviceBinder.AddMethod(__Method_vote, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.vote)); + serviceBinder.AddMethod(__Method_ready, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.ready)); serviceBinder.AddMethod(__Method_status, serviceImpl == null ? null : new grpc::UnaryServerMethod(serviceImpl.status)); }