← All Workshops

MudEngine Part 6: Multiplayer

Step 7 / 18

Static Room Data

The 9 rooms and their connections are pure data — they do not change while the game runs, and both sides need them:

  • The server validates movement against the exit table (it stays authoritative).
  • The client uses the same table to highlight and allow clicking reachable rooms, and reads room names/descriptions for display.

Because the data is identical on both sides, we store it once in src/game/room_data.rs and share it between the server and the client. ROOM_NAMES and ROOM_DESCS are pub static (readable from any component), and EXITS is a pub const array.

mud-engine/src/game/room_data.rs
// ── Static room data (shared by client and server) ──

pub static ROOM_NAMES: &[&str] = &[
    "Forest Path", "Hilltop", "Abandoned Tower",
    "Dark Forest", "Town Square", "Temple Courtyard",
    "Riverbank", "Old Bridge", "Graveyard",
];

pub static ROOM_DESCS: &[&str] = &[
    "A winding path leads through ancient oaks. Sunlight filters through the canopy.",
    "From this vantage point you can see the entire valley. A cool breeze carries the scent of pine.",
    "A crumbling stone tower stands alone. Vines crawl up its walls and crows nest in the windows.",
    "Twisted trees block out most of the light. Strange sounds echo through the undergrowth.",
    "A bustling town square with a fountain at its center. Cobblestones gleam from the morning rain.",
    "Ancient stone pillars surround a quiet courtyard. Moss clings to weathered statues.",
    "A slow-moving river borders a muddy bank. Frogs croak from the reeds.",
    "A weathered stone bridge crosses the river. Moss covers the ancient masonry.",
    "Rows of moss-covered headstones stretch into the fog. An iron gate creaks in the wind.",
];

/// Exit table: for each room index, a list of (direction, destination) pairs.
/// The client uses it to highlight and allow clicking reachable rooms;
/// the server uses it to validate moves.
pub const EXITS: &[&[(&str, usize)]] = &[
    &[("south", 3), ("east", 1)],                            // 0 Forest Path
    &[("south", 4), ("west", 0), ("east", 2)],               // 1 Hilltop
    &[("south", 5), ("west", 1)],                            // 2 Abandoned Tower
    &[("north", 0), ("south", 6), ("east", 4)],              // 3 Dark Forest
    &[("north", 1), ("south", 7), ("west", 3), ("east", 5)], // 4 Town Square
    &[("north", 2), ("south", 8), ("west", 4)],              // 5 Temple Courtyard
    &[("north", 3), ("east", 7)],                            // 6 Riverbank
    &[("north", 4), ("west", 6), ("east", 8)],               // 7 Old Bridge
    &[("north", 5), ("west", 7)],                            // 8 Graveyard
];
Step 7 / 18