Files
bl/common/socket/kick.go
xinian 49c15e26d3
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
refactor: 调整 QuitSelf 函数中的 goroutine 退出逻辑
2026-03-01 19:16:38 +08:00

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.Player) bool {
value.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.Player) bool {
if value != nil {
value.Kick(true)
}
return false
})
} else {
go func() {
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
if value != nil {
value.KickMessage()
}
return false
})
<-time.After(10 * time.Minute)
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
if value != nil {
value.Kick(true)
}
return false
})
os.Exit(0)
}()
}
return nil
}