minetest

package
v0.0.0-...-aecff93 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

This file contains abstractions for serializing data For how data is stored, and Database access, see client_storage.go

This file contains how data is saved in the database For how data is represented while loaded see client_data.go

minetest-go is a *very* simple minetest server written in golang

Index

Constants

View Source
const (
	LowestAOID  mt.AOID = (1)
	HighestAOID mt.AOID = (65534) // one lower than largest value
)
View Source
const (
	SerializeVer     = 28
	ProtoVer         = 39
	VersionString    = "mtgo-5.4.1"
	MaxPlayerNameLen = 20
)
View Source
const AOActionTimeout time.Duration = time.Second

ao

View Source
const RelevantDistance float32 = 100 * 10 // in 10th nodes

Variables

View Source
var (
	ActiveObjectsMu sync.RWMutex
	ActiveObjects   = make(map[mt.AOID]ActiveObject)
)
View Source
var (
	ErrInvalidLocation   = errors.New("the location specified is Invalid")
	ErrInvalidStack      = errors.New("tried to interact with invalid stack")
	ErrInvalidInv        = errors.New("tried to interact with invalid inventory")
	ErrStackInsufficient = errors.New("stack quanitiy is ErrStackInsufficient")
	ErrStackNotEmpty     = errors.New("the stack interacted with is not empty")
	ErrInvalidPos        = errors.New("the position supplied is not parsable (e.g. not 3 dimensional)")
	ErrOutOfSpace        = errors.New("inventory already full")

	ErrInvalidFormspec = errors.New("formspec is not registered")

	ErrClientNotReady = errors.New("client not ready")

	ErrClientDataNil = errors.New("client data unexpectedly nil")
	ErrAOTimeout     = errors.New("ActiveObject timeout reached")
)
View Source
var ErrClientDataInvalidType = errors.New("ClientData has invalid type!")
View Source
var ErrClientDataNotFound = errors.New("ClientData not found!")
View Source
var ErrInvalidDim = errors.New("invalid dimension")
View Source
var ErrInvalidDriver = errors.New("invalid mapdriver")
View Source
var ErrInvalidGenerator = errors.New("invalid map generator")
View Source
var (
	ErrNilValue = errors.New("unexpected nil value")
)
View Source
var (
	ErrServerShuttingDown = errors.New("Server shutting down")
)
View Source
var (
	ErrUUIDFormat = errors.New("uuid not 16 bytes!")
)
View Source
var Loggers interface {
	Default(s string, depth int)
	Defaultf(s string, depth int, v ...any)

	Info(s string, depth int)
	Infof(s string, depth int, v ...any)

	Verbose(s string, depth int)
	Verbosef(s string, depth int, v ...any)

	Warn(s string, depth int)
	Warnf(s string, depth int, v ...any)

	Error(s string, depth int)
	Errorf(s string, depth int, v ...any)
	// contains filtered or unexported methods
} = logLevels{}

Functions

func Acks

func Acks(acks ...<-chan struct{}) <-chan struct{}

Combine acks into one ack Waits for all acks to close then closes ack

func AddAlias

func AddAlias(alias ...Alias)

Add a Alias to the pool pls only use while init func

func AddExpiredCondition

func AddExpiredCondition(f func(*MapBlk) bool)

add a function that is used to determin whether a blk can be unloaded all have to be false, to unload a blk its possible for a chunk to get unloaded without your function getting called, for a hook use `RegisterUnloadHook`

func AddItemDef

func AddItemDef(defs ...ItemDef)

Add more item definitions to pool

func AddMedia

func AddMedia(m ...struct{ Name, Base64SHA1 string })

Add a file to the media pool pls only use while init func

func AddMediaURL

func AddMediaURL(url ...string)

Add a file to the mediaURL pls only use while init func

func AddNodeDef

func AddNodeDef(defs ...NodeDef)

Add more item definitions to pool Param0 field is overwritten

func AnticheatPos

func AnticheatPos(clt *Client, old, new PPos, dtime time.Duration) bool

Check if NewPos is valid

func Broadcast

func Broadcast(cmd mt.Cmd) []<-chan struct{}

func BroadcastAOMsgs

func BroadcastAOMsgs(ao ActiveObject, msgs ...mt.AOMsg) (<-chan struct{}, error)

func BroadcastClientM

func BroadcastClientM(s map[*Client]struct{}, cmd mt.Cmd) <-chan struct{}

BroadcastClientM broadcasts a mt.Cmd to a client slice

func BroadcastClientS

func BroadcastClientS(s []*Client, cmd mt.Cmd) <-chan struct{}

BroadcastClientS broadcasts a mt.Cmd to a client slice

func Caller

func Caller(i int) string

Returns file:line of caller at i with 0 identifying the caller of Path

func CleanCache

func CleanCache()

CleanCache cleans the cache of expired blks

func CltLeave

func CltLeave(l *Leave) (ack <-chan struct{}, err error)

func Clts

func Clts() map[*Client]struct{}

func ConfigVerbose

func ConfigVerbose() bool

ConfigVerbose is a helper function to indicate if verbose logging is turned on

func Cos32

func Cos32(x float32) float32

func DB_PlayerDelData

func DB_PlayerDelData(uuid UUID, name string) (err error)

PlayerDelData removes a data field

func DB_PlayerGetByUUID

func DB_PlayerGetByUUID(uuid UUID) (name string, err error)

PlayerGetByUUID returns the name corosponding to a given UUID

func DB_PlayerGetData

func DB_PlayerGetData(uuid UUID) (cd map[string]ClientData, bytes int, err error)

PlayerGetData returns all client data of a given UUID

func DB_PlayerSet

func DB_PlayerSet(uuid UUID, name string) (err error)

PlayerPut updates a players name / adds a player

func DB_PlayerSetData

func DB_PlayerSetData(uuid UUID, name string, data []byte) (err error)

PlayerSetData adds or updates some datafiled for a given UUID

func DefaultMapLoader

func DefaultMapLoader() string

func Deserialize

func Deserialize(r io.Reader, d interface{}) error

func Distance

func Distance(a, b [3]float32) float32

func Fields2map

func Fields2map(s []mt.NodeMetaField) map[string]mt.NodeMetaField

func ForInConfig

func ForInConfig(f func(k string, v any) error) (err error)

ForInConfig executes f `for k, v := range config` if any call of f results in a err != nil, err is returned

func GetConfig

func GetConfig[K any](key string, d K) (val K, ok bool)

Returns value which is is the config field if set or d if not ok is set if the config field existed

func GetConfigV

func GetConfigV[K any](key string, d K) (val K)

Like GetConfig but does not return ok

func GetNode

func GetNode(p IntPos) (node mt.Node, meta *mt.NodeMeta)

GetNode returns a mt.Node and NodeMeta for a coordinate If no NodeMeta is specified returns mt.Node and nil

func GetNodeID

func GetNodeID(name string) mt.Content

GetNodeID returns the Param0 of a node panics if not found

func GetPAOID

func GetPAOID(clt *Client) mt.AOID

func Give

func Give(c *Client, inv *InvLocation, cnt uint16, itm string) (uint16, <-chan struct{}, error)

Give adds cnt itms to inv as seen out of cs view. If InvLocation.Stack is <0 the function will try to figure out a free slot Returns the about of items added and any given error

func GroupCapsS2ToolGroupCapM

func GroupCapsS2ToolGroupCapM(s []mt.ToolGroupCap) (m map[string]ToolGroupCap)

func GroupsS2GroupsM

func GroupsS2GroupsM(groups []mt.Group) (m map[string]int16)

func HasAO

func HasAO(clt *Client, ao mt.AOID) bool

func IDAOMsgs

func IDAOMsgs(id mt.AOID, msgs ...mt.AOMsg) (s []mt.IDAOMsg)

func InitClient

func InitClient(c *Client)

func IsCached

func IsCached(pos IntPos) bool

IsCached returns true if there is a valid cache for pos p

func ListAOs

func ListAOs() map[mt.AOID]ActiveObject

func ListDrivers

func ListDrivers() (s []string)

func LoadBlk

func LoadBlk(clt *Client, p IntPos) <-chan struct{}

LoadBlk sends a blk and marks it as send only sends updates after that until client send DeletedBlks

func LoadConfig

func LoadConfig()

LoadConfig ensures the config is loaded

func Map2Slice

func Map2Slice[V comparable](m map[V]struct{}) []V

func MaxSpeed

func MaxSpeed(clt *Client) float32

Returns distance in 10th nodes speed is < 0, no max speed

func MustGetConfig

func MustGetConfig(key string) any

func NRGBA

func NRGBA(c color.Color) color.NRGBA

Converts Color to NRGBA

func NodeMaps

func NodeMaps() (NodeIdMap map[mt.Content]string, IdNodeMap map[string]mt.Content)

NodeMaps generates a NodeIdMap and IdNodeMap

func NodeMetasEqual

func NodeMetasEqual(m1, m2 *mt.NodeMeta) bool

func Path

func Path(path string) string

gets path relative to executable

func PlayerExists

func PlayerExists(name string) bool

func ReadInt

func ReadInt(r io.Reader, colon bool) (i int)

func ReadString

func ReadString(r io.Reader, colon bool) (str string)

Reads space or colon speperated strings from io.Reader

func ReadUint16

func ReadUint16(r io.Reader, colon bool) (i uint16)

Reads space speperated uint16 from io.Reader

func RealNodeName

func RealNodeName(name string) string

RealNodeName returns the underlying name of a given node checks aliases map if !ok returns name

func RegisterAO

func RegisterAO(ao ActiveObject) mt.AOID

RegisterAO registers the ActiveObject

func RegisterDetached

func RegisterDetached(name string, inv *DetachedInv)

func RegisterMapDriver

func RegisterMapDriver(name string, driver MapDriver)

func RegisterMapGenerator

func RegisterMapGenerator(name string, gen MapGenerator)

RegisterMapGenerator `gen` for `name` overwrites if allready exists

func RegisterMapLoader

func RegisterMapLoader(name string, loader MapLoader)

func RegisterPlayer

func RegisterPlayer(c *Client)

RegisterPlayer as active

func RegisterPlayerMaker

func RegisterPlayerMaker(name string, mk PlayerAOMaker)

func RegisterStage1

func RegisterStage1(f func())

func RegisterStage2

func RegisterStage2(f func())

func Relevant

func Relevant(ao ActiveObject, clt *Client) bool

func ReloadConfig

func ReloadConfig()

ReloadConfig reloads the config and triggers Config Reload hooks may break some modules

func RmAO

func RmAO(id mt.AOID) bool

RmAO removes AO after calling Clean on AO Returns false when ao was not registerd

func Round32

func Round32(x float32) float32

func RoundToEven32

func RoundToEven32(x float32) float32

func Run

func Run()

Starts the server

func SCaller

func SCaller(i int) string

func SaveCache

func SaveCache()

func SerializeString

func SerializeString(s func(io.Writer) error) (string, error)

func SetNode

func SetNode(p IntPos, node mt.Node, meta *mt.NodeMeta)

SetNode sets a mt.Node and NodeMeta for a coordinate If no NodeMeta is specified it WILL be overwritten

func SimpleInvFromNamedInvList

func SimpleInvFromNamedInvList(list mt.Inv, inv *SimpleInv)

func Sin32

func Sin32(x float32) float32

func Sqrt32

func Sqrt32(x float32) float32

func Stage1

func Stage1()

func Stage2

func Stage2()

func SyncPlayerData

func SyncPlayerData(c *Client)

SyncPlayerData, syncronizes all data for a given client

func T

func T[K any](c bool, t, f K) K

func TestSpec

func TestSpec() string

func TextureS2StringS

func TextureS2StringS(s []Texture) (r []string)

Converts a Texture slice to a string slice

func TextureStr

func TextureStr(t Texture) mt.Texture

func TimesS2TimesM

func TimesS2TimesM(s []mt.DigTime) (m map[int16]float32)

func TryCache

func TryCache(pos IntPos) error

TryCache caches if mapblk is either not cached already if cache is still valid, does nothing Refreshes Loaded.

func Update

func Update(inv RWInv, loc *InvLocation, c *Client) (<-chan struct{}, error)

func UseItem

func UseItem(inv RWInv, name string, slot int, i int) bool

Types

type ALH

type ALH func(IntPos, *MapBlk)

map after load hooks

type AOData

type AOData struct {
	sync.RWMutex

	Ready bool

	AOs map[mt.AOID]struct{}

	//is the clients AOID (client self does not have)
	AOID      mt.AOID
	SelfProps mt.AOProps // contains AOInit send to self (for future reference)

	Age time.Time
}

type AOInit

type AOInit struct {
	Name     string
	IsPlayer bool

	AOPos

	HP uint16

	AOMsgs []mt.AOMsg
}

func (*AOInit) AOInitData

func (i *AOInit) AOInitData(id mt.AOID) mt.AOInitData

type AOPos

type AOPos struct {
	Pos [3]float32
	Rot [3]float32

	Dim DimID
}

func (AOPos) AOPos

func (aopos AOPos) AOPos() (pos mt.AOPos)

type ActiveObject

type ActiveObject interface {
	//SetAO should set the AOID
	SetAO(mt.AOID)

	//GetAO should return the ID
	//0 when none is defined
	GetAO() mt.AOID

	//AOInit should return Initialisation data for the AO
	AOInit(*Client) *AOInit

	Punch(clt *Client, i *mt.ToSrvInteract)

	//is called when removing AO
	Clean()
}

ActiveObject

func GetAO

func GetAO(id mt.AOID) ActiveObject

type ActiveObjectAPIAOPos

type ActiveObjectAPIAOPos interface {
	ActiveObject

	//GetPos should return the position
	GetAOPos() AOPos
	SetAOPos(AOPos)
}

ActiveObjectAPIAOPos specifies a standard interface to work with Positions of AOs

type ActiveObjectPlayer

type ActiveObjectPlayer interface {
	ActiveObject

	//GetPos should return the position
	GetPos() PPos
	SetPos(PPos)
}

ActiveObjectPlayer specifies a client ActiveObject

func GetPAO

func GetPAO(clt *Client) ActiveObjectPlayer

GetPAO returns the ActiveObject representing clt.

type ActiveObjectRelevant

type ActiveObjectRelevant interface {
	ActiveObject

	// Tick gets called when client is evaluating relevante of AO
	// true: relevant and will be added; false: won't
	Relevant(c *Client) bool
}

ActiveObjectRelevant extends the ActiveObject to optionally overwrite the Relevance functions

type ActiveObjectTicker

type ActiveObjectTicker interface {
	ActiveObject

	// Tick gets called each PhysTick
	Tick(dtime time.Duration)
}

ActiveObjectTicker extends the ActiveObject to optional Ticked callbacks

type Alias

type Alias struct{ Alias, Orig string }

type BlamedErr

type BlamedErr struct {
	Err   error
	Cause string
}

func (*BlamedErr) Error

func (err *BlamedErr) Error() string

type Client

type Client struct {
	mt.Peer
	sync.RWMutex

	UUID UUID
	Name string

	State ClientState

	Pos      *ClientPos
	PosState sync.RWMutex

	//active Object stuffs (conains own mutex)
	AOData *AOData
	// contains filtered or unexported fields
}

A Client represents a client

func PlayerByName

func PlayerByName(name string) *Client

func (*Client) DelData

func (c *Client) DelData(field string) (found bool)

func (*Client) DigPos

func (c *Client) DigPos() (*IntPos, time.Time)

Returns nil if *Client is not digging

func (*Client) Fatalf

func (c *Client) Fatalf(str string, v ...any) (ack <-chan struct{}, err error)

like log.Fatalf but does not panic but kick Client with specified Message

func (*Client) GetData

func (c *Client) GetData(field string) (cd ClientData, ok bool)

func (*Client) GetFullPos

func (c *Client) GetFullPos() *ClientPos

GetFullPos returns pos of player / client

func (*Client) GetMapLoader

func (c *Client) GetMapLoader() *Registerd[*Registerd[MapLoader]]

func (*Client) GetPos

func (c *Client) GetPos() PPos

func (*Client) GetSpec

func (c *Client) GetSpec(name string) (spec *Formspec)

Returns formspec if registerd returns nil if not

func (*Client) Init

func (c *Client) Init() <-chan struct{}

func (*Client) IsDigging

func (c *Client) IsDigging() bool

func (*Client) Kick

func (c *Client) Kick(r mt.KickReason, Custom string) (ack <-chan struct{}, err error)

func (*Client) Log

func (c *Client) Log(v ...any)

Inserts space between each v (even if both are strings)

func (*Client) Logf

func (c *Client) Logf(format string, v ...any)

func (*Client) MapLoad

func (c *Client) MapLoad() bool

func (*Client) PRoD

func (c *Client) PRoD(pr float32) float32

PointRange or Default Returns pr if pr >= 0 && pr >= default else default

func (*Client) PointRange

func (c *Client) PointRange() float32

func (*Client) RegisterFormspec

func (c *Client) RegisterFormspec(spec *Formspec)

func (*Client) SendAnnounceMedia

func (c *Client) SendAnnounceMedia()

Send (cached) AnnounceMedia to client

func (*Client) SendCmd

func (c *Client) SendCmd(cmd mt.Cmd) (ack <-chan struct{}, err error)

func (*Client) SendItemDefs

func (c *Client) SendItemDefs() (<-chan struct{}, error)

Send (cached) ItemDefinitions to client

func (*Client) SendNodeDefs

func (c *Client) SendNodeDefs() (<-chan struct{}, error)

Send (cached) NodeDefinitions to client

func (*Client) SetData

func (c *Client) SetData(field string, value ClientData) (overwrote bool)

func (*Client) SetMapLoader

func (c *Client) SetMapLoader(loader *Registerd[MapLoader])

func (*Client) SetState

func (c *Client) SetState(state ClientState)

func (*Client) ShowSpec

func (c *Client) ShowSpec(spec *Formspec) (<-chan struct{}, error)

name is name of registerd FormspecDef returns ErrInvalidFormspec if formspec is not registered

func (*Client) ShowSpecf

func (c *Client) ShowSpecf(rspec *Formspec, v ...any) (<-chan struct{}, error)

func (*Client) String

func (c *Client) String() string

type ClientData

type ClientData interface {
}

type ClientDataSaved

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

The raw data loaded from the Database implements ClientData

func (*ClientDataSaved) Bytes

func (cd *ClientDataSaved) Bytes() (b []byte)

func (*ClientDataSaved) Desc

func (cd *ClientDataSaved) Desc() string

func (*ClientDataSaved) Serialize

func (cd *ClientDataSaved) Serialize(w io.Writer) (err error)

type ClientDataSerialize

type ClientDataSerialize interface {
	ClientData

	// Serialize should serialize ClientData into some kind of format
	// Binary is prefered as its more space efficient
	Serialize(w io.Writer) (err error)
}

If a ClientDataSerialize is used as ClientData it will be serialized and saved in the players table

type ClientDataString

type ClientDataString struct {
	String string
}

func TryClientDataString

func TryClientDataString(c *Client, f string) *ClientDataString

func (*ClientDataString) Desc

func (cd *ClientDataString) Desc() string

func (*ClientDataString) Serialize

func (cd *ClientDataString) Serialize(w io.Writer) (err error)

type ClientPos

type ClientPos struct {
	sync.RWMutex

	CurPos     PPos
	OldPos     PPos
	LastUpdate time.Time
}

func MakePos

func MakePos(c *Client) *ClientPos

func (*ClientPos) Copy

func (cp *ClientPos) Copy() ClientPos

func (*ClientPos) Deserialize

func (cp *ClientPos) Deserialize(w io.Reader) (err error)

func (*ClientPos) Serialize

func (cp *ClientPos) Serialize(w io.Writer) (err error)

type ClientState

type ClientState uint8
const (
	CsCreated ClientState = iota
	CsInit
	CsActive
	CsSudo
)

type CraftItem

type CraftItem struct {
	Item
}

func (*CraftItem) ItemDef

func (itm *CraftItem) ItemDef() mt.ItemDef

func (*CraftItem) Name

func (itm *CraftItem) Name() string

func (*CraftItem) OnActivate

func (itm *CraftItem) OnActivate(c *Client, s mt.Stack, a *mt.ToSrvInteract) mt.Stack

func (*CraftItem) OnMove

func (itm *CraftItem) OnMove(c *Client, s mt.Stack, a *InvAction) mt.Stack

func (*CraftItem) OnPlace

func (itm *CraftItem) OnPlace(c *Client, s mt.Stack, a *mt.ToSrvInteract) mt.Stack

func (*CraftItem) OnUse

func (itm *CraftItem) OnUse(c *Client, s mt.Stack, a *mt.ToSrvInteract) mt.Stack

type DetachedInv

type DetachedInv struct {
	SimpleInv
	Name string

	// List of clients suppost to have access
	ClientsMu sync.RWMutex
	Clients   map[*Client]struct{}
}

func (*DetachedInv) AddClient

func (di *DetachedInv) AddClient(c *Client) (<-chan struct{}, error)

func (*DetachedInv) RmClient

func (di *DetachedInv) RmClient(c *Client)

func (*DetachedInv) SendUpdates

func (di *DetachedInv) SendUpdates() (<-chan struct{}, error)

func (*DetachedInv) Set

func (di *DetachedInv) Set(k string, v InvList)

type DigCond

type DigCond func(*Client, *mt.ToSrvInteract, time.Duration) bool

type DimID

type DimID uint16

func RegisterDim

func RegisterDim(d *Dimension) (DimID, error)

RegisterDim registers a new Dimension Id will be generated by NewDim if id == 0; returns id

func (DimID) Lookup

func (d DimID) Lookup() *Dimension

func (DimID) String

func (d DimID) String() string

type Dimension

type Dimension struct {
	sync.RWMutex

	Driver    MapDriver
	Generator MapGenerator
	Name      string
	ID        DimID
}

func GetDim

func GetDim(name string) *Dimension

returns dim corosponding to name returns nil if Dim does not exist

func NewDim

func NewDim(name, gen, genargs, drv, file string) (*Dimension, error)

NewDim creates a new Dimension and registers it

type DropHook

type DropHook func(clt *Client, stack mt.Stack, act *InvActionDrop) mt.Stack

type ErrInvalidInvAction

type ErrInvalidInvAction struct {
	Action string
}

func (*ErrInvalidInvAction) Error

func (err *ErrInvalidInvAction) Error() string

type FormSpecSubmitFunc

type FormSpecSubmitFunc func(c *Client, values map[string]string, edittime time.Duration, closed bool)

type Formspec

type Formspec struct {
	Name   string
	Spec   string
	Submit FormSpecSubmitFunc
}

type HookRef

type HookRef[H any] struct {
	// contains filtered or unexported fields
}

func RegisterALH

func RegisterALH(h ALH) HookRef[Registerd[ALH]]

func RegisterDigCond

func RegisterDigCond(h DigCond) HookRef[Registerd[DigCond]]

DigCond gets called before Place is acted upon If returns false doesn't place node (NodeDef.OnDig not called) Gets called BEFORE NodeDef.OnPlace

func RegisterDropHook

func RegisterDropHook(h DropHook) HookRef[Registerd[DropHook]]

func RegisterInitHook

func RegisterInitHook(h InitHook) HookRef[Registerd[InitHook]]

Gets called as soon as client authentication is successfull

func RegisterJoinHook

func RegisterJoinHook(h JoinHook) HookRef[Registerd[JoinHook]]

Gets called after client is initialized After player is given controll

func RegisterLeaveHook

func RegisterLeaveHook(h LeaveHook) HookRef[Registerd[LeaveHook]]

Gets called after client has left (*Client struct still exists)

func RegisterPacketPre

func RegisterPacketPre(h PacketPre) HookRef[Registerd[PacketPre]]

Gets called before packet reaches Processors If (one) func returns false packet is dropped

func RegisterPhysTickHook

func RegisterPhysTickHook(h PhysHook) HookRef[Registerd[PhysHook]]

Gets called each tick dtime is time since last tick

func RegisterPktProcessor

func RegisterPktProcessor(h PktProcessor) HookRef[Registerd[PktProcessor]]

Gets called for each packet received; as long as clt is initialized

func RegisterPktTickHook

func RegisterPktTickHook(h PktTickHook) HookRef[Registerd[PktTickHook]]

Gets called at end of each tick If you can, send packets in here

func RegisterPlaceCond

func RegisterPlaceCond(h PlaceCond) HookRef[Registerd[PlaceCond]]

PlaceCond gets called before Place is acted upon If returns false doesn't place node (ItemDef.OnPlace not called) Gets called BEFORE NodeDef.OnPlace

func RegisterPosUpdater

func RegisterPosUpdater(pu PosUpdater) HookRef[Registerd[PosUpdater]]

PosUpdater is called with a UNLOCKED ClientPos

func RegisterRawPktProcessor

func RegisterRawPktProcessor(h RawPktProcessor) HookRef[Registerd[RawPktProcessor]]

Gets called for each packet received; even for uninitialized clients

func RegisterRegisterHook

func RegisterRegisterHook(h RegisterHook) HookRef[Registerd[RegisterHook]]

Gets called at registrationtime intended to initialize client data

func RegisterSaveFileHook

func RegisterSaveFileHook(h SaveFileHook) HookRef[Registerd[SaveFileHook]]

func RegisterShutdownHook

func RegisterShutdownHook(h ShutdownHook) HookRef[Registerd[ShutdownHook]]

Gets called when server shuts down NOTE: (Leave hooks also get called)

func RegisterTickHook

func RegisterTickHook(h func()) HookRef[Registerd[TickHook]]

Gets called each tick

func (*HookRef[H]) Stop

func (hr *HookRef[H]) Stop()

Remove HookRef from Hooks

type InitHook

type InitHook func(*Client)

type IntPos

type IntPos struct {
	Pos [3]int16
	Dim DimID
}

func Blkpos2Pos

func Blkpos2Pos(p IntPos, i uint16) (ni IntPos)

func Pos2Blkpos

func Pos2Blkpos(p IntPos) (ni IntPos, i uint16)

func (IntPos) String

func (p IntPos) String() string

type Inv

type Inv interface {
	Get(string) (InvList, bool)
	Set(string, InvList)

	Serialize(io.Writer) error
}

type InvAction

type InvAction interface {
	InvActionVerb() string
	Apply(c *Client) (<-chan struct{}, error)

	String() string // String does NOT searialize
}

func DeserializeInvAction

func DeserializeInvAction(r io.Reader) (act InvAction, err error)

type InvActionDrop

type InvActionDrop struct {
	Count uint16

	From *InvLocation
}

func (*InvActionDrop) Apply

func (act *InvActionDrop) Apply(c *Client) (_ <-chan struct{}, err error)

func (*InvActionDrop) Deserialize

func (act *InvActionDrop) Deserialize(r io.Reader)

func (*InvActionDrop) InvActionVerb

func (*InvActionDrop) InvActionVerb() string

func (*InvActionDrop) String

func (act *InvActionDrop) String() string

type InvActionMove

type InvActionMove struct {
	Count uint16

	From *InvLocation
	To   *InvLocation
}

func (*InvActionMove) Apply

func (act *InvActionMove) Apply(c *Client) (_ <-chan struct{}, err error)

