代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。