component

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Game Call Hall module
	//ROUND_OVER  牌局结束  example: Hall.RoundOver    s.RPC(ROUND_OVER,&gamepb.RoundOver{})   每一轮 游戏结束请求大厅做结算和清除动作
	RPCROUND_OVER = "Hall.RPCRoundOver"

	//每一轮结算  目前是单个玩家请求一次
	// s.RPC(RPCSettle,&gamepb.PlayerSettle{})
	RPCSETTLE = "Hall.RPCSettle"
	// Hall  Call  Game module
	//RPC_BEGIN  开始游戏  example: Xxx.RPCBegin   Xxx 对应子游戏路由前缀
	RPC_BEGIN = "RPCBegin"
	//RPC_REJOIN 登陆重新断线重连 example: Xxx.RPCReJoin
	RPC_REJOIN = "RPCReJoin"

	// Deprecated  由于需求中不要观看玩家该函数为过期函数 RPC_Enter 玩家中途进入游戏 只需要将玩家加入到 group 会话分组里面
	RPC_Enter = "RPCEnter"
	// Deprecated  由于需求中不要观看玩家该函数为过期函数
	RPC_WATCH_LEAVE = "RPCWatchLeave"
	// Deprecated  由于需求中不要观看玩家该函数为过期函数 玩家坐下   需要将玩家添加到牌桌玩家列表上面
	RPC_SITDOWN = "RPCSitdown"

	//RPC_RECONNECT   预留  重新连接 example: Xxx.RPC_RECONNECT
	RPC_RECONNECT = "RPCReConnect"
	//RPC_DISSOLVE 正常解散
	RPC_DISSOLVE = "RPCDissolve"
	//RPC_FORCE_DISSOLVE 强制解散
	RPC_FORCE_DISSOLVE = "RPCForceDissolve"
)

Variables

View Source
var (
	TypeOfSessions = reflect.TypeOf(([]*session.Session)(nil))
)

Functions

This section is empty.

Types

type Base

type Base struct{}

Base implements a default component for Component.

func (*Base) AfterInit

func (c *Base) AfterInit()

AfterInit was called after the component is initialized.

func (*Base) BeforeShutdown

func (c *Base) BeforeShutdown()

BeforeShutdown was called before the component to shutdown.

func (*Base) Init

func (c *Base) Init()

Init was called to initialize the component.

func (*Base) Name

func (c *Base) Name() string

Name

func (*Base) SchedName

func (c *Base) SchedName() string

SchedName

func (*Base) Shutdown

func (c *Base) Shutdown()

Shutdown was called to shutdown the component.

type CompWithOptions

type CompWithOptions struct {
	Comp Component
	Opts []Option
}

type Component

type Component interface {
	Init()
	AfterInit()
	BeforeShutdown()
	Shutdown()
	Name() string
	SchedName() string
}

Component is the interface that represent a component.

type Components

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

func Comps

func Comps(comps ...Component) *Components

Comps 组件注册 Example:

Comps(NewComponent1(),NewComponent2(),NewComponent2())

func (*Components) List

func (cs *Components) List() []CompWithOptions

List returns all components with it's options

func (*Components) Register

func (cs *Components) Register(c Component, options ...Option)

Register registers a component to hub with options

type GameBase

type GameBase struct{}

func (*GameBase) AfterInit

func (c *GameBase) AfterInit()

AfterInit was called after the component is initialized.

func (*GameBase) BeforeShutdown

func (c *GameBase) BeforeShutdown()

BeforeShutdown was called before the component to shutdown.

func (*GameBase) Init

func (c *GameBase) Init()

Init was called to initialize the component.

func (*GameBase) SchedName

func (c *GameBase) SchedName() string

func (*GameBase) Shutdown

func (c *GameBase) Shutdown()

Shutdown was called to shutdown the component.

type GameComponent

type GameComponent interface {
	Component
	// 开始游戏
	RPCBegin([]*session.Session, *gamepb.Begin) error
	// 重新登陆断线重连 牌桌信息 总共三部分数据  1. 房间基本信息   2.玩家列表 基本信息 位置 数据   3. 牌桌数据(牌桌状态 玩家牌组)
	RPCReJoin(*session.Session, *gamepb.ReJoin) error

	//游戏场景内重新连接    房间号 牌桌号 玩家编号
	RPCReConnect(*session.Session, *gamepb.ReConnect) error
	// 玩家挂后台     房间号 牌桌号 玩家编号
	RPCPause(*session.Session, *gamepb.Pause) error
	// 玩家切后台回来 房间号 牌桌号 玩家编号
	RPCResume(*session.Session, *gamepb.Resume) error
	// 正常解散 房间号 牌桌号
	RPCDissolve(*session.Session, *gamepb.Dissolve) error
	// 强制解散   房间号 牌桌号
	RPCForceDissolve(*session.Session, *gamepb.ForceDissolve) error

	// Deprecated  由于需求中不要观看玩家该函数为过期函数   玩家中途进入 需要同步牌桌数据  3. 牌桌数据 将玩家放入到观看列表中
	RPCEnter(*session.Session, []byte) error
	// Deprecated 由于需求中不要观看玩家该函数为过期函数 观看玩家离开 需求不需要观看玩家
	RPCWatchLeave(*session.Session, []byte) error
	// Deprecated 由于需求中不要观看玩家该函数为过期函数 房间玩家找位置坐下  给当前玩家在牌桌分配一个位置 需求不需要观看玩家
	RPCSitDown(*session.Session, []byte) error
}

type Handler

type Handler struct {
	Receiver reflect.Value  // receiver of method
	Method   reflect.Method // method stub
	Type     reflect.Type   // arg type of method
	IsRawArg bool           // whether the data need to unserialize
}

Handler represents a message.Message's handler's meta information.

type Option

type Option func(options *options)

Option used to customize handler

func WithName

func WithName(name string) Option

WithName used to rename component name

func WithNameFunc

func WithNameFunc(fn func(string) string) Option

WithNameFunc override handler name by specific function such as: strings.ToUpper/strings.ToLower

func WithSchedulerName

func WithSchedulerName(name string) Option

WithSchedulerName set the name of the service scheduler

type Service

type Service struct {
	Name      string              // name of service
	Type      reflect.Type        // type of the receiver
	Receiver  reflect.Value       // receiver of methods for the service
	Handlers  map[string]*Handler // registered methods
	SchedName string              // name of scheduler variable in session data
	Options   options             // options
}

Service implements a specific service, some of it's methods will be called when the correspond events is occurred.

func NewService

func NewService(comp Component, opts []Option) *Service

func (*Service) ExtractHandler

func (s *Service) ExtractHandler() error

ExtractHandler extract the set of methods from the receiver value which satisfy the following conditions: - exported method of exported type - two arguments, both of exported type - the first argument is *session.Session - the second argument is []byte or a pointer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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