internal

package
v0.0.0-...-3945403 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 客户端回调接口函数名前缀
	ClientHandlerMethodNamePrefix = "On"
	// 其他回调接口函数名前缀
	HandlerMethodNamePrefix = "Handle"
	// 事件响应接口函数名前缀
	EventHandlerMethodNamePrefix = "Trigger"
	// 事件分发嵌套层次限制
	SameEventLoopLimit = int32(3)
)
View Source
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

默认的进度检查接口

func GetTimeoutTimestamp

func GetTimeoutTimestamp(timeType, timeout int32) int32

计算超时时间戳

func PacketToGuildRoutePacket

func PacketToGuildRoutePacket(fromPlayerId int64, fromPlayerName string, reqPacket gnet.Packet, guildId int64) gnet.Packet

玩家对公会的请求消息转换成路由消息

原始消息基础上再加上一些附加数据
client -> game.Guild -> social.Guild

func RouteGuildServerId

func RouteGuildServerId(guildId int64) int32

根据公会id查找对应的服务器

Types

type Activity

type Activity interface {
	GetId() int32
	// 响应事件
	OnEvent(event interface{})
	// 日期更新
	OnDateChange(oldDate time.Time, curDate time.Time)
	// 活动结束时的处理
	OnEnd(t time.Time)

	// 提供一个统一的属性值查询接口
	GetPropertyInt32(propertyName string) int32
}

type ActivityMgr

type ActivityMgr interface {
	GetActivity(activityId int32) Activity
}

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) Run

func (this *BaseServer) Run(ctx context.Context)

运行

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 CfgData

type CfgData interface {
	GetCfgId() int32
}

配置数据提供一个统一的接口,以方便做一些统一的处理

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 EventDateChange

type EventDateChange struct {
	OldDate time.Time
	CurDate time.Time
}

日期更新

type EventPlayerEntryGame

type EventPlayerEntryGame struct {
	IsReconnect    bool
	OfflineSeconds int32 // 离线时长
}

玩家进游戏事件

type EventPlayerExit

type EventPlayerExit struct {
}

玩家退出游戏

type IPlayer

type IPlayer interface {
	gentity.Entity

	// 玩家名
	GetName() string

	// 账号id
	GetAccountId() int64

	// 区服id
	GetRegionId() int32

	SendPacket(packet gnet.Packet, opts ...gnet.SendOption) bool
}

type ListerConfig

type ListerConfig struct {
	Addr string `yaml:"Addr"`
}

type MongoConfig

type MongoConfig struct {
	Uri string `yaml:"Uri"`
	Db  string `yaml:"Db"`
}

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)

func (*PacketHandlerMgr) Invoke

func (this *PacketHandlerMgr) Invoke(entity gentity.Entity, packet gnet.Packet, processReturnValues func(*PacketHandlerInfo, []reflect.Value)) bool

执行注册的消息回调接口 return true表示执行了接口 return false表示未执行

type PlayerMgr

type PlayerMgr interface {
	GetPlayer(playerId int64) IPlayer
	AddPlayer(player IPlayer)
	RemovePlayer(player IPlayer)
}

type ProgressCheckFunc

type ProgressCheckFunc func(event any, progressCfg *pb.ProgressCfg) int32

进度检查接口 返回事件触发时的进度 example:

进度: 抽卡100次
事件: 抽卡(5连抽)
进度+5

type ProgressHolder

type ProgressHolder interface {
	GetProgress() int32
	SetProgress(progress int32)
}

进度读取接口

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 PropertyInt32 interface {
	GetPropertyInt32(propertyName string) int32
}

type RedisConfig

type RedisConfig struct {
	Uri      []string `yaml:"Uri"`
	UserName string   `yaml:"UserName"`
	Password string   `yaml:"Password"`
	Cluster  bool     `yaml:"Cluster"`
}

type ServerInfo

type ServerInfo interface {
	GetServerId() int32
	GetServerType() string
	GetLastActiveTime() int64
}

服务器信息接口

type ServerList

type ServerList struct {
	// contains filtered or unexported fields
}

服务器列表管理 每个服务器定时上传自己的信息到redis,其他服务器定时从redis获取整个服务器集群的信息 属于服务注册和发现的功能,zookeeper的临时节点更适合来实现这类需求 这里用redis来实现,pb.ServerInfo.LastActiveTime记录服务器最后上传信息的时间,达到类似"心跳检测"的效果

func GetServerList

func GetServerList() *ServerList

singleton

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

func (this *ServerList) StartListen(ctx context.Context, serverListenAddr string) gnet.Listener

开始监听服务器

type TimeLimited

type TimeLimited interface {
	// 超时时间戳
	GetTimeout() int32
}

限时类对象

type Uniquely

type Uniquely interface {
	// 配置id
	GetCfgId() int32
	// uuid
	GetUniqueId() int64
}

有唯一id的对象

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL