Documentation ¶
Index ¶
- Constants
- func DisableEcho(c io.Writer)
- func EnableEcho(c io.Writer)
- func Login(c *Connection) (bool, error)
- func VersionString() string
- type Connection
- func (c *Connection) CanDestroyExit(e *Exit) bool
- func (c *Connection) CanDestroyItem(i *Item) bool
- func (c *Connection) CanDestroyPlayer(p *Player) bool
- func (c *Connection) CanDestroyRoom(r *Room) bool
- func (c *Connection) CanEditExit(e *Exit, field string) bool
- func (c *Connection) CanEditItem(i *Item, field string) bool
- func (c *Connection) CanEditPlayer(p *Player, field string) bool
- func (c *Connection) CanEditRoom(r *Room, field string) bool
- func (c *Connection) Close()
- func (c *Connection) DestroyExit(id IDType) *Exit
- func (c *Connection) DestroyItem(id IDType) *Item
- func (c *Connection) DestroyRoom(id IDType) *Room
- func (c *Connection) Drop(itemName string)
- func (c *Connection) Emote(action string, loc *Location)
- func (c *Connection) ExecuteScript(code string) error
- func (c *Connection) ExecuteScriptWithScope(scope map[string]interface{}, code string) error
- func (c *Connection) FindAllItems() []*Item
- func (c *Connection) FindAllPlayers() []*Player
- func (c *Connection) FindAllRooms() []*Room
- func (c *Connection) FindItemByID(id IDType) *Item
- func (c *Connection) FindItemsByLocation(loc Location) []*Item
- func (c *Connection) FindItemsByOwner(id IDType) []*Item
- func (c *Connection) FindLocalThing(loc Location, nameOrID string, includeExits bool) (foundOne fmt.Stringer, foundMany []fmt.Stringer)
- func (c *Connection) FindOnlinePlayersByLocation(loc *Location) []*Player
- func (c *Connection) FindPlayerByID(id IDType) *Player
- func (c *Connection) FindPlayerByName(name string) *Player
- func (c *Connection) FindRoomByID(id IDType) *Room
- func (c *Connection) FindRoomsByOwner(id IDType) []*Room
- func (c *Connection) Go(target string)
- func (c *Connection) InLocation(loc *Location) bool
- func (c *Connection) IsAdmin() bool
- func (c *Connection) ListItems(items []*Item)
- func (c *Connection) ListPlayers(players []*Player)
- func (c *Connection) ListRooms(rooms []*Room)
- func (c *Connection) LocationName(loc Location) string
- func (c *Connection) LocationPrintf(loc *Location, fmt string, a ...interface{})
- func (c *Connection) Log(s string)
- func (c *Connection) Logf(format string, a ...interface{})
- func (c *Connection) Look(target string)
- func (c *Connection) Move(destination Location, leaveMessage string, arriveMessage string)
- func (c *Connection) NewExit(name string, description string) *Exit
- func (c *Connection) NewItem(name string, description string) *Item
- func (c *Connection) NewRoom(name string, description string) *Room
- func (c *Connection) Print(a ...interface{})
- func (c *Connection) Printf(format string, a ...interface{})
- func (c *Connection) Println(message string)
- func (c *Connection) ReadLine() string
- func (c *Connection) Say(target string, phrase string, loc *Location)
- func (c *Connection) Set(target string, field string, value string)
- func (c *Connection) Show(target string)
- func (c *Connection) String() string
- func (c *Connection) Summon(target string)
- func (c *Connection) Take(itemName string)
- func (c *Connection) TestScriptingEnvironment() error
- func (c *Connection) Whisper(target string, phrase string, loc *Location)
- func (c *Connection) Who()
- type ConnectionManager
- type ConnectionStateChange
- type DestroyExitMessage
- type DestroyItemMessage
- type DestroyPlayerMessage
- type DestroyRoomMessage
- type Exit
- type FindItemMessage
- type FindPlayerMessage
- type FindRoomMessage
- type IDType
- type Item
- type Location
- type LocationType
- type NewExitMessage
- type NewItemMessage
- type NewPlayerMessage
- type NewRoomMessage
- type PasswordHash
- type PasswordMessage
- type Player
- type Room
- type SaveWorldStateMessage
- type ScriptingEnv
- type Server
- type TelnetInterceptor
- type World
- type WorldDatabase
Constants ¶
const SaveStateFrequency time.Duration = time.Hour
SaveStateFrequency represents how often the game's state should be saved.
const VersionExtra = ""
VersionExtra contains additional version information about the server.
const VersionMajor = 0
VersionMajor is the major release of the server.
const VersionMinor = 0
VersionMinor is the minor release of the server.
const VersionName = "Vaelen/MUSH Server"
VersionName is the name of the server.
const VersionPatch = 1
VersionPatch is the patch release of the server.
Variables ¶
This section is empty.
Functions ¶
func DisableEcho ¶
DisableEcho sends the telnet escape sequence to disable local echo.
func EnableEcho ¶
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) 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 ¶
DestroyExitMessage is sent to DestroyExit to destroy an exit.
type DestroyItemMessage ¶
DestroyItemMessage is sent to DestroyItem to destroy an item.
type DestroyPlayerMessage ¶
DestroyPlayerMessage is sent to DestroyPlayer to destroy a given player.
type DestroyRoomMessage ¶
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.
type FindItemMessage ¶
FindItemMessage is sent to FindItem to find a set of items.
type FindPlayerMessage ¶
FindPlayerMessage is sent to FindPlayer to find a set of players.
type FindRoomMessage ¶
FindRoomMessage is sent to FindRoom to find a set of rooms.
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.
type Location ¶
type Location struct { ID IDType Type LocationType }
Location represents the location of a player or item.
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 ¶
NewExitMessage is sent to NewExit to create a new exit.
type NewItemMessage ¶
NewItemMessage is sent to NewItem to create a new item.
type NewPlayerMessage ¶
NewPlayerMessage is sent to NewPlayer to create a new player.
type NewRoomMessage ¶
NewRoomMessage is sent to NewRoom to create a new room.
type PasswordMessage ¶
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.
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.
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 ¶
Server represents a server instance.
func (*Server) Connections ¶
func (s *Server) Connections() []*Connection
Connections returns the list of open connections.
func (*Server) StartServer ¶
StartServer starts the given Server instance, calling all necessary goroutines.
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)
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 (*World) WorldThread ¶
func (w *World) WorldThread() func()
WorldThread returns a goroutine that handles World events.