msg

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2020 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package msg provides marshalling and unmarshalling functions for messages over websockets. Messages are formatted as such:

{OP_CODE} {PAYLOAD}

With a single space delimiting the op code from the payload. Where the payload is a json value, i.e., a json string/array/number/object, but may be omitted if no payload is necessary.

Messages from the server to the client: S_UserList - Sent on first connection with Angelina

["string"]  // Array of user identifiers '{REGION}_{UID}'

S_NewUser - When a new user logs in through Rhine

"string"  // User identifier '{REGION}_{UID}'

S_Attached

"string"  // User identifier '{REGION}_{UID}'

S_Detached - When the connected user is disconnected

No payload.

S_Hooked - On successful hook request.

{
	"id": "string",  // Required for unhooking
	"type": "string",  // 'gamestate' or 'packet'
	"target": "string",
	"event": "boolean"  // Optional, false if not sent
}

S_Unhooked - On successful unhook request.

"string"

S_HookEvt - Sent when a hook generates an event.

{
	"type": "string",  // 'gamestate' or 'packet'
	"target": "string",
	// data's JSON type may vary depending on the hook target.
	// Omitted if the hook is an event type
	"data": "data object"
}

S_Get - Sent after the client sends a C_Get request if the get is successful.

{
	"path": "string",
	"data": "data object"
}

S_Error - Sent when an error was generated while handling of a request.

{
	"request": "string",  // The request message that generated the error
	"error": "string"
}

Messages from the client to the server: C_Attach - C_Attach is sent from the websocket client to request for the server to attach them to the specified game user. A websocket client can only be attached to one user at a time and it is required for hooking and getting information from their game state.

"string"

C_Detach - unhooks all registered hooks and allows the websocket client to attach to another user.

No payload

C_Get - requests a piece of information from the attached user's game state.

"string"

C_Hook - requests a hook to be made on either a certain packet being received or if there's a change to the gamestate in a certain path. The event value specifies if the websocket client only needs to be notified of the change or packet and not sent the data itself.

{
	"type": "string",  // 'gamestate' or 'packet'
	"target": "string",
	"event": "boolean"  // Optional, defaults to false
}

C_Unhook - stop listening on an event.

"string"  // Hook ID

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServerAttached

func ServerAttached(user string) ([]byte, error)

ServerAttached creates a message notifying the client that they've successfully attached to a user.

func ServerDetach

func ServerDetach() ([]byte, error)

ServerDetach creates a message notifying the client that the user they were attached to has disconnected.

func ServerError

func ServerError(request []byte, err string) ([]byte, error)

ServerError creates a message to notify the client that an error has occurred during the handling of a request.

func ServerGet

func ServerGet(path string, data interface{}) ([]byte, error)

ServerGet creates a message relaying the results of their C_Get request.

func ServerHookEvt

func ServerHookEvt(kind, target string, data interface{}) ([]byte, error)

ServerHookEvt notifies the client when a hook generates an event.

func ServerHooked

func ServerHooked(id uint64, kind, target string, event bool) ([]byte, error)

ServerHooked creates a message to notify the client that they have successfully registered a hook for an event.

func ServerNewUser

func ServerNewUser(user string) ([]byte, error)

ServerNewUser creates a message notifying the client that a new user has connected through Rhine and is available to attach to.

func ServerUnhooked

func ServerUnhooked(id uint64) ([]byte, error)

ServerUnhooked creates a message to notify that they have successfully unhooked for an event.

func ServerUserList

func ServerUserList(users []string) ([]byte, error)

ServerUserList creates a message informing the client of the already attached users that are available to attach to.

func UnmarshalClientAttach

func UnmarshalClientAttach(payload []byte) (string, error)

func UnmarshalClientGet

func UnmarshalClientGet(payload []byte) (string, error)

func UnmarshalClientUnhook

func UnmarshalClientUnhook(payload []byte) (string, error)

UnmarshalClientUnhook unmarshals the payload of the C_Unhook message.

Types

type Hook

type Hook struct {
	Kind   string `json:"type"`
	Target string `json:"target"`
	Event  bool   `json:"event"`
}

func UnmarshalClientHook

func UnmarshalClientHook(payload []byte) (*Hook, error)

UnmarshalClientHook unmarshals the payload of the C_Hook message.

Jump to

Keyboard shortcuts

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