Files
blivedm-go/packet/enter.go
Akiba 4082c5489f 🎨
2022-07-22 17:18:05 +08:00

41 lines
895 B
Go

package packet
import (
"encoding/json"
log "github.com/sirupsen/logrus"
)
type Enter struct {
UID int `json:"uid"`
RoomID int `json:"roomid"`
ProtoVer int `json:"protover"`
Platform string `json:"platform"`
ClientVer string `json:"clientver"`
Type int `json:"type"`
Key string `json:"key"`
}
// NewEnterPacket 构造进入房间的包
// uid 可以为 0, key 在使用 broadcastlv 服务器的时候不需要
func NewEnterPacket(uid int, roomID int, key string) []byte {
ent := &Enter{
UID: uid,
RoomID: roomID,
ProtoVer: 2,
Platform: "web",
ClientVer: "1.14.3",
Type: 2,
Key: key,
}
pkt := NewPlainPacket(RoomEnter, ent.Json())
return pkt.Build()
}
func (e *Enter) Json() []byte {
marshal, err := json.Marshal(e)
if err != nil {
log.Error("NewEnterPacket JsonMarshal failed", err)
}
return marshal
}