feat: 添加抢先服玩家3天未登录自动降级功能
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

修复数据包处理中UserID为0的问题
优化解包失败时的错误处理格式
添加设置用户部门ID的服务方法
This commit is contained in:
xinian
2026-02-23 00:54:47 +08:00
committed by cnb
parent 236965cc63
commit e9915f481e
4 changed files with 22 additions and 2 deletions

View File

@@ -124,6 +124,9 @@ func (h *ClientData) OnEvent(data common.TomeeHeader) {
if cool.Config.ServerInfo.IsDebug != 0 {
fmt.Println("接收数据", data.UserID, data.CMD)
}
if data.UserID == 0 {
return
}
cmdlister, ok := cool.CmdCache[data.CMD]
if !ok {
@@ -150,7 +153,7 @@ func (h *ClientData) OnEvent(data common.TomeeHeader) {
cool.Logger.Error(context.Background(), data.UserID, data.CMD, "解包失败,", err, data.Data)
//fmt.Println(data.UserID, data.CMD, "解包失败,", hex.EncodeToString(data.Data))
data.Result=uint32(errorcode.ErrorCodes.ErrSystemProcessingError)
data.Result = uint32(errorcode.ErrorCodes.ErrSystemProcessingError)
playerconn.SendPack(data.Pack(nil))
return
}

View File

@@ -17,6 +17,7 @@ import (
"github.com/deatil/go-cryptobin/cryptobin/crypto"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
type BaseSysUserController struct {
@@ -64,11 +65,20 @@ func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq)
t1 := service.NewBaseSysUserService().GetPerson(uint32(t.UserId))
res.UserID = int(t1.ID)
if blazing.NewUserService(uint32(t1.ID)).Info.IsReg() {
playerinfo := blazing.NewUserService(uint32(t1.ID))
if playerinfo.Info.IsReg() {
res.IsReg = 1
if t1.DepartmentID == 35 { ///抢先服玩家3天没登录衰退
r := playerinfo.Info.Person(uint32(t1.ID))
if r.UpdateTime.AddDate(0, 0, 3).Before(gtime.Now()) {
t1.DepartmentID = 1
service.NewBaseSysUserService().SetdepartmentId(uint32(t1.ID), 1)
}
}
}
res.PetID = dict.NewDictInfoService().GetShiny()
res.Server = config.NewServerService().GetPort(t1.DepartmentID)
// share.ShareManager.DeleteSession(t1)

View File

@@ -46,6 +46,12 @@ func (s *BaseSysUserService) GetPerson(userId uint32) (res *model.BaseSysUser) {
return
}
func (s *BaseSysUserService) SetdepartmentId(userId, departmentId uint32) (res *model.BaseSysUser) {
m := cool.DBM(s.Model)
m.Where("id", userId).Data("departmentId", departmentId).Update()
return
}
// 单位是分
func (s *BaseSysUserService) UpdateGold(userId uint32, gold int64) {

View File

@@ -74,6 +74,7 @@ func (s *ServerService) GetPort(DepartmentID uint) gdb.List {
var res gdb.Result
m := cool.DBM(s.Model).Where("is_open", 1).Fields("ip", "port", "online_id", "is_vip", "name")
if DepartmentID != 1 {
res, _ = m.All()
} else {