玩家支持切换连接
This commit is contained in:
parent
5ee465c17e
commit
1616352bb9
|
@ -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...)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue