1 Star 0 Fork 0

Ms.Guo/CSO2014

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
inventory.go 1.49 KB
一键复制 编辑 原始数据 按行查看 历史
libaojie 提交于 2024-10-31 17:38 . 初始化
package host
import (
"context"
"errors"
"net"
"gitee.com/wusuitaitou/cso2014/main_service/client"
"gitee.com/wusuitaitou/cso2014/main_service/constant"
"gitee.com/wusuitaitou/cso2014/main_service/model/out"
"gitee.com/wusuitaitou/cso2014/main_service/model/packet"
"gitee.com/wusuitaitou/cso2014/utils"
)
type GetInventoryService interface {
Handle(ctx context.Context) error
}
type getInventoryServiceImpl struct {
dest uint32
client net.Conn
}
func NewGetInventoryService(p *packet.PacketData, client net.Conn) GetInventoryService {
return &getInventoryServiceImpl{
dest: utils.ReadUint32(p.Data, &p.CurOffset),
client: client,
}
}
func (g *getInventoryServiceImpl) Handle(ctx context.Context) error {
u := client.GetUserCacheClient().GetUserByConnection(ctx, g.client)
if u == nil || u.CurrentRoomId == 0 {
return errors.New("can't find user or user not in room")
}
room, err := client.GetRoomClient().GetRoomInfo(ctx, u.CurrentRoomId)
if err != nil {
return err
}
if room.HostUserID != u.UserID {
return errors.New("user try to get other player's inventory but is not host")
}
dest_player := client.GetUserCacheClient().GetUserByID(ctx, g.dest)
if dest_player == nil || dest_player.CurrentRoomId != u.CurrentRoomId {
return errors.New("can't find dest player or player not in room")
}
rst := utils.BytesCombine(packet.BuildHeader(u.GetNextSeq(), constant.PacketTypeHost), out.BuildSetUserInventory(dest_player))
packet.SendPacket(rst, u.CurrentConnection)
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wusuitaitou/cso2014.git
git@gitee.com:wusuitaitou/cso2014.git
wusuitaitou
cso2014
CSO2014
v1.0.0

搜索帮助