package rpc import ( "encoding/json" "git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/protocol/userProxy" "google.golang.org/protobuf/proto" ) func SendFruitMachine(date string, round uint32) error { msg := &userProxy.FruitMachine{ Date: date, Round: round, } if buffer, err := proto.Marshal(msg); err == nil { rspUids, err := broadcast(MsgFruitMachine, buffer) //记录socket,注意闭包问题 go func(userId uint64, msg *userProxy.FruitMachine, rspUids []uint64, err error) { buf, _ := json.Marshal(msg) AddRpcLog(MsgFruitMachine, userId, string(buf[:]), rspUids, err) }(0, msg, rspUids, err) if err != nil { mylogrus.MyLog.Errorf("grpc SendFruitMachine send fail") return err } else { mylogrus.MyLog.Info("grpc SendFruitMachine send success") } } else { return err } return nil } func SendGlobalRocketNotice(groupId string, period string, round uint32, stage uint32, fromUserId uint64, topUserIcon string, nick string, code string, avatar string) error { msg := &userProxy.GlobalRocketNotice{ GroupId: groupId, Period: period, Round: round, Stage: stage, TopUserIcon: topUserIcon, Nick: nick, Code: code, Avatar: avatar, } if buffer, err := proto.Marshal(msg); err == nil { rspUids, err := broadcast(MsgTypeGlobalRocketNotice, buffer) //记录socket,注意闭包问题 go func(userId uint64, msg *userProxy.GlobalRocketNotice, rspUids []uint64, err error) { buf, _ := json.Marshal(msg) AddRpcLog(MsgTypeGlobalRocketNotice, userId, string(buf[:]), rspUids, err) }(fromUserId, msg, rspUids, err) if err != nil { mylogrus.MyLog.Errorf("grpc GlobalRocketNotice send fail") return err } else { mylogrus.MyLog.Info("grpc GlobalRocketNotice send success") } } else { return err } return nil } // 发送钻石变化通知 func SendDiamondChange(userId uint64, diamond uint32) error { msg := &userProxy.DiamondChange{ RemainDiamond: diamond, } if buffer, err := proto.Marshal(msg); err == nil { rspUids, err := multicast([]uint64{userId}, MsgDiamondChange, buffer) //记录socket,注意闭包问题 go func(userId uint64, msg *userProxy.DiamondChange, rspUids []uint64, err error) { buf, _ := json.Marshal(msg) AddRpcLog(MsgDiamondChange, userId, string(buf[:]), rspUids, err) }(userId, msg, rspUids, err) if err != nil { mylogrus.MyLog.Errorf("grpc SendDiamondChange send fail") return err } else { mylogrus.MyLog.Info("grpc SendDiamondChange send success") } } else { return err } return nil } // 发送游戏横幅 // param winUserId:胜利的用户id // param gameType 0:slot 5:luckybox 6:fruit func SendGlobalGameBanner(winUserId uint64, diamond uint64, avatar string, gameType uint32) error { bannerUrl := "" switch gameType { case 0: bannerUrl = "https://image.whoisamy.shop/hilo/resource/game/game_banner_slot.png" case 5: bannerUrl = "https://image.whoisamy.shop/hilo/resource/game/game_banner_luckybox.png" case 6: bannerUrl = "https://image.whoisamy.shop/hilo/resource/game/game_banner_fruit.png" } msg := &userProxy.GlobalGameBanner{ GameType: gameType, UserId: winUserId, Avatar: avatar, Diamond: diamond, BannerUrl: bannerUrl, } if buffer, err := proto.Marshal(msg); err == nil { rspUids, err := broadcast(MsgTypeGlobalGameBanner, buffer) //记录socket,注意闭包问题 go func(userId uint64, msg *userProxy.GlobalGameBanner, rspUids []uint64, err error) { buf, _ := json.Marshal(msg) AddRpcLog(MsgTypeGlobalGameBanner, userId, string(buf[:]), rspUids, err) }(winUserId, msg, rspUids, err) if err != nil { mylogrus.MyLog.Errorf("grpc SendGlobalGameBanner send fail") return err } else { mylogrus.MyLog.Info("grpc SendGlobalGameBanner send success") } } else { return err } return nil } func SendJoinGroup(userId uint64, externalId string, groupId string) error { msg := &userProxy.JoinGroup{GroupId: groupId, ExternalId: externalId} if buffer, err := proto.Marshal(msg); err == nil { userIds := []uint64{userId} rspUids, err := multicast(userIds, MsgTypeJoinGroup, buffer) //记录socket,注意闭包问题 go func(userIds []uint64, msg *userProxy.JoinGroup, rspUids []uint64, err error) { buf, _ := json.Marshal(msg) AddRpcLogs(MsgTypeJoinGroup, userIds, string(buf[:]), rspUids, err) }(userIds, msg, rspUids, err) if err != nil { mylogrus.MyLog.Errorf("grpc SendJoinGroup send fail") return err } else { mylogrus.MyLog.Info("grpc SendJoinGroup send success") } } else { return err } return nil } func SendConfigChange(operUserId uint64, configType uint32) error { msg := &userProxy.ConfigChange{ Type: configType, } if buffer, err := proto.Marshal(msg); err == nil { rspUids, err := broadcast(MsgTypeConfigChange, buffer) //记录socket,注意闭包问题 go func(configType uint32, msg *userProxy.ConfigChange, rspUids []uint64, err error) { buf, _ := json.Marshal(msg) AddRpcLog(MsgTypeConfigChange, operUserId, string(buf[:]), rspUids, err) }(configType, msg, rspUids, err) if err != nil { mylogrus.MyLog.Errorf("grpc SendConfigChange send fail") return err } else { mylogrus.MyLog.Info("grpc SendConfigChange send success") } } else { return err } return nil } func SendGroupChatNotice(fromUserId uint64, userIds []uint64, senderExtId string, senderCode string, senderSex uint32, senderAvatar string, text string, groupId, groupName, groupCode, groupAvatar string, userInNum uint32) error { msg := &userProxy.GroupSendNotice{ SenderExtId: senderExtId, SenderCode: senderCode, SenderSex: senderSex, SenderAvatar: senderAvatar, Text: text, GroupName: groupName, GroupCode: groupCode, GroupAvatar: groupAvatar, UserInNum: userInNum, GroupId: groupId, } if buffer, err := proto.Marshal(msg); err == nil { rspUids, err := multicast(userIds, MsgTypeGroupChatNotice, buffer) //记录socket,注意闭包问题 go func(userId uint64, msg *userProxy.GroupSendNotice, rspUids []uint64, err error) { buf, _ := json.Marshal(msg) AddRpcLog(MsgTypeGroupChatNotice, userId, string(buf[:]), rspUids, err) }(fromUserId, msg, rspUids, err) if err != nil { mylogrus.MyLog.Errorf("grpc SendGroupChatNotice send fail,userId:", fromUserId) return err } else { mylogrus.MyLog.Info("grpc SendGroupChatNotice send success,userId:", fromUserId) } } else { return err } return nil }