gamestate

package
v0.0.0-...-5ad4fe9 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: BSD-3-Clause Imports: 11 Imported by: 1

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

Constants

This section is empty.

Variables

View Source
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

func New(log rhLog.Logger, strict bool) (*GameState, func(string, []byte, *goproxy.ProxyCtx))

New provides a newly instantiated GameState struct and a callback for the proxy to call on every game packet.

func (*GameState) Get

func (mod *GameState) Get(path string) (interface{}, error)

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

func (mod *GameState) IsLoaded() bool

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

func (mod *GameState) WalkAndNotify(data []byte) error

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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