H. Jun Huh

I built a game server for the web using Rust.

Translated by GPT

I built a web game server with Rust.

Among several candidate languages for game servers like Go, C++, and Rust, I ultimately chose Rust. Recently, it was integrated into the Space Zero production and is operating without issues. While performance is important for game servers, how reliably they operate and how well they can defend against cheats are also crucial factors. Rust was a good choice in all these aspects.

  1. Integration with the Physics Engine

Space Zero adopts the Rapier physics engine. Rapier is an engine developed in Rust and can be ported to WASM for simultaneous use in browsers. Therefore, it can be used on both web and server. Thanks to its high compatibility, creating the game server in Rust allows filtering out some cheating through physical detection. Although it might be difficult to prevent manipulation on the client side, severe cheating like killing enemies globally or expelling all players can mostly be prevented.

As a result, client-server simultaneous verification becomes possible, allowing faster cheat processing.

  1. Memory Safety

One of Rust’s features, memory safety, is advantageous for game servers. It can fundamentally block server manipulation and is suitable for game servers due to its high security. Stability can be ensured without a runtime GC, allowing real-time processing without frame drops.

Moreover, unexpected errors are mostly caught at the pre-compilation stage, reducing the need for server maintenance. Given the nature of game servers, stages like mid-term checks are necessary, but it becomes possible to operate the game server virtually without interruption, greatly enhancing user experience.

  1. Real-time & Performance

Rust is a language created to replace C++. Considering that game servers have adopted C++ for real-time performance, Rust is also deemed suitable for real-time performance. Additionally, the good ecosystem based on the Cargo package manager helps boost performance. WebSocket libraries and communication libraries are well-developed, and you can build them yourself. A representative example might be Cloudflare.

In the case of Cloudflare, they built an HTTP proxy with Rust to enhance the overall system efficiency. Recently, they have also written their WAF in Rust, capturing security, stability, and performance. As a language with strengths in low-level networking, it can be considered suitable for game servers that require high performance and real-time capabilities.

← Back