Backend server for the Quackers mmo game.
Simply use the use the cargo run
command to run the program. There is no additional configuration needed.
The server will run on 0.0.0.0:8000.
To get the full game experience, you can also run the front-end code for this (also a Rust project, made with Bevy).
Add secrets in github actions environment secrets:
BACKEND_WS_ENDPOINT =
SERVER_IP_ADDRESS =
then make a new git tag that includes the phrase "beta" and push it. eg:
git tag v0.0.1-beta
git push --tags
The regular cargo build won't deploy to ubuntu linx so we'll use cross to compile a build that will work.
Install cross into cargo if you haven't already:
cargo install cross --git https://github.com/cross-rs/cross
Add target for the linux distro you will be deploying to:
rustup target add x86_64-unknown-linux-gnu
Compile for ubuntu
cross build --target x86_64-unknown-linux-gnu --release
ssh root@your_ip
Once connected, clients can send these types of messages
Note: Requests must come in to the server as properly formed JSON! And likewise, responses will be JSON...
The structure of the request:
{ actionType: String, data: Value }
Allows a user to send a message that he or she is quacking.
Request
{
requestType: "quack",
data: {}
}
The server will then blast a message to all connected users, letting them know which user is quacking.
Response
{
responseType: "quack",
data: {
userId: String
}
}
{ "action_type": "bar", "data": "hey" }
Allows a user to send a message that he or she is quacking.
Request
{
requestType: "move",
data: {
direction: {
x: u64,
y: u64
}
}
}
The server will then accept the direction a player wants to move, calculates the player's new position, and blast a message to all connected users, letting them the user's new position.
Response
{
responseType: "move",
data: {
userId: String,
position: {
x: u64,
y: u64
}
}
}
There is no request needed for this event. When each player moves the server will calculate if the player is touching a "cracker". If so:
- player is awarded points
- leaderboard is updated
- a new "cracker" is spawned randomly on the map
Everyone see that the user gained crackers:
Response
{
responseType: "cracker",
data: {
userId: String,
newScore: u64
old_position: {
x: u64,
y: u64
},
new_position: {
x: u64,
y: u64
}
}
}
This code was inspired by the article and example project that can be found here: TMS Blog - Rust Warp WebSocket server
Thanks tmsdev82!