global

package
v0.0.0-...-6c2d201 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: BSD-4-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Login服务器使用 用于保存账号和角色基础信息 全局唯一
	RedisName_Login = "LoginRedis"
	// 用于缓存玩家落地数据 与DBservice同级
	RedisName_Data = "DataRedis"
	// 存放登录后的会话信息,使用哪个Gateway等信息 全局唯一
	RedisName_Session = "SessionRedis"
	// Entity对象的会话信息,主要保存路由信息 可互访Entity同级
	RedisName_Entity = "EntityRedis"
)
View Source
const (
	//服务器之间的连接信息
	ListenType_Inner = "Inner"
	//面向客户端的连接信息
	ListenType_Outer = "Outer"
	//面向服务器之间的Http信息
	ListenType_Http = "Http"
)

连接信息类型

View Source
const (
	Expire7Day = 7 * 24 * time.Hour // 7天有效期
	Expire3Day = 3 * 24 * time.Hour // 3天有效期
	Expire1Day = 1 * 24 * time.Hour // 1天有效期

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

Variables

View Source
var (
	Gitcommit string
	Version   string
	Built     string
	Branch    string
)

build 时给ldflags 赋值使用的变量

View Source
var (
	// 请求超时
	Err_TimeOut = common.NewError(-1, "timeout")
)

Functions

func CheckVersion

func CheckVersion() bool

检查是否需要打印版本信息

func GetRedisAccess

func GetRedisAccess(key string) *redislib.RedisAccess

redis连接池 单例 获取

func GetRedisConfigList

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

获取需要连接的redis

func GetRedisConn

func GetRedisConn(key string) *redislib.RedisHandleModel

redis连接池 单例 获取

func GetWatchList

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

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

func PostSrv

func PostSrv(
	srvid uint64, msg msgdef.IMsg,
	options ...srvOptionF,
) error

请求其他服务器消息,不等回复,也不需要处理

func PostSrvAsync

func PostSrvAsync(
	srvid uint64, msg msgdef.IMsg,
	fcall RouteCallBackF,
	options ...srvOptionF,
)

异步请求别的服务器事务,设置回复消息

func PostSrvSync

func PostSrvSync(
	srvid uint64, msg msgdef.IMsg,
	options ...srvOptionF,
) (result *protomsg.RouteMsgSrvRet, err error)

同步请求别的服务器事务

func PostSrvSyncByRouteReq

func PostSrvSyncByRouteReq(srvid uint64, srvreq *protomsg.RouteMsgSrvReq) (result *protomsg.RouteMsgSrvRet, err error)

func PrintConfig

func PrintConfig()

打印服务器配置信息

func PrintVersion

func PrintVersion()

打印版本信息

func SetRedisByName

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

func SrvSetEID

func SrvSetEID(spid, eid uint64) srvOptionF

设置消息处理的实体ID

func SrvSetIsRetClient

func SrvSetIsRetClient(v bool) srvOptionF

设置是否需要回复客户端

func SrvSetOrderID

func SrvSetOrderID(orderid uint64) srvOptionF

设置消息事务订单号

func SrvSetPID

func SrvSetPID(pid uint64) srvOptionF

设置消息的处理的角色ID

func SrvSetPrefix

func SrvSetPrefix(prefix string) srvOptionF

设置消息事务前缀

Types

type DBConfig

type DBConfig struct {
	Addr          string            `json:"Addr,omitempty"`          //地址信息
	User          string            `json:"User,omitempty"`          //用户名
	Pwd           string            `json:"Pwd,omitempty"`           //密码
	DB            string            `json:"DB,omitempty"`            //数据库名字
	MaxIdle       int               `json:"MaxIdle,omitempty"`       //保留最多空闲个数
	MaxOpen       int               `json:"MaxOpen,omitempty"`       //最大活跃连接
	MaxLifetime   time.Duration     `json:"MaxLifetime,omitempty"`   //连接最大存活时间
	SlowThreshold time.Duration     `json:"SlowThreshold,omitempty"` // 慢查询时间(毫秒)
	SubDBList     map[uint64]string `json:"SubDBList,omitempty"`     //分库列表 key:GroupID value:DBName
}

数据库配置信息

func (*DBConfig) ToMongoSource

func (this *DBConfig) ToMongoSource() string

func (*DBConfig) ToMysqlSource

func (this *DBConfig) ToMysqlSource() string

func (*DBConfig) ToPostgreSQLSource

func (this *DBConfig) ToPostgreSQLSource() string

type EtcdCfg

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

ETCD配置

type GlobalConfig

type GlobalConfig struct {
	ServerConfig

	Recover        bool `json:"Recover,omitempty"`        //是否Recover
	Debug          bool `json:"Debug,omitempty"`          //是否开起pprof的模式,用与查bug使用
	IsCreateDB     bool `json:"IsCreateDB,omitempty"`     //是否创建数据库表
	EncryptEnabled bool `json:"EncryptEnabled,omitempty"` //与客户端这间是否加密

	SessTimeout time.Duration `json:"SessTimeout,omitempty"` // 服务器连接超时时间 用于连接过来的sess超时时间
	SessTicker  time.Duration `json:"SessTicker,omitempty"`  // 服务器连接心跳时间 用于连接别人的sess心跳时间
	EtcdCfg     EtcdCfg       `json:"EtcdCfg,omitempty"`     //etcd配置

}

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

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

func LoadServerConfig

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

获取NewServer需要的参数

func (*GlobalConfig) GetDebug

func (this *GlobalConfig) GetDebug() bool

是否开启debug

func (*GlobalConfig) GetDefType

func (this *GlobalConfig) GetDefType() ServerTypeEnum

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

func (*GlobalConfig) GetFrameDeltaTime

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

服务器每帧的时间

func (*GlobalConfig) GetGroupID

func (this *GlobalConfig) GetGroupID() uint64

服务器组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
	// 是否开启debug
	GetDebug() bool

	//服务器名字
	GetSrvName() string
	//服务器组ID
	GetGroupID() uint64
	//服务器唯一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
	//Loop时的时间
	GetNowTime() time.Time
	//服务器是否可用
	IsSrvValid() bool
	// //服务器不可用的时候,的处理函数
	// HandlerSrvInvalid(eid uint64)
	//获取新的唯一ID
	GetNewEID() uint64
	// 获取等待回复的map
	GetWaitMap() *sync.Map

	// 发消息给其他服务器的对象
	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 `json:"Listen,omitempty"`  //监听地址
	Addr    string `json:"Addr,omitempty"`    //注册地址,让别人连接自己的地址,会注册到ETCD上
	PortMin int    `json:"PortMin,omitempty"` //最小端口
	PortMax int    `json:"PortMax,omitempty"` //最大端口
	MaxConn int    `json:"MaxConn,omitempty"` //连接数
}

监听地址

func GetListen

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

获取连接信息

type MysqlConfig deprecated

type MysqlConfig struct {
	MySQLUser         string            `json:"MySQLUser,omitempty"`
	MySQLPwd          string            `json:"MySQLPwd,omitempty"`
	MySQLAddr         string            `json:"MySQLAddr,omitempty"`
	MySQLDB           string            `json:"MySQLDB,omitempty"`
	MySQLMaxIdleConns int               `json:"MySQLMaxIdleConns,omitempty"`
	MySQLMaxOpenConns int               `json:"MySQLMaxOpenConns,omitempty"`
	MySQLMaxLifetime  time.Duration     `json:"MySQLMaxLifetime,omitempty"`
	SlowThreshold     time.Duration     `json:"SlowThreshold,omitempty"` // 慢查询时间(毫秒)
	SubDBList         map[uint64]string `json:"SubDBList,omitempty"`     //分库列表 key:GroupID value:DBName
}

Deprecated: 数据库配置信息 弃用MysqlConfig

func (*MysqlConfig) ToDataSource

func (c *MysqlConfig) ToDataSource() string

Mysql配置的链接字符串

func (*MysqlConfig) ToMongoSource

func (c *MysqlConfig) ToMongoSource() string

MongoDB配置的链接字符串

type RedisCfg

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

Redis配置

type RouteCallBackF

type RouteCallBackF = func(msgret *protomsg.RouteMsgSrvRet, err error)

type ServerConfig

type ServerConfig struct {
	//Deprecated: 弃用这个配置 使用MysqlMap 把Mysql配置放到Map中
	MysqlConfig MysqlConfig

	SrvName             string                  `json:"SrvName,omitempty"`             //服务器名字
	Number              uint64                  `json:"Number,omitempty"`              // 服务器编号
	ServerID            uint64                  `json:"ServerID,omitempty"`            //服务器ID
	SrvType             ServerTypeEnum          `json:"SrvType,omitempty"`             //服务器类型
	GroupID             uint64                  `json:"GroupID,omitempty"`             //服务器组ID
	OthGroupID          uint64                  `json:"OthGroupID,omitempty"`          //对应公共组ID
	ConSrvTypeList      []uint32                `json:"ConSrvTypeList,omitempty"`      //需要连接的服务器类型
	WatchSrvTypeList    []uint32                `json:"WatchSrvTypeList,omitempty"`    //需要关注的服务器类型
	OthConSrvTypeList   []uint32                `json:"OthConSrvTypeList,omitempty"`   //需要连接的公共组服务器类型
	OthWatchSrvTypeList []uint32                `json:"OthWatchSrvTypeList,omitempty"` //需要关注的公共组服务器类型
	ListenMap           map[string]*ListenCfg   `json:"ListenMap,omitempty"`           //地址信息
	RedisMap            map[string]*RedisCfg    `json:"RedisMap,omitempty"`            //redis配置
	MysqlMap            map[string]*MysqlConfig `json:"MysqlMap,omitempty"`            //Deprecated:mysql配置 弃用
	DBMap               map[string]*DBConfig    `json:"DBMap,omitempty"`               //数据库配置

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

服务器连接配置

type ServerTypeEnum

type ServerTypeEnum = uint32

服务器类型

const (
	//没有类型
	ServerTypeDefault ServerTypeEnum = iota
	// ServerTypeGateway 网关服
	ServerTypeGateway
	// ServerTypeClient 客户端
	ServerTypeClient
	// ServerTypeSpace  带场景的服务器
	ServerTypeSpace
	// ServerTypeDB 数据库服务器
	ServerTypeDB
)

Jump to

Keyboard shortcuts

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