pixelbattle

command module
v0.0.0-...-672060c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

README

Go Report Card License

🎨 Pixelbattle - Backend ⚙️

Blazingly fast ⚡ and reliable 🦾 backend for the pixelbattle game.

This repository is a part of pixelbattle series - a full stack journey into creating a simple, production grade service.

📝 Protocol

  1. The client connects to the websocket endpoint. Based on its session cookie, auth server provides a user id (or says that cookie is incorrect).
  2. Server sends image of a canvas in png format to the client, as a binary message.
  3. Client and server exchange symmetric canvas update messages in JSON format: {"pos": [x, y], "color": [r, g, b]}

🤔 Interesting facts

Initially, this project was supposed to be written in Rust. However unfortunately, Rust's websocket implementation, tungstenite, didn't have the feature I needed. So this one goes to the Gophers.

For this project I had to write my own mpmc channel for broadcasting canvas changes. Maybe go already had something like it, or I could kludge something up with the go channels, but I've decided that it would be better just to write it from scratch.

Here's some info about this channel:

  • It's a multi-producer multi-consumer channel (obviously).
  • It's based on a ring buffer.
  • The buffer is shared between all consumers and producers.
  • Sending messages never fails and never blocks (unless you do simultaneous reads/writes).
  • If the consumer is lagging behind by more than the buffer size, current read failes, and consumer queue is reset to the top message in channel.
  • No messages are lost (unless consumer had lagged behind).

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL