queqiao

package
v0.0.0-...-713866f Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package queqiao 实现 QueQiao WebSocket 协议。

Index

Constants

View Source
const (
	ActionBroadcast      = "broadcast"
	ActionPrivateMessage = "send_private_msg"
	ActionTitle          = "send_title"
	ActionActionBar      = "send_actionbar"
	ActionRconCommand    = "send_rcon_command"
	ActionGetStatus      = "get_status"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

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

func NewBridge

func NewBridge(serverName string, cfg Config, bus *event.Bus) *Bridge

func (*Bridge) Broadcast

func (b *Bridge) Broadcast(text string) error

func (*Bridge) Config

func (b *Bridge) Config() Config

func (*Bridge) Connected

func (b *Bridge) Connected() bool

func (*Bridge) Rcon

func (b *Bridge) Rcon(command string) error

func (*Bridge) RconResponse

func (b *Bridge) RconResponse(ctx context.Context, command string) (string, error)

func (*Bridge) Run

func (b *Bridge) Run(ctx context.Context)

func (*Bridge) Send

func (b *Bridge) Send(api string, data interface{}) error

func (*Bridge) Stop

func (b *Bridge) Stop()

func (*Bridge) Tell

func (b *Bridge) Tell(name, text string) error

type Client

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

Client 允许一个读取者和多个并发写入者。

func NewClient

func NewClient(cfg Config) *Client

func (*Client) Broadcast

func (c *Client) Broadcast(text string) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) Config

func (c *Client) Config() Config

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

func (*Client) Connected

func (c *Client) Connected() bool

func (*Client) Rcon

func (c *Client) Rcon(command string) error

Rcon 使用 QueQiao 的命令分发器,而不是 server.properties 的 RCON。

func (*Client) RconResponse

func (c *Client) RconResponse(ctx context.Context, command string) (string, error)

func (*Client) Read

func (c *Client) Read() (Incoming, error)

Read 会跳过格式错误的帧,而不是断开连接。

func (*Client) Send

func (c *Client) Send(api string, data interface{}) error

func (*Client) SendAndWait

func (c *Client) SendAndWait(ctx context.Context, api string, data interface{}) (Incoming, error)

func (*Client) Tell

func (c *Client) Tell(nickname, text string) error

type Config

type Config struct {
	URL         string // ws://host:port
	AccessToken string
	ServerName  string
}

type Incoming

type Incoming struct {
	PostType   string `json:"post_type"`
	EventName  string `json:"event_name"`
	SubType    string `json:"sub_type"`
	ServerName string `json:"server_name"`
	Timestamp  int64  `json:"timestamp"`
	Player     Player `json:"player"`
	RawMessage string `json:"raw_message"`
	Message    string `json:"message"`
	Command    string `json:"command"`
	Death      *struct {
		Text string `json:"text"`
		Key  string `json:"key"`
	} `json:"death,omitempty"`
	Achievement *struct {
		Text string `json:"text"`
		Key  string `json:"key"`
	} `json:"achievement,omitempty"`

	API    string          `json:"api"`
	Status string          `json:"status"`
	Code   int             `json:"code"`
	Echo   string          `json:"echo,omitempty"`
	Data   json.RawMessage `json:"data,omitempty"`
}

Incoming 是 QueQiao 事件和 API 响应共用的帧结构。

func (Incoming) IsEvent

func (in Incoming) IsEvent() bool

func (Incoming) IsResponse

func (in Incoming) IsResponse() bool

type Player

type Player struct {
	Nickname string `json:"nickname"`
	UUID     string `json:"uuid"`
	IsOP     bool   `json:"is_op"`
}

Jump to

Keyboard shortcuts

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