mush

package module
v0.0.0-...-a2a85d5 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: GPL-3.0 Imports: 26 Imported by: 0

README

Vaelen/MUSH

A MUSH written in Go

Documentation

Index

Constants

View Source
const SaveStateFrequency time.Duration = time.Hour

SaveStateFrequency represents how often the game's state should be saved.

View Source
const VersionExtra = ""

VersionExtra contains additional version information about the server.

View Source
const VersionMajor = 0

VersionMajor is the major release of the server.

View Source
const VersionMinor = 0

VersionMinor is the minor release of the server.

View Source
const VersionName = "Vaelen/MUSH Server"

VersionName is the name of the server.

View Source
const VersionPatch = 1

VersionPatch is the patch release of the server.

Variables

This section is empty.

Functions

func DisableEcho

func DisableEcho(c io.Writer)

DisableEcho sends the telnet escape sequence to disable local echo.

func EnableEcho

func EnableEcho(c io.Writer)

EnableEcho sends the telnet escape sequence to enable local echo.

func Login

func Login(c *Connection) (bool, error)

Login performs a login on the given connection.

func VersionString

func VersionString() string

VersionString outputs the server's version string. noinspection GoBoolExpressions

Types

type Connection

type Connection struct {
	ID            IDType
	C             net.Conn
	Player        *Player
	Shell         *ishell.Shell
	Server        *Server
	Authenticated bool
	Connected     time.Time
	LastActed     time.Time
	ScriptingEnv  *ScriptingEnv
}

Connection represents a connection to the server.

func (*Connection) CanDestroyExit

func (c *Connection) CanDestroyExit(e *Exit) bool

CanDestroyExit returns true if the player can destroy the room.

func (*Connection) CanDestroyItem

func (c *Connection) CanDestroyItem(i *Item) bool

CanDestroyItem returns true of the player can destroy the item.

func (*Connection) CanDestroyPlayer

func (c *Connection) CanDestroyPlayer(p *Player) bool

CanDestroyPlayer returns true if the player can destroy the room.

func (*Connection) CanDestroyRoom

func (c *Connection) CanDestroyRoom(r *Room) bool

CanDestroyRoom returns true if the player can destroy the room.

func (*Connection) CanEditExit

func (c *Connection) CanEditExit(e *Exit, field string) bool

CanEditExit returns true if the player can edit the field on the room.

func (*Connection) CanEditItem

func (c *Connection) CanEditItem(i *Item, field string) bool

CanEditItem returns true of the player can edit the field on the object.

func (*Connection) CanEditPlayer

func (c *Connection) CanEditPlayer(p *Player, field string) bool

CanEditPlayer returns true if the player can edit the field on the room.

func (*Connection) CanEditRoom

func (c *Connection) CanEditRoom(r *Room, field string) bool

CanEditRoom returns true if the player can edit the field on the room.

func (*Connection) Close

func (c *Connection) Close()

Close closes the given connection.

func (*Connection) DestroyExit

func (c *Connection) DestroyExit(id IDType) *Exit

DestroyExit is a helper method that destroys an exit.

func (*Connection) DestroyItem

func (c *Connection) DestroyItem(id IDType) *Item

DestroyItem is a helper method that destroy an item.

func (*Connection) DestroyRoom

func (c *Connection) DestroyRoom(id IDType) *Room

DestroyRoom is a helper method that destroys a room.

func (*Connection) Drop

func (c *Connection) Drop(itemName string)

Drop executes the "drop" command and moves an item out of the player's inventory.

func (*Connection) Emote

func (c *Connection) Emote(action string, loc *Location)

Emote executes the "emote" command for the given player. It can also be used by other commands to say that the player did something.

func (*Connection) ExecuteScript

func (c *Connection) ExecuteScript(code string) error

ExecuteScript executes the given code.

func (*Connection) ExecuteScriptWithScope

func (c *Connection) ExecuteScriptWithScope(scope map[string]interface{}, code string) error

ExecuteScriptWithScope executes the given code within the given scope.

func (*Connection) FindAllItems

func (c *Connection) FindAllItems() []*Item

FindAllItems returns all items in the database. TODO: Replace with a channel

func (*Connection) FindAllPlayers

func (c *Connection) FindAllPlayers() []*Player

FindAllPlayers returns all players in the database. TODO: Replace with a channel

func (*Connection) FindAllRooms

func (c *Connection) FindAllRooms() []*Room

FindAllRooms returns all rooms in the database. TODO: Replace with a channel

func (*Connection) FindItemByID

func (c *Connection) FindItemByID(id IDType) *Item

