mapper

package
v4.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package mapper implements a standard client interface for the mapper service.

EXPERIMENTAL CODE

THIS PACKAGE IS STILL A WORK IN PROGRESS and has not been completely tested yet. Although GMA generally is a stable product, this module of it is new, and is not.

This package handles the details of communicating with the GMA mapper service communication channel used to keep the mapper clients in sync with each other and with the other GMA tools.

A client should establish a connection to the game server by calling the Dial method in this package. This function will sign on to the server and then enter a loop, sending incoming server messages back on the channel(s) established via the Subscribe method. Dial returns when the session with the server has terminated.

Typically, an application will invoke the Dial method in a goroutine. Calling the associated context's cancel function will signal that we want to stop talking to the server, resulting in the termination of the running Dial method.

Index

Constants

View Source
const (
	GMAMapperProtocol           = 333     // @@##@@ auto-configured
	GMAVersionNumber            = "4.4.1" // @@##@@ auto-configured
	MinimumSupportedMapProtocol = 332
	MaximumSupportedMapProtocol = 333
)

The GMA Mapper Protocol version number current as of this build, and protocol versions supported by this code.

View Source
const (
	// ToGMOnly as one of the recipients to a ChatMessage
	// or Roll method will cause the message or die-roll
	// result to be sent to the GM only.
	ToGMOnly = "%"

	// ToAll as one of the recipients to a ChatMessage
	// or Roll method will cause the message to go to
	// all connected clients.
	ToAll = "*"
)
View Source
const GMAMapperFileFormat = 17 // @@##@@ auto-configured

GMAMapperFileFormat gives the GMA File Format version number current as of this build. This is the format which will be used for saving map data.

View Source
const MaximumSupportedMapFileFormat = 17

MaximumSupportedMapFileFormat gives the highest file format this package can understand. Saved data will be in this format.

View Source
const MinimumSupportedMapFileFormat = 14

MinimumSupportedMapFileFormat gives the lowest file format this package can understand.

Variables

View Source
var ErrAuthenticationFailed = errors.New("access denied to server")

ErrAuthenticationFailed is the error returned when our authentication was rejected by the server.

View Source
var ErrAuthenticationRequired = errors.New("authenticator required for connection")

ErrAuthenticationRequired is the error returned when the server requires authentication but we didn't provide any.

Functions

func AnchorDirectionString added in v4.3.12

func AnchorDirectionString(m AnchorDirection) string

AnchorDirectionString returns a string representation of the internal AnchorDirection value.

func AoETypeString added in v4.3.12

func AoETypeString(m AoEType) string

AoETypeString returns a string representation of the internal AoEType value.

func ArcModeString added in v4.3.12

func ArcModeString(m ArcModeType) string

ArcModeString returns a string representation of the internal ArcModeType value.

func ArrowTypeString added in v4.3.12

func ArrowTypeString(m ArrowType) string

ArrowTypeString returns a string representation of the internal ArrowType value.

func CreatureTypeString added in v4.3.12

func CreatureTypeString(t CreatureTypeCode) string

CreatureTypeString returns a string representation of the internal CreatureTypeCode value.

func DashTypeString added in v4.3.12

func DashTypeString(m DashType) string

DashTypeString returns a string representation of the internal DashType value.

func FontSlantString added in v4.3.12

func FontSlantString(m FontSlantType) string

FontSlantString returns a string representation of the internal FontSlantType value.

func FontWeightString added in v4.3.12

func FontWeightString(m FontWeightType) string

FontWeightString returns a string representation of the internal FontWeight value.

func JoinStyleString added in v4.3.12

func JoinStyleString(m JoinStyle) string

JoinStyleString returns a string representation of the internal JoinStyle value.

func MoveModeString added in v4.3.12

func MoveModeString(m MoveModeType) string

MoveModeString returns a string representation of the internal MoveMode value.

func ParseObjects

func ParseObjects(dataStream []string) ([]MapObject, map[string]ImageDefinition, []FileDefinition, error)

ParseObjects reads a map file which has already been loaded from disk or received from the server into a string slice, one string per line. These lines are parsed to construct the set of map objects recorded in them. These are returned along with the image and file definitions declared in the data stream.

The image list is a map of "imagename:zoom" to ImageDefinition structures.

func SaveObjects

func SaveObjects(objects []MapObject, images map[string]ImageDefinition, files []FileDefinition, options ...func(*saveObjOpts)) ([]string, error)

SaveObjects reverses the operation of ParseObjects. It accepts a slice of MapObjects, a map containing ImageDefinitions, and a slice of FileDefinitions, and emits as a slice of strings a text description of those objects in the map file format, suitable for saving to disk or sending to clients and servers.

A number of options may be given at the end of the argument list, including:

WithoutHeader   -- suppress output of the normal header line
WithDate(t)     -- use the given date instead of the current one
WithComment(s)  -- include the comment string in the header line

func WithComment

func WithComment(c string) func(*saveObjOpts)

WithComment modifies a call to SaveObjects by providing a comment string to include in the "__MAPPER__" header line.

func WithContext

func WithContext(ctx context.Context) func(*Connection) error

WithContext modifies the behavior of the NewConnection function by supplying a context for this connection, which may be used to signal the Dial method that the connection to the server should be terminated.

N.B.: When making the initial TCP connection to the server, if there is a timeout value specified via WithTimeout, then a hanging connection will terminate when that timer expires, regardless of the context. Otherwise, the connection will wait indefinitely to complete OR until the context is cancelled.

func WithDate

func WithDate(d time.Time) func(*saveObjOpts)

WithDate modifies a call to SaveObjects by specifying an already-determined date to record into the "__MAPPER__" header line. Normally, the current date and time is used.

func WithoutHeader

func WithoutHeader(o *saveObjOpts)

WithoutHeader modifies a call to SaveObjects by suppressing the normal "__MAPPER__" header line that should be in a map file.

This may be used, for example, if SaveObjects is generating output that will only be part of, but not the entire, saved data set.

Types

type AddCharacterMessagePayload

type AddCharacterMessagePayload struct {
	BaseMessagePayload
	CharacterDefinition
}

AddCharacterMessagePayload holds the information sent by the server's AddCharacter message to add a new PC to the party. This is not done for most creatures and NPCs encountered; it is for the PCs and significant NPCs who are important enough to be treated specially by clients (such as being included in menus).

type AddImageMessagePayload

type AddImageMessagePayload struct {
	BaseMessagePayload

	// The image definition received from the server.
	ImageDefinition

	// If non-nil, this holds the image data received directly
	// from the server. This usage is not recommended but still
	// supported. In this case the "File" member of the ImageDefinition
	// will be empty.
	ImageData []byte
}

AddImageMessagePayload holds the information sent by the server's AddImage message informing the client as to where it can locate an image's data.

Call the AddImage method to send this message out to others if you know of an image file they should be aware of.

type AddObjAttributesMessagePayload

type AddObjAttributesMessagePayload struct {
	BaseMessagePayload
	ObjID    string
	AttrName string
	Values   []string
}

AddObjAttributesMessagePayload holds the information sent by the server's AddObjAttributes message. This tells the client to adjust the multi-value attribute of the object with the given ID by adding the new values to it.

