玩家支持切换连接

This commit is contained in:
kercylan98 2023-05-22 09:57:02 +08:00
parent 5ee465c17e
commit 1616352bb9
2 changed files with 14 additions and 0 deletions

View File

@ -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...)

View File

@ -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)