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.

120 lines
5.2 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"
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 interface{} `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 int `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 int `json:"timestamp"` // 赠送时间
TopList interface{} `json:"top_list"` // ???
TotalCoin int `json:"total_coin"` // 总值 瓜子数
Uid int `json:"uid"` // 用户ID
Uname string `json:"uname"` // 用户名
}
const (
CoinTypeGold = "gold"
CoinTypeSilver = "silver"
)
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: pbMq.Platform_name[int32(pbMq.Platform_bilibili)],
LiveRoomId: h.liveRoomId,
Uid: int64(baseMsg.Data.Uid),
Uname: baseMsg.Data.Uname,
GiftId: baseMsg.Data.GiftId,
Num: baseMsg.Data.Num,
GiftName: baseMsg.Data.GiftName,
Price: int64(baseMsg.Data.Price),
IsPaid: h.isPaid(baseMsg.Data.CoinType),
}
_ = h.producer.SendMessageAsync(dmMsg, strconv.FormatInt(dmMsg.Uid, 10))
}
func (h *SendGiftHandler) isPaid(coinType string) bool {
if coinType == CoinTypeGold {
return true
}
if coinType == CoinTypeSilver {
return false
}
return false
}