← All Workshops

MudEngine Part 7: Save & Load

Persist the World

In Part 6 the game world (room names, descriptions, exits) was hardcoded in static arrays in main.rs. Every time the server restarts, all state resets — rooms and connected players are gone.

In this part we make the game data-driven again, following the pattern from Part 3:

  • The full 9-room world moves into a game.toml file in the project root
  • The server loads game.toml at startup — if the file is missing, the server panics
  • Every connected player and their position is tracked in the same file
  • On every player join, move, and disconnect, the server writes the updated player list back to disk

This gives us two things: the world definition is editable without recompiling, and player positions survive a server restart (until you restart with real players, at which point they reconnect fresh).

Architecture

game.toml ──load──▶  GameState { rooms, players }
                        │
            ┌───────────┼───────────┐
            ▼           ▼           ▼
        Player join  Player move  Player leave
            │           │           │
            └───────────┼───────────┘
                        ▼
            save_game_state() ──▶ game.toml

On the client side, the hardcoded ROOM_NAMES and ROOM_DESCS statics disappear. The server now sends room data as part of the initial State message, and the client renders room names from that data.

"server startup" "initial State message" "on every join/move/leave" game.toml rooms + players load_game_state() GameState { rooms, players } save_game_state() Browser room names + descriptions