internal

package
v0.0.0-...-bfc2f26 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

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

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

运行

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 CfgData

type CfgData interface {
	GetCfgId() int32
}

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

type ConditionCfg

type ConditionCfg struct {
	pb.BaseConditionCfg
	BaseProperties // 动态属性
}

条件配置数据

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 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 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 NewGateCodec(protoMessageTypeMap map[PacketCommand]reflect.Type) *GateCodec

func (*GateCodec) DecodePacket

func (this *GateCodec) DecodePacket(connection Connection, packetHeader PacketHeader, packetData []byte) Packet

func (*GateCodec) EncodePacket

func (this *GateCodec) EncodePacket(connection Connection, packet Packet) [][]byte

func (*GateCodec) Register

func (this *GateCodec) Register(command PacketCommand, protoMessage proto.Message)

注册消息和proto.Message的映射

protoMessage can be nil

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

func (this *GatePacket) Clone() Packet

deep copy

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 ProgressCfg

type ProgressCfg struct {
	pb.BaseProgressCfg
	BaseProperties // 动态属性
}

进度配置数据

type ProgressCheckFunc

type ProgressCheckFunc func(event interface{}, progressCfg *ProgressCfg) int32

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

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

type ProgressHolder

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

进度读取接口

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

type ServerList

type ServerList struct {
	gentity.BaseServerList
}

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

func GetServerList

func GetServerList() *ServerList

singleton

func NewServerList

func NewServerList() *ServerList

Jump to

Keyboard shortcuts

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