core

package module
v0.0.0-...-994ac0b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 36 Imported by: 4

Documentation

Index

Constants

View Source
const (
	DefaultDistance = 30.0 // Default starting distance
	MeleeRange      = 5.0  // Distance for melee combat
	PoleRange       = 10.0 // Distance for pole weapons
	FarRange        = 30.0 // Distance for far range
	VeryFarRange    = 50.0 // Maximum combat distance
)
View Source
const FalsePositiveRate = 0.01 // 1% bloom filter false positive rate

Variables

View Source
var ColorMap = map[string]string{
	"black":          "30",
	"red":            "31",
	"green":          "32",
	"yellow":         "33",
	"blue":           "34",
	"magenta":        "35",
	"cyan":           "36",
	"white":          "37",
	"bright_black":   "90",
	"bright_red":     "91",
	"bright_green":   "92",
	"bright_yellow":  "93",
	"bright_blue":    "94",
	"bright_magenta": "95",
	"bright_cyan":    "96",
	"bright_white":   "97",
}

ColorMap maps color names to ANSI color codes.

View Source
var (
	Logger *slog.Logger
)

Global variables

View Source
var WearLocations = map[string]bool{
	"head":         true,
	"neck":         true,
	"shoulders":    true,
	"chest":        true,
	"back":         true,
	"arms":         true,
	"hands":        true,
	"waist":        true,
	"legs":         true,
	"feet":         true,
	"left_finger":  true,
	"right_finger": true,
	"left_wrist":   true,
	"right_wrist":  true,
}

WearLocations defines all possible locations where an item can be worn

Functions

func ApplyColor

func ApplyColor(colorName, text string) string

ApplyColor applies the specified color to the text if the color exists in ColorMap.

func AutoSave

func AutoSave(game *Game, stop chan os.Signal)

AutoSave periodically saves the game state in the background.

func Challenge

func Challenge(attacker, defender, balance float64) float64

func ChangePassword

func ChangePassword(player *Player, oldPassword, newPassword string) error

func ConfirmUser

func ConfirmUser(email, confirmationCode string, config Configuration) (*cognitoidentityprovider.ConfirmSignUpOutput, error)

func DisplayArchetypes

func DisplayArchetypes(g *Game)

DisplayArchetypes logs the loaded archetypes for debugging purposes.

func DisplayPrototypes

func DisplayPrototypes(prototypes map[uuid.UUID]*Prototype)

DisplayPrototypes logs the details of each prototype for debugging purposes.

func DisplayRooms

func DisplayRooms(rooms map[int64]*Room)

DisplayRooms logs information about all rooms, useful for debugging.

func DisplayUnseenMOTDs

func DisplayUnseenMOTDs(server *Server, player *Player)

func EnableXRay

func EnableXRay(cfg *Configuration) error

func ExecuteAdvanceCommand

func ExecuteAdvanceCommand(character *Character, tokens []string) bool

func ExecuteAssessCommand

func ExecuteAssessCommand(character *Character, tokens []string) bool

func ExecuteChallengeCommand

func ExecuteChallengeCommand(character *Character, tokens []string) bool

func ExecuteCommand

func ExecuteCommand(character *Character, verb string, tokens []string) bool

func ExecuteDropCommand

func ExecuteDropCommand(character *Character, tokens []string) bool

func ExecuteExamineCommand

func ExecuteExamineCommand(character *Character, tokens []string) bool

func ExecuteFaceCommand

func ExecuteFaceCommand(character *Character, tokens []string) bool

func ExecuteGoCommand

func ExecuteGoCommand(character *Character, tokens []string) bool

func ExecuteHelpCommand

func ExecuteHelpCommand(character *Character, tokens []string) bool

func ExecuteInventoryCommand

func ExecuteInventoryCommand(character *Character, tokens []string) bool

func ExecuteLookCommand

func ExecuteLookCommand(character *Character, tokens []string) bool

func ExecutePasswordCommand

func ExecutePasswordCommand(character *Character, tokens []string) bool

func ExecuteQuitCommand

func ExecuteQuitCommand(character *Character, tokens []string) bool

func ExecuteRemoveCommand

func ExecuteRemoveCommand(character *Character, tokens []string) bool

func ExecuteRetreatCommand

func ExecuteRetreatCommand(character *Character, tokens []string) bool

func ExecuteSayCommand

func ExecuteSayCommand(character *Character, tokens []string) bool

func ExecuteShowCommand

func ExecuteShowCommand(character *Character, tokens []string) bool

func ExecuteTakeCommand

func ExecuteTakeCommand(character *Character, tokens []string) bool

func ExecuteWearCommand

func ExecuteWearCommand(character *Character, tokens []string) bool

func ExecuteWhoCommand

func ExecuteWhoCommand(character *Character, tokens []string) bool

func GetEnv

func GetEnv(key, defaultValue string) string

GetEnv retrieves environment variables or returns a default value if not set

func GetUserData

func GetUserData(accessToken string, config Configuration) (*cognitoidentityprovider.GetUserOutput, error)

func InitializeBloomFilter

func InitializeBloomFilter(game *Game) error

InitializeBloomFilter initializes the bloom filter with existing character names, as well as names from ../data/names.txt and ../data/obscenity.txt.

func InitializeLogging

func InitializeLogging(cfg *Configuration) error

func InputLoop

func InputLoop(c *Character)

InputLoop is the main loop that handles player commands. It reads commands from the player's input and executes them accordingly.

func LoadArchetypes

func LoadArchetypes(g *Game) error

LoadArchetypes retrieves all archetypes from the DynamoDB table and stores them in the Server's ArcheTypes map.

func ParseDims

func ParseDims(b []byte) (width, height int)

parseDims parses terminal dimensions from the SSH payload.

func PlayerInput

func PlayerInput(p *Player)

PlayerInput handles the player's input in a separate goroutine. It reads input from the player's SSH connection and sends it to the FromPlayer channel.

func PlayerOutput

func PlayerOutput(p *Player)

PlayerOutput handles sending messages to the player in a separate goroutine. It reads messages from the ToPlayer channel and writes them to the player's SSH connection.

func SendMetrics

func SendMetrics(s *Server, stop chan os.Signal, interval time.Duration) error

func SendRoomMessage

func SendRoomMessage(r *Room, message string)

SendRoomMessage sends a message to all characters in the room.

func SendRoomMessageExcept

func SendRoomMessageExcept(r *Room, message string, character *Character)

SendRoomMessageExcept sends a message to all characters in the room except for the specified character.

func SignInUser

func SignInUser(email, password string, config *Configuration) (*cognitoidentityprovider.InitiateAuthOutput, error)

SignInUser attempts to sign in a user with the provided credentials

func SignUpUser

func SignUpUser(email, password string, config Configuration) (*cognitoidentityprovider.SignUpOutput, error)

func ValidateCommand

func ValidateCommand(command string) (string, []string, error)

Types

type Archetype

type Archetype struct {
	ArchetypeName string             `json:"ArchetypeName" dynamodbav:"ArchetypeName"`
	Description   string             `json:"Description" dynamodbav:"Description"`
	Attributes    map[string]float64 `json:"Attributes" dynamodbav:"Attributes"`
	Abilities     map[string]float64 `json:"Abilities" dynamodbav:"Abilities"`
	StartRoom     int64              `json:"StartRoom" dynamodbav:"StartRoom"`
}

type Character

type Character struct {
	Game        *Game
	ID          uuid.UUID
	Player      *Player
	Name        string
	Attributes  map[string]float64
	Abilities   map[string]float64
	Essence     float64
	Health      float64
	Room        *Room
	Inventory   map[string]*Item
	Mutex       sync.RWMutex
	Facing      *Character
	Advancing   bool // true when character is advancing towards their facing target
	CombatRange map[uuid.UUID]float64
	LastEdited  time.Time
	LastSaved   time.Time
}

func SelectCharacter

func SelectCharacter(game *Game, player *Player) (*Character, error)

SelectCharacter handles the character selection process for a player. It presents the player with options to select or create a character.

func (*Character) AddToInventory

func (c *Character) AddToInventory(item *Item)

AddToInventory adds an item to the character's inventory.

func (*Character) CanCarryItem

func (c *Character) CanCarryItem(item *Item) bool

CanCarryItem checks if the character can carry the specified item. This is a placeholder for future weight and capacity checks.

func (*Character) CanEscape

func (c *Character) CanEscape() bool

CanEscape checks if the character can escape from combat Returns true if no other characters are at melee range

func (*Character) Cleanup

func (c *Character) Cleanup()

func (*Character) ClearFacing

func (c *Character) ClearFacing()

ClearFacing clears the character's facing

func (*Character) EnterCombat

func (c *Character) EnterCombat()

EnterCombat initializes the CombatRange map when a character enters combat

func (*Character) ExitCombat

func (c *Character) ExitCombat()

ExitCombat clears the CombatRange map when a character exits combat

func (*Character) FindInInventory

func (c *Character) FindInInventory(itemName string) *Item

FindInInventory searches for an item in the character's inventory by name.

func (*Character) FromData

func (c *Character) FromData(cd *CharacterData, game *Game) error

FromData populates a Character object from a CharacterData struct retrieved from the database.

func (*Character) GetCombatRange

func (c *Character) GetCombatRange(target *Character) float64

GetCombatRange gets the distance to a target character, returning DefaultDistance if not in combat

func (*Character) GetFacing

func (c *Character) GetFacing() *Character

GetFacing returns the character that this character is facing

func (*Character) IsInCombat

func (c *Character) IsInCombat() bool

IsInCombat checks if the character is currently in combat

func (*Character) ListInventory

func (c *Character) ListInventory() string

ListInventory lists the items in a character's inventory.

func (*Character) RemoveFromInventory

func (c *Character) RemoveFromInventory(item *Item)

RemoveFromInventory removes an item from the character's inventory.

func (*Character) RemoveWornItem

func (c *Character) RemoveWornItem(item *Item) error

RemoveWornItem allows a character to remove a worn item.

func (*Character) SetCombatRange

func (c *Character) SetCombatRange(target *Character, distance float64)

SetCombatRange sets the distance to a target character, initializing the map if necessary

func (*Character) SetFacing

func (c *Character) SetFacing(target *Character)

SetFacing sets the character's facing to the target character

func (*Character) ToData

func (c *Character) ToData() *CharacterData

ToData converts a Character object into a CharacterData struct for database storage.

func (*Character) WearItem

func (c *Character) WearItem(item *Item) error

WearItem allows a character to wear an item from their inventory.

type CharacterData

type CharacterData struct {
	CharacterID   string             `json:"CharacterID" dynamodbav:"CharacterID"`
	PlayerID      string             `json:"PlayerID" dynamodbav:"PlayerID"`
	CharacterName string             `json:"Name" dynamodbav:"Name"`
	Attributes    map[string]float64 `json:"Attributes" dynamodbav:"Attributes"`
	Abilities     map[string]float64 `json:"Abilities" dynamodbav:"Abilities"`
	Essence       float64            `json:"Essence" dynamodbav:"Essence"`
	Health        float64            `json:"Health" dynamodbav:"Health"`
	RoomID        int64              `json:"RoomID" dynamodbav:"RoomID"`
	Inventory     map[string]string  `json:"Inventory" dynamodbav:"Inventory"`
}

CharacterData for unmarshalling character.

type CloudWatchHandler

type CloudWatchHandler struct {
	// contains filtered or unexported fields
}

func NewCloudWatchHandler

func NewCloudWatchHandler(client *cloudwatchlogs.Client, logGroup, logStream string) *CloudWatchHandler

func (*CloudWatchHandler) Enabled

func (h *CloudWatchHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*CloudWatchHandler) Handle

func (h *CloudWatchHandler) Handle(ctx context.Context, r slog.Record) error

func (*CloudWatchHandler) WithAttrs

func (h *CloudWatchHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*CloudWatchHandler) WithGroup

func (h *CloudWatchHandler) WithGroup(name string) slog.Handler

type CommandHandler

type CommandHandler func(character *Character, tokens []string) bool

type Configuration