FindItemByID is a helper method that finds an item based on its ID.

func (*Connection) FindItemsByLocation

func (c *Connection) FindItemsByLocation(loc Location) []*Item

FindItemsByLocation is a helper method that finds a slice of items in a given location.

func (*Connection) FindItemsByOwner

func (c *Connection) FindItemsByOwner(id IDType) []*Item

FindItemsByOwner is a helper method that finds a slice of items that belong to the given player.

func (*Connection) FindLocalThing

func (c *Connection) FindLocalThing(loc Location, nameOrID string, includeExits bool) (foundOne fmt.Stringer, foundMany []fmt.Stringer)

FindLocalThing is a helper method for finding an item, player, or exit in a given location.

func (*Connection) FindOnlinePlayersByLocation

func (c *Connection) FindOnlinePlayersByLocation(loc *Location) []*Player

FindOnlinePlayersByLocation is a helper method that returns a slice of players who are online and in the given location. Passing in nil will return all players who are currently online.

func (*Connection) FindPlayerByID

func (c *Connection) FindPlayerByID(id IDType) *Player

FindPlayerByID is a helper method that returns a player based on their ID.

func (*Connection) FindPlayerByName

func (c *Connection) FindPlayerByName(name string) *Player

FindPlayerByName is a helper method that returns a player based on their name.

func (*Connection) FindRoomByID

func (c *Connection) FindRoomByID(id IDType) *Room

FindRoomByID is a helper method that returns a room based on its ID.

func (*Connection) FindRoomsByOwner

func (c *Connection) FindRoomsByOwner(id IDType) []*Room

FindRoomsByOwner is a helper method that returns a slice of rooms that belong to the given player.

func (*Connection) Go

func (c *Connection) Go(target string)

Go executes the "go" command and moves a player to another room.

func (*Connection) InLocation

func (c *Connection) InLocation(loc *Location) bool

InLocation returns true if the user is logged in and in the given location. Passing in a nil Location reference will return true as long as the user is authenticated.

func (*Connection) IsAdmin

func (c *Connection) IsAdmin() bool

IsAdmin returns true if the player is an admin.

func (*Connection) ListItems

func (c *Connection) ListItems(items []*Item)

ListItems displays a list of the given items.

func (*Connection) ListPlayers

func (c *Connection) ListPlayers(players []*Player)

ListPlayers shows a list of players.

func (*Connection) ListRooms

func (c *Connection) ListRooms(rooms []*Room)

ListRooms displays a list of the given rooms.

func (*Connection) LocationName

func (c *Connection) LocationName(loc Location) string

LocationName is a helper method that returns the name of a given location.

func (*Connection) LocationPrintf

func (c *Connection) LocationPrintf(loc *Location, fmt string, a ...interface{})

LocationPrintf sends text to all of the players in a given location.

func (*Connection) Log

func (c *Connection) Log(s string)

Log writes a log entry for the given connection.

func (*Connection) Logf

func (c *Connection) Logf(format string, a ...interface{})

Logf writes a log entry for the given connection.

func (*Connection) Look

func (c *Connection) Look(target string)

Look executes the "look" command for the given player.

func (*Connection) Move

func (c *Connection) Move(destination Location, leaveMessage string, arriveMessage string)

Move transports a player to another location. leaveMessage should contain "%s" for the player's name. arriveMessage should contain "%s" for the player's name.

func (*Connection) NewExit

func (c *Connection) NewExit(name string, description string) *Exit

NewExit is a helper method for creating a new exit.

func (*Connection) NewItem

func (c *Connection) NewItem(name string, description string) *Item

NewItem is a helper method that creates a new item.

func (*Connection) NewRoom

func (c *Connection) NewRoom(name string, description string) *Room

NewRoom is a helper method for creating a new room.

func (*Connection) Print

func (c *Connection) Print(a ...interface{})

Print writes the text to the given connection without transforming it.

func (*Connection) Printf

func (c *Connection) Printf(format string, a ...interface{})

Printf writes text to the given connection.

func (*Connection) Println

func (c *Connection) Println(message string)

Println writes text to the given connection, followed by a new line character.

func (*Connection) ReadLine

func (c *Connection) ReadLine() string

ReadLine reads a line of input from the given connection.

func (*Connection) Say

func (c *Connection) Say(target string, phrase string, loc *Location)

Say executes the "say" command for the given player.

func (*Connection) Set

func (c *Connection) Set(target string, field string, value string)

Set executes the "set" action by setting a given value on a given target

func (*Connection) Show

func (c *Connection) Show(target string)

Show executes the "show" action by showing a given target's field values

func (*Connection) String

