client

package
v0.0.0-...-6a1bf87 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BUFFERSIZE = 1024 * 1024
View Source
const (
	DEADLINE = time.Millisecond * 10
)
View Source
const MAX_CONTENT = 2000

number of lines to save

Variables

This section is empty.

Functions

func ClientHelp

func ClientHelp()

func OnEvent

func OnEvent(event string, tag string, run func(), repeat bool) bool

OnEvent executes the function f when the event with the corresponding string is raised. If tag is not "" then the function is only added if the tag is not already in the list. Returns true if the event is added, false if already in the queue. Tags must be unique.

func RaiseEvent

func RaiseEvent(event string)

RaiseEvent executes all enabled handlers for the given event. If a handler is marked to repeat it is re-added.

func RemoveHandler

func RemoveHandler(event string, tag string)

Types

type Client

type Client struct {

	// Publicly available variables
	Ignore     bool
	Gag        bool
	RawLine    []byte
	TextLine   []byte
	Var        map[string]string
	MatchCount int
	// contains filtered or unexported fields
}

Client stores state and provides methods for interacting with the client application.

func NewClient

func NewClient() *Client

Returns a new client with default configuration and initialized variables

func (*Client) AddAction

func (c *Client) AddAction(rs string, cmd func(*Trigger)) *Trigger

AddAction adds an action to the client based on the provided regex `rs` and the function to execute `cmd`

func (*Client) AddActionCmd

func (c *Client) AddActionCmd(t *Trigger)

func (*Client) AddActionString

func (c *Client) AddActionString(rs string, cmd string) *Trigger

func (*Client) AddActionTrigger

func (c *Client) AddActionTrigger(t *Trigger)

AddActionTrigger adds an action to the client based on the provided trigger

func (*Client) AddAlias

func (c *Client) AddAlias(rs string, cmd func(*Trigger)) *Trigger

func (*Client) AddAliasCmd

func (c *Client) AddAliasCmd(t *Trigger)

func (*Client) AddAliasString

func (c *Client) AddAliasString(rs string, cmd string) *Trigger

func (*Client) AddAliasTrigger

func (c *Client) AddAliasTrigger(t *Trigger)

func (*Client) AddCommand

func (c *Client) AddCommand(name string, r string, f func(*Trigger), sh string, lh string) *Command

NewCommand adds a command to the client. The command starts with the defined metacharacter, default '#'. Each command provides a name which is a single word that follows the metacharacter, a list of strings that will be converted into regular expressions that will be run against the command arguments, a short help string and a long help string. Returns nil on error. Pass "" as regex for no arguments.

func (*Client) AddFunction

func (c *Client) AddFunction(name string, f func(t *Trigger))

AddFunction maps a string to a function so that you can call the function from the mud with #function <name>

func (*Client) BaseActionCmd

func (c *Client) BaseActionCmd(t *Trigger)

func (*Client) BaseAliasCmd

func (c *Client) BaseAliasCmd(t *Trigger)

func (*Client) CaptureCmd

func (c *Client) CaptureCmd(t *Trigger)

func (*Client) ChatCmd

func (c *Client) ChatCmd(t *Trigger)

func (*Client) CheckCommand

func (c *Client) CheckCommand(text string)

If the leading character of a string is the metaCharacter then we check for a valid command

func (*Client) CheckTriggers

func (c *Client) CheckTriggers(list []*Trigger, text string) []*Trigger

func (*Client) ClearWindow

func (c *Client) ClearWindow(window string)

func (*Client) Close

func (c *Client) Close()

func (*Client) ConnectCmd

func (c *Client) ConnectCmd(t *Trigger)

ConnectCmd takes a string from the user and attempts to ConnectCmd to the mud server. If the connection is successful then a goroutine is launched to handle the connection.

func (*Client) FuncCmd

func (c *Client) FuncCmd(t *Trigger)

func (*Client) GetWindowSize

func (c *Client) GetWindowSize(name string) (int, int)

func (*Client) LoadPlugin

func (c *Client) LoadPlugin(name string, p *Config)

func (*Client) LoopCmd

func (c *Client) LoopCmd(t *Trigger)

Nested triggers overwrite matches... need to pass into the function

func (*Client) MatchCmd

