diff --git a/protobuf/protocol.proto b/protobuf/protocol.proto index 8a4fb78..f1b5839 100644 --- a/protobuf/protocol.proto +++ b/protobuf/protocol.proto @@ -27,6 +27,7 @@ message ClientServerPacket { // GAME game.CardKind queryCardImage = 12; game.CardId callOnClick = 13; + google.protobuf.Empty queryGameStatus = 14; } } diff --git a/server/src/server.rs b/server/src/server.rs index 854b71f..02fa79a 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -18,7 +18,7 @@ use crate::{ connection::{ connect, create_lobby, disconnect, get_public_lobbies, join_lobby_with_code, name, }, - game::{get_card_image, on_click}, + game::{get_card_image, on_click, query_status}, lobby::{leave, ready, users, vote}, }, server_properties::ServerProperties, @@ -244,6 +244,9 @@ pub async fn serve( .await .expect("Error handling on_click call") } + Data::QueryGameStatus(()) => query_status(&mut service_data, &socket_manager) + .await + .expect("Error handling game_status query"), } } if let Some(user) = service_data.user_id.0 { diff --git a/server/src/server/game.rs b/server/src/server/game.rs index fdb9771..2d36c7a 100644 --- a/server/src/server/game.rs +++ b/server/src/server/game.rs @@ -1,4 +1,8 @@ -use super::{ServiceData, protos::game::{game_status::Piles, CardKind, GameStatus, Image}, socket_manager::SocketManager}; +use super::{ + protos::game::{game_status::Piles, CardKind, GameStatus, Image}, + socket_manager::SocketManager, + ServiceData, +}; use crate::{ games::{CardId, CardIdx, Pile, PileKind}, server::protos::protocol::server_client_packet::Data, @@ -6,8 +10,7 @@ use crate::{ use anyhow::{anyhow, Result}; pub(super) async fn get_status(data: &mut ServiceData) -> Result { - let uuid = data - .user_id.get()?; + let uuid = data.user_id.get()?; log::info!("Creating a new status for {}", uuid); let lobby: u32 = match data.db.get_lobby_for_user(uuid).await { Some(l) => l, @@ -85,12 +88,21 @@ pub(super) async fn get_status(data: &mut ServiceData) -> Result { Ok(status) } -pub(super) async fn get_card_image(data: &mut ServiceData, - socket_mgr: &SocketManager, card_kind: CardKind) -> Result<()> { +pub(super) async fn query_status(data: &mut ServiceData, socket_mgr: &SocketManager) -> Result<()> { + let status = get_status(data).await?; + socket_mgr + .write(data.user_id.get_ref()?, Data::GameStatus(status)) + .await +} + +pub(super) async fn get_card_image( + data: &mut ServiceData, + socket_mgr: &SocketManager, + card_kind: CardKind, +) -> Result<()> { log::info!("Getting image location"); let time = std::time::Instant::now(); - let uuid = data - .user_id.get()?; + let uuid = data.user_id.get()?; let lobby: u32 = match data.db.get_lobby_for_user(uuid).await { Some(l) => l, None => return Err(anyhow!("User isn't in a lobby")), @@ -112,10 +124,13 @@ pub(super) async fn get_card_image(data: &mut ServiceData, log::info!("Loaded images [{:?}]", time.elapsed()); socket_mgr - .write(data.user_id.get_ref()?, Data::ReturnCardImage(Image { - face: face_buf, - back: back_buf, - })) + .write( + data.user_id.get_ref()?, + Data::ReturnCardImage(Image { + face: face_buf, + back: back_buf, + }), + ) .await?; Ok(()) } @@ -125,8 +140,7 @@ pub(super) async fn on_click( socket_mgr: &SocketManager, card: super::protos::game::CardId, ) -> Result<()> { - let uuid = data - .user_id.get()?; + let uuid = data.user_id.get()?; { let lobby: u32 = match data.db.get_lobby_for_user(uuid).await { Some(l) => l, @@ -157,7 +171,9 @@ pub(super) async fn on_click( } // drop the connection so that the lock is released let status = get_status(data).await?; - socket_mgr.broadcast_to_lobby(&mut data.db, data.user_id.get()?, Data::GameStatus(status)).await?; + socket_mgr + .broadcast_to_lobby(&mut data.db, data.user_id.get()?, Data::GameStatus(status)) + .await?; // self.update_status(uuid).await?; Ok(()) -} \ No newline at end of file +} diff --git a/server/src/server/protos/protocol.rs b/server/src/server/protos/protocol.rs index 2092d25..dfbefd3 100644 --- a/server/src/server/protos/protocol.rs +++ b/server/src/server/protos/protocol.rs @@ -1,6 +1,6 @@ #[derive(Clone, PartialEq, ::prost::Message)] pub struct ClientServerPacket { - #[prost(oneof="client_server_packet::Data", tags="1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13")] + #[prost(oneof="client_server_packet::Data", tags="1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14")] pub data: ::core::option::Option, } /// Nested message and enum types in `ClientServerPacket`. @@ -36,6 +36,8 @@ pub mod client_server_packet { QueryCardImage(super::super::game::CardKind), #[prost(message, tag="13")] CallOnClick(super::super::game::CardId), + #[prost(message, tag="14")] + QueryGameStatus(()), } } #[derive(Clone, PartialEq, ::prost::Message)] diff --git a/unity/Assets/Scripts/grpc/Protocol.cs b/unity/Assets/Scripts/grpc/Protocol.cs index 7c97ba2..b79dde5 100644 --- a/unity/Assets/Scripts/grpc/Protocol.cs +++ b/unity/Assets/Scripts/grpc/Protocol.cs @@ -26,7 +26,7 @@ namespace Protocol { string.Concat( "Cg5wcm90b2NvbC5wcm90bxIIcHJvdG9jb2waG2dvb2dsZS9wcm90b2J1Zi9l", "bXB0eS5wcm90bxoMY29tbW9uLnByb3RvGhBjb25uZWN0aW9uLnByb3RvGgts", - "b2JieS5wcm90bxoKZ2FtZS5wcm90byLKBAoSQ2xpZW50U2VydmVyUGFja2V0", + "b2JieS5wcm90bxoKZ2FtZS5wcm90byL9BAoSQ2xpZW50U2VydmVyUGFja2V0", "EisKCXF1ZXJ5TmFtZRgBIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5FbXB0eUgA", "Eh8KB2Nvbm5lY3QYAiABKAsyDC5jb21tb24uTmFtZUgAEiwKCmRpc2Nvbm5l", "Y3QYAyABKAsyFi5nb29nbGUucHJvdG9idWYuRW1wdHlIABIqCglqb2luTG9i", @@ -39,24 +39,25 @@ namespace Protocol { "eRgKIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5FbXB0eUgAEicKBWxlYXZlGAsg", "ASgLMhYuZ29vZ2xlLnByb3RvYnVmLkVtcHR5SAASKAoOcXVlcnlDYXJkSW1h", "Z2UYDCABKAsyDi5nYW1lLkNhcmRLaW5kSAASIwoLY2FsbE9uQ2xpY2sYDSAB", - "KAsyDC5nYW1lLkNhcmRJZEgAQgYKBGRhdGEioQMKElNlcnZlckNsaWVudFBh", - "Y2tldB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bm5lY3Rpb24uTG9i", + "YnlDb2RlSAASJgoLcmV0dXJuR2FtZXMYBCABKAsyDy5wcm90b2NvbC5HYW1l", + "c0gAEjMKE3JldHVyblB1YmxpY0xvYmJpZXMYBSABKAsyFC5wcm90b2NvbC5M", + "b2JieUNvZGVzSAASJgoLcmV0dXJuVXNlcnMYBiABKAsyDy5wcm90b2NvbC5O", + "YW1lc0gAEikKC2xvYmJ5U3RhdHVzGAcgASgLMhIubG9iYnkuTG9iYnlTdGF0", + "dXNIABImCg9yZXR1cm5DYXJkSW1hZ2UYCCABKAsyCy5nYW1lLkltYWdlSAAS", + "JgoKZ2FtZVN0YXR1cxgJIAEoCzIQLmdhbWUuR2FtZVN0YXR1c0gAQgYKBGRh", + "dGEiKAoFR2FtZXMSHwoFZ2FtZXMYASADKAsyEC5jb25uZWN0aW9uLkdhbWUi", + "NwoKTG9iYnlDb2RlcxIpCgpsb2JieUNvZGVzGAEgAygLMhUuY29ubmVjdGlv", + "bi5Mb2JieUNvZGUiJAoFTmFtZXMSGwoFbmFtZXMYASADKAsyDC5jb21tb24u", + "TmFtZWIGcHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.EmptyReflection.Descriptor, global::Common.CommonReflection.Descriptor, global::Connection.ConnectionReflection.Descriptor, global::Lobby.LobbyReflection.Descriptor, global::Game.GameReflection.Descriptor, }, new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { - new pbr::GeneratedClrTypeInfo(typeof(global::Protocol.ClientServerPacket), global::Protocol.ClientServerPacket.Parser, new[]{ "QueryName", "Connect", "Disconnect", "JoinLobby", "CreateLobby", "QueryGames", "QueryPublicLobbies", "QueryUsers", "Vote", "Ready", "Leave", "QueryCardImage", "CallOnClick" }, new[]{ "Data" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Protocol.ClientServerPacket), global::Protocol.ClientServerPacket.Parser, new[]{ "QueryName", "Connect", "Disconnect", "JoinLobby", "CreateLobby", "QueryGames", "QueryPublicLobbies", "QueryUsers", "Vote", "Ready", "Leave", "QueryCardImage", "CallOnClick", "QueryGameStatus" }, new[]{ "Data" }, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Protocol.ServerClientPacket), global::Protocol.ServerClientPacket.Parser, new[]{ "ReturnName", "ReturnConnect", "ReturnCreateLobby", "ReturnGames", "ReturnPublicLobbies", "ReturnUsers", "LobbyStatus", "ReturnCardImage", "GameStatus" }, new[]{ "Data" }, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Protocol.Games), global::Protocol.Games.Parser, new[]{ "Games_" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Protocol.LobbyCodes), global::Protocol.LobbyCodes.Parser, new[]{ "LobbyCodes_" }, null, null, null, null), @@ -136,6 +137,9 @@ namespace Protocol { case DataOneofCase.CallOnClick: CallOnClick = other.CallOnClick.Clone(); break; + case DataOneofCase.QueryGameStatus: + QueryGameStatus = other.QueryGameStatus.Clone(); + break; } _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); @@ -298,6 +302,17 @@ namespace Protocol { } } + /// Field number for the "queryGameStatus" field. + public const int QueryGameStatusFieldNumber = 14; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Google.Protobuf.WellKnownTypes.Empty QueryGameStatus { + get { return dataCase_ == DataOneofCase.QueryGameStatus ? (global::Google.Protobuf.WellKnownTypes.Empty) data_ : null; } + set { + data_ = value; + dataCase_ = value == null ? DataOneofCase.None : DataOneofCase.QueryGameStatus; + } + } + private object data_; /// Enum of possible cases for the "data" oneof. public enum DataOneofCase { @@ -315,6 +330,7 @@ namespace Protocol { Leave = 11, QueryCardImage = 12, CallOnClick = 13, + QueryGameStatus = 14, } private DataOneofCase dataCase_ = DataOneofCase.None; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -354,6 +370,7 @@ namespace Protocol { if (!object.Equals(Leave, other.Leave)) return false; if (!object.Equals(QueryCardImage, other.QueryCardImage)) return false; if (!object.Equals(CallOnClick, other.CallOnClick)) return false; + if (!object.Equals(QueryGameStatus, other.QueryGameStatus)) return false; if (DataCase != other.DataCase) return false; return Equals(_unknownFields, other._unknownFields); } @@ -374,6 +391,7 @@ namespace Protocol { if (dataCase_ == DataOneofCase.Leave) hash ^= Leave.GetHashCode(); if (dataCase_ == DataOneofCase.QueryCardImage) hash ^= QueryCardImage.GetHashCode(); if (dataCase_ == DataOneofCase.CallOnClick) hash ^= CallOnClick.GetHashCode(); + if (dataCase_ == DataOneofCase.QueryGameStatus) hash ^= QueryGameStatus.GetHashCode(); hash ^= (int) dataCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -443,6 +461,10 @@ namespace Protocol { output.WriteRawTag(106); output.WriteMessage(CallOnClick); } + if (dataCase_ == DataOneofCase.QueryGameStatus) { + output.WriteRawTag(114); + output.WriteMessage(QueryGameStatus); + } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -504,6 +526,10 @@ namespace Protocol { output.WriteRawTag(106); output.WriteMessage(CallOnClick); } + if (dataCase_ == DataOneofCase.QueryGameStatus) { + output.WriteRawTag(114); + output.WriteMessage(QueryGameStatus); + } if (_unknownFields != null) { _unknownFields.WriteTo(ref output); } @@ -552,6 +578,9 @@ namespace Protocol { if (dataCase_ == DataOneofCase.CallOnClick) { size += 1 + pb::CodedOutputStream.ComputeMessageSize(CallOnClick); } + if (dataCase_ == DataOneofCase.QueryGameStatus) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(QueryGameStatus); + } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -642,6 +671,12 @@ namespace Protocol { } CallOnClick.MergeFrom(other.CallOnClick); break; + case DataOneofCase.QueryGameStatus: + if (QueryGameStatus == null) { + QueryGameStatus = new global::Google.Protobuf.WellKnownTypes.Empty(); + } + QueryGameStatus.MergeFrom(other.QueryGameStatus); + break; } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); @@ -775,6 +810,15 @@ namespace Protocol { CallOnClick = subBuilder; break; } + case 114: { + global::Google.Protobuf.WellKnownTypes.Empty subBuilder = new global::Google.Protobuf.WellKnownTypes.Empty(); + if (dataCase_ == DataOneofCase.QueryGameStatus) { + subBuilder.MergeFrom(QueryGameStatus); + } + input.ReadMessage(subBuilder); + QueryGameStatus = subBuilder; + break; + } } } #endif @@ -906,6 +950,15 @@ namespace Protocol { CallOnClick = subBuilder; break; } + case 114: { + global::Google.Protobuf.WellKnownTypes.Empty subBuilder = new global::Google.Protobuf.WellKnownTypes.Empty(); + if (dataCase_ == DataOneofCase.QueryGameStatus) { + subBuilder.MergeFrom(QueryGameStatus); + } + input.ReadMessage(subBuilder); + QueryGameStatus = subBuilder; + break; + } } } }