ChatPlugin

package
v0.0.0-...-246bd56 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

* websocket客户端

Index

Constants

View Source
const ChanMaxSize int = 20
View Source
const Default_Message_MessageColor string = "white"
View Source
const Default_Message_PlayerColor string = "white"
View Source
const Default_Message_ServerNameColor string = "white"
View Source
const LocalServerId int = -1
View Source
const MinecraftServerId int = -2

Variables

View Source
var (
	WSsvr    *WSServer
	WSrsPool []WebSocketRS

	LocalServerName string
	IsStart         bool
	FirstTouch      int64 = 1024
	NotInWhitelist  int64 = 1
	ContainerName   string
)

Functions

func SendMessage

func SendMessage()

* 接受消息并发送

Types

type ChatPlugin

type ChatPlugin struct{}

func (*ChatPlugin) Close

func (Cp *ChatPlugin) Close()

func (*ChatPlugin) Handle

func (Cp *ChatPlugin) Handle(c *command.Command, s lib.Server)

func (*ChatPlugin) Init

func (Cp *ChatPlugin) Init(s lib.Server)

type Message

type Message struct {
	ServerName           *string  `protobuf:"bytes,1,req,name=ServerName" json:"ServerName,omitempty"`
	Player               *string  `protobuf:"bytes,2,opt,name=Player" json:"Player,omitempty"`
	Message              *string  `protobuf:"bytes,3,opt,name=Message" json:"Message,omitempty"`
	ServerNameColor      *string  `protobuf:"bytes,4,opt,name=ServerNameColor,def=white" json:"ServerNameColor,omitempty"`
	PlayerColor          *string  `protobuf:"bytes,5,opt,name=PlayerColor,def=white" json:"PlayerColor,omitempty"`
	MessageColor         *string  `protobuf:"bytes,6,opt,name=MessageColor,def=white" json:"MessageColor,omitempty"`
	State                *int64   `protobuf:"varint,7,opt,name=state" json:"state,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Message) Descriptor

func (*Message) Descriptor() ([]byte, []int)

func (*Message) GetMessage

func (m *Message) GetMessage() string

func (*Message) GetMessageColor

func (m *Message) GetMessageColor() string

func (*Message) GetPlayer

func (m *Message) GetPlayer() string

func (*Message) GetPlayerColor

func (m *Message) GetPlayerColor() string

func (*Message) GetServerName

func (m *Message) GetServerName() string

func (*Message) GetServerNameColor

func (m *Message) GetServerNameColor() string

func (*Message) GetState

func (m *Message) GetState() int64

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) Reset

func (m *Message) Reset()

func (*Message) String

func (m *Message) String() string

func (*Message) XXX_DiscardUnknown

func (m *Message) XXX_DiscardUnknown()

func (*Message) XXX_Marshal

func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Message) XXX_Merge

func (m *Message) XXX_Merge(src proto.Message)

func (*Message) XXX_Size

func (m *Message) XXX_Size() int

func (*Message) XXX_Unmarshal

func (m *Message) XXX_Unmarshal(b []byte) error

type WSClient

type WSClient struct {
	ServerId   int    //服务器id
	ServerName string //服务器名称
	Addr       string
	Origin     string

	ReceiveMessage chan *Message   //接受到的消息
	Ctx            context.Context //上下文
	Cancel         context.CancelFunc
	// contains filtered or unexported fields
}

func (*WSClient) GetId

func (WSC *WSClient) GetId() int

func (*WSClient) GetName

func (WSC *WSClient) GetName() string

func (*WSClient) IsAlive

func (WSC *WSClient) IsAlive() bool

func (*WSClient) Read

func (WSC *WSClient) Read()

func (*WSClient) Send

func (WSC *WSClient) Send(msg *Message)

func (*WSClient) Start

func (WSC *WSClient) Start() error

type WSServer

type WSServer struct {
	ServerId       int    //服务器id
	ServerName     string //服务器名称
	Port           int
	Suburl         string           //子路由
	ReceiveMessage chan *msgPackage //接受到的消息
	SendMessage    chan *Message    //要发送的消息

	ConnPool  map[string]*WSServerClient //连接池,键为服务器名称,值为封装的websocket连接对象
	RWPool    *sync.RWMutex              //连接池读写锁
	WhiteList map[string]interface{}     //白名单
	Ctx       context.Context            //上下文
	Cancel    context.CancelFunc
	Alive     bool //是否是活跃连接
	// contains filtered or unexported fields
}

func (*WSServer) GetId

func (WSS *WSServer) GetId() int

func (*WSServer) GetName

func (WSS *WSServer) GetName() string

func (*WSServer) IsAlive

func (WSS *WSServer) IsAlive() bool

func (*WSServer) Read

func (WSS *WSServer) Read()

func (*WSServer) Send

func (WSS *WSServer) Send(msg *Message)

接收要发送的消息

func (*WSServer) SendtoClient

func (WSS *WSServer) SendtoClient(msg *msgPackage)

向连接池里的所有连接发送消息

func (*WSServer) Start

func (WSS *WSServer) Start() error

type WSServerClient

type WSServerClient struct {
	ServerId int //服务器id
	Conn     *websocket.Conn
}

type WebSocketRS

type WebSocketRS interface {
	Start() error
	Send(*Message)
	Read()
	GetId() int
	GetName() string
	IsAlive() bool
}

Jump to

Keyboard shortcuts

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