diff --git a/game/builtin/player.go b/game/builtin/player.go index e13ff83..c66c2a9 100644 --- a/game/builtin/player.go +++ b/game/builtin/player.go @@ -19,6 +19,16 @@ func (slf *Player[ID]) GetID() ID { return slf.id } +func (slf *Player[ID]) UseConn(conn *server.Conn) { + if conn == nil { + return + } + if slf.conn != nil { + slf.conn.Close() + } + slf.conn = conn +} + // Send 向该玩家发送数据 func (slf *Player[ID]) Send(packet []byte, messageType ...int) { slf.conn.Write(packet, messageType...) diff --git a/game/player.go b/game/player.go index dd8ec32..ff8ffb4 100644 --- a/game/player.go +++ b/game/player.go @@ -1,9 +1,13 @@ package game +import "github.com/kercylan98/minotaur/server" + // Player 玩家 type Player[ID comparable] interface { // GetID 用户玩家ID GetID() ID + // UseConn 指定连接 + UseConn(conn *server.Conn) // Send 发送数据包 // - messageType: websocket模式中指定消息类型 Send(packet []byte, messageType ...int)