Documentation ¶
Index ¶
- Constants
- Variables
- func GetCommandByProto(protoMessage proto.Message) int32
- func GetResCommand(reqCommand int32) int32
- func IsGatePacket(packet Packet) bool
- func ListenClient(listenAddr string, listenerHandler gnet.ListenerHandler, ...) gnet.Listener
- func ListenGate(listenAddr string, packetRegister func(handler *gnet.DefaultConnectionHandler)) gnet.Listener
- func ListenGateClient(listenAddr string, listenerHandler gnet.ListenerHandler, ...) gnet.Listener
- func ListenWebSocketClient(listenAddr string, listenerHandler gnet.ListenerHandler, ...) gnet.Listener
- func NewPacket(message proto.Message) *gnet.ProtoPacket
- func SendPacketAdapt(connection Connection, reqPacket Packet, sendMessage proto.Message) bool
- type ClientCodec
- type ClientData
- type GateCodec
- type GatePacket
- func (this *GatePacket) Clone() Packet
- func (this *GatePacket) Command() PacketCommand
- func (this *GatePacket) GetStreamData() []byte
- func (this *GatePacket) Message() proto.Message
- func (this *GatePacket) PlayerId() int64
- func (this *GatePacket) RpcCallId() uint32
- func (this *GatePacket) SetPlayerId(playerId int64)
- func (this *GatePacket) SetRpcCallId(rpcCallId uint32)
- func (this *GatePacket) ToProtoPacket() *ProtoPacket
- func (this *GatePacket) WithRpc(arg any) *GatePacket
- func (this *GatePacket) WithStreamData(streamData []byte) *GatePacket
- type WsClientCodec
Constants ¶
View Source
const ( // 对应proto文件里的package导出名 ProtoPackageName = "gserver" // 客户端和服务器之间的消息号定义 CmdClientEnumName = "CmdClient" // 对应proto/cmd_client.proto里的enum CmdClient // 服务器之间的消息号定义 CmdServerEnumName = "CmdServer" // 对应proto/cmd_server.proto里的enum CmdServer )
Variables ¶
View Source
var ( ClientConnectionConfig = gnet.ConnectionConfig{ SendPacketCacheCap: 32, SendBufferSize: 8 * 1024, RecvBufferSize: 8 * 1024, MaxPacketSize: 16 * 1024, RecvTimeout: 20, } WebSocketClientConnectionConfig = gnet.ConnectionConfig{ SendPacketCacheCap: 32, SendBufferSize: 8 * 1024, RecvBufferSize: 8 * 1024, MaxPacketSize: 16 * 1024, RecvTimeout: 20, Path: "/ws", } GateConnectionConfig = gnet.ConnectionConfig{ SendPacketCacheCap: 128, SendBufferSize: 512 * 1024, RecvBufferSize: 512 * 1024, MaxPacketSize: 1024 * 1024, RecvTimeout: 5, HeartBeatInterval: 2, } ServerConnectionConfig = gnet.ConnectionConfig{ SendPacketCacheCap: 128, SendBufferSize: 512 * 1024, RecvBufferSize: 512 * 1024, MaxPacketSize: 1024 * 1024, RecvTimeout: 5, HeartBeatInterval: 2, } )
Functions ¶
func GetCommandByProto ¶
func GetResCommand ¶
本项目的request和response的消息号规范: resCmd = reqCmd + 1
func IsGatePacket ¶
func IsGatePacket(packet Packet) bool
func ListenClient ¶
func ListenClient(listenAddr string, listenerHandler gnet.ListenerHandler, packetRegister func(handler *gnet.DefaultConnectionHandler)) gnet.Listener
非网关服务器监听普通TCP客户端
func ListenGate ¶
func ListenGate(listenAddr string, packetRegister func(handler *gnet.DefaultConnectionHandler)) gnet.Listener
其他服务器监听网关
func ListenGateClient ¶
func ListenGateClient(listenAddr string, listenerHandler gnet.ListenerHandler, packetRegister func(handler *gnet.DefaultConnectionHandler)) gnet.Listener
网关服务器监听普通TCP客户端
func ListenWebSocketClient ¶
func ListenWebSocketClient(listenAddr string, listenerHandler gnet.ListenerHandler, packetRegister func(handler *gnet.DefaultConnectionHandler)) gnet.Listener
网关服务器监听WebSocket客户端
func SendPacketAdapt ¶
根据请求消息的类型,自动适配不同的发消息接口
Types ¶
type ClientCodec ¶
type ClientCodec struct { RingBufferCodec // 在proto序列化后的数据,再做一层编码 // encoder after proto.Message serialize ProtoPacketBytesEncoder func(protoPacketBytes [][]byte) [][]byte // 在proto反序列化之前,先做一层解码 // decoder before proto.Message deserialize ProtoPacketBytesDecoder func(packetData []byte) []byte // 消息号和proto.Message type的映射表 MessageCreatorMap map[PacketCommand]reflect.Type }
Tcp客户端和gate之间的编解码
func NewClientCodec ¶
func NewClientCodec() *ClientCodec
func (*ClientCodec) DecodePacket ¶
func (this *ClientCodec) DecodePacket(connection Connection, packetHeader PacketHeader, packetData []byte) Packet
func (*ClientCodec) EncodePacket ¶
func (this *ClientCodec) EncodePacket(connection Connection, packet Packet) ([][]byte, uint8)
func (*ClientCodec) Register ¶
func (this *ClientCodec) Register(command PacketCommand, protoMessage proto.Message)
注册消息和proto.Message的映射
protoMessage can be nil
type ClientData ¶
客户端绑定数据
type GateCodec ¶
type GateCodec struct { RingBufferCodec // 在proto序列化后的数据,再做一层编码 // encoder after proto.Message serialize ProtoPacketBytesEncoder func(protoPacketBytes [][]byte) [][]byte // 在proto反序列化之前,先做一层解码 // decoder before proto.Message deserialize ProtoPacketBytesDecoder func(packetData []byte) []byte // 消息号和proto.Message type的映射表 MessageCreatorMap map[PacketCommand]reflect.Type }
gate和其他服务器之间的编解码
func NewGateCodec ¶
func (*GateCodec) DecodePacket ¶
func (*GateCodec) EncodePacket ¶
type GatePacket ¶
type GatePacket struct {
// contains filtered or unexported fields
}
func NewGatePacket ¶
func NewGatePacket(playerId int64, command PacketCommand, message proto.Message) *GatePacket
func NewGatePacketWithData ¶
func NewGatePacketWithData(playerId int64, command PacketCommand, data []byte) *GatePacket
func (*GatePacket) Command ¶
func (this *GatePacket) Command() PacketCommand
func (*GatePacket) GetStreamData ¶
func (this *GatePacket) GetStreamData() []byte
某些特殊需求会直接使用序列化好的数据
support stream data
func (*GatePacket) Message ¶
func (this *GatePacket) Message() proto.Message
func (*GatePacket) PlayerId ¶
func (this *GatePacket) PlayerId() int64
func (*GatePacket) RpcCallId ¶
func (this *GatePacket) RpcCallId() uint32
func (*GatePacket) SetPlayerId ¶
func (this *GatePacket) SetPlayerId(playerId int64)
func (*GatePacket) SetRpcCallId ¶
func (this *GatePacket) SetRpcCallId(rpcCallId uint32)
func (*GatePacket) ToProtoPacket ¶
func (this *GatePacket) ToProtoPacket() *ProtoPacket
func (*GatePacket) WithRpc ¶
func (this *GatePacket) WithRpc(arg any) *GatePacket
func (*GatePacket) WithStreamData ¶
func (this *GatePacket) WithStreamData(streamData []byte) *GatePacket
type WsClientCodec ¶
type WsClientCodec struct {
SimpleProtoCodec
}
WebSocket客户端和gate之间的编解码
func NewWsClientCodec ¶
func NewWsClientCodec() *WsClientCodec
func (*WsClientCodec) Decode ¶
func (this *WsClientCodec) Decode(connection Connection, data []byte) (newPacket Packet, err error)
Click to show internal directories.
Click to hide internal directories.