Files
bl/common/socket/kick.go

71 lines
1.4 KiB
Go
Raw Normal View History

package socket
import (
"blazing/common/socket/errorcode"
"blazing/cool"
"blazing/logic/service/common"
"blazing/logic/service/player"
"context"
"fmt"
"time"
)
type Broadcast struct {
Name string
}
func (s *Server) Broadcast(t string) int {
cool.Logger.Info(context.TODO(), "全服广播", t)
var count int
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
count++
value.SendPackCmd(50003, &Broadcast{
Name: t,
})
return false
})
return count
}
func (s *Server) KickPerson(a int) error {
cool.Logger.Info(context.TODO(), "检测到踢人请求", a)
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 {
value.Kick(1)
return false
})
} else {
go func() {
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
head := common.NewTomeeHeader(1001, value.Info.UserID)
head.Result = uint32(errorcode.ErrorCodes.ErrXinPlanSleepMode)
value.SendPack(head.Pack(nil))
return false
})
<-time.After(10 * time.Minute)
player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
value.Kick(1)
return false
})
}()
}
return nil
}