proxy

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: 23 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnStart

func OnStart(cb func(log.Logger))

OnStart registers a function to be called back when the proxy is initialized, i.e., when the proxy server is ready, not when an Arknights user is connected. The Logger interface provided will be the proxy's logger.

func RegisterInitFunc

func RegisterInitFunc(name string, fun ModuleInitFunc)

RegisterInitFunc adds a rhineModule that will be initialized when a user authenticates with the Arknights server.

Types

type Hooker

type Hooker interface {
	Unhook()
}

Hooker is the generic Hook interface which exposes a single Unhook method which accepts and returns nothing. Receivers who implement this interface should fail silently if Unhook is called on a nil or already unhooked hook.

type ModuleInitFunc

type ModuleInitFunc func(*RhineModule)

ModuleInitFunc will be called when a user authenticates with the server to allow the module to setup its hooks and internal state for an individual user.

type Options

type Options struct {
	Logger      log.Logger // Defaults to log.Log if not specified
	LoggerFlags int        // Flags to pass to the standard logger, if a custom logger is not specified
	// LogPath defaults to "logs/proxy.log", setting it to "/dev/null", even on Windows,
	// will make the logger not output a file.
	LogPath          string
	LogDisableStdOut bool           // Should stdout output be DISABLED for the default logger
	EnableHostFilter bool           // Filters out packets from certain hosts if they match HostFilter
	HostFilter       *regexp.Regexp // Custom regexp filter for filtering packets, defaults to the block list in proxy/filters.go
	Verbose          bool           // log more Rhine information
	VerboseGoProxy   bool           // log every GoProxy request to stdout
	Address          string         // proxy listen address, defaults to ":8080"
	DisableCertStore bool           // Disables the built in certstore, reduces memory usage but increases HTTP latency and CPU usage.
	NoUnknownJSON    bool           // Disallows unknown fields when unmarshalling json in the gamestate module.
}

Options optionally changes the behavior of the proxy

type PacketHandler

type PacketHandler func(op string, data []byte, pktCtx *goproxy.ProxyCtx) []byte

PacketHandler represents handler functions exposed by a module.

type PacketHook

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

PacketHook contains information about the hook and allows for execution of the underlying Handle and Shutdown methods in the PacketHandler.

func (*PacketHook) Unhook

func (hook *PacketHook) Unhook()

Unhook will unhook the receiving PacketHook if it's hooked.

type Proxy

type Proxy struct {
	log.Logger
	// contains filtered or unexported fields
}

Proxy contains the internal state relevant to the proxy

func NewProxy

func NewProxy(options *Options) *Proxy

NewProxy returns a new initialized Dispatch

func (*Proxy) HandleReq

func (proxy *Proxy) HandleReq(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response)

HandleReq processes an outgoing HTTP request, dispatching it if it's game traffic.

func (*Proxy) HandleResp

func (proxy *Proxy) HandleResp(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response

HandleResp processes an incoming http(s) response.

func (*Proxy) Shutdown

func (p *Proxy) Shutdown()

Shutdown calls Shutdown on all modules for all users.

func (*Proxy) Start

func (p *Proxy) Start()

Start starts the proxy. This is blocking and does not return.

type RequestContext

type RequestContext struct {
	// Was the request blocked by the proxy
	RequestIsBlocked bool
	RequestOp        string
	// Contains the request body. Nil if DispatchState is for a request.
	RequestData []byte
	// Start time for handling the request
	StartT time.Time
	// contains filtered or unexported fields
}

RequestContext contains additional data to be stored in goproxy.ProxyCtx.UserData to provide request context to the response handler.

func GetRequestContext

func GetRequestContext(ctx *goproxy.ProxyCtx) *RequestContext

GetRequestContext returns the dispatch context for a goproxy.ProxyCtx, will panic if called on a goproxy.ProxyCtx not associated with game data. I.e., the request was not handled by proxy.HandleReq.

type RhineModule

type RhineModule struct {
	Region string
	UID    int
	// contains filtered or unexported fields
}

RhineModule provides modules with an interface to Rhine, allowing them to register hooks for events.

func (*RhineModule) GetGameState

func (m *RhineModule) GetGameState() *statestruct.User

GetGameState will block until the gamestate module finishes parsing S/account/syncData.

func (*RhineModule) Hook

func (m *RhineModule) Hook(target string, priority int, handler PacketHandler) Hooker

Hook registers a new packet hook whose PacketHandler will be called back when the specified target packet is received by Rhine. A Hooker is returned, allowing the caller to Unhook the hook to stop receiving callbacks. The current implementation sorts the hooks to maintain priority ordering, while this isn't the most efficient, especially after the initial hooking is done when all the modules are initialized, doing a binary search and bisecting would result in a lot of expensive copying anyway.

func (*RhineModule) OnShutdown

func (m *RhineModule) OnShutdown(cb ShutdownCb)

OnShutdown registers a void function which accepts a boolean argument to be called back the program is killed with SIGINT or when an Arknights user reconnects. The boolean argument will be set to true if the callback is initiated because of a SIGINT event, and false if it's a user reconnecting.

func (*RhineModule) StateGet

func (m *RhineModule) StateGet(path string) (interface{}, error)

StateGet 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.

func (*RhineModule) StateHook

func (m *RhineModule) StateHook(target string, listener chan gamestate.StateEvent, event bool) Hooker

StateHook registers a new game state hook whose listener chan will be notified when the specified game state has been modified. The StateEvent passed through the chan will exclude the new state at the path if the event bool is set to true.

type ShutdownCb

type ShutdownCb func(shuttingDown bool)

ShutdownCb will be called when the proxy is shutting down or when a user reconnects.

Directories

Path Synopsis
Package filters provides the default host filter list for Rhine and a small utility function to generate a regexp expression from a slice of strings.
Package filters provides the default host filter list for Rhine and a small utility function to generate a regexp expression from a slice of strings.
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.
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.

Jump to

Keyboard shortcuts

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