Skip to content

Commit 16cd64e

Browse files
committed
fixes #547 get_game rpc
1 parent e328c84 commit 16cd64e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

cpp/golf_grpc/server/golf_grpc_service.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ Status GolfServiceImpl::SwapForDiscard(ServerContext* context,
7070
Status GolfServiceImpl::Knock(ServerContext* context, const golf_grpc::KnockRequest* request,
7171
golf_grpc::KnockResponse* response) {
7272
return Status::OK;
73+
}
74+
75+
grpc::Status GolfServiceImpl::GetGame(grpc::ServerContext* context,
76+
const golf_grpc::GetGameRequest* request,
77+
golf_grpc::GetGameResponse* response) {
78+
auto status_or_game_state = gm_->getGameStateForUser(request->game_id(), request->user_id());
79+
auto mutable_game_state = response->mutable_game_state();
80+
81+
auto status_to_return =
82+
HandleGameStateResponse(status_or_game_state, request->user_id(), mutable_game_state);
83+
if (status_to_return.ok()) {
84+
auto& game_state = status_or_game_state.value();
85+
if (mutable_game_state->your_turn() && game_state->getPeekedAtDrawPile()) {
86+
FlipCard(mutable_game_state->mutable_top_draw(), game_state->getDrawPile());
87+
}
88+
}
89+
return status_to_return;
7390
};
7491

7592
void GolfServiceImpl::HydrateResponseGameState(const string& current_user_id,

cpp/golf_grpc/server/golf_grpc_service.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class GolfServiceImpl final : public golf_grpc::Golf::Service {
2929
golf_grpc::SwapForDiscardResponse* response) override;
3030
grpc::Status Knock(grpc::ServerContext* context, const golf_grpc::KnockRequest* request,
3131
golf_grpc::KnockResponse* response) override;
32+
grpc::Status GetGame(grpc::ServerContext* context, const golf_grpc::GetGameRequest* request,
33+
golf_grpc::GetGameResponse* response) override;
3234

3335
private:
3436
void HydrateResponseGameState(const std::string& current_user_id,

protos/golf_grpc/golf.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ service Golf {
1313
rpc SwapForDraw (SwapForDrawRequest) returns (SwapForDrawResponse) {}
1414
rpc SwapForDiscard (SwapForDiscardRequest) returns (SwapForDiscardResponse) {}
1515
rpc Knock (KnockRequest) returns (KnockResponse) {}
16+
rpc GetGame (GetGameRequest) returns (GetGameResponse) {}
1617
}
1718

1819
message RegisterUserRequest {
@@ -94,6 +95,15 @@ message KnockResponse {
9495
GameState game_state = 1;
9596
}
9697

98+
message GetGameRequest {
99+
string user_id = 1;
100+
string game_id = 2;
101+
}
102+
103+
message GetGameResponse {
104+
GameState game_state = 1;
105+
}
106+
97107
message VisibleHand {
98108
cards_proto.Card bottom_left = 1;
99109
cards_proto.Card bottom_right = 2;

0 commit comments

Comments
 (0)