fix(login): 深拷贝用户信息以避免数据竞争

在登录逻辑中,使用 `copier.CopyWithOption` 进行深拷贝,确保发送给其他玩家的
玩家信息不会因为引用同一对象而导致数据异常。同时修正了部分字段注释和默认值说明。

feat(maps): 更新地图角色信息结构体字段描述

更新 `OutInfo` 结构体中的 `Action`、`Direction` 和 `ChangeShape` 字段的注释,
使其更准确地反映其用途和含义,便于后续维护与开发理解。

fix(player): 完善登录位置判断条件

在玩家完成登录时,除了判断 `MapID > 10000` 外,增加对 `MapID == 0` 的处理,
确保角色能正确被传送到默认地图。

refactor(walk): 移除无用上下文导入并优化日志记录

移除了未使用的 `context` 包导入,并调整了行走逻辑中的赋值顺序,使代码更清晰。
同时注释掉不再需要的调试日志输出语句。
This commit is contained in:
2025-10-13 23:38:48 +08:00
parent 5e53b9caaa
commit eff23d5bd0
5 changed files with 14 additions and 14 deletions

View File

@@ -16,6 +16,7 @@ import (
"time"
"github.com/gogf/gf/v2/os/glog"
"github.com/jinzhu/copier"
)
func IsToday(t time.Time) bool {
@@ -78,14 +79,14 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c *player.Conn) (result *us
result.PlayerInfo = *t.Info
tt := maps.NewOutInfo()
//copier.Copy(t.Info, tt)
t1 := player.NewTomeeHeader(2001, t.Info.UserID)
defer func() {
tt := maps.NewOutInfo()
copier.CopyWithOption(tt, t.Info, copier.Option{DeepCopy: true})
//copier.Copy(t.Info, tt)
t1 := player.NewTomeeHeader(2001, t.Info.UserID)
space.GetSpace(t.Info.MapID).User.Set(t.Info.UserID, t)
space.GetSpace(t.Info.MapID).User.IterCb(func(playerID uint32, player common.PlayerI) {
player.SendPack(t1.Pack(&tt))
player.SendPack(t1.Pack(tt))
})

View File

@@ -51,7 +51,7 @@ func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *player.Play
result.Player = make([]maps.OutInfo, 0)
space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, player common.PlayerI) {
result1 := maps.NewOutInfo()
copier.Copy(result1, player.GetInfo())
copier.CopyWithOption(result1, player.GetInfo(), copier.Option{DeepCopy: true})
result.Player = append(result.Player, *result1)
})

View File

@@ -4,17 +4,16 @@ import (
"blazing/common/socket/errorcode"
"blazing/logic/service/maps"
"blazing/logic/service/player"
"context"
"github.com/gogf/gf/v2/os/glog"
"github.com/jinzhu/copier"
)
func (h Controller) Walk(data *maps.WalkInInfo, c *player.Player) (result *maps.WalkOutInfo, err errorcode.ErrorCode) {
result = &maps.WalkOutInfo{}
err1 := copier.Copy(result, data)
copier.Copy(result, data)
result.UserID = data.Head.UserID
glog.Debug(context.Background(), err1)
c.Info.Pos = data.Point
//glog.Debug(context.Background(), err1)
data.Broadcast(c.Info.MapID, *result) //走路的广播
return nil, -1