Technical Specification: Hybrid Room System - wwestlake/Labyrinth GitHub Wiki

Technical Specification: Hybrid Room System

1. Overview

This document details the implementation of the hybrid room system in the MUD, using MongoDB for data storage. The system employs a grid-based structure for rooms, with six directions of movement (north, south, east, west, up, and down) and allows for special teleportation exits. Rooms can primarily be created by admins, but players in guilds can create special Guild Rooms under certain conditions.

2. Data Model

2.1 Room Model

The Room model represents each room in the MUD. Rooms are stored in the rooms collection in MongoDB.

Room Model Structure:

  • _id: Unique identifier for the room document.
  • roomId: A unique string identifier for easy reference.
  • coordinates: The (x, y, z) coordinates of the room in the grid.
  • description: A text description of the room.
  • exits: Links to adjacent rooms (north, south, east, west, up, down).
  • specialExits: Array of teleportation exits or special doors with specific conditions.
  • owner: Identifies the room owner, which could be an admin, a guild, or a player.
  • permissions: Access control lists defining who can enter or modify the room.

Example structure of a room document:

  • _id: "ObjectId"
  • roomId: "string"
  • coordinates: { "x": "int", "y": "int", "z": "int" }
  • description: "string"
  • exits:
    • north: "ObjectId or null"
    • south: "ObjectId or null"
    • east: "ObjectId or null"
    • west: "ObjectId or null"
    • up: "ObjectId or null"
    • down: "ObjectId or null"
  • specialExits: [
    • name: "string"
    • targetRoomId: "ObjectId"
    • conditions: "array of conditions or null" ]
  • owner: "string"
  • permissions:
    • canEnter: "array of user roles or IDs"
    • canModify: "array of user roles or IDs"

3. Database Structure

3.1 Collections

  • rooms: Stores all room documents.

3.2 Indexing

  • Room Coordinates: Index (x, y, z) in the rooms collection for quick lookup by location.
  • Room Exits: Index roomId in exits and specialExits for fast room traversal.

4. Room Creation Process

4.1 Admin Room Creation

  • Creation: Admins create rooms by specifying the room details, including coordinates, exits, and description.
  • Linking Rooms: Rooms are linked by updating the exits field of the corresponding room documents with the roomId of the adjacent room.

4.2 Guild Room Creation

  • Eligibility: Guilds can create a room when they meet a predefined membership requirement.
  • Creation: The guild leader triggers the creation of a Guild Room, which is then linked to the guild’s existing territory or a specified coordinate in the grid.
  • Customization: Once created, the guild leader can customize the room’s description and exits, subject to admin approval.

4.3 Room Linking

  • Standard Exits: Rooms are connected via standard exits (north, south, east, west, up, down) by referencing adjacent room IDs.
  • Special Exits: Special exits can be added to link to non-adjacent rooms or create teleportation paths. These exits can have conditions, such as item requirements or player status.

5. Security and Access Control

  • Access Control: Rooms have ACLs that define which users or roles can enter or modify the room. This ensures that only authorized players or guild members can access or alter room settings.
  • Ownership: Rooms created by admins are typically public or system-owned. Guild Rooms are owned by the guild, with permissions managed by the guild leader.

6. Error Handling

  • Room Creation Errors: Includes checks for duplicate coordinates, invalid exits, or permission issues.
  • Movement Errors: Handles cases where players attempt to move in an invalid direction or use an unauthorized special exit.