diff --git a/protocol/userProxy.proto b/protocol/userProxy.proto index 559765e780c2d42d9b14fe00d0f09c0ce39cdd70..8d1d36a2267c98e1d30796f491b4d7140eed7d9d 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 2df110b906d4ae0a1e1b1d9ea9ad4125e9a12f34..78c70a46e671400a15d0134fb6e0c840ccbfaa12 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 a8ab897bbaff415c1d37b0dc823750d659082276..bddf1da4c407ee2bb9693b82aa8d3fe70c93a715 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 165111eff3b462a0b4016eb2bf00241a0be13716..28d1a39c6c1c2d6febb0b1bbf416e6337e438d42 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) }