API Documentation

This document describes the internal API of openRoads for developers who want to extend or modify the game.

World Management API

Loading the World

func LoadWorld() map[string]*Room

Loads the game world from the JSON file and returns a map of room IDs to Room objects.

Saving the World

func SaveWorld(worldData map[string]*Room) error

Saves the current state of the game world to the JSON file.

Room Structure

type Room struct {
    Short   string                   // Short description
    Long    string                   // Long description
    Exits   map[string]string        // Map of directions to room IDs
    Items   []map[string]interface{} // Items in the room
    Players []string                 // Players in the room
}

Player Management API

Getting a Player

func GetPlayer(s *Session) (*Player, error)

Retrieves a player object based on the session.

Getting a User by Client Name

func GetUserByClientName(clientName string) (*User, bool)

Looks up a user by their client name and returns the user object if found.

User Structure

type User struct {
    Conn          net.Conn
    Alias         string // In-game alias
    ClientName    string // Actual client username
    CurrentRoomID string // Current room ID
}

Player Structure

type Player struct {
    Alias         string
    Element       string
    CurrentRoomID string
    Brief         bool
    // Other player attributes
}

Session Management API

Session Structure

type Session struct {
    Conn       net.Conn
    ClientName string
    ServerName string
    TermType   string
}

Configuration API

Loading Configuration

func LoadConfig(filename string) (*AppConfig, error)

Loads the configuration from the specified file.

Getting Configuration

func GetConfig() *AppConfig

Returns the currently loaded configuration.

Configuration Structure

type AppConfig struct {
    NightlyCleanupTime string
    ActiveRoomCleanup  bool
    // Other configuration fields
}

Background Routines API

Starting the Engine

func StartEngine(loadWorld WorldLoader, saveWorld WorldSaver, cleanupEveryMinute bool, clients map[string]*lib.Session, clientsMu *sync.Mutex)

Initializes and runs all necessary background processes for the game.

Scheduling Cleanup

func ScheduleCleanup(cleanupTime string, loadWorld WorldLoader, saveWorld WorldSaver, everyMinute bool)

Schedules periodic cleanup operations.

Nightly Cleanup

func NightlyCleanup(loadWorld WorldLoader, saveWorld WorldSaver)

Performs the actual cleanup operations.

Last updated

Was this helpful?