gate

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLockAliveTime  = 10000 // 单个锁的最大存活时间 毫秒
	LockRetryWaitTime = 50    // 同步加锁重试间隔时间 毫秒
	MaxLockRetryTimes = 2     // 同步加锁最大重试次数
)
View Source
const (
	PacketMaxLen            = 343 * 1024 // 最大应用层包长度
	KcpConnAddrChangeNotify = "KcpConnAddrChangeNotify"
)

Variables

View Source
var CLIENT_CONN_NUM int32 = 0 // 当前客户端连接数
View Source
var QPS int64

Functions

func SendHandle

func SendHandle(p *PlayerGame, kcpMsg *alg.PackMsg)

发送事件处理

Types

type GateServer

type GateServer struct {
	AppId     uint32
	WorkerId  int64
	Port      string
	InnerAddr string
	OuterAddr string
	Config    *config.Config
	Store     *Store

	Ec2b *random.Ec2b

	Ticker *time.Ticker
	Stop   chan struct{}
	// contains filtered or unexported fields
}

func NewGate

func NewGate(cfg *config.Config, appid string) *GateServer

func (*GateServer) AutoDelPlayer added in v1.2.1

func (s *GateServer) AutoDelPlayer()

玩家超时离线

func (*GateServer) Close added in v1.2.1

func (s *GateServer) Close() error

func (*GateServer) GlobalRotationEvent5s added in v1.2.1

func (s *GateServer) GlobalRotationEvent5s()

func (*GateServer) NewGame

func (s *GateServer) NewGame(kcpConn *kcp.UDPSession) *PlayerGame

func (*GateServer) PlayerGetTokenCsReq added in v1.0.5

func (s *GateServer) PlayerGetTokenCsReq(p *PlayerGame, playerMsg []byte)

func (*GateServer) RunKcp added in v1.2.1

func (s *GateServer) RunKcp() error

type HandlerFunc added in v1.2.1

type HandlerFunc func(tcpMsg *alg.PackMsg)

type KcpEvent

type KcpEvent struct {
	SessionId    uint32
	EventId      string
	EventMessage any
}

type NodeService added in v1.2.1

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

func (*NodeService) GateToNodePingReq added in v1.2.2

func (n *NodeService) GateToNodePingReq()

func (*NodeService) GateToNodePingRsp added in v1.2.2

func (n *NodeService) GateToNodePingRsp(serviceMsg pb.Message)

func (*NodeService) ServiceConnectionReq added in v1.2.1

func (n *NodeService) ServiceConnectionReq()

向node注册

func (*NodeService) ServiceConnectionRsp added in v1.2.1

func (n *NodeService) ServiceConnectionRsp(serviceMsg pb.Message)

type PlayerGame

type PlayerGame struct {
	Status         spb.PlayerStatus
	Uid            uint32 // uid
	AccountId      uint32
	Seed           uint64
	XorKey         []byte // 密钥
	KcpConn        *kcp.UDPSession
	LastActiveTime uint64 // 最近一次的活跃时间
	RouteManager   *RouteManager
	// contains filtered or unexported fields
}

func (*PlayerGame) ApplyFriendCsReq added in v1.2.2

func (p *PlayerGame) ApplyFriendCsReq(tcpMsg *alg.PackMsg)

func (*PlayerGame) GateToGame

func (p *PlayerGame) GateToGame(tcpMsg *alg.PackMsg)

将玩家消息转发到game

func (*PlayerGame) GateToPlayer added in v1.2.1

func (p *PlayerGame) GateToPlayer(cmdId uint16, playerMsg pb.Message)

将消息发送给客户端

func (*PlayerGame) HandleFriendCsReq added in v1.2.2

func (p *PlayerGame) HandleFriendCsReq(tcpMsg *alg.PackMsg)

func (*PlayerGame) HandlePlayerHeartBeatCsReq

func (p *PlayerGame) HandlePlayerHeartBeatCsReq(tcpMsg *alg.PackMsg)

玩家ping包处理

func (*PlayerGame) PlayerLogoutCsReq added in v1.2.1

func (p *PlayerGame) PlayerLogoutCsReq(tcpMsg *alg.PackMsg)

玩家主动离线处理

func (*PlayerGame) PlayerRegisterMessage

func (p *PlayerGame) PlayerRegisterMessage(cmdId uint16, tcpMsg *alg.PackMsg)

func (*PlayerGame) SendMsgCsReq added in v1.2.2

func (p *PlayerGame) SendMsgCsReq(tcpMsg *alg.PackMsg)

type RouteManager added in v1.2.1

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

func NewRouteManager added in v1.2.1

func NewRouteManager(p *PlayerGame) (r *RouteManager)

type Store

type Store struct {
	PlayerUidMysql *gorm.DB
	LoginRedis     *redis.Client
	StatusRedis    *redis.Client
	// contains filtered or unexported fields
}

func NewStore

func NewStore(config *config.Config) *Store

NewStore 创建一个新的 store。

func (*Store) DistLockSync added in v1.0.5

func (s *Store) DistLockSync(accountId string) bool

DistLockSync 加锁同步阻塞直到成功或超时

func (*Store) DistUnlock added in v1.0.5

func (s *Store) DistUnlock(accountId string)

DistUnlock 解锁

func (*Store) DistUnlockPlayerStatus added in v1.2.1

func (s *Store) DistUnlockPlayerStatus(accountId string)

删除玩家状态

func (*Store) GetComboTokenByAccountId added in v1.0.5

func (s *Store) GetComboTokenByAccountId(accountId string) string

根据accounid拉取combotoken

func (*Store) GetPlayerStatus added in v1.0.5

func (s *Store) GetPlayerStatus(accountId string) ([]byte, bool)

获取玩家状态

func (*Store) GetPlayerUidByAccountId added in v1.0.5

func (s *Store) GetPlayerUidByAccountId(AccountId uint32) *database.PlayerUid

使用account id拉取数据

func (*Store) UpdatePlayerUid added in v1.0.5

func (s *Store) UpdatePlayerUid(AccountId uint32) *database.PlayerUid

指定account id 创建数据

Jump to

Keyboard shortcuts

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