global

package
v0.0.0-...-0012533 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Login服务器使用
	RedisName_Login = "LoginRedis"
	// 放db服的缓存数据,同group用一个
	RedisName_DBPlayer = "DBPlayerRedis"
	// 所有服务器都可访问,放用户会话信息
	RedisName_Session = "SessionRedis"
	// 对象路由信息,服务器上所有对象的状态信息等,同group用一个
	RedisName_Entity = "EntityRedis"
)
View Source
const (
	//服务器之间的连接信息
	ListenType_Inner = "Inner"
	//面向客户端的连接信息
	ListenType_Outer = "Outer"
	//面向服务器之间的Http信息
	ListenType_Http = "Http"
)

连接信息类型

View Source
const (
	//全服务器的公共组ID为0,像Login服务器、GM服务器等,还有些单例服务器,甚至跨全服务器的活动服务器
	GroupGlobalID uint32 = 0
)

Variables

This section is empty.

Functions

func GetDbserviceRedis

func GetDbserviceRedis() *redislib.RedisHandleModel

GetDbserviceRedis redis连接 放db服的缓存数据,同group用一个

func GetEntityRedis

func GetEntityRedis() *redislib.RedisHandleModel

GetEntityRedis redis连接 对象路由信息,服务器上所有对象的状态信息等,同othergroup用一个

func GetLoginRedis

func GetLoginRedis() *redislib.RedisHandleModel

GetLoginRedis redis连接 Login服务器使用

func GetRedisConfigList

func GetRedisConfigList(vmap, vsrv *viper.Viper) (result map[string]*RedisCfg)

获取需要连接的redis

func GetSessionRedis

func GetSessionRedis() *redislib.RedisHandleModel

GetSessionRedis redis连接 所有服务器都可访问,放用户会话信息

func GetValidSrvPort

func GetValidSrvPort(minPort, maxPort int) string

func GetValidSrvPortInt

func GetValidSrvPortInt(minPort, maxPort int) int

GetValidSrvPortInt 根据传入的最小端口和最大端口号,找一个可用端口,返回一个可用来绑定的地址

func GetWatchList

func GetWatchList(vmap *viper.Viper, key string) (result []uint32)

获取需要连接监听等信息的解析

func SetRedisByName

func SetRedisByName(name string, v *redislib.RedisAccess)

Types

type EtcdCfg

type EtcdCfg struct {
	Addrs       []string      //etcd集群地址
	DialTimeout time.Duration //连接请求超时时间默认为5秒(秒)
	LeaseTTL    int64         //租约时间(秒)
}

ETCD配置

type GlobalConfig

type GlobalConfig struct {
	ServerConfig

	Recover        bool          //是否Recover
	EncryptEnabled bool          //与客户端这间是否加密
	SessTimeout    time.Duration // 服务器连接超时时间 用于连接过来的sess超时时间
	SessTicker     time.Duration // 服务器连接心跳时间 用于连接别人的sess心跳时间
	EtcdCfg        EtcdCfg       //etcd配置
	Debug          bool          //是否开起pprof的模式,用与查bug使用
	LogFile        string        //Log的配置文件

}

服务器主动链接别的服务器的管理器

// 简单实现服务器配置的结构,实际上层可以不使用它 // 这个主要是给一些测试用的配置,给单例一个默认的实现

func LoadServerConfig

func LoadServerConfig(vmap *viper.Viper, sname string, stype ServerTypeEnum) (result *GlobalConfig)

获取NewServer需要的参数

func (*GlobalConfig) GetDefType

func (this *GlobalConfig) GetDefType() ServerTypeEnum

属性同步用到的服务器类型

func (*GlobalConfig) GetFrameDeltaTime

func (this *GlobalConfig) GetFrameDeltaTime() time.Duration

服务器每帧的时间

func (*GlobalConfig) GetGroupID

func (this *GlobalConfig) GetGroupID() uint32

服务器组ID

func (*GlobalConfig) GetRecover

func (this *GlobalConfig) GetRecover() bool

是否在异常时恢复

func (*GlobalConfig) GetServerID

func (this *GlobalConfig) GetServerID() uint64

服务器唯一ID

func (*GlobalConfig) GetSessTicker

func (this *GlobalConfig) GetSessTicker() time.Duration

服务器连接心跳时间 用于连接别人的sess心跳时间

func (*GlobalConfig) GetSessTimeout

func (this *GlobalConfig) GetSessTimeout() time.Duration

服务器连接超时时间 用于连接过来的sess超时时间

func (*GlobalConfig) GetSrvName

func (this *GlobalConfig) GetSrvName() string

服务器名字

func (*GlobalConfig) GetSrvType

func (this *GlobalConfig) GetSrvType() ServerTypeEnum

服务器类型

type ISrvConfig

type ISrvConfig interface {
	//是否在异常时恢复
	GetRecover() bool
	//服务器名字
	GetSrvName() string
	//服务器组ID
	GetGroupID() uint32
	//服务器唯一ID
	GetServerID() uint64
	//服务器类型
	GetSrvType() ServerTypeEnum
	//属性同步用到的服务器类型 场景服务器需要重载这个方法返回 ServerTypeSpace
	GetDefType() ServerTypeEnum

	//服务器每帧的时间
	GetFrameDeltaTime() time.Duration
	//服务器连接超时时间 用于连接过来的sess超时时间
	GetSessTimeout() time.Duration
	//服务器连接心跳时间 用于连接别人的sess心跳时间
	GetSessTicker() time.Duration
}

服务器实例配置

func GetCfgInst

func GetCfgInst() ISrvConfig

服务器实例配置 单例

func SetCfgInst

func SetCfgInst(inst ISrvConfig) ISrvConfig

type IsrvInst

type IsrvInst interface {
	// 操作子协程的管理器
	GetThreadGo() *threads.ThreadGo
	//获取服务器当前繁忙状态0-100
	GetLoad() int
	//服务器是否可用
	IsSrvValid() bool
	//服务器不可用的时候,的处理函数
	HandlerSrvInvalid(eid uint64)
	//获取新的EntityID
	GetNewEID() uint64
	//获取新的DBID
	GetNewDBID() uint64

	// 发消息给其他服务器的对象
	PostMsgToEntity(srvid, spid, eid uint64, msg msgdef.IMsg) (err error)
	// 通过目标服务器发消息给客户端
	PostMsgToClient(srvid, spid, eid uint64, msg msgdef.IMsg) (err error)
	// 通过目标服务器发消息给客户端
	PostMsgToClientBuf(srvid, spid, eid uint64, data []byte) (err error)
	// 发消息到目标服务器
	PostSess(srvid uint64, msg msgdef.IMsg)

	// 主协程调用
	Run()
}

服务器级状态

func GetSrvInst

func GetSrvInst() IsrvInst

服务器级状态单例

func SetSrvInst

func SetSrvInst(inst IsrvInst) IsrvInst

type ListenCfg

type ListenCfg struct {
	Listen  string //监听地址
	Addr    string //注册地址,让别人连接自己的地址,会注册到ETCD上
	MaxConn int    //连接数
}

监听地址

func GetListen

func GetListen(vmap *viper.Viper, key string) (result *ListenCfg)

获取连接信息

type MysqlConfig

type MysqlConfig struct {
	MySQLUser         string
	MySQLPwd          string
	MySQLAddr         string
	MySQLDB           string
	MySQLMaxIdleConns int
	MySQLMaxOpenConns int
	MySQLMaxLifetime  time.Duration
}

数据库配置信息

func (*MysqlConfig) ToDataSource

func (c *MysqlConfig) ToDataSource() string

type RedisCfg

type RedisCfg struct {
	Name        string //使用的名字
	Addr        string //地址信息
	Index       int    //库的索引号
	MaxIdle     int    //保留最多空闲个数
	IdleTimeout int    //空闲连接超时时间(秒)
	MaxActive   int    //最大活跃连接
	Password    string //密码
}

Redis配置

type ServerConfig

type ServerConfig struct {
	MysqlConfig
	SrvName             string                //服务器名字
	ServerID            uint64                //服务器ID
	SrvType             ServerTypeEnum        //服务器类型
	GroupID             uint32                //服务器组ID
	OthGroupID          uint32                //对应公共组ID
	ConSrvTypeList      []uint32              //需要连接的服务器类型
	WatchSrvTypeList    []uint32              //需要关注的服务器类型
	OthConSrvTypeList   []uint32              //需要连接的公共组服务器类型
	OthWatchSrvTypeList []uint32              //需要关注的公共组服务器类型
	ListenMap           map[string]*ListenCfg //地址信息
	RedisMap            map[string]*RedisCfg  //redis配置

	FrameDeltaTime time.Duration //服务器帧间隔(毫秒)
	DebugAddr      string        //开起pprof的模式的地址
}

服务器连接配置

type ServerTypeEnum

type ServerTypeEnum = uint32

服务器类型

const (
	//没有类型
	ServerTypeDefault ServerTypeEnum = iota
	// ServerTypeGateway 网关服
	ServerTypeGateway

	// ServerTypeClient 客户端
	ServerTypeClient

	// ServerTypeSpace  带场景的服务器
	ServerTypeSpace
)

Jump to

Keyboard shortcuts

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