From 7c039f1993ae17e32120e0a5af345172a184aced Mon Sep 17 00:00:00 2001 From: hujiebin Date: Thu, 10 Aug 2023 14:36:25 +0800 Subject: [PATCH] =?UTF-8?q?H5=E6=B8=B8=E6=88=8F=E9=9D=99=E9=9F=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol/userProxy.proto | 14 ++++++- rpc/user_center_coder.go | 2 + rpc/user_center_func.go | 83 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/protocol/userProxy.proto b/protocol/userProxy.proto index 2e61658..0caaf9d 100644 --- a/protocol/userProxy.proto +++ b/protocol/userProxy.proto @@ -377,6 +377,10 @@ message SheepMatchSuccess { User user = 2; User otherUser = 3; uint64 game_id = 4; + string channelId = 5; + string token = 6; + uint32 agoraId = 7; + uint32 provider = 8; } message SheepGamePlayer { @@ -473,4 +477,12 @@ message LobbyMatchSuccess { User user = 4; User otherUser = 5; string gameCode = 6; -} \ No newline at end of file +} + +/* id == 158 H5游戏静音 */ +message H5GameVoiceMute { +} + +/* id == 159 H5游戏打开语音 */ +message H5GameVoiceUnMute { +} diff --git a/rpc/user_center_coder.go b/rpc/user_center_coder.go index 9113073..4ff9795 100644 --- a/rpc/user_center_coder.go +++ b/rpc/user_center_coder.go @@ -68,6 +68,8 @@ const ( MsgTypeSvipUpgrade = 151 // svip升级 MsgTypeGroupMicChange = 155 // 麦位变化 MsgTypeLobbyMatchSuccess = 157 // 羊羊匹配成功 + MsgTypeH5GameMute = 158 // H5游戏静音 + MsgTypeH5GameUnMute = 159 // H5游戏开音 ) const ( diff --git a/rpc/user_center_func.go b/rpc/user_center_func.go index 526ec63..e147053 100644 --- a/rpc/user_center_func.go +++ b/rpc/user_center_func.go @@ -255,6 +255,7 @@ func SendGroupChatNotice(fromUserId uint64, userIds []uint64, senderExtId string } // 羊羊匹配成功 +// Deprecated: missing Params func SendSheepMatchSuccess(matchId, myUserId, otherUserId uint64, nick1, nick2, avatar1, avatar2 string, gameIds ...uint64) error { gameId := uint64(0) if len(gameIds) > 0 { @@ -288,6 +289,40 @@ func SendSheepMatchSuccess(matchId, myUserId, otherUserId uint64, nick1, nick2, return nil } +// 羊羊匹配成功 +func SendSheepMatchSuccessV2(matchId, myUserId, otherUserId uint64, nick1, nick2, avatar1, avatar2 string, gameId uint64, channelId, token string, agoraId uint32, provider int) error { + msg := &userProxy.SheepMatchSuccess{ + MatchId: matchId, + User: &userProxy.User{Id: myUserId, Nick: nick1, Avatar: avatar1}, + OtherUser: &userProxy.User{Id: otherUserId, Nick: nick2, Avatar: avatar2}, + GameId: gameId, + ChannelId: channelId, + Token: token, + AgoraId: agoraId, + Provider: uint32(provider), + } + if buffer, err := proto.Marshal(msg); err == nil { + userIds := []uint64{myUserId} + rspUids, err := multicast(userIds, MsgTypeSheepGameMatchSuccess, buffer) + + //记录socket,注意闭包问题 + go func(userIds []uint64, msg *userProxy.SheepMatchSuccess, rspUids []uint64, err error) { + buf, _ := json.Marshal(msg) + AddRpcLogs(MsgTypeSheepGameMatchSuccess, userIds, string(buf[:]), rspUids, err) + }(userIds, msg, rspUids, err) + + if err != nil { + mylogrus.MyLog.Errorf("grpc SendSheepMatchSuccess send fail") + return err + } else { + mylogrus.MyLog.Info("grpc SendSheepMatchSuccess send success") + } + } else { + return err + } + return nil +} + // 羊羊游戏结果 func SendSheepGameResult(matchId, winId, userId1, userId2 uint64, nick1, nick2, avatar1, avatar2 string, isAiMap map[uint64]bool, gameIds ...uint64) error { if isAiMap == nil { @@ -508,3 +543,51 @@ func SendLobbyMatchSuccess(myUserId, otherUserId uint64, nick1, nick2, avatar1, } return nil } + +// h5游戏静音 +func SendH5GameMute(userId uint64) error { + msg := &userProxy.H5GameVoiceMute{} + if buffer, err := proto.Marshal(msg); err == nil { + rspUids, err := multicast([]uint64{userId}, MsgTypeH5GameMute, buffer) + + //记录socket,注意闭包问题 + go func(userId uint64, msg *userProxy.H5GameVoiceMute, rspUids []uint64, err error) { + buf, _ := json.Marshal(msg) + AddRpcLog(MsgTypeH5GameUnMute, userId, string(buf[:]), rspUids, err) + }(userId, msg, rspUids, err) + + if err != nil { + mylogrus.MyLog.Errorf("grpc SendH5GameMute send fail") + return err + } else { + mylogrus.MyLog.Info("grpc SendH5GameMute send success") + } + } else { + return err + } + return nil +} + +// h5游戏开音 +func SendH5GameUnMute(userId uint64) error { + msg := &userProxy.H5GameVoiceUnMute{} + if buffer, err := proto.Marshal(msg); err == nil { + rspUids, err := multicast([]uint64{userId}, MsgTypeH5GameUnMute, buffer) + + //记录socket,注意闭包问题 + go func(userId uint64, msg *userProxy.H5GameVoiceUnMute, rspUids []uint64, err error) { + buf, _ := json.Marshal(msg) + AddRpcLog(MsgTypeH5GameUnMute, userId, string(buf[:]), rspUids, err) + }(userId, msg, rspUids, err) + + if err != nil { + mylogrus.MyLog.Errorf("grpc SendH5GameUnMute send fail") + return err + } else { + mylogrus.MyLog.Info("grpc SendH5GameUnMute send success") + } + } else { + return err + } + return nil +} -- 2.22.0