更新user缓存结构
This commit is contained in:
parent
d373a401de
commit
e387e9b8e5
@ -6,7 +6,6 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/sys/cache"
|
|
||||||
"go_dreamfactory/sys/db"
|
"go_dreamfactory/sys/db"
|
||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
"time"
|
"time"
|
||||||
@ -23,11 +22,13 @@ import (
|
|||||||
type LoginComp struct {
|
type LoginComp struct {
|
||||||
modules.MComp_GateComp
|
modules.MComp_GateComp
|
||||||
service base.IRPCXService
|
service base.IRPCXService
|
||||||
|
model *User
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *LoginComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *LoginComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
this.MComp_GateComp.Init(service, module, comp, options)
|
this.MComp_GateComp.Init(service, module, comp, options)
|
||||||
this.service = service.(base.IRPCXService)
|
this.service = service.(base.IRPCXService)
|
||||||
|
this.model = module.(*User)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,16 +61,14 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req
|
|||||||
)
|
)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
session.SendMsg("user", "login", code, &pb.UserLoginResp{
|
|
||||||
Data: &pb.Cache_UserData{
|
|
||||||
UserData: db_user,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if db_user != nil {
|
if db_user != nil {
|
||||||
|
session.SendMsg("user", "login", code, &pb.UserLoginResp{
|
||||||
|
Data: &pb.Cache_UserData{
|
||||||
|
Uid: db_user.Id,
|
||||||
|
},
|
||||||
|
})
|
||||||
event.TriggerEvent(comm.Event_UserLogin, db_user.Uid)
|
event.TriggerEvent(comm.Event_UserLogin, db_user.Uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if !utils.ValidSecretKey(req.Sec) {
|
if !utils.ValidSecretKey(req.Sec) {
|
||||||
@ -86,6 +85,11 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cache_user := &pb.Cache_UserData{
|
||||||
|
SessionId: session.GetSessionId(),
|
||||||
|
GatewayServiceId: session.GetGatewayServiceId(),
|
||||||
|
}
|
||||||
|
|
||||||
//如果是新玩家,创建一条基础的数据,页面会引导进入创角页面
|
//如果是新玩家,创建一条基础的数据,页面会引导进入创角页面
|
||||||
if db_user == nil {
|
if db_user == nil {
|
||||||
err = db.Defsys.User_Create(user)
|
err = db.Defsys.User_Create(user)
|
||||||
@ -94,20 +98,21 @@ func (this *LoginComp) Login(ctx context.Context, session comm.IUserSession, req
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
session.Bind(user.Uid, this.service.GetId())
|
session.Bind(user.Uid, this.service.GetId())
|
||||||
|
cache_user.Uid = user.Uid
|
||||||
} else {
|
} else {
|
||||||
session.Bind(db_user.Uid, this.service.GetId())
|
session.Bind(db_user.Uid, this.service.GetId())
|
||||||
|
cache_user.Uid = db_user.Uid
|
||||||
}
|
}
|
||||||
|
// data := map[string]interface{}{
|
||||||
cache_user := &pb.Cache_UserData{
|
// "sessionId": cache_user.SessionId,
|
||||||
SessionId: session.GetSessionId(),
|
// "gatewayServiceId": cache_user.GatewayServiceId,
|
||||||
GatewayServiceId: session.GetGatewayServiceId(),
|
// }
|
||||||
UserData: db_user,
|
// this.model.ModuleBas.Set(cache_user.Uid, data)
|
||||||
}
|
// err = cache.Defsys.Update(cache_user)
|
||||||
err = cache.Defsys.Update(cache_user)
|
// if err != nil {
|
||||||
if err != nil {
|
// log.Errorf("update cache err:%v", err)
|
||||||
log.Errorf("update cache err:%v", err)
|
// return err
|
||||||
return err
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -42,13 +42,15 @@ func (this *UserComp) Create(ctx context.Context, session comm.IUserSession, req
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
user.UserData.Name = req.NickName
|
user.Name = req.NickName
|
||||||
err = cache.Defsys.Update(user)
|
err = cache.Defsys.Update(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("cache update err")
|
log.Errorf("cache update err")
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
event.RegisterGO(comm.Event_CreateUser, session.GetUserId())
|
event.RegisterGO(comm.Event_CreateUser, session.GetUserId())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@ syntax = "proto3";
|
|||||||
option go_package = ".;pb";
|
option go_package = ".;pb";
|
||||||
|
|
||||||
message Cache_UserData {
|
message Cache_UserData {
|
||||||
|
string uid = 1;
|
||||||
string SessionId = 2;
|
string SessionId = 2;
|
||||||
string GatewayServiceId = 3;
|
string GatewayServiceId = 3;
|
||||||
DB_UserData UserData = 4;
|
// DB_UserData UserData = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DB_UserData {
|
message DB_UserData {
|
||||||
|
@ -25,9 +25,9 @@ type Cache_UserData struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId,omitempty"`
|
Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"`
|
||||||
GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"`
|
SessionId string `protobuf:"bytes,2,opt,name=SessionId,proto3" json:"SessionId,omitempty"`
|
||||||
UserData *DB_UserData `protobuf:"bytes,4,opt,name=UserData,proto3" json:"UserData,omitempty"`
|
GatewayServiceId string `protobuf:"bytes,3,opt,name=GatewayServiceId,proto3" json:"GatewayServiceId,omitempty"` // DB_UserData UserData = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Cache_UserData) Reset() {
|
func (x *Cache_UserData) Reset() {
|
||||||
@ -62,6 +62,13 @@ func (*Cache_UserData) Descriptor() ([]byte, []int) {
|
|||||||
return file_user_user_db_proto_rawDescGZIP(), []int{0}
|
return file_user_user_db_proto_rawDescGZIP(), []int{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Cache_UserData) GetUid() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Uid
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (x *Cache_UserData) GetSessionId() string {
|
func (x *Cache_UserData) GetSessionId() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.SessionId
|
return x.SessionId
|
||||||
@ -76,13 +83,6 @@ func (x *Cache_UserData) GetGatewayServiceId() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Cache_UserData) GetUserData() *DB_UserData {
|
|
||||||
if x != nil {
|
|
||||||
return x.UserData
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type DB_UserData struct {
|
type DB_UserData struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
@ -222,35 +222,34 @@ var File_user_user_db_proto protoreflect.FileDescriptor
|
|||||||
|
|
||||||
var file_user_user_db_proto_rawDesc = []byte{
|
var file_user_user_db_proto_rawDesc = []byte{
|
||||||
0x0a, 0x12, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x64, 0x62, 0x2e, 0x70,
|
0x0a, 0x12, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x64, 0x62, 0x2e, 0x70,
|
||||||
0x72, 0x6f, 0x74, 0x6f, 0x22, 0x84, 0x01, 0x0a, 0x0e, 0x43, 0x61, 0x63, 0x68, 0x65, 0x5f, 0x55,
|
0x72, 0x6f, 0x74, 0x6f, 0x22, 0x6c, 0x0a, 0x0e, 0x43, 0x61, 0x63, 0x68, 0x65, 0x5f, 0x55, 0x73,
|
||||||
0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1c, 0x0a, 0x09, 0x53, 0x65, 0x73, 0x73, 0x69,
|
0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20,
|
||||||
0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x53, 0x65, 0x73, 0x73,
|
0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x53, 0x65, 0x73, 0x73,
|
||||||
0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79,
|
0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x53, 0x65, 0x73,
|
||||||
0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61,
|
||||||
0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49,
|
0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x64, 0x12, 0x28, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20,
|
0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||||
0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74,
|
0x49, 0x64, 0x22, 0xaf, 0x02, 0x0a, 0x0b, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61,
|
||||||
0x61, 0x52, 0x08, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x22, 0xaf, 0x02, 0x0a, 0x0b,
|
0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02,
|
||||||
0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69,
|
0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75,
|
0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01,
|
||||||
0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a,
|
0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x69, 0x6e, 0x64,
|
||||||
0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69,
|
0x75, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75,
|
||||||
0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01,
|
0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x28, 0x09, 0x52, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e,
|
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x06, 0x20,
|
||||||
0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12,
|
0x01, 0x28, 0x05, 0x52, 0x03, 0x73, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x72, 0x65, 0x61,
|
||||||
0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x73, 0x69,
|
0x74, 0x65, 0x69, 0x70, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x72, 0x65, 0x61,
|
||||||
0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x69, 0x70, 0x18, 0x07, 0x20,
|
0x74, 0x65, 0x69, 0x70, 0x12, 0x20, 0x0a, 0x0b, 0x6c, 0x61, 0x73, 0x74, 0x6c, 0x6f, 0x67, 0x69,
|
||||||
0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x69, 0x70, 0x12, 0x20, 0x0a,
|
0x6e, 0x69, 0x70, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6c, 0x61, 0x73, 0x74, 0x6c,
|
||||||
0x0b, 0x6c, 0x61, 0x73, 0x74, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x69, 0x70, 0x18, 0x08, 0x20, 0x01,
|
0x6f, 0x67, 0x69, 0x6e, 0x69, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18,
|
||||||
0x28, 0x09, 0x52, 0x0b, 0x6c, 0x61, 0x73, 0x74, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x69, 0x70, 0x12,
|
0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09,
|
||||||
0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05,
|
0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52,
|
||||||
0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, 0x69,
|
0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x46, 0x72,
|
||||||
0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74,
|
0x69, 0x65, 0x6e, 0x64, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||||
0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x50, 0x6f, 0x69,
|
0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06,
|
||||||
0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64,
|
0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x76,
|
||||||
0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18,
|
0x61, 0x74, 0x61, 0x72, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
|
||||||
0x0c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x42, 0x06, 0x5a,
|
0x6f, 0x74, 0x6f, 0x33,
|
||||||
0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -271,12 +270,11 @@ var file_user_user_db_proto_goTypes = []interface{}{
|
|||||||
(*DB_UserData)(nil), // 1: DB_UserData
|
(*DB_UserData)(nil), // 1: DB_UserData
|
||||||
}
|
}
|
||||||
var file_user_user_db_proto_depIdxs = []int32{
|
var file_user_user_db_proto_depIdxs = []int32{
|
||||||
1, // 0: Cache_UserData.UserData:type_name -> DB_UserData
|
0, // [0:0] is the sub-list for method output_type
|
||||||
1, // [1:1] is the sub-list for method output_type
|
0, // [0:0] is the sub-list for method input_type
|
||||||
1, // [1:1] is the sub-list for method input_type
|
0, // [0:0] is the sub-list for extension type_name
|
||||||
1, // [1:1] is the sub-list for extension type_name
|
0, // [0:0] is the sub-list for extension extendee
|
||||||
1, // [1:1] is the sub-list for extension extendee
|
0, // [0:0] is the sub-list for field type_name
|
||||||
0, // [0:1] is the sub-list for field type_name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_user_user_db_proto_init() }
|
func init() { file_user_user_db_proto_init() }
|
||||||
|
Loading…
Reference in New Issue
Block a user