Documentation
¶
Index ¶
- Variables
- type App
- func (a *App) AddHandler(opcode uint16, h Handler)
- func (a *App) AddModule(module Moddule)
- 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) 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 Context
- type DefaultContext
- type DefaultPacket
- type Handler
- type Listener
- type Middleware
- type Moddule
- type Packet
- 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) UserData() interface{}
- func (s *Session) UserID() int64
- func (s *Session) Valid(userId int64)
- func (s *Session) WritePacket(p Packet) (err error)
- type SessionCallback
- type SessionCreator
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoImplementNetwork = errors.New("no implement network: ") ErrConnClosing = errors.New("session connect is closing") )
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
boot.BaseInstance
// contains filtered or unexported fields
}
App 游戏服务器实现
func (*App) SetBeforeMiddleware ¶
func (a *App) SetBeforeMiddleware(m Middleware)
SetBeforeMiddleware 设置消息处理前中间件
func (*App) SetConnectListener ¶
SetConnectListener 设置连接监听器
func (*App) SetDisconnectListener ¶
SetDisconnectListener 设置断连监听器
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
}
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
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 Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session 网络会话
Click to show internal directories.
Click to hide internal directories.