ws

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const PluginBridgeScope = "plugin-bridge"

PluginBridgeScope 是插件桥 token 要求的 scope claim 值。 CP 签发插件桥 token 时写入 scope=plugin-bridge,Worker 握手时据此与终端 token 区分, 拒绝拿终端 token(无此 scope)冒连插件桥(见 ADR-016)。

Variables

View Source
var (

	// ErrBridgeNotConnected 指定实例当前无活动探针会话(治理同步往返时立即返回,不阻塞)。
	ErrBridgeNotConnected = errors.New("探针未连接")
	// ErrBridgeCommandTimeout 探针未在期限内回 command_result(FR-067 治理同步往返超时)。
	ErrBridgeCommandTimeout = errors.New("探针指令执行超时")
)

校验错误,供握手与单测区分失败原因。

Functions

This section is empty.

Types

type CommandResult

type CommandResult struct {
	RequestID string
	Success   bool
	Output    string // 命令输出(list/whitelist 等)
	Error     string
}

CommandResult 是探针执行一条治理/查询指令后的回执(FR-067,见 ADR-016)。 由探针经 command_result 事件帧带回,Worker 据 request_id 路由给同步等待的调用方。

type PluginBridgeServer

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

PluginBridgeServer 是 ServerProbe 探针反向 WS 连入的服务端(端点 /ws/plugin-bridge,FR-065)。 维护「实例 UUID → 探针会话」表:同一实例同时仅一活动会话,新连顶替旧连(见 ADR-016)。 token 校验复用 JIANMANAGER_JWT_SECRET,要求 scope=plugin-bridge 且 instanceId 与 query 一致。

func NewPluginBridgeServer

func NewPluginBridgeServer(jwtSecret string) *PluginBridgeServer

NewPluginBridgeServer 创建插件桥服务端。

func (*PluginBridgeServer) Handler

func (s *PluginBridgeServer) Handler() http.HandlerFunc

Handler 返回 /ws/plugin-bridge 的 HTTP handler。

func (*PluginBridgeServer) IsConnected

func (s *PluginBridgeServer) IsConnected(instanceID string) bool

IsConnected 返回指定实例当前是否有活动探针会话。

func (*PluginBridgeServer) SendCommand

func (s *PluginBridgeServer) SendCommand(instanceID string, payload interface{}) (bool, error)

SendCommand 向指定实例的活动探针会话下发一帧指令(command),不等待执行结果。 实例当前无活动会话时返回 false。

func (*PluginBridgeServer) SendCommandAndWait

func (s *PluginBridgeServer) SendCommandAndWait(instanceID, requestID string, payload interface{}, timeout time.Duration) (CommandResult, error)

SendCommandAndWait 向实例的活动探针会话下发指令并同步等待 command_result(FR-067 治理)。

以 request_id 关联回执:注册等待 channel → 写出 command 帧 → 等 command_result 或超时。 替代 RCON 的同步请求/响应语义(踢/封/解封/白名单/在线列表)。实例无活动会话立即返回 ErrBridgeNotConnected;探针未在 timeout 内回执返回 ErrBridgeCommandTimeout(均不永久阻塞)。

func (*PluginBridgeServer) SessionCount

func (s *PluginBridgeServer) SessionCount() int

SessionCount 返回当前活动探针会话总数(用于观测/测试)。

func (*PluginBridgeServer) SetEventHandler

func (s *PluginBridgeServer) SetEventHandler(h PluginEventHandler)

SetEventHandler 注入事件回调,把 connected/disconnected/业务事件桥接到 gRPC StreamPluginEvents。

func (*PluginBridgeServer) SetJWTSecret

func (s *PluginBridgeServer) SetJWTSecret(secret string)

SetJWTSecret 热更新 token 校验密钥(FR-275,见 ADR-061):CP 经注册/心跳下发新密钥时调用。 仅影响后续握手;已建立的探针会话不受影响(握手只校验一次)。

type PluginEvent

