Documentation
¶
Overview ¶
Package gamestate currently only marshals and stores the initial data sync, planned to mirror the client's state perfectly and enable other mods to hook onto it to query data or receive updates if values have changed.
Index ¶
- Variables
- type GameState
- func (mod *GameState) Get(path string) (interface{}, error)
- func (mod *GameState) GetStateRef() *statestruct.User
- func (mod *GameState) Hook(target, moduleName string, listener chan StateEvent, event bool) *GameStateHook
- func (mod *GameState) IsLoaded() bool
- func (mod *GameState) StateSync()
- func (mod *GameState) WalkAndNotify(data []byte) error
- type GameStateHook
- type StateEvent
- type SyntaxError
Constants ¶
This section is empty.
Variables ¶
var (
ErrMaxPath = errors.New("Maximum path depth reached")
)
Functions ¶
This section is empty.
Types ¶
type GameState ¶
type GameState struct {
// contains filtered or unexported fields
}
GameState provides a handle in which users can obtain a reference to the gamestate struct.
func New ¶
New provides a newly instantiated GameState struct and a callback for the proxy to call on every game packet.
func (*GameState) Get ¶
Get returns the value of the gamestate from the path specified. Path is a period separated string based on the JSON keys, see https://github.com/mcuadros/go-lookup for reference. Blocks until the state is ready.
func (*GameState) GetStateRef ¶
func (mod *GameState) GetStateRef() *statestruct.User
GetStateRef will block until the module finishes parsing S/account/syncData.
func (*GameState) Hook ¶
func (mod *GameState) Hook(target, moduleName string, listener chan StateEvent, event bool) *GameStateHook
Hook creates a GameStateHook and attaches it as soon as possible. Notably, users should not expect the hook to be attached when the function returns as the attaching is done in a separate goroutine, allowing users to hook without blocking when the module is initialized on account/login, i.e., before game state is initialized from the SyncData packet.
func (*GameState) IsLoaded ¶
IsLoaded checks if the initial sync packet has already been parsed and the gamestate instance is ready for use.
func (*GameState) StateSync ¶
func (mod *GameState) StateSync()
StateSync blocks until the gamestate is usable. The consistency provided by this function isn't strict, but considering the time between packets, and that that the gamestate is guaranteed to be at least as new as the seqnum of the packet context that StateSync was called on and any transitional states up to the seqnum of the latest packet context.
func (*GameState) WalkAndNotify ¶
WalkAndNotify utilizes the scanner statemachine from the standard library to send notification events via callbacks while walking a json input.
type GameStateHook ¶
type GameStateHook struct {
// contains filtered or unexported fields
}
func (*GameStateHook) Unhook ¶
func (oldHook *GameStateHook) Unhook()
Unhook unhooks the hook from the gamestate.
type StateEvent ¶
type StateEvent struct { Path string Payload interface{} }
type SyntaxError ¶
type SyntaxError struct { Offset int64 // error occurred after reading Offset bytes // contains filtered or unexported fields }
A SyntaxError is a description of a JSON syntax error.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string