Documentation ¶
Index ¶
- Constants
- func DefaultProgressChecker(event any, progressCfg *pb.ProgressCfg) int32
- func GetTimeoutTimestamp(timeType, timeout int32) int32
- func PacketToGuildRoutePacket(fromPlayerId int64, fromPlayerName string, reqPacket gnet.Packet, ...) gnet.Packet
- func RouteGuildServerId(guildId int64) int32
- type Activity
- type ActivityMgr
- type Bag
- type BaseActivity
- type BaseServer
- func (this *BaseServer) AddServerHook(hooks ...gentity.ApplicationHook)
- func (this *BaseServer) Exit()
- func (this *BaseServer) GetConfigFile() string
- func (this *BaseServer) GetContext() context.Context
- 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) NewAdaptPacket(cmd PacketCommand, message proto.Message) Packet
- 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
- type BaseServerConfig
- type CfgData
- type ConditionCheckFunc
- type ConditionMgr
- type EventDateChange
- type EventPlayerEntryGame
- type EventPlayerExit
- type IPlayer
- type ListerConfig
- type MongoConfig
- type PacketHandlerInfo
- type PacketHandlerMgr
- func (this *PacketHandlerMgr) AddHandlerInfo(handlerInfo *PacketHandlerInfo)
- func (this *PacketHandlerMgr) AutoRegister(entity gentity.Entity, methodNamePrefix string)
- func (this *PacketHandlerMgr) AutoRegisterWithClient(entity gentity.Entity, packetHandlerRegister gnet.PacketHandlerRegister, ...)
- func (this *PacketHandlerMgr) Invoke(entity gentity.Entity, packet gnet.Packet, ...) bool
- type PlayerMgr
- type ProgressCheckFunc
- type ProgressHolder
- type ProgressInitFunc
- type ProgressMgr
- func (m *ProgressMgr) CheckProgress(event any, progressCfg *pb.ProgressCfg, progressHolder ProgressHolder) bool
- func (m *ProgressMgr) GetProgressChecker(event any, progressType int32) (ProgressCheckFunc, bool)
- func (m *ProgressMgr) InitProgress(arg any, progressCfg *pb.ProgressCfg, progressHolder ProgressHolder) bool
- func (m *ProgressMgr) IsMatchEvent(event any, progressType int32) bool
- func (m *ProgressMgr) Register(progressType int32, event any, checker ProgressCheckFunc)
- func (m *ProgressMgr) RegisterDefault(progressType int32, event ...any)
- func (m *ProgressMgr) RegisterWithInit(progressType int32, event any, checker ProgressCheckFunc, ...)
- type PropertyInt32
- type RedisConfig
- type ServerInfo
- type ServerList
- func (this *ServerList) AddListUpdateHook(...)
- func (this *ServerList) ConnectServer(ctx context.Context, info *pb.ServerInfo)
- func (this *ServerList) FindAndConnectServers(ctx context.Context)
- func (this *ServerList) GetLocalServerInfo() *pb.ServerInfo
- func (this *ServerList) GetServerConnection(serverId int32) gnet.Connection
- func (this *ServerList) GetServerConnectionHandler() *gnet.DefaultConnectionHandler
- func (this *ServerList) GetServerInfo(serverId int32) *pb.ServerInfo
- func (this *ServerList) GetServerListenerHandler() *gnet.DefaultConnectionHandler
- func (this *ServerList) GetServersByType(serverType string) []*pb.ServerInfo
- func (this *ServerList) NewAdaptPacket(cmd gnet.PacketCommand, message proto.Message) gnet.Packet
- func (this *ServerList) OnServerConnected(serverId int32, connection gnet.Connection)
- func (this *ServerList) OnServerConnectorDisconnect(serverId int32)
- func (this *ServerList) RegisterLocalServerInfo()
- func (this *ServerList) Rpc(serverId int32, request gnet.Packet, reply proto.Message, ...) error
- func (this *ServerList) Send(serverId int32, cmd gnet.PacketCommand, message proto.Message, ...) bool
- func (this *ServerList) SendPacket(serverId int32, packet gnet.Packet, opts ...gnet.SendOption) bool
- func (this *ServerList) SetCache(cache gentity.KvCache)
- func (this *ServerList) SetFetchAndConnectServerTypes(serverTypes ...string)
- func (this *ServerList) SetFetchServerTypes(serverTypes ...string)
- func (this *ServerList) StartListen(ctx context.Context, serverListenAddr string) gnet.Listener
- type TimeLimited
- type Uniquely
Constants ¶
const ( // 客户端回调接口函数名前缀 ClientHandlerMethodNamePrefix = "On" // 其他回调接口函数名前缀 HandlerMethodNamePrefix = "Handle" // 事件响应接口函数名前缀 EventHandlerMethodNamePrefix = "Trigger" // 事件分发嵌套层次限制 SameEventLoopLimit = int32(3) )
const ( ServerType_Login = "Login" ServerType_Game = "Game" ServerType_Gate = "Gate" )
Variables ¶
This section is empty.
Functions ¶
func DefaultProgressChecker ¶
func DefaultProgressChecker(event any, progressCfg *pb.ProgressCfg) int32
默认的进度检查接口
Types ¶
type ActivityMgr ¶
type Bag ¶
type Bag interface { // 背包容量 GetCapacity() int32 // 获取物品数量 GetItemCount(itemCfgId int32) int32 // 添加物品,返回实际添加数量 AddItem(arg *pb.AddItemArg) int32 // 删除指定数量物品,返回实际删除数量 DelItem(arg *pb.DelItemArg) int32 }
背包通用操作接口
type BaseActivity ¶
type BaseActivity struct {
Id int32
}
func (*BaseActivity) GetId ¶
func (this *BaseActivity) GetId() int32
type BaseServer ¶
type BaseServer struct {
// contains filtered or unexported fields
}
服务器基础流程
func NewBaseServer ¶
func NewBaseServer(ctx context.Context, serverType string, configFile string) *BaseServer
func (*BaseServer) AddServerHook ¶
func (this *BaseServer) AddServerHook(hooks ...gentity.ApplicationHook)
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) 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) NewAdaptPacket ¶
func (this *BaseServer) NewAdaptPacket(cmd PacketCommand, message proto.Message) Packet
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
发消息给另一个服务器
type BaseServerConfig ¶
type BaseServerConfig struct { // 服务器id ServerId int32 `yaml:"ServerId"` Client ListerConfig `yaml:"Client"` Gate ListerConfig `yaml:"Gate"` Server ListerConfig `yaml:"Server"` Mongo MongoConfig `yaml:"Mongo"` Redis RedisConfig `yaml:"Redis"` }
type ConditionCheckFunc ¶
type ConditionCheckFunc func(arg any, conditionCfg *pb.ConditionCfg) bool
条件检查接口
type ConditionMgr ¶
type ConditionMgr struct {
// contains filtered or unexported fields
}
条件相关接口管理
func NewConditionMgr ¶
func NewConditionMgr() *ConditionMgr
func (*ConditionMgr) CheckConditions ¶
func (m *ConditionMgr) CheckConditions(arg any, conditions []*pb.ConditionCfg) bool
func (*ConditionMgr) GetConditionChecker ¶
func (m *ConditionMgr) GetConditionChecker(conditionType int32) ConditionCheckFunc
func (*ConditionMgr) Register ¶
func (m *ConditionMgr) Register(conditionType int32, checker ConditionCheckFunc)
注册条件检查接口
type EventPlayerEntryGame ¶
玩家进游戏事件
type ListerConfig ¶
type ListerConfig struct {
Addr string `yaml:"Addr"`
}
type MongoConfig ¶
type PacketHandlerInfo ¶
type PacketHandlerInfo struct { // 组件名,如果为空,就表示是直接写在Entity上的接口 ComponentName string // req消息号 Cmd gnet.PacketCommand // res消息号 ResCmd gnet.PacketCommand // res消息type ResMessageElem reflect.Type // 函数信息 Method reflect.Method }
消息回调接口信息
type PacketHandlerMgr ¶
type PacketHandlerMgr struct {
HandlerInfos map[gnet.PacketCommand]*PacketHandlerInfo
}
消息回调接口管理类
func NewPacketHandlerMgr ¶
func NewPacketHandlerMgr() *PacketHandlerMgr
func (*PacketHandlerMgr) AddHandlerInfo ¶
func (this *PacketHandlerMgr) AddHandlerInfo(handlerInfo *PacketHandlerInfo)
注册消息回调
func (*PacketHandlerMgr) AutoRegister ¶
func (this *PacketHandlerMgr) AutoRegister(entity gentity.Entity, methodNamePrefix string)
自动注册消息回调接口类型是func (this *Component) OnFinishQuestReq(cmd PacketCommand, req *pb.XxxMessage)的回调
根据proto的命名规则和组件里消息回调的格式,通过反射自动生成消息的注册 类似Java的注解功能 用于服务器内部的逻辑消息 可以在组件里编写函数: HandleXxx(cmd PacketCommand, req *pb.Xxx)
func (*PacketHandlerMgr) AutoRegisterWithClient ¶
func (this *PacketHandlerMgr) AutoRegisterWithClient(entity gentity.Entity, packetHandlerRegister gnet.PacketHandlerRegister, clientHandlerPrefix, otherHandlerPrefix string)
自动注册消息回调接口类型是func (this *Component) OnFinishQuestReq(cmd PacketCommand, req *pb.XxxMessage)的回调,并注册PacketHandler,一般用于服务器监听客户端的连接
根据proto的命名规则和消息回调的格式,通过反射自动生成消息的注册 类似Java的注解功能 游戏常见有2类消息 1.客户端的请求消息 可以在组件里编写函数: OnXxx(cmd PacketCommand, req *pb.Xxx) 2.服务器内部的逻辑消息 可以在组件里编写函数: HandleXxx(cmd PacketCommand, req *pb.Xxx)
type ProgressCheckFunc ¶
type ProgressCheckFunc func(event any, progressCfg *pb.ProgressCfg) int32
进度检查接口 返回事件触发时的进度 example:
进度: 抽卡100次 事件: 抽卡(5连抽) 进度+5
type ProgressHolder ¶
进度读取接口
type ProgressInitFunc ¶
type ProgressInitFunc func(arg any, progressCfg *pb.ProgressCfg) int32
进度初始化接口 返回初始进度
type ProgressMgr ¶
type ProgressMgr struct {
// contains filtered or unexported fields
}
进度相关接口管理
func NewProgressMgr ¶
func NewProgressMgr() *ProgressMgr
func (*ProgressMgr) CheckProgress ¶
func (m *ProgressMgr) CheckProgress(event any, progressCfg *pb.ProgressCfg, progressHolder ProgressHolder) bool
检查事件是否触发进度的更新,并更新进度
func (*ProgressMgr) GetProgressChecker ¶
func (m *ProgressMgr) GetProgressChecker(event any, progressType int32) (ProgressCheckFunc, bool)
获取事件,进度对应的检查接口
func (*ProgressMgr) InitProgress ¶
func (m *ProgressMgr) InitProgress(arg any, progressCfg *pb.ProgressCfg, progressHolder ProgressHolder) bool
初始化进度,更新初始进度
examples: 任务举例:玩家升级到10级,当5级玩家接任务时,初始进度就是5/10
func (*ProgressMgr) IsMatchEvent ¶
func (m *ProgressMgr) IsMatchEvent(event any, progressType int32) bool
检查事件是否关联某个进度
func (*ProgressMgr) Register ¶
func (m *ProgressMgr) Register(progressType int32, event any, checker ProgressCheckFunc)
注册事件和进度检查接口 checker可以为nil
func (*ProgressMgr) RegisterDefault ¶
func (m *ProgressMgr) RegisterDefault(progressType int32, event ...any)
注册默认的进度检查接口
func (*ProgressMgr) RegisterWithInit ¶
func (m *ProgressMgr) RegisterWithInit(progressType int32, event any, checker ProgressCheckFunc, init ProgressInitFunc)
注册事件和进度检查接口
checker: 进度检查接口,可以为nil init: 初始化时,更新当前进度,可以为nil
type PropertyInt32 ¶
type RedisConfig ¶
type ServerInfo ¶
服务器信息接口
type ServerList ¶
type ServerList struct {
// contains filtered or unexported fields
}
服务器列表管理 每个服务器定时上传自己的信息到redis,其他服务器定时从redis获取整个服务器集群的信息 属于服务注册和发现的功能,zookeeper的临时节点更适合来实现这类需求 这里用redis来实现,pb.ServerInfo.LastActiveTime记录服务器最后上传信息的时间,达到类似"心跳检测"的效果
func NewServerList ¶
func NewServerList(serverInfo *pb.ServerInfo) *ServerList
func (*ServerList) AddListUpdateHook ¶
func (this *ServerList) AddListUpdateHook(onListUpdateFunc ...func(serverList map[string][]*pb.ServerInfo, oldServerList map[string][]*pb.ServerInfo))
添加服务器列表更新回调
func (*ServerList) ConnectServer ¶
func (this *ServerList) ConnectServer(ctx context.Context, info *pb.ServerInfo)
连接其他服务器(包括自己),我方作为connector
func (*ServerList) FindAndConnectServers ¶
func (this *ServerList) FindAndConnectServers(ctx context.Context)
服务发现: 读取服务器列表信息,并连接这些服务器
func (*ServerList) GetLocalServerInfo ¶
func (this *ServerList) GetLocalServerInfo() *pb.ServerInfo
自己的服务器信息
func (*ServerList) GetServerConnection ¶
func (this *ServerList) GetServerConnection(serverId int32) gnet.Connection
获取服务器的连接
func (*ServerList) GetServerConnectionHandler ¶
func (this *ServerList) GetServerConnectionHandler() *gnet.DefaultConnectionHandler
func (*ServerList) GetServerInfo ¶
func (this *ServerList) GetServerInfo(serverId int32) *pb.ServerInfo
获取某个服务器的信息
func (*ServerList) GetServerListenerHandler ¶
func (this *ServerList) GetServerListenerHandler() *gnet.DefaultConnectionHandler
func (*ServerList) GetServersByType ¶
func (this *ServerList) GetServersByType(serverType string) []*pb.ServerInfo
获取某类服务器的信息列表
func (*ServerList) NewAdaptPacket ¶
func (this *ServerList) NewAdaptPacket(cmd gnet.PacketCommand, message proto.Message) gnet.Packet
func (*ServerList) OnServerConnected ¶
func (this *ServerList) OnServerConnected(serverId int32, connection gnet.Connection)
其他服务器连接上,我方作为listener
func (*ServerList) OnServerConnectorDisconnect ¶
func (this *ServerList) OnServerConnectorDisconnect(serverId int32)
服务器连接断开了
func (*ServerList) RegisterLocalServerInfo ¶
func (this *ServerList) RegisterLocalServerInfo()
服务注册:上传本地服务器的信息
func (*ServerList) Rpc ¶
func (this *ServerList) Rpc(serverId int32, request gnet.Packet, reply proto.Message, opts ...gnet.SendOption) error
func (*ServerList) Send ¶
func (this *ServerList) Send(serverId int32, cmd gnet.PacketCommand, message proto.Message, opts ...gnet.SendOption) bool
发消息给另一个服务器
func (*ServerList) SendPacket ¶
func (this *ServerList) SendPacket(serverId int32, packet gnet.Packet, opts ...gnet.SendOption) bool
func (*ServerList) SetCache ¶
func (this *ServerList) SetCache(cache gentity.KvCache)
func (*ServerList) SetFetchAndConnectServerTypes ¶
func (this *ServerList) SetFetchAndConnectServerTypes(serverTypes ...string)
设置要获取并连接的服务器类型
func (*ServerList) SetFetchServerTypes ¶
func (this *ServerList) SetFetchServerTypes(serverTypes ...string)
设置要获取的服务器类型
func (*ServerList) StartListen ¶
开始监听服务器