Skip to content

A poker game gRPC server implementation, written in Rust πŸ¦€πŸƒ

License

Notifications You must be signed in to change notification settings

kon14/RusticPoker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


A poker game service written in Rust πŸ¦€


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.
If your client doesn't support gRPC reflection, you're going to have to provide it with RusticPoker's .proto file.


Building πŸ”¨

# 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" .

Running πŸ’»

docker run --name=rustic-poker -p 55100:55100 rustic-poker

Documentation πŸ“š

If you're interacting with the API through 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' ...

The examples provided utilize 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.

I'd strongly suggest consulting the RPC docs section and checking out the project's .proto file.
In the meantime, here's a brief usage example of a stateless RPC to get your feet wet:

RateHands

Request:

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:

{
  "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!


Environment Variables πŸ“ƒ

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

About

A poker game gRPC server implementation, written in Rust πŸ¦€πŸƒ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published