refactor(controller): 替换用户遍历逻辑为迭代回调方式 将多个控制器中使用的 `Items()` 方法遍历用户列表的方式, 统一修改为通过 `IterCb()` 回调函数方式进行处理, 提升代码一致性与可维护性。 同时引入 `blazing/logic/service/common` 包以支持 PlayerI 接口调用。 此外,移除了未使用的 `model.Pos` 类型及相关注释,精简结构体定义。 ```
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
"blazing/cool"
|
|
|
|
"blazing/logic/service/common"
|
|
"blazing/logic/service/player"
|
|
"blazing/logic/service/space"
|
|
"blazing/logic/service/user"
|
|
blservice "blazing/modules/blazing/service"
|
|
"strings"
|
|
)
|
|
|
|
// 处理命令: 1001
|
|
func (h *Controller) CreatePlayer(data *user.CreatePlayerInboundInfo, c *player.Conn) (result *user.CreatePlayerOutInfo, err errorcode.ErrorCode) {
|
|
|
|
blservice.NewUserService(data.Head.UserID).Reg(cool.Filter.Replace(data.Nickname, '*'), data.Color)
|
|
return result, 0
|
|
}
|
|
|
|
func (h *Controller) ChangePlayerName(data *user.ChangePlayerNameInboundInfo, c *player.Player) (result *user.ChangePlayerNameOutboundInfo, err errorcode.ErrorCode) {
|
|
newnice := cool.Filter.Replace(strings.Trim(data.Nickname, "\x00"), '*')
|
|
|
|
c.Info.Nick = newnice
|
|
result = &user.ChangePlayerNameOutboundInfo{
|
|
Nickname: newnice,
|
|
UserID: c.Info.UserID,
|
|
}
|
|
|
|
space.GetSpace(c.Info.MapID).User.IterCb(func(playerID uint32, player common.PlayerI) {
|
|
player.SendPack(data.Head.Pack(&result))
|
|
})
|
|
|
|
return result, 0
|
|
}
|