Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building a multiplayer game server in Go and We...

GoDays
January 22, 2020

Building a multiplayer game server in Go and Webassembly - Arne Wieding - Delivery Hero

The talk discusses the functionalities of Triebwerk, an experimental Go multiplayer game server that I have developed for the browser game http://panzerkampf.io, which is a side project of mine (still in development). Video of the game and multiplayer techniques used: https://www.youtube.com/watch?v=TC6hluQ8UjY

The talk details the implementation of the server in Golang. To achieve that It first illustrates the basics of multiplayer game development in regards to networking and latency compensation techniques. It then briefly goes over the overall architecture of the game server and the algorithms for player movement, collision and hit detection and their implementation in Go
In addition, the talk details how to reuse the core game logic written in Go as a Webassembly module in the Javascript client of the game, using the latest WebAssembly features of Go v1.13. The usage of WebAssembly enables the use of the same code on the server and on the client, which allows Go to replace Node.Js for similar use cases.

GoDays

January 22, 2020
Tweet

More Decks by GoDays

Other Decks in Technology

Transcript

  1. Building a multiplayer game server in Go and Webassembly by

    Arne Wieding https://twitter.com/awdng https://github.com/awdng
  2. whoami && whatisthis Arne is: • A Software Engineer at

    Delivery Hero • The angry German • Not a professional Game-Developer The project: • Called Panzr.io • Just a side-project and very much a prototype • The server is open-source • You probably should not use it (in production)
  3. Introducing Panzr.io • A game based on open-source technologies •

    Using the web as a distribution platform • Lightweight and fast • Exploring fundamental multiplayer techniques • Extend Go knowledge
  4. Panzr.io Architecture Client Application Three.js Firebase Game Component Web browser

    Javascript Environment WebGL Vue.js Golang runtime Game Component Gorilla Websocket Game Logic WebAssembly Module Websocket over TCP/IP Server Application Websocket
  5. Panzr.io Deployment Caching Play via Websocket Amazon S3 Game Client

    Web browser API Server Cloudflare Dedicated Server Game Server Docker Container Game Server Docker Container Update Game State via GRPC Player / Game data via REST using GRPC Gateway
  6. Introducing Triebwerk https://github.com/awdng/triebwerk Status: • Multiplayer server Triebwerk is Open-Source

    • Written in Go (obviously) • Just a prototype • Fork it to port it to your game • Feedback/Contributions welcome!
  7. How do games actually work? Process Input Update Game world

    Render Game world 60 FPS = ~16.67ms per Update The game loop
  8. Server Authoritative Architecture • Communication only through the server •

    Clients send all their input to the server • Server has the authority over the simulation • Prevents cheating but introduces latency
  9. Client side prediction and server reconciliation • First popularised by

    QuakeWorld • Simulate movement locally • Constantly sync with the server state • Correct local state based on server state
  10. Client interpolation • Network Updates < Frames per Second •

    Interpolation between past states • Conservative algorithm • No extrapolation
  11. Defining boundaries Limitations: • all game logic only in 2D

    Space • Even surfaces • Input control via keyboard only • Limited map size • Slow-moving vehicles • No physics engine
  12. Server implementation Game Loop Protocol Websocket Transport GameState Collider Info

    Controls (0..n) Player Map Weapons NetworkManager Clients Encoding / Decoding Sending / Receiving Receiving Input Broadcasting State Updating State
  13. Binary Data Transfer • Minimises the resource usage • Prevent

    packet segmentation • Minimises effects of packet loss
  14. • Filesize > 2MB • Server and client compute the

    state based on the same logic • Data transfer through binary types WebAssembly Module Game logic Server → Client
  15. Wrapping up Results and Learnings • Playable prototype • Isomorphic

    apps using WebAssembly • Multiplayer server with low resource usage • Based entirely on Open Source • It's fun! What else? • Triebwerk clean-up • Releasing Panzr.io • Article series on implementation details • https://github.com/awdng/triebwerk • Please do whatever you want with it https://twitter.com/awdng https://github.com/awdng