1 Star 0 Fork 0

Ms.Guo/CSO2014

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
data.go 994 Bytes
一键复制 编辑 原始数据 按行查看 历史
libaojie 提交于 2024-10-31 17:38 +08:00 . 初始化
package host
import (
"context"
"errors"
"net"
"gitee.com/wusuitaitou/cso2014/main_service/client"
"gitee.com/wusuitaitou/cso2014/main_service/model/packet"
"gitee.com/wusuitaitou/cso2014/utils"
)
type GameDataService interface {
Handle(ctx context.Context) error
}
type gameDataServiceImpl struct {
data []byte
client net.Conn
}
func NewGameDataService(p *packet.PacketData, client net.Conn) GameDataService {
len := utils.ReadUint16(p.Data, &p.CurOffset)
return &gameDataServiceImpl{
data: utils.ReadString(p.Data, &p.CurOffset, int(len)),
client: client,
}
}
func (g *gameDataServiceImpl) 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")
}
if u.CurrentRoomId == 0 {
return errors.New("user send game data but is not host")
}
return client.GetUserCacheClient().FlushUserRoomData(ctx, u.UserID, g.data)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wusuitaitou/cso2014.git
git@gitee.com:wusuitaitou/cso2014.git
wusuitaitou
cso2014
CSO2014
v1.0.0

搜索帮助