type Configuration struct {
	Server struct {
		Port           uint16 `yaml:"Port"`
		PrivateKeyPath string `yaml:"PrivateKeyPath"`
	} `yaml:"Server"`
	Aws struct {
		Region string `yaml:"Region"`
	} `yaml:"Aws"`
	Cognito struct {
		UserPoolID     string `yaml:"UserPoolId"`
		ClientSecret   string `yaml:"UserPoolClientSecret"`
		ClientID       string `yaml:"UserPoolClientId"`
		UserPoolDomain string `yaml:"UserPoolDomain"`
		UserPoolArn    string `yaml:"UserPoolArn"`
	} `yaml:"Cognito"`
	Game struct {
		Balance         float64 `yaml:"Balance"`
		AutoSave        uint16  `yaml:"AutoSave"`
		StartingEssence uint16  `yaml:"StartingEssence"`
		StartingHealth  uint16  `yaml:"StartingHealth"`
	} `yaml:"Game"`
	Logging struct {
		ApplicationName string `yaml:"ApplicationName"`
		LogLevel        int    `yaml:"LogLevel"`
		LogGroup        string `yaml:"LogGroup"`
		LogStream       string `yaml:"LogStream"`
		MetricNamespace string `yaml:"MetricNamespace"`
	} `yaml:"Logging"`
}

type Exit

type Exit struct {
	ExitID     uuid.UUID
	Direction  string
	TargetRoom *Room
	Visible    bool
	LastEdited time.Time
	LastSaved  time.Time
}

Exit represents the in-memory structure for an exit

type ExitData

type ExitData struct {
	ExitID     string `json:"ExitID" dynamodbav:"ExitID"`
	Direction  string `json:"Direction" dynamodbav:"Direction"`
	TargetRoom int64  `json:"TargetRoom" dynamodbav:"TargetRoom"`
	Visible    bool   `json:"Visible" dynamodbav:"Visible"`
}

ExitData represents the structure for storing exit data in DynamoDB

type Game

type Game struct {
	Config               *Configuration
	Context              context.Context
	Mutex                sync.RWMutex
	WaitGroup            sync.WaitGroup
	Ticker               *time.Ticker
	Database             *KeyPair
	ArcheTypes           map[string]*Archetype
	CharacterBloomFilter *bloom.BloomFilter
	Characters           map[uuid.UUID]*Character
	Rooms                map[int64]*Room
	Prototypes           map[uuid.UUID]*Prototype
	Items                map[uuid.UUID]*Item
}

func NewGame

func NewGame(config *Configuration) (*Game, error)

NewGame initializes the game struct.

func (*Game) AddCharacterName

func (game *Game) AddCharacterName(name string)

AddCharacterName adds a character name to the bloom filter to prevent duplicates.

func (*Game) CharacterNameExists

func (game *Game) CharacterNameExists(name string) bool

CharacterNameExists checks if a character name already exists using the bloom filter.

func (*Game) CreateCharacter

func (g *Game) CreateCharacter(player *Player) (*Character, error)

CreateCharacter handles the character creation process for a player. It prompts the player for a character name and archetype, and initializes the character.

func (*Game) CreateItemFromPrototype

func (g *Game) CreateItemFromPrototype(prototypeID uuid.UUID) (*Item, error)

func (*Game) NewCharacter

func (g *Game) NewCharacter(name string, player *Player, room *Room, archetypeName string) (*Character, error)

NewCharacter creates a new character with the specified name and archetype.

func (*Game) SaveActiveCharacters

func (g *Game) SaveActiveCharacters() error

SaveActiveCharacters saves all active characters to the database if they have been edited since the last save.

func (*Game) SaveActiveItems

func (g *Game) SaveActiveItems() error

SaveActiveItems saves all active items from rooms and characters to the database.

func (*Game) SaveActiveRooms

func (g *Game) SaveActiveRooms() error

SaveActiveRooms saves all active rooms to the database if they have been edited since the last save.

func (*Game) StoreArchetypes

func (g *Game) StoreArchetypes() error

StoreArchetypes stores all archetypes from the Server's ArcheTypes map into the DynamoDB table.

type Index

type Index struct {
	IndexID uint64
	// contains filtered or unexported fields
}

The Index struct is to be depricated in favor of UUIDs

func (*Index) GetID

func (i *Index) GetID() uint64

func (*Index) SetID

func (i *Index) SetID(id uint64)

type Item