func (*InvActionMove) Deserialize

func (act *InvActionMove) Deserialize(r io.Reader)

func (*InvActionMove) InvActionVerb

func (*InvActionMove) InvActionVerb() string

---

func (*InvActionMove) String

func (act *InvActionMove) String() string

type InvIdentifier

type InvIdentifier interface {
	InvIdentifier() string

	Equals(InvIdentifier) bool
}

type InvIdentifierCurrentPlayer

type InvIdentifierCurrentPlayer struct{}

func (*InvIdentifierCurrentPlayer) Deserialize

func (*InvIdentifierCurrentPlayer) Deserialize(io.Reader)

InvIdentifierCurrentPlayer

func (*InvIdentifierCurrentPlayer) Equals

func (*InvIdentifierCurrentPlayer) InvIdentifier

func (*InvIdentifierCurrentPlayer) InvIdentifier() string

type InvIdentifierDetached

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

InvIdentifierDetached

func (*InvIdentifierDetached) Deserialize

func (i *InvIdentifierDetached) Deserialize(r io.Reader)

func (*InvIdentifierDetached) Equals

func (*InvIdentifierDetached) InvIdentifier

func (*InvIdentifierDetached) InvIdentifier() string

type InvIdentifierNodeMeta

type InvIdentifierNodeMeta struct {
	X, Y, Z int16
}

InvIdentifierNodeMeta

func (*InvIdentifierNodeMeta) Deserialize

func (i *InvIdentifierNodeMeta) Deserialize(r io.Reader)

func (*InvIdentifierNodeMeta) Equals

func (self *InvIdentifierNodeMeta) Equals(to InvIdentifier) bool

func (*InvIdentifierNodeMeta) InvIdentifier

func (*InvIdentifierNodeMeta) InvIdentifier() string

type InvIdentifierPlayer

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

InvIdentifierPlayer

func (*InvIdentifierPlayer) Deserialize

func (i *InvIdentifierPlayer) Deserialize(r io.Reader)

func (*InvIdentifierPlayer) Equals

func (self *InvIdentifierPlayer) Equals(to InvIdentifier) bool

func (*InvIdentifierPlayer) InvIdentifier

func (*InvIdentifierPlayer) InvIdentifier() string

type InvIdentifierUndefined

type InvIdentifierUndefined struct{}

InvIdentifierUndefined

func (*InvIdentifierUndefined) Deserialize

func (*InvIdentifierUndefined) Deserialize(io.Reader)

func (*InvIdentifierUndefined) Equals

undefined is like NaN not itsel

func (*InvIdentifierUndefined) InvIdentifier

func (*InvIdentifierUndefined) InvIdentifier() string

type InvList

type InvList interface {
	Width() int
	GetStack(int) (mt.Stack, bool)
	SetStack(int, mt.Stack) bool

	Serialize(io.Writer) error

	InvList() mt.InvList
}

type InvLocation

type InvLocation struct {
	Identifier InvIdentifier
	Name       string
	Stack      int
}

InvLocation

func ParseInvLocation

func ParseInvLocation(str string) *InvLocation

func (*InvLocation) Aquire

func (l *InvLocation) Aquire(c *Client) (RWInv, error)

func (*InvLocation) Deserialize

func (l *InvLocation) Deserialize(r io.Reader)

func (*InvLocation) SendUpdate

func (l *InvLocation) SendUpdate(list string, c *Client) (<-chan struct{}, error)

type Item

type Item struct {
	Type ItemType

	Name      string
	Desc      string
	ShortDesc string

	StackMax uint16

	Usable          bool
	CanPointLiquids bool

	Groups map[string]int16

	PointRange float32

	Textures ItemTextures
}

func (*Item) ItemDef

func (itm *Item) ItemDef() mt.ItemDef

returns partial mt.ItemDef

func (*Item) MtGroups

func (itm *Item) MtGroups() (s []mt.Group)

type ItemActivateFunc

type ItemActivateFunc func(*Client, Inv, *mt.ToSrvInteract)

type ItemDef

type ItemDef interface {
	ItemDef() mt.ItemDef
	Name() string

	//returned mt.Stack will overwrite old
	OnMove(*Client, mt.Stack, *InvAction) mt.Stack
	OnPlace(*Client, mt.Stack, *mt.ToSrvInteract) mt.Stack
	OnUse(*Client, mt.Stack, *mt.ToSrvInteract) mt.Stack
	OnActivate(*Client, mt.Stack, *mt.ToSrvInteract) mt.Stack
}

func TryItemDef

func TryItemDef(def mt.ItemDef) (rdef ItemDef, ok bool)

Trys to create ItemDef from mt.ItemDef

type ItemMoveFunc

type ItemMoveFunc func(*Client, Inv, *InvAction)

type ItemPlaceFunc

type ItemPlaceFunc func(*Client, Inv, *mt.ToSrvInteract)

type ItemTextures

type ItemTextures struct {
	InvImg     Texture
	InvOverlay Texture

	WieldImg     Texture
	WieldOverlay Texture

	Palette Texture // TODO: why? and what does?
	Color   color.NRGBA

	WieldScale [3]float32
}

type ItemType

type ItemType uint8

Do not confuse with mt.ItemType

const (
	TypeNodeItem       ItemType = iota
	TypeSimpleNodeItem          //TODO
	TypeCraftItem
	TypeToolItem

	TypeInvalid = 255
)

func Mt2ItemType

func Mt2ItemType(t mt.ItemType) ItemType

Mapps mt.ItemTypes to ItemTypes

func (ItemType) MtItemType

