``` fix(player): 优化战斗结束处理逻辑,避免线程阻塞并修复格式问题

This commit is contained in:
1
2025-10-14 15:12:08 +00:00
parent fead9ed6b5
commit fccdda3c9d
3 changed files with 9 additions and 4 deletions

View File

@@ -25,10 +25,13 @@ func (p *Player) SendNoteReadyToFightInfo(b info.NoteReadyToFightInfo) {
p.SendPack(t1.Pack(&b)) //准备包由各自发,因为协议不一样
}
func (p *Player) SendFightEndInfo(b info.FightOverInfo) {
t1 := NewTomeeHeader(2506, p.Info.UserID)
t1 := NewTomeeHeader(2506, p.Info.UserID)
p.SendPack(t1.Pack(&b))
p.FightC = nil
p.SendPack(t1.Pack(&b))
p.FightC = nil
}
func (p *Player) CatchPetInfo(b info.CatchMonsterOutboundInfo) {

View File

@@ -228,6 +228,7 @@ func (p *Player) ItemAdd(t []model.SingleItemInfo) {
}
func (p *Player) SendPack(b []byte) error {
p.MainConn.Context().(*ClientData).Mu.Lock()
defer p.MainConn.Context().(*ClientData).Mu.Unlock()
@@ -285,7 +286,7 @@ func (p *Player) Save() {
}
if p.FightC != nil {
p.FightC.Over(p, info.BattleOverReason.PlayerOffline) //玩家逃跑
go p.FightC.Over(p, info.BattleOverReason.PlayerOffline) //玩家逃跑,但是不能锁线程
}
p.Info.TimeToday = p.Info.TimeToday + uint32(time.Now().Unix()) - uint32(p.Onlinetime) //保存电池时间

View File

@@ -41,6 +41,7 @@ func KickPlayer(userid uint32) { //踢出玩家
//实际上这里有个问题,会造成重复保存问题
player1.SendPack(head.Pack(nil))
player1.MainConn.Context().(*ClientData).Mu.Lock()
player1.MainConn.Close()
player1.MainConn.Context().(*ClientData).Mu.Unlock()