type Item struct {
	ID          uuid.UUID
	PrototypeID uuid.UUID
	Name        string
	Description string
	Mass        float64
	Value       uint64
	Stackable   bool
	MaxStack    uint32
	Quantity    uint32
	Wearable    bool
	WornOn      []string
	Verbs       map[string]string
	Overrides   map[string]string
	TraitMods   map[string]int8
	Container   bool
	Contents    []*Item
	IsWorn      bool
	CanPickUp   bool
	Metadata    map[string]string
	Mutex       sync.RWMutex
	LastEdited  time.Time
	LastSaved   time.Time
}

type ItemData

type ItemData struct {
	ItemID      string            `json:"itemId" dynamodbav:"ItemID"`
	PrototypeID string            `json:"prototypeID" dynamodbav:"PrototypeID"`
	Name        string            `json:"name" dynamodbav:"Name"`
	Description string            `json:"description" dynamodbav:"Description"`
	Mass        float64           `json:"mass" dynamodbav:"Mass"`
	Value       uint64            `json:"value" dynamodbav:"Value"`
	Stackable   bool              `json:"stackable" dynamodbav:"Stackable"`
	MaxStack    uint32            `json:"max_stack" dynamodbav:"MaxStack"`
	Quantity    uint32            `json:"quantity" dynamodbav:"Quantity"`
	Wearable    bool              `json:"wearable" dynamodbav:"Wearable"`
	WornOn      []string          `json:"worn_on" dynamodbav:"WornOn"`
	Verbs       map[string]string `json:"verbs" dynamodbav:"Verbs"`
	Overrides   map[string]string `json:"overrides" dynamodbav:"Overrides"`
	TraitMods   map[string]int8   `json:"trait_mods" dynamodbav:"TraitMods"`
	Container   bool              `json:"container" dynamodbav:"Container"`
	Contents    []string          `json:"contents" dynamodbav:"Contents"`
	IsWorn      bool              `json:"is_worn" dynamodbav:"IsWorn"`
	CanPickUp   bool              `json:"can_pick_up" dynamodbav:"CanPickUp"`
	Metadata    map[string]string `json:"metadata" dynamodbav:"Metadata"`
}

type KeyPair

type KeyPair struct {
	// contains filtered or unexported fields
}

func NewKeyPair

func NewKeyPair(region string) (*KeyPair, error)

NewKeyPair initializes a new DynamoDB client.

func (*KeyPair) Delete

func (k *KeyPair) Delete(tableName string, key map[string]*dynamodb.AttributeValue) error

Delete removes an item from the DynamoDB table.

func (*KeyPair) DeleteCharacter

func (kp *KeyPair) DeleteCharacter(player *Player, characterName string) error

DeleteCharacter removes a character from the player's character list and the database.

func (*KeyPair) Get

func (k *KeyPair) Get(tableName string, key map[string]*dynamodb.AttributeValue, item interface{}) error

Get retrieves an item from the DynamoDB table.

func (*KeyPair) GetAllMOTDs

func (k *KeyPair) GetAllMOTDs() ([]*MOTD, error)

func (*KeyPair) LoadAllExits

func (kp *KeyPair) LoadAllExits() (map[string]*Exit, error)

LoadAllExits loads all exits for all rooms.

func (*KeyPair) LoadAllItems

func (kp *KeyPair) LoadAllItems() (map[string]*Item, error)

LoadAllItems loads all items for all rooms.

func (*KeyPair) LoadCharacter

func (kp *KeyPair) LoadCharacter(characterID uuid.UUID, player *Player, game *Game) (*Character, error)

LoadCharacter retrieves a character from the DynamoDB database and reconstructs the Character object.

func (*KeyPair) LoadCharacterNames

func (kp *KeyPair) LoadCharacterNames() (map[string]bool, error)

LoadCharacterNames loads all character names from the database to initialize the bloom filter.

func (*KeyPair) LoadItem

func (k *KeyPair) LoadItem(id string) (*Item, error)

LoadItem retrieves an item from the DynamoDB table.

func (*KeyPair) LoadItemsForRoom

func (kp *KeyPair) LoadItemsForRoom(roomID int64) (map[uuid.UUID]*Item, error)

LoadItemsForRoom loads all items for a specific room

func (*KeyPair) LoadPrototypes

func (kp *KeyPair) LoadPrototypes() (map[uuid.UUID]*Prototype, error)

