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.

134 lines
6.1 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package msg_handler
import (
"encoding/json"
"git.noahlan.cn/northlan/ntools-go/kafka"
"live-gateway/config"
"live-gateway/pb/mq"
pbVars "live-gateway/pb/vars"
kfk "live-gateway/pkg/kafka"
"strconv"
)
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 *BlindGift `json:"blind_gift"` // ??
BroadcastId int `json:"broadcast_id"` // 广播ID ??
CoinType string `json:"coin_type"` // 瓜子类型, gold金瓜子 silver银瓜子(免费礼物)
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
Draw int `json:"draw"` // ???
Effect int `json:"effect"` // ???
EffectBlock int `json:"effect_block"` // ???
Face string `json:"face"` // 头像?
GiftId int64 `json:"giftId"` // 礼物ID
GiftName string `json:"giftName"` // 礼物名称
GiftType int `json:"giftType"` // 礼物类型 普通,弹幕,活动
Gold int `json:"gold"` // 用户剩余金瓜子
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"` // 数量
OriginalGiftName string `json:"original_gift_name"` // 原始礼物名称???
Price int64 `json:"price"` // 价格? 但不是电池
RCost int `json:"rcost"` // ???
Remain int `json:"remain"` // 用户道具包裹剩余数量
Rnd string `json:"rnd"` // 随机数?
SendMaster interface{} `json:"send_master"` // ???
Silver int `json:"silver"` // 用户剩余银瓜子
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"` // 赠送时间
TopList interface{} `json:"top_list"` // ???
TotalCoin int `json:"total_coin"` // 总值 瓜子数
Uid int64 `json:"uid"` // 用户ID
Uname string `json:"uname"` // 用户名
}
// BlindGift 宝箱类礼物
BlindGift struct {
BlindGiftConfigId int64 `json:"blind_gift_config_id"` // id
From int64 `json:"from"` // ??
GiftAction string `json:"gift_action"` // 爆出/投喂
OriginalGiftId int64 `json:"original_gift_id"` // 原始礼物ID
OriginalGiftName string `json:"original_gift_name"` // 原始礼物名
}
)
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,
}
}
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: pbVars.Platform_name[int32(pbVars.Platform_Bilibili)],
LiveRoomId: h.liveRoomId,
MsgId: "",
Timestamp: baseMsg.Data.Timestamp,
Uid: baseMsg.Data.Uid,
Uname: baseMsg.Data.Uname,
Avatar: baseMsg.Data.Face,
NobilityLevel: int64(baseMsg.Data.GuardLevel),
GiftId: baseMsg.Data.GiftId,
GiftName: baseMsg.Data.GiftName,
GiftNum: baseMsg.Data.Num,
Price: baseMsg.Data.Price,
IsPaid: IsPaidGift(baseMsg.Data.CoinType),
Type: pbMq.MqGift_NORMAL,
PackGift: nil,
FansMedalWearingStatus: baseMsg.Data.MedalInfo.AnchorRoomId == h.liveRoomId,
FansMedalName: baseMsg.Data.MedalInfo.MedalName,
FansMedalLevel: baseMsg.Data.MedalInfo.MedalLevel,
}
// type - pack
if baseMsg.Data.BlindGift != nil {
dmMsg.Type = pbMq.MqGift_PACK
dmMsg.PackGift = &pbMq.MqGift_PackGift{
GiftId: baseMsg.Data.BlindGift.OriginalGiftId,
GiftName: baseMsg.Data.BlindGift.OriginalGiftName,
}
}
_ = h.producer.SendMessageAsync(dmMsg, strconv.FormatInt(dmMsg.Uid, 10))
}