internal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWSAuthPlugin

func NewWSAuthPlugin() sdk.PluginProvider

NewWSAuthPlugin returns the ws-auth SDK plugin provider.

func SetGlobalEnforcer

func SetGlobalEnforcer(pe *ProtocolEnforcer)

SetGlobalEnforcer sets the global protocol enforcer.

Types

type AuthenticatedConnection

type AuthenticatedConnection struct {
	ConnID     string
	PlayerID   string
	PlayerType string
	SessionID  string
	HMACKey    []byte
	LastSeq    uint64
}

AuthenticatedConnection holds per-connection state after a completed handshake.

type ConnectionChallenge

type ConnectionChallenge struct {
	Nonce     string `json:"nonce"`
	Timestamp int64  `json:"timestamp"`
	ServerID  string `json:"server_id"`
}

ConnectionChallenge is sent to the client to initiate handshake.

type HandshakeResponse

type HandshakeResponse struct {
	Signature  string `json:"signature"`
	PlayerType string `json:"player_type"`
	SessionID  string `json:"session_id"`
	AuthToken  string `json:"auth_token"`
	SDKVersion string `json:"sdk_version"`
}

HandshakeResponse is the client's reply to a challenge.

type ProtocolEnforcer

type ProtocolEnforcer struct {

	// OnAuthenticated is called after successful handshake, before the
	// handshake_ok message is sent. Useful for joining rooms synchronously.
	OnAuthenticated func(connID, playerType, sessionID, playerID string)

	// OnDisconnect is called when a connection is removed.
	OnDisconnect func(connID, playerID string)

	// SendFunc delivers a message to a connection. Must be set by the host.
	SendFunc func(connID string, msg []byte) bool
	// contains filtered or unexported fields
}

ProtocolEnforcer manages HMAC handshakes and validates signed messages.

func GetGlobalEnforcer

func GetGlobalEnforcer() *ProtocolEnforcer

GetGlobalEnforcer returns the global protocol enforcer.

func NewProtocolEnforcer

func NewProtocolEnforcer(sdkSecret []byte, serverID string) *ProtocolEnforcer

NewProtocolEnforcer creates a ProtocolEnforcer with the given shared SDK secret.

func (*ProtocolEnforcer) GetConnID

func (pe *ProtocolEnforcer) GetConnID(playerID string) string

GetConnID returns the connID for a playerID, if any.

func (*ProtocolEnforcer) GetConnection

func (pe *ProtocolEnforcer) GetConnection(connID string) (AuthenticatedConnection, bool)

GetConnection returns a copy of the authenticated connection for inspection.

func (*ProtocolEnforcer) GetPlayerID

func (pe *ProtocolEnforcer) GetPlayerID(connID string) string

GetPlayerID returns the playerID associated with a connection, if any.

func (*ProtocolEnforcer) HandleConnect

func (pe *ProtocolEnforcer) HandleConnect(connID string)

HandleConnect generates a challenge for a new connection and sends it.

func (*ProtocolEnforcer) HandleDisconnect

func (pe *ProtocolEnforcer) HandleDisconnect(connID string)

HandleDisconnect cleans up per-connection state.

func (*ProtocolEnforcer) HandleMessage

func (pe *ProtocolEnforcer) HandleMessage(connID string, raw []byte) ([]byte, bool)

HandleMessage processes an inbound message. Returns (payload, true) when the message should be forwarded to pipeline routing. Returns (nil, false) when consumed internally (handshake) or rejected.

type SignedMessage

type SignedMessage struct {
	Seq       uint64 `json:"seq"`
	Payload   []byte `json:"payload"`
	Signature string `json:"signature"`
}

SignedMessage wraps a payload with sequence and HMAC signature.

Jump to

Keyboard shortcuts

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