func (t ItemType) MtItemType() mt.ItemType

func (ItemType) String

func (i ItemType) String() string

type ItemUseFunc

type ItemUseFunc func(*Client, Inv, *mt.ToSrvInteract)

type JoinHook

type JoinHook func(*Client)

type Leave

type Leave struct {
	Reason      mt.KickReason
	Custom      string
	AbstrReason Reason

	Client *Client
}

type LeaveHook

type LeaveHook func(*Leave)

type MapBlk

type MapBlk struct {
	MapBlk mt.MapBlk
	Pos    [3]int16

	Driver MapDriver

	sync.RWMutex

	ForceLoaded bool      // if set the default func for cleanup block won't be unloaded
	Loaded      time.Time // timestamp when blk was loaded (unixmillis)
	LastAccess  time.Time // timestamp when blk was last Accessed (unixmillis)
	LastSeen    time.Time // timestamp when client was in blk for the last time (unixmillis)
	LastRefresh time.Time // timestamp when blk was last manualy refreshed (unixmillis)
	// contains filtered or unexported fields
}

func GetBlk

func GetBlk(p IntPos) *MapBlk

GetBlk returns a pointer to block at a BlkPos

func (*MapBlk) IsLoadedBy

func (blk *MapBlk) IsLoadedBy(c *Client) bool

func (*MapBlk) Save

func (blk *MapBlk) Save() error

type MapDriver

type MapDriver interface {
	Make() MapDriver // create new instance of MapDriver

	Open(string) error

	GetBlk([3]int16) (*MapBlk, error)
	SetBlk(*MapBlk) error
}

type MapGenerator

type MapGenerator interface {
	Make(drv MapDriver, args string) MapGenerator

	// Generate is called with a BlkPos
	// Should save generated Blk into MapDriver
	Generate([3]int16) (*MapBlk, error)
}

MapGenerator specifies the API a MapGen has to use has access to mapdriver can but should (in most cases) not set blocks its not asked to

type MapLoader

type MapLoader interface {
	Make(*Client) MapLoader

	Load()
}

type MultiError

type MultiError struct {
	Errs []error
}

func (*MultiError) Add

func (merr *MultiError) Add(err error)

func (*MultiError) Error

func (err *MultiError) Error() string

type NodeDef

type NodeDef struct {
	mt.NodeDef

	OnDig         NodeDigFunc
	OnStopDigging NodeStopDiggingFunc
	OnDug         NodeDugFunc
}

type NodeDigFunc

type NodeDigFunc func(c *Client, i *mt.ToSrvInteract, digtime <-chan time.Duration)

type NodeDugFunc

type NodeDugFunc func(c *Client, i *mt.ToSrvInteract, digtime time.Duration)

type NodeItem

type NodeItem struct {
	Item

	Places string

	PlaceSnd, PlaceFailSnd SoundDef
}

NodeItem specifies a item that will palce NoteItem.Places

func (*NodeItem) ItemDef

func (itm *NodeItem) ItemDef() mt.ItemDef

func (*NodeItem) Name

func (itm *NodeItem) Name() string

func (*NodeItem) OnActivate

func (itm *NodeItem) OnActivate(c *Client, s mt.Stack, a *mt.ToSrvInteract) mt.Stack

func (*NodeItem) OnMove

func (itm *NodeItem) OnMove(c *Client, s mt.Stack, a *InvAction) mt.Stack

func (*NodeItem) OnPlace

func (itm *NodeItem) OnPlace(c *Client, s mt.Stack, i *mt.ToSrvInteract) mt.Stack

func (*NodeItem) OnUse

func (itm *NodeItem) OnUse(c *Client, s mt.Stack, a *mt.ToSrvInteract) mt.Stack

type NodeStopDiggingFunc

type NodeStopDiggingFunc func(c *Client, i *mt.ToSrvInteract, digtime time.Duration)

type PPos

type PPos struct {
	Pos

	FOV80 uint8
}

PPos defines a PlayerPosition

func PlayerPos2PPos

func PlayerPos2PPos(pos mt.PlayerPos, d DimID) PPos

func SetPos

func SetPos(c *Client, p PPos, send bool) PPos

SetPos sets position returns old position

func (PPos) AOPos

func (ppos PPos) AOPos() AOPos

func (PPos) PlayerPos

func (p PPos) PlayerPos() mt.PlayerPos

func (PPos) String

func (p PPos) String() string

type PacketPre

type PacketPre func(*Client, mt.Cmd) bool

type PhysHook

type PhysHook func(dtime float32)

type PktProcessor

type PktProcessor func(*Client, *mt.Pkt)

type PktTickHook

type PktTickHook func()

type PlaceCond

type PlaceCond func(*Client, *mt.ToSrvInteract) bool

type PlayerAOMaker

type PlayerAOMaker func(clt *Client, id mt.AOID) ActiveObject

func GetPlayerAOmaker

func GetPlayerAOmaker(clt *Client) (PlayerAOMaker, string)

type Pos

type Pos struct {
	Pos, Vel   [3]float32
	Pitch, Yaw float32

	Dim DimID
}

func (Pos) Int

func (p Pos) Int() (i [3]int16)

func (Pos) IntPos

func (p Pos) IntPos() IntPos

func (Pos) Pitch100

func (p Pos) Pitch100() (i int32)

func (Pos) Pos100

func (p Pos) Pos100() (i [3]int32)

func (Pos) String

func (p Pos) String() string

func (Pos) Vel100

func (p Pos) Vel100() (i [3]int32)

func (Pos) Yaw100

func (p Pos) Yaw100() (i int32)

