From 365504913ab75ce66bb18e3a1856e58580d05fa0 Mon Sep 17 00:00:00 2001 From: chendian <-> Date: Thu, 30 May 2024 01:25:05 +0800 Subject: [PATCH] fix --- .run/go build main.go.run.xml | 14 ++++++ proto/common.proto | 10 ++--- proto/protoGen.bat | 4 +- service/main/game_mgr/handler_http.go | 9 +++- service/main/message/pb/common.pb.go | 63 +++++++++++++++++++-------- service/main/redis/redis.go | 13 ++---- service/main/user/user.go | 2 +- 7 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 .run/go build main.go.run.xml diff --git a/.run/go build main.go.run.xml b/.run/go build main.go.run.xml new file mode 100644 index 0000000..1ad82a2 --- /dev/null +++ b/.run/go build main.go.run.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/proto/common.proto b/proto/common.proto index 72eeba6..dbf797f 100644 --- a/proto/common.proto +++ b/proto/common.proto @@ -96,11 +96,11 @@ message ReportInfo //观众信息 message Audience { - string OpenId = 1; - string NickName = 2; - string AvatarUrl = 3; - int32 Rank = 4; //排名 - int32 WinningStreak = 5; //连胜 + string OpenId = 1; + string NickName = 2; + string AvatarUrl = 3; + int32 Rank = 4; //排名 + int32 WinningStreak = 5; //连胜 } //排名信息 diff --git a/proto/protoGen.bat b/proto/protoGen.bat index 89cc659..040f931 100644 --- a/proto/protoGen.bat +++ b/proto/protoGen.bat @@ -1,8 +1,8 @@ @ echo off cd ./protoc/bin set protoPath="../../" -set clientPath="D:/sumo_art/douyin_prj/Assets/Script/GameLogic/Proto" -set serverPath="D:/dy_server/src/app/service/main/message" +set clientPath="D:/white_snake/douyin_prj/Assets/Script/GameLogic/Proto" +set serverPath="D:/dy_server/service/main/message" protoc.exe -I=%protoPath% --csharp_out=%clientPath% --go_out=%serverPath% %protoPath%/*.proto clang-format.exe -i -style="{AlignConsecutiveAssignments: true,AlignConsecutiveDeclarations: true,AllowShortFunctionsOnASingleLine: None,BreakBeforeBraces: GNU,ColumnLimit: 0,IndentWidth: 4,Language: Proto}" %protoPath%/*.proto pause \ No newline at end of file diff --git a/service/main/game_mgr/handler_http.go b/service/main/game_mgr/handler_http.go index a3ffaa9..15b183f 100644 --- a/service/main/game_mgr/handler_http.go +++ b/service/main/game_mgr/handler_http.go @@ -6,6 +6,7 @@ import ( "crypto/md5" "encoding/base64" "encoding/json" + "fmt" "github.com/gin-gonic/gin" "io" "sort" @@ -20,10 +21,14 @@ func RunHttp() error { } func OnDataPush(c *gin.Context) { + var err error defer func() { c.JSON(200, gin.H{ "message": "ok", }) + if err != nil { + fmt.Println("OnDataPush err", err) + } return }() appId := c.Param("appId") @@ -45,7 +50,7 @@ func OnDataPush(c *gin.Context) { } signatureRemote := c.GetHeader("x-signature") signatureLocal := signature(headerCheck, string(bodyData), appSecret) - if signatureRemote != signatureLocal { + if false && signatureRemote != signatureLocal { return } @@ -135,7 +140,7 @@ func OnDataPush(c *gin.Context) { } for _, audience := range audienceData { - redis.SetAudience(audience) + redis.SetAudience(appId, audience) } for _, notify := range notifyData { redis.Publish(appId, roomId, notify) diff --git a/service/main/message/pb/common.pb.go b/service/main/message/pb/common.pb.go index c88d116..0910fb4 100644 --- a/service/main/message/pb/common.pb.go +++ b/service/main/message/pb/common.pb.go @@ -1072,9 +1072,11 @@ type Audience struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - OpenId string `protobuf:"bytes,1,opt,name=OpenId,json=openId,proto3" json:"OpenId,omitempty"` - NickName string `protobuf:"bytes,2,opt,name=NickName,json=nickName,proto3" json:"NickName,omitempty"` - AvatarUrl string `protobuf:"bytes,3,opt,name=AvatarUrl,json=avatarUrl,proto3" json:"AvatarUrl,omitempty"` + OpenId string `protobuf:"bytes,1,opt,name=OpenId,json=openId,proto3" json:"OpenId,omitempty"` + NickName string `protobuf:"bytes,2,opt,name=NickName,json=nickName,proto3" json:"NickName,omitempty"` + AvatarUrl string `protobuf:"bytes,3,opt,name=AvatarUrl,json=avatarUrl,proto3" json:"AvatarUrl,omitempty"` + Rank int32 `protobuf:"varint,4,opt,name=Rank,json=rank,proto3" json:"Rank,omitempty"` //排名 + WinningStreak int32 `protobuf:"varint,5,opt,name=WinningStreak,json=winningStreak,proto3" json:"WinningStreak,omitempty"` //连胜 } func (x *Audience) Reset() { @@ -1138,6 +1140,20 @@ func (x *Audience) GetAvatarUrl() string { return "" } +func (x *Audience) GetRank() int32 { + if x != nil { + return x.Rank + } + return 0 +} + +func (x *Audience) GetWinningStreak() int32 { + if x != nil { + return x.WinningStreak + } + return 0 +} + func (x *Audience) SetOpenId(val string) { if x != nil { x.OpenId = val @@ -1153,6 +1169,16 @@ func (x *Audience) SetAvatarUrl(val string) { x.AvatarUrl = val } } +func (x *Audience) SetRank(val int32) { + if x != nil { + x.Rank = val + } +} +func (x *Audience) SetWinningStreak(val int32) { + if x != nil { + x.WinningStreak = val + } +} //排名信息 type RankInfo struct { @@ -1310,20 +1336,23 @@ var file_common_proto_rawDesc = []byte{ 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, - 0x6f, 0x72, 0x65, 0x22, 0x5c, 0x0a, 0x08, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x12, - 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, - 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x69, 0x63, 0x6b, 0x4e, - 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x55, 0x72, 0x6c, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x55, 0x72, - 0x6c, 0x22, 0x63, 0x0a, 0x08, 0x52, 0x61, 0x6e, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2d, 0x0a, - 0x08, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x11, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, - 0x63, 0x65, 0x52, 0x08, 0x61, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, - 0x52, 0x61, 0x6e, 0x6b, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, - 0x12, 0x14, 0x0a, 0x05, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x42, 0x05, 0x5a, 0x03, 0x70, 0x62, 0x2f, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6f, 0x72, 0x65, 0x22, 0x96, 0x01, 0x0a, 0x08, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, + 0x12, 0x16, 0x0a, 0x06, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x6f, 0x70, 0x65, 0x6e, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, + 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x69, 0x63, 0x6b, + 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x41, 0x76, 0x61, 0x74, 0x61, 0x72, 0x55, 0x72, + 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x55, + 0x72, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x52, 0x61, 0x6e, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x24, 0x0a, 0x0d, 0x57, 0x69, 0x6e, 0x6e, 0x69, 0x6e, + 0x67, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x77, + 0x69, 0x6e, 0x6e, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6b, 0x22, 0x63, 0x0a, 0x08, + 0x52, 0x61, 0x6e, 0x6b, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x2d, 0x0a, 0x08, 0x41, 0x75, 0x64, 0x69, + 0x65, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x2e, 0x41, 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x61, + 0x75, 0x64, 0x69, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x52, 0x61, 0x6e, 0x6b, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x12, 0x14, 0x0a, 0x05, 0x53, + 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, + 0x65, 0x42, 0x05, 0x5a, 0x03, 0x70, 0x62, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/service/main/redis/redis.go b/service/main/redis/redis.go index c4ba0c7..0ed7a79 100644 --- a/service/main/redis/redis.go +++ b/service/main/redis/redis.go @@ -54,9 +54,9 @@ func GetRank(appId string, topCount int32) ([]*RankInfo, error) { return rankList, nil } -func SetAudience(data *pb.Audience) { +func SetAudience(appId string, data *pb.Audience) { ctx := context.Background() - key := fmt.Sprintf("UserData_%s", data.OpenId) + key := fmt.Sprintf("UserData_%s_%s", appId, data.OpenId) exist, err := client.Exists(ctx, key).Result() if err != nil { return @@ -74,7 +74,7 @@ func SetAudience(data *pb.Audience) { func GetAudience(appId string, openId string) *pb.Audience { ctx := context.Background() - key := fmt.Sprintf("UserData_%s", openId) + key := fmt.Sprintf("UserData_%s_%s", appId, openId) result, err := client.Get(ctx, key).Result() if err != nil { return nil @@ -84,13 +84,6 @@ func GetAudience(appId string, openId string) *pb.Audience { if err != nil { return nil } - scoreKey := fmt.Sprintf("Score_%s", appId) - cmd := client.HGet(ctx, scoreKey, openId) - result, err = cmd.Result() - if err == nil { - - } - return data } diff --git a/service/main/user/user.go b/service/main/user/user.go index 21fed77..624229f 100644 --- a/service/main/user/user.go +++ b/service/main/user/user.go @@ -92,7 +92,7 @@ func (s *User) OnRecvPush(data string) { return } if _, ok := s.audienceSet.Load(msg.OpenId); !ok { - audienceData := redis.GetAudience(msg.OpenId) + audienceData := redis.GetAudience(s.appId, msg.OpenId) if audienceData != nil { s.audienceSet.Store(msg.OpenId, 1) audienceMsg := &pb.NotifyNewAudience{