基本游戏玩家和登录扩展实现

This commit is contained in:
kercylan98
2023-04-22 13:21:13 +08:00
parent e584d85231
commit 973ea1fd3d
3 changed files with 74 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
package builtin
import "minotaur/server"
func NewPlayer[ID comparable](id ID, conn *server.Conn) *Player[ID] {
return &Player[ID]{
id: id,
conn: conn,
}
}
// Player 游戏玩家
type Player[ID comparable] struct {
id ID
conn *server.Conn
}
func (slf *Player[ID]) GetID() ID {
return slf.id
}
// Send 向该玩家发送数据
func (slf *Player[ID]) Send(packet []byte) error {
return slf.conn.Write(packet)
}
// Close 关闭玩家
func (slf *Player[ID]) Close() {
slf.conn.Close()
}