You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
5.3 KiB
Go

3 years ago
package msg_handler
import (
"encoding/json"
"git.noahlan.cn/northlan/ntools-go/kafka"
"live-gateway/config"
"live-gateway/pb"
kfk "live-gateway/pkg/kafka"
"strconv"
3 years ago
)
type SendGift struct {
Action string `json:"action"` // 动作,投喂等
BatchComboId string `json:"batch_combo_id"` // 礼物连击ID
BatchComboSend interface{} `json:"batch_combo_send"` // ???
BeatId string `json:"beatId"` // ???
BizSource string `json:"biz_source"` // ?? :live
BlindGift interface{} `json:"blind_gift"` // ??
BroadcastId int `json:"broadcast_id"` // 广播ID ??
CoinType string `json:"coin_type"` // 瓜子类型, gold金瓜子 silver银瓜子(免费礼物)
3 years ago
ComboResourcesId int `json:"combo_resources_id"` // ???
ComboSend interface{} `json:"combo_send"` // ???
ComboStayTime int `json:"combo_stay_time"` // 连击停留时间??? 秒?
ComboTotalCoin int `json:"combo_total_coin"` // 连击总币数???
CritProb int `json:"crit_prob"` // ???
Demarcation int `json:"demarcation"` // ???: 1
DiscountPrice int `json:"discount_price"` // 折扣价???
DMScore int `json:"dmscore"` // 活动积分普通道具为0
3 years ago
Draw int `json:"draw"` // ???
Effect int `json:"effect"` // ???
EffectBlock int `json:"effect_block"` // ???
Face string `json:"face"` // 头像?
GiftId int64 `json:"giftId"` // 礼物ID
3 years ago
GiftName string `json:"giftName"` // 礼物名称
GiftType int `json:"giftType"` // 礼物类型 普通,弹幕,活动
Gold int `json:"gold"` // 用户剩余金瓜子
3 years ago
GuardLevel int `json:"guard_level"` // 舰队等级
IsFirst bool `json:"is_first"` // 是否首次投喂?
IsSpecialBatch int `json:"is_special_batch"` // ???
Magnification int `json:"magnification"` // 是否放大???
MedalInfo *FansMedal `json:"medal_info"` // 佩戴勋章的主播信息
NameColor string `json:"name_color"` // 名 颜色
Num int64 `json:"num"` // 数量
3 years ago
OriginalGiftName string `json:"original_gift_name"` // 原始礼物名称???
Price int64 `json:"price"` // 价格? 但不是电池
3 years ago
RCost int `json:"rcost"` // ???
Remain int `json:"remain"` // 用户道具包裹剩余数量
3 years ago
Rnd string `json:"rnd"` // 随机数?
SendMaster interface{} `json:"send_master"` // ???
Silver int `json:"silver"` // 用户剩余银瓜子
3 years ago
Super int `json:"super"` // ???
SuperBatchGiftNum int `json:"super_batch_gift_num"` // ???
SuperGiftNum int `json:"super_gift_num"` // ???
SvgaBlock int `json:"svga_block"` // ???
TagImage string `json:"tag_image"` // ???
Timestamp int64 `json:"timestamp"` // 赠送时间
3 years ago
TopList interface{} `json:"top_list"` // ???
TotalCoin int `json:"total_coin"` // 总值 瓜子数
3 years ago
Uid int `json:"uid"` // 用户ID
Uname string `json:"uname"` // 用户名
}
type SendGiftHandler struct {
producer *kafka.Producer
liveRoomId int64
}
func NewSendGiftHandler(liveRoomId int64) *SendGiftHandler {
cfg := config.Config.Kafka.Gift
return &SendGiftHandler{
producer: kafka.NewKafkaProducer(kfk.DefaultProducerConfig, cfg.Addr, cfg.Topic),
liveRoomId: liveRoomId,
}
3 years ago
}
func (h *SendGiftHandler) CMD() string {
return "SEND_GIFT"
}
func (h *SendGiftHandler) HandlerMessage(data []byte) {
var baseMsg struct {
CMD string `json:"cmd"`
Data *SendGift `json:"data"`
}
if err := json.Unmarshal(data, &baseMsg); err != nil {
return
}
//logger.SLog.Infof("%s %s礼物 %s x%d", baseMsg.Data.Uname, baseMsg.Data.Action, baseMsg.Data.GiftName, baseMsg.Data.Num)
dmMsg := &pbMq.MqGift{
Platform: pbMq.Platform_name[int32(pbMq.Platform_bilibili)],
LiveRoomId: h.liveRoomId,
Uid: int64(baseMsg.Data.Uid),
Uname: baseMsg.Data.Uname,
Avatar: "",
GiftId: baseMsg.Data.GiftId,
GiftName: baseMsg.Data.GiftName,
GiftNum: baseMsg.Data.Num,
Price: baseMsg.Data.Price,
IsPaid: IsPaidGift(baseMsg.Data.CoinType),
MsgId: "",
Timestamp: baseMsg.Data.Timestamp,
NobilityLevel: 0,
FansMedalWearingStatus: false,
FansMedalName: "",
FansMedalLevel: 0,
}
_ = h.producer.SendMessageAsync(dmMsg, strconv.FormatInt(dmMsg.Uid, 10))
3 years ago
}