一款基于 Rust 和 WebAssembly 的多人棋盘游戏
A multiplayer board game in Rust and WebAssembly
使用 Rust 和 WebAssembly 构建的多人棋盘游戏
Pont is an online implementation of Qwirkle, a board game by Mindware Games. It was written for my parents, so they could play with friends and family during the COVID-19 stay-at-home era.
Pont 是 Qwirkle(Mindware Games 出品的一款棋盘游戏)的在线实现。它是为我的父母编写的,以便他们在 COVID-19 居家期间能与朋友和家人一起玩。
Play is split into rooms, which are identified by a three-word code (size moody shape in the image above). Within each room, the game distributes pieces, enforces the game rules, and provides a local chat window.
游戏被划分为多个房间,每个房间由一个三个单词的代码标识(上图中的 size moody shape)。在每个房间内,游戏分发棋子、执行游戏规则,并提供一个本地聊天窗口。
Unusually, it's a web-based multiplayer game without any Javascript: both the client and server are written in Rust, which is compiled into WebAssembly to run on the browser. (There's a Javascript shim to load the WebAssembly module, but I didn't have to write it myself)
不同寻常的是,这是一个没有任何 Javascript 的基于 Web 的多人游戏:客户端和服务器都是用 Rust 编写的,并编译为 WebAssembly 以在浏览器中运行。(有一个 Javascript 垫片用于加载 WebAssembly 模块,但我不需要自己编写它)
Architecture
架构
Keep in mind, I'm not a web developer, so this is probably a weird outsider architecture for web applications. Here's what the system looks like:
请记住,我不是 Web 开发人员,所以这可能是一种奇怪的 局外人架构,用于 Web 应用程序。以下是系统的结构:
The system uses Let's Encrypt for certificates: both static assets and WebSocket communication are encrypted between the client and the server. The game server does not communicate securely with the NGINX proxy, but if anyone is on the server watching, I've got bigger problems.
系统使用 Let's Encrypt 提供证书:客户端和服务器之间的静态资源与 WebSocket 通信均被加密。游戏服务器与 NGINX 代理之间没有进行安全通信,但如果有人能在服务器上监听,那我面临的问题就大得多了。
The wasm bundle and pont-server executable are both written in Rust and managed in the pont repository. They both depend on pont-common, which defines basic types and logic for gameplay (e.g. so that both the client and server can check whether a move is legal).
wasm 包和 pont-server 可执行文件均使用 Rust 编写,并在pont 仓库中进行管理。它们都依赖于pont-common,该库定义了游戏的基本类型和逻辑(例如,以便客...