func (c *Connection) String() string

func (*Connection) Summon

func (c *Connection) Summon(target string)

Summon executes the "summon" action by forcefully relocating a player or object.

func (*Connection) Take

func (c *Connection) Take(itemName string)

Take executes the "take" command and moves an item into the player's inventory.

func (*Connection) TestScriptingEnvironment

func (c *Connection) TestScriptingEnvironment() error

TestScriptingEnvironment tests that the scripting environment is functioning properly.

func (*Connection) Whisper

func (c *Connection) Whisper(target string, phrase string, loc *Location)

Whisper executes the "whisper" command for the given player.

func (*Connection) Who

func (c *Connection) Who()

Who shows a list of the currently logged in players. TODO: Have the column widths auto-adjust to fit the data

type ConnectionManager

type ConnectionManager struct {

	// Opened: Sending a ConnectionStateChange message to this channel adds the connection to the ConnectionManager.
	Opened chan ConnectionStateChange
	// Closed: Sending a ConnectionStateChange message to this channel removes the connection from the ConnectionManager.
	Closed chan ConnectionStateChange
	// Shutdown: Sending true to this channel shuts down the ConnectionManager.
	Shutdown chan bool
	// contains filtered or unexported fields
}

ConnectionManager maintains open connections to the server

func NewConnectionManager

func NewConnectionManager() *ConnectionManager

NewConnectionManager creates a new ConnectionManager instance.

func (*ConnectionManager) ConnectionManagerThread

func (m *ConnectionManager) ConnectionManagerThread() func()

ConnectionManagerThread returns a goroutine for the Connection Manager. This goroutine must be running for the ConnectionManager to operate. Running multiple copies of this goroutine for the same ConnectionManager will produce unknown side effects.

func (*ConnectionManager) Connections

func (m *ConnectionManager) Connections() []*Connection

Connections returns a slice of the currently open connections.

type ConnectionStateChange

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

ConnectionStateChange is an event that is fired when a connection changes state.

type DestroyExitMessage

type DestroyExitMessage struct {
	Room IDType
	ID   IDType
	Ack  chan bool
}

DestroyExitMessage is sent to DestroyExit to destroy an exit.

type DestroyItemMessage

type DestroyItemMessage struct {
	ID  IDType
	Ack chan bool
}

DestroyItemMessage is sent to DestroyItem to destroy an item.

type DestroyPlayerMessage

type DestroyPlayerMessage struct {
	ID  IDType
	Ack chan bool
}

DestroyPlayerMessage is sent to DestroyPlayer to destroy a given player.

type DestroyRoomMessage

type DestroyRoomMessage struct {
	Room IDType
	ID   IDType
	Ack  chan bool
}

DestroyRoomMessage is sent to DestroyRoom to destroy a room.

type Exit

type Exit struct {
	ID              IDType
	Name            string
	Description     string
	LongDescription string
	Destination     IDType
	ArriveMessage   string
	LeaveMessage    string
	Owner           IDType
	Hidden          bool
	Lockable        bool
	Locked          bool
	Key             IDType
	Attributes      map[string]string
}

Exit represents an exit between two rooms.

func (*Exit) String

func (e *Exit) String() string

type FindItemMessage

type FindItemMessage struct {
	ID       IDType
	Owner    IDType
	Location *Location
	Ack      chan []*Item
}

FindItemMessage is sent to FindItem to find a set of items.

type FindPlayerMessage

type FindPlayerMessage struct {
	ID       IDType
	Name     string
	Location *Location
	Ack      chan []*Player
}

FindPlayerMessage is sent to FindPlayer to find a set of players.

type FindRoomMessage

type FindRoomMessage struct {
	ID    IDType
	Owner IDType
	Ack   chan []*Room
}

FindRoomMessage is sent to FindRoom to find a set of rooms.

type IDType

type IDType uint64

IDType is the type used for all ID values

func ParseID

func ParseID(s string) (IDType, error)

ParseID parses a string to an IDType

func (IDType) String

func (id IDType) String() string

type Item

type Item struct {
	ID          IDType
	Name        string
	Description string
	Owner       IDType
	Location    Location
	Attached    bool
	Attributes  map[string]string
}

Item represents an item in the world.

func (*Item) String

func (i *Item) String() string

type Location

type Location struct {
	ID   IDType
	Type LocationType
}

Location represents the location of a player or item.

func (Location) String

func (l Location) String() string

type LocationType

type LocationType uint8

LocationType is used to represent the type of a Location.

const (
	// LocationRoom means that the location is a room.
	LocationRoom LocationType = iota
	// LocationPlayer means that the location is a player.
	LocationPlayer
	// LocationItem means that the location is an item.
	LocationItem
)

