Documentation
¶
Index ¶
- Constants
- Variables
- type App
- func (a *App) AddHandler(opcode uint16, h Handler)
- func (a *App) AddModule(module Moddule)
- func (a *App) AddSession(userID int64, session *Session)
- func (a *App) GetTotalConn() int64
- func (a *App) Init() (err error)
- func (a *App) OnConnect(session *Session) bool
- func (a *App) OnDisConnect(sesssion *Session)
- func (a *App) OnMessage(session *Session, p Packet) bool
- func (a *App) SendActor(userID int64, opcode uint16, msg proto.Message) error
- func (a *App) SetBeforeMiddleware(m Middleware)
- func (a *App) SetConnectListener(l Listener)
- func (a *App) SetDisconnectListener(l Listener)
- func (a *App) Start() error
- func (a *App) Stop()
- type Client
- type Context
- type DefaultContext
- func (c *DefaultContext) Context() context.Context
- func (c *DefaultContext) Params(m protoreflect.ProtoMessage) error
- func (c *DefaultContext) Send(opcode uint16, msg proto.Message) error
- func (c *DefaultContext) SendActor(userID int64, opcode uint16, msg proto.Message) error
- func (c *DefaultContext) Session() *Session
- func (c *DefaultContext) Valid(userID int64)
- type DefaultPacket
- type Handler
- type Listener
- type Middleware
- type Moddule
- type Packet
- type PushActorMessage
- type Session
- func (s *Session) Close()
- func (s *Session) GetConn() net.Conn
- func (s *Session) IsClosed() bool
- func (s *Session) IsValid() bool
- func (s *Session) Run()
- func (s *Session) SetUserData(d interface{})
- func (s *Session) SetUserID(userID int64)
- func (s *Session) UserData() interface{}
- func (s *Session) UserID() int64
- func (s *Session) WritePacket(p Packet) (err error)
- type SessionCallback
- type SessionCreator
Constants ¶
View Source
const (
// 向NATS中push推送给其他玩家消息的键
NatsPushUserK = "GAME_PUSH_USER"
)
Variables ¶
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct { boot.BaseInstance // contains filtered or unexported fields }
App 游戏服务器实现
func (*App) AddSession ¶ added in v0.0.4
AddSession 加入Session
func (*App) SetBeforeMiddleware ¶
func (a *App) SetBeforeMiddleware(m Middleware)
SetBeforeMiddleware 设置消息处理前中间件
func (*App) SetConnectListener ¶
SetConnectListener 设置连接监听器
func (*App) SetDisconnectListener ¶
SetDisconnectListener 设置断连监听器
type Client ¶ added in v0.0.4
Client 客户端实现,用于压测和机器人测试
func NewClient ¶ added in v0.0.4
NewClient 新客户端 conn 连接协议实例 readLimit 最大读取包 sendLimit 最大写入包 heart 心跳周期
func (*Client) Send ¶ added in v0.0.4
func (c *Client) Send(opcode uint16, msg protoreflect.ProtoMessage) error
Send 发送消息
type Context ¶
type Context interface { // Context 返回一个context.Context Context() context.Context // Parmas 取出请求参数 Params(m protoreflect.ProtoMessage) error // Session 获取这个玩家的Session Session() *Session // Send 发送消息到玩家 Send(opcode uint16, msg proto.Message) error // SendActor 向其他玩家发送消息 SendActor(userID int64, opcode uint16, msg proto.Message) error // Valid 验证玩家成功,传入用户ID Valid(userID int64) }
Context 抽象每个Handler的调用参数
type DefaultContext ¶
type DefaultContext struct {
// contains filtered or unexported fields
}
DefaultContext 默认Context实现
func (*DefaultContext) Context ¶
func (c *DefaultContext) Context() context.Context
func (*DefaultContext) Params ¶
func (c *DefaultContext) Params(m protoreflect.ProtoMessage) error
func (*DefaultContext) Send ¶
func (c *DefaultContext) Send(opcode uint16, msg proto.Message) error
WritePbPacket 写入Protobuf的包
func (*DefaultContext) Session ¶
func (c *DefaultContext) Session() *Session
func (*DefaultContext) Valid ¶ added in v0.0.4
func (c *DefaultContext) Valid(userID int64)
Valid 验证成功
type DefaultPacket ¶
type DefaultPacket struct {
// contains filtered or unexported fields
}
DefaultPacket 基于Protobuffer的包协议
func NewDefaultPacket ¶
func NewDefaultPacket(buff []byte, opcode uint16) *DefaultPacket
NewPbPacket 新建一个pb的Packet
func (*DefaultPacket) Serialize ¶
func (p *DefaultPacket) Serialize() []byte
Serialize 序列化,输出完整的字符数组
type Packet ¶
type Packet interface { // Serialize 序列化 Serialize() []byte // OpeCode 获取该包的OpCode OpCode() uint16 // BodyLen 内容长度 BodyLen() uint16 // Body 获取完整body Body() []byte }
Packet 包接口
var HeartPacket Packet = NewDefaultPacket(nil, 0)
HeartPacket 默认使用0号协议作为心跳包的协议
func CretaePbPacket ¶
CretaePbPacket 创建要给protobuf的包
type PushActorMessage ¶ added in v0.0.4
type PushActorMessage struct { UserID int64 `json:"user_id"` OpCode uint16 `json:"opcode"` Msg []byte `json:"msg"` }
PushActorMessage 发送消息给远程玩家
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session 网络会话
func (*Session) Run ¶
func (s *Session) Run()
Run 执行主体逻辑,三套循环 readLoop 读循环 writeLoop 写循环 handleLopp 处理消息循环
Click to show internal directories.
Click to hide internal directories.