Documentation ¶
Index ¶
- Constants
- func DefaultProgressChecker(event interface{}, progressCfg *ProgressCfg) int32
- func IsGatePacket(packet Packet) bool
- func SendPacketAdapt(connection Connection, reqPacket Packet, command PacketCommand, ...) bool
- type Activity
- type ActivityMgr
- type BaseActivity
- type BaseProperties
- type BaseServer
- func (this *BaseServer) AddServerHook(hooks ...gentity.ApplicationHook)
- func (this *BaseServer) DefaultServerConnectorFunc(ctx context.Context, info gentity.ServerInfo) Connection
- func (this *BaseServer) Exit()
- func (this *BaseServer) GetConfigFile() string
- func (this *BaseServer) GetContext() context.Context
- func (this *BaseServer) GetDefaultServerConnectorConfig() *ConnectionConfig
- func (this *BaseServer) GetId() int32
- func (this *BaseServer) GetServerHooks() []gentity.ApplicationHook
- func (this *BaseServer) GetServerInfo() *pb.ServerInfo
- func (this *BaseServer) GetServerList() *ServerList
- func (this *BaseServer) GetWaitGroup() *sync.WaitGroup
- func (this *BaseServer) Init(ctx context.Context, configFile string) bool
- func (this *BaseServer) OnUpdate(ctx context.Context, updateCount int64)
- func (this *BaseServer) Run(ctx context.Context)
- func (this *BaseServer) SendToServer(serverId int32, cmd PacketCommand, message proto.Message) bool
- func (this *BaseServer) SetDefaultServerConnectorConfig(config ConnectionConfig, defaultServerConnectorCodec Codec)
- type BaseServerConfig
- type CfgData
- type ConditionCfg
- type ConditionCheckFunc
- type ConditionMgr
- type EventDateChange
- type EventPlayerEntryGame
- type EventPlayerExit
- 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) SetPlayerId(playerId int64)
- func (this *GatePacket) ToProtoPacket() *ProtoPacket
- type ProgressCfg
- type ProgressCheckFunc
- type ProgressHolder
- type ProgressInitFunc
- type ProgressMgr
- func (this *ProgressMgr) CheckProgress(event interface{}, progressCfg *ProgressCfg, progressHolder ProgressHolder) bool
- func (this *ProgressMgr) GetProgressChecker(event interface{}, progressType int32) (ProgressCheckFunc, bool)
- func (this *ProgressMgr) InitProgress(arg interface{}, progressCfg *ProgressCfg, progressHolder ProgressHolder) bool
- func (this *ProgressMgr) IsMatchEvent(event interface{}, progressType int32) bool
- func (this *ProgressMgr) Register(progressType int32, event interface{}, checker ProgressCheckFunc)
- func (this *ProgressMgr) RegisterDefault(progressType int32, event interface{})
- func (this *ProgressMgr) RegisterWithInit(progressType int32, event interface{}, checker ProgressCheckFunc, ...)
- type Properties
- type PropertyInt32
- type ServerList
Constants ¶
View Source
const ( // 简单计数,每触发一次事件,进度+1 // example: // 进度: 进行10场战斗 // 每触发一次战斗事件,进度就+1 CountType_Counter = 1 // 每次事件触发时,重置进度 // example: // 进度: 升到10级 // 每触发一次升级事件,进度重置为当前等级 CountType_Reset = 2 )
进度计数类型
View Source
const ( ServerType_Login = "LoginServer" ServerType_Game = "GameServer" ServerType_Gate = "GateServer" )
Variables ¶
This section is empty.
Functions ¶
func DefaultProgressChecker ¶
func DefaultProgressChecker(event interface{}, progressCfg *ProgressCfg) int32
默认的进度检查接口
func IsGatePacket ¶
func IsGatePacket(packet Packet) bool
func SendPacketAdapt ¶
func SendPacketAdapt(connection Connection, reqPacket Packet, command PacketCommand, message proto.Message) bool
根据请求消息的类型,自动适配不同的发消息接口
Types ¶
type ActivityMgr ¶
type BaseActivity ¶
type BaseActivity struct {
Id int32
}
func (*BaseActivity) GetId ¶
func (this *BaseActivity) GetId() int32
type BaseProperties ¶
type BaseProperties struct {
Properties map[string]interface{} `json:"Properties"` // 动态属性
}
动态属性
func (*BaseProperties) GetProperty ¶
func (this *BaseProperties) GetProperty(name string) interface{}
func (*BaseProperties) GetPropertyString ¶
func (this *BaseProperties) GetPropertyString(name string) string
type BaseServer ¶
type BaseServer struct {
// contains filtered or unexported fields
}
服务器基础流程
func (*BaseServer) AddServerHook ¶
func (this *BaseServer) AddServerHook(hooks ...gentity.ApplicationHook)
func (*BaseServer) DefaultServerConnectorFunc ¶
func (this *BaseServer) DefaultServerConnectorFunc(ctx context.Context, info gentity.ServerInfo) Connection
默认的服务器连接接口
func (*BaseServer) Exit ¶
func (this *BaseServer) Exit()
func (*BaseServer) GetConfigFile ¶
func (this *BaseServer) GetConfigFile() string
func (*BaseServer) GetContext ¶
func (this *BaseServer) GetContext() context.Context
func (*BaseServer) GetDefaultServerConnectorConfig ¶
func (this *BaseServer) GetDefaultServerConnectorConfig() *ConnectionConfig
func (*BaseServer) GetId ¶
func (this *BaseServer) GetId() int32
func (*BaseServer) GetServerHooks ¶
func (this *BaseServer) GetServerHooks() []gentity.ApplicationHook
func (*BaseServer) GetServerInfo ¶
func (this *BaseServer) GetServerInfo() *pb.ServerInfo
func (*BaseServer) GetServerList ¶
func (this *BaseServer) GetServerList() *ServerList
func (*BaseServer) GetWaitGroup ¶
func (this *BaseServer) GetWaitGroup() *sync.WaitGroup
func (*BaseServer) Init ¶
func (this *BaseServer) Init(ctx context.Context, configFile string) bool
加载配置文件
func (*BaseServer) OnUpdate ¶
func (this *BaseServer) OnUpdate(ctx context.Context, updateCount int64)
func (*BaseServer) SendToServer ¶
func (this *BaseServer) SendToServer(serverId int32, cmd PacketCommand, message proto.Message) bool
发消息给另一个服务器
func (*BaseServer) SetDefaultServerConnectorConfig ¶
func (this *BaseServer) SetDefaultServerConnectorConfig(config ConnectionConfig, defaultServerConnectorCodec Codec)
设置默认的服务器间的编解码和回调接口
type BaseServerConfig ¶
type BaseServerConfig struct { // 服务器id ServerId int32 // 客户端监听地址 ClientListenAddr string // 客户端监听配置 ClientConnConfig ConnectionConfig // 网关监听地址 GateListenAddr string // 其他服务器监听地址 ServerListenAddr string // 服务器连接配置 ServerConnConfig ConnectionConfig // mongodb地址 MongoUri string // mongodb db name MongoDbName string // redis地址 RedisUri []string RedisUsername string RedisPassword string // 是否使用redis集群模式 RedisCluster bool }
type ConditionCheckFunc ¶
type ConditionCheckFunc func(arg interface{}, conditionCfg *ConditionCfg) bool
条件检查接口
type ConditionMgr ¶
type ConditionMgr struct {
// contains filtered or unexported fields
}
条件相关接口管理
func NewConditionMgr ¶
func NewConditionMgr() *ConditionMgr
func (*ConditionMgr) CheckConditions ¶
func (this *ConditionMgr) CheckConditions(arg interface{}, conditions []*ConditionCfg) bool
func (*ConditionMgr) GetConditionChecker ¶
func (this *ConditionMgr) GetConditionChecker(conditionType int32) ConditionCheckFunc
func (*ConditionMgr) Register ¶
func (this *ConditionMgr) Register(conditionType int32, checker ConditionCheckFunc)
注册条件检查接口
type EventPlayerEntryGame ¶
玩家进游戏事件
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) SetPlayerId ¶
func (this *GatePacket) SetPlayerId(playerId int64)
func (*GatePacket) ToProtoPacket ¶
func (this *GatePacket) ToProtoPacket() *ProtoPacket
type ProgressCheckFunc ¶
type ProgressCheckFunc func(event interface{}, progressCfg *ProgressCfg) int32
进度检查接口 返回事件触发时的进度 example:
进度: 抽卡100次 事件: 抽卡(5连抽) 进度+5
type ProgressHolder ¶
进度读取接口
type ProgressInitFunc ¶
type ProgressInitFunc func(arg interface{}, progressCfg *ProgressCfg) int32
进度初始化接口 返回初始进度
type ProgressMgr ¶
type ProgressMgr struct {
// contains filtered or unexported fields
}
进度相关接口管理
func NewProgressMgr ¶
func NewProgressMgr() *ProgressMgr
func (*ProgressMgr) CheckProgress ¶
func (this *ProgressMgr) CheckProgress(event interface{}, progressCfg *ProgressCfg, progressHolder ProgressHolder) bool
检查事件是否触发进度的更新,并更新进度
func (*ProgressMgr) GetProgressChecker ¶
func (this *ProgressMgr) GetProgressChecker(event interface{}, progressType int32) (ProgressCheckFunc, bool)
获取事件,进度对应的检查接口
func (*ProgressMgr) InitProgress ¶
func (this *ProgressMgr) InitProgress(arg interface{}, progressCfg *ProgressCfg, progressHolder ProgressHolder) bool
初始化进度,更新初始进度
examples: 任务举例:玩家升级到10级,当5级玩家接任务时,初始进度就是5/10
func (*ProgressMgr) IsMatchEvent ¶
func (this *ProgressMgr) IsMatchEvent(event interface{}, progressType int32) bool
检查事件是否关联某个进度
func (*ProgressMgr) Register ¶
func (this *ProgressMgr) Register(progressType int32, event interface{}, checker ProgressCheckFunc)
注册事件和进度检查接口 checker可以为nil
func (*ProgressMgr) RegisterDefault ¶
func (this *ProgressMgr) RegisterDefault(progressType int32, event interface{})
注册默认的进度检查接口
func (*ProgressMgr) RegisterWithInit ¶
func (this *ProgressMgr) RegisterWithInit(progressType int32, event interface{}, checker ProgressCheckFunc, init ProgressInitFunc)
注册事件和进度检查接口
checker: 进度检查接口,可以为nil init: 初始化时,更新当前进度,可以为nil
type Properties ¶
type Properties interface { GetProperty(name string) interface{} GetPropertyString(name string) string }
动态属性接口
type PropertyInt32 ¶
type ServerList ¶
type ServerList struct {
gentity.BaseServerList
}
服务器列表管理 每个服务器定时上传自己的信息到redis,其他服务器定时从redis获取整个服务器集群的信息 属于服务注册和发现的功能,zookeeper的临时节点更适合来实现这类需求 这里用redis来实现,pb.ServerInfo.LastActiveTime记录服务器最后上传信息的时间,达到类似"心跳检测"的效果
func NewServerList ¶
func NewServerList() *ServerList
Click to show internal directories.
Click to hide internal directories.