LoadPrototypes retrieves all item prototypes from the DynamoDB table.

func (*KeyPair) LoadRooms

func (kp *KeyPair) LoadRooms() (map[int64]*Room, error)

LoadRooms retrieves all rooms from the DynamoDB database and returns them as a map of Room instances.

func (*KeyPair) Put

func (k *KeyPair) Put(tableName string, item interface{}) error

func (*KeyPair) Query

func (k *KeyPair) Query(tableName string, keyConditionExpression string, expressionAttributeValues map[string]*dynamodb.AttributeValue, items interface{}) error

Query performs a query operation on the DynamoDB table.

func (*KeyPair) ReadPlayer

func (k *KeyPair) ReadPlayer(playerName string) (string, map[string]uuid.UUID, []uuid.UUID, error)

ReadPlayer retrieves the player data from the DynamoDB database.

func (*KeyPair) Scan

func (k *KeyPair) Scan(tableName string, items interface{}) error

Scan performs a scan operation on the DynamoDB table.

func (*KeyPair) StorePrototypes

func (kp *KeyPair) StorePrototypes(prototypes map[uuid.UUID]*Prototype) error

StorePrototypes stores item prototypes into the DynamoDB table.

func (*KeyPair) StoreRooms

func (kp *KeyPair) StoreRooms(rooms map[int64]*Room) error

StoreRooms stores all rooms into the DynamoDB database.

func (*KeyPair) WriteCharacter

func (kp *KeyPair) WriteCharacter(character *Character) error

WriteCharacter saves the character to the DynamoDB database.

func (*KeyPair) WriteItem

func (k *KeyPair) WriteItem(obj *Item) error

WriteItem stores an item into the DynamoDB table, handling nested contents if it's a container.

func (*KeyPair) WritePlayer

func (k *KeyPair) WritePlayer(player *Player) error

WritePlayer stores the player data into the DynamoDB database.

func (*KeyPair) WriteRoom

func (kp *KeyPair) WriteRoom(room *Room) error

WriteRoom stores a single room into the DynamoDB database.

type MOTD

type MOTD struct {
	MotdID    uuid.UUID
	Active    bool
	Message   string
	CreatedAt time.Time
}

type MOTDData

type MOTDData struct {
	MotdID    string `json:"MotdID" dynamodbav:"MotdID"`
	Active    bool   `json:"active" dynamodbav:"Active"`
	Message   string `json:"message" dynamodbav:"Message"`
	CreatedAt string `json:"createdAt" dynamodbav:"CreatedAt"`
}

type MultiHandler

type MultiHandler struct {
	// contains filtered or unexported fields
}

func NewMultiHandler

func NewMultiHandler(handlers ...slog.Handler) *MultiHandler

func (*MultiHandler) Enabled

func (h *MultiHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*MultiHandler) Handle

func (h *MultiHandler) Handle(ctx context.Context, r slog.Record) error

func (*MultiHandler) WithAttrs

func (h *MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*MultiHandler) WithGroup

func (h *MultiHandler) WithGroup(name string) slog.Handler

type Player

type Player struct {
	Server        *Server
	Index         uint64
	PlayerID      string
	ToPlayer      chan string
	FromPlayer    chan string
	PlayerError   chan error
	Echo          bool
	Prompt        string
	Connection    ssh.Channel
	ConsoleWidth  int
	ConsoleHeight int
	SeenMotD      []uuid.UUID
	CharacterList map[string]uuid.UUID
	Character     *Character
	LoginTime     time.Time
	Mutex         sync.RWMutex
	Context       context.Context
	Cancel        context.CancelFunc
}

func (*Player) Cleanup

func (p *Player) Cleanup()

type PlayerData

type PlayerData struct {
	PlayerID      string            `json:"PlayerID" dynamodbav:"PlayerID"`
	CharacterList map[string]string `json:"characterList" dynamodbav:"CharacterList"`
	SeenMotDs     []string          `json:"seenMotD" dynamodbav:"SeenMotD"`
}

type Prototype

