2025-06-23 10:15:22 +08:00
|
|
|
package entity
|
|
|
|
|
|
2025-06-24 22:09:05 +08:00
|
|
|
import (
|
|
|
|
|
"github.com/panjf2000/gnet/v2"
|
|
|
|
|
)
|
|
|
|
|
|
2025-06-23 10:15:22 +08:00
|
|
|
type Player struct {
|
2025-06-26 23:20:11 +08:00
|
|
|
UserID uint32 //用户ID
|
|
|
|
|
IsLogin bool //是否登录 //TODO 待实现登录包为第一个包,后续再发其他的包
|
|
|
|
|
Conn gnet.Conn
|
2025-06-24 22:09:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PlayerOption 定义配置 Player 的函数类型
|
|
|
|
|
type PlayerOption func(*Player)
|
|
|
|
|
|
|
|
|
|
// WithUserID 设置用户ID的选项函数
|
|
|
|
|
func WithUserID(userID uint32) PlayerOption {
|
|
|
|
|
return func(p *Player) {
|
|
|
|
|
p.UserID = userID
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func WithConn(Conn gnet.Conn) PlayerOption {
|
|
|
|
|
return func(p *Player) {
|
|
|
|
|
p.Conn = Conn
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewPlayer 使用 Options 模式创建 Player 实例
|
|
|
|
|
func NewPlayer(opts ...PlayerOption) *Player {
|
|
|
|
|
p := &Player{}
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
|
opt(p)
|
|
|
|
|
}
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Player) GetUserID() uint32 {
|
|
|
|
|
return p.UserID
|
|
|
|
|
}
|