2.5 KiB
Implementation
This document goes into detail about the implementation of the game and the tech-stack used.
Tech-Stack
- Vue for the frontend (except for the tilemap)
- Go for the backend
- gorilla/websocket for real time connections
- Postgres
Architecture and Networking
Ecosim uses a simple client-server architecture where the client runs in the browser and is connected to the server using a web socket. The client only connects to running games using a web socket. A REST API is used for everything else, like the registration, login, setting up a game, and so on.
Should a player join a running game, for example after losing the connection, the game will be paused until the client has catched up to the current state of the game. The state is simply represented by the current ingame date and time (timestamp).
Games are started by a player and automatically closed and saved when the last player leaves. It's possible to configure this behavior. When a new game is created the player can decide whether he would like to wait for all players to be present, pause the game when someone loses the connection, or make it open so that player can hot join and leave whenever they want. Games can be protected by passwords and are browsed on a global list.
The server and client communicate through a simple TCP (web socket) and JSON protocol. The client receives updates to the game state and sents commands that are validated on the server. This will prevent anyone from cheating. The state updates contain the current ingame date and time (timestamp), that can be used to validate that no state updates are missing. While the game is running a new state will only be produced once a tick has been calculated. The game speed can be configured when creating a game. The default will be set to one ingame hour = one second, so 24 seconds represent a ingame single day.
Authentication
For authentication oAuth with a refresh token will be used. Clients need to authenticate themselves when connecting to a game.
Tilemap
The tilemap is implemented as a simple 2D array of objects. Each tile has an owner, properties of it's type, price, and so on. Maps are crafted by hand and don't change during the game, except for some population growth (new houses, higher demand) and changes made by the players. Roads for example cannot be changed. Each map has a biome, which sets the basic theme for the map (desert, green, artic, ...).
Savegames
Savegames are stored in Postgres as JSON blobs and serialized/deserialized when saving/loading a game.