Call the AddObjAttributes method to send this message out to other clients.

type AdjustViewMessagePayload

type AdjustViewMessagePayload struct {
	BaseMessagePayload
	XView, YView float64
}

AdjustViewMessagePayload holds the information sent by the server's AdjustView message. This tells the client to set its viewable area so that its x and y scrollbars are at the given proportion of their full range.

Call the AdjustView method to send this message out to other clients.

type AnchorDirection added in v4.3.12

type AnchorDirection byte

The valid values for the Anchor attribute of a TextElement.

const (
	AnchorCenter AnchorDirection = iota
	AnchorNorth
	AnchorSouth
	AnchorEast
	AnchorWest
	AnchorNE
	AnchorNW
	AnchorSW
	AnchorSE
)

type AoEType added in v4.3.12

type AoEType byte

These are the valid values for the AoEShape attribute.

const (
	AoEShapeCone AoEType = iota
	AoEShapeRadius
	AoEShapeRay
)

type ArcElement

type ArcElement struct {
	MapElement
	ArcMode ArcModeType
	Extent  float64
	Start   float64
}

ArcElement is a MapElement that draws an arc on-screen. The arc is defined as a portion of a circle which is inscribed within the rectangle formed by the reference point and the single additional point in its Points attribute.

Start and Extent specify the portion of that circle to include in the arc, measured in degrees.

