refactor(socket): 更新广播和退出逻辑中的类型引用 更新socket服务器中广播功能和退出功能的代码, 将player.Player类型替换为player.ClientData类型, 并相应调整方法调用以适应新的数据结构。 feat(map): 添加LoadOrStore方法支持 在并发安全的swiss map中新增LoadOrStore方法, 提供原子性的加载或存储功能,增强map的操作能力。 refactor(login): 优化登录逻辑中的玩家获取方式 重构登录控制器中获取玩家对象的方式, 直接从
76 lines
1.2 KiB
Go
76 lines
1.2 KiB
Go
package socket
|
|
|
|
import (
|
|
"blazing/logic/service/player"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type Broadcast struct {
|
|
Name string
|
|
}
|
|
|
|
func (s *Server) Broadcast(t string) int {
|
|
|
|
player.Mainplayer.Range(func(key uint32, value *player.ClientData) bool {
|
|
|
|
value.Player.SendPackCmd(50003, &Broadcast{
|
|
Name: t,
|
|
})
|
|
return true
|
|
})
|
|
|
|
return player.Mainplayer.Count()
|
|
}
|
|
|
|
const kickTimeout = 5 * time.Second
|
|
|
|
func (s *Server) KickPerson(a int) error {
|
|
|
|
if a == 0 {
|
|
return nil
|
|
}
|
|
|
|
return player.KickPlayer(uint32(a))
|
|
}
|
|
|
|
// 参数不为0是强制踢出
|
|
func (s *Server) QuitSelf(a int) error {
|
|
//TODO 这里待退出
|
|
fmt.Println("检测到退出请求")
|
|
|
|
s.quit = true
|
|
if a != 0 {
|
|
player.Mainplayer.Range(func(key uint32, value *player.ClientData) bool {
|
|
if value != nil {
|
|
value.Player.Kick(true)
|
|
}
|
|
|
|
return false
|
|
})
|
|
} else {
|
|
|
|
go func() {
|
|
player.Mainplayer.Range(func(key uint32, value *player.ClientData) bool {
|
|
if value != nil {
|
|
value.Player.KickMessage()
|
|
}
|
|
return false
|
|
})
|
|
|
|
<-time.After(10 * time.Minute)
|
|
player.Mainplayer.Range(func(key uint32, value *player.ClientData) bool {
|
|
if value != nil {
|
|
value.Player.Kick(true)
|
|
}
|
|
|
|
return false
|
|
})
|
|
os.Exit(0)
|
|
}()
|
|
}
|
|
|
|
return nil
|
|
}
|