This commit is contained in:
hahwu 2026-03-16 16:09:39 +08:00
parent 0020a4af8c
commit 4caadbf837
2 changed files with 37 additions and 7 deletions

View File

@ -510,6 +510,14 @@ func (ad *GameLogic) SendServerVersion(a gate.Agent) {
}
func (ad *GameLogic) ClearData(args []interface{}) {
G_GameLogicPtr.M_Players.Range(func(k, v interface{}) bool {
v.(*Player).PushAndSendClienRes(&msg.ForceKickOut{})
v.(*Player).ClearData()
v = nil
log.Debug("palyer %d 断开连接 写入数据", k)
return true
})
return
player := args[0].(*Player)
if player != nil && player.M_DwUin != 0 {
player.agent = nil

View File

@ -65,6 +65,9 @@ type Player struct {
activity map[int]*ActivityInfo
stop bool
wg sync.WaitGroup
dispatcherWg sync.WaitGroup
stopOnce sync.Once
msgChanOnce sync.Once
func_time int
}
@ -79,19 +82,25 @@ type PlayerMsg struct {
}
func (p *Player) Stop() {
select {
case <-p.stopSignal:
// 通道已经关闭
return
default:
p.wg.Wait()
close(p.stopSignal)
p.wg.Wait()
p.stopDispatcherLoop()
p.msgChanOnce.Do(func() {
close(p.msgChan)
})
for _, timer := range p.timerList {
timer.Stop()
}
p.McronSave.Stop()
p.stop = true
}
func (p *Player) stopDispatcherLoop() {
p.stopOnce.Do(func() {
close(p.stopSignal)
})
p.dispatcherWg.Wait()
}
func (p *Player) CallEvent(Duration time.Duration, F func(), Label string) {
if v, ok := p.timerList[Label]; ok {
v.Stop()
@ -213,6 +222,8 @@ func (p *Player) InitPlayer(UserName string) error {
p.timerList = make(map[string]*timer.Timer)
p.MDispatr = timer.NewDispatcher(100)
p.stopSignal = make(chan bool)
p.stopOnce = sync.Once{}
p.msgChanOnce = sync.Once{}
Base := &PlayerBaseData{p: p}
// 玩家基础数据
@ -272,6 +283,8 @@ func (p *Player) InitPlayerByUid(Uid int) error {
p.timerList = make(map[string]*timer.Timer)
p.MDispatr = timer.NewDispatcher(100)
p.stopSignal = make(chan bool)
p.stopOnce = sync.Once{}
p.msgChanOnce = sync.Once{}
Base := &PlayerBaseData{p: p}
// 玩家基础数据
@ -1010,6 +1023,8 @@ func (p *Player) InitPlayerOnly() {
p.timerList = make(map[string]*timer.Timer)
p.MDispatr = timer.NewDispatcher(10)
p.stopSignal = make(chan bool)
p.stopOnce = sync.Once{}
p.msgChanOnce = sync.Once{}
Base := &PlayerBaseData{p: p}
@ -1347,7 +1362,9 @@ func (p *Player) func_exec_add() error {
}
func (p *Player) DispatcherHandle() {
p.dispatcherWg.Add(1)
go func() {
defer p.dispatcherWg.Done()
var cb *timer.Timer
for {
select {
@ -1372,6 +1389,11 @@ func (p *Player) DispatcherHandle() {
}()
}
func (p *Player) StopDispatcher() {
p.wg.Wait()
p.stopDispatcherLoop()
}
func CheckPlayerLose(Uid int) bool {
FriendSimpleData := G_GameLogicPtr.GetSimplePlayerByUid(Uid)
if FriendSimpleData == nil {