Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kon14/rusticpoker
A poker game gRPC server implementation, written in Rust 🦀🃏
https://github.com/kon14/rusticpoker
Last synced: 19 days ago
JSON representation
A poker game gRPC server implementation, written in Rust 🦀🃏
- Host: GitHub
- URL: https://github.com/kon14/rusticpoker
- Owner: kon14
- License: agpl-3.0
- Created: 2024-01-28T12:36:24.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-25T19:44:21.000Z (8 months ago)
- Last Synced: 2024-04-26T02:39:49.565Z (8 months ago)
- Language: Rust
- Size: 135 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
The server utilizes gRPC and the implementation is free and open-source.
The code is written with a primary emphasis on legibility.
Performance is barely ever going to be an issue for this use case.
As such, I've opted in favor of contextual clarity over squeezing out CPU and memory optimizations at the expense of readability.RusticPoker's server provides support for the [gRPC Server Reflection Protocol](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md).
If your client doesn't support gRPC reflection, you're going to have to provide it with [RusticPoker's `.proto` file](https://github.com/kon14/RusticPoker/blob/main/src/proto/rustic_poker.proto).---
``` bash
# Standard Build
docker build -t rustic-poker .# Enabling Development Features
docker build -t rustic-poker --build-arg BUILD_FEATURES="dbg_disable_client_watch,dbg_peer_addr_spoofing" .
`````` bash
docker run --name=rustic-poker -p 55100:55100 rustic-poker
```---
If you're interacting with the API through [`gRPCurl`](https://github.com/fullstorydev/grpcurl) or any similar API testing tool, you're most likely going to have to enable the following dev build features:
#### - `dbg_disable_client_watch`
Disables inactive client dropping.
Normally, any clients that don't maintain a persistent `Heartbeat` client stream get removed.#### - `dbg_peer_addr_spoofing`
Enables client spoofing via the `peer-address` request metadata header.
Besides allowing for client impersonation, this is extremely relevant for any gRPC test clients.
That is because the latter don't typically persist server connections and peer address ports usually change on every single connection.
As such, any test code or manual API interaction incapable of relying on a persistent connection would register as a separate client on every single request!Example Usage: `grpcurl -H 'peer-address: 0.0.0.0:55200' ...`
### [RPC Usage Examples via gRPCurl](examples/gRPCurl)
The examples provided utilize [`gRPCurl`](https://github.com/fullstorydev/grpcurl) as the gRPC client.
You may alternatively build your own client or choose any API testing tool of your choice.
The `awesome-grpc` repo maintains a [comprehensive list of useful tooling](https://github.com/grpc-ecosystem/awesome-grpc#tools).I'd strongly suggest consulting the RPC docs section and checking out the project's [.proto file](proto/rustic_poker.proto).
In the meantime, here's a brief usage example of a stateless RPC to get your feet wet:_Request:_
``` bash
grpcurl -plaintext -d \
'{"hands": ["2H 2D 2S 2C 6S", "2H 2D 2S 2C 6S", "2H 2D 2S 6H 2C", "2H 2D 2S 2C 5S", "AH AD 3S 3H 6C", "2H 2D 6H 2S 2C"]}' \
0.0.0.0:55100 rustic_poker.RusticPoker.RateHands
```_Response:_
``` bash
{
"winners": [
"2H 2D 2S 2C 6S",
"2H 2D 2S 6H 2C",
"2H 2D 6H 2S 2C"
]
}
```Our poker hand array input contains 5 stringified poker hand representations:
One of them is `Two Pairs`, while the others are `Four of a Kind`.Of the latter, only 3 are actually unique poker hands:
-`Four of a Kind`: `Quads(2), Kicker(6S)`
-`Four of a Kind`: `Quads(2), Kicker(6H)`
-`Four of a Kind`: `Quads(2), Kicker(5S)`Regarding the 2 cases of `Quads(2), Kicker(6)`, we have:
-2x str-duplicated representations of: `Quads(2), Kicker(6S)`
-2x card-shuffled representations of: `Quads(2), Kicker(6H)`Both the `Two Pairs` hand and the `Four of a Kind` with the lowest kicker get eliminated.
The str-duplicated hands get deduplicated, whereas the card-shuffled hands get returned as is!---
_Note: Host envs won't propagate inside the container._
| Variable | Description | Required | Default | Example |
|:-----------:|:---------------------------------------------------------------|:--------:|:-------:|:-------:|
| `GRPC_PORT` | Specifies the port number that the gRPC server will listen on. | False | `55100` | `55101` |