2025-10-10 23:59:54 +08:00
|
|
|
package socket
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"blazing/logic/service/player"
|
|
|
|
|
"fmt"
|
2026-02-10 13:05:45 +08:00
|
|
|
"os"
|
2026-01-25 03:40:29 +08:00
|
|
|
"time"
|
2025-10-10 23:59:54 +08:00
|
|
|
)
|
|
|
|
|
|
2025-11-25 16:36:55 +08:00
|
|
|
type Broadcast struct {
|
|
|
|
|
Name string
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-08 23:57:22 +08:00
|
|
|
func (s *Server) Broadcast(t string) int {
|
2026-02-02 01:01:01 +08:00
|
|
|
|
2025-11-25 16:36:55 +08:00
|
|
|
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
2026-02-02 01:01:01 +08:00
|
|
|
|
2025-11-25 16:36:55 +08:00
|
|
|
value.SendPackCmd(50003, &Broadcast{
|
|
|
|
|
Name: t,
|
|
|
|
|
})
|
2026-02-02 01:01:01 +08:00
|
|
|
return true
|
2025-11-25 16:36:55 +08:00
|
|
|
})
|
|
|
|
|
|
2026-02-02 01:01:01 +08:00
|
|
|
return player.Mainplayer.Count()
|
2025-11-25 16:36:55 +08:00
|
|
|
}
|
2026-02-02 01:01:01 +08:00
|
|
|
|
|
|
|
|
const kickTimeout = 5 * time.Second
|
|
|
|
|
|
2026-01-08 23:57:22 +08:00
|
|
|
func (s *Server) KickPerson(a int) error {
|
2026-02-02 18:32:41 +08:00
|
|
|
|
2025-11-03 15:30:41 +00:00
|
|
|
if a == 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2025-10-16 12:16:03 +08:00
|
|
|
|
2026-02-02 23:11:14 +08:00
|
|
|
return player.KickPlayer(uint32(a))
|
2025-10-10 23:59:54 +08:00
|
|
|
}
|
2025-10-26 15:12:29 +08:00
|
|
|
|
|
|
|
|
// 参数不为0是强制踢出
|
2026-01-08 23:57:22 +08:00
|
|
|
func (s *Server) QuitSelf(a int) error {
|
2025-10-10 23:59:54 +08:00
|
|
|
//TODO 这里待退出
|
|
|
|
|
fmt.Println("检测到退出请求")
|
2025-10-26 14:56:29 +08:00
|
|
|
|
2026-02-16 03:02:59 +08:00
|
|
|
s.quit = true
|
2025-10-26 15:12:29 +08:00
|
|
|
if a != 0 {
|
|
|
|
|
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
2026-02-04 19:43:05 +08:00
|
|
|
if value != nil {
|
2026-02-07 00:18:14 +08:00
|
|
|
value.Kick(true)
|
2026-02-04 19:43:05 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-25 17:36:40 +08:00
|
|
|
return false
|
2025-10-26 15:12:29 +08:00
|
|
|
})
|
2026-01-25 03:40:29 +08:00
|
|
|
} else {
|
|
|
|
|
go func() {
|
2026-01-25 17:36:40 +08:00
|
|
|
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
2026-02-04 19:43:05 +08:00
|
|
|
if value != nil {
|
|
|
|
|
value.KickMessage()
|
|
|
|
|
}
|
2026-01-25 17:36:40 +08:00
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
|
2026-01-25 03:40:29 +08:00
|
|
|
<-time.After(10 * time.Minute)
|
|
|
|
|
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
|
2026-02-04 19:43:05 +08:00
|
|
|
if value != nil {
|
2026-02-07 00:18:14 +08:00
|
|
|
value.Kick(true)
|
2026-02-04 19:43:05 +08:00
|
|
|
}
|
2026-02-10 13:05:45 +08:00
|
|
|
os.Exit(0)
|
2026-01-25 17:36:40 +08:00
|
|
|
return false
|
2026-01-25 03:40:29 +08:00
|
|
|
})
|
|
|
|
|
}()
|
2025-10-26 15:12:29 +08:00
|
|
|
}
|
2025-10-26 14:56:29 +08:00
|
|
|
|
2025-10-10 23:59:54 +08:00
|
|
|
return nil
|
|
|
|
|
}
|