type PosUpdater

type PosUpdater func(c *Client, pos *ClientPos, lu time.Duration)

type RWInv

type RWInv interface {
	Inv

	RLock()
	RUnlock()
	Lock()
	Unlock()
}

type RawPktProcessor

type RawPktProcessor func(*Client, *mt.Pkt)

type Reason

type Reason uint8
const (
	Kick Reason = iota
	Timeout
	Exit
	NetErr
)

type RegisterHook

type RegisterHook func(*Client)

type Registerd

type Registerd[T any] struct {
	Thing T
	// contains filtered or unexported fields
}

func GetDetached

func GetDetached(name string, c *Client) (inv *Registerd[*DetachedInv], err error)

func GetItemDef

func GetItemDef(name string) (def *Registerd[ItemDef])

GetItemDef returns pointer to ItemDef if registerd

func GetMapLoader

func GetMapLoader(name string) *Registerd[MapLoader]

func GetNodeDef

func GetNodeDef(name string) (def *Registerd[NodeDef])

GetNodeDef returns pointer to node def if registerd otherwise nil

func GetNodeDefID

func GetNodeDefID(id mt.Content) (def *Registerd[NodeDef])

GetNodeID returns pointer to node def if registerd otherwise nil

func (Registerd[T]) Blame

func (r Registerd[T]) Blame(err error) error

func (Registerd[T]) Path

func (r Registerd[T]) Path() string

type SaveFileHook

type SaveFileHook func()

type SerializationError

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

type ServerState

type ServerState uint8
const (
	StateInitializing ServerState = iota
	StateOnline
	StateShuttingDown
	StateOffline // only reached when saving
)

func State

func State() ServerState

type ShutdownHook

type ShutdownHook func()

type SimpleInv

type SimpleInv struct {
	M map[string]InvList

	sync.RWMutex
}

func GetInv

func GetInv(c *Client) (inv *SimpleInv, err error)

func (*SimpleInv) Deserialize

func (inv *SimpleInv) Deserialize(w io.Reader) (err error)

func (*SimpleInv) Get

func (si *SimpleInv) Get(k string) (l InvList, ok bool)

func (*SimpleInv) Inv

func (inv *SimpleInv) Inv() (r mt.Inv)

func (*SimpleInv) Serialize

func (si *SimpleInv) Serialize(w io.Writer) error

func (*SimpleInv) Set

func (si *SimpleInv) Set(k string, v InvList)

type SimpleInvList

type SimpleInvList struct {
	List mt.InvList
}

func (*SimpleInvList) GetStack

func (il *SimpleInvList) GetStack(i int) (s mt.Stack, ok bool)

func (*SimpleInvList) InvList

func (il *SimpleInvList) InvList() mt.InvList

func (*SimpleInvList) Serialize

func (il *SimpleInvList) Serialize(w io.Writer) error

func (*SimpleInvList) SetStack

func (il *SimpleInvList) SetStack(i int, s mt.Stack) bool

func (*SimpleInvList) Width

func (il *SimpleInvList) Width() int

type SoundDef

type SoundDef mt.SoundDef

type StrTexture

type StrTexture mt.Texture

func (StrTexture) Texture

func (str StrTexture) Texture() string

type Texture

type Texture interface {
	// should return string representation of texture
	Texture() string
}

type TextureOverlay

type TextureOverlay struct {
	Textures []Texture
}

func (TextureOverlay) Texture

func (o TextureOverlay) Texture() string

type TickHook

type TickHook func()

type ToolGroupCap

type ToolGroupCap struct {
	Uses int32

	MaxLvl int16

	Times map[int16]float32
}

func (ToolGroupCap) MtDigTimes

func (caps ToolGroupCap) MtDigTimes() (s []mt.DigTime)

type ToolItem

type ToolItem struct {
	Item

	AttackCooldown float32
	MaxDropLvl     int16 //TODO: figure out

	GroupCaps map[string]ToolGroupCap
}

func (*ToolItem) ItemDef

func (itm *ToolItem) ItemDef() mt.ItemDef

func (*ToolItem) MtGroupCaps

func (itm *ToolItem) MtGroupCaps() (s []mt.ToolGroupCap)

func (*ToolItem) Name

func (itm *ToolItem) Name() string

func (*ToolItem) OnActivate

func (itm *ToolItem) OnActivate(c *Client, s mt.Stack, a *mt.ToSrvInteract) mt.Stack

func (*ToolItem) OnMove

func (itm *ToolItem) OnMove(c *Client, s mt.Stack, a *InvAction) mt.Stack

func (*ToolItem) OnPlace

func (itm *ToolItem) OnPlace(c *Client, s mt.Stack, a *mt.ToSrvInteract) mt.Stack

func (*ToolItem) OnUse

func (itm *ToolItem) OnUse(c *Client, s mt.Stack, a *mt.ToSrvInteract) mt.Stack

type UUID

type UUID [16]byte
var UUIDNil UUID

func DB_PlayerGetByName

func DB_PlayerGetByName(name string) (uuid UUID, err error)

PlayerGetByName returns the UUID of a name

func (UUID) Quaters

func (u UUID) Quaters() string

Returns UUID in 4 hex-encoded 4byte blocks seperated by dashes

func (UUID) RFC4122

func (u UUID) RFC4122() string

Returns a RFC4122 formatted UUID

func (UUID) String

func (u UUID) String() string

Returns UUID.RFC4122

Directories

Path Synopsis
This just wraps the minetest.LogLevels struct
This just wraps the minetest.LogLevels struct

Jump to

Keyboard shortcuts

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