type NewExitMessage

type NewExitMessage struct {
	Room  IDType
	Name  string
	Owner IDType
	Ack   chan *Exit
}

NewExitMessage is sent to NewExit to create a new exit.

type NewItemMessage

type NewItemMessage struct {
	Name  string
	Owner IDType
	Ack   chan *Item
}

NewItemMessage is sent to NewItem to create a new item.

type NewPlayerMessage

type NewPlayerMessage struct {
	Name  string
	Owner IDType
	Ack   chan *Player
}

NewPlayerMessage is sent to NewPlayer to create a new player.

type NewRoomMessage

type NewRoomMessage struct {
	Name  string
	Owner IDType
	Ack   chan *Room
}

NewRoomMessage is sent to NewRoom to create a new room.

type PasswordHash

type PasswordHash [sha256.Size]byte

PasswordHash stores a password hash

type PasswordMessage

type PasswordMessage struct {
	ID       IDType
	Password string
	Ack      chan bool
}

PasswordMessage is sent to CheckPassword to check a password and SetPassword to set a password.

type Player

type Player struct {
	ID          IDType
	Name        string
	Description string
	Location    Location
	Admin       bool
	LastActed   time.Time
}

Player represents a player in the world.

func (*Player) String

func (p *Player) String() string

type Room

type Room struct {
	ID          IDType
	Name        string
	Description string
	Exits       []*Exit
	Owner       IDType
	Attributes  map[string]string
}

Room represents a room in the world.

func (*Room) String

func (r *Room) String() string

type SaveWorldStateMessage

type SaveWorldStateMessage struct {
	Ack chan error
}

SaveWorldStateMessage is sent to SaveWorldState to save the world's current state to disk.

type ScriptingEnv

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

ScriptingEnv wraps the scripting environment so that it is isolated from the underlying implementation.

func (*ScriptingEnv) Execute

func (env *ScriptingEnv) Execute(scope map[string]interface{}, code string) error

Execute executes the given code in the given scope.

func (*ScriptingEnv) Test

func (env *ScriptingEnv) Test() error

Test tests that the scripting environment is functioning properly.

type Server

type Server struct {
	World    *World
	Shutdown chan bool
	// contains filtered or unexported fields
}

Server represents a server instance.

func NewServer

func NewServer() Server

NewServer creates a new Server instance.

func (*Server) Connections

func (s *Server) Connections() []*Connection

Connections returns the list of open connections.

func (*Server) StartServer

func (s *Server) StartServer(addr string, tlsAddr string)

StartServer starts the given Server instance, calling all necessary goroutines.

func (*Server) Wall

func (s *Server) Wall(format string, a ...interface{})

Wall writes a string to all open connections.

type TelnetInterceptor

type TelnetInterceptor struct {
	Debug bool
	// contains filtered or unexported fields
}

TelnetInterceptor intercepts telnet escape sequences in a stream.

func (TelnetInterceptor) Close

func (t TelnetInterceptor) Close() (err error)

func (TelnetInterceptor) Read

func (t TelnetInterceptor) Read(p []byte) (n int, err error)

type World

type World struct {
	FindPlayer    chan FindPlayerMessage
	NewPlayer     chan NewPlayerMessage
	DestroyPlayer chan DestroyPlayerMessage

	FindRoom    chan FindRoomMessage
	NewRoom     chan NewRoomMessage
	DestroyRoom chan DestroyRoomMessage

	NewExit     chan NewExitMessage
	DestroyExit chan DestroyExitMessage

	FindItem    chan FindItemMessage
	NewItem     chan NewItemMessage
	DestroyItem chan DestroyItemMessage

	SaveWorldState chan SaveWorldStateMessage
	Shutdown       chan bool

	CheckPassword chan PasswordMessage
	SetPassword   chan PasswordMessage
	// contains filtered or unexported fields
}

World contains a WorldDatabase and all of the channels needed to modify it.

func LoadWorld

func LoadWorld() (*World, error)

LoadWorld loads a World from disk.

func NewWorld

func NewWorld() *World

NewWorld creates a new World instance

func (*World) WorldThread

func (w *World) WorldThread() func()

WorldThread returns a goroutine that handles World events.

type WorldDatabase

type WorldDatabase struct {
	// Data
	NextID      IDType
	DefaultRoom IDType
	Players     map[IDType]*Player
	Rooms       map[IDType]*Room
	Items       map[IDType]*Item
	Auth        map[IDType]PasswordHash
}

WorldDatabase holds all of the players, rooms, and items in the world.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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