feat: 增强踢人逻辑与BOSS脚本支持
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

优化踢人超时处理和僵尸连接清理,支持BOSS动作脚本并增加测试,修复事件匹配与战斗循环中的并发问题。
This commit is contained in:
xinian
2026-04-05 21:59:22 +08:00
committed by cnb
parent 36dd93b076
commit c021b40fbe
16 changed files with 457 additions and 151 deletions

View File

@@ -7,6 +7,7 @@ import (
"encoding/binary"
"encoding/hex"
"sync"
"sync/atomic"
"context"
@@ -102,6 +103,10 @@ func putPacketData(buf []byte) {
}
func (h *ClientData) PushEvent(v []byte, submit func(task func()) error) {
if h == nil || h.IsClosed() {
return
}
var header common.TomeeHeader
header.Len = binary.BigEndian.Uint32(v[0:4])
header.CMD = binary.BigEndian.Uint32(v[5:9])
@@ -111,9 +116,18 @@ func (h *ClientData) PushEvent(v []byte, submit func(task func()) error) {
copy(header.Data, v[17:])
}
_ = submit(func() {
h.LF.Producer().Write(header)
err := submit(func() {
if h.IsClosed() || h.LF == nil || !h.LF.Running() {
putPacketData(header.Data)
return
}
if err := h.LF.Producer().Write(header); err != nil {
putPacketData(header.Data)
}
})
if err != nil {
putPacketData(header.Data)
}
}
// 重写
@@ -241,6 +255,20 @@ type ClientData struct {
Wsmsg *WsCodec
Conn gnet.Conn
LF *lockfree.Lockfree[common.TomeeHeader]
closed int32
}
func (p *ClientData) IsClosed() bool {
return atomic.LoadInt32(&p.closed) == 1
}
func (p *ClientData) Close() {
if !atomic.CompareAndSwapInt32(&p.closed, 0, 1) {
return
}
if p.LF != nil && p.LF.Running() {
_ = p.LF.Close()
}
}
func (p *ClientData) GetPlayer(userid uint32) *Player { //TODO 这里待优化,可能存在内存泄漏问题