重构
This commit is contained in:
61
common/data/socket/Client.go
Normal file
61
common/data/socket/Client.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package socket
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
func ConutPlayer() int {
|
||||
|
||||
count := 0
|
||||
Mainplayer.Range(func(uint32, *Player) bool {
|
||||
count++
|
||||
return true // 继续遍历
|
||||
})
|
||||
return count
|
||||
}
|
||||
|
||||
type ClientData struct {
|
||||
isCrossDomain bool //是否跨域过
|
||||
player *Player //客户实体
|
||||
//UserID uint32
|
||||
m sync.Mutex
|
||||
|
||||
wsmsg WsCodec
|
||||
}
|
||||
|
||||
func (cd *ClientData) SetPlayer(player *Player) {
|
||||
cd.m.Lock()
|
||||
defer cd.m.Unlock()
|
||||
cd.player = player
|
||||
}
|
||||
func (cd *ClientData) GetPlayer() *Player {
|
||||
cd.m.Lock()
|
||||
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()
|
||||
cd.isCrossDomain = isCrossDomain
|
||||
}
|
||||
func (cd *ClientData) GetIsCrossDomain() bool {
|
||||
cd.m.Lock()
|
||||
defer cd.m.Unlock()
|
||||
return cd.isCrossDomain
|
||||
}
|
||||
|
||||
func NewClientData() *ClientData {
|
||||
cd := ClientData{
|
||||
isCrossDomain: false,
|
||||
player: nil,
|
||||
m: sync.Mutex{},
|
||||
wsmsg: WsCodec{},
|
||||
}
|
||||
return &cd
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user