atsf4g_go_robot_user

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefaultUserLogHandler added in v1.1.7

func CreateDefaultUserLogHandler(openId string) func(format string, a ...any)

func LogoutAllUsers added in v1.1.5

func LogoutAllUsers()

LogoutAllUsers 登出并清理所有在线用户

func OnUserLogin added in v1.1.7

func OnUserLogin()

func OnUserLogout added in v1.1.7

func OnUserLogout()

func OnlineUserCount added in v1.1.5

func OnlineUserCount() int

OnlineUserCount 返回当前在线用户数

func UserContainerDelUser added in v1.0.1

func UserContainerDelUser(holder *UserHolder)

Types

type CreateUserFuncType added in v1.1.5

type CreateUserFuncType func(openId string, logHandler func(format string, a ...any),
	enableActorLog bool, unpack UserReceiveUnpackFunc, createMsg UserReceiveCreateMessageFunc,
	connectFn conn.NewConnectFunc) User

type MessageHandlerFunc added in v1.2.0

type MessageHandlerFunc func(*TaskActionUser, *pu.LazyUnmarshalProtobufMessage, int32) error

type RPCRingBuffer added in v1.1.7

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

RPCRingBuffer 是基于环形数组的 RPC 等待队列,替代 sync.Map。 以 sequence % capacity 为索引,支持 Store / Load+Delete。 当 slot 被占用(sequence 冲突)时返回错误,调用方应确保 capacity 足够大。

func NewRPCRingBuffer added in v1.1.7

func NewRPCRingBuffer(capacity int) *RPCRingBuffer

NewRPCRingBuffer 创建指定容量的环形缓冲区。capacity 必须为 2 的幂。

func (*RPCRingBuffer) Delete added in v1.1.7

func (r *RPCRingBuffer) Delete(sequence uint64)

Delete 删除 sequence 对应的 slot。

func (*RPCRingBuffer) Load added in v1.1.7

func (r *RPCRingBuffer) Load(sequence uint64) (base.TaskActionImpl, bool)

Load 读取 sequence 对应的 task(不删除)。

func (*RPCRingBuffer) LoadAndDelete added in v1.1.7

func (r *RPCRingBuffer) LoadAndDelete(sequence uint64) (base.TaskActionImpl, bool)

LoadAndDelete 读取并删除 sequence 对应的 task。

func (*RPCRingBuffer) Store added in v1.1.7

func (r *RPCRingBuffer) Store(sequence uint64, task base.TaskActionImpl) error

Store 将 task 存入 sequence 对应的 slot。 如果 slot 已被不同 sequence 占用,返回错误。

func (*RPCRingBuffer) StoreBlocking added in v1.1.7

func (r *RPCRingBuffer) StoreBlocking(sequence uint64, task base.TaskActionImpl)

StoreBlocking 将 task 存入 sequence 对应的 slot。 如果 slot 已被不同 sequence 占用,会自旋等待直到 slot 释放。

type TaskActionUser

type TaskActionUser struct {
	base.TaskActionBase
	User User
	Fn   func(*TaskActionUser) error
}

func (*TaskActionUser) AfterYield

func (t *TaskActionUser) AfterYield() error

func (*TaskActionUser) BeforeYield

func (t *TaskActionUser) BeforeYield() error

func (*TaskActionUser) HookRun

func (t *TaskActionUser) HookRun() error

func (*TaskActionUser) IsTakenActionGuard added in v1.1.14

func (t *TaskActionUser) IsTakenActionGuard() bool

func (*TaskActionUser) Log

func (t *TaskActionUser) Log(format string, a ...any)

type User

type User interface {
	IsLogin() bool
	Login()
	Logout()

	AllocSequence() uint64
	ReceiveHandler(unpack UserReceiveUnpackFunc, createMsg UserReceiveCreateMessageFunc)
	SendReq(action base.TaskActionImpl, csMsg proto.Message, csHead proto.Message,
		csBody proto.Message, rpcName string, sequence uint64, needRsp bool) (int32, *pu.LazyUnmarshalProtobufMessage, error)

	TakeActionGuard(task base.TaskActionImpl) error
	ReleaseActionGuard(task base.TaskActionImpl) error
	IsTakenActionGuard(task base.TaskActionImpl) bool

	AwaitReceiveHandlerClose(task base.TaskActionImpl) error

	RunTask(timeout time.Duration, f func(*TaskActionUser) error, name string) *TaskActionUser
	RunTaskDefaultTimeout(f func(*TaskActionUser) error, name string) *TaskActionUser
	AddOnClosedHandler(f func(User))
	Log(format string, a ...any)
	InitHeartbeatFunc(func(User) error)

	GetLogined() bool
	GetOpenId() string
	GetAccessToken() string
	GetUserId() uint64
	GetZoneId() uint32

	SetUserId(uint64)
	SetZoneId(uint32)
	SetHeartbeatInterval(time.Duration)
	SetLastPingTime(time.Time)
	SetHasGetInfo(bool)
	RegisterMessageHandler(rpcName string, f MessageHandlerFunc)

	GetExtralData(key string) any
	SetExtralData(key string, value any)
}

func CreateUser

func CreateUser(openId string, logHandler func(format string, a ...any), enableActorLog bool) User

func GetAllUsers added in v1.1.7

func GetAllUsers() []User

type UserHolder added in v1.1.7

type UserHolder struct {
	OpenId      string
	PrivateData any
	// contains filtered or unexported fields
}

func UserContainerGetUser added in v1.0.1

func UserContainerGetUser(openId string) *UserHolder

func UserContainerTryGetUser added in v1.1.7

func UserContainerTryGetUser(openId string) *UserHolder

func (*UserHolder) GetUser added in v1.1.14

func (h *UserHolder) GetUser() User

func (*UserHolder) InitUser added in v1.1.14

func (h *UserHolder) InitUser(u User)

func (*UserHolder) IsUserVaildLogin added in v1.1.7

func (h *UserHolder) IsUserVaildLogin() bool

type UserReceiveCreateMessageFunc

type UserReceiveCreateMessageFunc func() proto.Message

type UserReceiveUnpackFunc

type UserReceiveUnpackFunc func(proto.Message) (
	rpcName string,
	typeName string,
	errorCode int32,
	msgHead proto.Message,
	bodyBin []byte,
	sequence uint64,
	err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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