ArcMode defines how to draw the arc: it may be an arc (curve along the circle's permieter without connecting the endpoints), chord (the endpoints connected to each other with a straight line), or a pieslice (endpoints connected to the center of the circle with straight lines).

type ArcModeType added in v4.3.12

type ArcModeType byte

These are the allowed values for the ArcMode attribute of an ArcElement.

const (
	ArcModePieSlice ArcModeType = iota
	ArcModeArc
	ArcModeChord
)

type ArrowType added in v4.3.12

type ArrowType byte

Valid values for a line's Arrow attribute.

const (
	ArrowNone ArrowType = iota
	ArrowFirst
	ArrowLast
	ArrowBoth
)

type BaseMapObject

type BaseMapObject struct {
	// Unique object identifier. May be any string
	// consisting of upper- or lower-case letters, digits, '_', and "#"
	// characters.
	//
	// By convention, we create these from a UUID expressed in
	// hex without punctuation. Local conventions may also be
	// used, such as PC character tokens using ID strings such as
	// "PC1", "PC2", etc.
	ID string
}

BaseMapObject holds attributes all MapObjects have in common, so they will import BaseMapObject into their definitions by composition.

func (BaseMapObject) ObjID

func (o BaseMapObject) ObjID() string

ObjID returns the unique ID of a MapObject. Each type must have one of these methods to satisfy the MapObject interface.

type BaseMessagePayload

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

BaseMessagePayload is not a payload type that you should ever encounter directly, but it is included in all other payload types. It holds the bare minimum data for any server message.

func (BaseMessagePayload) MessageType

func (p BaseMessagePayload) MessageType() ServerMessage

MessageType returns the type of message this MessagePayload represents. This value will be the same as the ServerMessage value used for the Subscribe function, and may be used with channels which receive multiple kinds of messages to differentiate them, like so:

select {
case p<-messages:
    // This channel may receive a ChatMessage or RollResult.
    switch p.MessageType() {
    case ChatMessage:
        // Do whatever with p.(ChatMessageMessagePayload)
    case RollResult:
        // Do whatever with p.(RollResultMessagePayload)
    default:
        // Something bad happened!
    }
 ...
}

You can also use a type switch to accomplish the same thing and avoid the explicit type assertions:

select {
case p<-messages:
    // This channel may receive a ChatMessage or RollResult.
    switch msg := p.(type) {
    case ChatMessageMessagePayload:
        // Do whatever with msg
    case RollResultMessagePayload:
        // Do whatever with msg
    default:
        // Something bad happened!
    }
 ...
}

func (BaseMessagePayload) RawMessage

func (p BaseMessagePayload) RawMessage() []string

RawMessage returns the raw message received from the server before it was parsed out into the MessagePayload the client should arguably be looking at instead.

The raw message data may be useful for debugging purposes or other low-level poking around, though, so we make it available here. The value returned is a slice of strings representing the fields of the received message after being broken out into fields. For multi-line messages, it will instead be a slice of un-broken-out lines.

type CharacterDefinition

type CharacterDefinition struct {
	// Character name as appears on the map.
	Name string

	// ObjID to use for the character rather than generating one.
	ObjID string

	// Color to use to draw the threat zone around the character.
	Color string

	// Size codes of the threat area and creature token size.
	Area, Size string
}

CharacterDefinition describes a PC known as a regular player of the game system.

func (CharacterDefinition) Text

func (c CharacterDefinition) Text() string

Text produces a simple text description of the receiving CharacterDefinition value.

type CharacterDefinitions

type CharacterDefinitions map[string]CharacterDefinition

CharacterDefinitions is a collection of the known characters in the game (note that these are the ones explicitly defined by the server up-front, usually the player characters in the party, which are special enough to be included in UI elements, not the other characters and other creatures encountered during the game).

These are collected in a map where the keys are the object IDs of the characters.

func (CharacterDefinitions) Text

func (cs CharacterDefinitions) Text() string

Text describes the PCs in the receiving map of CharacterDefinitions in a simple multi-line text form.

type ChatCommon

type ChatCommon struct {
	// The name of the person sending the message.
	Sender string

	// The names of the people the message was explicitly addressed to.
	// This will be nil for global messages.
	Recipients []string

	// The unique ID number for the chat message.
	MessageID int

	// True if this is a global message (sent to all users).
	ToAll bool

	// True if this message was sent only to the GM.
	ToGM bool
}

ChatCommon holds fields common to chat messages and die-roll results.

type ChatMessageMessagePayload

type ChatMessageMessagePayload struct {
	BaseMessagePayload
	ChatCommon

	// The text of the chat message we received.
	Text string
}

ChatMessageMessagePayload holds the information sent by the server's ChatMessage message. This is a message sent by other players or perhaps by the server itself.

Call the ChatMessage, ChatMessageToAll, or ChatMessageToGM methods to send this message out to other clients.

type CircleElement

type CircleElement struct {
	MapElement
}

CircleElement is a MapElement that draws an ellipse or circle on-screen. The ellipse is described by the rectangle formed by the reference point and the single point in the Points attribute (as diagonally opposing points), with the circle/ellipse being inscribed in that rectangle.

type ClearChatMessagePayload

type ClearChatMessagePayload struct {
	BaseMessagePayload

	// User requesting the action, if known.
	RequestedBy string

	// Don't notify the user of the operation.
	DoSilently bool

	// If >0, clear all messages with IDs greater than target.
	// If <0, clear most recent -N messages.
	// If 0, clear all messages.
	Target int

	// Chat message ID of this notice.
	MessageID int
}

ClearChatMessagePayload holds the information sent by the server's ClearChat message. This tells the client to remove some messages from its chat history.

Call the ClearChat method to send this message out to other clients.

type ClearFromMessagePayload

type ClearFromMessagePayload struct {
	BaseMessagePayload
	FileDefinition
}

ClearFromMessagePayload holds the information sent by the server's ClearFrom message. This tells the client to remove all elements mentioned in the specified map file.

Call the ClearFrom method to send this message out to other clients.

type ClearMessagePayload

type ClearMessagePayload struct {
	BaseMessagePayload

	// The ObjID gives the object ID for the object to be removed, or one of
	// the following:
	//   *                    Remove all objects
	//   E*                   Remove all map elements
	//   M*                   Remove all monster tokens
	//   P*                   Remove all player tokens
	//   [<imagename>=]<name> Remove token with given <name>
	ObjID string
}

ClearMessagePayload holds the information sent by the server's Clear message. This tells the client to remove one or more objects from its canvas.

Call the Clear method to send this message out to other clients.

type CombatModeMessagePayload

type CombatModeMessagePayload struct {
	BaseMessagePayload

	// If true, we should be in combat mode.
	Enabled bool
}

CombatModeMessagePayload holds the information sent by the server's CombatMode message. This tells the client to enter or exit combat (initiative) mode.

Call the CombatMode method to send this message out to other clients.

type CommentMessagePayload

type CommentMessagePayload struct {
	BaseMessagePayload
	Text string
}

CommentMessagePayload holds the information sent by the server's Comment message. This provides information from the server that the client is free to ignore, but may find interesting. Nothing sent in comments is critical to the operation of a client. However, some incidental bits of information such as an advisement of currently-supported client versions and progress gauge data are sent via comments.

type Connection

type Connection struct {
	// The context for our session, either one we created in the
	// NewConnection function or one we received from the caller.
	Context context.Context

	// The server endpoint, in any form acceptable to the net.Dial
	// function.
	Endpoint string

	// If this is non-nil, we will use this to identify the user
	// to the server.
	Authenticator *auth.Authenticator

	// Server message subscriptions currently in effect.
	Subscriptions map[ServerMessage]chan MessagePayload

	// If nonzero, we will re-try a failing connection this many
	// times before giving up on the server. Otherwise we will keep
	// trying forever.
	Retries uint

	// If nonzero, our connection attempts will timeout after the
	// specified time interval. Otherwise they will wait indefinitely.
	Timeout time.Duration

	// We will log informational messages here as we work.
	Logger *log.Logger

	// The server's protocol version number.
	Protocol int

	// Characters received from the server.
	Characters map[string]CharacterDefinition

	// Conditions and their token markings received from the server.
	Conditions map[string]StatusMarkerDefinition

	// If we received pre-authentication data from the server other than
	// definition of characters and condition codes, they are technically
	// too early to be valid (the server shouldn't do anything else before
	// authenticating), so we'll merely collect them here in case they are
	// of interest forensically.
	Preamble []string

	// Any progress gauges sent by the server will be tracked here as well
	// as passed to a channel subscribed to UpdateProgress.
	Gauges map[string]*UpdateProgressMessagePayload

	// The last error encountered while communicating with the server.
	LastError error

	// The verbosity level of debugging log messages.
	DebuggingLevel uint

	// The calendar system the server indicated as preferred, if any
	CalendarSystem string

	// If true, we will always try to reconnect to the server if we
	// lose our connection.
	StayConnected bool
	// contains filtered or unexported fields
}

Connection describes a connection to the server. These are created with NewConnection and then send methods such as Subscribe and Dial.

func NewConnection

func NewConnection(endpoint string, opts ...ConnectionOption) (Connection, error)

NewConnection creates a new server connection value which can then be used to manage our communication with the server.

After the endpoint, you may specify any of the following options to define the behavior desired for this connection:

StayConnected(bool)
WithAuthenticator(a)
WithDebugging(level)
WithContext(ctx)
WithLogger(l)
WithRetries(n)
WithSubscription(ch, msgs...)
WithTimeout(t)

Example:

a := NewClientAuthenticator("fred", []byte("sekret"), "some random client")
ctx, cancel := context.Background()
defer cancel()

messages := make(chan MessagePayload, 10)
problems := make(chan MessagePayload, 10)

server, err := NewConnection("mygame.example.org:2323",
                  WithAuthenticator(a),
                  WithContext(ctx),
                  StayConnected(true),
                  WithSubscription(messages, ChatMessage, RollResult),
                  WithSubscription(problems, ERROR, UNKNOWN))
if err != nil {
   log.Fatalf("can't reach the server: %v", err)
}
go server.Dial()

func (*Connection) AddDicePresets

func (c *Connection) AddDicePresets(presets []DieRollPreset) error

AddDicePresets is like DefineDicePresets except that it adds the presets passed in to the existing set rather than replacing them.

func (*Connection) AddImage

func (c *Connection) AddImage(idef ImageDefinition) error

AddImage informs the server and peers about an image they can use.

func (*Connection) AddImageData

func (c *Connection) AddImageData(idef ImageDefinition, data []byte) error

AddImageData sends binary image data to peer clients.

Generally, it is better to store an image file on the server, and then call AddImage to point others to find the image there, since that will be more efficient than sending it through the mapper protocol.

func (*Connection) AddObjAttributes

func (c *Connection) AddObjAttributes(objID, attrName string, values []string) error

AddObjAttributes informs peers to add a set of string values to the existing value of an object attribute. The attribute must be one whose value is a list of strings, such as STATUSLIST.

func (*Connection) AdjustView

func (c *Connection) AdjustView(xview, yview float64) error

AdjustView tells other clients to adjust their scrollbars so that the x and y directions are scrolled to xview and yview respectively, where those values are a fraction from 0.0 to 1.0 indicating the proportion of the full range in each direction.

func (*Connection) Allow added in v4.4.1

func (c *Connection) Allow(features ...OptionalFeature) error

Allow tells the server which optional features this client is prepared to accept.

func (*Connection) CacheFile

func (c *Connection) CacheFile(serverID string) error

CacheFile asks other clients to be sure they retrieve and cache the map file with the given server ID.

func (*Connection) ChatMessage

func (c *Connection) ChatMessage(to []string, message string) error

ChatMessage sends a message on the chat channel to other users. The to paramter is a slice of user names of the people who should receive this message. Any of them may also be the special values

ToGMOnly  -- ignore any other names on the list. Send only to GM.
ToAll     -- send to all users.

func (*Connection) ChatMessageToAll

func (c *Connection) ChatMessageToAll(message string) error

ChatMessageToAll is equivalent to ChatMessage, but is addressed to all users.

func (*Connection) ChatMessageToGM

func (c *Connection) ChatMessageToGM(message string) error

ChatMessageToGM is equivalent to ChatMessage, but is addressed only to the GM.

func (*Connection) Clear

func (c *Connection) Clear(objID string) error

Clear tells peers to remove objects from their canvases. The objID may be one of the following:

  • Remove all objects E* Remove all map elements M* Remove all monster tokens P* Remove all player tokens [<imagename>=]<name> Remove token with given <name> <id> Remove object with given <id>

func (*Connection) ClearChat

func (c *Connection) ClearChat(target int, silently bool) error

ClearChat tells peers to remove all messages from their chat histories if target is zero. If target>0, then all messages with IDs greater than target are removed. Otherwise, if target<0 then only the most recent |target| messages are kept.

func (*Connection) ClearFrom

func (c *Connection) ClearFrom(serverID string) error

ClearFrom tells all peers to load the map file with the given server ID, but to remove from their canvases all objects described in the file rather than loading them on.

func (*Connection) Close

func (c *Connection) Close()

Close terminates the connection to the server. Note that the Dial function normally closes the connection before it returns, so calling this explicitly should not normally be necessary.

Calling Close will result in the Dial function stopping due to the connection disappearing, but it is better to cancel the context being watched by Dial instead.

func (*Connection) CombatMode

func (c *Connection) CombatMode(enabled bool) error

CombatMode tells all peers to enable or disable combat mode.

func (*Connection) DefineDicePresets

func (c *Connection) DefineDicePresets(presets []DieRollPreset) error

DefineDicePresets replaces any existing die-roll presets you have stored on the server with the new set passed as the presets parameter.

func (*Connection) Dial

func (c *Connection) Dial()

Dial connects to the server, negotiates the initial sign-on sequence with it, and then enters a loop to receive messages from the server until the connection is broken or the context is cancelled, at which point the Dial method returns.

Dial is designed to be called in a goroutine so it can run in the background while the rest of the appliction continues with other tasks.

Any errors encountered by the Dial method will be reported to the channel subscribed to watch for ERROR messages. If the client application did not subscribe to ERROR messages, they will be logged.

Example:

ctx, cancel := context.Background()
server, err := NewConnection("example.org:2323",
                             WithAuthenticator(a),
                             WithContext(ctx))
defer cancel()
go server.Dial()

func (*Connection) FilterDicePresets

func (c *Connection) FilterDicePresets(re string) error

FilterDicePresets asks the server to remove all of your die-roll presets whose names match the given regular expression.

func (*Connection) IsReady

func (c *Connection) IsReady() bool

IsReady returns true if the connection to the server has completed and authentication was successful, so the connection is ready for interactive use.

func (*Connection) LoadFrom

func (c *Connection) LoadFrom(path string, local bool, merge bool) error

LoadFrom asks other clients to load a map files from a local disk file or from the server. The previous map contents are erased before each file is loaded.

If local is true, a local path is specified. This is discouraged in favor of storing files on the server.

Otherwise, the path should be the ID for the file stored on the server.

If merge is true, then the current map elements are not deleted first. In this case, the newly-loaded elements will be merged with what is already on the map.

func (*Connection) LoadObject

func (c *Connection) LoadObject(mo MapObject) error

LoadObject sends a MapObject to all peers.

func (*Connection) Mark

func (c *Connection) Mark(x, y float64) error

Mark tells clients to visibly mark a location centered on the given (x, y) coordinates.

func (*Connection) PlaceSomeone

func (c *Connection) PlaceSomeone(someone interface{}) error

PlaceSomeone tells all peers to add a new creature token on their maps. The parameter passed must be either a PlayerToken or MonsterToken.

If the creature is already on the map, it will be replaced by the new one being presented here. Thus, PlaceSomeone may be used to change the name or location of an existing creature, although the preferred way to do that would be to use UpdateObjAttributes to change those specific attributes of the creature directly.

func (*Connection) Polo added in v4.3.12

func (c *Connection) Polo() error

Polo send the client's response to the server's MARCO ping message.

func (*Connection) QueryDicePresets

func (c *Connection) QueryDicePresets() error

QueryDicePresets requests that the server send you the die-roll presets currently stored for you. It will send you an UpdateDicePresets message.

func (*Connection) QueryImage

func (c *Connection) QueryImage(idef ImageDefinition) error

QueryImage asks the server and peers if anyone else knows where to find the data for the given image name and zoom factor. If someone does, you'll receive an AddImage message.

func (*Connection) QueryPeers

func (c *Connection) QueryPeers() error

QueryPeers asks the server to send an UpdatePeerList message with the current set of peers who are connected to the server.

func (*Connection) RemoveObjAttributes

func (c *Connection) RemoveObjAttributes(objID, attrName string, values []string) error

RemoveObjAttributes informs peers to remove a set of string values from the existing value of an object attribute. The attribute must be one whose value is a list of strings, such as STATUSLIST.

func (*Connection) RollDice

func (c *Connection) RollDice(to []string, rollspec string) error

RollDice sends a rollspec such as "d20+12" or "6d6 fire" to the server, initiating a die roll using the server's built-in facility for that.

This will result in a response in the form of a RollResult message. If something went wrong when trying to satisfy the request, you'll receive a ChatMessage with an explanation instead.

The to parameter lists the users who should receive the results of the die roll, in the same way as recipients are listed to the ChatMessage function.

The rollspec may have any form that would be accepted to the dice.Roll function and dice.DieRoller.DoRoll method. See the dice package for details. https://pkg.go.dev/github.com/MadScienceZone/go-gma/v4/dice#DieRoller.DoRoll

func (*Connection) RollDiceToAll

func (c *Connection) RollDiceToAll(rollspec string) error

RollDiceToAll is equivalent to RollDice, sending the results to all users.

func (*Connection) RollDiceToGM

func (c *Connection) RollDiceToGM(rollspec string) error

RollDiceToGM is equivalent to RollDice, sending the results only to the GM.

func (*Connection) Subscribe

func (c *Connection) Subscribe(ch chan MessagePayload, messages ...ServerMessage) error

Subscribe arranges for server messages to be sent to the specified channel when they arrive.

If multiple messages are specified, they are all directed to send their payloads to the channel, which may use the MessageType method to differentiate what kind of payload was sent.

This method may be called multiple times for the same channel, in which case the specified message(s) are added to the set which sends to that channel.

If another Subscribe method is called with the same ServerMessage that a previous Subscribe mentioned, that will change the subscription for that message to go to the new channel instead of the previous one.

Unless subscribed, the following default behaviors are assumed:

Marco:   Auto-reply with Polo
ERROR:   Log a message
UNKNOWN: Log a message

If any of these are subscribed to, then the default behavior is NOT taken, on the assumption that the code consuming the subscribed events will fully handle an appropriate response.

Further, if AddCharacter or UpdateStatusMarker messages are received from the server, the Connection struct's Characters and Conditions maps are automatically updated (respectively) regardless of whether they are subscribed to.

The default behavior for all other incoming server messages is to ignore them completely. The client will ask the server not to send any non-subscribed messages.

This method may be called on an established connection to change the subscription list on the fly.

If the channel is nil, the message(s) are unsubscribed and will not be received by the client until subscribed to again.

Example: (error checking not shown for the sake of brevity)

cm := make(chan MessagePayload, 1)
service, err := NewConnection(endpoint)
err = service.Subscribe(cm, ChatMessage)

func (*Connection) Sync

func (c *Connection) Sync() error

Sync requests that the server send the entire game state to it.

func (*Connection) SyncChat

func (c *Connection) SyncChat(target int) error

SyncChat requests that the server (re-)send past messages greater than the target message ID (target≥0) or the most recent |target| messages (target<0).

func (*Connection) UpdateObjAttributes

func (c *Connection) UpdateObjAttributes(objID string, newAttrs map[string]interface{}) error

UpdateObjAttributes informs peers that they should modify the specified object's attributes which are mentioned in the newAttrs map. This maps attribute names to their new values.

func (*Connection) WriteOnly

func (c *Connection) WriteOnly() error

WriteOnly informs the server that from this point forward, we will not be interested in receiving any messages. We will only be sending.

Regardless of sending this, clients should still read any data that is sent anyway. The Dial method does in fact do this in case a misbehaving server doesn't fully respect the WriteOnly request.

type ConnectionOption added in v4.3.12

type ConnectionOption func(*Connection) error

ConnectionOption is an option to be passed to the NewConnection function.

func StayConnected

func StayConnected(enable bool) ConnectionOption

StayConnected modifies the behavior of the NewConnection call so that when Dial is called on the new Connection, it will continue to try to re-establish connections to the server (if enable is true) until it utterly fails in the attempt. This is useful in case connections to the server tend to get inadvertently dropped, since this will allow the client to automatically reconnect and resume operations.

If enable is false (the default), Dial will return as soon as the server connection is dropped for any reason.

func WithAuthenticator

func WithAuthenticator(a *auth.Authenticator) ConnectionOption

WithAuthenticator modifies the behavior of the NewConnection function by adding an authenticator which will be used to identify the client to the server. If this option is not given, no attempt will be made to authenticate, which is only appropriate for servers which do not require authentication. (Which, hopefully, won't be the case anyway.)

func WithDebugging

func WithDebugging(level uint) ConnectionOption

WithDebugging modifies the behavior of the NewConnection function so that the operations of the Connection's interaction with the server are logged to varying levels of verbosity:

0 - no extra logging
1 - each incoming/outgoing message is logged
2 - more internal state is exposed
3 - the full data for each incoming/outgoing message is logged

func WithLogger

func WithLogger(l *log.Logger) ConnectionOption

WithLogger modifies the behavior of the NewConnection function by specifying a custom logger instead of the default one for the Connection to use during its operations.

func WithRetries

func WithRetries(n uint) ConnectionOption

WithRetries modifies the behavior of the NewConnection function to indicate how many times the Dial method should try to establish a connection to the server before giving up.

Setting this to 0 means to retry infinitely many times. The default is to make a single attempt to connect to the server.

func WithSubscription

func WithSubscription(ch chan MessagePayload, messages ...ServerMessage) ConnectionOption

WithSubscription modifies the behavior of the NewConnection function by adding a server message subscription to the connection just as if the Subscribe method had been called on the connection value.

For example, this:

server, err := NewConnection(endpoint,
                 WithSubscription(chats, ChatMessage, RollResult),
                 WithSubscription(oops, ERROR, UNKNOWN))
go server.Dial()

is equivalent to this:

server, err := NewConnection(endpoint)
err = server.Subscribe(chats, ChatMessage, RollResult)
err = server.Subscribe(oops, ERROR, UNKNOWN)
go server.Dial()

(Of course, real production code should check the returned error values.)

func WithTimeout

func WithTimeout(t time.Duration) ConnectionOption

WithTimeout modifies the behavior of the NewConnection function by specifying the time to allow the Dial method to make the TCP connection to the server. After this time expires, the attempt is abandoned (but may be retried based on the value of WithRetries, if any).

N.B.: When making the initial TCP connection to the server, if there is a timeout value specified via WithTimeout, then a hanging connection will terminate when that timer expires, regardless of the context (although a canceled context will stop retry attempts). Otherwise, the connection will wait indefinitely to complete OR until the context is cancelled.

type Coordinates

type Coordinates struct {
	X, Y float64
}

Coordinates give an (x, y) coordinate pair to locate something on the map. Coordinates are in standard map pixel units (10 pixels = 1 foot).

type CreatureHealth

type CreatureHealth struct {
	// The maximum hit points possible for the creature.
	MaxHP int

	// The amount of lethal and non-lethal damage suffered by the creature.
	LethalDamage    int
	NonLethalDamage int

	// The grace amount of hit points a creature may suffer over their maximum before
	// they are actually dead (as opposed to critically wounded). This is generally
	// the creature's Constitution score, hence the name.
	Con int

	// Is the creature flat-footed?
	IsFlatFooted bool

	// Has the creature been stabilized to prevent death while critically wounded?
	IsStable bool

	// Override the map client's idea of how to display the creature's health condition.
	// Normally this is the empty string which allows the client to calculate it from the
	// information available to it.
	Condition string

	// If 0, the creature's health is displayed accurately on the map. Otherwise,
	// this gives the percentage by which to "blur" the hit points as seen by the
	// players. For example, if HpBlur is 10, then hit points are displayed only in
	// 10% increments.
	HpBlur int
}

CreatureHealth describes the current health statistics of a creature if we are tracking it for them.

type CreatureToken

type CreatureToken struct {
	BaseMapObject

	// The name of the creature as displayed on the map. Must be unique
	// among the other creatures.
	Name string

	// If non-nil, this tracks the health status of the creature.
	Health *CreatureHealth

	// Grid (x, y) coordinates for the reference point of the
	// creature.  Unlike MapElement coordinates, these are in
	// grid units (1 grid = 5 feet).  The upper-left corner of
	// the creature token is at this location.
	Gx, Gy float64

	// For creatures which may change their shape or appearance,
	// multiple "skins" may be defined to display as appropriate.
	//
	// Skin is 0 for the default appearance of the creature, 1
	// for the alternate image, 2 for the 2nd alternate image, etc.
	Skin int

	// If the different "skins" are different sizes, this is a list
	// of size codes for each of them. For example, if there are 3
	// skins defined, the first two medium-size and the 3rd large
	// size, then SkinSize would have the value {"M", "M", "L"}.
	// If this is empty or nil, all skins are assumed to be the
	// size specified in the Size attribute. Note that SkinSize
	// also sets the Area at the same time.
	SkinSize []string

	// Current elevation in feet relative to the "floor" of the
	// current location.
	Elev int

	// The color to draw the creature's threat zone when in combat.
	Color string

	// A note to attach to the creature token to indicate special
	// conditions affecting the creature which are not otherwise shown.
	Note string

	// The tactical size category of the creature ("S", "M", "L",
	// etc). Lower-case letters indicate the "wide" version of the
	// category while upper-case indicates "tall" versions.
	//
	// May also be the size in feet (DEPRECATED).
	Size string

	// The tactical threat zone size of the creature, specified just
	// as with Size.
	Area string

	// A list of condition codes which apply to the character. These
	// are arbitrary and defined by the server according to the needs
	// of the particular game, but may include things such
	// as "confused", "helpless", "hasted", etc.
	StatusList []string

	// If there is a spell effect radiating from the creature, its
	// area of effect is described by this value. If there is none,
	// this is nil.
	//
	// Currently only radius emanations are supported. In future, the
	// type of this attribute may change to handle other shapes.
	AoE *RadiusAoE

	// The method of locomotion currently being used by this creature.
	// Normally this is MoveModeLand for land-based creatures which
	// are walking/running.
	MoveMode MoveModeType

	// Is the creature currently wielding a reach weapon or otherwise
	// using the "reach" alternate threat zone?
	Reach bool

	// Is the creature currently dead? (This takes precedence over the
	// Health attribute's indication that the creature has taken a
	// fatal amount of damage.)
	Killed bool

	// In combat, if this is true, the token is "dimmed" to indicate
	// that it is not their turn to act.
	Dim bool

	// The creature type.
	CreatureType CreatureTypeCode
}

CreatureToken is a MapObject (but not a MapElement) which displays a movable token indicating the size and location of a creature in the game.

type CreatureTypeCode added in v4.3.12

type CreatureTypeCode byte

Creature type codes for the CreatureType field of CreatureToken (and PlayerToken and MonsterToken) values.

const (
	CreatureTypeUnknown CreatureTypeCode = iota
	CreatureTypeMonster
	CreatureTypePlayer
)

type DashType added in v4.3.12

type DashType byte

These are the allowed values for the Dash attribute of a MapElement.

const (
	DashSolid DashType = iota
	DashLong
	DashMedium
	DashShort
	DashLongShort
	DashLong2Short
)

type DieRollPreset

type DieRollPreset struct {
	// The name by which this die-roll preset is identified to the user.
	// This must be unique among that user's presets.
	//
	// Clients typically
	// sort these names before displaying them.
	// Note that if a vertical bar ("|") appears in the name, all text
	// up to and including the bar are suppressed from display. This allows
	// for the displayed names to be forced into a particular order on-screen,
	// and allow a set of presets to appear to have the same name from the user's
	// point of view.
	Name string

	// A text description of the purpose for this die-roll specification.
	Description string

	// The die-roll specification to send to the server. This must be in a
	// form acceptable to the dice.Roll function. For details, see
	// https://pkg.go.dev/github.com/MadScienceZone/go-gma/v4/dice#DieRoller.DoRoll
	DieRollSpec string
}

DieRollPreset describes each die-roll specification the user has stored on the server as a ready-to-go preset value which will be used often, and needs to be persistent across gaming sessions.

type ErrorMessagePayload

type ErrorMessagePayload struct {
	BaseMessagePayload
	OriginalMessageType ServerMessage
	Error               error
}

ErrorMessagePayload describes an error which encountered when trying to receive a message.

type FileDefinition

type FileDefinition struct {
	// The filename or Server ID.
	File string

	// If IsLocalFile is true, File is the name of the file on disk;
	// otherwise it is the server's internal ID by which you may request
	// that file from the server.
	IsLocalFile bool
}

FileDefinition describes a file as known to the mapper which may be of interest to retrieve at some point.

type FontSlantType added in v4.3.12

type FontSlantType byte

The valid font slants.

const (
	FontSlantRoman FontSlantType = iota
	FontSlantItalic
)

type FontWeightType added in v4.3.12

type FontWeightType byte

The valid font weights.

const (
	FontWeightNormal FontWeightType = iota
	FontWeightBold
)

type ImageDefinition

type ImageDefinition struct {
	// The zoom (magnification) level this bitmap represents for the given
	// image.
	Zoom float64

	// The name of the image as known within the mapper.
	Name string

	// The filename by which the image can be retrieved.
	File string

	// If IsLocalFile is true, File is the name of the image file on disk;
	// otherwise it is the server's internal ID by which you may request
	// that file from the server.
	IsLocalFile bool
}

ImageDefinition describes an image as known to the mapper system. TileElements' Image attribute refers to the Name attribute of one of these.

type InitiativeSlot

type InitiativeSlot struct {
	// The slot number (currently 0–59, corresponding to the 1/10th second "count" in the initiative round)
	Slot int

	// The current hit point total for the creature.
	CurrentHP int

	// The creature's name as displayed on the map.
	Name string

	// If true, the creature is holding their action.
	IsHolding bool

	// If true, the creature has a readied action.
	HasReadiedAction bool

	// It true, the creature is flat-footed.
	IsFlatFooted bool
}

InitiativeSlot describes the creature occupying a given slot of the initiative list.

type JoinStyle added in v4.3.12

type JoinStyle byte

These are the allowed values for the Join attribute of a PolygonElement.

const (
	JoinBevel JoinStyle = iota
	JoinMiter
	JoinRound
)

type LineElement

type LineElement struct {
	MapElement

	// What arrowheads, if any, to draw on the endpoints
	Arrow ArrowType
}

LineElement is a MapElement that draws a straight line segment from the reference point to the single point in the Points attribute.

If there are multiple points in the Points attribute, the element will be drawn from each point to the next, as connected line segments.

The line will have arrowheads drawn on the first (reference) point, the last point, both, or neither, as indicated by the Arrow attribute.

N.B.: the lines will be drawn with the Fill color, not the Line color, to match the behavior of the Tk library underlying our client implementations.

type LoadFromMessagePayload

type LoadFromMessagePayload struct {
	BaseMessagePayload
	FileDefinition

	// If true, the client should only pre-load this data into a
	// local cache, but not start displaying these elements yet.
	CacheOnly bool

	// If true, the elements are merged with the existing map
	// contents rather than replacing them.
	Merge bool
}

LoadFromMessagePayload holds the information sent by the server's LoadFrom message. This tells the client to open the file named (which may either be a local disk file or one retrieved from the server), and either replacing their current canvas contents with the elements from that file, or adding those elements to the existing contents.

Call the LoadFrom method to send this message out to other clients.

type LoadObjectMessagePayload

type LoadObjectMessagePayload struct {
	BaseMessagePayload
	MapObject
}

LoadObjectMessagePayload holds the information sent by the server's LoadObject message. This tells the client to load the MapObject contained in the payload structure. This is used when the server (on behalf of other clients, usually) sends map objects directly rather than loading them from files.

Call the LoadObject method to send this message out to other clients.

type MapElement

type MapElement struct {
	BaseMapObject
	Coordinates

	// Objects which need additional coordinate pairs to describe their
	// geometry (beyond the standard reference point) store them here.
	Points []Coordinates

	// The z "coordinate" is the vertical stacking order relative to the other
	// displayed on-screen objects.
	Z int

	// The colors used to draw the element's outline and/or to fill it's interior.
	// These may be standard color names such as "blue" or an RGB string such as
	// "#336699". A fill color that is the empty string means not to fill that element.
	Line string
	Fill string

	// The width in pixel units to draw the element's outline.
	Width int

	// The map layer this element belongs to.
	Layer string

	// The dungeon level where this element appears. Typically, level 0
	// is the default (ground) level, with level numbers increasing as
	// 1, 2, 3, etc., for floors above it, and with underground levels
	// counting down as -1, -2, -3, etc.
	Level int

	// Elements may be arranged into logical groups to be manipulated
	// together. This is the ID of the group to which this belongs, or
	// is empty if this element is not grouped.
	Group string

	// The element's line(s) are to be drawn with this dash pattern.
	Dash DashType

	// Is this element currently concealed from view?
	Hidden bool

	// Is the object locked from editing by the user?
	Locked bool
}

MapElement is a MapObject which represents a static map feature to be displayed.

Each MapElement has at least one pair of (x, y) coordinates which locate the element's "reference point" on the map. What this means is up to each different kind of MapElement.

type MapObject

type MapObject interface {
	ObjID() string
	// contains filtered or unexported methods
}

MapObject is anything the map server or client tracks and manages. These are generally things that are displayed on-screen such as map features, creature tokens, etc.

type MarcoMessagePayload

type MarcoMessagePayload struct {
	BaseMessagePayload
}

MarcoMessagePayload holds the information sent by the server's Marco message. This is a "ping" message the server periodically sends to all clients to ensure they are still responding. A client who receives a MARCO message is expected to respond with a POLO message.

If the client doesn't subscribe to Marco messages, the Dial method will automatically reply with Polo messages.

type MarkMessagePayload

type MarkMessagePayload struct {
	BaseMessagePayload
	Coordinates
}

MarkMessagePayload holds the information sent by the server's Mark message. This tells the client to visually mark the given map coordinates.

Call the Mark method to send this message out to other clients.

type MessagePayload

type MessagePayload interface {
	MessageType() ServerMessage
	RawMessage() []string
}

MessagePayload is an interface that includes any kind of message the server will send to us.

type MonsterToken

type MonsterToken struct {
	CreatureToken
}

MonsterToken is a CreatureToken which describes a monster or NPC adversary.

type MoveModeType added in v4.3.12

type MoveModeType byte

The valid values for a creature's MoveMode attribute.

const (
	MoveModeLand MoveModeType = iota
	MoveModeBurrow
	MoveModeClimb
	MoveModeFly
	MoveModeSwim
)

type OptionalFeature added in v4.4.1

type OptionalFeature byte
const (
	DiceColorBoxes OptionalFeature = iota
)

type Peer

type Peer struct {
	// IP address and port of the peer
	Addr string

	// The username provided by the peer when it authenticated
	User string

	// A description of the peer client program (provided by that client)
	Client string

	// How many seconds ago the peer last answered a "still alive?" ping from the server
	LastPolo float64

	// True if the client authenticated successfully
	IsAuthenticated bool

	// True if this structure describes the connection of this client program
	IsMe bool

	// True if the peer is running as the "main" or "primary" client
	IsMain bool

	// True if the peer client is not paying attention to any incoming
	// messages
	IsWriteOnly bool
}

Peer describes each peer we can reach via our server connection.

type PlaceSomeoneMessagePayload

type PlaceSomeoneMessagePayload struct {
	BaseMessagePayload
	CreatureToken
}

PlaceSomeoneMessagePayload holds the information sent by the server's PlaceSomeone message. This tells the client to introduce a new creature token, or if that token is already on the board, update it with the new information (usually just moving its location).

Retain any existing attributes in the original which have nil values here (notably, this server message never carries health stats so that structure will always be nil).

Call the PlaceSomeone method to send this message out to other clients.

type PlayerToken

type PlayerToken struct {
	CreatureToken
}

PlayerToken is a CreatureToken which describes a player character or NPC ally.

type PolygonElement

type PolygonElement struct {
	MapElement

	// Spline gives the factor to use when smoothing the sides of the polygon between
	// its points. 0 means not to smooth them at all, resulting in a shape with straight
	// edges between the vertices. Otherwise, larger values provide greater smoothing.
	Spline float64

	// The join style to control how the intersection between line segments is drawn.
	Join JoinStyle
}

PolygonElement is a MapElement that draws an arbitrary polygon, just as with the LineElement, but the interior of the shape described by the line segments may be filled in as a solid shape.

type QueryImageMessagePayload

type QueryImageMessagePayload struct {
	BaseMessagePayload
	ImageDefinition
}

QueryImageMessagePayload holds the information sent by the server's QueryImage message. This tells the client that a peer wants to know where to find a given image and the server didn't know either. If you know the definition for that image, reply with an AddImage message of your own.

Call the QueryImage method to send this message out to other clients.

type RadiusAoE

type RadiusAoE struct {
	// Distance in standard map pixels away from the creature token's center
	// to the perimeter of the affected area.
	Radius float64

	// Color to draw the affected zone.
	Color string
}

RadiusAoE describes the area of some spell or special effect emanating from the creature.

type RectangleElement

type RectangleElement struct {
	MapElement
}

RectangleElement is a MapElement which describes a rectangle as defined by diagonally opposing points: the reference point and the single coordinate pair in the Points attribute.

type RemoveObjAttributesMessagePayload

type RemoveObjAttributesMessagePayload struct {
	BaseMessagePayload

	// The ID of the object to be modified
	ObjID string

	// The name of the attribute to modify. Must be one with a []string value.
	AttrName string

	// The values to remove from the attribute.
	Values []string
}

RemoveObjAttributesMessagePayload holds the information sent by the server's RemoveObjAttributes message. This tells the client to adjust the multi-value attribute of the object with the given ID by removing the listed values from it.

Call the RemoveObjAttributes method to send this message out to other clients.

type RollResultMessagePayload

type RollResultMessagePayload struct {
	BaseMessagePayload
	ChatCommon

	// The title describing the purpose of the die-roll, as set by the user.
	Title string

	// The die roll result and details behind where it came from.
	Result dice.StructuredResult
}

RollResultMessagePayload holds the information sent by the server's RollResult message. This tells the client the results of a die roll.

type ServerMessage

type ServerMessage byte

ServerMessage is an arbitrary code which identifies specific message types that we can receive from the server. This value is passed to the Subscribe method and returned by the MessageType method. These values are intended for use within an actively-running program but are not guaranteed to remain stable across new releases of the code, so they should not be stored and re-used by a later execution of the client, nor passed to other programs whose definition of these values may not agree.

const (
	AddCharacter ServerMessage = iota
	AddImage
	AddObjAttributes
	AdjustView
	ChatMessage
	Clear
	ClearChat
	ClearFrom
	CombatMode
	Comment
	LoadFrom
	LoadObject
	Marco
	Mark
	PlaceSomeone
	QueryImage
	RemoveObjAttributes
	RollResult
	Toolbar
	UpdateClock
	UpdateDicePresets
	UpdateInitiative
	UpdateObjAttributes
	UpdatePeerList
	UpdateProgress
	UpdateStatusMarker
	UpdateTurn
	UNKNOWN
	ERROR
)

ServerMessage values (see the comments accompanying the type definition).

type SpellAreaOfEffectElement

type SpellAreaOfEffectElement struct {
	MapElement

	// The shape of the affected region of the map.
	AoEShape AoEType
}

SpellAreaOfEffectElement is a MapElement that shows a region on the map affected by a spell or other area effect.

The region has one of the following shapes as indicated by the AoEShape attribute:

cone    A 90° pieslice described as with ArcElement
radius  An ellipse described as with CircleElement
ray     A rectangle described as with RectangleElement

type StatusMarkerDefinition

type StatusMarkerDefinition struct {
	// The name of the condition
	Condition string

	// The shape of the marker to be drawn on the token. This may
	// be one of the following:
	//   |v  small downward-pointing triangle against the left edge
	//   v|  small downward-pointing triangle against the right edge
	//   |o  small circle against the left edge
	//   o|  small circle against the right edge
	//   |<> small diamond against the left edge
	//   <>| small diamond against the right edge
	//   /   slash from upper right to lower left
	//   \   slash from upper left to lower right
	//   //  double slash from upper right to lower left
	//   \\  double slash from upper left to lower right
	//   -   horizontal line through the center of the token
	//   =   double horizontal line through the center
	//   |   vertical line through the center
	//   ||  double vertical line through the center
	//   +   cross (vertical and horizontal lines) through center
	//   #   double cross (vertical and horizontal lines) through center
	//   V   large downward-pointing triangle around token
	//   ^   large upward-pointing triangle around token
	//   <>  large diamond around token
	//   O   large circle around token
	Shape string

	// The color to draw the marker. If the name begins with a pair
	// of hyphens (e.g., "--red") then the marker is drawn with long
	// dashed lines. If it begins with dots (e.g., "..blue") it is
	// drawn with short dashed lines.
	//
	// The special color "*" may be used to indicate that the marker
	// should be drawn in the same color as the creature's threat zone.
	Color string

	// The description of the condition, including what effects it has
	// on the affected creature.
	Description string
}

StatusMarkerDefinition describes each creature token status that the map clients indicate.

func (StatusMarkerDefinition) Text

func (c StatusMarkerDefinition) Text() string

Text produces a simple text description of a StatusMarkerDefinition structure.

type StatusMarkerDefinitions

type StatusMarkerDefinitions map[string]StatusMarkerDefinition

StatusMarkerDefinitions is a map of a condition code name to the full description of the marker to use for that condition.

func (StatusMarkerDefinitions) Text

func (cs StatusMarkerDefinitions) Text() string

Text produces a simple text description of a map of StatusMarkerDefinitions as a multi-line string.

type TextElement

type TextElement struct {
	MapElement

	// The text to be displayed.
	Text string

	// Font to use for the text.
	Font TextFont

	// Where is the reference point in relation to the text?
	Anchor AnchorDirection
}

TextElement is a MapElement which displays text on the map.

The reference point is at the center of the text if Anchor is AnchorCenter, or is at the top-left corner of the text if Anchor is AnchorNW, and so on.

type TextFont

type TextFont struct {
	// The name of the font family as recognized by Tk.
	Family string

	// The font size as recognized by Tk.
	Size float64

	// The font weight (normal or bold).
	Weight FontWeightType

	// The font slant (roman or italic).
	Slant FontSlantType
}

TextFont describes a font used by TextElements.

type TileElement

type TileElement struct {
	MapElement

	// Image name as known to the mapper system.
	Image string

	// Bounding box in pixels for the image tile.
	// If for some reason the tile can't be found, clients
	// can use the bounding box to indicate where the tile should be.
	// If the bounding box is not known, these values may both
	// be zero.
	BBHeight, BBWidth float64
}

TileElement is a MapElement which displays a bitmap image on the map. The upper-left corner of the image will be drawn at the reference point.

type ToolbarMessagePayload

type ToolbarMessagePayload struct {
	BaseMessagePayload
	Enabled bool
}

ToolbarMessagePayload holds the information sent by the server's Toolbar message. This tells the client to display or hide its toolbar.

type UnknownMessagePayload

type UnknownMessagePayload struct {
	BaseMessagePayload
}

UnknownMessagePayload describes a server message we received but have no idea what it is.

type UpdateClockMessagePayload

type UpdateClockMessagePayload struct {
	BaseMessagePayload

	// The clock is now at the given absolute number of
	// seconds from the GMA clock's global epoch.
	Absolute float64

	// The elapsed time counter is now this many seconds from
	// some reference point set by the GM (often the start of
	// combat).
	Relative float64
}

UpdateClockMessagePayload holds the information sent by the server's UpdateClock message. This tells the client to update its clock display to the new value.

type UpdateDicePresetsMessagePayload

type UpdateDicePresetsMessagePayload struct {
	BaseMessagePayload
	Presets []DieRollPreset
}

UpdateDicePresetsMessagePayload holds the information sent by the server's UpdateDicePresets message. This tells the client to accept the die-roll presets described here, replacing any previous presets it was using.

type UpdateInitiativeMessagePayload

type UpdateInitiativeMessagePayload struct {
	BaseMessagePayload
	InitiativeList []InitiativeSlot
}

UpdateInitiativeMessagePayload holds the information sent by the server's UpdateInitiative message. This tells the client that the initiative order has been changed. Its current notion of the initiative order should be replaced by the one given here.

type UpdateObjAttributesMessagePayload

type UpdateObjAttributesMessagePayload struct {
	BaseMessagePayload

	// The ID of the object to be modified.
	ObjID string

	// A map of attribute name to its new value.
	NewAttrs map[string]interface{}
}

UpdateObjAttributesMessagePayload holds the information sent by the server's UpdateObjAttributes message. This tells the client to update an existing object with new attributes. Any attributes not listed here should remain intact.

Call the UpdateObjAttributes method to send this message out to other clients.

type UpdatePeerListMessagePayload

type UpdatePeerListMessagePayload struct {
	BaseMessagePayload
	PeerList []Peer
}

UpdatePeerListMessagePayload holds the information sent by the server's UpdatePeerList message. This tells the client that the list of other connected peers has changed.

type UpdateProgressMessagePayload

type UpdateProgressMessagePayload struct {
	BaseMessagePayload

	// Unique identifier for the operation we're tracking
	OperationID string

	// Description of the operation in progress, suitable for display.
	Title string

	// The current progress toward MaxValue.
	Value int

	// The maximum expected value for the progress indication.
	// If this is 0, we don't yet know what the maximum will be.
	// Note that this may change from one message to another, if
	// the server realizes its previous estimate was incorrect.
	MaxValue int

	// If true, we can dispose of the tracked operation
	// and should not expect further updates about it.
	IsDone bool
}

UpdateProgressMessagePayload holds the information sent by the server's UpdateProgress Comment notification. This advises the client of the status of an operation in progress. The client may wish to display a progress indicator to the user.

type UpdateStatusMarkerMessagePayload

type UpdateStatusMarkerMessagePayload struct {
	BaseMessagePayload
	StatusMarkerDefinition
}

UpdateStatusMarkerMessagePayload holds the information sent by the server's UpdateStatusMarker message. This tells the client to add or change a status marker which may be placed on creature tokens.

Note: the server usually sends these upon login, which the Connection struct stores internally. When this message is received, the Connection's status marker list is updated regardless of whether the client is subscribed to this message (which it may be if some overt action is required on its part to (re-)define the status marker later in the interaction).

type UpdateTurnMessagePayload

type UpdateTurnMessagePayload struct {
	BaseMessagePayload

	// The ObjID of the creature whose turn it is. This may also be one of:
	//   *Monsters*   All monsters are up now.
	//   (empty)      It is no one's turn now.
	//   /regex       All creatures whose names match regex
	ActorID string

	// The time lapsed so far since the start of combat.
	// Count is the initiative slot within the round.
	Hours, Minutes, Seconds, Rounds, Count int
}

UpdateTurnMessagePayload holds the information sent by the server's UpdateTurn message. This tells the client whose turn it is in combat.

Jump to

Keyboard shortcuts

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