core

package
v0.0.0-...-643218b Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 9 Imported by: 13

Documentation

Index

Constants

View Source
const (
	PLAIN_CONTENT = "plain"
	ALGO_AES      = "aes"
	ALGO_XXX_TEA  = "xxtea"
	// 加密的 header key
	X_CRYPTO_ALGO = "_x_crypto_algo"
)

Variables

This section is empty.

Functions

func Contains

func Contains[K comparable](array []K, ele K) bool

func CopyMap

func CopyMap[K comparable, V any](src map[K]V, SkipKeys ...K) map[K]V

func GenSimpleUUIDStr

func GenSimpleUUIDStr() string

without -

func GenUUIDStr

func GenUUIDStr() string

func LastSuffixAfterDot

func LastSuffixAfterDot(s string) string

func StartService

func StartService(ctx context.Context, services ...IService)

Types

type Hashable

type Hashable interface {
	~string | ~int | ~int64 | ~uint64 | ~uint32 | ~int32
}

type IAnno

type IAnno interface {
	Reg(cmdCode int32, pb proto.Message)
	Instance(cmdCode int32, bytes []byte) (proto.Message, error)
}

func NewAnnoProto

func NewAnnoProto() IAnno

func NewAnnoProtoType

func NewAnnoProtoType() IAnno

type IMgr

type IMgr[T any] interface {
	Id() string

	Add(T)

	Remove(T)

	Get(string) T
}

type IPlayer

type IPlayer[PK Hashable] interface {
	Id() PK

	Load()

	Unload()

	ReplaceBy(IPlayer[PK])

	Read(netty.Message)

	Write(netty.Message)
}

玩家对象的接口

type IPlayerMgr

type IPlayerMgr[PK Hashable, T IPlayer[PK]] interface {
	IService

	Id() string

	// 加入
	Join(T)

	// 退出
	Quit(T)

	Read(netty.HandlerContext, netty.Message)

	// 推送数据 async=false 为同步发送,async=true 为异步发送 写数据
	Write(msg netty.Message, async bool)

	// 向特定的玩家的id集合推送数据
	WriteToIds(ids []PK, msg netty.Message, async bool)

	WritePredicateById(predicate func(PK) bool, msg netty.Message, async bool)

	WritePredicateByPlayer(predicate func(T) bool, msg netty.Message, async bool)
}

玩家服 管理玩家资源

type IRoom

type IRoom[PK Hashable, T IPlayer[PK]] interface {
	IPlayerMgr[PK, T]
}

房间 针对房间服 管理房间资源

type IScene

type IScene[PK Hashable, T IPlayer[PK]] interface {
	IPlayerMgr[PK, T]
}

场景 针对场景服 管理场景资源

type ISceneMgr

type ISceneMgr[PK Hashable, P IPlayer[PK], T IScene[PK, P]] interface {
	IMgr[T]
}

type IService

type IService interface {
	Start(context.Context) error
	Stop() error
	Name() string
	Id() string
}

服务

type ITeam

type ITeam[PK Hashable, T IPlayer[PK]] interface {
	IPlayerMgr[PK, T]
}

队伍

type ITeamMgr

type ITeamMgr[PK Hashable, P IPlayer[PK], T IRoom[PK, P]] interface {
	IMgr[T]
}

type IUnion

type IUnion[PK Hashable, T IPlayer[PK]] interface {
	IPlayerMgr[PK, T]
}

联盟

type IUnionMgr

type IUnionMgr[PK Hashable, P IPlayer[PK], T IUnion[PK, P]] interface {
	IMgr[T]
}

type IWorld

type IWorld interface {
	IService
}

世界 包含服务器一切资源

Jump to

Keyboard shortcuts

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