type PluginEvent struct {
	InstanceUUID string
	Type         PluginEventKind
	Timestamp    int64
	Platform     string // bukkit | bungee(来自探针 hello)
	Version      string // 探针版本(来自探针 hello)
	// 以下为探针业务事件(FR-066)携带的结构化字段;连接/心跳事件为空。
	PlayerName string // 玩家事件:玩家名
	PlayerUUID string // 玩家事件:玩家 UUID
	Message    string // chat 内容 / 事件描述
	Server     string // 子服名(玩家所在/事件发生)
	FromServer string // cross_server:来源子服
	ToServer   string // cross_server:目标子服
	Raw        string // 透传原始消息载荷(下游按需解析)
	// 以下为 JBIS 业务事件(FR-115/ADR-027)字段;监控/治理事件为空。
	Domain   string // 业务域(economy/inventory…;空/core 为非业务)
	DedupKey string // 业务事件去重键(CP 按 (domain,dedupKey) 幂等落库)
}

PluginEvent 是插件桥向上(gRPC StreamPluginEvents)冒泡的一条事件。 平台无关:Worker 侧负责会话/握手/心跳与连接状态冒泡,并把探针 event 帧里的结构化 玩家字段解析出来(FR-066:join/quit/chat/cross_server),供 gRPC 侧填充 workerpb.PluginEvent。 Worker 只解析、不消费语义(治理执行在 FR-067,跨服感知聚合在 CP)。

type PluginEventHandler

type PluginEventHandler func(PluginEvent)

PluginEventHandler 接收插件桥冒泡的事件,由 Worker 注入以桥接到 gRPC 事件流。

type PluginEventKind

type PluginEventKind = string

PluginEventKind 是插件桥冒泡事件的类型,与 proto PluginEvent.type 对应。 地基(FR-065)真实产生 connected/disconnected/heartbeat;其余子类型留 FR-066/067。

const (
	PluginEventConnected    PluginEventKind = "connected"
	PluginEventDisconnected PluginEventKind = "disconnected"
	PluginEventHeartbeat    PluginEventKind = "heartbeat"
)

type PluginSession

type PluginSession struct {
	InstanceID string
	Platform   string
	Version    string
	Conn       *websocket.Conn
	// contains filtered or unexported fields
}

PluginSession 是一个实例当前活动的探针会话。

type ResizeHandler

type ResizeHandler func(instanceID string, cols, rows int)

ResizeHandler 终端大小调整处理函数。

type StdinHandler

type StdinHandler func(instanceID, data string)

StdinHandler stdin 输入处理函数。

type TerminalMessage

type TerminalMessage struct {
	Type       string `json:"type"`
	InstanceID string `json:"instanceId,omitempty"`
	Data       string `json:"data,omitempty"`
	Cols       int    `json:"cols,omitempty"`
	Rows       int    `json:"rows,omitempty"`
	State      string `json:"state,omitempty"`
}

type TerminalServer

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

TerminalServer 终端 WebSocket 服务器。

func NewTerminalServer

func NewTerminalServer(jwtSecret string) *TerminalServer

NewTerminalServer 创建终端服务器。

func (*TerminalServer) Broadcast

func (s *TerminalServer) Broadcast(instanceID string, msgType, data string)

Broadcast 向指定实例的所有观察者广播消息,同时写入共享环形缓冲区。

func (*TerminalServer) BufferedOutput

func (s *TerminalServer) BufferedOutput(instanceID string) []byte

BufferedOutput 返回实例终端环形缓冲区当前内容的副本;实例尚无缓冲时返回 nil。 供崩溃快照截取尾部输出(FR-313)——只读旁路,不创建缓冲、不影响终端回放。

func (*TerminalServer) GetSessionCount

func (s *TerminalServer) GetSessionCount(instanceID string) int

GetSessionCount 获取指定实例的终端会话数。

func (*TerminalServer) Handler

func (s *TerminalServer) Handler() http.HandlerFunc

Handler 返回 HTTP handler。

func (*TerminalServer) SetJWTSecret

func (s *TerminalServer) SetJWTSecret(secret string)

SetJWTSecret 热更新 token 校验密钥(FR-275,见 ADR-061):CP 经注册/心跳下发新密钥时调用。 仅影响后续握手;已建立的会话不受影响(握手只校验一次)。

func (*TerminalServer) SetResizeHandler

func (s *TerminalServer) SetResizeHandler(handler ResizeHandler)

SetResizeHandler 设置终端大小调整处理函数。

func (*TerminalServer) SetStdinHandler

func (s *TerminalServer) SetStdinHandler(handler StdinHandler)

SetStdinHandler 设置 stdin 输入处理函数。

type TerminalSession

type TerminalSession struct {
	InstanceID string
	Permission string
	Conn       *websocket.Conn
}

TerminalSession 终端会话。

Jump to

Keyboard shortcuts

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