func (c *Client) MatchCmd(t *Trigger)

func (*Client) MemStatsCmd

func (c *Client) MemStatsCmd(t *Trigger)

func (*Client) NewTrigger

func (c *Client) NewTrigger(re string, cmd func(*Trigger)) *Trigger

NewAction provides a pointer to an action and ensures that all variables are initialized. Returns nil if the provided regex is invalid.

func (*Client) Parse

func (c *Client) Parse(text string)

Parse the string and send the result to the server

func (*Client) Print

func (c *Client) Print(text string)

Print prints text on the main screen

func (*Client) PrintBytesTo

func (c *Client) PrintBytesTo(window string, b []byte)

func (*Client) PrintTimestamp

func (c *Client) PrintTimestamp(w, s string)

func (*Client) PrintTo

func (c *Client) PrintTo(window string, text string)

PrintTo prints text to the specified window

func (*Client) ReadConfigCmd

func (c *Client) ReadConfigCmd(path string)

func (*Client) Run

func (c *Client) Run()

func (*Client) SendNow

func (c *Client) SendNow(text string)

func (*Client) UnactionCmd

func (c *Client) UnactionCmd(t *Trigger)

func (*Client) UnaliasCmd

func (c *Client) UnaliasCmd(t *Trigger)

func (*Client) Write

func (c *Client) Write(b []byte) (int, error)

type Command

type Command struct {
	Name string
	// contains filtered or unexported fields
}

A command is a special string parsed from the input line that executes client functionality instead of being parsed as an alias or being passed directly to the MUD

type Config

type Config struct {
	Actions        map[string]string `yaml:"actions"` // Actions to be registered
	Aliases        map[string]string `yaml:"aliases"` // Aliases to be registered
	Grid           Grid              `yaml:"grid"`
	Windows        map[string]Window `yaml:"windows"` // Windows to be registered
	Functions      map[string]func(*Trigger)
	CredentialFile string `yaml:"credentialfile"`
	AutoLogin      string `yaml:"autologin"`
}

func Merge

func Merge(a *Config, b *Config) *Config

func ReadConfig

func ReadConfig(cfg string) (*Config, error)

Load a plugin from a YAML config file

type Grid

type Grid struct {
	Columns []int `yaml:"columns"`
	Rows    []int `yaml:"rows"`
}

type GzLogger

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

func NewGzLogger

func NewGzLogger(file string, fm fs.FileMode) *GzLogger

func (*GzLogger) Close

func (g *GzLogger) Close()

func (*GzLogger) Write

func (g *GzLogger) Write(b []byte)

type TUI

type TUI struct {
	Windows map[string]*window
	// contains filtered or unexported fields
}

func NewTUI

func NewTUI(parse func(string)) *TUI

func (*TUI) AddWindow

func (t *TUI) AddWindow(name string, win Window)

func (*TUI) ClearWindow

func (t *TUI) ClearWindow(window string)

func (*TUI) FixInputLine

func (t *TUI) FixInputLine(rows []int, cols []int)

func (*TUI) PrintBytes

func (t *TUI) PrintBytes(name string, text []byte)

func (*TUI) Run

func (t *TUI) Run()

func (*TUI) SetGrid

func (t *TUI) SetGrid(rows []int, cols []int)

type Trigger

type Trigger struct {
	*regexp.Regexp
	// Results map named groups to the values captured in the group
	Results map[string]string
	// Matches contains a list of matches and group matches
	Matches []string
	// Enabled determines if the action is compared to incoming text or skipped
	Enabled bool
	// contains filtered or unexported fields
}

Trigger is the base struct used for Actions and Aliases. It matches against text and executes a function when there is a match. It provides convenience functions to enable or disable itself as well as gathering named groups from the regex into a map.

var FuncTrigger *Trigger

func (*Trigger) Do

func (t *Trigger) Do()

Do provides a function that determines if the Action is disabled and decides whether to execute the function or skip

type Window

type Window struct {
	Row           int
	Col           int
	RowSpan       int
	ColSpan       int
	MinGridHeight int
	MinGridWidth  int
	Border        bool
	Scrollable    bool
	MaxLines      int
	Wrap          bool
}

Jump to

Keyboard shortcuts

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