From 2edfa2a35bf7fb2d2c0efb4e514dd98920394a53 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Tue, 18 Apr 2023 17:34:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=8A=E7=BE=8A=E4=B8=A4=E4=B8=AAws?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol/userProxy.proto | 18 +++++++++++ rpc/user_center_coder.go | 2 ++ rpc/user_center_func.go | 64 ++++++++++++++++++++++++++++++++++++++ script/utils/utils_test.go | 2 +- 4 files changed, 85 insertions(+), 1 deletion(-) diff --git a/protocol/userProxy.proto b/protocol/userProxy.proto index 559765e..8d1d36a 100644 --- a/protocol/userProxy.proto +++ b/protocol/userProxy.proto @@ -364,4 +364,22 @@ message GlobalGameBanner { uint64 diamond = 4; string bannerUrl = 5; uint64 gameId = 6; // 1.ludo 2.uno 3.dice 4.lucky wheel 5.lucky box 6.fruit 7.slot +} + +/* id == 147 羊羊匹配成功 */ +message SheepMatchSuccess { + uint64 match_id = 1; + User userId1 = 2; + User userId2 = 3; +} + +message SheepGamePlayer { + User user = 1; + bool IsWin = 2; +} + +/* id == 148 羊羊游戏结果 */ +message SheepGameResult { + uint64 match_id = 1; + repeated SheepGamePlayer players = 2; } \ No newline at end of file diff --git a/rpc/user_center_coder.go b/rpc/user_center_coder.go index 2df110b..78c70a4 100644 --- a/rpc/user_center_coder.go +++ b/rpc/user_center_coder.go @@ -61,6 +61,8 @@ const ( MsgRoomInviteMember = 144 // 邀请用户成为房间会员 MsgDiamondChange = 145 // 钻石数变化 MsgTypeGlobalGameBanner = 146 // 游戏横幅 + MsgTypeSheepGameMatchSuccess = 147 // 羊羊匹配成功 + MsgTypeSheepGameResult = 148 // 羊羊游戏结果 ) const ( diff --git a/rpc/user_center_func.go b/rpc/user_center_func.go index a8ab897..bddf1da 100644 --- a/rpc/user_center_func.go +++ b/rpc/user_center_func.go @@ -217,3 +217,67 @@ func SendGroupChatNotice(fromUserId uint64, userIds []uint64, senderExtId string } return nil } + +// 羊羊匹配成功 +func SendSheepMatchSuccess(matchId, userId1, userId2 uint64, nick1, nick2, avatar1, avatar2 string) error { + msg := &userProxy.SheepMatchSuccess{ + MatchId: matchId, + UserId1: &userProxy.User{Id: userId1, Nick: nick1, Avatar: avatar1}, + UserId2: &userProxy.User{Id: userId2, Nick: nick2, Avatar: avatar2}, + } + if buffer, err := proto.Marshal(msg); err == nil { + userIds := []uint64{userId1, userId2} + 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) error { + var players []*userProxy.SheepGamePlayer + players = append(players, &userProxy.SheepGamePlayer{IsWin: winId == userId1, User: &userProxy.User{ + Id: userId1, Nick: nick1, Avatar: avatar1, + }}) + players = append(players, &userProxy.SheepGamePlayer{IsWin: winId == userId2, User: &userProxy.User{ + Id: userId2, Nick: nick2, Avatar: avatar2, + }}) + msg := &userProxy.SheepGameResult{ + MatchId: matchId, + Players: players, + } + if buffer, err := proto.Marshal(msg); err == nil { + userIds := []uint64{userId1, userId2} + rspUids, err := multicast(userIds, MsgTypeSheepGameResult, buffer) + + //记录socket,注意闭包问题 + go func(userIds []uint64, msg *userProxy.SheepGameResult, rspUids []uint64, err error) { + buf, _ := json.Marshal(msg) + AddRpcLogs(MsgTypeSheepGameResult, userIds, string(buf[:]), rspUids, err) + }(userIds, msg, rspUids, err) + + if err != nil { + mylogrus.MyLog.Errorf("grpc SendSheepGameResult send fail") + return err + } else { + mylogrus.MyLog.Info("grpc SendSheepGameResult send success") + } + } else { + return err + } + return nil +} diff --git a/script/utils/utils_test.go b/script/utils/utils_test.go index 165111e..28d1a39 100644 --- a/script/utils/utils_test.go +++ b/script/utils/utils_test.go @@ -10,6 +10,6 @@ func TestTestCommon(t *testing.T) { } func TestJwt(t *testing.T) { - token, _ := jwt.GenerateToken(4510, "4474ac74c17e42f4820586279eda37c9", "hiloApi") + token, _ := jwt.GenerateToken(4549, "f98c7fe5698e447c998615332eb660d1", "hiloApi") t.Logf(token) } -- 2.22.0