feat(common): 添加 WebSocket 支持
- 在 ClientData 结构中添加 WsCodec 字段 - 实现 WebSocket 升级和消息处理逻辑 - 添加 WebSocket 相关的依赖包
This commit is contained in:
@@ -7,6 +7,8 @@ type ClientData struct {
|
||||
player *Player //客户实体
|
||||
//UserID uint32
|
||||
m sync.Mutex
|
||||
|
||||
wsmsg WsCodec
|
||||
}
|
||||
|
||||
func (cd *ClientData) SetPlayer(player *Player) {
|
||||
@@ -19,6 +21,11 @@ func (cd *ClientData) GetPlayer() *Player {
|
||||
defer cd.m.Unlock()
|
||||
return cd.player
|
||||
}
|
||||
func (cd *ClientData) Getwsmsg() *WsCodec {
|
||||
cd.m.Lock()
|
||||
defer cd.m.Unlock()
|
||||
return &cd.wsmsg
|
||||
}
|
||||
func (cd *ClientData) SetCrossDomain(isCrossDomain bool) {
|
||||
cd.m.Lock()
|
||||
defer cd.m.Unlock()
|
||||
@@ -35,6 +42,7 @@ func NewClientData() *ClientData {
|
||||
isCrossDomain: false,
|
||||
player: nil,
|
||||
m: sync.Mutex{},
|
||||
wsmsg: WsCodec{},
|
||||
}
|
||||
return &cd
|
||||
|
||||
|
||||
Reference in New Issue
Block a user