plugins

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPluginRegistry

func GetPluginRegistry() pluginRegistry

func GetRegisteredRoomTags added in v0.9.8

func GetRegisteredRoomTags() map[string][]string

GetRegisteredRoomTags returns a map of plugin name to the room tags it has reserved, containing only plugins that reserved at least one tag.

func Load

func Load(dataFilesPath string)

func OnNetConnect

func OnNetConnect(n NetConnection)

func ReadFile

func ReadFile(dfPath string) ([]byte, error)

func Save

func Save()

func SetAdminRegistrar added in v0.9.8

func SetAdminRegistrar(r ModuleAdminRegistrar)

SetAdminRegistrar provides the callback that plugins.Load() uses to register module admin pages and API endpoints without importing web directly.

Types

type AdminAPIRoute added in v0.9.8

type AdminAPIRoute struct {
	Method        string
	Slug          string
	Path          string // "/admin/api/v1/<slug>"
	Handler       ModuleAPIHandler
	PermissionKey string // if non-empty, required permission key for this endpoint
}

AdminAPIRoute describes an admin API endpoint contributed by a module.

type AdminWebPage added in v0.9.8

type AdminWebPage struct {
	Name                 string
	Slug                 string // e.g. "mudmail" -> /admin/mudmail
	Path                 string // "/admin/mudmail"
	HTMLFile             string // path inside plugin FS, relative to datafiles/html/admin/
	Description          string // short one-sentence description for this leaf entry
	NavParentDescription string // short one-sentence description for the parent nav group entry
	AddToNav             bool
	NavGroup             string // if non-empty, place inside this top-level group dropdown
	NavParent            string // if non-empty, nest under this parent entry within the group (or top-level)
	DataFunction         func(*http.Request) map[string]any
}

AdminWebPage describes an admin page contributed by a module.

type ModuleAPIHandler added in v0.9.8

type ModuleAPIHandler func(r *http.Request) (status int, success bool, data any)

ModuleAPIHandler is the signature for module-provided admin API handlers. The handler receives the raw *http.Request and returns:

status  - HTTP status code (e.g. 200, 400, 500)
success - written into APIResponse.Success
data    - written into APIResponse.Data (must be JSON-serialisable)

type ModuleAdminRegistrar added in v0.9.8

type ModuleAdminRegistrar interface {
	RegisterAdminPage(name, slug, htmlContent string, addToNav bool, navGroup, navParent, description, navParentDescription string, dataFunc func(*http.Request) map[string]any)
	RegisterAdminAPIEndpoint(method, slug, permissionKey string, handler func(*http.Request) (int, bool, any))
	// RegisterPermission adds a single module-contributed permission key to the
	// catalog so it appears in the admin permission picker.
	RegisterPermission(key, description, category string)
}

ModuleAdminRegistrar is implemented by internal/web and provided to plugins via SetAdminRegistrar. This breaks the import cycle between web and plugins.

type ModulePermission added in v0.9.8

type ModulePermission struct {
	Key         string
	Description string
	Category    string
}

ModulePermission describes a permission key contributed by a module.

type NetConnection

type NetConnection interface {
	IsWebSocket() bool
	Read(p []byte) (n int, err error)
	Write(p []byte) (n int, err error)
	Close()
	RemoteAddr() net.Addr
	ConnectionId() uint64
	InputDisabled(setTo ...bool) bool
}

type Plugin

type Plugin struct {
	Callbacks PluginCallbacks

	Config PluginConfig

	Web WebConfig
	// contains filtered or unexported fields
}

func New

func New(name string, version string) *Plugin

func (*Plugin) AddMobCommand

func (p *Plugin) AddMobCommand(command string, handlerFunc mobcommands.MobCommand, allowWhenDowned bool)

Registers a MobCommand and callback

func (*Plugin) AddScriptingFunction

func (p *Plugin) AddScriptingFunction(funcName string, scriptFunc any)

Registers a UserCommand and callback

func (*Plugin) AddUserCommand

func (p *Plugin) AddUserCommand(command string, handlerFunc usercommands.UserCommand, allowWhenDowned bool, isAdminOnly bool)

Registers a UserCommand and callback

func (*Plugin) AttachFileSystem

func (p *Plugin) AttachFileSystem(f embed.FS) error

Adds an embedded file system to the plugin

func (*Plugin) ExportFunction

func (p *Plugin) ExportFunction(stringId string, f any)

func (*Plugin) ReadBytes

func (p *Plugin) ReadBytes(identifier string) ([]byte, error)

func (*Plugin) ReadIntoStruct

func (p *Plugin) ReadIntoStruct(identifier string, out any) error

func (*Plugin) Requires

func (p *Plugin) Requires(modname string, modversion string)

func (*Plugin) ReserveTags added in v0.9.8

func (p *Plugin) ReserveTags(tags ...string)

ReserveTags registers room tags that this plugin recognises, so that "room tags" can list them alongside the owning module name.

func (*Plugin) WriteBytes

func (p *Plugin) WriteBytes(identifier string, bytes []byte) error

func (*Plugin) WriteStruct

func (p *Plugin) WriteStruct(identifier string, in any) error

type PluginCallbacks

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

func (*PluginCallbacks) SetIACHandler

func (c *PluginCallbacks) SetIACHandler(f func(uint64, []byte) bool)

func (*PluginCallbacks) SetOnLoad

func (c *PluginCallbacks) SetOnLoad(f func())

func (*PluginCallbacks) SetOnNetConnect

func (c *PluginCallbacks) SetOnNetConnect(f func(NetConnection))

func (*PluginCallbacks) SetOnSave

func (c *PluginCallbacks) SetOnSave(f func())

func (*PluginCallbacks) SetTextPrefixHandler added in v0.9.8

func (c *PluginCallbacks) SetTextPrefixHandler(f func(uint64, []byte) bool)

type PluginConfig

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

func (*PluginConfig) Get

func (p *PluginConfig) Get(name string) any

func (*PluginConfig) Set

func (p *PluginConfig) Set(name string, val any)

type PluginFiles

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

Implements fs.ReadFileFS

func (PluginFiles) KnownPaths added in v0.9.8

func (p PluginFiles) KnownPaths() []string

KnownPaths returns all file paths registered in this plugin's file system.

func (PluginFiles) Open

func (p PluginFiles) Open(name string) (fs.File, error)

func (PluginFiles) ReadFile

func (p PluginFiles) ReadFile(name string) ([]byte, error)

func (PluginFiles) Stat

func (p PluginFiles) Stat(name string) (fs.FileInfo, error)

type WebConfig

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

func (*WebConfig) AdminAPIEndpoint added in v0.9.8

func (w *WebConfig) AdminAPIEndpoint(method, slug string, handler ModuleAPIHandler, permissionKey ...string)

AdminAPIEndpoint registers an HTTP handler under /admin/api/v1/<slug>.

  • method - HTTP method string: "GET", "POST", "PATCH", "DELETE", etc.
  • slug - path suffix, e.g. "mudmail" -> /admin/api/v1/mudmail
  • handler - the handler function
  • permissionKey - if non-empty, the permission key required to call this endpoint. Conventionally "<module>.write" for mutating methods. Leave empty for GET (read) endpoints.

func (*WebConfig) AdminPage added in v0.9.8

func (w *WebConfig) AdminPage(name, slug, htmlFile string, addToNav bool, navGroup, navParent, description, navParentDescription string, dataFunc func(*http.Request) map[string]any)

AdminPage registers an admin-only page served under /admin/<slug>.

  • name - display label used in nav
  • slug - URL path segment, e.g. "mudmail" -> /admin/mudmail
  • htmlFile - path inside the plugin's embedded FS, relative to datafiles/html/admin/
  • addToNav - whether to add a nav entry
  • navGroup - if non-empty, places the nav entry inside a top-level group dropdown
  • navParent - if non-empty, nests the entry under this parent within the group (or top-level)
  • description - short one-sentence description for this leaf entry
  • navParentDescription - short one-sentence description for the parent nav group entry (used on first registration)
  • dataFunc - optional function to supply extra template data; receives *http.Request
func (w *WebConfig) NavLink(name string, path string)

func (*WebConfig) RegisterPermissions added in v0.9.8

func (w *WebConfig) RegisterPermissions(perms ...ModulePermission)

RegisterPermissions declares permission keys that this module contributes. Call this during module initialisation for any write permission keys used in AdminAPIEndpoint calls so they appear in the admin permission picker.

func (*WebConfig) WebPage

func (w *WebConfig) WebPage(name string, path string, file string, addToNav bool, dataFunc func(r *http.Request) map[string]any)

type WebPage

type WebPage struct {
	Name         string
	Path         string
	Filepath     string
	DataFunction func(r *http.Request) map[string]any
}

Jump to

Keyboard shortcuts

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