refactor(socket): 重构 ClientData 结构体并优化相关逻辑
- 简化 ClientData 结构体,移除不必要的方法 - 优化 Player 结构体,调整 Conn 类型 - 更新 wscodec.go 中的 Conn 结构体 - 删除未使用的 XML 相关文件和代码 - 调整 ServerEvent 和 controller 中的相关逻辑
This commit is contained in:
@@ -20,7 +20,7 @@ var Mainplayer = &utils.SyncMap[uint32, *Player]{} //玩家数据
|
||||
|
||||
func (c *Conn) SendPack(bytes []byte) error {
|
||||
if t, ok := c.MainConn.Context().(*ClientData); ok {
|
||||
if t.Getwsmsg().Upgraded {
|
||||
if t.Wsmsg.Upgraded {
|
||||
// This is the echo server
|
||||
err := wsutil.WriteServerMessage(c.MainConn, ws.OpBinary, bytes)
|
||||
if err != nil {
|
||||
@@ -41,7 +41,7 @@ func (c *Conn) SendPack(bytes []byte) error {
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
MainConn Conn
|
||||
MainConn *Conn
|
||||
|
||||
IsLogin bool //是否登录
|
||||
mu sync.Mutex
|
||||
@@ -58,7 +58,7 @@ type Player struct {
|
||||
// PlayerOption 定义配置 Player 的函数类型
|
||||
type PlayerOption func(*Player)
|
||||
|
||||
func WithConn(c Conn) PlayerOption {
|
||||
func WithConn(c *Conn) PlayerOption {
|
||||
return func(p *Player) {
|
||||
p.MainConn = c
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func NewPlayer(opts ...PlayerOption) *Player {
|
||||
}
|
||||
|
||||
func (p *Player) SendPack(b []byte) error {
|
||||
fmt.Println("发送数据包", len(b))
|
||||
// fmt.Println("发送数据包", len(b))
|
||||
err := p.MainConn.SendPack(b)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user