74 lines
1.2 KiB
Go
74 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)
|
|
}
|
|
os.Exit(0)
|
|
return false
|
|
})
|
|
}()
|
|
}
|
|
|
|
return nil
|
|
}
|