diff --git a/cmd/robot/user.go b/cmd/robot/user.go index a71969bd5..f96f1593a 100644 --- a/cmd/robot/user.go +++ b/cmd/robot/user.go @@ -14,7 +14,7 @@ var user_builders = []*TestCase{ mainType: string(comm.ModuleUser), subType: user.UserSubTypeCreate, req: &pb.UserCreateReq{ //设置请求参数 - NickName: "乐谷7411", + NickName: "乐谷7422", }, rsp: &pb.UserCreateResp{}, enabled: true, diff --git a/modules/user/model_session.go b/modules/user/model_session.go index 18b0f5522..04cfba88b 100644 --- a/modules/user/model_session.go +++ b/modules/user/model_session.go @@ -18,11 +18,11 @@ func (this *ModelSession) Init(service core.IService, module core.IModule, comp } //获取用户 -func (this *ModelSession) getUserSession(uid string) *pb.CacheUser { - cacheUser := &pb.CacheUser{} - if err := this.Get(uid, cacheUser); err != nil { +func (this *ModelSession) getUserSession(uid string) (cuser *pb.CacheUser) { + cuser = &pb.CacheUser{} + if err := this.Get(uid, cuser); err != nil { log.Errorf("GetUserSession err:%v", err) - return nil + return } - return cacheUser + return } diff --git a/modules/user/model_user.go b/modules/user/model_user.go index 9b6331b6d..843fe4339 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -61,13 +61,13 @@ func (this *ModelUser) User_Create(user *pb.DBUser) (err error) { } //获取用户 -func (this *ModelUser) GetUser(uid string) *pb.DBUser { - dbUser := &pb.DBUser{} - if err := this.Get(uid, dbUser); err != nil { +func (this *ModelUser) GetUser(uid string) (user *pb.DBUser) { + user = &pb.DBUser{} + if err := this.Get(uid, user); err != nil { log.Errorf("getUser err:%v", err) - return nil + return } - return dbUser + return } //设置属性 diff --git a/modules/user/module.go b/modules/user/module.go index 05a112764..5064faf09 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -41,12 +41,20 @@ func (this *User) OnInstallComp() { //获取用户数据 func (this *User) GetUser(uid string) *pb.DBUser { - return this.modelUser.GetUser(uid) + user := this.modelUser.GetUser(uid) + if user.Id == "" { + return nil + } + return user } //获取用户会话 func (this *User) GetUserSession(uid string) *pb.CacheUser { - return this.modelSession.getUserSession(uid) + cuser := this.modelSession.getUserSession(uid) + if cuser.Uid == "" { + return nil + } + return cuser } //查询用户属性值 例如 金币 经验 diff --git a/pb/proto/user/user_db.proto b/pb/proto/user/user_db.proto index 69156cc96..1e27beda4 100644 --- a/pb/proto/user/user_db.proto +++ b/pb/proto/user/user_db.proto @@ -5,6 +5,7 @@ message CacheUser { string uid = 1; string SessionId = 2; string GatewayServiceId = 3; + string ip = 4; // DB_UserData UserData = 4; //@go_tags(`json:",inline"`) } diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index 678686ea8..34f029e4b 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -27,7 +27,8 @@ type CacheUser struct { Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"` SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId"` - GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:",inline"` // DB_UserData UserData = 4; // + GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId"` + Ip string `protobuf:"bytes,4,opt,name=ip,proto3" json:",inline"` // DB_UserData UserData = 4; // } func (x *CacheUser) Reset() { @@ -83,6 +84,13 @@ func (x *CacheUser) GetGatewayServiceId() string { return "" } +func (x *CacheUser) GetIp() string { + if x != nil { + return x.Ip + } + return "" +} + type DBUser struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -262,13 +270,14 @@ var File_user_user_db_proto protoreflect.FileDescriptor var file_user_user_db_proto_rawDesc = []byte{ 0x0a, 0x12, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x64, 0x62, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x67, 0x0a, 0x09, 0x43, 0x61, 0x63, 0x68, 0x65, 0x55, 0x73, 0x65, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x77, 0x0a, 0x09, 0x43, 0x61, 0x63, 0x68, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x47, 0x61, 0x74, - 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x22, 0x8c, 0x03, + 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x70, 0x22, 0x8c, 0x03, 0x0a, 0x06, 0x44, 0x42, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75,