type Prototype struct {
	ID          uuid.UUID
	Name        string
	Description string
	Mass        float64
	Value       uint64
	Stackable   bool
	MaxStack    uint32
	Quantity    uint32
	Wearable    bool
	WornOn      []string
	Verbs       map[string]string
	Overrides   map[string]string
	TraitMods   map[string]int8
	Container   bool
	Contents    []uuid.UUID
	CanPickUp   bool
	Metadata    map[string]string
	Mutex       sync.RWMutex
	LastEdited  time.Time
	LastSaved   time.Time
}

type PrototypeData

type PrototypeData struct {
	PrototypeID string            `json:"id" dynamodbav:"prototypeID"`
	Name        string            `json:"name" dynamodbav:"name"`
	Description string            `json:"description" dynamodbav:"description"`
	Mass        float64           `json:"mass" dynamodbav:"mass"`
	Value       uint64            `json:"value" dynamodbav:"value"`
	Stackable   bool              `json:"stackable" dynamodbav:"stackable"`
	MaxStack    uint32            `json:"max_stack" dynamodbav:"max_stack"`
	Quantity    uint32            `json:"quantity" dynamodbav:"quantity"`
	Wearable    bool              `json:"wearable" dynamodbav:"wearable"`
	WornOn      []string          `json:"worn_on" dynamodbav:"worn_on"`
	Verbs       map[string]string `json:"verbs" dynamodbav:"verbs"`
	Overrides   map[string]string `json:"overrides" dynamodbav:"overrides"`
	TraitMods   map[string]int8   `json:"trait_mods" dynamodbav:"trait_mods"`
	Container   bool              `json:"container" dynamodbav:"container"`
	Contents    []string          `json:"contents" dynamodbav:"contents"`
	CanPickUp   bool              `json:"can_pick_up" dynamodbav:"can_pick_up"`
	Metadata    map[string]string `json:"metadata" dynamodbav:"metadata"`
}

type Room

type Room struct {
	RoomID      int64
	Area        string
	Title       string
	Description string
	Exits       map[string]*Exit
	Characters  map[uuid.UUID]*Character
	Items       map[uuid.UUID]*Item
	Mutex       sync.RWMutex
	LastEdited  time.Time
	LastSaved   time.Time
}

Room represents the in-memory structure for a room

func NewRoom

func NewRoom(roomID int64, area string, title string, description string) *Room

NewRoom creates a new Room instance with initialized fields.

func (*Room) AddExit

func (r *Room) AddExit(exit *Exit)

AddExit adds an exit to the room's exits map.

func (*Room) AddItem

func (r *Room) AddItem(item *Item)

AddItem adds an item to the room's item list.

func (*Room) CleanupNilItems

func (r *Room) CleanupNilItems()

CleanupNilItems removes any nil items from the room's item list.

func (*Room) FromData

func (r *Room) FromData(data *RoomData, exits map[string]*Exit, items map[string]*Item)

FromData populates a Room from RoomData.

func (*Room) RemoveItem

func (r *Room) RemoveItem(item *Item)

RemoveItem removes an item from the room's item list.

func (*Room) ToData

func (r *Room) ToData() *RoomData

ToData converts a Room to RoomData for database storage.

type RoomData

type RoomData struct {
	RoomID      int64    `json:"roomID" dynamodbav:"RoomID"`
	Area        string   `json:"area" dynamodbav:"Area"`
	Title       string   `json:"title" dynamodbav:"Title"`
	Description string   `json:"description" dynamodbav:"Description"`
	ExitIDs     []string `json:"exitID" dynamodbav:"ExitID"`
	ItemIDs     []string `json:"itemID" dynamodbav:"ItemID"`
}

RoomData represents the structure for storing room data in DynamoDB

type Server

type Server struct {
	Config      *Configuration
	Context     context.Context
	Mutex       sync.RWMutex
	WaitGroup   sync.WaitGroup
	Database    *KeyPair
	StartTime   time.Time
	Port        uint16
	Listener    net.Listener
	SSHConfig   *ssh.ServerConfig
	PlayerCount uint64
	PlayerIndex *Index
	Players     map[uint64]*Player
	ActiveMotDs []*MOTD
}

func NewServer

func NewServer(config *Configuration) (*Server, error)

NewServer initializes a new server instance with the given configuration. It sets up the database connection, loads game data, and prepares the server for incoming connections.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL