Files
bl/logic/controller/user_action.go
昔念 026689f3ed ```
feat(cache): 添加复合键缓存操作支持

添加了基于 uint32+string 组合键的缓存操作方法,包括
GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和
ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景

fix(vscode): 添加 cSpell 配置支持 struc 词汇

refactor(session): 移除过时的会话管理方法

移除了基于单一字符串键的会话管理方法,因为已迁移到使用
复合键的缓存操作方式
```
2026-01-19 18:51:56 +08:00

195 lines
5.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controller
import (
"blazing/common/socket/errorcode"
"blazing/common/utils"
"blazing/cool"
"blazing/logic/service/item"
"blazing/logic/service/player"
"blazing/logic/service/user"
"blazing/modules/player/model"
"strings"
)
// PlayerAim 玩家射击操作
// data: 包含射击信息的输入数据
// player: 当前玩家对象
// 返回: 射击结果和错误码
func (h Controller) PlayerAim(data *user.AimatInboundInfo, player *player.Player) (result *user.AimatOutboundInfo, err errorcode.ErrorCode) {
result = &user.AimatOutboundInfo{
ItemId: data.ItemId,
Point: data.Point,
ShootType: data.ShootType,
UserId: player.Info.UserID,
}
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
// PlayerChat 玩家聊天功能
// data: 包含聊天消息的输入数据
// player: 当前玩家对象
// 返回: 聊天结果和错误码
func (h Controller) PlayerChat(data *user.ChatInboundInfo, player *player.Player) (result *user.ChatOutboundInfo, err errorcode.ErrorCode) {
result = &user.ChatOutboundInfo{
Message: utils.RemoveLast(data.Message),
SenderNickname: player.Info.Nick,
SenderId: player.Info.UserID,
}
result.Message = cool.Filter.Replace(result.Message, '*')
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
// ChangePlayerColor 修改玩家颜色消耗50赛尔豆
// data: 包含颜色信息的输入数据
// player: 当前玩家对象
// 返回: 颜色更改结果和错误码
func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, player *player.Player) (result *user.ChangeColorOutboundInfo, err errorcode.ErrorCode) {
const changeColorCost = 50
if !player.GetCoins(changeColorCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
player.Info.Coins -= changeColorCost
player.Info.Color = data.Color
player.Info.Texture = 0
result = &user.ChangeColorOutboundInfo{
UserId: player.Info.UserID,
Color: data.Color,
Coins: player.Info.Coins,
Texture: player.Info.Texture,
}
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
// ChangePlayerDoodle 修改玩家涂鸦消耗50赛尔豆
// data: 包含涂鸦信息的输入数据
// player: 当前玩家对象
// 返回: 涂鸦更改结果和错误码
func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, player *player.Player) (result *user.ChangeDoodleOutboundInfo, err errorcode.ErrorCode) {
const changeDoodleCost = 50
if !player.GetCoins(changeDoodleCost) {
return nil, errorcode.ErrorCodes.ErrSunDouInsufficient10016
}
player.Info.Coins -= changeDoodleCost
player.Info.Texture = data.Id
player.Info.Color = data.Color
result = &user.ChangeDoodleOutboundInfo{
UserId: player.Info.UserID,
Color: player.Info.Color,
Coins: player.Info.Coins,
Texture: player.Info.Texture,
}
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
// ChangeNONOColor 修改NONO颜色
// data: 包含NONO颜色信息的输入数据
// player: 当前玩家对象
// 返回: NONO颜色更改结果和错误码
func (h Controller) ChangeNONOColor(data *user.ChangeNONOColorInboundInfo, player *player.Player) (result *user.ChangeNONOColorOutboundInfo, err errorcode.ErrorCode) {
//player.Info.Coins -= 200
player.Info.NONO.NonoColor = data.Color
result = &user.ChangeNONOColorOutboundInfo{
Sataus: player.Info.UserID,
Color: player.Info.Color,
}
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
// DanceAction 跳舞动作
// data: 包含跳舞类型信息的输入数据
// player: 当前玩家对象
// 返回: 跳舞动作结果和错误码
func (h Controller) DanceAction(data *user.C2SDanceAction, player *player.Player) (result *user.S2CDanceAction, err errorcode.ErrorCode) {
result = &user.S2CDanceAction{
Type: data.Type,
UserID: player.Info.UserID,
}
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
// PeopleTransform 人物变形
// data: 包含变形信息的输入数据
// player: 当前玩家对象
// 返回: 变形结果和错误码
func (h Controller) PeopleTransform(data *user.C2SPEOPLE_TRANSFROM, player *player.Player) (result *user.S2CPEOPLE_TRANSFROM, err errorcode.ErrorCode) {
result = &user.S2CPEOPLE_TRANSFROM{
SuitID: data.SuitID,
UserID: player.Info.UserID,
}
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
// ChangePlayerCloth 更换玩家服装
// data: 包含服装信息的输入数据
// player: 当前玩家对象
// 返回: 服装更改结果和错误码
func (h Controller) ChangePlayerCloth(data *item.ChangePlayerClothInboundInfo, player *player.Player) (result *item.ChangePlayerClothOutboundInfo, err errorcode.ErrorCode) {
result = &item.ChangePlayerClothOutboundInfo{
UserID: player.Info.UserID,
ClothList: make([]model.PeopleItemInfo, 0),
}
for _, clothID := range data.ClothList {
result.ClothList = append(result.ClothList, model.PeopleItemInfo{ID: clothID, Level: 1})
}
player.Info.Clothes = result.ClothList
player.GetSpace().Broadcast(player, data.Head.CMD, result)
return
}
func (h Controller) ChangePlayerName(data *user.ChangePlayerNameInboundInfo, c *player.Player) (result *user.ChangePlayerNameOutboundInfo, err errorcode.ErrorCode) {
newNickname := cool.Filter.Replace(strings.Trim(data.Nickname, "\x00"), '*')
c.Info.Nick = newNickname
result = &user.ChangePlayerNameOutboundInfo{
Nickname: newNickname,
UserID: c.Info.UserID,
}
c.GetSpace().Broadcast(c, data.Head.CMD, result)
return result, 0
}
func (h Controller) ChangeTile(data *user.ChangeTitleInboundInfo, c *player.Player) (result *user.ChangeTitleOutboundInfo, err errorcode.ErrorCode) {
result = &user.ChangeTitleOutboundInfo{
UserID: c.Info.UserID,
}
if data.TileID == 0 {
return result, 0
}
if !c.Service.Title.Can(data.TileID) {
return nil, errorcode.ErrorCodes.ErrSystemError
}
c.Info.Title = data.TileID
result.TileID = data.TileID
c.GetSpace().Broadcast(c, data.Head.CMD, result)
return result, 0
}